1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996 Free Software Foundation, Inc.
3 Contributed by Gary Funck (gary@intrepid.com). Derived from the
4 DWARF 1 implementation written by Ron Guilmette (rfg@monkeys.com).
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #if defined(DWARF_DEBUGGING_INFO) && defined(DWARF_VERSION) \
31 #include "hard-reg-set.h"
33 #include "insn-config.h"
38 /* #define NDEBUG 1 */
40 #if defined(DWARF_TIMESTAMPS)
43 #else /* !defined(POSIX) */
44 #include <sys/types.h>
46 extern time_t time (time_t *);
47 #else /* !defined(__STDC__) */
48 extern time_t time ();
49 #endif /* !defined(__STDC__) */
50 #endif /* !defined(POSIX) */
51 #endif /* defined(DWARF_TIMESTAMPS) */
53 extern char *getpwd ();
54 extern char *index ();
55 extern char *rindex ();
57 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
58 regarding the GNU implementation of DWARF. */
60 /* NOTE: In the comments in this file, many references are made to
61 "Debugging Information Entries". This term is abbreviated as `DIE'
62 throughout the remainder of this file. */
64 /* NOTE: The implementation of C++ support is unfinished. */
66 #if defined(__GNUC__) && (NDEBUG == 1)
67 #define inline static inline
73 /* An internal representation of the DWARF output is built, and then
74 walked to generate the DWARF debugging info. The walk of the internal
75 representation is done after the entire program has been compiled.
76 The types below are used to describe the internal representation. */
78 /* Each DIE may have a series of attribute/value pairs. Values
79 can take on several forms. The forms that are used in this
80 impelementation are listed below. */
86 dw_val_class_unsigned_const
,
87 dw_val_class_double_const
,
92 dw_val_class_section_offset
,
97 /* Various DIE's use offsets relative to the beginning of the
98 .debug_info section to refer to each other. */
99 typedef long int dw_offset
;
101 /* Define typedefs here to avoid circular dependencies. */
102 typedef struct die_struct
*dw_die_ref
;
103 typedef struct dw_attr_struct
*dw_attr_ref
;
104 typedef struct dw_val_struct
*dw_val_ref
;
105 typedef struct dw_line_info_struct
*dw_line_info_ref
;
106 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
107 typedef struct dw_cfi_struct
*dw_cfi_ref
;
108 typedef struct dw_fde_struct
*dw_fde_ref
;
109 typedef union dw_cfi_oprnd_struct
*dw_cfi_oprnd_ref
;
110 typedef struct backchain
*backchain_ref
;
112 /* Describe a double word constant value. */
113 typedef struct dw_double_const_struct
115 unsigned long dw_dbl_hi
;
116 unsigned long dw_dbl_low
;
120 /* Each entry in the line_info_table maintains the file and
121 line nuber associated with the label generated for that
122 entry. The label gives the PC value associated with
123 the line number entry. */
124 typedef struct dw_line_info_struct
126 unsigned long dw_file_num
;
127 unsigned long dw_line_num
;
131 /* The dw_val_node describes an attibute's value, as it is
132 represnted internally. */
133 typedef struct dw_val_struct
135 dw_val_class val_class
;
139 dw_loc_descr_ref val_loc
;
141 long unsigned val_unsigned
;
142 dw_dbl_const val_dbl_const
;
143 dw_die_ref val_die_ref
;
144 unsigned val_fde_index
;
148 unsigned char val_flag
;
154 /* Locations in memory are described using a sequence of stack machine
156 typedef struct dw_loc_descr_struct
158 dw_loc_descr_ref dw_loc_next
;
159 enum dwarf_location_atom dw_loc_opc
;
160 dw_val_node dw_loc_oprnd1
;
161 dw_val_node dw_loc_oprnd2
;
165 /* Each DIE attribute has a field specifying the attribute kind,
166 a link to the next attribute in the chain, and an attribute value.
167 Attributes are typically linked below the DIE they modify. */
168 typedef struct dw_attr_struct
170 enum dwarf_attribute dw_attr
;
171 dw_attr_ref dw_attr_next
;
172 dw_val_node dw_attr_val
;
176 /* Call frames are described using a sequence of Call Frame
177 Information instructions. The register number, offset
178 and address fields are provided as possible operands;
179 their use is selected by the opcode field. */
180 typedef union dw_cfi_oprnd_struct
182 unsigned long dw_cfi_reg_num
;
183 long int dw_cfi_offset
;
188 typedef struct dw_cfi_struct
190 dw_cfi_ref dw_cfi_next
;
191 enum dwarf_call_frame_info dw_cfi_opc
;
192 dw_cfi_oprnd dw_cfi_oprnd1
;
193 dw_cfi_oprnd dw_cfi_oprnd2
;
197 /* All call frame descriptions (FDE's) in the GCC generated DWARF
198 refer to a signle Common Information Entry (CIE), defined at
199 the beginning of the .debug_frame section. This used of a single
200 CIE obviates the need to keep track of multiple CIE's
201 in the DWARF generation routines below. */
202 typedef struct dw_fde_struct
204 unsigned long dw_fde_offset
;
206 char *dw_fde_end_prolog
;
207 char *dw_fde_begin_epilogue
;
209 dw_cfi_ref dw_fde_cfi
;
213 /* The Debugging Information Entry (DIE) structure */
214 typedef struct die_struct
216 enum dwarf_tag die_tag
;
217 dw_attr_ref die_attr
;
218 dw_attr_ref die_attr_last
;
219 dw_die_ref die_parent
;
220 dw_die_ref die_child
;
221 dw_die_ref die_child_last
;
223 dw_offset die_offset
;
224 unsigned long die_abbrev
;
228 /* The structure for backchaining support, when structure tags are declared
229 before they are defined. */
231 typedef struct backchain
234 dw_die_ref placeholder
;
239 /* How to start an assembler comment. */
240 #ifndef ASM_COMMENT_START
241 #define ASM_COMMENT_START ";#"
244 /* Define a macro which returns non-zero for any tagged type which is used
245 (directly or indirectly) in the specification of either some function's
246 return type or some formal parameter of some function. We use this macro
247 when we are operating in "terse" mode to help us know what tagged types
248 have to be represented in Dwarf (even in terse mode) and which ones don't.
249 A flag bit with this meaning really should be a part of the normal GCC
250 ..._TYPE nodes, but at the moment, there is no such bit defined for these
251 nodes. For now, we have to just fake it. It it safe for us to simply
252 return zero for all complete tagged types (which will get forced out
253 anyway if they were used in the specification of some formal or return
254 type) and non-zero for all incomplete tagged types. */
255 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
257 /* Information concerning the compilation unit's programming
258 language, and compiler version. */
259 extern int flag_traditional
;
260 extern char *version_string
;
261 extern char *language_string
;
263 /* Maximum size (in bytes) of an artificially generated label. */
264 #define MAX_ARTIFICIAL_LABEL_BYTES 30
266 /* Make sure we know the sizes of the various types dwarf can describe. These
267 are only defaults. If the sizes are different for your target, you should
268 override these values by defining the appropriate symbols in your tm.h
270 #ifndef CHAR_TYPE_SIZE
271 #define CHAR_TYPE_SIZE BITS_PER_UNIT
273 #ifndef SHORT_TYPE_SIZE
274 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
276 #ifndef INT_TYPE_SIZE
277 #define INT_TYPE_SIZE BITS_PER_WORD
279 #ifndef LONG_TYPE_SIZE
280 #define LONG_TYPE_SIZE BITS_PER_WORD
282 #ifndef LONG_LONG_TYPE_SIZE
283 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
285 #ifndef WCHAR_TYPE_SIZE
286 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
288 #ifndef WCHAR_UNSIGNED
289 #define WCHAR_UNSIGNED 0
291 #ifndef FLOAT_TYPE_SIZE
292 #define FLOAT_TYPE_SIZE BITS_PER_WORD
294 #ifndef DOUBLE_TYPE_SIZE
295 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
297 #ifndef LONG_DOUBLE_TYPE_SIZE
298 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
301 #define PTR_SIZE (POINTER_SIZE / 8)
304 /* Fixed size portion of the DWARF compilation unit header. */
305 #define DWARF_COMPILE_UNIT_HEADER_SIZE 11
307 /* Fixed size portion of debugging line information prolog. */
308 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
310 /* Fixed size portion of public names info. */
311 #define DWARF_PUBNAMES_HEADER_SIZE 10
313 /* Fixed size portion of the address range info. */
314 #define DWARF_ARANGES_HEADER_SIZE 12
316 /* Fixed size portion of the Common Information Entry (including
317 the length field). */
318 #define DWARF_CIE_HEADER_SIZE 16
320 /* Fixed size of the Common Information Entry in the call frame
321 information (.debug_frame) section rounded up to an 8 byte boundary. */
322 #define DWARF_CIE_SIZE ((DWARF_CIE_HEADER_SIZE + 7) & ~7)
324 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
325 #define DWARF_CIE_DATA_ALIGNMENT -4
327 /* Fixed size portion of the FDE. */
328 #define DWARF_FDE_HEADER_SIZE (4 + 4 + (2 * PTR_SIZE))
330 /* Define the architecture-dependent minimum instruction length (in bytes).
331 In this implementation of DWARF, this field is used for information
332 purposes only. Since GCC generates assembly language, we have
333 no a priori knowledge of how many instruction bytes are generated
334 for each source line, and therefore can use only the DW_LNE_set_address
335 and DW_LNS_fixed_advance_pc line information commands. */
336 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
337 #define DWARF_LINE_MIN_INSTR_LENGTH 4
340 /* Minimum line offset in a special line info. opcode.
341 This value was chosen to give a reasonable range of values. */
342 #define DWARF_LINE_BASE -10
344 /* First special line opcde - leave room for the standard opcodes. */
345 #define DWARF_LINE_OPCODE_BASE 10
347 /* Range of line offsets in a special line info. opcode. */
348 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
350 /* Flag that indicates the initial value of the is_stmt_start flag.
351 In the present implementation, we do not mark any lines as
352 the beginning of a source statement, because that information
353 is not made available by the GCC front-end. */
354 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
356 /* This location is used by calc_die_sizes() to keep track
357 the offset of each DIE within the .debug_info section. */
358 static unsigned long next_die_offset
;
360 /* This location is used by calc_fde_sizes() to keep track
361 the offset of each FDE within the .debug_frame section. */
362 static unsigned long next_fde_offset
;
364 /* Record the root of the DIE's built for the current compilation unit. */
365 dw_die_ref comp_unit_die
;
367 /* Pointer to an array of filenames referenced by this compilation unit. */
368 static char **file_table
;
370 /* Total number of entries in the table (i.e. array) pointed to by
371 `file_table'. This is the *total* and includes both used and unused
373 static unsigned file_table_allocated
;
375 /* Number of entries in the file_table which are actually in use. */
376 static unsigned file_table_in_use
;
378 /* Size (in elements) of increments by which we may expand the filename
380 #define FILE_TABLE_INCREMENT 64
382 /* Local pointer to the name of the main input file. Initialized in
384 static char *primary_filename
;
386 /* For Dwarf output, we must assign lexical-blocks id numbers in the order in
387 which their beginnings are encountered. We output Dwarf debugging info
388 that refers to the beginnings and ends of the ranges of code for each
389 lexical block. The labels themselves are generated in final.c, which
390 assigns numbers to the blocks in the same way. */
391 static unsigned next_block_number
= 2;
393 /* Non-zero if we are performing the file-scope finalization pass and if we
394 should force out Dwarf descriptions of any and all file-scope tagged types
395 which are still incomplete types. */
396 static int finalizing
= 0;
398 /* A pointer to the base of a list of references to DIE's that describe
399 types. The table is indexed by TYPE_UID() which is a unique number,
400 indentifying each type. */
401 static dw_die_ref
*type_die_table
;
403 /* Number of elements currently allocated for type_die_table. */
404 static unsigned type_die_table_allocated
;
406 /* Number of elements in type_die_table currently in use. */
407 static unsigned type_die_table_in_use
;
409 /* Size (in elements) of increments by which we may expand the
411 #define TYPE_DIE_TABLE_INCREMENT 4096
413 /* A pointer to the base of a table of references to DIE's that describe
414 declarations. The table is indexed by DECL_UID() which is a unique
415 number, indentifying each decl. */
416 static dw_die_ref
*decl_die_table
;
418 /* Number of elements currently allocated for the decl_die_table. */
419 static unsigned decl_die_table_allocated
;
421 /* Number of elements in decl_die_table currently in use. */
422 static unsigned decl_die_table_in_use
;
424 /* Size (in elements) of increments by which we may expand the
426 #define DECL_DIE_TABLE_INCREMENT 256
428 /* A pointer to the base of a table of references to declaration
429 scopes. This table is a display which tracks the nesting
430 of declaration scopes at the current scope and containing
431 scopes. This table is used to find the proper place to
432 define type declaration DIE's. */
433 static tree
*decl_scope_table
;
435 /* Number of elements currently allocated for the decl_scope_table. */
436 static unsigned decl_scope_table_allocated
;
438 /* Current level of nesting of declataion scopes. */
439 static unsigned decl_scope_depth
;
441 /* Size (in elements) of increments by which we may expand the
443 #define DECL_SCOPE_TABLE_INCREMENT 64
445 /* A pointer to the base of a list of references to DIE's that
446 are uniquely identified by their tag, presence/absence of
447 children DIE's, and list of attribute/value pairs. */
448 static dw_die_ref
*abbrev_die_table
;
450 /* Number of elements currently allocated for abbrev_die_table. */
451 static unsigned abbrev_die_table_allocated
;
453 /* Number of elements in type_die_table currently in use. */
454 static unsigned abbrev_die_table_in_use
;
456 /* Size (in elements) of increments by which we may expand the
458 #define ABBREV_DIE_TABLE_INCREMENT 256
460 /* A pointer to the base of a table that contains line information
461 for each source code line in the compilation unit. */
462 static dw_line_info_ref line_info_table
;
464 /* Number of elements currently allocated for line_info_table. */
465 static unsigned line_info_table_allocated
;
467 /* Number of elements in line_info_table currently in use. */
468 static unsigned line_info_table_in_use
;
470 /* Size (in elements) of increments by which we may expand the
472 #define LINE_INFO_TABLE_INCREMENT 1024
474 /* Keep track of the last line_info_table entry number, returned
475 by the prior call to lookup_filename(). This serves as a
476 cache used to speed up file name look ups. */
477 static unsigned prev_file_entry_num
= (unsigned) -1;
479 /* A pointer to the base of a table that contains frame description
480 information for each routine. */
481 static dw_fde_ref fde_table
;
483 /* Number of elements currently allocated for fde_table. */
484 static unsigned fde_table_allocated
;
486 /* Number of elements in fde_table currently in use. */
487 static unsigned fde_table_in_use
;
489 /* Size (in elements) of increments by which we may expand the
491 #define FDE_TABLE_INCREMENT 256
493 /* The number of the current function definition for which debugging
494 information is being generated. These numbers range from 1 up to the
495 maximum number of function definitions contained within the current
496 compilation unit. These numbers are used to create unique label id's
497 unique to each function definition. */
498 static unsigned current_funcdef_number
= 1;
500 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
501 attribute that accelerates the lookup of the FDE associated
502 with the subprogram. This variable holds the table index of the FDE
503 associated with the current function (body) definition. */
504 static unsigned current_funcdef_fde
;
506 /* Record the size of the frame, so that the DW_AT_frame_base
507 attribute can be set properly in gen_subprogram_die. */
508 static long int current_funcdef_frame_size
= 0;
510 /* DWARF requires that the compiler's primary datatypes
511 are mapped into a reference to a DIE that defines that
512 primary (base) type. The base_type_info structure is used
513 to track the correspondence between the name of a
514 base type used by GCC, and its corresponding type
515 characteristics. Note, that the bt_size field below
516 is the size in bits. */
517 typedef struct base_type_struct
*base_type_ref
;
518 typedef struct base_type_struct
521 enum dwarf_type bt_type
;
527 /* Characteristics of base types used by the compiler. */
528 static base_type_info base_type_table
[] =
530 {"void", DW_ATE_unsigned
, 0, 0},
531 /* TODO: on some architectures, "char" may be signed. */
532 {"char", DW_ATE_unsigned_char
, 0, CHAR_TYPE_SIZE
},
533 {"unsigned char", DW_ATE_unsigned_char
, 0, CHAR_TYPE_SIZE
},
534 {"signed char", DW_ATE_signed_char
, 1, CHAR_TYPE_SIZE
},
535 {"int", DW_ATE_signed
, 1, /* INT_TYPE_SIZE */ 4*8},
536 {"unsigned int", DW_ATE_unsigned
, 0, /* INT_TYPE_SIZE */ 4*8},
537 {"short", DW_ATE_signed
, 1, SHORT_TYPE_SIZE
},
538 {"short int", DW_ATE_signed
, 1, SHORT_TYPE_SIZE
},
539 {"short unsigned int", DW_ATE_unsigned
, 0, SHORT_TYPE_SIZE
},
540 {"long", DW_ATE_signed
, 1, /* LONG_TYPE_SIZE */ 4*8},
541 {"long int", DW_ATE_signed
, 1, /* LONG_TYPE_SIZE */ 4*8},
542 {"long unsigned int", DW_ATE_unsigned
, 0, /* LONG_TYPE_SIZE */ 4*8},
543 {"long long int", DW_ATE_signed
, 1, LONG_LONG_TYPE_SIZE
},
544 {"long long unsigned int", DW_ATE_unsigned
, 0, LONG_LONG_TYPE_SIZE
},
545 {"float", DW_ATE_float
, 1, /* FLOAT_TYPE_SIZE */ 4*8},
546 {"double", DW_ATE_float
, 1, DOUBLE_TYPE_SIZE
},
547 {"long double", DW_ATE_float
, 1, LONG_DOUBLE_TYPE_SIZE
},
548 {"complex", DW_ATE_complex_float
, 1, 2 * /* FLOAT_TYPE_SIZE */ 4*8},
549 {"double complex", DW_ATE_complex_float
, 1, 2 * DOUBLE_TYPE_SIZE
},
550 {"long double complex", DW_ATE_complex_float
, 1, 2 * LONG_DOUBLE_TYPE_SIZE
}
552 #define NUM_BASE_TYPES (sizeof(base_type_table)/sizeof(base_type_info))
554 /* Record the DIE associated with a given base type This table is
555 parallel to the base_type_table, and records the DIE genereated
556 to describe base type that has been previously referenced. */
557 static dw_die_ref base_type_die_table
[NUM_BASE_TYPES
];
559 /* This predefined base type is used to create certain anonymous types */
560 static dw_die_ref int_base_type_die
;
562 /* A pointer to the ..._DECL node which we have most recently been working
563 on. We keep this around just in case something about it looks screwy and
564 we want to tell the user what the source coordinates for the actual
566 static tree dwarf_last_decl
;
568 /* A list of DIE reference attributes values that need backchaining
570 static backchain_ref backchain
;
572 /* Forward declarations for functions defined in this file. */
573 static void gen_type_die ();
574 static void add_type_attribute ();
575 static void decls_for_scope ();
576 static void gen_decl_die ();
577 static unsigned lookup_filename ();
580 /* Definitions of defaults for assembler-dependent names of various
581 pseudo-ops and section names.
582 Theses may be overridden in the tm.h file (if necessary) for a particular
584 #ifndef UNALIGNED_SHORT_ASM_OP
585 #define UNALIGNED_SHORT_ASM_OP ".2byte"
587 #ifndef UNALIGNED_INT_ASM_OP
588 #define UNALIGNED_INT_ASM_OP ".4byte"
591 #define ASM_BYTE_OP ".byte"
594 /* Pseudo-op for defining a new section. */
595 #ifndef SECTION_ASM_OP
596 #define SECTION_ASM_OP ".section"
599 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
600 print the SECTION_ASM_OP and the section name. The default here works for
601 almost all svr4 assemblers, except for the sparc, where the section name
602 must be enclosed in double quotes. (See sparcv4.h). */
603 #ifndef SECTION_FORMAT
604 #define SECTION_FORMAT "\t%s\t%s\n"
607 /* Section names used to hold DWARF debugging information. */
608 #ifndef DEBUG_SECTION
609 #define DEBUG_SECTION ".debug_info"
611 #ifndef ABBREV_SECTION
612 #define ABBREV_SECTION ".debug_abbrev"
614 #ifndef ARANGES_SECTION
615 #define ARANGES_SECTION ".debug_aranges"
617 #ifndef DW_MACINFO_SECTION
618 #define DW_MACINFO_SECTION ".debug_macinfo"
620 #ifndef FRAME_SECTION
621 #define FRAME_SECTION ".debug_frame"
624 #define LINE_SECTION ".debug_line"
627 #define LOC_SECTION ".debug_loc"
629 #ifndef PUBNAMES_SECTION
630 #define PUBNAMES_SECTION ".debug_pubnames"
633 #define STR_SECTION ".debug_str"
636 /* Standerd ELF section names for compiled code and data. */
638 #define TEXT_SECTION ".text"
641 #define DATA_SECTION ".data"
643 #ifndef DATA1_SECTION
644 #define DATA1_SECTION ".data1"
646 #ifndef RODATA_SECTION
647 #define RODATA_SECTION ".rodata"
649 #ifndef RODATA1_SECTION
650 #define RODATA1_SECTION ".rodata1"
653 #define BSS_SECTION ".bss"
657 /* Definitions of defaults for formats and names of various special
658 (artificial) labels which may be generated within this file (when the -g
659 options is used and DWARF_DEBUGGING_INFO is in effect.
660 If necessary, these may be overridden from within the tm.h file, but
661 typically, overriding these defaults is unnecessary.
662 These labels have been hacked so that they all begin with a
663 `.L' sequence to appease the stock sparc/svr4 assembler and the
664 stock m88k/svr4 assembler, both of which need to see .L at the start of a
665 label in order to prevent that label from going into the linker symbol
666 table). Eventually, the ASM_GENERATE_INTERNAL_LABEL and
667 ASM_OUTPUT_INTERNAL_LABEL should be used, but that will require
669 #ifndef TEXT_BEGIN_LABEL
670 #define TEXT_BEGIN_LABEL ".L_text_b"
672 #ifndef TEXT_END_LABEL
673 #define TEXT_END_LABEL ".L_text_e"
675 #ifndef DATA_BEGIN_LABEL
676 #define DATA_BEGIN_LABEL ".L_data_b"
678 #ifndef DATA_END_LABEL
679 #define DATA_END_LABEL ".L_data_e"
681 #ifndef RODATA_BEGIN_LABEL
682 #define RODATA_BEGIN_LABEL ".L_rodata_b"
684 #ifndef RODATA_END_LABEL
685 #define RODATA_END_LABEL ".L_rodata_e"
687 #ifndef BSS_BEGIN_LABEL
688 #define BSS_BEGIN_LABEL ".L_bss_b"
690 #ifndef BSS_END_LABEL
691 #define BSS_END_LABEL ".L_bss_e"
693 #ifndef LINE_BEGIN_LABEL
694 #define LINE_BEGIN_LABEL ".L_line_b"
696 #ifndef LINE_END_LABEL
697 #define LINE_END_LABEL ".L_line_e"
699 #ifndef INSN_LABEL_FMT
700 #define INSN_LABEL_FMT ".L_I%u_%u"
702 #ifndef BLOCK_BEGIN_LABEL_FMT
703 #define BLOCK_BEGIN_LABEL_FMT ".L_B%u"
705 #ifndef BLOCK_END_LABEL_FMT
706 #define BLOCK_END_LABEL_FMT ".L_B%u_e"
708 #ifndef BODY_BEGIN_LABEL_FMT
709 #define BODY_BEGIN_LABEL_FMT ".L_b%u"
711 #ifndef BODY_END_LABEL_FMT
712 #define BODY_END_LABEL_FMT ".L_b%u_e"
714 #ifndef FUNC_END_LABEL_FMT
715 #define FUNC_END_LABEL_FMT ".L_f%u_e"
717 #ifndef LINE_CODE_LABEL_FMT
718 #define LINE_CODE_LABEL_FMT ".L_LC%u"
720 #ifndef SFNAMES_ENTRY_LABEL_FMT
721 #define SFNAMES_ENTRY_LABEL_FMT ".L_F%u"
725 /* Definitions of defaults for various types of primitive assembly language
726 output operations. These may be overridden from within the tm.h file,
727 but typically, that is unecessary. */
728 #ifndef ASM_OUTPUT_SECTION
729 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
730 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
733 #ifndef ASM_OUTPUT_DWARF_DELTA2
734 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
735 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
736 assemble_name (FILE, LABEL1); \
737 fprintf (FILE, "-"); \
738 assemble_name (FILE, LABEL2); \
742 #ifndef ASM_OUTPUT_DWARF_DELTA4
743 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
744 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
745 assemble_name (FILE, LABEL1); \
746 fprintf (FILE, "-"); \
747 assemble_name (FILE, LABEL2); \
751 #ifndef ASM_OUTPUT_DWARF_ADDR
752 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
753 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
754 assemble_name (FILE, LABEL); \
758 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
759 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
760 fprintf ((FILE), "\t%s\t%s", UNALIGNED_INT_ASM_OP, (ADDR))
763 #ifndef ASM_OUTPUT_DWARF_DATA1
764 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
765 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, VALUE)
768 #ifndef ASM_OUTPUT_DWARF_DATA2
769 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
770 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
773 #ifndef ASM_OUTPUT_DWARF_DATA4
774 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
775 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
778 #ifndef ASM_OUTPUT_DWARF_DATA8
779 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
781 if (WORDS_BIG_ENDIAN) \
783 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
784 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
788 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
789 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
794 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
795 newline is produced. When flag_verbose_asm is asserted, we add commnetary
796 at the end of the line, so we must avoid output of a newline here. */
797 #ifndef ASM_OUTPUT_DWARF_STRING
798 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
800 register int slen = strlen(P); \
801 register char *p = (P); \
803 fprintf (FILE, "\t.ascii \""); \
804 for (i = 0; i < slen; i++) \
806 register int c = p[i]; \
807 if (c == '\"' || c == '\\') \
809 if (c >= ' ' && c < 0177) \
813 fprintf (FILE, "\\%o", c); \
816 fprintf (FILE, "\\0\""); \
821 /* Convert a reference to the assembler name of a C-level name. This
822 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
823 a string rather than writing to a file. */
824 #ifndef ASM_NAME_TO_STRING
825 #define ASM_NAME_TO_STRING(STR, NAME) \
827 if ((NAME)[0] == '*') \
828 strcpy (STR, NAME+1); \
830 strcpy (STR, NAME); \
836 /************************ general utility functions **************************/
838 /* Return a pointer to a copy of the section string name 's' with all
839 attributes stripped off. */
844 register char *stripped
, *p
;
845 stripped
= xstrdup (s
);
847 while (*p
&& *p
!= ',')
853 /* Convert an integer constant expression into assembler syntax.
854 Addition and subtraction are the only arithmetic
855 that may appear in these expressions. This is an adaptation
856 of output_addr_const() in final.c. Here, the target of the
857 conversion is a string buffer. We can't use output_addr_const
858 directly, because it writes to a file. */
860 addr_const_to_string (str
, x
)
869 switch (GET_CODE (x
))
879 ASM_NAME_TO_STRING (buf1
, XSTR (x
, 0));
884 ASM_GENERATE_INTERNAL_LABEL (buf1
, "L", CODE_LABEL_NUMBER (XEXP (x
, 0)));
885 ASM_NAME_TO_STRING (buf2
, buf1
);
890 ASM_GENERATE_INTERNAL_LABEL (buf1
, "L", CODE_LABEL_NUMBER (x
));
891 ASM_NAME_TO_STRING (buf2
, buf1
);
897 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
907 /* This used to output parentheses around the expression, but that does
908 not work on the 386 (either ATT or BSD assembler). */
909 addr_const_to_string (buf1
, XEXP (x
, 0));
914 if (GET_MODE (x
) == VOIDmode
)
916 /* We can use %d if the number is one word and positive. */
917 if (CONST_DOUBLE_HIGH (x
))
919 #if HOST_BITS_PER_WIDE_INT == 64
920 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
926 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
932 CONST_DOUBLE_HIGH (x
), CONST_DOUBLE_LOW (x
));
933 else if (CONST_DOUBLE_LOW (x
) < 0)
935 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
940 CONST_DOUBLE_LOW (x
));
943 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
948 CONST_DOUBLE_LOW (x
));
952 /* We can't handle floating point constants; PRINT_OPERAND must
954 output_operand_lossage ("floating constant misused");
958 /* Some assemblers need integer constants to appear last (eg masm). */
959 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
)
961 addr_const_to_string (buf1
, XEXP (x
, 1));
963 if (INTVAL (XEXP (x
, 0)) >= 0)
965 addr_const_to_string (buf1
, XEXP (x
, 0));
970 addr_const_to_string (buf1
, XEXP (x
, 0));
972 if (INTVAL (XEXP (x
, 0)) >= 0)
974 addr_const_to_string (buf1
, XEXP (x
, 1));
980 /* Avoid outputting things like x-x or x+5-x, since some assemblers
981 can't handle that. */
982 x
= simplify_subtraction (x
);
983 if (GET_CODE (x
) != MINUS
)
986 addr_const_to_string (buf1
, XEXP (x
, 0));
989 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
990 && INTVAL (XEXP (x
, 1)) < 0)
992 strcat (str
, ASM_OPEN_PAREN
);
993 addr_const_to_string (buf1
, XEXP (x
, 1));
995 strcat (str
, ASM_CLOSE_PAREN
);
999 addr_const_to_string (buf1
, XEXP (x
, 1));
1006 addr_const_to_string (buf1
, XEXP (x
, 0));
1011 output_operand_lossage ("invalid expression as operand");
1015 /* Convert an address constant to a string, and return a pointer to
1016 a copy of the result, located on the heap. */
1022 addr_const_to_string (buf
, x
);
1023 return xstrdup (buf
);
1026 /* Test if rtl node points to a psuedo register. */
1031 return (((GET_CODE (rtl
) == REG
) && (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
))
1032 || ((GET_CODE (rtl
) == SUBREG
)
1033 && (REGNO (XEXP (rtl
, 0)) >= FIRST_PSEUDO_REGISTER
)));
1037 /* Return a reference to a type, with its const and volatile qualifiers
1040 type_main_variant (type
)
1043 type
= TYPE_MAIN_VARIANT (type
);
1045 /* There really should be only one main variant among any group of variants
1046 of a given type (and all of the MAIN_VARIANT values for all members of
1047 the group should point to that one type) but sometimes the C front-end
1048 messes this up for array types, so we work around that bug here. */
1049 if (TREE_CODE (type
) == ARRAY_TYPE
)
1051 while (type
!= TYPE_MAIN_VARIANT (type
))
1052 type
= TYPE_MAIN_VARIANT (type
);
1057 /* Return non-zero if the given type node represents a tagged type. */
1059 is_tagged_type (type
)
1062 register enum tree_code code
= TREE_CODE (type
);
1064 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
1065 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
1068 /* Convert a DIE tag into its string name. */
1070 dwarf_tag_name (tag
)
1071 register unsigned tag
;
1075 case DW_TAG_padding
:
1076 return "DW_TAG_padding";
1077 case DW_TAG_array_type
:
1078 return "DW_TAG_array_type";
1079 case DW_TAG_class_type
:
1080 return "DW_TAG_class_type";
1081 case DW_TAG_entry_point
:
1082 return "DW_TAG_entry_point";
1083 case DW_TAG_enumeration_type
:
1084 return "DW_TAG_enumeration_type";
1085 case DW_TAG_formal_parameter
:
1086 return "DW_TAG_formal_parameter";
1087 case DW_TAG_imported_declaration
:
1088 return "DW_TAG_imported_declaration";
1090 return "DW_TAG_label";
1091 case DW_TAG_lexical_block
:
1092 return "DW_TAG_lexical_block";
1094 return "DW_TAG_member";
1095 case DW_TAG_pointer_type
:
1096 return "DW_TAG_pointer_type";
1097 case DW_TAG_reference_type
:
1098 return "DW_TAG_reference_type";
1099 case DW_TAG_compile_unit
:
1100 return "DW_TAG_compile_unit";
1101 case DW_TAG_string_type
:
1102 return "DW_TAG_string_type";
1103 case DW_TAG_structure_type
:
1104 return "DW_TAG_structure_type";
1105 case DW_TAG_subroutine_type
:
1106 return "DW_TAG_subroutine_type";
1107 case DW_TAG_typedef
:
1108 return "DW_TAG_typedef";
1109 case DW_TAG_union_type
:
1110 return "DW_TAG_union_type";
1111 case DW_TAG_unspecified_parameters
:
1112 return "DW_TAG_unspecified_parameters";
1113 case DW_TAG_variant
:
1114 return "DW_TAG_variant";
1115 case DW_TAG_common_block
:
1116 return "DW_TAG_common_block";
1117 case DW_TAG_common_inclusion
:
1118 return "DW_TAG_common_inclusion";
1119 case DW_TAG_inheritance
:
1120 return "DW_TAG_inheritance";
1121 case DW_TAG_inlined_subroutine
:
1122 return "DW_TAG_inlined_subroutine";
1124 return "DW_TAG_module";
1125 case DW_TAG_ptr_to_member_type
:
1126 return "DW_TAG_ptr_to_member_type";
1127 case DW_TAG_set_type
:
1128 return "DW_TAG_set_type";
1129 case DW_TAG_subrange_type
:
1130 return "DW_TAG_subrange_type";
1131 case DW_TAG_with_stmt
:
1132 return "DW_TAG_with_stmt";
1133 case DW_TAG_access_declaration
:
1134 return "DW_TAG_access_declaration";
1135 case DW_TAG_base_type
:
1136 return "DW_TAG_base_type";
1137 case DW_TAG_catch_block
:
1138 return "DW_TAG_catch_block";
1139 case DW_TAG_const_type
:
1140 return "DW_TAG_const_type";
1141 case DW_TAG_constant
:
1142 return "DW_TAG_constant";
1143 case DW_TAG_enumerator
:
1144 return "DW_TAG_enumerator";
1145 case DW_TAG_file_type
:
1146 return "DW_TAG_file_type";
1148 return "DW_TAG_friend";
1149 case DW_TAG_namelist
:
1150 return "DW_TAG_namelist";
1151 case DW_TAG_namelist_item
:
1152 return "DW_TAG_namelist_item";
1153 case DW_TAG_packed_type
:
1154 return "DW_TAG_packed_type";
1155 case DW_TAG_subprogram
:
1156 return "DW_TAG_subprogram";
1157 case DW_TAG_template_type_param
:
1158 return "DW_TAG_template_type_param";
1159 case DW_TAG_template_value_param
:
1160 return "DW_TAG_template_value_param";
1161 case DW_TAG_thrown_type
:
1162 return "DW_TAG_thrown_type";
1163 case DW_TAG_try_block
:
1164 return "DW_TAG_try_block";
1165 case DW_TAG_variant_part
:
1166 return "DW_TAG_variant_part";
1167 case DW_TAG_variable
:
1168 return "DW_TAG_variable";
1169 case DW_TAG_volatile_type
:
1170 return "DW_TAG_volatile_type";
1171 case DW_TAG_MIPS_loop
:
1172 return "DW_TAG_MIPS_loop";
1173 case DW_TAG_format_label
:
1174 return "DW_TAG_format_label";
1175 case DW_TAG_function_template
:
1176 return "DW_TAG_function_template";
1177 case DW_TAG_class_template
:
1178 return "DW_TAG_class_template";
1180 return "DW_TAG_<unknown>";
1184 /* Convert a DWARF attribute code into its string name. */
1186 dwarf_attr_name (attr
)
1187 register unsigned attr
;
1192 return "DW_AT_sibling";
1193 case DW_AT_location
:
1194 return "DW_AT_location";
1196 return "DW_AT_name";
1197 case DW_AT_ordering
:
1198 return "DW_AT_ordering";
1199 case DW_AT_subscr_data
:
1200 return "DW_AT_subscr_data";
1201 case DW_AT_byte_size
:
1202 return "DW_AT_byte_size";
1203 case DW_AT_bit_offset
:
1204 return "DW_AT_bit_offset";
1205 case DW_AT_bit_size
:
1206 return "DW_AT_bit_size";
1207 case DW_AT_element_list
:
1208 return "DW_AT_element_list";
1209 case DW_AT_stmt_list
:
1210 return "DW_AT_stmt_list";
1212 return "DW_AT_low_pc";
1214 return "DW_AT_high_pc";
1215 case DW_AT_language
:
1216 return "DW_AT_language";
1218 return "DW_AT_member";
1220 return "DW_AT_discr";
1221 case DW_AT_discr_value
:
1222 return "DW_AT_discr_value";
1223 case DW_AT_visibility
:
1224 return "DW_AT_visibility";
1226 return "DW_AT_import";
1227 case DW_AT_string_length
:
1228 return "DW_AT_string_length";
1229 case DW_AT_common_reference
:
1230 return "DW_AT_common_reference";
1231 case DW_AT_comp_dir
:
1232 return "DW_AT_comp_dir";
1233 case DW_AT_const_value
:
1234 return "DW_AT_const_value";
1235 case DW_AT_containing_type
:
1236 return "DW_AT_containing_type";
1237 case DW_AT_default_value
:
1238 return "DW_AT_default_value";
1240 return "DW_AT_inline";
1241 case DW_AT_is_optional
:
1242 return "DW_AT_is_optional";
1243 case DW_AT_lower_bound
:
1244 return "DW_AT_lower_bound";
1245 case DW_AT_producer
:
1246 return "DW_AT_producer";
1247 case DW_AT_prototyped
:
1248 return "DW_AT_prototyped";
1249 case DW_AT_return_addr
:
1250 return "DW_AT_return_addr";
1251 case DW_AT_start_scope
:
1252 return "DW_AT_start_scope";
1253 case DW_AT_stride_size
:
1254 return "DW_AT_stride_size";
1255 case DW_AT_upper_bound
:
1256 return "DW_AT_upper_bound";
1257 case DW_AT_abstract_origin
:
1258 return "DW_AT_abstract_origin";
1259 case DW_AT_accessibility
:
1260 return "DW_AT_accessibility";
1261 case DW_AT_address_class
:
1262 return "DW_AT_address_class";
1263 case DW_AT_artificial
:
1264 return "DW_AT_artificial";
1265 case DW_AT_base_types
:
1266 return "DW_AT_base_types";
1267 case DW_AT_calling_convention
:
1268 return "DW_AT_calling_convention";
1270 return "DW_AT_count";
1271 case DW_AT_data_member_location
:
1272 return "DW_AT_data_member_location";
1273 case DW_AT_decl_column
:
1274 return "DW_AT_decl_column";
1275 case DW_AT_decl_file
:
1276 return "DW_AT_decl_file";
1277 case DW_AT_decl_line
:
1278 return "DW_AT_decl_line";
1279 case DW_AT_declaration
:
1280 return "DW_AT_declaration";
1281 case DW_AT_discr_list
:
1282 return "DW_AT_discr_list";
1283 case DW_AT_encoding
:
1284 return "DW_AT_encoding";
1285 case DW_AT_external
:
1286 return "DW_AT_external";
1287 case DW_AT_frame_base
:
1288 return "DW_AT_frame_base";
1290 return "DW_AT_friend";
1291 case DW_AT_identifier_case
:
1292 return "DW_AT_identifier_case";
1293 case DW_AT_macro_info
:
1294 return "DW_AT_macro_info";
1295 case DW_AT_namelist_items
:
1296 return "DW_AT_namelist_items";
1297 case DW_AT_priority
:
1298 return "DW_AT_priority";
1300 return "DW_AT_segment";
1301 case DW_AT_specification
:
1302 return "DW_AT_specification";
1303 case DW_AT_static_link
:
1304 return "DW_AT_static_link";
1306 return "DW_AT_type";
1307 case DW_AT_use_location
:
1308 return "DW_AT_use_location";
1309 case DW_AT_variable_parameter
:
1310 return "DW_AT_variable_parameter";
1311 case DW_AT_virtuality
:
1312 return "DW_AT_virtuality";
1313 case DW_AT_vtable_elem_location
:
1314 return "DW_AT_vtable_elem_location";
1316 #ifdef MIPS_DEBUGGING_INFO
1317 case DW_AT_MIPS_fde
:
1318 return "DW_AT_MIPS_fde";
1319 case DW_AT_MIPS_loop_begin
:
1320 return "DW_AT_MIPS_loop_begin";
1321 case DW_AT_MIPS_tail_loop_begin
:
1322 return "DW_AT_MIPS_tail_loop_begin";
1323 case DW_AT_MIPS_epilog_begin
:
1324 return "DW_AT_MIPS_epilog_begin";
1325 case DW_AT_MIPS_loop_unroll_factor
:
1326 return "DW_AT_MIPS_loop_unroll_factor";
1327 case DW_AT_MIPS_software_pipeline_depth
:
1328 return "DW_AT_MIPS_software_pipeline_depth";
1329 case DW_AT_MIPS_linkage_name
:
1330 return "DW_AT_MIPS_linkage_name";
1333 case DW_AT_sf_names
:
1334 return "DW_AT_sf_names";
1335 case DW_AT_src_info
:
1336 return "DW_AT_src_info";
1337 case DW_AT_mac_info
:
1338 return "DW_AT_mac_info";
1339 case DW_AT_src_coords
:
1340 return "DW_AT_src_coords";
1341 case DW_AT_body_begin
:
1342 return "DW_AT_body_begin";
1343 case DW_AT_body_end
:
1344 return "DW_AT_body_end";
1346 return "DW_AT_<unknown>";
1350 /* Convert a DWARF value form code into its string name. */
1352 dwarf_form_name (form
)
1353 register unsigned form
;
1358 return "DW_FORM_addr";
1359 case DW_FORM_block2
:
1360 return "DW_FORM_block2";
1361 case DW_FORM_block4
:
1362 return "DW_FORM_block4";
1364 return "DW_FORM_data2";
1366 return "DW_FORM_data4";
1368 return "DW_FORM_data8";
1369 case DW_FORM_string
:
1370 return "DW_FORM_string";
1372 return "DW_FORM_block";
1373 case DW_FORM_block1
:
1374 return "DW_FORM_block1";
1376 return "DW_FORM_data1";
1378 return "DW_FORM_flag";
1380 return "DW_FORM_sdata";
1382 return "DW_FORM_strp";
1384 return "DW_FORM_udata";
1385 case DW_FORM_ref_addr
:
1386 return "DW_FORM_ref_addr";
1388 return "DW_FORM_ref1";
1390 return "DW_FORM_ref2";
1392 return "DW_FORM_ref4";
1394 return "DW_FORM_ref8";
1395 case DW_FORM_ref_udata
:
1396 return "DW_FORM_ref_udata";
1397 case DW_FORM_indirect
:
1398 return "DW_FORM_indirect";
1400 return "DW_FORM_<unknown>";
1404 /* Convert a DWARF stack opcode into its string name. */
1406 dwarf_stack_op_name (op
)
1407 register unsigned op
;
1412 return "DW_OP_addr";
1414 return "DW_OP_deref";
1416 return "DW_OP_const1u";
1418 return "DW_OP_const1s";
1420 return "DW_OP_const2u";
1422 return "DW_OP_const2s";
1424 return "DW_OP_const4u";
1426 return "DW_OP_const4s";
1428 return "DW_OP_const8u";
1430 return "DW_OP_const8s";
1432 return "DW_OP_constu";
1434 return "DW_OP_consts";
1438 return "DW_OP_drop";
1440 return "DW_OP_over";
1442 return "DW_OP_pick";
1444 return "DW_OP_swap";
1448 return "DW_OP_xderef";
1456 return "DW_OP_minus";
1468 return "DW_OP_plus";
1469 case DW_OP_plus_uconst
:
1470 return "DW_OP_plus_uconst";
1476 return "DW_OP_shra";
1494 return "DW_OP_skip";
1496 return "DW_OP_lit0";
1498 return "DW_OP_lit1";
1500 return "DW_OP_lit2";
1502 return "DW_OP_lit3";
1504 return "DW_OP_lit4";
1506 return "DW_OP_lit5";
1508 return "DW_OP_lit6";
1510 return "DW_OP_lit7";
1512 return "DW_OP_lit8";
1514 return "DW_OP_lit9";
1516 return "DW_OP_lit10";
1518 return "DW_OP_lit11";
1520 return "DW_OP_lit12";
1522 return "DW_OP_lit13";
1524 return "DW_OP_lit14";
1526 return "DW_OP_lit15";
1528 return "DW_OP_lit16";
1530 return "DW_OP_lit17";
1532 return "DW_OP_lit18";
1534 return "DW_OP_lit19";
1536 return "DW_OP_lit20";
1538 return "DW_OP_lit21";
1540 return "DW_OP_lit22";
1542 return "DW_OP_lit23";
1544 return "DW_OP_lit24";
1546 return "DW_OP_lit25";
1548 return "DW_OP_lit26";
1550 return "DW_OP_lit27";
1552 return "DW_OP_lit28";
1554 return "DW_OP_lit29";
1556 return "DW_OP_lit30";
1558 return "DW_OP_lit31";
1560 return "DW_OP_reg0";
1562 return "DW_OP_reg1";
1564 return "DW_OP_reg2";
1566 return "DW_OP_reg3";
1568 return "DW_OP_reg4";
1570 return "DW_OP_reg5";
1572 return "DW_OP_reg6";
1574 return "DW_OP_reg7";
1576 return "DW_OP_reg8";
1578 return "DW_OP_reg9";
1580 return "DW_OP_reg10";
1582 return "DW_OP_reg11";
1584 return "DW_OP_reg12";
1586 return "DW_OP_reg13";
1588 return "DW_OP_reg14";
1590 return "DW_OP_reg15";
1592 return "DW_OP_reg16";
1594 return "DW_OP_reg17";
1596 return "DW_OP_reg18";
1598 return "DW_OP_reg19";
1600 return "DW_OP_reg20";
1602 return "DW_OP_reg21";
1604 return "DW_OP_reg22";
1606 return "DW_OP_reg23";
1608 return "DW_OP_reg24";
1610 return "DW_OP_reg25";
1612 return "DW_OP_reg26";
1614 return "DW_OP_reg27";
1616 return "DW_OP_reg28";
1618 return "DW_OP_reg29";
1620 return "DW_OP_reg30";
1622 return "DW_OP_reg31";
1624 return "DW_OP_breg0";
1626 return "DW_OP_breg1";
1628 return "DW_OP_breg2";
1630 return "DW_OP_breg3";
1632 return "DW_OP_breg4";
1634 return "DW_OP_breg5";
1636 return "DW_OP_breg6";
1638 return "DW_OP_breg7";
1640 return "DW_OP_breg8";
1642 return "DW_OP_breg9";
1644 return "DW_OP_breg10";
1646 return "DW_OP_breg11";
1648 return "DW_OP_breg12";
1650 return "DW_OP_breg13";
1652 return "DW_OP_breg14";
1654 return "DW_OP_breg15";
1656 return "DW_OP_breg16";
1658 return "DW_OP_breg17";
1660 return "DW_OP_breg18";
1662 return "DW_OP_breg19";
1664 return "DW_OP_breg20";
1666 return "DW_OP_breg21";
1668 return "DW_OP_breg22";
1670 return "DW_OP_breg23";
1672 return "DW_OP_breg24";
1674 return "DW_OP_breg25";
1676 return "DW_OP_breg26";
1678 return "DW_OP_breg27";
1680 return "DW_OP_breg28";
1682 return "DW_OP_breg29";
1684 return "DW_OP_breg30";
1686 return "DW_OP_breg31";
1688 return "DW_OP_regx";
1690 return "DW_OP_fbreg";
1692 return "DW_OP_bregx";
1694 return "DW_OP_piece";
1695 case DW_OP_deref_size
:
1696 return "DW_OP_deref_size";
1697 case DW_OP_xderef_size
:
1698 return "DW_OP_xderef_size";
1702 return "OP_<unknown>";
1706 /* Convert a DWARF type code into its string name. */
1708 dwarf_type_encoding_name (enc
)
1709 register unsigned enc
;
1713 case DW_ATE_address
:
1714 return "DW_ATE_address";
1715 case DW_ATE_boolean
:
1716 return "DW_ATE_boolean";
1717 case DW_ATE_complex_float
:
1718 return "DW_ATE_complex_float";
1720 return "DW_ATE_float";
1722 return "DW_ATE_signed";
1723 case DW_ATE_signed_char
:
1724 return "DW_ATE_signed_char";
1725 case DW_ATE_unsigned
:
1726 return "DW_ATE_unsigned";
1727 case DW_ATE_unsigned_char
:
1728 return "DW_ATE_unsigned_char";
1730 return "DW_ATE_<unknown>";
1734 /* Convert a DWARF call frame info. operation to its string name */
1736 dwarf_cfi_name (cfi_opc
)
1737 register unsigned cfi_opc
;
1741 case DW_CFA_advance_loc
:
1742 return "DW_CFA_advance_loc";
1744 return "DW_CFA_offset";
1745 case DW_CFA_restore
:
1746 return "DW_CFA_restore";
1748 return "DW_CFA_nop";
1749 case DW_CFA_set_loc
:
1750 return "DW_CFA_set_loc";
1751 case DW_CFA_advance_loc1
:
1752 return "DW_CFA_advance_loc1";
1753 case DW_CFA_advance_loc2
:
1754 return "DW_CFA_advance_loc2";
1755 case DW_CFA_advance_loc4
:
1756 return "DW_CFA_advance_loc4";
1757 case DW_CFA_offset_extended
:
1758 return "DW_CFA_offset_extended";
1759 case DW_CFA_restore_extended
:
1760 return "DW_CFA_restore_extended";
1761 case DW_CFA_undefined
:
1762 return "DW_CFA_undefined";
1763 case DW_CFA_same_value
:
1764 return "DW_CFA_same_value";
1765 case DW_CFA_register
:
1766 return "DW_CFA_register";
1767 case DW_CFA_remember_state
:
1768 return "DW_CFA_remember_state";
1769 case DW_CFA_restore_state
:
1770 return "DW_CFA_restore_state";
1771 case DW_CFA_def_cfa
:
1772 return "DW_CFA_def_cfa";
1773 case DW_CFA_def_cfa_register
:
1774 return "DW_CFA_def_cfa_register";
1775 case DW_CFA_def_cfa_offset
:
1776 return "DW_CFA_def_cfa_offset";
1777 /* SGI/MIPS specific */
1778 case DW_CFA_MIPS_advance_loc8
:
1779 return "DW_CFA_MIPS_advance_loc8";
1781 return "DW_CFA_<unknown>";
1785 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
1786 instance of an inlined instance of a decl which is local to an inline
1787 function, so we have to trace all of the way back through the origin chain
1788 to find out what sort of node actually served as the original seed for the
1791 decl_ultimate_origin (decl
)
1794 register tree immediate_origin
= DECL_ABSTRACT_ORIGIN (decl
);
1796 if (immediate_origin
== NULL
)
1800 register tree ret_val
;
1801 register tree lookahead
= immediate_origin
;
1805 ret_val
= lookahead
;
1806 lookahead
= DECL_ABSTRACT_ORIGIN (ret_val
);
1808 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
1813 /* Determine the "ultimate origin" of a block. The block may be an inlined
1814 instance of an inlined instance of a block which is local to an inline
1815 function, so we have to trace all of the way back through the origin chain
1816 to find out what sort of node actually served as the original seed for the
1819 block_ultimate_origin (block
)
1820 register tree block
;
1822 register tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
1824 if (immediate_origin
== NULL
)
1828 register tree ret_val
;
1829 register tree lookahead
= immediate_origin
;
1833 ret_val
= lookahead
;
1834 lookahead
= (TREE_CODE (ret_val
) == BLOCK
)
1835 ? BLOCK_ABSTRACT_ORIGIN (ret_val
)
1838 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
1843 /**************** DIE internal representation constturction *******************/
1845 /* Add an attribute/value pair to a DIE */
1847 add_dwarf_attr (die
, attr
)
1848 register dw_die_ref die
;
1849 register dw_attr_ref attr
;
1851 if (die
!= NULL
&& attr
!= NULL
)
1853 if (die
->die_attr
== NULL
)
1855 die
->die_attr
= attr
;
1856 die
->die_attr_last
= attr
;
1860 die
->die_attr_last
->dw_attr_next
= attr
;
1861 die
->die_attr_last
= attr
;
1866 /* Add a flag value attribute to a DIE. */
1868 add_AT_flag (die
, attr_kind
, flag
)
1869 register dw_die_ref die
;
1870 register enum dwarf_attribute attr_kind
;
1871 register unsigned flag
;
1873 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
1876 attr
->dw_attr_next
= NULL
;
1877 attr
->dw_attr
= attr_kind
;
1878 attr
->dw_attr_val
.val_class
= dw_val_class_flag
;
1879 attr
->dw_attr_val
.v
.val_flag
= flag
;
1880 add_dwarf_attr (die
, attr
);
1884 /* Add a signed integer attribute value to a DIE. */
1886 add_AT_int (die
, attr_kind
, int_val
)
1887 register dw_die_ref die
;
1888 register enum dwarf_attribute attr_kind
;
1889 register long int int_val
;
1891 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
1894 attr
->dw_attr_next
= NULL
;
1895 attr
->dw_attr
= attr_kind
;
1896 attr
->dw_attr_val
.val_class
= dw_val_class_const
;
1897 attr
->dw_attr_val
.v
.val_int
= int_val
;
1898 add_dwarf_attr (die
, attr
);
1902 /* Add an unsigned integer attribute value to a DIE. */
1904 add_AT_unsigned (die
, attr_kind
, unsigned_val
)
1905 register dw_die_ref die
;
1906 register enum dwarf_attribute attr_kind
;
1907 register unsigned long unsigned_val
;
1909 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
1912 attr
->dw_attr_next
= NULL
;
1913 attr
->dw_attr
= attr_kind
;
1914 attr
->dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
1915 attr
->dw_attr_val
.v
.val_unsigned
= unsigned_val
;
1916 add_dwarf_attr (die
, attr
);
1920 /* Add an unsigned double integer attribute value to a DIE. */
1922 add_AT_double (die
, attr_kind
, val_hi
, val_low
)
1923 register dw_die_ref die
;
1924 register enum dwarf_attribute attr_kind
;
1925 register unsigned long val_hi
;
1926 register unsigned long val_low
;
1928 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
1931 attr
->dw_attr_next
= NULL
;
1932 attr
->dw_attr
= attr_kind
;
1933 attr
->dw_attr_val
.val_class
= dw_val_class_double_const
;
1934 attr
->dw_attr_val
.v
.val_dbl_const
.dw_dbl_hi
= val_hi
;
1935 attr
->dw_attr_val
.v
.val_dbl_const
.dw_dbl_low
= val_low
;
1936 add_dwarf_attr (die
, attr
);
1940 /* Add a string attribute value to a DIE. */
1942 add_AT_string (die
, attr_kind
, str
)
1943 register dw_die_ref die
;
1944 register enum dwarf_attribute attr_kind
;
1947 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
1950 attr
->dw_attr_next
= NULL
;
1951 attr
->dw_attr
= attr_kind
;
1952 attr
->dw_attr_val
.val_class
= dw_val_class_str
;
1953 attr
->dw_attr_val
.v
.val_str
= xstrdup (str
);
1954 add_dwarf_attr (die
, attr
);
1958 /* Add a DIE reference attribute value to a DIE. */
1960 add_AT_die_ref (die
, attr_kind
, targ_die
)
1961 register dw_die_ref die
;
1962 register enum dwarf_attribute attr_kind
;
1963 register dw_die_ref targ_die
;
1965 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
1968 attr
->dw_attr_next
= NULL
;
1969 attr
->dw_attr
= attr_kind
;
1970 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
1971 attr
->dw_attr_val
.v
.val_die_ref
= targ_die
;
1972 add_dwarf_attr (die
, attr
);
1976 /* Add an FDE reference attribute value to a DIE. */
1978 add_AT_fde_ref (die
, attr_kind
, targ_fde
)
1979 register dw_die_ref die
;
1980 register enum dwarf_attribute attr_kind
;
1981 register unsigned targ_fde
;
1983 register dw_attr_ref attr
;
1985 attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
1988 attr
->dw_attr_next
= NULL
;
1989 attr
->dw_attr
= attr_kind
;
1990 attr
->dw_attr_val
.val_class
= dw_val_class_fde_ref
;
1991 attr
->dw_attr_val
.v
.val_fde_index
= targ_fde
;
1992 add_dwarf_attr (die
, attr
);
1996 /* Add a location description attribute value to a DIE. */
1998 add_AT_loc (die
, attr_kind
, loc
)
1999 register dw_die_ref die
;
2000 register enum dwarf_attribute attr_kind
;
2001 register dw_loc_descr_ref loc
;
2003 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
2006 attr
->dw_attr_next
= NULL
;
2007 attr
->dw_attr
= attr_kind
;
2008 attr
->dw_attr_val
.val_class
= dw_val_class_loc
;
2009 attr
->dw_attr_val
.v
.val_loc
= loc
;
2010 add_dwarf_attr (die
, attr
);
2014 /* Add an address constant attribute value to a DIE. */
2016 add_AT_addr (die
, attr_kind
, addr
)
2017 register dw_die_ref die
;
2018 register enum dwarf_attribute attr_kind
;
2021 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
2024 attr
->dw_attr_next
= NULL
;
2025 attr
->dw_attr
= attr_kind
;
2026 attr
->dw_attr_val
.val_class
= dw_val_class_addr
;
2027 attr
->dw_attr_val
.v
.val_addr
= addr
;
2028 add_dwarf_attr (die
, attr
);
2032 /* Add a label identifier attribute value to a DIE. */
2034 add_AT_lbl_id (die
, attr_kind
, lbl_id
)
2035 register dw_die_ref die
;
2036 register enum dwarf_attribute attr_kind
;
2037 register char *lbl_id
;
2039 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
2042 attr
->dw_attr_next
= NULL
;
2043 attr
->dw_attr
= attr_kind
;
2044 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_id
;
2045 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
2046 add_dwarf_attr (die
, attr
);
2050 /* Add a section offset attribute value to a DIE. */
2052 add_AT_section_offset (die
, attr_kind
, section
)
2053 register dw_die_ref die
;
2054 register enum dwarf_attribute attr_kind
;
2055 register char *section
;
2057 register dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
2060 attr
->dw_attr_next
= NULL
;
2061 attr
->dw_attr
= attr_kind
;
2062 attr
->dw_attr_val
.val_class
= dw_val_class_section_offset
;
2063 attr
->dw_attr_val
.v
.val_section
= section
;
2064 add_dwarf_attr (die
, attr
);
2068 /* Save a DIE reference attribute value to a DIE for later backchaining. */
2070 backchain_AT_die_ref (type
, placeholder
)
2072 register dw_die_ref placeholder
;
2074 register backchain_ref back
= (backchain_ref
) xmalloc (sizeof (backchain_t
));
2078 back
->placeholder
= placeholder
;
2080 back
->next
= backchain
;
2085 /* Test if die refers to an external subroutine. */
2087 is_extern_subr_die (die
)
2088 register dw_die_ref die
;
2090 register dw_attr_ref a
;
2091 register int is_subr
= FALSE
;
2092 register int is_extern
= FALSE
;
2093 if (die
!= NULL
&& die
->die_tag
== DW_TAG_subprogram
)
2096 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
2098 if (a
->dw_attr
== DW_AT_external
2099 && a
->dw_attr_val
.val_class
== dw_val_class_flag
2100 && a
->dw_attr_val
.v
.val_flag
!= 0)
2107 return is_subr
&& is_extern
;
2110 /* Return the "low pc" attribute value, typically associated with
2111 a subprogram DIE. Return null if the "low pc" attribute is
2112 either not prsent, or if it cannot be represented as an
2113 assembler label identifier. */
2116 register dw_die_ref die
;
2118 register dw_attr_ref a
;
2119 register char *low_pc
= NULL
;
2122 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
2124 if (a
->dw_attr
== DW_AT_low_pc
2125 && a
->dw_attr_val
.val_class
== dw_val_class_lbl_id
)
2127 low_pc
= a
->dw_attr_val
.v
.val_lbl_id
;
2136 /* Return the "high pc" attribute value, typically associated with
2137 a subprogram DIE. Return null if the "high pc" attribute is
2138 either not prsent, or if it cannot be represented as an
2139 assembler label identifier. */
2142 register dw_die_ref die
;
2144 register dw_attr_ref a
;
2145 register char *hi_pc
= NULL
;
2148 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
2150 if (a
->dw_attr
== DW_AT_high_pc
2151 && a
->dw_attr_val
.val_class
== dw_val_class_lbl_id
)
2153 hi_pc
= a
->dw_attr_val
.v
.val_lbl_id
;
2161 /* Add a child DIE below its parent. */
2163 add_child_die (die
, child_die
)
2164 register dw_die_ref die
;
2165 register dw_die_ref child_die
;
2167 if (die
!= NULL
&& child_die
!= NULL
)
2169 assert (die
!= child_die
);
2170 child_die
->die_parent
= die
;
2171 child_die
->die_sib
= NULL
;
2172 if (die
->die_child
== NULL
)
2174 die
->die_child
= child_die
;
2175 die
->die_child_last
= child_die
;
2179 die
->die_child_last
->die_sib
= child_die
;
2180 die
->die_child_last
= child_die
;
2185 /* Return a pointer to a newly created DIE node. */
2187 new_die (tag_value
, parent_die
)
2188 register enum dwarf_tag tag_value
;
2189 register dw_die_ref parent_die
;
2191 register dw_die_ref die
= (dw_die_ref
) xmalloc (sizeof (die_node
));
2194 die
->die_tag
= tag_value
;
2195 die
->die_abbrev
= 0;
2196 die
->die_offset
= 0;
2197 die
->die_child
= NULL
;
2198 die
->die_parent
= NULL
;
2199 die
->die_sib
= NULL
;
2200 die
->die_child_last
= NULL
;
2201 die
->die_attr
= NULL
;
2202 die
->die_attr_last
= NULL
;
2203 if (parent_die
!= NULL
)
2205 add_child_die (parent_die
, die
);
2211 /* Return the DIE associated with the given type specifier. */
2213 lookup_type_die (type
)
2216 register unsigned type_id
= TYPE_UID (type
);
2217 return (type_id
< type_die_table_in_use
)
2218 ? type_die_table
[type_id
] : NULL
;
2221 /* Equate a DIE to a given type specifier. */
2223 equate_type_number_to_die (type
, type_die
)
2225 register dw_die_ref type_die
;
2227 register unsigned type_id
= TYPE_UID (type
);
2228 register unsigned i
;
2229 register unsigned num_allocated
;
2230 if (type_id
>= type_die_table_allocated
)
2232 num_allocated
= (((type_id
+ 1)
2233 + TYPE_DIE_TABLE_INCREMENT
- 1)
2234 / TYPE_DIE_TABLE_INCREMENT
)
2235 * TYPE_DIE_TABLE_INCREMENT
;
2236 type_die_table
= (dw_die_ref
*) xrealloc (type_die_table
,
2237 sizeof (dw_die_ref
) * num_allocated
);
2238 bzero (&type_die_table
[type_die_table_allocated
],
2239 (num_allocated
- type_die_table_allocated
) * sizeof (dw_die_ref
));
2240 type_die_table_allocated
= num_allocated
;
2242 if (type_id
>= type_die_table_in_use
)
2244 type_die_table_in_use
= (type_id
+ 1);
2246 type_die_table
[type_id
] = type_die
;
2249 /* Return the DIE associated with a given declaration. */
2251 lookup_decl_die (decl
)
2254 register unsigned decl_id
= DECL_UID (decl
);
2255 return (decl_id
< decl_die_table_in_use
)
2256 ? decl_die_table
[decl_id
] : NULL
;
2259 /* Equate a DIE to a particular declaration. */
2261 equate_decl_number_to_die (decl
, decl_die
)
2263 register dw_die_ref decl_die
;
2265 register unsigned decl_id
= DECL_UID (decl
);
2266 register unsigned i
;
2267 register unsigned num_allocated
;
2268 if (decl_id
>= decl_die_table_allocated
)
2270 num_allocated
= (((decl_id
+ 1)
2271 + DECL_DIE_TABLE_INCREMENT
- 1)
2272 / DECL_DIE_TABLE_INCREMENT
)
2273 * DECL_DIE_TABLE_INCREMENT
;
2274 decl_die_table
= (dw_die_ref
*) xrealloc (decl_die_table
,
2275 sizeof (dw_die_ref
) * num_allocated
);
2276 bzero (&decl_die_table
[decl_die_table_allocated
],
2277 (num_allocated
- decl_die_table_allocated
) * sizeof (dw_die_ref
));
2278 decl_die_table_allocated
= num_allocated
;
2280 if (decl_id
>= decl_die_table_in_use
)
2282 decl_die_table_in_use
= (decl_id
+ 1);
2284 decl_die_table
[decl_id
] = decl_die
;
2287 /* Return a pointer to a newly allocated location description. Location
2288 descriptions are simple expression terms that can be strung
2289 together to form more complicated location (address) descriptions. */
2290 inline dw_loc_descr_ref
2291 new_loc_descr (op
, oprnd1
, oprnd2
)
2292 register enum dwarf_location_atom op
;
2293 register unsigned long oprnd1
;
2294 register unsigned long oprnd2
;
2296 register dw_loc_descr_ref descr
=
2297 (dw_loc_descr_ref
) xmalloc (sizeof (dw_loc_descr_node
));
2300 descr
->dw_loc_next
= NULL
;
2301 descr
->dw_loc_opc
= op
;
2302 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
2303 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
2304 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
2305 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
2310 /* Add a location description term to a location description expression. */
2312 add_loc_descr (list_head
, descr
)
2313 register dw_loc_descr_ref
*list_head
;
2314 register dw_loc_descr_ref descr
;
2316 register dw_loc_descr_ref
*d
;
2317 /* find the end of the chain. */
2318 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
2325 /* Return a pointer to a newly allocated Call Frame Instruction. */
2329 register dw_cfi_ref cfi
= (dw_cfi_ref
) xmalloc (sizeof (dw_cfi_node
));
2332 cfi
->dw_cfi_next
= NULL
;
2333 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
2334 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
2339 /* Add a Call Frame Instruction to list of instructions. */
2341 add_cfi (list_head
, cfi
)
2342 register dw_cfi_ref
*list_head
;
2343 register dw_cfi_ref cfi
;
2345 register dw_cfi_ref
*p
;
2346 /* find the end of the chain. */
2347 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
2354 /********* Print DWARF Internal Representation (debugging aids) ***************/
2356 /* Keep track of the number of spaces used to indent the
2357 output of the debugging routines that print the structure of
2358 the DIE internal representation. */
2359 static int print_indent
;
2361 /* Indent the line the number of spaces given by print_indent. */
2363 print_spaces (outfile
)
2366 fprintf (outfile
, "%*s", print_indent
, "");
2369 /* Print the information assoaciated with a given DIE, and its children.
2370 This routine is a debugging aid only. */
2372 print_die (die
, outfile
)
2376 register dw_attr_ref a
;
2377 register dw_die_ref c
;
2378 print_spaces (outfile
);
2379 fprintf (outfile
, "DIE %4u: %s\n",
2380 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
2381 print_spaces (outfile
);
2382 fprintf (outfile
, " abbrev id: %u", die
->die_abbrev
);
2383 fprintf (outfile
, " offset: %u\n", die
->die_offset
);
2384 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
2386 print_spaces (outfile
);
2387 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
2388 switch (a
->dw_attr_val
.val_class
)
2390 case dw_val_class_addr
:
2391 fprintf (outfile
, "address");
2393 case dw_val_class_loc
:
2394 fprintf (outfile
, "location descriptor");
2396 case dw_val_class_const
:
2397 fprintf (outfile
, "%d", a
->dw_attr_val
.v
.val_int
);
2399 case dw_val_class_unsigned_const
:
2400 fprintf (outfile
, "%u", a
->dw_attr_val
.v
.val_unsigned
);
2402 case dw_val_class_double_const
:
2403 fprintf (outfile
, "constant (%u,%u)",
2404 a
->dw_attr_val
.v
.val_dbl_const
.dw_dbl_hi
,
2405 a
->dw_attr_val
.v
.val_dbl_const
.dw_dbl_low
);
2407 case dw_val_class_flag
:
2408 fprintf (outfile
, "%u", a
->dw_attr_val
.v
.val_flag
);
2410 case dw_val_class_die_ref
:
2411 if (a
->dw_attr_val
.v
.val_die_ref
!= NULL
)
2413 fprintf (outfile
, "die -> %u",
2414 a
->dw_attr_val
.v
.val_die_ref
->die_offset
);
2418 fprintf (outfile
, "die -> <null>");
2421 case dw_val_class_lbl_id
:
2422 fprintf (outfile
, "label: %s", a
->dw_attr_val
.v
.val_lbl_id
);
2424 case dw_val_class_section_offset
:
2425 fprintf (outfile
, "section: %s", a
->dw_attr_val
.v
.val_section
);
2427 case dw_val_class_str
:
2428 if (a
->dw_attr_val
.v
.val_str
!= NULL
)
2430 fprintf (outfile
, "\"%s\"", a
->dw_attr_val
.v
.val_str
);
2434 fprintf (outfile
, "<null>");
2438 fprintf (outfile
, "\n");
2440 if (die
->die_child
!= NULL
)
2443 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
2445 print_die (c
, outfile
);
2451 /* Print the contents of the source code line number correspondence table.
2452 This routine is a debugging aid only. */
2454 print_dwarf_line_table (outfile
)
2457 register unsigned i
;
2458 register dw_line_info_ref line_info
;
2459 fprintf (outfile
, "\n\nDWARF source line information\n");
2460 for (i
= 1; i
< line_info_table_in_use
; ++i
)
2462 line_info
= &line_info_table
[i
];
2463 fprintf (outfile
, "%5d: ", i
);
2464 fprintf (outfile
, "%-20s", file_table
[line_info
->dw_file_num
]);
2465 fprintf (outfile
, "%6d", line_info
->dw_line_num
);
2466 fprintf (outfile
, "\n");
2468 fprintf (outfile
, "\n\n");
2471 /* Print the information collected for a given DIE. */
2473 debug_dwarf_die (die
)
2476 print_die (die
, stderr
);
2479 /* Print all DWARF informaiton collected for the compilation unit.
2480 This routine is a debugging aid only. */
2485 print_die (comp_unit_die
, stderr
);
2486 print_dwarf_line_table (stderr
);
2490 /***************** DWARF Information Construction Support *********************/
2492 /* Traverse the DIE, and add a sibling attribute if it may have the
2493 effect of speeding up access to siblings. To save some space,
2494 avoid generating sibling attributes for DIE's without children. */
2496 add_sibling_attributes(die
)
2497 register dw_die_ref die
;
2499 register dw_die_ref c
;
2500 register dw_attr_ref attr
;
2501 if (die
!= comp_unit_die
&& die
->die_child
!= NULL
)
2503 attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
2506 attr
->dw_attr_next
= NULL
;
2507 attr
->dw_attr
= DW_AT_sibling
;
2508 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
2509 attr
->dw_attr_val
.v
.val_die_ref
= die
->die_sib
;
2511 /* add the sibling link to the front of the attribute list. */
2512 attr
->dw_attr_next
= die
->die_attr
;
2513 if (die
->die_attr
== NULL
)
2515 die
->die_attr_last
= attr
;
2517 die
->die_attr
= attr
;
2519 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
2521 add_sibling_attributes (c
);
2525 /* The format of each DIE (and its attribute value pairs)
2526 is encoded in an abbreviation table. This routine builds the
2527 abbreviation table and assigns a unique abbreviation id for
2528 each abbreviation entry. The children of each die are visited
2531 build_abbrev_table (die
)
2532 register dw_die_ref die
;
2534 register unsigned long abbrev_id
;
2535 register unsigned long n_alloc
;
2536 register dw_die_ref c
;
2537 register dw_attr_ref d_attr
, a_attr
;
2538 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
2540 register dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
2541 if (abbrev
->die_tag
== die
->die_tag
)
2543 if ((abbrev
->die_child
!= NULL
) == (die
->die_child
!= NULL
))
2545 a_attr
= abbrev
->die_attr
;
2546 d_attr
= die
->die_attr
;
2547 while (a_attr
!= NULL
&& d_attr
!= NULL
)
2549 if ((a_attr
->dw_attr
!= d_attr
->dw_attr
)
2550 || (a_attr
->dw_attr_val
.val_class
2551 != d_attr
->dw_attr_val
.val_class
))
2555 a_attr
= a_attr
->dw_attr_next
;
2556 d_attr
= d_attr
->dw_attr_next
;
2558 if (a_attr
== NULL
&& d_attr
== NULL
)
2565 if (abbrev_id
>= abbrev_die_table_in_use
)
2567 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
2569 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
2570 abbrev_die_table
= (dw_die_ref
*)
2571 xmalloc (abbrev_die_table
,
2572 sizeof (dw_die_ref
) * n_alloc
);
2573 bzero (&abbrev_die_table
[abbrev_die_table_allocated
],
2574 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
2575 abbrev_die_table_allocated
= n_alloc
;
2577 ++abbrev_die_table_in_use
;
2578 abbrev_die_table
[abbrev_id
] = die
;
2580 die
->die_abbrev
= abbrev_id
;
2581 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
2583 build_abbrev_table (c
);
2588 /********************** DWARF Information Sizing *****************************/
2590 /* Return the size of an unsigned LEB128 quantity. */
2591 inline unsigned long
2592 size_of_uleb128 (value
)
2593 register unsigned long value
;
2595 register unsigned long size
= 0;
2596 register unsigned byte
;
2599 byte
= (value
& 0x7f);
2607 /* Return the size of a signed LEB128 quantity. */
2608 inline unsigned long
2609 size_of_sleb128 (value
)
2610 register long value
;
2612 register unsigned long size
= 0;
2613 register unsigned byte
;
2616 byte
= (value
& 0x7f);
2620 while (!(((value
== 0) && ((byte
& 0x40) == 0))
2621 || ((value
== -1) && ((byte
& 0x40) != 0))));
2625 /* Return the size of a string, including the null byte. */
2626 static unsigned long
2627 size_of_string (str
)
2630 register unsigned long size
= 0;
2631 register unsigned long slen
= strlen (str
);
2632 register unsigned long i
;
2633 register unsigned c
;
2634 for (i
= 0; i
< slen
; ++i
)
2643 /* Null terminator. */
2648 /* Return the size of a location descriptor. */
2649 static unsigned long
2650 size_of_loc_descr (loc
)
2651 register dw_loc_descr_ref loc
;
2653 register unsigned long size
= 1;
2654 switch (loc
->dw_loc_opc
)
2676 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2679 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2684 case DW_OP_plus_uconst
:
2685 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2723 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2726 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2729 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2732 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2733 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
2736 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2738 case DW_OP_deref_size
:
2739 case DW_OP_xderef_size
:
2748 /* Return the size of a DIE, as it is represented in the
2749 .debug_info section. */
2750 static unsigned long
2752 register dw_die_ref die
;
2754 register unsigned long size
= 0;
2755 register dw_attr_ref a
;
2756 register dw_loc_descr_ref loc
;
2757 size
+= size_of_uleb128 (die
->die_abbrev
);
2758 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
2760 switch (a
->dw_attr_val
.val_class
)
2762 case dw_val_class_addr
:
2765 case dw_val_class_loc
:
2768 for (loc
= a
->dw_attr_val
.v
.val_loc
; loc
!= NULL
;
2769 loc
= loc
->dw_loc_next
)
2771 size
+= size_of_loc_descr (loc
);
2774 case dw_val_class_const
:
2777 case dw_val_class_unsigned_const
:
2780 case dw_val_class_double_const
:
2783 case dw_val_class_flag
:
2786 case dw_val_class_die_ref
:
2789 case dw_val_class_fde_ref
:
2792 case dw_val_class_lbl_id
:
2795 case dw_val_class_section_offset
:
2798 case dw_val_class_str
:
2799 size
+= size_of_string (a
->dw_attr_val
.v
.val_str
);
2808 /* Size the debgging information associted with a given DIE.
2809 Visits the DIE's children recursively. Updates the global
2810 variable next_die_offset, on each time through. Uses the
2811 current value of next_die_offset to updete the die_offset
2812 field in each DIE. */
2814 calc_die_sizes (die
)
2817 register dw_die_ref c
;
2818 register unsigned long die_size
;
2819 die
->die_offset
= next_die_offset
;
2820 next_die_offset
+= size_of_die (die
);
2821 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
2825 if (die
->die_child
!= NULL
)
2827 /* Count the null byte used to terminate sibling lists. */
2828 next_die_offset
+= 1;
2832 /* Return the size of the line information prolog generated for the
2833 compilation unit. */
2834 static unsigned long
2835 size_of_line_prolog ()
2837 register unsigned long size
;
2838 register unsigned opc
;
2839 register unsigned n_op_args
;
2840 register unsigned long ft_index
;
2841 size
= DWARF_LINE_PROLOG_HEADER_SIZE
;
2842 /* Count the size of the table giving number of args for each
2844 size
+= DWARF_LINE_OPCODE_BASE
- 1;
2845 /* Include directory table is empty (at present). Count only the
2846 the null byte used to terminate the table. */
2848 for (ft_index
= 1; ft_index
< file_table_in_use
; ++ft_index
)
2850 /* File name entry. */
2851 size
+= size_of_string (file_table
[ft_index
]);
2852 /* Include directory index. */
2853 size
+= size_of_uleb128 (0);
2854 /* Modification time. */
2855 size
+= size_of_uleb128 (0);
2856 /* File length in bytes. */
2857 size
+= size_of_uleb128 (0);
2859 /* Count the file table terminator. */
2864 /* Return the size of the line information generated for this
2865 compilation unit. */
2866 static unsigned long
2867 size_of_line_info ()
2869 register unsigned long size
;
2870 register dw_line_info_ref line_info
;
2871 register unsigned long lt_index
;
2872 register unsigned long current_line
;
2873 register long line_offset
;
2874 register long line_delta
;
2875 register unsigned long current_file
;
2876 /* Version number. */
2878 /* Prolog length specifier. */
2881 size
+= size_of_line_prolog ();
2882 /* Set address register instruction. */
2883 size
+= 1 + size_of_uleb128 (1 + PTR_SIZE
)
2887 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
2889 /* Advance pc instruction. */
2891 line_info
= &line_info_table
[lt_index
];
2892 if (line_info
->dw_file_num
!= current_file
)
2894 /* Set file number instruction. */
2896 current_file
= line_info
->dw_file_num
;
2897 size
+= size_of_uleb128 (current_file
);
2899 if (line_info
->dw_line_num
!= current_line
)
2901 line_offset
= line_info
->dw_line_num
- current_line
;
2902 line_delta
= line_offset
- DWARF_LINE_BASE
;
2903 current_line
= line_info
->dw_line_num
;
2904 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
2906 /* 1-byte special line number instruction. */
2911 /* Advance line instruction. */
2913 size
+= size_of_sleb128 (line_offset
);
2914 /* Generate line entry instruction. */
2919 /* Set address register instruction. */
2920 size
+= 1 + size_of_uleb128 (1 + PTR_SIZE
)
2922 /* End of line number info. marker. */
2923 size
+= 1 + size_of_uleb128 (1) + 1;
2927 /* Return the size of the .debug_pubnames table generated for the
2928 compilation unit. */
2929 static unsigned long
2933 register unsigned long size
;
2934 size
= DWARF_PUBNAMES_HEADER_SIZE
;
2935 for (die
= comp_unit_die
->die_child
; die
!= NULL
; die
= die
->die_sib
)
2937 if (is_extern_subr_die (die
))
2939 char *low_pc
= get_AT_low_pc (die
);
2943 size
+= size_of_string (low_pc
);
2951 /* Return the size of the information in the .debug_aranges seciton. */
2952 static unsigned long
2955 register unsigned long size
;
2956 size
= DWARF_ARANGES_HEADER_SIZE
;
2957 /* Count the address/length pair for this compilation unit. */
2959 /* Count the two zero words used to terminated the address range table. */
2964 /**************** DWARF Debug Information Output *****************************/
2966 /* Output an unsigned LEB128 quantity. */
2968 output_uleb128 (value
)
2969 register unsigned long value
;
2971 fprintf (asm_out_file
, "\t%s\t", ASM_BYTE_OP
);
2974 register unsigned byte
= (value
& 0x7f);
2978 /* More bytes to follow. */
2981 fprintf (asm_out_file
, "0x%x", byte
);
2984 fprintf (asm_out_file
, ",");
2990 /* Output an signed LEB128 quantity. */
2992 output_sleb128 (value
)
2993 register long value
;
2996 register unsigned byte
;
2997 fprintf (asm_out_file
, "\t%s\t", ASM_BYTE_OP
);
3000 byte
= (value
& 0x7f);
3001 /* arithmetic shift */
3003 more
= !((((value
== 0) && ((byte
& 0x40) == 0))
3004 || ((value
== -1) && ((byte
& 0x40) != 0))));
3009 fprintf (asm_out_file
, "0x%x", byte
);
3012 fprintf (asm_out_file
, ",");
3018 /* Output the encoding of an attribute value. */
3020 output_value_format (v
)
3023 enum dwarf_form form
;
3024 switch (v
->val_class
)
3026 case dw_val_class_addr
:
3027 form
= DW_FORM_addr
;
3029 case dw_val_class_loc
:
3030 form
= DW_FORM_block2
;
3032 case dw_val_class_const
:
3033 form
= DW_FORM_data4
;
3035 case dw_val_class_unsigned_const
:
3036 form
= DW_FORM_data4
;
3038 case dw_val_class_double_const
:
3039 form
= DW_FORM_data8
;
3041 case dw_val_class_flag
:
3042 form
= DW_FORM_flag
;
3044 case dw_val_class_die_ref
:
3045 form
= DW_FORM_ref4
;
3047 case dw_val_class_fde_ref
:
3048 form
= DW_FORM_data4
;
3050 case dw_val_class_lbl_id
:
3051 form
= DW_FORM_addr
;
3053 case dw_val_class_section_offset
:
3054 form
= DW_FORM_data4
;
3056 case dw_val_class_str
:
3057 form
= DW_FORM_string
;
3062 output_uleb128 (form
);
3063 if (flag_verbose_asm
)
3065 fprintf (asm_out_file
, "\t%s %s",
3066 ASM_COMMENT_START
, dwarf_form_name (form
));
3068 fputc ('\n', asm_out_file
);
3071 /* Output the .debug_abbrev section which defines the DIE abbreviation
3074 output_abbrev_section ()
3076 unsigned long abbrev_id
;
3078 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
3080 register dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
3081 output_uleb128 (abbrev_id
);
3082 if (flag_verbose_asm
)
3084 fprintf (asm_out_file
, "\t%s abbrev code = %u",
3085 ASM_COMMENT_START
, abbrev_id
);
3087 fputc ('\n', asm_out_file
);
3088 output_uleb128 (abbrev
->die_tag
);
3089 if (flag_verbose_asm
)
3091 fprintf (asm_out_file
, "\t%s TAG: %s",
3092 ASM_COMMENT_START
, dwarf_tag_name (abbrev
->die_tag
));
3094 fputc ('\n', asm_out_file
);
3095 fprintf (asm_out_file
, "\t%s\t0x%x", ASM_BYTE_OP
,
3096 (abbrev
->die_child
!= NULL
)
3097 ? DW_children_yes
: DW_children_no
);
3098 if (flag_verbose_asm
)
3100 fprintf (asm_out_file
, "\t%s %s",
3102 (abbrev
->die_child
!= NULL
)
3103 ? "DW_children_yes" : "DW_children_no");
3105 fputc ('\n', asm_out_file
);
3106 for (a_attr
= abbrev
->die_attr
; a_attr
!= NULL
;
3107 a_attr
= a_attr
->dw_attr_next
)
3109 output_uleb128 (a_attr
->dw_attr
);
3110 if (flag_verbose_asm
)
3112 fprintf (asm_out_file
, "\t%s %s",
3114 dwarf_attr_name (a_attr
->dw_attr
));
3116 fputc ('\n', asm_out_file
);
3117 output_value_format (&a_attr
->dw_attr_val
);
3119 fprintf (asm_out_file
, "\t%s\t0,0\n", ASM_BYTE_OP
);
3123 /* Output location description stack opcode's operands (if any). */
3125 output_loc_operands (loc
)
3126 register dw_loc_descr_ref loc
;
3128 register dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
3129 register dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
3130 switch (loc
->dw_loc_opc
)
3133 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file
, val1
->v
.val_addr
);
3134 fputc ('\n', asm_out_file
);
3138 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, val1
->v
.val_flag
);
3139 fputc ('\n', asm_out_file
);
3143 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, val1
->v
.val_int
);
3144 fputc ('\n', asm_out_file
);
3148 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, val1
->v
.val_int
);
3149 fputc ('\n', asm_out_file
);
3153 ASM_OUTPUT_DWARF_DATA8 (asm_out_file
,
3154 val1
->v
.val_dbl_const
.dw_dbl_hi
,
3155 val2
->v
.val_dbl_const
.dw_dbl_low
);
3156 fputc ('\n', asm_out_file
);
3159 output_uleb128 (val1
->v
.val_unsigned
);
3160 fputc ('\n', asm_out_file
);
3163 output_sleb128 (val1
->v
.val_unsigned
);
3164 fputc ('\n', asm_out_file
);
3167 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, val1
->v
.val_int
);
3168 fputc ('\n', asm_out_file
);
3170 case DW_OP_plus_uconst
:
3171 output_uleb128 (val1
->v
.val_unsigned
);
3172 fputc ('\n', asm_out_file
);
3176 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, val1
->v
.val_int
);
3177 fputc ('\n', asm_out_file
);
3211 output_sleb128 (val1
->v
.val_int
);
3212 fputc ('\n', asm_out_file
);
3215 output_uleb128 (val1
->v
.val_unsigned
);
3216 fputc ('\n', asm_out_file
);
3219 output_sleb128 (val1
->v
.val_unsigned
);
3220 fputc ('\n', asm_out_file
);
3223 output_uleb128 (val1
->v
.val_unsigned
);
3224 fputc ('\n', asm_out_file
);
3225 output_sleb128 (val2
->v
.val_unsigned
);
3226 fputc ('\n', asm_out_file
);
3229 output_uleb128 (val1
->v
.val_unsigned
);
3230 fputc ('\n', asm_out_file
);
3232 case DW_OP_deref_size
:
3233 case DW_OP_xderef_size
:
3234 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, val1
->v
.val_flag
);
3235 fputc ('\n', asm_out_file
);
3242 /* Compute the offset of a sibling. */
3243 static unsigned long
3244 sibling_offset (die
)
3247 unsigned long offset
;
3248 if (die
->die_child_last
== NULL
)
3250 offset
= die
->die_offset
+ size_of_die (die
);
3254 offset
= sibling_offset (die
->die_child_last
) + 1;
3259 /* Output the DIE and its attributes. Called recursively to generate
3260 the definitions of each child DIE. */
3263 register dw_die_ref die
;
3265 register dw_attr_ref a
;
3266 register dw_die_ref c
;
3267 register unsigned long ref_offset
;
3268 register unsigned long size
;
3269 register dw_loc_descr_ref loc
;
3270 output_uleb128 (die
->die_abbrev
);
3271 if (flag_verbose_asm
)
3273 fprintf (asm_out_file
, "\t%s DIE (0x%x) %s",
3276 dwarf_tag_name (die
->die_tag
));
3278 fputc ('\n', asm_out_file
);
3279 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
3281 switch (a
->dw_attr_val
.val_class
)
3283 case dw_val_class_addr
:
3284 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file
,
3285 a
->dw_attr_val
.v
.val_addr
);
3287 case dw_val_class_loc
:
3289 for (loc
= a
->dw_attr_val
.v
.val_loc
; loc
!= NULL
;
3290 loc
= loc
->dw_loc_next
)
3292 size
+= size_of_loc_descr (loc
);
3294 /* Output the block length for this list of location operations. */
3295 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, size
);
3296 if (flag_verbose_asm
)
3298 fprintf (asm_out_file
, "\t%s %s",
3299 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
3301 fputc ('\n', asm_out_file
);
3302 for (loc
= a
->dw_attr_val
.v
.val_loc
; loc
!= NULL
;
3303 loc
= loc
->dw_loc_next
)
3305 /* Output the opcode. */
3306 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, loc
->dw_loc_opc
);
3307 if (flag_verbose_asm
)
3309 fprintf (asm_out_file
, "\t%s %s",
3311 dwarf_stack_op_name (loc
->dw_loc_opc
));
3313 fputc ('\n', asm_out_file
);
3314 /* Output the operand(s) (if any). */
3315 output_loc_operands (loc
);
3318 case dw_val_class_const
:
3319 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, a
->dw_attr_val
.v
.val_int
);
3321 case dw_val_class_unsigned_const
:
3322 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, a
->dw_attr_val
.v
.val_unsigned
);
3324 case dw_val_class_double_const
:
3325 ASM_OUTPUT_DWARF_DATA8 (asm_out_file
,
3326 a
->dw_attr_val
.v
.val_dbl_const
.dw_dbl_hi
,
3327 a
->dw_attr_val
.v
.val_dbl_const
.dw_dbl_low
);
3329 case dw_val_class_flag
:
3330 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, a
->dw_attr_val
.v
.val_flag
);
3332 case dw_val_class_die_ref
:
3333 if (a
->dw_attr_val
.v
.val_die_ref
!= NULL
)
3335 ref_offset
= a
->dw_attr_val
.v
.val_die_ref
->die_offset
;
3337 else if (a
->dw_attr
== DW_AT_sibling
)
3339 ref_offset
= sibling_offset(die
);
3345 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, ref_offset
);
3347 case dw_val_class_fde_ref
:
3348 ref_offset
= fde_table
[a
->dw_attr_val
.v
.val_fde_index
].dw_fde_offset
;
3349 fprintf (asm_out_file
, "\t%s\t%s+0x%x", UNALIGNED_INT_ASM_OP
,
3350 stripattributes (FRAME_SECTION
), ref_offset
);
3352 case dw_val_class_lbl_id
:
3353 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, a
->dw_attr_val
.v
.val_lbl_id
);
3355 case dw_val_class_section_offset
:
3356 ASM_OUTPUT_DWARF_ADDR (asm_out_file
,
3357 stripattributes (a
->dw_attr_val
.v
.val_section
));
3359 case dw_val_class_str
:
3360 ASM_OUTPUT_DWARF_STRING (asm_out_file
, a
->dw_attr_val
.v
.val_str
);
3365 if (a
->dw_attr_val
.val_class
!= dw_val_class_loc
)
3367 if (flag_verbose_asm
)
3369 fprintf (asm_out_file
, "\t%s %s",
3370 ASM_COMMENT_START
, dwarf_attr_name (a
->dw_attr
));
3372 fputc ('\n', asm_out_file
);
3375 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
3379 if (die
->die_child
!= NULL
)
3381 /* Add null byte to terminate sibling list. */
3382 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
3383 fputc ('\n', asm_out_file
);
3387 /* Output the compilation unit that appears at the beginning of the
3388 .debug_info section, and precedes the DIE descriptions. */
3390 output_compilation_unit_header ()
3392 /* ??? The dwarf standard says this must be a 4 byte integer, but the
3393 SGI dwarf reader assumes this is the same size as a pointer. */
3394 fprintf (asm_out_file
, "\t%s\t0x%x",
3395 UNALIGNED_INT_ASM_OP
, next_die_offset
- 4);
3396 if (flag_verbose_asm
)
3398 fprintf (asm_out_file
, "\t%s Length of Compilation Unit Info.",
3401 fputc ('\n', asm_out_file
);
3402 fprintf (asm_out_file
, "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP
, DWARF_VERSION
);
3403 if (flag_verbose_asm
)
3405 fprintf (asm_out_file
, "\t%s DWARF version number",
3408 fputc ('\n', asm_out_file
);
3409 fprintf (asm_out_file
, "\t%s\t%s", UNALIGNED_INT_ASM_OP
,
3410 stripattributes (ABBREV_SECTION
));
3411 if (flag_verbose_asm
)
3413 fprintf (asm_out_file
, "\t%s Offset Into Abbrev. Section",
3416 fputc ('\n', asm_out_file
);
3417 fprintf (asm_out_file
, "\t%s\t0x%x", ASM_BYTE_OP
, PTR_SIZE
);
3418 if (flag_verbose_asm
)
3420 fprintf (asm_out_file
, "\t%s Pointer Size (in bytes)",
3423 fputc ('\n', asm_out_file
);
3426 /* Return the size of a Call Frame Instruction. */
3427 static unsigned long
3431 register unsigned long size
;
3432 /* count the 1-byte opcode */
3434 switch (cfi
->dw_cfi_opc
)
3437 size
+= size_of_uleb128(cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3439 case DW_CFA_set_loc
:
3442 case DW_CFA_advance_loc1
:
3445 case DW_CFA_advance_loc2
:
3448 case DW_CFA_advance_loc4
:
3451 #ifdef MIPS_DEBUGGING_INFO
3452 case DW_CFA_MIPS_advance_loc8
:
3456 case DW_CFA_offset_extended
:
3457 case DW_CFA_def_cfa
:
3458 size
+= size_of_uleb128(cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
3459 size
+= size_of_uleb128(cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3461 case DW_CFA_restore_extended
:
3462 case DW_CFA_undefined
:
3463 size
+= size_of_uleb128(cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
3465 case DW_CFA_same_value
:
3466 case DW_CFA_def_cfa_register
:
3467 size
+= size_of_uleb128(cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
3469 case DW_CFA_register
:
3470 size
+= size_of_uleb128(cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
3471 size
+= size_of_uleb128(cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
);
3473 case DW_CFA_def_cfa_offset
:
3474 size
+= size_of_uleb128(cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3482 /* Return the size of an FDE sans the length word. */
3483 inline unsigned long
3484 size_of_fde (fde
, npad
)
3486 unsigned long *npad
;
3488 register dw_cfi_ref cfi
;
3489 register unsigned long aligned_size
;
3490 register unsigned long size
;
3491 size
= DWARF_FDE_HEADER_SIZE
;
3492 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
3494 size
+= size_of_cfi(cfi
);
3496 /* Round the size up to an 8 byte boundary. */
3497 aligned_size
= (size
+ 7) & ~7;
3498 *npad
= aligned_size
- size
;
3499 return aligned_size
;
3502 /* Calculate the size of the FDE table, and establish the offset
3503 of each FDE in the .debug_frame section. */
3507 register unsigned long i
;
3508 register dw_fde_ref fde
;
3509 register unsigned long fde_size
;
3510 unsigned long fde_pad
;
3511 for (i
= 0; i
< fde_table_in_use
; ++i
)
3513 fde
= &fde_table
[i
];
3514 fde
->dw_fde_offset
= next_fde_offset
;
3515 fde_size
= size_of_fde (fde
, &fde_pad
);
3516 next_fde_offset
+= fde_size
;
3520 /* Output a Call Frame Information opcode and its operand(s). */
3522 output_cfi (cfi
, fde
)
3523 register dw_cfi_ref cfi
;
3524 register dw_fde_ref fde
;
3526 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
3528 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
3530 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f));
3531 if (flag_verbose_asm
)
3533 fprintf (asm_out_file
, "\t%s DW_CFA_advance_loc", ASM_COMMENT_START
);
3535 fputc ('\n', asm_out_file
);
3537 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
3539 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
3541 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f));
3542 if (flag_verbose_asm
)
3544 fprintf (asm_out_file
, "\t%s DW_CFA_offset", ASM_COMMENT_START
);
3546 fputc ('\n', asm_out_file
);
3547 output_uleb128(cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3548 fputc ('\n', asm_out_file
);
3550 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
3552 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
3554 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f));
3555 if (flag_verbose_asm
)
3557 fprintf (asm_out_file
, "\t%s DW_CFA_restore", ASM_COMMENT_START
);
3559 fputc ('\n', asm_out_file
);
3563 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, cfi
->dw_cfi_opc
);
3564 if (flag_verbose_asm
)
3566 fprintf (asm_out_file
, "\t%s %s",
3568 dwarf_cfi_name (cfi
->dw_cfi_opc
));
3570 fputc ('\n', asm_out_file
);
3571 switch (cfi
->dw_cfi_opc
)
3573 case DW_CFA_set_loc
:
3574 ASM_OUTPUT_DWARF_ADDR (asm_out_file
,
3575 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
);
3576 fputc ('\n', asm_out_file
);
3578 case DW_CFA_advance_loc1
:
3579 /* TODO: not currently implemented. */
3582 case DW_CFA_advance_loc2
:
3583 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
,
3584 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3586 fputc ('\n', asm_out_file
);
3588 case DW_CFA_advance_loc4
:
3589 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file
,
3590 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3592 fputc ('\n', asm_out_file
);
3594 #ifdef MIPS_DEBUGGING_INFO
3595 case DW_CFA_MIPS_advance_loc8
:
3596 /* TODO: not currently implemented. */
3600 case DW_CFA_offset_extended
:
3601 case DW_CFA_def_cfa
:
3602 output_uleb128(cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
3603 fputc ('\n', asm_out_file
);
3604 output_uleb128(cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3605 fputc ('\n', asm_out_file
);
3607 case DW_CFA_restore_extended
:
3608 case DW_CFA_undefined
:
3609 output_uleb128(cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
3610 fputc ('\n', asm_out_file
);
3612 case DW_CFA_same_value
:
3613 case DW_CFA_def_cfa_register
:
3614 output_uleb128(cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
3615 fputc ('\n', asm_out_file
);
3617 case DW_CFA_register
:
3618 output_uleb128(cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
3619 fputc ('\n', asm_out_file
);
3620 output_uleb128(cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
);
3621 fputc ('\n', asm_out_file
);
3623 case DW_CFA_def_cfa_offset
:
3624 output_uleb128(cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3625 fputc ('\n', asm_out_file
);
3633 /* Output the call frame information used to used to record information
3634 that relates to calculating the frame pointer, and records the
3635 location of saved registers. */
3637 output_call_frame_info ()
3639 register unsigned long i
, j
;
3640 register dw_fde_ref fde
;
3641 register unsigned long fde_size
;
3642 dw_cfi_node cfi_node
;
3643 register dw_cfi_ref cfi
;
3644 unsigned long fde_pad
;
3646 /* Output the CIE. */
3647 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, DWARF_CIE_SIZE
- 4);
3648 if (flag_verbose_asm
)
3650 fprintf (asm_out_file
, "\t%s Length of Common Information Entry",
3653 fputc ('\n', asm_out_file
);
3654 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, DW_CIE_ID
);
3655 if (flag_verbose_asm
)
3657 fprintf (asm_out_file
, "\t%s CIE Identifier Tag",
3660 fputc ('\n', asm_out_file
);
3661 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_CIE_VERSION
);
3662 if (flag_verbose_asm
)
3664 fprintf (asm_out_file
, "\t%s CIE Version",
3667 fputc ('\n', asm_out_file
);
3668 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
3669 if (flag_verbose_asm
)
3671 fprintf (asm_out_file
, "\t%s CIE Augmentation (none)",
3674 fputc ('\n', asm_out_file
);
3676 if (flag_verbose_asm
)
3678 fprintf (asm_out_file
, "\t%s CIE Code Alignment Factor",
3681 fputc ('\n', asm_out_file
);
3682 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT
);
3683 if (flag_verbose_asm
)
3685 fprintf (asm_out_file
, "\t%s CIE Data Alignment Factor",
3688 fputc ('\n', asm_out_file
);
3689 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_FRAME_RA_COL
);
3690 if (flag_verbose_asm
)
3692 fprintf (asm_out_file
, "\t%s CIE RA Column",
3695 fputc ('\n', asm_out_file
);
3697 /* Output the CFA instructions common to all FDE's. */
3699 #ifdef MIPS_DEBUGGING_INFO
3701 /* Set the RA on entry to be the contents of r31. */
3702 bzero (&cfi_node
, sizeof (dw_cfi_node
));
3704 cfi
->dw_cfi_opc
= DW_CFA_register
;
3705 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= DW_FRAME_RA_COL
;
3706 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= DW_FRAME_REG31
;
3711 /* Pad the CIE out to an address sized boundary. */
3712 for (i
= DWARF_CIE_HEADER_SIZE
; i
< DWARF_CIE_SIZE
; ++i
)
3714 /* Pad out to a pointer size boundary */
3715 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_CFA_nop
);
3716 if (flag_verbose_asm
)
3718 fprintf (asm_out_file
, "\t%s CIE DW_CFA_nop (pad)",
3721 fputc ('\n', asm_out_file
);
3724 /* Loop through all of the FDE's. */
3725 for (i
= 0; i
< fde_table_in_use
; ++i
)
3727 fde
= &fde_table
[i
];
3728 fde_size
= size_of_fde (fde
, &fde_pad
);
3729 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, fde_size
- 4);
3730 if (flag_verbose_asm
)
3732 fprintf (asm_out_file
, "\t%s FDE Length",
3735 fputc ('\n', asm_out_file
);
3736 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, stripattributes (FRAME_SECTION
));
3737 if (flag_verbose_asm
)
3739 fprintf (asm_out_file
, "\t%s FDE CIE offset",
3742 fputc ('\n', asm_out_file
);
3743 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, fde
->dw_fde_begin
);
3744 if (flag_verbose_asm
)
3746 fprintf (asm_out_file
, "\t%s FDE initial location",
3749 fputc ('\n', asm_out_file
);
3750 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file
,
3751 fde
->dw_fde_end
, fde
->dw_fde_begin
);
3752 if (flag_verbose_asm
)
3754 fprintf (asm_out_file
, "\t%s FDE address range",
3757 fputc ('\n', asm_out_file
);
3759 /* Loop through the Call Frame Instructions associated with
3761 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
3763 output_cfi (cfi
, fde
);
3766 /* Pad to a double word boundary. */
3767 for (j
= 0; j
< fde_pad
; ++j
)
3769 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_CFA_nop
);
3770 if (flag_verbose_asm
)
3772 fprintf (asm_out_file
, "\t%s CIE DW_CFA_nop (pad)",
3775 fputc ('\n', asm_out_file
);
3780 /* Output the public names table used to speed up access to externally
3781 visible names. For now, only generate entries for externally
3782 visible procedures. */
3787 register unsigned long pubnames_length
= size_of_pubnames ();
3788 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, pubnames_length
);
3789 if (flag_verbose_asm
)
3791 fprintf (asm_out_file
, "\t%s Length of Public Names Info.",
3794 fputc ('\n', asm_out_file
);
3795 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
3796 if (flag_verbose_asm
)
3798 fprintf (asm_out_file
, "\t%s DWARF Version",
3801 fputc ('\n', asm_out_file
);
3802 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, stripattributes (DEBUG_SECTION
));
3803 if (flag_verbose_asm
)
3805 fprintf (asm_out_file
, "\t%s Offset of Compilation Unit Info.",
3808 fputc ('\n', asm_out_file
);
3809 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, next_die_offset
);
3810 if (flag_verbose_asm
)
3812 fprintf (asm_out_file
, "\t%s Compilation Unit Length",
3815 fputc ('\n', asm_out_file
);
3816 for (die
= comp_unit_die
->die_child
; die
!= NULL
; die
= die
->die_sib
)
3818 if (is_extern_subr_die (die
))
3820 char *low_pc
= get_AT_low_pc (die
);
3823 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, die
->die_offset
);
3824 if (flag_verbose_asm
)
3826 fprintf (asm_out_file
, "\t%s DIE offset",
3829 fputc ('\n', asm_out_file
);
3830 ASM_OUTPUT_DWARF_STRING (asm_out_file
, low_pc
);
3831 if (flag_verbose_asm
)
3833 fprintf (asm_out_file
, "%s external name",
3836 fputc ('\n', asm_out_file
);
3840 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, 0);
3841 fputc ('\n', asm_out_file
);
3844 /* Output the information that goes into the .debug_aranges table.
3845 Namely, define the beginning and ending address range of the
3846 text section generated for this compilation unit. */
3851 register unsigned long aranges_length
= size_of_aranges ();
3852 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, aranges_length
);
3853 if (flag_verbose_asm
)
3855 fprintf (asm_out_file
, "\t%s Length of Address Ranges Info.",
3858 fputc ('\n', asm_out_file
);
3859 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
3860 if (flag_verbose_asm
)
3862 fprintf (asm_out_file
, "\t%s DWARF Version",
3865 fputc ('\n', asm_out_file
);
3866 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, stripattributes (DEBUG_SECTION
));
3867 if (flag_verbose_asm
)
3869 fprintf (asm_out_file
, "\t%s Offset of Compilation Unit Info.",
3872 fputc ('\n', asm_out_file
);
3873 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, PTR_SIZE
);
3874 if (flag_verbose_asm
)
3876 fprintf (asm_out_file
, "\t%s Size of Address",
3879 fputc ('\n', asm_out_file
);
3880 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
3881 if (flag_verbose_asm
)
3883 fprintf (asm_out_file
, "\t%s Size of Segment Descriptor",
3886 fputc ('\n', asm_out_file
);
3887 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, 4);
3888 if (flag_verbose_asm
)
3890 fprintf (asm_out_file
, "\t%s Pad to 8 byte boundary",
3893 fputc ('\n', asm_out_file
);
3894 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, TEXT_BEGIN_LABEL
);
3895 if (flag_verbose_asm
)
3897 fprintf (asm_out_file
, "\t%s Address", ASM_COMMENT_START
);
3899 fputc ('\n', asm_out_file
);
3900 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file
, TEXT_END_LABEL
, TEXT_BEGIN_LABEL
);
3901 if (flag_verbose_asm
)
3903 fprintf (asm_out_file
, "%s Length", ASM_COMMENT_START
);
3905 fputc ('\n', asm_out_file
);
3906 /* Output the terminator words. */
3907 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, 0);
3908 fputc ('\n', asm_out_file
);
3909 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, 0);
3910 fputc ('\n', asm_out_file
);
3913 /* Output the source line number correspondence information. This
3914 information goes into the .debug_line section. */
3918 register unsigned long line_info_len
;
3919 register unsigned long line_info_prolog_len
;
3920 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3921 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3922 register unsigned opc
;
3923 register unsigned n_op_args
;
3924 register dw_line_info_ref line_info
;
3925 register unsigned long ft_index
;
3926 register unsigned long lt_index
;
3927 register unsigned long current_line
;
3928 register long line_offset
;
3929 register long line_delta
;
3930 register unsigned long current_file
;
3931 line_info_len
= size_of_line_info ();
3932 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, line_info_len
);
3933 if (flag_verbose_asm
)
3935 fprintf (asm_out_file
, "\t%s Length of Source Line Info.",
3938 fputc ('\n', asm_out_file
);
3939 ASM_OUTPUT_DWARF_DATA2 (asm_out_file
, DWARF_VERSION
);
3940 if (flag_verbose_asm
)
3942 fprintf (asm_out_file
, "\t%s DWARF Version",
3945 fputc ('\n', asm_out_file
);
3946 line_info_prolog_len
= size_of_line_prolog ();
3947 ASM_OUTPUT_DWARF_DATA4 (asm_out_file
, line_info_prolog_len
);
3948 if (flag_verbose_asm
)
3950 fprintf (asm_out_file
, "\t%s Prolog Length",
3953 fputc ('\n', asm_out_file
);
3954 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF_LINE_MIN_INSTR_LENGTH
);
3955 if (flag_verbose_asm
)
3957 fprintf (asm_out_file
, "\t%s Minimum Instruction Length",
3960 fputc ('\n', asm_out_file
);
3961 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DWARF_LINE_DEFAULT_IS_STMT_START
);
3962 if (flag_verbose_asm
)
3964 fprintf (asm_out_file
, "\t%s Default is_stmt_start flag",
3967 fputc ('\n', asm_out_file
);
3968 fprintf (asm_out_file
, "\t%s\t%d", ASM_BYTE_OP
, DWARF_LINE_BASE
);
3969 if (flag_verbose_asm
)
3971 fprintf (asm_out_file
, "\t%s Line Base Value (Special Opcodes)",
3974 fputc ('\n', asm_out_file
);
3975 fprintf (asm_out_file
, "\t%s\t%u", ASM_BYTE_OP
, DWARF_LINE_RANGE
);
3976 if (flag_verbose_asm
)
3978 fprintf (asm_out_file
, "\t%s Line Range Value (Special Opcodes)",
3981 fputc ('\n', asm_out_file
);
3982 fprintf (asm_out_file
, "\t%s\t%u", ASM_BYTE_OP
, DWARF_LINE_OPCODE_BASE
);
3983 if (flag_verbose_asm
)
3985 fprintf (asm_out_file
, "\t%s Special Opcode Base",
3988 fputc ('\n', asm_out_file
);
3989 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; ++opc
)
3993 case DW_LNS_advance_pc
:
3994 case DW_LNS_advance_line
:
3995 case DW_LNS_set_file
:
3996 case DW_LNS_set_column
:
3997 case DW_LNS_fixed_advance_pc
:
4004 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, n_op_args
);
4005 if (flag_verbose_asm
)
4007 fprintf (asm_out_file
, "\t%s opcode: 0x%x has %d args",
4008 ASM_COMMENT_START
, opc
, n_op_args
);
4010 fputc ('\n', asm_out_file
);
4012 if (flag_verbose_asm
)
4014 fprintf (asm_out_file
, "%s Include Directory Table\n",
4017 /* Include directory table is empty, at present */
4018 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
4019 fputc ('\n', asm_out_file
);
4020 if (flag_verbose_asm
)
4022 fprintf (asm_out_file
, "%s File Name Table\n", ASM_COMMENT_START
);
4024 for (ft_index
= 1; ft_index
< file_table_in_use
; ++ft_index
)
4026 ASM_OUTPUT_DWARF_STRING (asm_out_file
, file_table
[ft_index
]);
4027 if (flag_verbose_asm
)
4029 fprintf (asm_out_file
, "%s File Entry: 0x%x",
4030 ASM_COMMENT_START
, ft_index
);
4032 fputc ('\n', asm_out_file
);
4033 /* Include directory index */
4035 fputc ('\n', asm_out_file
);
4036 /* Modification time */
4038 fputc ('\n', asm_out_file
);
4039 /* File length in bytes */
4041 fputc ('\n', asm_out_file
);
4043 /* Terminate the file name table */
4044 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
4045 fputc ('\n', asm_out_file
);
4047 /* Set the address register to the first location in the text section */
4048 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
4049 if (flag_verbose_asm
)
4051 fprintf (asm_out_file
, "\t%s DW_LNE_set_address", ASM_COMMENT_START
);
4053 fputc ('\n', asm_out_file
);
4054 output_uleb128 (1 + PTR_SIZE
);
4055 fputc ('\n', asm_out_file
);
4056 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
4057 fputc ('\n', asm_out_file
);
4058 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, TEXT_BEGIN_LABEL
);
4059 fputc ('\n', asm_out_file
);
4061 /* Generate the line number to PC correspondence table, encoded as
4062 a series of state machine operations. */
4065 strcpy (prev_line_label
, TEXT_BEGIN_LABEL
);
4066 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
4068 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_fixed_advance_pc
);
4069 if (flag_verbose_asm
)
4071 fprintf (asm_out_file
, "\t%s DW_LNS_fixed_advance_pc",
4074 fputc ('\n', asm_out_file
);
4075 sprintf (line_label
, LINE_CODE_LABEL_FMT
, lt_index
);
4076 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file
, line_label
, prev_line_label
);
4077 fputc ('\n', asm_out_file
);
4078 line_info
= &line_info_table
[lt_index
];
4079 if (line_info
->dw_file_num
!= current_file
)
4081 current_file
= line_info
->dw_file_num
;
4082 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_set_file
);
4083 if (flag_verbose_asm
)
4085 fprintf (asm_out_file
,
4086 "\t%s DW_LNS_set_file", ASM_COMMENT_START
);
4088 fputc ('\n', asm_out_file
);
4089 output_uleb128 (current_file
);
4090 if (flag_verbose_asm
)
4092 fprintf (asm_out_file
, "\t%s \"%s\"",
4093 ASM_COMMENT_START
, file_table
[current_file
]);
4095 fputc ('\n', asm_out_file
);
4097 if (line_info
->dw_line_num
!= current_line
)
4099 line_offset
= line_info
->dw_line_num
- current_line
;
4100 line_delta
= line_offset
- DWARF_LINE_BASE
;
4101 current_line
= line_info
->dw_line_num
;
4102 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
4104 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
,
4105 DWARF_LINE_OPCODE_BASE
+ line_delta
);
4106 if (flag_verbose_asm
)
4108 fprintf (asm_out_file
,
4109 "\t%s line %d", ASM_COMMENT_START
, current_line
);
4111 fputc ('\n', asm_out_file
);
4115 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_advance_line
);
4116 if (flag_verbose_asm
)
4118 fprintf (asm_out_file
,
4119 "\t%s advance to line %d",
4120 ASM_COMMENT_START
, current_line
);
4122 fputc ('\n', asm_out_file
);
4123 output_sleb128 (line_offset
);
4124 fputc ('\n', asm_out_file
);
4125 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNS_copy
);
4126 fputc ('\n', asm_out_file
);
4129 strcpy (prev_line_label
, line_label
);
4132 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
4133 if (flag_verbose_asm
)
4135 fprintf (asm_out_file
, "\t%s DW_LNE_set_address", ASM_COMMENT_START
);
4137 fputc ('\n', asm_out_file
);
4138 output_uleb128 (1 + PTR_SIZE
);
4139 fputc ('\n', asm_out_file
);
4140 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_set_address
);
4141 fputc ('\n', asm_out_file
);
4142 ASM_OUTPUT_DWARF_ADDR (asm_out_file
, TEXT_END_LABEL
);
4143 fputc ('\n', asm_out_file
);
4144 /* Output the marker for the end of the line number info. */
4145 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, 0);
4146 if (flag_verbose_asm
)
4148 fprintf (asm_out_file
, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START
);
4150 fputc ('\n', asm_out_file
);
4152 fputc ('\n', asm_out_file
);
4153 ASM_OUTPUT_DWARF_DATA1 (asm_out_file
, DW_LNE_end_sequence
);
4154 fputc ('\n', asm_out_file
);
4157 /**************** attribute support utilities ********************************/
4160 * Given a pointer to a BLOCK node return non-zero if (and only if) the node
4161 * in question represents the outermost pair of curly braces (i.e. the "body
4162 * block") of a function or method.
4164 * For any BLOCK node representing a "body block" of a function or method, the
4165 * BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
4166 * represents the outermost (function) scope for the function or method (i.e.
4167 * the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of
4168 * *that* node in turn will point to the relevant FUNCTION_DECL node.
4171 is_body_block (stmt
)
4174 if (TREE_CODE (stmt
) == BLOCK
)
4176 register tree parent
= BLOCK_SUPERCONTEXT (stmt
);
4178 if (TREE_CODE (parent
) == BLOCK
)
4180 register tree grandparent
= BLOCK_SUPERCONTEXT (parent
);
4182 if (TREE_CODE (grandparent
) == FUNCTION_DECL
)
4189 /* Reset the base type to DIE table, and build a special predefined
4190 base type entry for the "int" signed integer base type. The
4191 "int" base type is used to construct subscript index range
4192 definitions, in situations where an anonymous integer type
4195 init_base_type_table ()
4198 register base_type_ref bt
;
4199 for (i
= 0; i
< NUM_BASE_TYPES
; ++i
)
4201 base_type_die_table
[i
] = NULL
;
4203 assert (comp_unit_die
!= 0);
4204 for (i
= 0; i
< NUM_BASE_TYPES
; ++i
)
4206 bt
= &base_type_table
[i
];
4207 if (strcmp (bt
->bt_name
, "int") == 0)
4209 int_base_type_die
= new_die (DW_TAG_base_type
, comp_unit_die
);
4210 base_type_die_table
[i
] = int_base_type_die
;
4211 add_AT_string (int_base_type_die
, DW_AT_name
, bt
->bt_name
);
4212 add_AT_unsigned (int_base_type_die
,
4213 DW_AT_byte_size
, bt
->bt_size
/ 8);
4214 add_AT_unsigned (int_base_type_die
, DW_AT_encoding
, bt
->bt_type
);
4220 /* Given a pointer to a tree node for some base type, return a pointer to
4221 a DIE that describes the given type.
4223 This routine must only be called for GCC type nodes that correspond to
4224 Dwarf base (fundamental) types. */
4226 base_type_die (type
)
4229 register dw_die_ref base_type_result
= NULL
;
4230 register char *type_name
= NULL
;
4231 register int type_index
= 0;
4232 register base_type_ref bt
;
4235 if (TREE_CODE (type
) == ERROR_MARK
)
4238 switch (TREE_CODE (type
))
4245 /* Carefully distinguish all the standard types of C, without messing
4246 up if the language is not C. Note that we check only for the names
4247 that contain spaces; other names might occur by coincidence in other
4249 if (TYPE_NAME (type
) != 0
4250 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
4251 && DECL_NAME (TYPE_NAME (type
)) != 0
4252 && TREE_CODE (DECL_NAME (TYPE_NAME (type
))) == IDENTIFIER_NODE
)
4254 type_name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
4255 for (i
= 0; i
< NUM_BASE_TYPES
; ++i
)
4257 bt
= &base_type_table
[i
];
4258 if (strcmp (type_name
, bt
->bt_name
) == 0)
4266 /* Most integer types will be sorted out above, however, for the sake
4267 of special `array index' integer types, the following code is also
4269 if (type_index
== 0)
4271 for (i
= 0; i
< NUM_BASE_TYPES
; ++i
)
4273 bt
= &base_type_table
[i
];
4274 if (bt
->bt_size
== TYPE_PRECISION (type
)
4275 && (TREE_UNSIGNED (type
) == 0) == bt
->bt_is_signed
)
4285 /* Carefully distinguish all the standard types of C, without messing
4286 up if the language is not C. */
4287 for (i
= 0; i
< NUM_BASE_TYPES
; ++i
)
4289 bt
= &base_type_table
[i
];
4290 if ((bt
->bt_type
== DW_ATE_float
)
4291 && (bt
->bt_size
== TYPE_PRECISION (type
)))
4300 for (i
= 0; i
< NUM_BASE_TYPES
; ++i
)
4302 bt
= &base_type_table
[i
];
4303 if ((bt
->bt_type
== DW_ATE_complex_float
)
4304 && (bt
->bt_size
== TYPE_PRECISION (type
)))
4313 /* GNU Pascal/Ada CHAR type. Not used in C. */
4314 for (i
= 0; i
< NUM_BASE_TYPES
; ++i
)
4316 bt
= &base_type_table
[i
];
4317 if (bt
->bt_type
== DW_ATE_signed_char
4318 || bt
->bt_type
== DW_ATE_unsigned_char
)
4320 if (bt
->bt_size
== TYPE_PRECISION (type
)
4321 && ((TREE_UNSIGNED (type
) == 0) == bt
->bt_is_signed
))
4331 /* GNU FORTRAN/Ada BOOLEAN type. */
4332 for (i
= 0; i
< NUM_BASE_TYPES
; ++i
)
4334 bt
= &base_type_table
[i
];
4335 if (bt
->bt_type
== DW_ATE_boolean
4336 && bt
->bt_size
== TYPE_PRECISION (type
))
4345 abort (); /* No other TREE_CODEs are Dwarf fundamental
4349 if (type_index
== 0)
4351 base_type_result
= NULL
;
4355 base_type_result
= base_type_die_table
[type_index
];
4356 if (base_type_result
== NULL
)
4358 bt
= &base_type_table
[type_index
];
4359 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
);
4360 base_type_die_table
[type_index
] = base_type_result
;
4361 add_AT_string (base_type_result
, DW_AT_name
, bt
->bt_name
);
4362 add_AT_unsigned (base_type_result
, DW_AT_byte_size
, bt
->bt_size
/ 8);
4363 add_AT_unsigned (base_type_result
, DW_AT_encoding
, bt
->bt_type
);
4368 return base_type_result
;
4371 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
4372 the Dwarf "root" type for the given input type. The Dwarf "root" type of
4373 a given type is generally the same as the given type, except that if the
4374 given type is a pointer or reference type, then the root type of the given
4375 type is the root type of the "basis" type for the pointer or reference
4376 type. (This definition of the "root" type is recursive.) Also, the root
4377 type of a `const' qualified type or a `volatile' qualified type is the
4378 root type of the given type without the qualifiers. */
4383 if (TREE_CODE (type
) == ERROR_MARK
)
4384 return error_mark_node
;
4386 switch (TREE_CODE (type
))
4389 return error_mark_node
;
4392 case REFERENCE_TYPE
:
4393 return type_main_variant (root_type (TREE_TYPE (type
)));
4396 return type_main_variant (type
);
4400 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
4401 given input type is a Dwarf "fundamental" type. Otherwise return null. */
4406 switch (TREE_CODE (type
))
4421 case QUAL_UNION_TYPE
:
4426 case REFERENCE_TYPE
:
4438 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
4439 entry that chains various modifiers in front of the given type. */
4441 modified_type_die (type
, is_const_type
, is_volatile_type
, context_die
)
4443 register int is_const_type
;
4444 register int is_volatile_type
;
4445 register dw_die_ref context_die
;
4447 register enum tree_code code
= TREE_CODE (type
);
4448 register dw_die_ref mod_type_die
= NULL
;
4449 register dw_die_ref sub_die
= NULL
;
4450 register tree item_type
;
4452 if (code
!= ERROR_MARK
)
4456 mod_type_die
= new_die (DW_TAG_const_type
, context_die
);
4457 sub_die
= modified_type_die (type
,
4458 0, is_volatile_type
, context_die
);
4460 else if (is_volatile_type
)
4462 mod_type_die
= new_die (DW_TAG_volatile_type
, context_die
);
4463 sub_die
= modified_type_die (type
, 0, 0, context_die
);
4465 else if (code
== POINTER_TYPE
)
4467 mod_type_die
= new_die (DW_TAG_pointer_type
, context_die
);
4468 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
4469 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
4470 item_type
= TREE_TYPE (type
);
4471 sub_die
= modified_type_die (item_type
,
4472 TYPE_READONLY (item_type
),
4473 TYPE_VOLATILE (item_type
),
4476 else if (code
== REFERENCE_TYPE
)
4478 mod_type_die
= new_die (DW_TAG_reference_type
, context_die
);
4479 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
4480 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
4481 item_type
= TREE_TYPE (type
);
4482 sub_die
= modified_type_die (item_type
,
4483 TYPE_READONLY (item_type
),
4484 TYPE_VOLATILE (item_type
),
4487 else if (is_base_type (type
))
4489 mod_type_die
= base_type_die (type
);
4493 /* We have to get the type_main_variant here (and pass that to the
4494 `lookup_type_die' routine) because the ..._TYPE node we have
4495 might simply be a *copy* of some original type node (where the
4496 copy was created to help us keep track of typedef names) and
4497 that copy might have a different TYPE_UID from the original
4498 ..._TYPE node. (Note that when `equate_type_number_to_die' is
4499 labeling a given type DIE for future reference, it always only
4500 handles DIEs representing *main variants*, and it never even
4501 knows about non-main-variants.). */
4502 mod_type_die
= lookup_type_die (type_main_variant (type
));
4504 /* Normally, we assume that all types are defined before they are
4505 referenced. If this is not the case, then mod_type_die will
4506 be NULL here, and we must backchain. This can happen as the
4507 result of a forward declaration of a structure tag. */
4508 if (mod_type_die
== NULL
)
4510 dw_die_ref placeholder_die
= new_die (DW_TAG_padding
,
4512 backchain_AT_die_ref (type
, placeholder_die
);
4516 if (sub_die
!= NULL
)
4518 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
4520 return mod_type_die
;
4523 /* Fix all unresolved die references that resulted from forward
4526 resolve_backchains ()
4528 register backchain_ref back
;
4533 register dw_die_ref type_die
;
4535 type_die
= lookup_type_die (type_main_variant (back
->type
));
4537 assert (type_die
!= NULL
);
4539 /* ??? It would be cleaner to find the die attribute, and change
4540 the val_dir_ref field to point to this new die. Just overwriting
4541 the temporary die with the correct one is easier though, and seems
4542 to work just as well. */
4543 memcpy (back
->placeholder
, type_die
, sizeof (die_node
));
4549 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
4550 an enumerated type. */
4555 return TREE_CODE (type
) == ENUMERAL_TYPE
;
4558 /* Return the register number described by a given RTL node. */
4563 register unsigned regno
= REGNO (rtl
);
4565 if (regno
>= FIRST_PSEUDO_REGISTER
)
4567 warning_with_decl (dwarf_last_decl
, "internal regno botch: regno = %d\n",
4571 regno
= DBX_REGISTER_NUMBER (regno
);
4575 /* Return a location descriptor that designates a machine register. */
4576 static dw_loc_descr_ref
4577 reg_loc_descriptor (rtl
)
4580 register dw_loc_descr_ref loc_result
= NULL
;
4581 register unsigned reg
= reg_number (rtl
);
4582 if (reg
>= 0 && reg
<= 31)
4584 loc_result
= new_loc_descr (DW_OP_reg0
+ reg
, 0);
4588 loc_result
= new_loc_descr (DW_OP_regx
, reg
, 0);
4593 /* Return a location descriptor that designates a base+offset location. */
4594 static dw_loc_descr_ref
4595 based_loc_descr (reg
, offset
)
4599 register dw_loc_descr_ref loc_result
;
4600 register unsigned fp_reg
= (frame_pointer_needed
)
4601 ? FRAME_POINTER_REGNUM
4602 : STACK_POINTER_REGNUM
;
4605 loc_result
= new_loc_descr (DW_OP_fbreg
,
4606 offset
- current_funcdef_frame_size
, 0);
4608 else if (reg
>= 0 && reg
<= 31)
4610 loc_result
= new_loc_descr (DW_OP_breg0
+ reg
, offset
);
4614 loc_result
= new_loc_descr (DW_OP_bregx
, reg
, offset
);
4619 /* Return true if this RTL expression describes a base+offset calculation. */
4624 return GET_CODE (rtl
) == PLUS
4625 && ((GET_CODE (XEXP (rtl
, 0)) == REG
4626 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
));
4629 /* The following routine converts the RTL for a variable or parameter
4630 (resident in memory) into an equivalent Dwarf representation of a
4631 mechanism for getting the address of that same variable onto the top of a
4632 hypothetical "address evaluation" stack.
4633 When creating memory location descriptors, we are effectively transforming
4634 the RTL for a memory-resident object into its Dwarf postfix expression
4635 equivalent. This routine recursively descends an RTL tree, turning
4636 it into Dwarf postfix code as it goes. */
4637 static dw_loc_descr_ref
4638 mem_loc_descriptor (rtl
)
4641 dw_loc_descr_ref mem_loc_result
= NULL
;
4642 /* Note that for a dynamically sized array, the location we will generate a
4643 description of here will be the lowest numbered location which is
4644 actually within the array. That's *not* necessarily the same as the
4645 zeroth element of the array. */
4646 switch (GET_CODE (rtl
))
4649 /* The case of a subreg may arise when we have a local (register)
4650 variable or a formal (register) parameter which doesn't quite fill
4651 up an entire register. For now, just assume that it is
4652 legitimate to make the Dwarf info refer to the whole register which
4653 contains the given subreg. */
4654 rtl
= XEXP (rtl
, 0);
4658 /* Whenever a register number forms a part of the description of the
4659 method for calculating the (dynamic) address of a memory resident
4660 object, DWARF rules require the register number be referred to as
4661 a "base register". This distinction is not based in any way upon
4662 what category of register the hardware believes the given register
4663 belongs to. This is strictly DWARF terminology we're dealing with
4664 here. Note that in cases where the location of a memory-resident
4665 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
4666 OP_CONST (0)) the actual DWARF location descriptor that we generate
4667 may just be OP_BASEREG (basereg). This may look deceptively like
4668 the object in question was allocated to a register (rather than in
4669 memory) so DWARF consumers need to be aware of the subtle
4670 distinction between OP_REG and OP_BASEREG. */
4671 mem_loc_result
= based_loc_descr (reg_number (rtl
), 0);
4675 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0));
4676 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
4681 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
4682 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
4683 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= addr_to_string (rtl
);
4687 if (is_based_loc (rtl
))
4689 mem_loc_result
= based_loc_descr (
4690 reg_number (XEXP (rtl
, 0)),
4691 INTVAL (XEXP (rtl
, 1)));
4695 add_loc_descr (&mem_loc_result
, mem_loc_descriptor (XEXP (rtl
, 0)));
4696 add_loc_descr (&mem_loc_result
, mem_loc_descriptor (XEXP (rtl
, 1)));
4697 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_plus
, 0, 0));
4702 mem_loc_result
= new_loc_descr (DW_OP_constu
, INTVAL (rtl
), 0);
4708 return mem_loc_result
;
4711 /* Output a proper Dwarf location descriptor for a variable or parameter
4712 which is either allocated in a register or in a memory location. For a
4713 register, we just generate an OP_REG and the register number. For a
4714 memory location we provide a Dwarf postfix expression describing how to
4715 generate the (dynamic) address of the object onto the address stack. */
4716 static dw_loc_descr_ref
4717 loc_descriptor (rtl
)
4720 dw_loc_descr_ref loc_result
= NULL
;
4721 switch (GET_CODE (rtl
))
4725 /* The case of a subreg may arise when we have a local (register)
4726 variable or a formal (register) parameter which doesn't quite fill
4727 up an entire register. For now, just assume that it is
4728 legitimate to make the Dwarf info refer to the whole register which
4729 contains the given subreg. */
4731 rtl
= XEXP (rtl
, 0);
4732 loc_result
= new_loc_descr (DW_OP_regx
, reg_number (rtl
), 0);
4736 loc_result
= new_loc_descr (DW_OP_regx
, reg_number (rtl
), 0);
4740 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0));
4744 abort (); /* Should never happen */
4749 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
4750 which is not less than the value itself. */
4752 ceiling (value
, boundary
)
4753 register unsigned value
;
4754 register unsigned boundary
;
4756 return (((value
+ boundary
- 1) / boundary
) * boundary
);
4759 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
4760 pointer to the declared type for the relevant field variable, or return
4761 `integer_type_node' if the given node turns out to be an
4769 if (TREE_CODE (decl
) == ERROR_MARK
)
4770 return integer_type_node
;
4772 type
= DECL_BIT_FIELD_TYPE (decl
);
4774 type
= TREE_TYPE (decl
);
4779 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
4780 node, return the alignment in bits for the type, or else return
4781 BITS_PER_WORD if the node actually turns out to be an
4784 simple_type_align_in_bits (type
)
4787 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
4790 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
4791 node, return the size in bits for the type if it is a constant, or else
4792 return the alignment for the type if the type's size is not constant, or
4793 else return BITS_PER_WORD if the type actually turns out to be an
4796 simple_type_size_in_bits (type
)
4799 if (TREE_CODE (type
) == ERROR_MARK
)
4800 return BITS_PER_WORD
;
4803 register tree type_size_tree
= TYPE_SIZE (type
);
4805 if (TREE_CODE (type_size_tree
) != INTEGER_CST
)
4806 return TYPE_ALIGN (type
);
4808 return (unsigned) TREE_INT_CST_LOW (type_size_tree
);
4812 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
4813 return the byte offset of the lowest addressed byte of the "containing
4814 object" for the given FIELD_DECL, or return 0 if we are unable to
4815 determine what that offset is, either because the argument turns out to
4816 be a pointer to an ERROR_MARK node, or because the offset is actually
4817 variable. (We can't handle the latter case just yet). */
4819 field_byte_offset (decl
)
4822 register unsigned type_align_in_bytes
;
4823 register unsigned type_align_in_bits
;
4824 register unsigned type_size_in_bits
;
4825 register unsigned object_offset_in_align_units
;
4826 register unsigned object_offset_in_bits
;
4827 register unsigned object_offset_in_bytes
;
4829 register tree bitpos_tree
;
4830 register tree field_size_tree
;
4831 register unsigned bitpos_int
;
4832 register unsigned deepest_bitpos
;
4833 register unsigned field_size_in_bits
;
4835 if (TREE_CODE (decl
) == ERROR_MARK
)
4838 if (TREE_CODE (decl
) != FIELD_DECL
)
4841 type
= field_type (decl
);
4843 bitpos_tree
= DECL_FIELD_BITPOS (decl
);
4844 field_size_tree
= DECL_SIZE (decl
);
4846 /* We cannot yet cope with fields whose positions or sizes are variable, so
4847 for now, when we see such things, we simply return 0. Someday, we may
4848 be able to handle such cases, but it will be damn difficult. */
4849 if (TREE_CODE (bitpos_tree
) != INTEGER_CST
)
4851 bitpos_int
= (unsigned) TREE_INT_CST_LOW (bitpos_tree
);
4853 if (TREE_CODE (field_size_tree
) != INTEGER_CST
)
4855 field_size_in_bits
= (unsigned) TREE_INT_CST_LOW (field_size_tree
);
4857 type_size_in_bits
= simple_type_size_in_bits (type
);
4859 type_align_in_bits
= simple_type_align_in_bits (type
);
4860 type_align_in_bytes
= type_align_in_bits
/ BITS_PER_UNIT
;
4862 /* Note that the GCC front-end doesn't make any attempt to keep track of
4863 the starting bit offset (relative to the start of the containing
4864 structure type) of the hypothetical "containing object" for a bit-
4865 field. Thus, when computing the byte offset value for the start of the
4866 "containing object" of a bit-field, we must deduce this information on
4867 our own. This can be rather tricky to do in some cases. For example,
4868 handling the following structure type definition when compiling for an
4869 i386/i486 target (which only aligns long long's to 32-bit boundaries)
4872 struct S { int field1; long long field2:31; };
4874 Fortunately, there is a simple rule-of-thumb which can be
4875 used in such cases. When compiling for an i386/i486, GCC will allocate
4876 8 bytes for the structure shown above. It decides to do this based upon
4877 one simple rule for bit-field allocation. Quite simply, GCC allocates
4878 each "containing object" for each bit-field at the first (i.e. lowest
4879 addressed) legitimate alignment boundary (based upon the required
4880 minimum alignment for the declared type of the field) which it can
4881 possibly use, subject to the condition that there is still enough
4882 available space remaining in the containing object (when allocated at
4883 the selected point) to fully accommodate all of the bits of the
4884 bit-field itself. This simple rule makes it obvious why GCC allocates
4885 8 bytes for each object of the structure type shown above. When looking
4886 for a place to allocate the "containing object" for `field2', the
4887 compiler simply tries to allocate a 64-bit "containing object" at each
4888 successive 32-bit boundary (starting at zero) until it finds a place to
4889 allocate that 64- bit field such that at least 31 contiguous (and
4890 previously unallocated) bits remain within that selected 64 bit field.
4891 (As it turns out, for the example above, the compiler finds that it is
4892 OK to allocate the "containing object" 64-bit field at bit-offset zero
4893 within the structure type.) Here we attempt to work backwards from the
4894 limited set of facts we're given, and we try to deduce from those facts,
4895 where GCC must have believed that the containing object started (within
4896 the structure type). The value we deduce is then used (by the callers of
4897 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
4898 for fields (both bit-fields and, in the case of DW_AT_location, regular
4901 /* Figure out the bit-distance from the start of the structure to the
4902 "deepest" bit of the bit-field. */
4903 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
4905 /* This is the tricky part. Use some fancy footwork to deduce where the
4906 lowest addressed bit of the containing object must be. */
4907 object_offset_in_bits
4908 = ceiling (deepest_bitpos
, type_align_in_bits
) - type_size_in_bits
;
4910 /* Compute the offset of the containing object in "alignment units". */
4911 object_offset_in_align_units
= object_offset_in_bits
/ type_align_in_bits
;
4913 /* Compute the offset of the containing object in bytes. */
4914 object_offset_in_bytes
= object_offset_in_align_units
* type_align_in_bytes
;
4916 return object_offset_in_bytes
;
4921 /****************************** attributes *********************************/
4923 /* The following routines define various Dwarf attributes
4924 (and any data associated with them). */
4927 /* Output the form of location attributes suitable for whole variables and
4928 whole parameters. Note that the location attributes for struct fields are
4929 generated by the routine `data_member_location_attribute' below. */
4931 add_location_attribute (die
, rtl
)
4935 dw_loc_descr_ref loc_descr
= NULL
;
4937 /* Handle a special case. If we are about to output a location descriptor
4938 for a variable or parameter which has been optimized out of existence,
4939 don't do that. Instead we output a null location descriptor value as
4940 part of the location attribute. A variable which has been optimized out
4941 of existence will have a DECL_RTL value which denotes a pseudo-reg.
4942 Currently, in some rare cases, variables can have DECL_RTL values which
4943 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
4944 elsewhere in the compiler. We treat such cases as if the variable(s) in
4945 question had been optimized out of existence. Note that in all cases
4946 where we wish to express the fact that a variable has been optimized out
4947 of existence, we do not simply suppress the generation of the entire
4948 location attribute because the absence of a location attribute in
4949 certain kinds of DIEs is used to indicate something else entirely...
4950 i.e. that the DIE represents an object declaration, but not a
4951 definition. So sayeth the PLSIG. */
4952 if (!is_pseudo_reg (rtl
)
4953 && (GET_CODE (rtl
) != MEM
4954 || !is_pseudo_reg (XEXP (rtl
, 0))))
4956 loc_descr
= loc_descriptor (eliminate_regs (rtl
, 0, NULL_RTX
));
4959 #ifdef MIPS_DEBUGGING_INFO
4960 /* ??? SGI's dwarf reader is buggy, and will not accept a zero size
4961 location descriptor. Lets just use r0 for now to represent a
4962 variable that has been optimized away. */
4963 if (loc_descr
== NULL
)
4965 loc_descr
= loc_descriptor (gen_rtx (REG
, word_mode
, 0));
4969 add_AT_loc (die
, DW_AT_location
, loc_descr
);
4972 /* Attach the specialized form of location attribute used for data
4973 members of struct and union types. In the special case of a
4974 FIELD_DECL node which represents a bit-field, the "offset" part
4975 of this special location descriptor must indicate the distance
4976 in bytes from the lowest-addressed byte of the containing struct
4977 or union type to the lowest-addressed byte of the "containing
4978 object" for the bit-field. (See the `field_byte_offset' function
4979 above).. For any given bit-field, the "containing object" is a
4980 hypothetical object (of some integral or enum type) within which
4981 the given bit-field lives. The type of this hypothetical
4982 "containing object" is always the same as the declared type of
4983 the individual bit-field itself (for GCC anyway... the DWARF
4984 spec doesn't actually mandate this). Note that it is the size
4985 (in bytes) of the hypothetical "containing object" which will
4986 be given in the DW_AT_byte_size attribute for this bit-field.
4987 (See the `byte_size_attribute' function below.) It is also used
4988 when calculating the value of the DW_AT_bit_offset attribute.
4989 (See the `bit_offset_attribute' function below). */
4991 add_data_member_location_attribute (die
, decl
)
4992 register dw_die_ref die
;
4995 register unsigned long offset
= field_byte_offset (decl
);
4996 register dw_loc_descr_ref loc_descr
;
4997 register enum dwarf_location_atom op
;
4999 /* The DWARF2 standard says that we should assume that the structure address
5000 is already on the stack, so we can specify a structure field address
5001 by using DW_OP_plus_uconst. */
5002 #ifdef MIPS_DEBUGGING_INFO
5003 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
5004 correctly. It works only if we leave the offset on the stack. */
5007 op
= DW_OP_plus_uconst
;
5009 loc_descr
= new_loc_descr (op
, offset
, 0);
5010 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
5013 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
5014 does not have a "location" either in memory or in a register. These
5015 things can arise in GNU C when a constant is passed as an actual parameter
5016 to an inlined function. They can also arise in C++ where declared
5017 constants do not necessarily get memory "homes". */
5019 add_const_value_attribute (die
, rtl
)
5020 register dw_die_ref die
;
5023 switch (GET_CODE (rtl
))
5026 /* Note that a CONST_INT rtx could represent either an integer or a
5027 floating-point constant. A CONST_INT is used whenever the constant
5028 will fit into a single word. In all such cases, the original mode
5029 of the constant value is wiped out, and the CONST_INT rtx is
5030 assigned VOIDmode. */
5031 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned) INTVAL (rtl
));
5035 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
5036 floating-point constant. A CONST_DOUBLE is used whenever the
5037 constant requires more than one word in order to be adequately
5038 represented. In all such cases, the original mode of the constant
5039 value is preserved as the mode of the CONST_DOUBLE rtx, but for
5040 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
5041 add_AT_double (die
, DW_AT_const_value
,
5042 (unsigned) CONST_DOUBLE_HIGH (rtl
),
5043 (unsigned) CONST_DOUBLE_LOW (rtl
));
5047 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
5053 add_AT_addr (die
, DW_AT_const_value
, addr_to_string (rtl
));
5057 /* In cases where an inlined instance of an inline function is passed
5058 the address of an `auto' variable (which is local to the caller) we
5059 can get a situation where the DECL_RTL of the artificial local
5060 variable (for the inlining) which acts as a stand-in for the
5061 corresponding formal parameter (of the inline function) will look
5062 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
5063 exactly a compile-time constant expression, but it isn't the address
5064 of the (artificial) local variable either. Rather, it represents the
5065 *value* which the artificial local variable always has during its
5066 lifetime. We currently have no way to represent such quasi-constant
5067 values in Dwarf, so for now we just punt and generate an
5068 DW_AT_const_value attribute with null address. */
5069 add_AT_addr (die
, DW_AT_const_value
, addr_to_string (const0_rtx
));
5073 /* No other kinds of rtx should be possible here. */
5079 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
5080 data attribute for a variable or a parameter. We generate the
5081 DW_AT_const_value attribute only in those cases where the given variable
5082 or parameter does not have a true "location" either in memory or in a
5083 register. This can happen (for example) when a constant is passed as an
5084 actual argument in a call to an inline function. (It's possible that
5085 these things can crop up in other ways also.) Note that one type of
5086 constant value which can be passed into an inlined function is a constant
5087 pointer. This can happen for example if an actual argument in an inlined
5088 function call evaluates to a compile-time constant address. */
5090 add_location_or_const_value_attribute (die
, decl
)
5091 register dw_die_ref die
;
5095 register tree declared_type
;
5096 register tree passed_type
;
5098 if (TREE_CODE (decl
) == ERROR_MARK
)
5102 if ((TREE_CODE (decl
) != VAR_DECL
)
5103 && (TREE_CODE (decl
) != PARM_DECL
))
5105 /* Should never happen. */
5109 /* Here we have to decide where we are going to say the parameter "lives"
5110 (as far as the debugger is concerned). We only have a couple of
5111 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
5112 DECL_RTL normally indicates where the parameter lives during most of the
5113 activa- tion of the function. If optimization is enabled however, this
5114 could be either NULL or else a pseudo-reg. Both of those cases indicate
5115 that the parameter doesn't really live anywhere (as far as the code
5116 generation parts of GCC are concerned) during most of the function's
5117 activation. That will happen (for example) if the parameter is never
5118 referenced within the function. We could just generate a location
5119 descriptor here for all non-NULL non-pseudo values of DECL_RTL and
5120 ignore all of the rest, but we can be a little nicer than that if we
5121 also consider DECL_INCOMING_RTL in cases where DECL_RTL is NULL or is a
5122 pseudo-reg. Note however that we can only get away with using
5123 DECL_INCOMING_RTL as a backup substitute for DECL_RTL in certain limited
5124 cases. In cases where DECL_ARG_TYPE(decl) indicates the same type as
5125 TREE_TYPE(decl) we can be sure that the parameter was passed using the
5126 same type as it is declared to have within the function, and that its
5127 DECL_INCOMING_RTL points us to a place where a value of that type is
5128 passed. In cases where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are
5129 different types however, we cannot (in general) use DECL_INCOMING_RTL as
5130 a backup substitute for DECL_RTL because in these cases,
5131 DECL_INCOMING_RTL points us to a value of some type which is *different*
5132 from the type of the parameter itself. Thus, if we tried to use
5133 DECL_INCOMING_RTL to generate a location attribute in such cases, the
5134 debugger would end up (for example) trying to fetch a `float' from a
5135 place which actually contains the first part of a `double'. That would
5136 lead to really incorrect and confusing output at debug-time, and we
5137 don't want that now do we? So in general, we DO NOT use
5138 DECL_INCOMING_RTL as a backup for DECL_RTL in cases where
5139 DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a couple of cute
5140 exceptions however. On little-endian machines we can get away with
5141 using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is not the same as
5142 TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is an integral type
5143 which is smaller than TREE_TYPE(decl). These cases arise when (on a
5144 little-endian machine) a non-prototyped function has a parameter
5145 declared to be of type `short' or `char'. In such cases,
5146 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
5147 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
5148 passed `int' value. If the debugger then uses that address to fetch a
5149 `short' or a `char' (on a little-endian machine) the result will be the
5150 correct data, so we allow for such exceptional cases below. Note that
5151 our goal here is to describe the place where the given formal parameter
5152 lives during most of the function's activation (i.e. between the end of
5153 the prologue and the start of the epilogue). We'll do that as best as
5154 we can. Note however that if the given formal parameter is modified
5155 sometime during the execution of the function, then a stack backtrace
5156 (at debug-time) will show the function as having been called with the
5157 *new* value rather than the value which was originally passed in. This
5158 happens rarely enough that it is not a major problem, but it *is* a
5159 problem, and I'd like to fix it. A future version of dwarfout.c may
5160 generate two additional attributes for any given DW_TAG_formal_parameter
5161 DIE which will describe the "passed type" and the "passed location" for
5162 the given formal parameter in addition to the attributes we now generate
5163 to indicate the "declared type" and the "active location" for each
5164 parameter. This additional set of attributes could be used by debuggers
5165 for stack backtraces. Separately, note that sometimes DECL_RTL can be
5166 NULL and DECL_INCOMING_RTL can be NULL also. This happens (for example)
5167 for inlined-instances of inline function formal parameters which are
5168 never referenced. This really shouldn't be happening. All PARM_DECL
5169 nodes should get valid non-NULL DECL_INCOMING_RTL values, but
5170 integrate.c doesn't currently generate these values for inlined
5171 instances of inline function parameters, so when we see such cases, we
5172 are just SOL (shit-out-of-luck) for the time being (until integrate.c
5175 /* Use DECL_RTL as the "location" unless we find something better. */
5176 rtl
= DECL_RTL (decl
);
5178 if (TREE_CODE (decl
) == PARM_DECL
)
5180 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
5182 declared_type
= type_main_variant (TREE_TYPE (decl
));
5183 passed_type
= type_main_variant (DECL_ARG_TYPE (decl
));
5184 /* This decl represents a formal parameter which was
5187 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
5188 all* cases where (rtl == NULL_RTX) just below. */
5189 if (declared_type
== passed_type
)
5191 rtl
= DECL_INCOMING_RTL (decl
);
5193 else if (!BYTES_BIG_ENDIAN
)
5195 if (TREE_CODE (declared_type
) == INTEGER_TYPE
)
5197 if (TYPE_SIZE (declared_type
) <= TYPE_SIZE (passed_type
))
5199 rtl
= DECL_INCOMING_RTL (decl
);
5203 if (rtl
== NULL_RTX
)
5209 switch (GET_CODE (rtl
))
5218 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
5219 add_const_value_attribute (die
, rtl
);
5225 add_location_attribute (die
, rtl
);
5229 abort (); /* Should never happen. */
5233 /* Generate an DW_AT_name attribute given some string value to be included as
5234 the value of the attribute. */
5236 add_name_attribute (die
, name_string
)
5237 register dw_die_ref die
;
5238 register char *name_string
;
5240 if (name_string
&& *name_string
)
5242 add_AT_string (die
, DW_AT_name
, name_string
);
5246 /* Given a tree node describing an array bound (either lower or upper) output
5247 a representation for that bound. */
5249 add_bound_info (subrange_die
, bound_attr
, bound
)
5250 register dw_die_ref subrange_die
;
5251 register enum dwarf_attribute bound_attr
;
5252 register tree bound
;
5254 register dw_loc_descr_ref bound_loc
= NULL
;
5255 register unsigned bound_value
= 0;
5256 switch (TREE_CODE (bound
))
5261 /* All fixed-bounds are represented by INTEGER_CST nodes. */
5263 bound_value
= TREE_INT_CST_LOW (bound
);
5264 /* TODO: we need to check for C language below, or some flag
5265 derived from the language. C implies a lower bound of 0. */
5266 if (!(bound_attr
== DW_AT_lower_bound
&& bound_value
== 0))
5268 add_AT_unsigned (subrange_die
, bound_attr
, bound_value
);
5272 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
5275 bound
= TREE_OPERAND (bound
, 0);
5276 /* ... fall thru... */
5279 /* If optimization is turned on, the SAVE_EXPRs that describe how to
5280 access the upper bound values are essentially bogus. They only
5281 describe (at best) how to get at these values at the points in the
5282 generated code right after they have just been computed. Worse yet,
5283 in the typical case, the upper bound values will not even *be*
5284 computed in the optimized code, so these SAVE_EXPRs are entirely
5285 bogus. In order to compensate for this fact, we check here to see if
5286 optimization is enabled, and if so, we effectively create an empty
5287 location description for the (unknown and unknowable) upper bound.
5288 This should not cause too much trouble for existing (stupid?)
5289 debuggers because they have to deal with empty upper bounds location
5290 descriptions anyway in order to be able to deal with incomplete array
5291 types. Of course an intelligent debugger (GDB?) should be able to
5292 comprehend that a missing upper bound specification in a array type
5293 used for a storage class `auto' local array variable indicates that
5294 the upper bound is both unknown (at compile- time) and unknowable (at
5295 run-time) due to optimization. */
5298 bound_loc
= mem_loc_descriptor (
5299 eliminate_regs (SAVE_EXPR_RTL (bound
),
5306 add_AT_loc (subrange_die
, bound_attr
, bound_loc
);
5314 /* Note that the block of subscript information for an array type also
5315 includes information about the element type of type given array type. */
5317 add_subscript_info (type_die
, type
)
5318 register dw_die_ref type_die
;
5321 register unsigned dimension_number
;
5322 register tree lower
, upper
;
5323 register dw_die_ref subrange_die
;
5325 /* The GNU compilers represent multidimensional array types as sequences of
5326 one dimensional array types whose element types are themselves array
5327 types. Here we squish that down, so that each multidimensional array
5328 type gets only one array_type DIE in the Dwarf debugging info. The draft
5329 Dwarf specification say that we are allowed to do this kind of
5330 compression in C (because there is no difference between an array or
5331 arrays and a multidimensional array in C) but for other source languages
5332 (e.g. Ada) we probably shouldn't do this. */
5333 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
5334 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
5335 We work around this by disabling this feature. See also
5336 gen_array_type_die. */
5337 #ifndef MIPS_DEBUGGING_INFO
5338 for (dimension_number
= 0;
5339 TREE_CODE (type
) == ARRAY_TYPE
;
5340 type
= TREE_TYPE (type
), dimension_number
++)
5343 register tree domain
= TYPE_DOMAIN (type
);
5345 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
5346 and (in GNU C only) variable bounds. Handle all three forms
5348 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
);
5351 /* We have an array type with specified bounds. */
5352 lower
= TYPE_MIN_VALUE (domain
);
5353 upper
= TYPE_MAX_VALUE (domain
);
5355 /* TODO: establish DW_AT_type for the basis type a byte_size
5356 attribute if the byte size is non-standard */
5357 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
5358 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
5362 /* We have an array type with an unspecified length. For C and C++
5363 we can assume that this really means that (a) the index type is
5364 an integral type, and (b) the lower bound is zero. Note that
5365 Dwarf defines the representation of an unspecified (upper) bound
5366 as being a zero-length location description. */
5368 /* define the (assumed) index type. */
5369 add_AT_die_ref (subrange_die
, DW_AT_type
, int_base_type_die
);
5371 /* Add the (assumed) lower bound (constant) value. */
5372 add_AT_unsigned (subrange_die
, DW_AT_lower_bound
, 0);
5374 /* Add the (empty) location description for the upper bound. */
5375 add_AT_loc (subrange_die
, DW_AT_upper_bound
, NULL
);
5377 #ifndef MIPS_DEBUGGING_INFO
5383 add_byte_size_attribute (die
, tree_node
)
5385 register tree tree_node
;
5387 register unsigned size
;
5389 switch (TREE_CODE (tree_node
))
5397 case QUAL_UNION_TYPE
:
5398 size
= int_size_in_bytes (tree_node
);
5401 /* For a data member of a struct or union, the DW_AT_byte_size is
5402 generally given as the number of bytes normally allocated for an
5403 object of the *declared* type of the member itself. This is true
5404 even for bit-fields. */
5405 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
5411 /* Note that `size' might be -1 when we get to this point. If it is, that
5412 indicates that the byte size of the entity in question is variable. We
5413 have no good way of expressing this fact in Dwarf at the present time,
5414 so just let the -1 pass on through. */
5416 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
5419 /* For a FIELD_DECL node which represents a bit-field, output an attribute
5420 which specifies the distance in bits from the highest order bit of the
5421 "containing object" for the bit-field to the highest order bit of the
5424 For any given bit-field, the "containing object" is a hypothetical object (of
5425 some integral or enum type) within which the given bit-field lives. The
5426 type of this hypothetical "containing object" is always the same as the
5427 declared type of the individual bit-field itself.
5428 The determination of the exact location of the "containing object" for a
5429 bit-field is rather complicated. It's handled by the `field_byte_offset'
5432 Note that it is the size (in bytes) of the hypothetical "containing object"
5433 which will be given in the DW_AT_byte_size attribute for this bit-field.
5434 (See `byte_size_attribute' above). */
5436 add_bit_offset_attribute (die
, decl
)
5437 register dw_die_ref die
;
5440 register unsigned object_offset_in_bytes
= field_byte_offset (decl
);
5441 register tree type
= DECL_BIT_FIELD_TYPE (decl
);
5442 register tree bitpos_tree
= DECL_FIELD_BITPOS (decl
);
5443 register unsigned bitpos_int
;
5444 register unsigned highest_order_object_bit_offset
;
5445 register unsigned highest_order_field_bit_offset
;
5446 register unsigned bit_offset
;
5448 assert (TREE_CODE (decl
) == FIELD_DECL
); /* Must be a field. */
5449 assert (type
); /* Must be a bit field. */
5451 /* We can't yet handle bit-fields whose offsets are variable, so if we
5452 encounter such things, just return without generating any attribute
5454 if (TREE_CODE (bitpos_tree
) != INTEGER_CST
)
5458 bitpos_int
= (unsigned) TREE_INT_CST_LOW (bitpos_tree
);
5460 /* Note that the bit offset is always the distance (in bits) from the
5461 highest-order bit of the "containing object" to the highest-order bit of
5462 the bit-field itself. Since the "high-order end" of any object or field
5463 is different on big-endian and little-endian machines, the computation
5464 below must take account of these differences. */
5465 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
5466 highest_order_field_bit_offset
= bitpos_int
;
5468 if (!BYTES_BIG_ENDIAN
)
5470 highest_order_field_bit_offset
5471 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl
));
5473 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
5477 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
5478 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
5480 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
5483 /* For a FIELD_DECL node which represents a bit field, output an attribute
5484 which specifies the length in bits of the given field. */
5486 add_bit_size_attribute (die
, decl
)
5487 register dw_die_ref die
;
5490 assert (TREE_CODE (decl
) == FIELD_DECL
); /* Must be a field. */
5491 assert (DECL_BIT_FIELD_TYPE (decl
)); /* Must be a bit field. */
5492 add_AT_unsigned (die
, DW_AT_bit_size
,
5493 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl
)));
5497 add_member_attribute (die
, context
)
5498 register dw_die_ref die
;
5499 register tree context
;
5501 register dw_die_ref type_die
;
5503 /* Generate this attribute only for members in C++. */
5504 if (context
!= NULL
&& is_tagged_type (context
))
5506 type_die
= lookup_type_die (context
);
5507 add_AT_die_ref (die
, DW_AT_member
, type_die
);
5511 /* If the compiled language is GNU C, then add a 'prototyped'
5512 attribute, if arg types are given for the parameters of a function. */
5514 add_prototyped_attribute (die
, func_type
)
5515 register dw_die_ref die
;
5516 register tree func_type
;
5518 if ((strcmp (language_string
, "GNU C") == 0)
5519 && (TYPE_ARG_TYPES (func_type
) != NULL
))
5521 add_AT_flag (die
, DW_AT_prototyped
, 0);
5526 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
5527 by looking in either the type declaration or object declaration
5530 add_abstract_origin_attribute (die
, origin
)
5531 register dw_die_ref die
;
5532 register tree origin
;
5534 dw_die_ref origin_die
= NULL
;
5535 if (TREE_CODE_CLASS (TREE_CODE (origin
)) == 'd')
5537 origin_die
= lookup_decl_die (origin
);
5539 else if (TREE_CODE_CLASS (TREE_CODE (origin
)) == 't')
5541 origin_die
= lookup_type_die (origin
);
5543 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
5546 /* If the compiled source program is C++, define the pure_virtual
5549 add_pure_or_virtual_attribute (die
, func_decl
)
5550 register dw_die_ref die
;
5551 register tree func_decl
;
5553 if (DECL_VIRTUAL_P (func_decl
))
5555 if ((strcmp (language_string
, "GNU C++") == 0)
5556 && (DECL_VIRTUAL_P (func_decl
)))
5558 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_pure_virtual
);
5562 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
5567 /********************* utility routines for DIEs *************************/
5569 /* Add an DW_AT_name attribute and source coordinate attribute for the
5570 given decl, but only if it actually has a name. */
5572 add_name_and_src_coords_attributes (die
, decl
)
5573 register dw_die_ref die
;
5576 register tree decl_name
= DECL_NAME (decl
);
5577 register unsigned file_index
;
5578 if (decl_name
&& IDENTIFIER_POINTER (decl_name
))
5580 add_name_attribute (die
, IDENTIFIER_POINTER (decl_name
));
5581 file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
5582 add_AT_unsigned (die
, DW_AT_decl_file
, file_index
);
5583 add_AT_unsigned (die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
5587 /* Push a new declaration scope. */
5589 push_decl_scope (scope
)
5592 /* Make room in the decl_scope_table, if necessary. */
5593 if (decl_scope_table_allocated
== decl_scope_depth
)
5595 decl_scope_table_allocated
+= DECL_SCOPE_TABLE_INCREMENT
;
5596 decl_scope_table
= (tree
*) xrealloc (decl_scope_table
,
5597 decl_scope_table_allocated
* sizeof (tree
));
5599 decl_scope_table
[decl_scope_depth
++] = scope
;
5602 /* Return the DIE for the scope the immediately contains this declaration. */
5604 scope_die_for_type (type
, context_die
)
5606 register dw_die_ref context_die
;
5608 register dw_die_ref scope_die
= NULL
;
5609 register tree containing_scope
;
5610 register unsigned long i
;
5612 /* Walk back up the declaration tree looking for a place to define
5614 containing_scope
= TYPE_CONTEXT (type
);
5615 if (containing_scope
== NULL
)
5617 scope_die
= comp_unit_die
;
5621 for (i
= decl_scope_depth
- 1, scope_die
= context_die
;
5623 && scope_die
!= NULL
5624 && decl_scope_table
[i
] != containing_scope
;
5625 --i
, scope_die
= scope_die
->die_parent
)
5629 if (scope_die
== NULL
)
5631 scope_die
= context_die
;
5637 /* Pop a declaration scope. */
5641 assert (decl_scope_depth
> 0);
5645 /* Many forms of DIEs require a "type description" attribute. This
5646 routine locates the proper "type descriptor" die for the type given
5647 by 'type', and adds an DW_AT_type attribute below the given die. */
5649 add_type_attribute (object_die
, type
, decl_const
, decl_volatile
, context_die
)
5650 register dw_die_ref object_die
;
5652 register int decl_const
;
5653 register int decl_volatile
;
5654 register dw_die_ref context_die
;
5656 register enum tree_code code
= TREE_CODE (type
);
5657 register dw_die_ref scope_die
= NULL
;
5658 register dw_die_ref type_die
= NULL
;
5660 if (code
== ERROR_MARK
)
5665 /* Handle a special case. For functions whose return type is void, we
5666 generate *no* type attribute. (Note that no object may have type
5667 `void', so this only applies to function return types). */
5668 if (code
== VOID_TYPE
)
5673 scope_die
= scope_die_for_type (type
, context_die
);
5674 type_die
= modified_type_die (type
,
5675 decl_const
|| TYPE_READONLY (type
),
5676 decl_volatile
|| TYPE_VOLATILE (type
),
5678 if (type_die
!= NULL
)
5680 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
5684 /* Given a tree pointer to a struct, class, union, or enum type node, return
5685 a pointer to the (string) tag name for the given type, or zero if the type
5686 was declared without a tag. */
5691 register char *name
= 0;
5693 if (TYPE_NAME (type
) != 0)
5695 register tree t
= 0;
5697 /* Find the IDENTIFIER_NODE for the type name. */
5698 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
5699 t
= TYPE_NAME (type
);
5701 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
5702 a TYPE_DECL node, regardless of whether or not a `typedef' was
5703 involved. This is distinctly different from what the gcc front-end
5704 does. It always makes the TYPE_NAME for each tagged type be either
5705 NULL (signifying an anonymous tagged type) or else a pointer to an
5706 IDENTIFIER_NODE. Obviously, we would like to generate correct Dwarf
5707 for both C and C++, but given this inconsistency in the TREE
5708 representation of tagged types for C and C++ in the GNU front-ends,
5709 we cannot support both languages correctly unless we introduce some
5710 front-end specific code here, and rms objects to that, so we can
5711 only generate correct Dwarf for one of these two languages. C is
5712 more important, so for now we'll do the right thing for C and let
5714 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
)
5715 t
= DECL_NAME (TYPE_NAME (type
));
5717 /* Now get the name as a string, or invent one. */
5720 name
= IDENTIFIER_POINTER (t
);
5723 return (name
== 0 || *name
== '\0') ? 0 : name
;
5726 /* Return the type associated with a data member, make a special check
5727 for bit field types. */
5729 member_declared_type (member
)
5730 register tree member
;
5732 return (DECL_BIT_FIELD_TYPE (member
))
5733 ? DECL_BIT_FIELD_TYPE (member
)
5734 : TREE_TYPE (member
);
5737 /* Get the function's label, as described by its RTL. This may be different
5738 from the DECL_NAME name used in the source file. */
5740 function_start_label (decl
)
5745 x
= DECL_RTL (decl
);
5746 if (GET_CODE (x
) != MEM
)
5751 if (GET_CODE (x
) != SYMBOL_REF
)
5755 fnname
= XSTR (x
, 0);
5759 /******************************* DIE Generation *************************/
5761 /* These routines generate the internnal representation of the DIE's for
5762 the compilation unit. Debugging information is collected by walking
5763 the declaration trees passed in from dwarfout_file_scope_decl(). */
5766 gen_array_type_die (type
, context_die
)
5768 register dw_die_ref context_die
;
5770 register dw_die_ref scope_die
= scope_die_for_type (type
, context_die
);
5771 register dw_die_ref array_die
= new_die (DW_TAG_array_type
, scope_die
);
5772 register tree element_type
;
5773 /* TODO: why a member_attribute under an array?
5774 member_attribute (array_die, TYPE_CONTEXT (type)); */
5776 /* We default the array ordering. SDB will probably do
5777 the right things even if DW_AT_ordering is not present. It's not even
5778 an issue until we start to get into multidimensional arrays anyway. If
5779 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
5780 then we'll have to put the DW_AT_ordering attribute back in. (But if
5781 and when we find out that we need to put these in, we will only do so
5782 for multidimensional arrays. */
5783 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
5786 add_subscript_info (array_die
, type
);
5788 equate_type_number_to_die (type
, array_die
);
5790 /* Add representation of the type of the elements of this array type. */
5791 element_type
= TREE_TYPE (type
);
5792 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
5793 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
5794 We work around this by disabling this feature. See also
5795 add_subscript_info. */
5796 #ifndef MIPS_DEBUGGING_INFO
5797 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
5799 element_type
= TREE_TYPE (element_type
);
5802 gen_type_die (element_type
, context_die
);
5804 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
5808 gen_set_type_die (type
, context_die
)
5810 register dw_die_ref context_die
;
5812 register dw_die_ref type_die
;
5813 type_die
= new_die (DW_TAG_set_type
, scope_die_for_type (type
, context_die
));
5814 equate_type_number_to_die (type
, type_die
);
5815 add_member_attribute (type_die
, TYPE_CONTEXT (type
));
5816 add_type_attribute (type_die
, TREE_TYPE (type
), 0, 0, context_die
);
5820 gen_entry_point_die (decl
, context_die
)
5822 register dw_die_ref context_die
;
5824 register tree origin
= decl_ultimate_origin (decl
);
5825 register dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
);
5828 add_abstract_origin_attribute (decl_die
, origin
);
5832 add_name_and_src_coords_attributes (decl_die
, decl
);
5833 add_member_attribute (decl_die
, DECL_CONTEXT (decl
));
5834 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
5837 if (DECL_ABSTRACT (decl
))
5839 equate_decl_number_to_die (decl
, decl_die
);
5843 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, function_start_label (decl
));
5847 /* Generate a DIE to represent an inlined instance of an enumeration type. */
5849 gen_inlined_enumeration_type_die (type
, context_die
)
5851 register dw_die_ref context_die
;
5853 register dw_die_ref type_die
;
5854 type_die
= new_die (DW_TAG_enumeration_type
,
5855 scope_die_for_type (type
, context_die
));
5856 assert (TREE_ASM_WRITTEN (type
));
5857 add_abstract_origin_attribute (type_die
, type
);
5860 /* Generate a DIE to represent an inlined instance of a structure type. */
5862 gen_inlined_structure_type_die (type
, context_die
)
5864 register dw_die_ref context_die
;
5866 register dw_die_ref type_die
;
5867 type_die
= new_die (DW_TAG_structure_type
,
5868 scope_die_for_type (type
, context_die
));
5869 assert (TREE_ASM_WRITTEN (type
));
5870 add_abstract_origin_attribute (type_die
, type
);
5873 /* Generate a DIE to represent an inlined instance of a union type. */
5875 gen_inlined_union_type_die (type
, context_die
)
5877 register dw_die_ref context_die
;
5879 register dw_die_ref type_die
;
5880 type_die
= new_die (DW_TAG_union_type
,
5881 scope_die_for_type (type
, context_die
));
5882 assert (TREE_ASM_WRITTEN (type
));
5883 add_abstract_origin_attribute (type_die
, type
);
5886 /* Generate a DIE to represent an enumeration type. Note that these DIEs
5887 include all of the information about the enumeration values also. Each
5888 enumerated type name/value is listed as a child of the enumerated type DIE */
5890 gen_enumeration_type_die (type
, is_complete
, context_die
)
5892 register unsigned is_complete
;
5893 register dw_die_ref context_die
;
5895 register dw_die_ref type_die
;
5896 register dw_die_ref enum_die
;
5898 type_die
= lookup_type_die (type
);
5899 if (type_die
== NULL
)
5901 type_die
= new_die (DW_TAG_enumeration_type
,
5902 scope_die_for_type (type
, context_die
));
5903 equate_type_number_to_die (type
, type_die
);
5904 add_name_attribute (type_die
, type_tag (type
));
5905 add_member_attribute (type_die
, TYPE_CONTEXT (type
));
5909 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
5910 given enum type is incomplete, do not generate the DW_AT_byte_size
5911 attribute or the DW_AT_element_list attribute. */
5912 if (TYPE_SIZE (type
))
5914 add_byte_size_attribute (type_die
, type
);
5915 for (link
= TYPE_FIELDS (type
);
5916 link
!= NULL
; link
= TREE_CHAIN (link
))
5918 enum_die
= new_die (DW_TAG_enumerator
, type_die
);
5919 add_name_attribute (enum_die
,
5920 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
5921 add_AT_unsigned (enum_die
, DW_AT_const_value
,
5922 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link
)));
5929 /* Generate a DIE to represent either a real live formal parameter decl or to
5930 represent just the type of some formal parameter position in some function
5932 Note that this routine is a bit unusual because its argument may be a
5933 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
5934 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
5935 node. If it's the former then this function is being called to output a
5936 DIE to represent a formal parameter object (or some inlining thereof). If
5937 it's the latter, then this function is only being called to output a
5938 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
5939 argument type of some subprogram type. */
5941 gen_formal_parameter_die (node
, context_die
)
5943 register dw_die_ref context_die
;
5945 register dw_die_ref parm_die
= new_die (DW_TAG_formal_parameter
,
5947 register tree origin
;
5948 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
5950 /* We were called with some kind of a ..._DECL node. */
5952 origin
= decl_ultimate_origin (node
);
5955 add_abstract_origin_attribute (parm_die
, origin
);
5959 add_name_and_src_coords_attributes (parm_die
, node
);
5960 add_type_attribute (parm_die
, TREE_TYPE (node
),
5961 TREE_READONLY (node
),
5962 TREE_THIS_VOLATILE (node
),
5965 if (DECL_ABSTRACT (node
))
5967 equate_decl_number_to_die (node
, parm_die
);
5971 add_location_or_const_value_attribute (parm_die
, node
);
5975 /* We were called with some kind of a ..._TYPE node. */
5977 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
5980 /* Should never happen. */
5986 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
5987 at the end of an (ANSI prototyped) formal parameters list. */
5989 gen_unspecified_parameters_die (decl_or_type
, context_die
)
5990 register tree decl_or_type
;
5991 register dw_die_ref context_die
;
5993 register dw_die_ref parm_die
= new_die (DW_TAG_unspecified_parameters
,
5995 /* This kludge is here only for the sake of being compatible with what the
5996 USL CI5 C compiler does. The specification of Dwarf Version 1 doesn't
5997 say that DW_TAG_unspecified_parameters DIEs should contain any
5998 attributes other than the DW_AT_sibling attribute, but they are
5999 certainly allowed to contain additional attributes, and the CI5 compiler
6000 generates DW_AT_name, DW_AT_base_type, and DW_AT_location attributes
6001 within DW_TAG_unspecified_parameters DIEs which appear in the child
6002 lists for DIEs representing function definitions, so we do likewise
6004 if (TREE_CODE (decl_or_type
) == FUNCTION_DECL
6005 && DECL_INITIAL (decl_or_type
))
6007 add_name_attribute (parm_die
, "...");
6008 add_AT_die_ref (parm_die
, DW_AT_type
, int_base_type_die
);
6012 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
6013 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
6014 parameters as specified in some function type specification (except for
6015 those which appear as part of a function *definition*).
6016 Note that we must be careful here to output all of the parameter DIEs before*
6017 we output any DIEs needed to represent the types of the formal parameters.
6018 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
6019 non-parameter DIE it sees ends the formal parameter list. */
6021 gen_formal_types_die (function_or_method_type
, context_die
)
6022 register tree function_or_method_type
;
6023 register dw_die_ref context_die
;
6026 register tree formal_type
= NULL
;
6027 register tree first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
6029 /* In the case where we are generating a formal types list for a C++
6030 non-static member function type, skip over the first thing on the
6031 TYPE_ARG_TYPES list because it only represents the type of the hidden
6032 `this pointer'. The debugger should be able to figure out (without
6033 being explicitly told) that this non-static member function type takes a
6034 `this pointer' and should be able to figure what the type of that hidden
6035 parameter is from the DW_AT_member attribute of the parent
6036 DW_TAG_subroutine_type DIE. */
6037 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
)
6038 first_parm_type
= TREE_CHAIN (first_parm_type
);
6040 /* Make our first pass over the list of formal parameter types and output a
6041 DW_TAG_formal_parameter DIE for each one. */
6042 for (link
= first_parm_type
; link
; link
= TREE_CHAIN (link
))
6044 formal_type
= TREE_VALUE (link
);
6045 if (formal_type
== void_type_node
)
6048 /* Output a (nameless) DIE to represent the formal parameter itself. */
6049 gen_formal_parameter_die (formal_type
, context_die
);
6052 /* If this function type has an ellipsis, add a
6053 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
6054 if (formal_type
!= void_type_node
)
6055 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
6057 /* Make our second (and final) pass over the list of formal parameter types
6058 and output DIEs to represent those types (as necessary). */
6059 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
6061 link
= TREE_CHAIN (link
))
6063 formal_type
= TREE_VALUE (link
);
6064 if (formal_type
== void_type_node
)
6067 gen_type_die (formal_type
, function_or_method_type
, context_die
);
6071 /* Generate a DIE to represent a declared function (either file-scope or
6074 gen_subprogram_die (decl
, context_die
)
6076 register dw_die_ref context_die
;
6078 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
6079 register tree origin
= decl_ultimate_origin (decl
);
6080 register dw_die_ref subr_die
= new_die (DW_TAG_subprogram
, context_die
);
6081 register dw_loc_descr_ref fp_loc
= NULL
;
6082 register unsigned fp_reg
;
6084 register tree fn_arg_types
;
6085 register tree outer_scope
;
6086 register tree label
;
6090 add_abstract_origin_attribute (subr_die
, origin
);
6094 if (TREE_PUBLIC (decl
) || DECL_EXTERNAL (decl
))
6096 add_AT_flag (subr_die
, DW_AT_external
, 1);
6098 add_name_and_src_coords_attributes (subr_die
, decl
);
6099 if (DECL_INLINE (decl
))
6101 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
6103 type
= TREE_TYPE (decl
);
6104 add_prototyped_attribute (subr_die
, type
);
6105 add_member_attribute (subr_die
, DECL_CONTEXT (decl
));
6106 add_type_attribute (subr_die
, TREE_TYPE (type
), 0, 0, context_die
);
6107 add_pure_or_virtual_attribute (subr_die
, decl
);
6109 if (DECL_ABSTRACT (decl
))
6111 equate_decl_number_to_die (decl
, subr_die
);
6113 else if (!DECL_EXTERNAL (decl
))
6116 equate_decl_number_to_die (decl
, subr_die
);
6117 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, function_start_label (decl
));
6118 sprintf (label_id
, FUNC_END_LABEL_FMT
, current_funcdef_number
);
6119 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
6121 #ifdef MIPS_DEBUGGING_INFO
6123 /* Add a reference to the FDE for this routine. */
6124 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
6127 /* Define the frame pointer location for this routine. */
6128 fp_reg
= (frame_pointer_needed
) ? FRAME_POINTER_REGNUM
6129 : STACK_POINTER_REGNUM
;
6130 assert (fp_reg
>= 0 && fp_reg
<= 31);
6131 fp_loc
= new_loc_descr (DW_OP_breg0
+ fp_reg
, current_funcdef_frame_size
);
6132 add_AT_loc (subr_die
, DW_AT_frame_base
, fp_loc
);
6134 #ifdef DWARF_GNU_EXTENSIONS
6135 sprintf (label_id
, BODY_BEGIN_LABEL_FMT
, current_funcdef_number
);
6136 add_AT_lbl_id (subr_die
, DW_AT_body_begin
, label_id
);
6137 sprintf (label_id
, BODY_END_LABEL_FMT
, current_funcdef_number
);
6138 add_AT_lbl_id (subr_die
, DW_AT_body_end
, label_id
);
6143 /* Now output descriptions of the arguments for this function. This gets
6144 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
6145 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
6146 `...' at the end of the formal parameter list. In order to find out if
6147 there was a trailing ellipsis or not, we must instead look at the type
6148 associated with the FUNCTION_DECL. This will be a node of type
6149 FUNCTION_TYPE. If the chain of type nodes hanging off of this
6150 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
6151 an ellipsis at the end. */
6153 /* In the case where we are describing a mere function declaration, all we
6154 need to do here (and all we *can* do here) is to describe the *types* of
6155 its formal parameters. */
6156 if (DECL_INITIAL (decl
) == NULL_TREE
)
6158 gen_formal_types_die (TREE_TYPE (decl
), subr_die
);
6162 /* Generate DIEs to represent all known formal parameters */
6163 register tree arg_decls
= DECL_ARGUMENTS (decl
);
6166 /* When generating DIEs, generate the unspecified_parameters DIE
6167 instead if we come across the arg "__builtin_va_alist" */
6168 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
6170 if (TREE_CODE (parm
) == PARM_DECL
)
6172 if (DECL_NAME (parm
) &&
6173 !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
6174 "__builtin_va_alist"))
6176 gen_unspecified_parameters_die (parm
, subr_die
);
6180 gen_decl_die (parm
, subr_die
);
6185 /* Decide whether we need a unspecified_parameters DIE at the end.
6186 There are 2 more cases to do this for: 1) the ansi ... declaration -
6187 this is detectable when the end of the arg list is not a
6188 void_type_node 2) an unprototyped function declaration (not a
6189 definition). This just means that we have no info about the
6190 parameters at all. */
6191 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
6194 /* this is the prototyped case, check for ... */
6195 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
6197 gen_unspecified_parameters_die (decl
, subr_die
);
6202 /* this is unprotoyped, check for undefined (just declaration) */
6203 if (!DECL_INITIAL (decl
))
6205 gen_unspecified_parameters_die (decl
, subr_die
);
6210 /* Output Dwarf info for all of the stuff within the body of the function
6211 (if it has one - it may be just a declaration). */
6212 outer_scope
= DECL_INITIAL (decl
);
6214 if (outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
6216 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
6217 node created to represent a function. This outermost BLOCK actually
6218 represents the outermost binding contour for the function, i.e. the
6219 contour in which the function's formal parameters and labels get
6220 declared. Curiously, it appears that the front end doesn't actually
6221 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
6222 list for this outer scope. (They are strung off of the
6223 DECL_ARGUMENTS list for the function instead.) The BLOCK_VARS list
6224 for the `outer_scope' does provide us with a list of the LABEL_DECL
6225 nodes for the function however, and we output DWARF info for those
6226 here. Just within the `outer_scope' there will be another BLOCK node
6227 representing the function's outermost pair of curly braces. We
6228 musn't generate a lexical_block DIE for this outermost pair of curly
6229 braces because that is not really an independent scope according to
6230 ANSI C rules. Rather, it is the same scope in which the parameters
6232 for (label
= BLOCK_VARS (outer_scope
);
6234 label
= TREE_CHAIN (label
))
6236 gen_decl_die (label
, subr_die
);
6239 /* Note here that `BLOCK_SUBBLOCKS (outer_scope)' points to a list of
6240 BLOCK nodes which is always only one element long. That one element
6241 represents the outermost pair of curley braces for the function
6243 decls_for_scope (BLOCK_SUBBLOCKS (outer_scope
), subr_die
);
6247 /* Generate a DIE to represent a declared data object. */
6249 gen_variable_die (decl
, context_die
)
6251 register dw_die_ref context_die
;
6253 register tree origin
= decl_ultimate_origin (decl
);
6254 register dw_die_ref var_die
= new_die (DW_TAG_variable
, context_die
);
6255 if (TREE_PUBLIC (decl
) || DECL_EXTERNAL (decl
))
6257 add_AT_flag (var_die
, DW_AT_external
, 1);
6261 add_abstract_origin_attribute (var_die
, origin
);
6265 add_name_and_src_coords_attributes (var_die
, decl
);
6266 add_member_attribute (var_die
, DECL_CONTEXT (decl
));
6267 add_type_attribute (var_die
, TREE_TYPE (decl
),
6268 TREE_READONLY (decl
),
6269 TREE_THIS_VOLATILE (decl
), context_die
);
6271 if (DECL_ABSTRACT (decl
))
6273 equate_decl_number_to_die (decl
, var_die
);
6275 else if (!DECL_EXTERNAL (decl
))
6277 add_location_or_const_value_attribute (var_die
, decl
);
6281 /* Generate a DIE to represent a label identifier. */
6283 gen_label_die (decl
, context_die
)
6285 register dw_die_ref context_die
;
6287 register tree origin
= decl_ultimate_origin (decl
);
6288 register dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
);
6290 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6293 add_abstract_origin_attribute (lbl_die
, origin
);
6297 add_name_and_src_coords_attributes (lbl_die
, decl
);
6299 if (DECL_ABSTRACT (decl
))
6301 equate_decl_number_to_die (decl
, lbl_die
);
6305 insn
= DECL_RTL (decl
);
6306 if (GET_CODE (insn
) == CODE_LABEL
)
6308 /* When optimization is enabled (via -O) some parts of the compiler
6309 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
6310 represent source-level labels which were explicitly declared by
6311 the user. This really shouldn't be happening though, so catch
6312 it if it ever does happen. */
6313 if (INSN_DELETED_P (insn
))
6315 abort (); /* Should never happen. */
6317 sprintf (label
, INSN_LABEL_FMT
, current_funcdef_number
,
6318 (unsigned) INSN_UID (insn
));
6319 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
6324 /* Generate a DIE for a lexical block. */
6326 gen_lexical_block_die (stmt
, context_die
)
6328 register dw_die_ref context_die
;
6330 register dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
);
6331 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6332 if (!BLOCK_ABSTRACT (stmt
))
6334 sprintf (label
, BLOCK_BEGIN_LABEL_FMT
, next_block_number
);
6335 add_AT_lbl_id (stmt_die
, DW_AT_low_pc
, label
);
6336 sprintf (label
, BLOCK_END_LABEL_FMT
, next_block_number
);
6337 add_AT_lbl_id (stmt_die
, DW_AT_high_pc
, label
);
6339 decls_for_scope (stmt
, stmt_die
);
6342 /* Generate a DIE for an inlined subprogram. */
6344 gen_inlined_subroutine_die (stmt
, context_die
)
6346 register dw_die_ref context_die
;
6348 register dw_die_ref subr_die
= new_die (DW_TAG_inlined_subroutine
,
6350 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6351 add_abstract_origin_attribute (subr_die
, block_ultimate_origin (stmt
));
6352 if (!BLOCK_ABSTRACT (stmt
))
6354 sprintf (label
, BLOCK_BEGIN_LABEL_FMT
, next_block_number
);
6355 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label
);
6356 sprintf (label
, BLOCK_END_LABEL_FMT
, next_block_number
);
6357 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label
);
6359 decls_for_scope (stmt
, subr_die
);
6362 /* Generate a DIE for a field in a record, or structure. */
6364 gen_field_die (decl
, context_die
)
6366 register dw_die_ref context_die
;
6368 register dw_die_ref decl_die
= new_die (DW_TAG_member
, context_die
);
6369 add_name_and_src_coords_attributes (decl_die
, decl
);
6370 add_member_attribute (decl_die
, DECL_CONTEXT (decl
));
6371 add_type_attribute (decl_die
, member_declared_type (decl
),
6372 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
6374 /* If this is a bit field... */
6375 if (DECL_BIT_FIELD_TYPE (decl
))
6377 add_byte_size_attribute (decl_die
, decl
);
6378 add_bit_size_attribute (decl_die
, decl
);
6379 add_bit_offset_attribute (decl_die
, decl
);
6381 add_data_member_location_attribute (decl_die
, decl
);
6384 /* Don't generate either pointer_type DIEs or reference_type DIEs.
6385 Use modified type DIE's instead.
6386 We keep this code here just in case these types of DIEs may be needed to
6387 represent certain things in other languages (e.g. Pascal) someday. */
6389 gen_pointer_type_die (type
, context_die
)
6391 register dw_die_ref context_die
;
6393 register dw_die_ref ptr_die
= new_die (DW_TAG_pointer_type
, context_die
);
6394 equate_type_number_to_die (type
, ptr_die
);
6395 add_member_attribute (ptr_die
, TYPE_CONTEXT (type
));
6396 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
6399 /* Don't generate either pointer_type DIEs or reference_type DIEs.
6400 Use modified type DIE's instead.
6401 We keep this code here just in case these types of DIEs may be needed to
6402 represent certain things in other languages (e.g. Pascal) someday. */
6404 gen_reference_type_die (type
, context_die
)
6406 register dw_die_ref context_die
;
6408 register dw_die_ref ref_die
= new_die (DW_TAG_reference_type
, context_die
);
6409 equate_type_number_to_die (type
, ref_die
);
6410 add_member_attribute (ref_die
, TYPE_CONTEXT (type
));
6411 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
6414 /* Generate a DIE for a pointer to a member type. */
6416 gen_ptr_to_mbr_type_die (type
, context_die
)
6418 register dw_die_ref context_die
;
6420 register dw_die_ref ptr_die
= new_die (DW_TAG_ptr_to_member_type
,
6422 equate_type_number_to_die (type
, ptr_die
);
6423 add_member_attribute (ptr_die
, TYPE_CONTEXT (type
));
6424 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
6425 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
6426 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
6429 /* Generate the DIE for the compilation unit. */
6431 gen_compile_unit_die (main_input_filename
)
6432 register char *main_input_filename
;
6435 char full_src_name
[1024];
6436 char *wd
= getpwd ();
6438 comp_unit_die
= new_die (DW_TAG_compile_unit
, NULL
);
6440 /* MIPS/SGI requires the full pathname of the input file. */
6441 if (main_input_filename
[0] == '/')
6443 add_name_attribute (comp_unit_die
, main_input_filename
);
6447 sprintf (full_src_name
, "%s/%s", wd
, main_input_filename
);
6448 add_name_attribute (comp_unit_die
, full_src_name
);
6451 sprintf (producer
, "%s %s", language_string
, version_string
);
6453 #ifdef MIPS_DEBUGGING_INFO
6454 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
6455 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
6456 not appear in the producer string, the debugger reaches the conclusion
6457 that the object file is stripped and has no debugging information.
6458 To get the MIPS/SGI debugger to believe that there is debugging
6459 information in the object file, we add a -g to the producer string. */
6460 if (write_symbols
!= NO_DEBUG
)
6462 strcpy (producer
, " -g");
6467 add_AT_string (comp_unit_die
, DW_AT_producer
, producer
);
6468 if (strcmp (language_string
, "GNU C++") == 0)
6470 add_AT_unsigned (comp_unit_die
, DW_AT_language
, DW_LANG_C_plus_plus
);
6472 else if (strcmp (language_string
, "GNU Ada") == 0)
6474 add_AT_unsigned (comp_unit_die
, DW_AT_language
, DW_LANG_Ada83
);
6476 else if (flag_traditional
)
6478 add_AT_unsigned (comp_unit_die
, DW_AT_language
, DW_LANG_C
);
6482 add_AT_unsigned (comp_unit_die
, DW_AT_language
, DW_LANG_C89
);
6484 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, TEXT_BEGIN_LABEL
);
6485 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, TEXT_END_LABEL
);
6488 add_AT_string (comp_unit_die
, DW_AT_comp_dir
, wd
);
6490 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
6492 add_AT_section_offset (comp_unit_die
, DW_AT_stmt_list
, LINE_SECTION
);
6493 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
6495 add_AT_unsigned (comp_unit_die
, DW_AT_macro_info
, 0);
6500 /* Generate a DIE for a string type. */
6502 gen_string_type_die (type
, context_die
)
6504 register dw_die_ref context_die
;
6506 register dw_die_ref type_die
;
6507 type_die
= new_die (DW_TAG_string_type
,
6508 scope_die_for_type (type
, context_die
));
6509 add_member_attribute (type_die
, TYPE_CONTEXT (type
));
6511 /* Fudge the string length attribute for now. */
6513 /* TODO: add string length info.
6514 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
6515 bound_representation (upper_bound, 0, 'u'); */
6518 /* Genearate a DIE for a class member. */
6520 gen_member_die (type
, context_die
)
6522 register dw_die_ref context_die
;
6524 register tree normal_member
;
6525 register tree vec_base
;
6526 register tree first_func_member
;
6527 register tree func_member
;
6528 /* If this is not an incomplete type, output descriptions of each of its
6529 members. Note that as we output the DIEs necessary to represent the
6530 members of this record or union type, we will also be trying to output
6531 DIEs to represent the *types* of those members. However the `type'
6532 function (above) will specifically avoid generating type DIEs for member
6533 types *within* the list of member DIEs for this (containing) type execpt
6534 for those types (of members) which are explicitly marked as also being
6535 members of this (containing) type themselves. The g++ front- end can
6536 force any given type to be treated as a member of some other
6537 (containing) type by setting the TYPE_CONTEXT of the given (member) type
6538 to point to the TREE node representing the appropriate (containing)
6541 /* First output info about the data members and type members. */
6542 for (normal_member
= TYPE_FIELDS (type
);
6544 normal_member
= TREE_CHAIN (normal_member
))
6546 gen_decl_die (normal_member
, context_die
);
6549 /* Now output info about the function members (if any). */
6550 vec_base
= TYPE_METHODS (type
);
6553 first_func_member
= TREE_VEC_ELT (vec_base
, 0);
6554 /* This isn't documented, but the first element of the vector of member
6555 functions can be NULL in cases where the class type in question
6556 didn't have either a constructor or a destructor declared for it.
6557 We have to make allowances for that here. */
6558 if (first_func_member
== NULL
)
6560 first_func_member
= TREE_VEC_ELT (vec_base
, 1);
6563 for (func_member
= first_func_member
;
6565 func_member
= TREE_CHAIN (func_member
))
6567 gen_decl_die (func_member
, context_die
);
6572 /* Generate a DIE for a structure or union type. */
6574 gen_struct_or_union_type_die (type
, is_complete
, context_die
)
6576 register unsigned is_complete
;
6577 register dw_die_ref context_die
;
6579 register dw_die_ref type_die
;
6580 type_die
= lookup_type_die (type
);
6581 if (type_die
== NULL
)
6583 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
6584 ? DW_TAG_structure_type
: DW_TAG_union_type
,
6585 scope_die_for_type (type
, context_die
));
6586 equate_type_number_to_die (type
, type_die
);
6587 add_name_attribute (type_die
, type_tag (type
));
6588 add_member_attribute (type_die
, TYPE_CONTEXT (type
));
6591 /* If this type has been completed, then give it a byte_size attribute and
6592 then give a list of members. */
6595 /* Prevent infinite recursion in cases where the type of some member of
6596 this type is expressed in terms of this type itself. */
6597 TREE_ASM_WRITTEN (type
) = 1;
6598 if (TYPE_SIZE (type
))
6600 add_byte_size_attribute (type_die
, type
);
6601 gen_member_die (type
, type_die
);
6606 /* Generate a DIE for a subroutine _type_. */
6608 gen_subroutine_type_die (type
, context_die
)
6610 register dw_die_ref context_die
;
6612 register tree return_type
= TREE_TYPE (type
);
6613 register dw_die_ref subr_die
= new_die (DW_TAG_subroutine_type
, context_die
);
6614 equate_type_number_to_die (type
, subr_die
);
6615 add_prototyped_attribute (subr_die
, type
);
6616 add_member_attribute (subr_die
, TYPE_CONTEXT (type
));
6617 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
6618 gen_formal_types_die (type
, context_die
);
6621 /* Generate a DIE for a type definition */
6623 gen_typedef_die (decl
, context_die
)
6625 register dw_die_ref context_die
;
6627 register tree origin
= decl_ultimate_origin (decl
);
6628 register dw_die_ref type_die
;
6629 type_die
= new_die (DW_TAG_typedef
,
6630 scope_die_for_type (decl
, context_die
));
6633 add_abstract_origin_attribute (type_die
, origin
);
6637 add_name_and_src_coords_attributes (type_die
, decl
);
6638 add_member_attribute (type_die
, DECL_CONTEXT (decl
));
6639 add_type_attribute (type_die
, TREE_TYPE (decl
),
6640 TREE_READONLY (decl
),
6641 TREE_THIS_VOLATILE (decl
),
6644 if (DECL_ABSTRACT (decl
))
6646 equate_decl_number_to_die (decl
, type_die
);
6650 /* Generate a type description DIE. */
6652 gen_type_die (type
, context_die
)
6654 register dw_die_ref context_die
;
6656 register unsigned is_complete
;
6657 if (type
== 0 || type
== error_mark_node
)
6662 /* We are going to output a DIE to represent the unqualified version of of
6663 this type (i.e. without any const or volatile qualifiers) so get the
6664 main variant (i.e. the unqualified version) of this type now. */
6665 type
= type_main_variant (type
);
6667 if (TREE_ASM_WRITTEN (type
))
6672 switch (TREE_CODE (type
))
6678 case REFERENCE_TYPE
:
6679 /* For these types, all that is required is that we output a DIE (or a
6680 set of DIEs) to represent the "basis" type. */
6681 gen_type_die (TREE_TYPE (type
), context_die
);
6685 /* This code is used for C++ pointer-to-data-member types. */
6686 /* Output a description of the relevant class type. */
6687 gen_type_die (TYPE_OFFSET_BASETYPE (type
), context_die
);
6688 /* Output a description of the type of the object pointed to. */
6689 gen_type_die (TREE_TYPE (type
), context_die
);
6690 /* Now output a DIE to represent this pointer-to-data-member type
6692 gen_ptr_to_mbr_type_die (type
, context_die
);
6696 gen_type_die (TYPE_DOMAIN (type
), context_die
);
6697 gen_set_type_die (type
, context_die
);
6701 gen_type_die (TREE_TYPE (type
), context_die
);
6702 abort (); /* No way to represent these in Dwarf yet! */
6706 /* Force out return type (in case it wasn't forced out already). */
6707 gen_type_die (TREE_TYPE (type
), context_die
);
6708 gen_subroutine_type_die (type
, context_die
);
6712 /* Force out return type (in case it wasn't forced out already). */
6713 gen_type_die (TREE_TYPE (type
), context_die
);
6714 gen_subroutine_type_die (type
, context_die
);
6718 if (TYPE_STRING_FLAG (type
) && TREE_CODE (TREE_TYPE (type
)) == CHAR_TYPE
)
6720 gen_type_die (TREE_TYPE (type
), context_die
);
6721 gen_string_type_die (type
, context_die
);
6725 gen_array_type_die (type
, context_die
);
6732 case QUAL_UNION_TYPE
:
6733 /* For a non-file-scope tagged type, we can always go ahead and output
6734 a Dwarf description of this type right now, even if the type in
6735 question is still incomplete, because if this local type *was* ever
6736 completed anywhere within its scope, that complete definition would
6737 already have been attached to this RECORD_TYPE, UNION_TYPE,
6738 QUAL_UNION_TYPE or ENUMERAL_TYPE node by the time we reach this
6739 point. That's true because of the way the front-end does its
6740 processing of file-scope declarations (of functions and class types)
6741 within which other types might be nested. The C and C++ front-ends
6742 always gobble up such "local scope" things en-mass before they try
6743 to output *any* debugging information for any of the stuff contained
6744 inside them and thus, we get the benefit here of what is (in effect)
6745 a pre-resolution of forward references to tagged types in local
6746 scopes. Note however that for file-scope tagged types we cannot
6747 assume that such pre-resolution of forward references has taken
6748 place. A given file-scope tagged type may appear to be incomplete
6749 when we reach this point, but it may yet be given a full definition
6750 (at file-scope) later on during compilation. In order to avoid
6751 generating a premature (and possibly incorrect) set of Dwarf DIEs
6752 for such (as yet incomplete) file-scope tagged types, we generate
6753 nothing at all for as-yet incomplete file-scope tagged types here
6754 unless we are making our special "finalization" pass for file-scope
6755 things at the very end of compilation. At that time, we will
6756 certainly know as much about each file-scope tagged type as we are
6757 ever going to know, so at that point in time, we can safely generate
6758 correct Dwarf descriptions for these file-scope tagged types. */
6759 is_complete
= TYPE_SIZE (type
) != 0
6760 || TYPE_CONTEXT (type
) != NULL
6762 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
6764 gen_enumeration_type_die (type
, is_complete
, context_die
);
6768 gen_struct_or_union_type_die (type
, is_complete
, context_die
);
6778 /* No DIEs needed for fundamental types. */
6782 /* No Dwarf representation currently defined. */
6789 TREE_ASM_WRITTEN (type
) = 1;
6792 /* Generate a DIE for a tagged type instantiation. */
6794 gen_tagged_type_instantiation_die (type
, context_die
)
6796 register dw_die_ref context_die
;
6798 if (type
== 0 || type
== error_mark_node
)
6803 /* We are going to output a DIE to represent the unqualified version of of
6804 this type (i.e. without any const or volatile qualifiers) so make sure
6805 that we have the main variant (i.e. the unqualified version) of this
6807 assert (type
== type_main_variant (type
));
6808 assert (TREE_ASM_WRITTEN (type
));
6810 switch (TREE_CODE (type
))
6816 gen_inlined_enumeration_type_die (type
, context_die
);
6820 gen_inlined_structure_type_die (type
, context_die
);
6824 case QUAL_UNION_TYPE
:
6825 gen_inlined_union_type_die (type
, context_die
);
6829 abort (); /* Should never happen. */
6833 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
6834 things which are local to the given block. */
6836 gen_block_die (stmt
, context_die
)
6838 register dw_die_ref context_die
;
6840 register int must_output_die
= 0;
6841 register tree origin
;
6843 register enum tree_code origin_code
;
6845 /* Ignore blocks never really used to make RTL. */
6847 if (!stmt
|| !TREE_USED (stmt
))
6852 /* Determine the "ultimate origin" of this block. This block may be an
6853 inlined instance of an inlined instance of inline function, so we have
6854 to trace all of the way back through the origin chain to find out what
6855 sort of node actually served as the original seed for the creation of
6856 the current block. */
6857 origin
= block_ultimate_origin (stmt
);
6858 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
6860 /* Determine if we need to output any Dwarf DIEs at all to represent this
6862 if (origin_code
== FUNCTION_DECL
)
6864 /* The outer scopes for inlinings *must* always be represented. We
6865 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
6866 must_output_die
= 1;
6870 /* In the case where the current block represents an inlining of the
6871 "body block" of an inline function, we must *NOT* output any DIE for
6872 this block because we have already output a DIE to represent the
6873 whole inlined function scope and the "body block" of any function
6874 doesn't really represent a different scope according to ANSI C
6875 rules. So we check here to make sure that this block does not
6876 represent a "body block inlining" before trying to set the
6877 `must_output_die' flag. */
6878 if (origin
== NULL
|| !is_body_block (origin
))
6880 /* Determine if this block directly contains any "significant"
6881 local declarations which we will need to output DIEs for. */
6882 if (debug_info_level
> DINFO_LEVEL_TERSE
)
6884 /* We are not in terse mode so *any* local declaration counts
6885 as being a "significant" one. */
6886 must_output_die
= (BLOCK_VARS (stmt
) != NULL
);
6890 /* We are in terse mode, so only local (nested) function
6891 definitions count as "significant" local declarations. */
6892 for (decl
= BLOCK_VARS (stmt
);
6893 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
6895 if (TREE_CODE (decl
) == FUNCTION_DECL
6896 && DECL_INITIAL (decl
))
6898 must_output_die
= 1;
6906 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
6907 DIE for any block which contains no significant local declarations at
6908 all. Rather, in such cases we just call `decls_for_scope' so that any
6909 needed Dwarf info for any sub-blocks will get properly generated. Note
6910 that in terse mode, our definition of what constitutes a "significant"
6911 local declaration gets restricted to include only inlined function
6912 instances and local (nested) function definitions. */
6913 if (must_output_die
)
6915 if (origin_code
== FUNCTION_DECL
)
6917 gen_inlined_subroutine_die (stmt
, context_die
);
6921 gen_lexical_block_die (stmt
, context_die
);
6925 decls_for_scope (stmt
, context_die
);
6928 /* Generate all of the decls declared within a given scope and (recursively)
6929 all of it's sub-blocks. */
6931 decls_for_scope (stmt
, context_die
)
6933 register dw_die_ref context_die
;
6936 register tree subblocks
;
6937 /* Ignore blocks never really used to make RTL. */
6938 if (!stmt
|| !TREE_USED (stmt
))
6942 if (!BLOCK_ABSTRACT (stmt
))
6944 next_block_number
++;
6947 /* Output the DIEs to represent all of the data objects, functions,
6948 typedefs, and tagged types declared directly within this block but not
6949 within any nested sub-blocks. */
6950 for (decl
= BLOCK_VARS (stmt
);
6951 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
6953 gen_decl_die (decl
, context_die
);
6956 /* Output the DIEs to represent all sub-blocks (and the items declared
6957 therein) of this block. */
6958 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
6960 subblocks
= BLOCK_CHAIN (subblocks
))
6962 gen_block_die (subblocks
, context_die
);
6966 /* Generate Dwarf debug information for a decl described by DECL. */
6968 gen_decl_die (decl
, context_die
)
6970 register dw_die_ref context_die
;
6972 register tree origin
;
6973 /* Make a note of the decl node we are going to be working on. We may need
6974 to give the user the source coordinates of where it appeared in case we
6975 notice (later on) that something about it looks screwy. */
6976 dwarf_last_decl
= decl
;
6978 if (TREE_CODE (decl
) == ERROR_MARK
)
6983 /* If this ..._DECL node is marked to be ignored, then ignore it. But don't
6984 ignore a function definition, since that would screw up our count of
6985 blocks, and that it turn will completely screw up the the labels we will
6986 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
6987 subsequent blocks). */
6988 if (DECL_IGNORED_P (decl
) && TREE_CODE (decl
) != FUNCTION_DECL
)
6993 push_decl_scope (DECL_CONTEXT (decl
));
6994 switch (TREE_CODE (decl
))
6997 /* The individual enumerators of an enum type get output when we output
6998 the Dwarf representation of the relevant enum type itself. */
7002 /* If we are in terse mode, don't output any DIEs to represent mere
7003 function declarations. */
7004 if (DECL_INITIAL (decl
) == NULL_TREE
)
7008 /* Before we describe the FUNCTION_DECL itself, make sure that we have
7009 described its return type. */
7010 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
7012 /* Now output a DIE to represent the function itself. */
7013 gen_subprogram_die (decl
, context_die
);
7017 /* If we are in terse mode, don't generate any DIEs to represent any
7018 actual typedefs. Note that even when we are in terse mode, we must
7019 still output DIEs to represent those tagged types which are used
7020 (directly or indirectly) in the specification of either a return
7021 type or a formal parameter type of some function. */
7022 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
7024 if (DECL_NAME (decl
) != NULL
7025 || !TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl
)))
7031 /* In the special case of a null-named TYPE_DECL node (representing the
7032 declaration of some type tag), if the given TYPE_DECL is marked as
7033 having been instantiated from some other (original) TYPE_DECL node
7034 (e.g. one which was generated within the original definition of an
7035 inline function) we have to generate a special (abbreviated)
7036 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration-type
7038 if (!DECL_NAME (decl
) && DECL_ABSTRACT_ORIGIN (decl
))
7040 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
7043 gen_type_die (TREE_TYPE (decl
), context_die
);
7045 /* Note that unlike the gcc front end (which generates a NULL named
7046 TYPE_DECL node for each complete tagged type, each array type, and
7047 each function type node created) the g++ front end generates a
7048 _named_ TYPE_DECL node for each tagged type node created.
7049 Unfortunately, these g++ TYPE_DECL nodes cause us to output many
7050 superfluous and unnecessary DW_TAG_typedef DIEs here. When g++ is
7051 fixed to stop generating these superfluous named TYPE_DECL nodes,
7052 the superfluous DW_TAG_typedef DIEs will likewise cease. */
7053 if (DECL_NAME (decl
))
7055 /* Output a DIE to represent the typedef itself. */
7056 gen_typedef_die (decl
, context_die
);
7061 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
7063 gen_label_die (decl
, context_die
);
7068 /* If we are in terse mode, don't generate any DIEs to represent any
7069 variable declarations or definitions. */
7070 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
7075 /* Output any DIEs that are needed to specify the type of this data
7077 gen_type_die (TREE_TYPE (decl
), context_die
);
7079 /* Now output the DIE to represent the data object itself. This gets
7080 complicated because of the possibility that the VAR_DECL really
7081 represents an inlined instance of a formal parameter for an inline
7083 origin
= decl_ultimate_origin (decl
);
7084 if (origin
!= NULL
&& TREE_CODE (origin
) == PARM_DECL
)
7086 gen_formal_parameter_die (decl
, context_die
);
7090 gen_variable_die (decl
, context_die
);
7095 /* Ignore the nameless fields that are used to skip bits. */
7096 if (DECL_NAME (decl
) != 0)
7098 gen_type_die (member_declared_type (decl
), context_die
);
7099 gen_field_die (decl
, context_die
);
7104 gen_type_die (TREE_TYPE (decl
), context_die
);
7105 gen_formal_parameter_die (decl
, context_die
);
7114 /***************** Debug Information Generation Hooks ***********************/
7116 dwarfout_file_scope_decl (decl
, set_finalizing
)
7118 register int set_finalizing
;
7120 if (TREE_CODE (decl
) == ERROR_MARK
)
7125 /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta
7126 hope that the node in question doesn't represent a function definition.
7127 If it does, then totally ignoring it is bound to screw up our count of
7128 blocks, and that it turn will completely screw up the the labels we will
7129 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
7130 subsequent blocks). (It's too bad that BLOCK nodes don't carry their
7131 own sequence numbers with them!) */
7132 if (DECL_IGNORED_P (decl
))
7134 if (TREE_CODE (decl
) == FUNCTION_DECL
7135 && DECL_INITIAL (decl
) != NULL
)
7142 switch (TREE_CODE (decl
))
7145 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
7146 builtin function. Explicit programmer-supplied declarations of
7147 these same functions should NOT be ignored however. */
7148 if (DECL_EXTERNAL (decl
) && DECL_FUNCTION_CODE (decl
))
7153 /* What we would really like to do here is to filter out all mere
7154 file-scope declarations of file-scope functions which are never
7155 referenced later within this translation unit (and keep all of ones
7156 that *are* referenced later on) but we aren't clarvoiant, so we have
7157 no idea which functions will be referenced in the future (i.e. later
7158 on within the current translation unit). So here we just ignore all
7159 file-scope function declarations which are not also definitions. If
7160 and when the debugger needs to know something about these funcstion,
7161 it wil have to hunt around and find the DWARF information associated
7162 with the definition of the function. Note that we can't just check
7163 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
7164 definitions and which ones represent mere declarations. We have to
7165 check `DECL_INITIAL' instead. That's because the C front-end
7166 supports some weird semantics for "extern inline" function
7167 definitions. These can get inlined within the current translation
7168 unit (an thus, we need to generate DWARF info for their abstract
7169 instances so that the DWARF info for the concrete inlined instances
7170 can have something to refer to) but the compiler never generates any
7171 out-of-lines instances of such things (despite the fact that they
7172 *are* definitions). The important point is that the C front-end
7173 marks these "extern inline" functions as DECL_EXTERNAL, but we need
7174 to generate DWARf for them anyway. Note that the C++ front-end also
7175 plays some similar games for inline function definitions appearing
7176 within include files which also contain
7177 `#pragma interface' pragmas. */
7178 if (DECL_INITIAL (decl
) == NULL_TREE
)
7185 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
7186 declaration and if the declaration was never even referenced from
7187 within this entire compilation unit. We suppress these DIEs in
7188 order to save space in the .debug section (by eliminating entries
7189 which are probably useless). Note that we must not suppress
7190 block-local extern declarations (whether used or not) because that
7191 would screw-up the debugger's name lookup mechanism and cause it to
7192 miss things which really ought to be in scope at a given point. */
7193 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
7198 /* If we are in terse mode, don't generate any DIEs to represent any
7199 variable declarations or definitions. */
7200 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
7207 /* Don't bother trying to generate any DIEs to represent any of the
7208 normal built-in types for the language we are compiling, except in
7209 cases where the types in question are *not* DWARF fundamental types.
7210 We make an exception in the case of non-fundamental types for the
7211 sake of objective C (and perhaps C++) because the GNU front-ends for
7212 these languages may in fact create certain "built-in" types which
7213 are (for example) RECORD_TYPEs. In such cases, we really need to
7214 output these (non-fundamental) types because other DIEs may contain
7215 references to them. */
7216 if (DECL_SOURCE_LINE (decl
) == 0
7217 && is_base_type (TREE_TYPE (decl
)))
7222 /* If we are in terse mode, don't generate any DIEs to represent any
7223 actual typedefs. Note that even when we are in terse mode, we must
7224 still output DIEs to represent those tagged types which are used
7225 (directly or indirectly) in the specification of either a return
7226 type or a formal parameter type of some function. */
7227 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
7229 if (DECL_NAME (decl
) != NULL
7230 || !TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl
)))
7241 finalizing
= set_finalizing
;
7242 gen_decl_die (decl
, comp_unit_die
);
7244 if (TREE_CODE (decl
) == FUNCTION_DECL
7245 && DECL_INITIAL (decl
) != NULL
)
7247 current_funcdef_number
++;
7252 /* Output a marker (i.e. a label) for the beginning of the generated code for
7255 dwarfout_begin_block (blocknum
)
7256 register unsigned blocknum
;
7258 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7260 function_section (current_function_decl
);
7261 sprintf (label
, BLOCK_BEGIN_LABEL_FMT
, blocknum
);
7262 ASM_OUTPUT_LABEL (asm_out_file
, label
);
7265 /* Output a marker (i.e. a label) for the end of the generated code for a
7268 dwarfout_end_block (blocknum
)
7269 register unsigned blocknum
;
7271 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7273 function_section (current_function_decl
);
7274 sprintf (label
, BLOCK_END_LABEL_FMT
, blocknum
);
7275 ASM_OUTPUT_LABEL (asm_out_file
, label
);
7278 /* Output a marker (i.e. a label) at a point in the assembly code which
7279 corresponds to a given source level label. */
7281 dwarfout_label (insn
)
7284 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7285 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
7287 function_section (current_function_decl
);
7288 sprintf (label
, INSN_LABEL_FMT
, current_funcdef_number
,
7289 (unsigned) INSN_UID (insn
));
7290 ASM_OUTPUT_LABEL (asm_out_file
, label
);
7294 /* Output a marker (i.e. a label) for the point in the generated code where
7295 the real body of the function begins (after parameters have been moved to
7296 their home locations). */
7298 dwarfout_begin_function ()
7300 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7301 register long int offset
;
7302 register dw_fde_ref fde
;
7303 register dw_cfi_ref cfi
;
7305 function_section (current_function_decl
);
7306 sprintf (label
, BODY_BEGIN_LABEL_FMT
, current_funcdef_number
);
7307 ASM_OUTPUT_LABEL (asm_out_file
, label
);
7309 /* Expand the fde table if necessary. */
7310 if (fde_table_in_use
== fde_table_allocated
)
7312 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
7313 fde_table
= (dw_fde_ref
) xrealloc (fde_table
,
7314 fde_table_allocated
* sizeof (dw_fde_node
));
7317 /* Record the FDE associated with this function. */
7318 current_funcdef_fde
= fde_table_in_use
;
7320 /* Add the new FDE at the end of the fde_table. */
7321 fde
= &fde_table
[fde_table_in_use
++];
7322 fde
->dw_fde_begin
= xstrdup (function_start_label (current_function_decl
));
7323 fde
->dw_fde_end_prolog
= xstrdup (label
);
7324 fde
->dw_fde_begin_epilogue
= NULL
;
7325 fde
->dw_fde_end
= NULL
;
7326 fde
->dw_fde_cfi
= NULL
;
7328 #ifdef MIPS_DEBUGGING_INFO
7330 /* On entry, the Call Frame Address is in the stack pointer register. */
7332 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
7333 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= STACK_POINTER_REGNUM
;
7334 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= 0;
7335 add_cfi (&fde
->dw_fde_cfi
, cfi
);
7337 /* Set the location counter to the end of the function prolog. */
7339 cfi
->dw_cfi_opc
= DW_CFA_advance_loc4
;
7340 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
= xstrdup (label
);
7341 add_cfi (&fde
->dw_fde_cfi
, cfi
);
7343 /* Define the CFA as either an explicit frame pointer register,
7344 or an offset from the stack pointer. */
7346 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
7347 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= (frame_pointer_needed
)
7348 ? FRAME_POINTER_REGNUM
7349 : STACK_POINTER_REGNUM
;
7350 offset
= current_frame_info
.total_size
;
7351 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
7352 add_cfi (&fde
->dw_fde_cfi
, cfi
);
7354 /* record the frame size for later definition of the DW_AT_frame_base
7356 current_funcdef_frame_size
= offset
;
7358 /* Define the rule for restoring the stack pointer. */
7359 if (frame_pointer_needed
)
7361 /* Restore the stack register from the frame pointer. */
7363 cfi
->dw_cfi_opc
= DW_CFA_register
;
7364 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= STACK_POINTER_REGNUM
;
7365 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= FRAME_POINTER_REGNUM
;
7366 add_cfi (&fde
->dw_fde_cfi
, cfi
);
7369 /* If RA is saved on the stack, define it here. */
7370 if (regs_ever_live
[31])
7372 offset
= current_frame_info
.gp_save_offset
/ DWARF_CIE_DATA_ALIGNMENT
;
7373 assert (offset
>= 0);
7375 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
7376 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= DW_FRAME_RA_COL
;
7377 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
7378 add_cfi (&fde
->dw_fde_cfi
, cfi
);
7381 /* If FP is saved on the stack, define it here. */
7382 if (current_frame_info
.mask
& (1 << 30))
7384 offset
= (current_frame_info
.gp_save_offset
7385 - (((current_frame_info
.mask
>> 31) & 1) * UNITS_PER_WORD
))
7386 / DWARF_CIE_DATA_ALIGNMENT
;
7387 assert (offset
>= 0);
7389 cfi
->dw_cfi_opc
= DW_CFA_offset
;
7390 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= FRAME_POINTER_REGNUM
;
7391 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
7392 add_cfi (&fde
->dw_fde_cfi
, cfi
);
7399 /* Output a marker (i.e. a label) for the point in the generated code where
7400 the real body of the function ends (just before the epilogue code). */
7402 dwarfout_end_function ()
7405 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7406 function_section (current_function_decl
);
7407 sprintf (label
, BODY_END_LABEL_FMT
, current_funcdef_number
);
7408 ASM_OUTPUT_LABEL (asm_out_file
, label
);
7409 /* Record the ending code location in the FDE. */
7410 fde
= &fde_table
[fde_table_in_use
- 1];
7411 fde
->dw_fde_begin_epilogue
= xstrdup(label
);
7414 /* Output a marker (i.e. a label) for the absolute end of the generated code
7415 for a function definition. This gets called *after* the epilogue code has
7418 dwarfout_end_epilogue ()
7421 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7422 /* Output a label to mark the endpoint of the code generated for this
7424 sprintf (label
, FUNC_END_LABEL_FMT
, current_funcdef_number
);
7425 ASM_OUTPUT_LABEL (asm_out_file
, label
);
7426 fde
= &fde_table
[fde_table_in_use
- 1];
7427 fde
->dw_fde_end
= xstrdup (label
);
7430 /* Lookup a filename (in the list of filenames that we know about here in
7431 dwarfout.c) and return its "index". The index of each (known) filename is
7432 just a unique number which is associated with only that one filename.
7433 We need such numbers for the sake of generating labels
7434 (in the .debug_sfnames section) and references to those
7435 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
7436 If the filename given as an argument is not found in our current list,
7437 add it to the list and assign it the next available unique index number.
7438 In order to speed up searches, we remember the index of the filename
7439 was looked up last. This handles the majority of all searches. */
7441 lookup_filename (file_name
)
7444 static unsigned last_file_lookup_index
= 0;
7446 register unsigned i
;
7448 /* Check to see if the file name that was searched on the previous call
7449 matches this file name. If so, return the index. */
7450 if (last_file_lookup_index
!= 0)
7452 fn
= file_table
[last_file_lookup_index
];
7453 if (strcmp (file_name
, fn
) == 0)
7455 return last_file_lookup_index
;
7459 /* Didn't match the previous lookup, search the table */
7460 for (i
= 1; i
< file_table_in_use
; ++i
)
7463 if (strcmp (file_name
, fn
) == 0)
7465 last_file_lookup_index
= i
;
7470 /* Prepare to add a new table entry by making sure there is enough space in
7471 the table to do so. If not, expand the current table. */
7472 if (file_table_in_use
== file_table_allocated
)
7474 file_table_allocated
+= FILE_TABLE_INCREMENT
;
7477 xrealloc (file_table
, file_table_allocated
* sizeof (char *));
7480 /* add the new entry to the end of the filename table. */
7481 file_table
[file_table_in_use
] = xstrdup (file_name
);
7482 last_file_lookup_index
= file_table_in_use
++;
7483 return last_file_lookup_index
;
7486 /* Output a label to mark the beginning of a source code line entry
7487 and record information relating to this source line, in
7488 'line_info_table' for later output of the .debug_line section. */
7490 dwarfout_line (filename
, line
)
7491 register char *filename
;
7492 register unsigned line
;
7494 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7495 register unsigned this_file_entry_num
= lookup_filename (filename
);
7496 register dw_line_info_ref line_info
;
7497 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
7499 function_section (current_function_decl
);
7500 sprintf (label
, LINE_CODE_LABEL_FMT
, line_info_table_in_use
);
7501 ASM_OUTPUT_LABEL (asm_out_file
, label
);
7502 fputc ('\n', asm_out_file
);
7504 /* expand the line info table if necessary */
7505 if (line_info_table_in_use
== line_info_table_allocated
)
7507 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
7509 = (dw_line_info_ref
)
7510 xrealloc (line_info_table
,
7511 line_info_table_allocated
* sizeof (dw_line_info_entry
));
7513 /* add the new entry at the end of the line_info_table. */
7514 line_info
= &line_info_table
[line_info_table_in_use
++];
7515 line_info
->dw_file_num
= lookup_filename (filename
);
7516 line_info
->dw_line_num
= line
;
7520 /* Record the beginning of a new source file, for later output
7521 of the .debug_macinfo section. At present, unimplemented. */
7523 dwarfout_start_new_source_file (filename
)
7524 register char *filename
;
7528 /* Record the resumption of a source file, for later output
7529 of the .debug_macinfo section. At present, unimplemented. */
7531 dwarfout_resume_previous_source_file (lineno
)
7532 register unsigned lineno
;
7536 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
7537 the tail part of the directive line, i.e. the part which is past the
7538 initial whitespace, #, whitespace, directive-name, whitespace part. */
7540 dwarfout_define (lineno
, buffer
)
7541 register unsigned lineno
;
7542 register char *buffer
;
7544 static int initialized
= 0;
7547 dwarfout_start_new_source_file (primary_filename
);
7552 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
7553 the tail part of the directive line, i.e. the part which is past the
7554 initial whitespace, #, whitespace, directive-name, whitespace part. */
7556 dwarfout_undef (lineno
, buffer
)
7557 register unsigned lineno
;
7558 register char *buffer
;
7562 /* Set up for Dwarf output at the start of compilation. */
7564 dwarfout_init (asm_out_file
, main_input_filename
)
7565 register FILE *asm_out_file
;
7566 register char *main_input_filename
;
7569 /* Remember the name of the primary input file. */
7570 primary_filename
= main_input_filename
;
7572 /* Allocate the initial hunk of the file_table. */
7573 file_table
= (char **) xmalloc (FILE_TABLE_INCREMENT
* sizeof (char *));
7574 bzero (file_table
, FILE_TABLE_INCREMENT
* sizeof (char *));
7575 file_table_allocated
= FILE_TABLE_INCREMENT
;
7576 /* skip the first entry - file numbers begin at 1 */
7577 file_table_in_use
= 1;
7579 /* Allocate the initial hunk of the type_die_table. */
7581 = (dw_die_ref
*) xmalloc (TYPE_DIE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
7582 bzero (type_die_table
, TYPE_DIE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
7583 type_die_table_allocated
= TYPE_DIE_TABLE_INCREMENT
;
7584 type_die_table_in_use
= 0;
7586 /* Allocate the initial hunk of the decl_die_table. */
7588 = (dw_die_ref
*) xmalloc (DECL_DIE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
7589 bzero (decl_die_table
, DECL_DIE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
7590 decl_die_table_allocated
= DECL_DIE_TABLE_INCREMENT
;
7591 decl_die_table_in_use
= 0;
7593 /* Allocate the initial hunk of the decl_scope_table. */
7595 = (tree
*) xmalloc (DECL_SCOPE_TABLE_INCREMENT
* sizeof (tree
));
7596 bzero (decl_scope_table
, DECL_SCOPE_TABLE_INCREMENT
* sizeof (tree
));
7597 decl_scope_table_allocated
= DECL_SCOPE_TABLE_INCREMENT
;
7598 decl_scope_depth
= 0;
7600 /* Allocate the initial hunk of the abbrev_die_table. */
7602 = (dw_die_ref
*) xmalloc (ABBREV_DIE_TABLE_INCREMENT
7603 * sizeof (dw_die_ref
));
7604 bzero (abbrev_die_table
, ABBREV_DIE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
7605 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
7606 /* zero-th entry is allocated, but unused */
7607 abbrev_die_table_in_use
= 1;
7609 /* Allocate the initial hunk of the line_info_table. */
7611 = (dw_line_info_ref
) xmalloc (LINE_INFO_TABLE_INCREMENT
7612 * sizeof (dw_line_info_entry
));
7613 bzero (line_info_table
, LINE_INFO_TABLE_INCREMENT
7614 * sizeof (dw_line_info_entry
));
7615 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
7616 /* zero-th entry is allocated, but unused */
7617 line_info_table_in_use
= 1;
7619 /* Allocate the initial hunk of the fde_table. */
7620 fde_table
= (dw_fde_ref
) xmalloc (FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
7621 bzero (fde_table
, FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
7622 fde_table_allocated
= FDE_TABLE_INCREMENT
;
7623 fde_table_in_use
= 0;
7625 /* Output a starting label for the .text section. */
7626 fputc ('\n', asm_out_file
);
7627 ASM_OUTPUT_SECTION (asm_out_file
, TEXT_SECTION
);
7628 ASM_OUTPUT_LABEL (asm_out_file
, TEXT_BEGIN_LABEL
);
7630 /* Output a starting label for the .data section. */
7631 fputc ('\n', asm_out_file
);
7632 ASM_OUTPUT_SECTION (asm_out_file
, DATA_SECTION
);
7633 ASM_OUTPUT_LABEL (asm_out_file
, DATA_BEGIN_LABEL
);
7635 /* Output a starting label for the .rodata section. */
7636 fputc ('\n', asm_out_file
);
7637 ASM_OUTPUT_SECTION (asm_out_file
, RODATA_SECTION
);
7638 ASM_OUTPUT_LABEL (asm_out_file
, RODATA_BEGIN_LABEL
);
7640 /* Output a starting label for the .bss section. */
7641 fputc ('\n', asm_out_file
);
7642 ASM_OUTPUT_SECTION (asm_out_file
, BSS_SECTION
);
7643 ASM_OUTPUT_LABEL (asm_out_file
, BSS_BEGIN_LABEL
);
7645 /* Generate the initial DIE for the .debug section. Note that the (string)
7646 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
7647 will (typically) be a relative pathname and that this pathname should be
7648 taken as being relative to the directory from which the compiler was
7649 invoked when the given (base) source file was compiled. */
7650 gen_compile_unit_die (main_input_filename
);
7652 /* clear the association between base types and their DIE's */
7653 init_base_type_table ();
7655 /* clear the backchain list. */
7659 /* Output stuff that dwarf requires at the end of every file,
7660 and generate the DWARF-2 debugging info. */
7665 resolve_backchains ();
7667 /* Traverse the DIE tree and add sibling attributes to those DIE's
7668 that have children. */
7669 add_sibling_attributes (comp_unit_die
);
7671 /* Output a terminator label for the .text section. */
7672 fputc ('\n', asm_out_file
);
7673 ASM_OUTPUT_SECTION (asm_out_file
, TEXT_SECTION
);
7674 ASM_OUTPUT_LABEL (asm_out_file
, TEXT_END_LABEL
);
7676 /* Output a terminator label for the .data section. */
7677 fputc ('\n', asm_out_file
);
7678 ASM_OUTPUT_SECTION (asm_out_file
, DATA_SECTION
);
7679 ASM_OUTPUT_LABEL (asm_out_file
, DATA_END_LABEL
);
7681 /* Output a terminator label for the .rodata section. */
7682 fputc ('\n', asm_out_file
);
7683 ASM_OUTPUT_SECTION (asm_out_file
, RODATA_SECTION
);
7684 ASM_OUTPUT_LABEL (asm_out_file
, RODATA_END_LABEL
);
7686 /* Output a terminator label for the .bss section. */
7687 fputc ('\n', asm_out_file
);
7688 ASM_OUTPUT_SECTION (asm_out_file
, BSS_SECTION
);
7689 ASM_OUTPUT_LABEL (asm_out_file
, BSS_END_LABEL
);
7691 /* Output the abbreviation table. */
7692 fputc ('\n', asm_out_file
);
7693 ASM_OUTPUT_SECTION (asm_out_file
, ABBREV_SECTION
);
7694 build_abbrev_table (comp_unit_die
);
7695 output_abbrev_section ();
7697 /* Output the source line correspondence table. */
7698 fputc ('\n', asm_out_file
);
7699 ASM_OUTPUT_SECTION (asm_out_file
, LINE_SECTION
);
7700 output_line_info ();
7702 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
7703 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7704 calc_die_sizes (comp_unit_die
);
7706 /* Initialize the beginning FDE offset - and calculate sizes/offsets. */
7707 next_fde_offset
= DWARF_CIE_SIZE
;
7710 /* Output debugging information. */
7711 fputc ('\n', asm_out_file
);
7712 ASM_OUTPUT_SECTION (asm_out_file
, DEBUG_SECTION
);
7713 output_compilation_unit_header ();
7714 output_die (comp_unit_die
);
7716 if (fde_table_in_use
)
7718 /* Output call frame information. */
7719 fputc ('\n', asm_out_file
);
7720 ASM_OUTPUT_SECTION (asm_out_file
, FRAME_SECTION
);
7721 output_call_frame_info ();
7723 /* Output public names table. */
7724 fputc ('\n', asm_out_file
);
7725 ASM_OUTPUT_SECTION (asm_out_file
, PUBNAMES_SECTION
);
7728 /* Output the address range information. */
7729 fputc ('\n', asm_out_file
);
7730 ASM_OUTPUT_SECTION (asm_out_file
, ARANGES_SECTION
);
7734 #endif /* DWARF_DEBUGGING_INFO && DWARF_VERSION == 2 */