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. */
25 #define DWARF_VERSION 1
27 #if defined (DWARF_DEBUGGING_INFO) && (DWARF_VERSION == 2)
33 #include "hard-reg-set.h"
35 #include "insn-config.h"
40 /* #define NDEBUG 1 */
42 #if defined(DWARF_TIMESTAMPS)
45 #else /* !defined(POSIX) */
46 #include <sys/types.h>
48 extern time_t time (time_t *);
49 #else /* !defined(__STDC__) */
50 extern time_t time ();
51 #endif /* !defined(__STDC__) */
52 #endif /* !defined(POSIX) */
53 #endif /* defined(DWARF_TIMESTAMPS) */
55 extern char *getpwd ();
56 extern char *index ();
57 extern char *rindex ();
59 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
60 regarding the GNU implementation of DWARF. */
62 /* NOTE: In the comments in this file, many references are made to
63 "Debugging Information Entries". This term is abbreviated as `DIE'
64 throughout the remainder of this file. */
66 /* NOTE: The implementation of C++ support is unfinished. */
68 #if defined(__GNUC__) && (NDEBUG == 1)
69 #define inline static inline
75 /* An internal representation of the DWARF output is built, and then
76 walked to generate the DWARF debugging info. The walk of the internal
77 representation is done after the entire program has been compiled.
78 The types below are used to describe the internal representation. */
80 /* Each DIE may have a series of attribute/value pairs. Values
81 can take on several forms. The forms that are used in this
82 impelementation are listed below. */
88 dw_val_class_unsigned_const,
89 dw_val_class_double_const,
94 dw_val_class_section_offset,
99 /* Various DIE's use offsets relative to the beginning of the
100 .debug_info section to refer to each other. */
101 typedef long int dw_offset;
103 /* Define typedefs here to avoid circular dependencies. */
104 typedef struct die_struct *dw_die_ref;
105 typedef struct dw_attr_struct *dw_attr_ref;
106 typedef struct dw_val_struct *dw_val_ref;
107 typedef struct dw_line_info_struct *dw_line_info_ref;
108 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
109 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
110 typedef struct dw_cfi_struct *dw_cfi_ref;
111 typedef struct dw_fde_struct *dw_fde_ref;
112 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
113 typedef struct pubname_struct *pubname_ref;
114 typedef dw_die_ref *arange_ref;
116 /* Describe a double word constant value. */
117 typedef struct dw_double_const_struct
119 unsigned long dw_dbl_hi;
120 unsigned long dw_dbl_low;
124 /* Each entry in the line_info_table maintains the file and
125 line nuber associated with the label generated for that
126 entry. The label gives the PC value associated with
127 the line number entry. */
128 typedef struct dw_line_info_struct
130 unsigned long dw_file_num;
131 unsigned long dw_line_num;
135 /* Line information for functions in separate sections; each one gets its
137 typedef struct dw_separate_line_info_struct
139 unsigned long dw_file_num;
140 unsigned long dw_line_num;
141 unsigned long function;
143 dw_separate_line_info_entry;
145 /* The dw_val_node describes an attibute's value, as it is
146 represnted internally. */
147 typedef struct dw_val_struct
149 dw_val_class val_class;
153 dw_loc_descr_ref val_loc;
155 long unsigned val_unsigned;
156 dw_dbl_const val_dbl_const;
157 dw_die_ref val_die_ref;
158 unsigned val_fde_index;
162 unsigned char val_flag;
168 /* Locations in memory are described using a sequence of stack machine
170 typedef struct dw_loc_descr_struct
172 dw_loc_descr_ref dw_loc_next;
173 enum dwarf_location_atom dw_loc_opc;
174 dw_val_node dw_loc_oprnd1;
175 dw_val_node dw_loc_oprnd2;
179 /* Each DIE attribute has a field specifying the attribute kind,
180 a link to the next attribute in the chain, and an attribute value.
181 Attributes are typically linked below the DIE they modify. */
182 typedef struct dw_attr_struct
184 enum dwarf_attribute dw_attr;
185 dw_attr_ref dw_attr_next;
186 dw_val_node dw_attr_val;
190 /* Call frames are described using a sequence of Call Frame
191 Information instructions. The register number, offset
192 and address fields are provided as possible operands;
193 their use is selected by the opcode field. */
194 typedef union dw_cfi_oprnd_struct
196 unsigned long dw_cfi_reg_num;
197 long int dw_cfi_offset;
202 typedef struct dw_cfi_struct
204 dw_cfi_ref dw_cfi_next;
205 enum dwarf_call_frame_info dw_cfi_opc;
206 dw_cfi_oprnd dw_cfi_oprnd1;
207 dw_cfi_oprnd dw_cfi_oprnd2;
211 /* All call frame descriptions (FDE's) in the GCC generated DWARF
212 refer to a single Common Information Entry (CIE), defined at
213 the beginning of the .debug_frame section. This used of a single
214 CIE obviates the need to keep track of multiple CIE's
215 in the DWARF generation routines below. */
216 typedef struct dw_fde_struct
218 unsigned long dw_fde_offset;
220 char *dw_fde_end_prolog;
221 char *dw_fde_begin_epilogue;
223 dw_cfi_ref dw_fde_cfi;
227 /* The Debugging Information Entry (DIE) structure */
228 typedef struct die_struct
230 enum dwarf_tag die_tag;
231 dw_attr_ref die_attr;
232 dw_attr_ref die_attr_last;
233 dw_die_ref die_parent;
234 dw_die_ref die_child;
235 dw_die_ref die_child_last;
237 dw_offset die_offset;
238 unsigned long die_abbrev;
242 /* The pubname structure */
243 typedef struct pubname_struct
250 /* How to start an assembler comment. */
251 #ifndef ASM_COMMENT_START
252 #define ASM_COMMENT_START ";#"
255 /* Define a macro which returns non-zero for any tagged type which is used
256 (directly or indirectly) in the specification of either some function's
257 return type or some formal parameter of some function. We use this macro
258 when we are operating in "terse" mode to help us know what tagged types
259 have to be represented in Dwarf (even in terse mode) and which ones don't.
260 A flag bit with this meaning really should be a part of the normal GCC
261 ..._TYPE nodes, but at the moment, there is no such bit defined for these
262 nodes. For now, we have to just fake it. It it safe for us to simply
263 return zero for all complete tagged types (which will get forced out
264 anyway if they were used in the specification of some formal or return
265 type) and non-zero for all incomplete tagged types. */
266 #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
268 /* Information concerning the compilation unit's programming
269 language, and compiler version. */
270 extern int flag_traditional;
271 extern char *version_string;
272 extern char *language_string;
274 /* Maximum size (in bytes) of an artificially generated label. */
275 #define MAX_ARTIFICIAL_LABEL_BYTES 30
277 /* Make sure we know the sizes of the various types dwarf can describe. These
278 are only defaults. If the sizes are different for your target, you should
279 override these values by defining the appropriate symbols in your tm.h
281 #ifndef CHAR_TYPE_SIZE
282 #define CHAR_TYPE_SIZE BITS_PER_UNIT
284 #ifndef SHORT_TYPE_SIZE
285 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
287 #ifndef INT_TYPE_SIZE
288 #define INT_TYPE_SIZE BITS_PER_WORD
290 #ifndef LONG_TYPE_SIZE
291 #define LONG_TYPE_SIZE BITS_PER_WORD
293 #ifndef LONG_LONG_TYPE_SIZE
294 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
296 #ifndef WCHAR_TYPE_SIZE
297 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
299 #ifndef WCHAR_UNSIGNED
300 #define WCHAR_UNSIGNED 0
302 #ifndef FLOAT_TYPE_SIZE
303 #define FLOAT_TYPE_SIZE BITS_PER_WORD
305 #ifndef DOUBLE_TYPE_SIZE
306 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
308 #ifndef LONG_DOUBLE_TYPE_SIZE
309 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
312 #define PTR_SIZE (POINTER_SIZE / 8)
315 /* The size in bytes of a DWARF field indicating an offset or length
316 relative to a debug info section, specified to be 4 bytes in the DWARF-2
317 specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */
318 #ifndef DWARF_OFFSET_SIZE
319 #define DWARF_OFFSET_SIZE 4
322 /* Fixed size portion of the DWARF compilation unit header. */
323 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
325 /* Fixed size portion of debugging line information prolog. */
326 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
328 /* Fixed size portion of public names info. */
329 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
331 /* Round SIZE up to the nearest BOUNDARY. */
332 #define DWARF_ROUND(SIZE,BOUNDARY) \
333 (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
335 /* Fixed size portion of the address range info. */
336 #define DWARF_ARANGES_HEADER_SIZE \
337 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
339 /* Fixed size portion of the Common Information Entry (including
340 the length field). */
341 #define DWARF_CIE_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 8)
343 /* Fixed size of the Common Information Entry in the call frame
344 information (.debug_frame) section rounded up to a word boundary. */
345 #define DWARF_CIE_SIZE DWARF_ROUND (DWARF_CIE_HEADER_SIZE, PTR_SIZE)
347 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
348 #define DWARF_CIE_DATA_ALIGNMENT -4
350 /* Fixed size portion of the FDE. */
351 #define DWARF_FDE_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2 * PTR_SIZE)
353 /* Define the architecture-dependent minimum instruction length (in bytes).
354 In this implementation of DWARF, this field is used for information
355 purposes only. Since GCC generates assembly language, we have
356 no a priori knowledge of how many instruction bytes are generated
357 for each source line, and therefore can use only the DW_LNE_set_address
358 and DW_LNS_fixed_advance_pc line information commands. */
359 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
360 #define DWARF_LINE_MIN_INSTR_LENGTH 4
363 /* Minimum line offset in a special line info. opcode.
364 This value was chosen to give a reasonable range of values. */
365 #define DWARF_LINE_BASE -10
367 /* First special line opcde - leave room for the standard opcodes. */
368 #define DWARF_LINE_OPCODE_BASE 10
370 /* Range of line offsets in a special line info. opcode. */
371 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
373 /* Flag that indicates the initial value of the is_stmt_start flag.
374 In the present implementation, we do not mark any lines as
375 the beginning of a source statement, because that information
376 is not made available by the GCC front-end. */
377 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
379 /* This location is used by calc_die_sizes() to keep track
380 the offset of each DIE within the .debug_info section. */
381 static unsigned long next_die_offset;
383 /* This location is used by calc_fde_sizes() to keep track
384 the offset of each FDE within the .debug_frame section. */
385 static unsigned long next_fde_offset;
387 /* Record the root of the DIE's built for the current compilation unit. */
388 dw_die_ref comp_unit_die;
390 /* Pointer to an array of filenames referenced by this compilation unit. */
391 static char **file_table;
393 /* Total number of entries in the table (i.e. array) pointed to by
394 `file_table'. This is the *total* and includes both used and unused
396 static unsigned file_table_allocated;
398 /* Number of entries in the file_table which are actually in use. */
399 static unsigned file_table_in_use;
401 /* Size (in elements) of increments by which we may expand the filename
403 #define FILE_TABLE_INCREMENT 64
405 /* Local pointer to the name of the main input file. Initialized in
407 static char *primary_filename;
409 /* For Dwarf output, we must assign lexical-blocks id numbers in the order in
410 which their beginnings are encountered. We output Dwarf debugging info
411 that refers to the beginnings and ends of the ranges of code for each
412 lexical block. The labels themselves are generated in final.c, which
413 assigns numbers to the blocks in the same way. */
414 static unsigned next_block_number = 2;
416 /* Non-zero if we are performing the file-scope finalization pass and if we
417 should force out Dwarf descriptions of any and all file-scope tagged types
418 which are still incomplete types. */
419 static int finalizing = 0;
421 /* A pointer to the base of a list of references to DIE's that describe
422 types. The table is indexed by TYPE_UID() which is a unique number,
423 indentifying each type. */
424 static dw_die_ref *type_die_table;
426 /* Number of elements currently allocated for type_die_table. */
427 static unsigned type_die_table_allocated;
429 /* Number of elements in type_die_table currently in use. */
430 static unsigned type_die_table_in_use;
432 /* Size (in elements) of increments by which we may expand the
434 #define TYPE_DIE_TABLE_INCREMENT 4096
436 /* A pointer to the base of a table of references to DIE's that describe
437 declarations. The table is indexed by DECL_UID() which is a unique
438 number, indentifying each decl. */
439 static dw_die_ref *decl_die_table;
441 /* Number of elements currently allocated for the decl_die_table. */
442 static unsigned decl_die_table_allocated;
444 /* Number of elements in decl_die_table currently in use. */
445 static unsigned decl_die_table_in_use;
447 /* Size (in elements) of increments by which we may expand the
449 #define DECL_DIE_TABLE_INCREMENT 256
451 /* A pointer to the base of a table of references to declaration
452 scopes. This table is a display which tracks the nesting
453 of declaration scopes at the current scope and containing
454 scopes. This table is used to find the proper place to
455 define type declaration DIE's. */
456 static tree *decl_scope_table;
458 /* Number of elements currently allocated for the decl_scope_table. */
459 static unsigned decl_scope_table_allocated;
461 /* Current level of nesting of declataion scopes. */
462 static unsigned decl_scope_depth;
464 /* Size (in elements) of increments by which we may expand the
466 #define DECL_SCOPE_TABLE_INCREMENT 64
468 /* A pointer to the base of a list of references to DIE's that
469 are uniquely identified by their tag, presence/absence of
470 children DIE's, and list of attribute/value pairs. */
471 static dw_die_ref *abbrev_die_table;
473 /* Number of elements currently allocated for abbrev_die_table. */
474 static unsigned abbrev_die_table_allocated;
476 /* Number of elements in type_die_table currently in use. */
477 static unsigned abbrev_die_table_in_use;
479 /* Size (in elements) of increments by which we may expand the
481 #define ABBREV_DIE_TABLE_INCREMENT 256
483 /* A pointer to the base of a table that contains line information
484 for each source code line in .text in the compilation unit. */
485 static dw_line_info_ref line_info_table;
487 /* Number of elements currently allocated for line_info_table. */
488 static unsigned line_info_table_allocated;
490 /* Number of elements in separate_line_info_table currently in use. */
491 static unsigned separate_line_info_table_in_use;
493 /* A pointer to the base of a table that contains line information
494 for each source code line outside of .text in the compilation unit. */
495 static dw_separate_line_info_ref separate_line_info_table;
497 /* Number of elements currently allocated for separate_line_info_table. */
498 static unsigned separate_line_info_table_allocated;
500 /* Number of elements in line_info_table currently in use. */
501 static unsigned line_info_table_in_use;
503 /* Size (in elements) of increments by which we may expand the
505 #define LINE_INFO_TABLE_INCREMENT 1024
507 /* Keep track of the last line_info_table entry number, returned
508 by the prior call to lookup_filename(). This serves as a
509 cache used to speed up file name look ups. */
510 static unsigned prev_file_entry_num = (unsigned) -1;
512 /* A pointer to the base of a table that contains frame description
513 information for each routine. */
514 static dw_fde_ref fde_table;
516 /* Number of elements currently allocated for fde_table. */
517 static unsigned fde_table_allocated;
519 /* Number of elements in fde_table currently in use. */
520 static unsigned fde_table_in_use;
522 /* Size (in elements) of increments by which we may expand the
524 #define FDE_TABLE_INCREMENT 256
526 /* A pointer to the base of a table that contains a list of publicly
528 static pubname_ref pubname_table;
530 /* Number of elements currently allocated for pubname_table. */
531 static unsigned pubname_table_allocated;
533 /* Number of elements in pubname_table currently in use. */
534 static unsigned pubname_table_in_use;
536 /* Size (in elements) of increments by which we may expand the
538 #define PUBNAME_TABLE_INCREMENT 64
540 /* A pointer to the base of a table that contains a list of publicly
542 static arange_ref arange_table;
544 /* Number of elements currently allocated for arange_table. */
545 static unsigned arange_table_allocated;
547 /* Number of elements in arange_table currently in use. */
548 static unsigned arange_table_in_use;
550 /* Size (in elements) of increments by which we may expand the
552 #define ARANGE_TABLE_INCREMENT 64
554 /* The number of the current function definition for which debugging
555 information is being generated. These numbers range from 1 up to the
556 maximum number of function definitions contained within the current
557 compilation unit. These numbers are used to create unique label id's
558 unique to each function definition. */
559 static unsigned current_funcdef_number = 1;
561 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
562 attribute that accelerates the lookup of the FDE associated
563 with the subprogram. This variable holds the table index of the FDE
564 associated with the current function (body) definition. */
565 static unsigned current_funcdef_fde;
567 /* Record the size of the frame, so that the DW_AT_frame_base
568 attribute can be set properly in gen_subprogram_die. */
569 static long int current_funcdef_frame_size = 0;
571 /* Record whether the function being analyzed contains inlined functions. */
572 static int current_function_has_inlines;
573 static int comp_unit_has_inlines;
575 /* DWARF requires that the compiler's primary datatypes
576 are mapped into a reference to a DIE that defines that
577 primary (base) type. The base_type_info structure is used
578 to track the correspondence between the name of a
579 base type used by GCC, and its corresponding type
580 characteristics. Note, that the bt_size field below
581 is the size in bits. */
582 typedef struct base_type_struct *base_type_ref;
583 typedef struct base_type_struct
586 enum dwarf_type bt_type;
592 /* Characteristics of base types used by the compiler. */
593 static base_type_info base_type_table[] =
595 {"void", DW_ATE_unsigned, 0, 0},
596 /* TODO: on some architectures, "char" may be signed. */
597 {"char", DW_ATE_unsigned_char, 0, CHAR_TYPE_SIZE},
598 {"unsigned char", DW_ATE_unsigned_char, 0, CHAR_TYPE_SIZE},
599 {"signed char", DW_ATE_signed_char, 1, CHAR_TYPE_SIZE},
600 {"int", DW_ATE_signed, 1, /* INT_TYPE_SIZE */ 4*8},
601 {"unsigned int", DW_ATE_unsigned, 0, /* INT_TYPE_SIZE */ 4*8},
602 {"short", DW_ATE_signed, 1, SHORT_TYPE_SIZE},
603 {"short int", DW_ATE_signed, 1, SHORT_TYPE_SIZE},
604 {"short unsigned int", DW_ATE_unsigned, 0, SHORT_TYPE_SIZE},
605 {"long", DW_ATE_signed, 1, /* LONG_TYPE_SIZE */ 4*8},
606 {"long int", DW_ATE_signed, 1, /* LONG_TYPE_SIZE */ 4*8},
607 {"long unsigned int", DW_ATE_unsigned, 0, /* LONG_TYPE_SIZE */ 4*8},
608 {"long long int", DW_ATE_signed, 1, LONG_LONG_TYPE_SIZE},
609 {"long long unsigned int", DW_ATE_unsigned, 0, LONG_LONG_TYPE_SIZE},
610 {"float", DW_ATE_float, 1, /* FLOAT_TYPE_SIZE */ 4*8},
611 {"double", DW_ATE_float, 1, DOUBLE_TYPE_SIZE},
612 {"long double", DW_ATE_float, 1, LONG_DOUBLE_TYPE_SIZE},
613 {"complex", DW_ATE_complex_float, 1, 2 * /* FLOAT_TYPE_SIZE */ 4*8},
614 {"double complex", DW_ATE_complex_float, 1, 2 * DOUBLE_TYPE_SIZE},
615 {"long double complex", DW_ATE_complex_float, 1, 2 * LONG_DOUBLE_TYPE_SIZE}
617 #define NUM_BASE_TYPES (sizeof(base_type_table)/sizeof(base_type_info))
619 /* Record the DIE associated with a given base type This table is
620 parallel to the base_type_table, and records the DIE genereated
621 to describe base type that has been previously referenced. */
622 static dw_die_ref base_type_die_table[NUM_BASE_TYPES];
624 /* This predefined base type is used to create certain anonymous types */
625 static dw_die_ref int_base_type_die;
627 /* A pointer to the ..._DECL node which we have most recently been working
628 on. We keep this around just in case something about it looks screwy and
629 we want to tell the user what the source coordinates for the actual
631 static tree dwarf_last_decl;
633 /* Forward declarations for functions defined in this file. */
634 static void gen_type_die ();
635 static void add_type_attribute ();
636 static void decls_for_scope ();
637 static void gen_decl_die ();
638 static unsigned lookup_filename ();
639 static int constant_size PROTO((long unsigned));
641 /* Definitions of defaults for assembler-dependent names of various
642 pseudo-ops and section names.
643 Theses may be overridden in the tm.h file (if necessary) for a particular
645 #ifndef UNALIGNED_SHORT_ASM_OP
646 #define UNALIGNED_SHORT_ASM_OP ".2byte"
648 #ifndef UNALIGNED_INT_ASM_OP
649 #define UNALIGNED_INT_ASM_OP ".4byte"
651 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
652 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
655 #define ASM_BYTE_OP ".byte"
658 #ifndef UNALIGNED_OFFSET_ASM_OP
659 #define UNALIGNED_OFFSET_ASM_OP \
660 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
663 #ifndef UNALIGNED_WORD_ASM_OP
664 #define UNALIGNED_WORD_ASM_OP \
665 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
668 /* Data and reference forms for relocatable data. */
669 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
670 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
672 /* Pseudo-op for defining a new section. */
673 #ifndef SECTION_ASM_OP
674 #define SECTION_ASM_OP ".section"
677 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
678 print the SECTION_ASM_OP and the section name. The default here works for
679 almost all svr4 assemblers, except for the sparc, where the section name
680 must be enclosed in double quotes. (See sparcv4.h). */
681 #ifndef SECTION_FORMAT
682 #define SECTION_FORMAT "\t%s\t%s\n"
685 /* Section names used to hold DWARF debugging information. */
686 #ifndef DEBUG_SECTION
687 #define DEBUG_SECTION ".debug_info"
689 #ifndef ABBREV_SECTION
690 #define ABBREV_SECTION ".debug_abbrev"
692 #ifndef ARANGES_SECTION
693 #define ARANGES_SECTION ".debug_aranges"
695 #ifndef DW_MACINFO_SECTION
696 #define DW_MACINFO_SECTION ".debug_macinfo"
698 #ifndef FRAME_SECTION
699 #define FRAME_SECTION ".debug_frame"
702 #define LINE_SECTION ".debug_line"
705 #define LOC_SECTION ".debug_loc"
707 #ifndef PUBNAMES_SECTION
708 #define PUBNAMES_SECTION ".debug_pubnames"
711 #define STR_SECTION ".debug_str"
714 /* Standerd ELF section names for compiled code and data. */
716 #define TEXT_SECTION ".text"
719 #define DATA_SECTION ".data"
721 #ifndef DATA1_SECTION
722 #define DATA1_SECTION ".data1"
724 #ifndef RODATA_SECTION
725 #define RODATA_SECTION ".rodata"
727 #ifndef RODATA1_SECTION
728 #define RODATA1_SECTION ".rodata1"
731 #define BSS_SECTION ".bss"
735 /* Definitions of defaults for formats and names of various special
736 (artificial) labels which may be generated within this file (when the -g
737 options is used and DWARF_DEBUGGING_INFO is in effect.
738 If necessary, these may be overridden from within the tm.h file, but
739 typically, overriding these defaults is unnecessary.
740 These labels have been hacked so that they all begin with a
741 `.L' sequence to appease the stock sparc/svr4 assembler and the
742 stock m88k/svr4 assembler, both of which need to see .L at the start of a
743 label in order to prevent that label from going into the linker symbol
744 table). Eventually, the ASM_GENERATE_INTERNAL_LABEL and
745 ASM_OUTPUT_INTERNAL_LABEL should be used, but that will require
747 #ifndef TEXT_BEGIN_LABEL
748 #define TEXT_BEGIN_LABEL ".L_text_b"
750 #ifndef TEXT_END_LABEL
751 #define TEXT_END_LABEL ".L_text_e"
753 #ifndef DATA_BEGIN_LABEL
754 #define DATA_BEGIN_LABEL ".L_data_b"
756 #ifndef DATA_END_LABEL
757 #define DATA_END_LABEL ".L_data_e"
759 #ifndef RODATA_BEGIN_LABEL
760 #define RODATA_BEGIN_LABEL ".L_rodata_b"
762 #ifndef RODATA_END_LABEL
763 #define RODATA_END_LABEL ".L_rodata_e"
765 #ifndef BSS_BEGIN_LABEL
766 #define BSS_BEGIN_LABEL ".L_bss_b"
768 #ifndef BSS_END_LABEL
769 #define BSS_END_LABEL ".L_bss_e"
771 #ifndef LINE_BEGIN_LABEL
772 #define LINE_BEGIN_LABEL ".L_line_b"
774 #ifndef LINE_END_LABEL
775 #define LINE_END_LABEL ".L_line_e"
777 #ifndef INSN_LABEL_FMT
778 #define INSN_LABEL_FMT ".L_I%u_%u"
780 #ifndef BLOCK_BEGIN_LABEL_FMT
781 #define BLOCK_BEGIN_LABEL_FMT ".L_B%u"
783 #ifndef BLOCK_END_LABEL_FMT
784 #define BLOCK_END_LABEL_FMT ".L_B%u_e"
786 #ifndef BODY_BEGIN_LABEL_FMT
787 #define BODY_BEGIN_LABEL_FMT ".L_b%u"
789 #ifndef BODY_END_LABEL_FMT
790 #define BODY_END_LABEL_FMT ".L_b%u_e"
792 #ifndef FUNC_BEGIN_LABEL_FMT
793 #define FUNC_BEGIN_LABEL_FMT ".L_f%u"
795 #ifndef FUNC_END_LABEL_FMT
796 #define FUNC_END_LABEL_FMT ".L_f%u_e"
798 #ifndef LINE_CODE_LABEL_FMT
799 #define LINE_CODE_LABEL_FMT ".L_LC%u"
801 #ifndef SEPARATE_LINE_CODE_LABEL_FMT
802 #define SEPARATE_LINE_CODE_LABEL_FMT ".L_SLC%u"
804 #ifndef SFNAMES_ENTRY_LABEL_FMT
805 #define SFNAMES_ENTRY_LABEL_FMT ".L_F%u"
808 /* Definitions of defaults for various types of primitive assembly language
809 output operations. These may be overridden from within the tm.h file,
810 but typically, that is unecessary. */
811 #ifndef ASM_OUTPUT_SECTION
812 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
813 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
816 #ifndef ASM_OUTPUT_DWARF_DELTA2
817 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
818 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
819 assemble_name (FILE, LABEL1); \
820 fprintf (FILE, "-"); \
821 assemble_name (FILE, LABEL2); \
825 #ifndef ASM_OUTPUT_DWARF_DELTA4
826 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
827 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
828 assemble_name (FILE, LABEL1); \
829 fprintf (FILE, "-"); \
830 assemble_name (FILE, LABEL2); \
834 #ifndef ASM_OUTPUT_DWARF_DELTA
835 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
836 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
837 assemble_name (FILE, LABEL1); \
838 fprintf (FILE, "-"); \
839 assemble_name (FILE, LABEL2); \
843 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
844 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
845 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
846 assemble_name (FILE, LABEL1); \
847 fprintf (FILE, "-"); \
848 assemble_name (FILE, LABEL2); \
852 #ifndef ASM_OUTPUT_DWARF_ADDR
853 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
854 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
855 assemble_name (FILE, LABEL); \
859 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
860 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
861 fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR))
864 #ifndef ASM_OUTPUT_DWARF_OFFSET
865 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
866 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
867 assemble_name (FILE, LABEL); \
871 #ifndef ASM_OUTPUT_DWARF_DATA1
872 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
873 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, VALUE)
876 #ifndef ASM_OUTPUT_DWARF_DATA2
877 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
878 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
881 #ifndef ASM_OUTPUT_DWARF_DATA4
882 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
883 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
886 #ifndef ASM_OUTPUT_DWARF_DATA
887 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
888 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
889 (unsigned long) VALUE)
892 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
893 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
894 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
895 (unsigned long) VALUE)
898 #ifndef ASM_OUTPUT_DWARF_DATA8
899 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
901 if (WORDS_BIG_ENDIAN) \
903 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
904 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
908 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
909 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
914 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
915 newline is produced. When flag_verbose_asm is asserted, we add commnetary
916 at the end of the line, so we must avoid output of a newline here. */
917 #ifndef ASM_OUTPUT_DWARF_STRING
918 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
920 register int slen = strlen(P); \
921 register char *p = (P); \
923 fprintf (FILE, "\t.ascii \""); \
924 for (i = 0; i < slen; i++) \
926 register int c = p[i]; \
927 if (c == '\"' || c == '\\') \
929 if (c >= ' ' && c < 0177) \
933 fprintf (FILE, "\\%o", c); \
936 fprintf (FILE, "\\0\""); \
941 /* Convert a reference to the assembler name of a C-level name. This
942 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
943 a string rather than writing to a file. */
944 #ifndef ASM_NAME_TO_STRING
945 #define ASM_NAME_TO_STRING(STR, NAME) \
947 if ((NAME)[0] == '*') \
948 strcpy (STR, NAME+1); \
950 strcpy (STR, NAME); \
956 /************************ general utility functions **************************/
958 /* Return a pointer to a copy of the section string name 's' with all
959 attributes stripped off. */
964 register char *stripped, *p;
965 stripped = xstrdup (s);
967 while (*p && *p != ',')
973 /* Convert an integer constant expression into assembler syntax.
974 Addition and subtraction are the only arithmetic
975 that may appear in these expressions. This is an adaptation
976 of output_addr_const() in final.c. Here, the target of the
977 conversion is a string buffer. We can't use output_addr_const
978 directly, because it writes to a file. */
980 addr_const_to_string (str, x)
989 switch (GET_CODE (x))
999 ASM_NAME_TO_STRING (buf1, XSTR (x, 0));
1004 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
1005 ASM_NAME_TO_STRING (buf2, buf1);
1010 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
1011 ASM_NAME_TO_STRING (buf2, buf1);
1017 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
1027 /* This used to output parentheses around the expression, but that does
1028 not work on the 386 (either ATT or BSD assembler). */
1029 addr_const_to_string (buf1, XEXP (x, 0));
1034 if (GET_MODE (x) == VOIDmode)
1036 /* We can use %d if the number is one word and positive. */
1037 if (CONST_DOUBLE_HIGH (x))
1039 #if HOST_BITS_PER_WIDE_INT == 64
1040 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
1046 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
1052 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
1053 else if (CONST_DOUBLE_LOW (x) < 0)
1055 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
1060 CONST_DOUBLE_LOW (x));
1063 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
1068 CONST_DOUBLE_LOW (x));
1072 /* We can't handle floating point constants; PRINT_OPERAND must
1074 output_operand_lossage ("floating constant misused");
1078 /* Some assemblers need integer constants to appear last (eg masm). */
1079 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
1081 addr_const_to_string (buf1, XEXP (x, 1));
1083 if (INTVAL (XEXP (x, 0)) >= 0)
1085 addr_const_to_string (buf1, XEXP (x, 0));
1090 addr_const_to_string (buf1, XEXP (x, 0));
1092 if (INTVAL (XEXP (x, 1)) >= 0)
1094 addr_const_to_string (buf1, XEXP (x, 1));
1100 /* Avoid outputting things like x-x or x+5-x, since some assemblers
1101 can't handle that. */
1102 x = simplify_subtraction (x);
1103 if (GET_CODE (x) != MINUS)
1106 addr_const_to_string (buf1, XEXP (x, 0));
1109 if (GET_CODE (XEXP (x, 1)) == CONST_INT
1110 && INTVAL (XEXP (x, 1)) < 0)
1112 strcat (str, ASM_OPEN_PAREN);
1113 addr_const_to_string (buf1, XEXP (x, 1));
1115 strcat (str, ASM_CLOSE_PAREN);
1119 addr_const_to_string (buf1, XEXP (x, 1));
1126 addr_const_to_string (buf1, XEXP (x, 0));
1131 output_operand_lossage ("invalid expression as operand");
1135 /* Convert an address constant to a string, and return a pointer to
1136 a copy of the result, located on the heap. */
1142 addr_const_to_string (buf, x);
1143 return xstrdup (buf);
1146 /* Test if rtl node points to a psuedo register. */
1151 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
1152 || ((GET_CODE (rtl) == SUBREG)
1153 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
1157 /* Return a reference to a type, with its const and volatile qualifiers
1160 type_main_variant (type)
1163 type = TYPE_MAIN_VARIANT (type);
1165 /* There really should be only one main variant among any group of variants
1166 of a given type (and all of the MAIN_VARIANT values for all members of
1167 the group should point to that one type) but sometimes the C front-end
1168 messes this up for array types, so we work around that bug here. */
1169 if (TREE_CODE (type) == ARRAY_TYPE)
1171 while (type != TYPE_MAIN_VARIANT (type))
1172 type = TYPE_MAIN_VARIANT (type);
1177 /* Return non-zero if the given type node represents a tagged type. */
1179 is_tagged_type (type)
1182 register enum tree_code code = TREE_CODE (type);
1184 return (code == RECORD_TYPE || code == UNION_TYPE
1185 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
1188 /* Convert a DIE tag into its string name. */
1190 dwarf_tag_name (tag)
1191 register unsigned tag;
1195 case DW_TAG_padding:
1196 return "DW_TAG_padding";
1197 case DW_TAG_array_type:
1198 return "DW_TAG_array_type";
1199 case DW_TAG_class_type:
1200 return "DW_TAG_class_type";
1201 case DW_TAG_entry_point:
1202 return "DW_TAG_entry_point";
1203 case DW_TAG_enumeration_type:
1204 return "DW_TAG_enumeration_type";
1205 case DW_TAG_formal_parameter:
1206 return "DW_TAG_formal_parameter";
1207 case DW_TAG_imported_declaration:
1208 return "DW_TAG_imported_declaration";
1210 return "DW_TAG_label";
1211 case DW_TAG_lexical_block:
1212 return "DW_TAG_lexical_block";
1214 return "DW_TAG_member";
1215 case DW_TAG_pointer_type:
1216 return "DW_TAG_pointer_type";
1217 case DW_TAG_reference_type:
1218 return "DW_TAG_reference_type";
1219 case DW_TAG_compile_unit:
1220 return "DW_TAG_compile_unit";
1221 case DW_TAG_string_type:
1222 return "DW_TAG_string_type";
1223 case DW_TAG_structure_type:
1224 return "DW_TAG_structure_type";
1225 case DW_TAG_subroutine_type:
1226 return "DW_TAG_subroutine_type";
1227 case DW_TAG_typedef:
1228 return "DW_TAG_typedef";
1229 case DW_TAG_union_type:
1230 return "DW_TAG_union_type";
1231 case DW_TAG_unspecified_parameters:
1232 return "DW_TAG_unspecified_parameters";
1233 case DW_TAG_variant:
1234 return "DW_TAG_variant";
1235 case DW_TAG_common_block:
1236 return "DW_TAG_common_block";
1237 case DW_TAG_common_inclusion:
1238 return "DW_TAG_common_inclusion";
1239 case DW_TAG_inheritance:
1240 return "DW_TAG_inheritance";
1241 case DW_TAG_inlined_subroutine:
1242 return "DW_TAG_inlined_subroutine";
1244 return "DW_TAG_module";
1245 case DW_TAG_ptr_to_member_type:
1246 return "DW_TAG_ptr_to_member_type";
1247 case DW_TAG_set_type:
1248 return "DW_TAG_set_type";
1249 case DW_TAG_subrange_type:
1250 return "DW_TAG_subrange_type";
1251 case DW_TAG_with_stmt:
1252 return "DW_TAG_with_stmt";
1253 case DW_TAG_access_declaration:
1254 return "DW_TAG_access_declaration";
1255 case DW_TAG_base_type:
1256 return "DW_TAG_base_type";
1257 case DW_TAG_catch_block:
1258 return "DW_TAG_catch_block";
1259 case DW_TAG_const_type:
1260 return "DW_TAG_const_type";
1261 case DW_TAG_constant:
1262 return "DW_TAG_constant";
1263 case DW_TAG_enumerator:
1264 return "DW_TAG_enumerator";
1265 case DW_TAG_file_type:
1266 return "DW_TAG_file_type";
1268 return "DW_TAG_friend";
1269 case DW_TAG_namelist:
1270 return "DW_TAG_namelist";
1271 case DW_TAG_namelist_item:
1272 return "DW_TAG_namelist_item";
1273 case DW_TAG_packed_type:
1274 return "DW_TAG_packed_type";
1275 case DW_TAG_subprogram:
1276 return "DW_TAG_subprogram";
1277 case DW_TAG_template_type_param:
1278 return "DW_TAG_template_type_param";
1279 case DW_TAG_template_value_param:
1280 return "DW_TAG_template_value_param";
1281 case DW_TAG_thrown_type:
1282 return "DW_TAG_thrown_type";
1283 case DW_TAG_try_block:
1284 return "DW_TAG_try_block";
1285 case DW_TAG_variant_part:
1286 return "DW_TAG_variant_part";
1287 case DW_TAG_variable:
1288 return "DW_TAG_variable";
1289 case DW_TAG_volatile_type:
1290 return "DW_TAG_volatile_type";
1291 case DW_TAG_MIPS_loop:
1292 return "DW_TAG_MIPS_loop";
1293 case DW_TAG_format_label:
1294 return "DW_TAG_format_label";
1295 case DW_TAG_function_template:
1296 return "DW_TAG_function_template";
1297 case DW_TAG_class_template:
1298 return "DW_TAG_class_template";
1300 return "DW_TAG_<unknown>";
1304 /* Convert a DWARF attribute code into its string name. */
1306 dwarf_attr_name (attr)
1307 register unsigned attr;
1312 return "DW_AT_sibling";
1313 case DW_AT_location:
1314 return "DW_AT_location";
1316 return "DW_AT_name";
1317 case DW_AT_ordering:
1318 return "DW_AT_ordering";
1319 case DW_AT_subscr_data:
1320 return "DW_AT_subscr_data";
1321 case DW_AT_byte_size:
1322 return "DW_AT_byte_size";
1323 case DW_AT_bit_offset:
1324 return "DW_AT_bit_offset";
1325 case DW_AT_bit_size:
1326 return "DW_AT_bit_size";
1327 case DW_AT_element_list:
1328 return "DW_AT_element_list";
1329 case DW_AT_stmt_list:
1330 return "DW_AT_stmt_list";
1332 return "DW_AT_low_pc";
1334 return "DW_AT_high_pc";
1335 case DW_AT_language:
1336 return "DW_AT_language";
1338 return "DW_AT_member";
1340 return "DW_AT_discr";
1341 case DW_AT_discr_value:
1342 return "DW_AT_discr_value";
1343 case DW_AT_visibility:
1344 return "DW_AT_visibility";
1346 return "DW_AT_import";
1347 case DW_AT_string_length:
1348 return "DW_AT_string_length";
1349 case DW_AT_common_reference:
1350 return "DW_AT_common_reference";
1351 case DW_AT_comp_dir:
1352 return "DW_AT_comp_dir";
1353 case DW_AT_const_value:
1354 return "DW_AT_const_value";
1355 case DW_AT_containing_type:
1356 return "DW_AT_containing_type";
1357 case DW_AT_default_value:
1358 return "DW_AT_default_value";
1360 return "DW_AT_inline";
1361 case DW_AT_is_optional:
1362 return "DW_AT_is_optional";
1363 case DW_AT_lower_bound:
1364 return "DW_AT_lower_bound";
1365 case DW_AT_producer:
1366 return "DW_AT_producer";
1367 case DW_AT_prototyped:
1368 return "DW_AT_prototyped";
1369 case DW_AT_return_addr:
1370 return "DW_AT_return_addr";
1371 case DW_AT_start_scope:
1372 return "DW_AT_start_scope";
1373 case DW_AT_stride_size:
1374 return "DW_AT_stride_size";
1375 case DW_AT_upper_bound:
1376 return "DW_AT_upper_bound";
1377 case DW_AT_abstract_origin:
1378 return "DW_AT_abstract_origin";
1379 case DW_AT_accessibility:
1380 return "DW_AT_accessibility";
1381 case DW_AT_address_class:
1382 return "DW_AT_address_class";
1383 case DW_AT_artificial:
1384 return "DW_AT_artificial";
1385 case DW_AT_base_types:
1386 return "DW_AT_base_types";
1387 case DW_AT_calling_convention:
1388 return "DW_AT_calling_convention";
1390 return "DW_AT_count";
1391 case DW_AT_data_member_location:
1392 return "DW_AT_data_member_location";
1393 case DW_AT_decl_column:
1394 return "DW_AT_decl_column";
1395 case DW_AT_decl_file:
1396 return "DW_AT_decl_file";
1397 case DW_AT_decl_line:
1398 return "DW_AT_decl_line";
1399 case DW_AT_declaration:
1400 return "DW_AT_declaration";
1401 case DW_AT_discr_list:
1402 return "DW_AT_discr_list";
1403 case DW_AT_encoding:
1404 return "DW_AT_encoding";
1405 case DW_AT_external:
1406 return "DW_AT_external";
1407 case DW_AT_frame_base:
1408 return "DW_AT_frame_base";
1410 return "DW_AT_friend";
1411 case DW_AT_identifier_case:
1412 return "DW_AT_identifier_case";
1413 case DW_AT_macro_info:
1414 return "DW_AT_macro_info";
1415 case DW_AT_namelist_items:
1416 return "DW_AT_namelist_items";
1417 case DW_AT_priority:
1418 return "DW_AT_priority";
1420 return "DW_AT_segment";
1421 case DW_AT_specification:
1422 return "DW_AT_specification";
1423 case DW_AT_static_link:
1424 return "DW_AT_static_link";
1426 return "DW_AT_type";
1427 case DW_AT_use_location:
1428 return "DW_AT_use_location";
1429 case DW_AT_variable_parameter:
1430 return "DW_AT_variable_parameter";
1431 case DW_AT_virtuality:
1432 return "DW_AT_virtuality";
1433 case DW_AT_vtable_elem_location:
1434 return "DW_AT_vtable_elem_location";
1436 case DW_AT_MIPS_fde:
1437 return "DW_AT_MIPS_fde";
1438 case DW_AT_MIPS_loop_begin:
1439 return "DW_AT_MIPS_loop_begin";
1440 case DW_AT_MIPS_tail_loop_begin:
1441 return "DW_AT_MIPS_tail_loop_begin";
1442 case DW_AT_MIPS_epilog_begin:
1443 return "DW_AT_MIPS_epilog_begin";
1444 case DW_AT_MIPS_loop_unroll_factor:
1445 return "DW_AT_MIPS_loop_unroll_factor";
1446 case DW_AT_MIPS_software_pipeline_depth:
1447 return "DW_AT_MIPS_software_pipeline_depth";
1448 case DW_AT_MIPS_linkage_name:
1449 return "DW_AT_MIPS_linkage_name";
1450 case DW_AT_MIPS_stride:
1451 return "DW_AT_MIPS_stride";
1452 case DW_AT_MIPS_abstract_name:
1453 return "DW_AT_MIPS_abstract_name";
1454 case DW_AT_MIPS_clone_origin:
1455 return "DW_AT_MIPS_clone_origin";
1456 case DW_AT_MIPS_has_inlines:
1457 return "DW_AT_MIPS_has_inlines";
1459 case DW_AT_sf_names:
1460 return "DW_AT_sf_names";
1461 case DW_AT_src_info:
1462 return "DW_AT_src_info";
1463 case DW_AT_mac_info:
1464 return "DW_AT_mac_info";
1465 case DW_AT_src_coords:
1466 return "DW_AT_src_coords";
1467 case DW_AT_body_begin:
1468 return "DW_AT_body_begin";
1469 case DW_AT_body_end:
1470 return "DW_AT_body_end";
1472 return "DW_AT_<unknown>";
1476 /* Convert a DWARF value form code into its string name. */
1478 dwarf_form_name (form)
1479 register unsigned form;
1484 return "DW_FORM_addr";
1485 case DW_FORM_block2:
1486 return "DW_FORM_block2";
1487 case DW_FORM_block4:
1488 return "DW_FORM_block4";
1490 return "DW_FORM_data2";
1492 return "DW_FORM_data4";
1494 return "DW_FORM_data8";
1495 case DW_FORM_string:
1496 return "DW_FORM_string";
1498 return "DW_FORM_block";
1499 case DW_FORM_block1:
1500 return "DW_FORM_block1";
1502 return "DW_FORM_data1";
1504 return "DW_FORM_flag";
1506 return "DW_FORM_sdata";
1508 return "DW_FORM_strp";
1510 return "DW_FORM_udata";
1511 case DW_FORM_ref_addr:
1512 return "DW_FORM_ref_addr";
1514 return "DW_FORM_ref1";
1516 return "DW_FORM_ref2";
1518 return "DW_FORM_ref4";
1520 return "DW_FORM_ref8";
1521 case DW_FORM_ref_udata:
1522 return "DW_FORM_ref_udata";
1523 case DW_FORM_indirect:
1524 return "DW_FORM_indirect";
1526 return "DW_FORM_<unknown>";
1530 /* Convert a DWARF stack opcode into its string name. */
1532 dwarf_stack_op_name (op)
1533 register unsigned op;
1538 return "DW_OP_addr";
1540 return "DW_OP_deref";
1542 return "DW_OP_const1u";
1544 return "DW_OP_const1s";
1546 return "DW_OP_const2u";
1548 return "DW_OP_const2s";
1550 return "DW_OP_const4u";
1552 return "DW_OP_const4s";
1554 return "DW_OP_const8u";
1556 return "DW_OP_const8s";
1558 return "DW_OP_constu";
1560 return "DW_OP_consts";
1564 return "DW_OP_drop";
1566 return "DW_OP_over";
1568 return "DW_OP_pick";
1570 return "DW_OP_swap";
1574 return "DW_OP_xderef";
1582 return "DW_OP_minus";
1594 return "DW_OP_plus";
1595 case DW_OP_plus_uconst:
1596 return "DW_OP_plus_uconst";
1602 return "DW_OP_shra";
1620 return "DW_OP_skip";
1622 return "DW_OP_lit0";
1624 return "DW_OP_lit1";
1626 return "DW_OP_lit2";
1628 return "DW_OP_lit3";
1630 return "DW_OP_lit4";
1632 return "DW_OP_lit5";
1634 return "DW_OP_lit6";
1636 return "DW_OP_lit7";
1638 return "DW_OP_lit8";
1640 return "DW_OP_lit9";
1642 return "DW_OP_lit10";
1644 return "DW_OP_lit11";
1646 return "DW_OP_lit12";
1648 return "DW_OP_lit13";
1650 return "DW_OP_lit14";
1652 return "DW_OP_lit15";
1654 return "DW_OP_lit16";
1656 return "DW_OP_lit17";
1658 return "DW_OP_lit18";
1660 return "DW_OP_lit19";
1662 return "DW_OP_lit20";
1664 return "DW_OP_lit21";
1666 return "DW_OP_lit22";
1668 return "DW_OP_lit23";
1670 return "DW_OP_lit24";
1672 return "DW_OP_lit25";
1674 return "DW_OP_lit26";
1676 return "DW_OP_lit27";
1678 return "DW_OP_lit28";
1680 return "DW_OP_lit29";
1682 return "DW_OP_lit30";
1684 return "DW_OP_lit31";
1686 return "DW_OP_reg0";
1688 return "DW_OP_reg1";
1690 return "DW_OP_reg2";
1692 return "DW_OP_reg3";
1694 return "DW_OP_reg4";
1696 return "DW_OP_reg5";
1698 return "DW_OP_reg6";
1700 return "DW_OP_reg7";
1702 return "DW_OP_reg8";
1704 return "DW_OP_reg9";
1706 return "DW_OP_reg10";
1708 return "DW_OP_reg11";
1710 return "DW_OP_reg12";
1712 return "DW_OP_reg13";
1714 return "DW_OP_reg14";
1716 return "DW_OP_reg15";
1718 return "DW_OP_reg16";
1720 return "DW_OP_reg17";
1722 return "DW_OP_reg18";
1724 return "DW_OP_reg19";
1726 return "DW_OP_reg20";
1728 return "DW_OP_reg21";
1730 return "DW_OP_reg22";
1732 return "DW_OP_reg23";
1734 return "DW_OP_reg24";
1736 return "DW_OP_reg25";
1738 return "DW_OP_reg26";
1740 return "DW_OP_reg27";
1742 return "DW_OP_reg28";
1744 return "DW_OP_reg29";
1746 return "DW_OP_reg30";
1748 return "DW_OP_reg31";
1750 return "DW_OP_breg0";
1752 return "DW_OP_breg1";
1754 return "DW_OP_breg2";
1756 return "DW_OP_breg3";
1758 return "DW_OP_breg4";
1760 return "DW_OP_breg5";
1762 return "DW_OP_breg6";
1764 return "DW_OP_breg7";
1766 return "DW_OP_breg8";
1768 return "DW_OP_breg9";
1770 return "DW_OP_breg10";
1772 return "DW_OP_breg11";
1774 return "DW_OP_breg12";
1776 return "DW_OP_breg13";
1778 return "DW_OP_breg14";
1780 return "DW_OP_breg15";
1782 return "DW_OP_breg16";
1784 return "DW_OP_breg17";
1786 return "DW_OP_breg18";
1788 return "DW_OP_breg19";
1790 return "DW_OP_breg20";
1792 return "DW_OP_breg21";
1794 return "DW_OP_breg22";
1796 return "DW_OP_breg23";
1798 return "DW_OP_breg24";
1800 return "DW_OP_breg25";
1802 return "DW_OP_breg26";
1804 return "DW_OP_breg27";
1806 return "DW_OP_breg28";
1808 return "DW_OP_breg29";
1810 return "DW_OP_breg30";
1812 return "DW_OP_breg31";
1814 return "DW_OP_regx";
1816 return "DW_OP_fbreg";
1818 return "DW_OP_bregx";
1820 return "DW_OP_piece";
1821 case DW_OP_deref_size:
1822 return "DW_OP_deref_size";
1823 case DW_OP_xderef_size:
1824 return "DW_OP_xderef_size";
1828 return "OP_<unknown>";
1832 /* Convert a DWARF type code into its string name. */
1834 dwarf_type_encoding_name (enc)
1835 register unsigned enc;
1839 case DW_ATE_address:
1840 return "DW_ATE_address";
1841 case DW_ATE_boolean:
1842 return "DW_ATE_boolean";
1843 case DW_ATE_complex_float:
1844 return "DW_ATE_complex_float";
1846 return "DW_ATE_float";
1848 return "DW_ATE_signed";
1849 case DW_ATE_signed_char:
1850 return "DW_ATE_signed_char";
1851 case DW_ATE_unsigned:
1852 return "DW_ATE_unsigned";
1853 case DW_ATE_unsigned_char:
1854 return "DW_ATE_unsigned_char";
1856 return "DW_ATE_<unknown>";
1860 /* Convert a DWARF call frame info. operation to its string name */
1862 dwarf_cfi_name (cfi_opc)
1863 register unsigned cfi_opc;
1867 case DW_CFA_advance_loc:
1868 return "DW_CFA_advance_loc";
1870 return "DW_CFA_offset";
1871 case DW_CFA_restore:
1872 return "DW_CFA_restore";
1874 return "DW_CFA_nop";
1875 case DW_CFA_set_loc:
1876 return "DW_CFA_set_loc";
1877 case DW_CFA_advance_loc1:
1878 return "DW_CFA_advance_loc1";
1879 case DW_CFA_advance_loc2:
1880 return "DW_CFA_advance_loc2";
1881 case DW_CFA_advance_loc4:
1882 return "DW_CFA_advance_loc4";
1883 case DW_CFA_offset_extended:
1884 return "DW_CFA_offset_extended";
1885 case DW_CFA_restore_extended:
1886 return "DW_CFA_restore_extended";
1887 case DW_CFA_undefined:
1888 return "DW_CFA_undefined";
1889 case DW_CFA_same_value:
1890 return "DW_CFA_same_value";
1891 case DW_CFA_register:
1892 return "DW_CFA_register";
1893 case DW_CFA_remember_state:
1894 return "DW_CFA_remember_state";
1895 case DW_CFA_restore_state:
1896 return "DW_CFA_restore_state";
1897 case DW_CFA_def_cfa:
1898 return "DW_CFA_def_cfa";
1899 case DW_CFA_def_cfa_register:
1900 return "DW_CFA_def_cfa_register";
1901 case DW_CFA_def_cfa_offset:
1902 return "DW_CFA_def_cfa_offset";
1903 /* SGI/MIPS specific */
1904 case DW_CFA_MIPS_advance_loc8:
1905 return "DW_CFA_MIPS_advance_loc8";
1907 return "DW_CFA_<unknown>";
1911 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
1912 instance of an inlined instance of a decl which is local to an inline
1913 function, so we have to trace all of the way back through the origin chain
1914 to find out what sort of node actually served as the original seed for the
1917 decl_ultimate_origin (decl)
1920 register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
1922 if (immediate_origin == NULL)
1926 register tree ret_val;
1927 register tree lookahead = immediate_origin;
1931 ret_val = lookahead;
1932 lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
1934 while (lookahead != NULL && lookahead != ret_val);
1939 /* Determine the "ultimate origin" of a block. The block may be an inlined
1940 instance of an inlined instance of a block which is local to an inline
1941 function, so we have to trace all of the way back through the origin chain
1942 to find out what sort of node actually served as the original seed for the
1945 block_ultimate_origin (block)
1946 register tree block;
1948 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
1950 if (immediate_origin == NULL)
1954 register tree ret_val;
1955 register tree lookahead = immediate_origin;
1959 ret_val = lookahead;
1960 lookahead = (TREE_CODE (ret_val) == BLOCK)
1961 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
1964 while (lookahead != NULL && lookahead != ret_val);
1969 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
1970 of a virtual function may refer to a base class, so we check the 'this'
1974 decl_class_context (decl)
1977 tree context = NULL_TREE;
1978 if (TREE_CODE (decl) != FUNCTION_DECL
1979 || ! DECL_VIRTUAL_P (decl))
1980 context = DECL_CONTEXT (decl);
1982 context = TYPE_MAIN_VARIANT
1983 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
1985 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
1986 context = NULL_TREE;
1991 /**************** DIE internal representation constturction *******************/
1993 /* Add an attribute/value pair to a DIE */
1995 add_dwarf_attr (die, attr)
1996 register dw_die_ref die;
1997 register dw_attr_ref attr;
1999 if (die != NULL && attr != NULL)
2001 if (die->die_attr == NULL)
2003 die->die_attr = attr;
2004 die->die_attr_last = attr;
2008 die->die_attr_last->dw_attr_next = attr;
2009 die->die_attr_last = attr;
2014 /* Add a flag value attribute to a DIE. */
2016 add_AT_flag (die, attr_kind, flag)
2017 register dw_die_ref die;
2018 register enum dwarf_attribute attr_kind;
2019 register unsigned flag;
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_flag;
2027 attr->dw_attr_val.v.val_flag = flag;
2028 add_dwarf_attr (die, attr);
2032 /* Add a signed integer attribute value to a DIE. */
2034 add_AT_int (die, attr_kind, int_val)
2035 register dw_die_ref die;
2036 register enum dwarf_attribute attr_kind;
2037 register long int int_val;
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_const;
2045 attr->dw_attr_val.v.val_int = int_val;
2046 add_dwarf_attr (die, attr);
2050 /* Add an unsigned integer attribute value to a DIE. */
2052 add_AT_unsigned (die, attr_kind, unsigned_val)
2053 register dw_die_ref die;
2054 register enum dwarf_attribute attr_kind;
2055 register unsigned long unsigned_val;
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_unsigned_const;
2063 attr->dw_attr_val.v.val_unsigned = unsigned_val;
2064 add_dwarf_attr (die, attr);
2068 /* Add an unsigned double integer attribute value to a DIE. */
2070 add_AT_double (die, attr_kind, val_hi, val_low)
2071 register dw_die_ref die;
2072 register enum dwarf_attribute attr_kind;
2073 register unsigned long val_hi;
2074 register unsigned long val_low;
2076 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2079 attr->dw_attr_next = NULL;
2080 attr->dw_attr = attr_kind;
2081 attr->dw_attr_val.val_class = dw_val_class_double_const;
2082 attr->dw_attr_val.v.val_dbl_const.dw_dbl_hi = val_hi;
2083 attr->dw_attr_val.v.val_dbl_const.dw_dbl_low = val_low;
2084 add_dwarf_attr (die, attr);
2088 /* Add a string attribute value to a DIE. */
2090 add_AT_string (die, attr_kind, str)
2091 register dw_die_ref die;
2092 register enum dwarf_attribute attr_kind;
2095 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2098 attr->dw_attr_next = NULL;
2099 attr->dw_attr = attr_kind;
2100 attr->dw_attr_val.val_class = dw_val_class_str;
2101 attr->dw_attr_val.v.val_str = xstrdup (str);
2102 add_dwarf_attr (die, attr);
2106 /* Add a DIE reference attribute value to a DIE. */
2108 add_AT_die_ref (die, attr_kind, targ_die)
2109 register dw_die_ref die;
2110 register enum dwarf_attribute attr_kind;
2111 register dw_die_ref targ_die;
2113 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2116 attr->dw_attr_next = NULL;
2117 attr->dw_attr = attr_kind;
2118 attr->dw_attr_val.val_class = dw_val_class_die_ref;
2119 attr->dw_attr_val.v.val_die_ref = targ_die;
2120 add_dwarf_attr (die, attr);
2124 /* Add an FDE reference attribute value to a DIE. */
2126 add_AT_fde_ref (die, attr_kind, targ_fde)
2127 register dw_die_ref die;
2128 register enum dwarf_attribute attr_kind;
2129 register unsigned targ_fde;
2131 register dw_attr_ref attr;
2133 attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2136 attr->dw_attr_next = NULL;
2137 attr->dw_attr = attr_kind;
2138 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
2139 attr->dw_attr_val.v.val_fde_index = targ_fde;
2140 add_dwarf_attr (die, attr);
2144 /* Add a location description attribute value to a DIE. */
2146 add_AT_loc (die, attr_kind, loc)
2147 register dw_die_ref die;
2148 register enum dwarf_attribute attr_kind;
2149 register dw_loc_descr_ref loc;
2151 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2154 attr->dw_attr_next = NULL;
2155 attr->dw_attr = attr_kind;
2156 attr->dw_attr_val.val_class = dw_val_class_loc;
2157 attr->dw_attr_val.v.val_loc = loc;
2158 add_dwarf_attr (die, attr);
2162 /* Add an address constant attribute value to a DIE. */
2164 add_AT_addr (die, attr_kind, addr)
2165 register dw_die_ref die;
2166 register enum dwarf_attribute attr_kind;
2169 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2172 attr->dw_attr_next = NULL;
2173 attr->dw_attr = attr_kind;
2174 attr->dw_attr_val.val_class = dw_val_class_addr;
2175 attr->dw_attr_val.v.val_addr = addr;
2176 add_dwarf_attr (die, attr);
2180 /* Add a label identifier attribute value to a DIE. */
2182 add_AT_lbl_id (die, attr_kind, lbl_id)
2183 register dw_die_ref die;
2184 register enum dwarf_attribute attr_kind;
2185 register char *lbl_id;
2187 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2190 attr->dw_attr_next = NULL;
2191 attr->dw_attr = attr_kind;
2192 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
2193 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
2194 add_dwarf_attr (die, attr);
2198 /* Add a section offset attribute value to a DIE. */
2200 add_AT_section_offset (die, attr_kind, section)
2201 register dw_die_ref die;
2202 register enum dwarf_attribute attr_kind;
2203 register char *section;
2205 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2208 attr->dw_attr_next = NULL;
2209 attr->dw_attr = attr_kind;
2210 attr->dw_attr_val.val_class = dw_val_class_section_offset;
2211 attr->dw_attr_val.v.val_section = section;
2212 add_dwarf_attr (die, attr);
2216 /* Test if die refers to an external subroutine. */
2218 is_extern_subr_die (die)
2219 register dw_die_ref die;
2221 register dw_attr_ref a;
2222 register int is_subr = FALSE;
2223 register int is_extern = FALSE;
2224 if (die != NULL && die->die_tag == DW_TAG_subprogram)
2227 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2229 if (a->dw_attr == DW_AT_external
2230 && a->dw_attr_val.val_class == dw_val_class_flag
2231 && a->dw_attr_val.v.val_flag != 0)
2238 return is_subr && is_extern;
2241 /* Get the attribute of type attr_kind. */
2243 get_AT (die, attr_kind)
2244 register dw_die_ref die;
2245 register enum dwarf_attribute attr_kind;
2247 register dw_attr_ref a;
2248 register dw_die_ref spec = NULL;
2252 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2254 if (a->dw_attr == attr_kind)
2256 if (a->dw_attr == DW_AT_specification
2257 || a->dw_attr == DW_AT_abstract_origin)
2258 spec = a->dw_attr_val.v.val_die_ref;
2261 return get_AT (spec, attr_kind);
2266 /* Return the "low pc" attribute value, typically associated with
2267 a subprogram DIE. Return null if the "low pc" attribute is
2268 either not prsent, or if it cannot be represented as an
2269 assembler label identifier. */
2272 register dw_die_ref die;
2274 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
2275 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
2276 return a->dw_attr_val.v.val_lbl_id;
2280 /* Return the "high pc" attribute value, typically associated with
2281 a subprogram DIE. Return null if the "high pc" attribute is
2282 either not prsent, or if it cannot be represented as an
2283 assembler label identifier. */
2286 register dw_die_ref die;
2288 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
2289 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
2290 return a->dw_attr_val.v.val_lbl_id;
2294 /* Return the value of the string attribute designated by ATTR_KIND, or
2295 NULL if it is not present. */
2297 get_AT_string (die, attr_kind)
2298 register dw_die_ref die;
2299 register enum dwarf_attribute attr_kind;
2301 register dw_attr_ref a = get_AT (die, attr_kind);
2302 if (a && a->dw_attr_val.val_class == dw_val_class_str)
2303 return a->dw_attr_val.v.val_str;
2307 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
2308 if it is not present. */
2310 get_AT_flag (die, attr_kind)
2311 register dw_die_ref die;
2312 register enum dwarf_attribute attr_kind;
2314 register dw_attr_ref a = get_AT (die, attr_kind);
2315 if (a && a->dw_attr_val.val_class == dw_val_class_flag)
2316 return a->dw_attr_val.v.val_flag;
2320 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
2321 if it is not present. */
2323 get_AT_unsigned (die, attr_kind)
2324 register dw_die_ref die;
2325 register enum dwarf_attribute attr_kind;
2327 register dw_attr_ref a = get_AT (die, attr_kind);
2328 if (a && a->dw_attr_val.val_class == dw_val_class_unsigned_const)
2329 return a->dw_attr_val.v.val_unsigned;
2333 /* Remove the specified attribute if present. */
2335 remove_AT (die, attr_kind)
2336 register dw_die_ref die;
2337 register enum dwarf_attribute attr_kind;
2339 register dw_attr_ref a;
2340 register dw_attr_ref removed = NULL;;
2343 if (die->die_attr->dw_attr == attr_kind)
2345 removed = die->die_attr;
2346 if (die->die_attr_last == die->die_attr)
2347 die->die_attr_last = NULL;
2348 die->die_attr = die->die_attr->dw_attr_next;
2350 else for (a = die->die_attr; a->dw_attr_next != NULL;
2351 a = a->dw_attr_next)
2352 if (a->dw_attr_next->dw_attr == attr_kind)
2354 removed = a->dw_attr_next;
2355 if (die->die_attr_last == a->dw_attr_next)
2356 die->die_attr_last = a;
2357 a->dw_attr_next = a->dw_attr_next->dw_attr_next;
2365 /* Discard the children of this DIE. */
2367 remove_children (die)
2368 register dw_die_ref die;
2370 register dw_die_ref child_die = die->die_child;
2371 die->die_child = NULL;
2372 die->die_child_last = NULL;
2373 while (child_die != NULL)
2375 register dw_die_ref tmp_die = child_die;
2376 register dw_attr_ref a;
2377 child_die = child_die->die_sib;
2379 for (a = tmp_die->die_attr; a != NULL; )
2381 register dw_attr_ref tmp_a = a;
2382 a = a->dw_attr_next;
2389 /* Add a child DIE below its parent. */
2391 add_child_die (die, child_die)
2392 register dw_die_ref die;
2393 register dw_die_ref child_die;
2395 if (die != NULL && child_die != NULL)
2397 assert (die != child_die);
2398 child_die->die_parent = die;
2399 child_die->die_sib = NULL;
2400 if (die->die_child == NULL)
2402 die->die_child = child_die;
2403 die->die_child_last = child_die;
2407 die->die_child_last->die_sib = child_die;
2408 die->die_child_last = child_die;
2413 /* Return a pointer to a newly created DIE node. */
2415 new_die (tag_value, parent_die)
2416 register enum dwarf_tag tag_value;
2417 register dw_die_ref parent_die;
2419 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
2422 die->die_tag = tag_value;
2423 die->die_abbrev = 0;
2424 die->die_offset = 0;
2425 die->die_child = NULL;
2426 die->die_parent = NULL;
2427 die->die_sib = NULL;
2428 die->die_child_last = NULL;
2429 die->die_attr = NULL;
2430 die->die_attr_last = NULL;
2431 if (parent_die != NULL)
2433 add_child_die (parent_die, die);
2439 /* Return the DIE associated with the given type specifier. */
2441 lookup_type_die (type)
2444 register unsigned type_id = TYPE_UID (type);
2445 return (type_id < type_die_table_in_use)
2446 ? type_die_table[type_id] : NULL;
2449 /* Equate a DIE to a given type specifier. */
2451 equate_type_number_to_die (type, type_die)
2453 register dw_die_ref type_die;
2455 register unsigned type_id = TYPE_UID (type);
2456 register unsigned i;
2457 register unsigned num_allocated;
2458 if (type_id >= type_die_table_allocated)
2460 num_allocated = (((type_id + 1)
2461 + TYPE_DIE_TABLE_INCREMENT - 1)
2462 / TYPE_DIE_TABLE_INCREMENT)
2463 * TYPE_DIE_TABLE_INCREMENT;
2464 type_die_table = (dw_die_ref *) xrealloc (type_die_table,
2465 sizeof (dw_die_ref) * num_allocated);
2466 bzero (&type_die_table[type_die_table_allocated],
2467 (num_allocated - type_die_table_allocated) * sizeof (dw_die_ref));
2468 type_die_table_allocated = num_allocated;
2470 if (type_id >= type_die_table_in_use)
2472 type_die_table_in_use = (type_id + 1);
2474 type_die_table[type_id] = type_die;
2477 /* Return the DIE associated with a given declaration. */
2479 lookup_decl_die (decl)
2482 register unsigned decl_id = DECL_UID (decl);
2483 return (decl_id < decl_die_table_in_use)
2484 ? decl_die_table[decl_id] : NULL;
2487 /* Equate a DIE to a particular declaration. */
2489 equate_decl_number_to_die (decl, decl_die)
2491 register dw_die_ref decl_die;
2493 register unsigned decl_id = DECL_UID (decl);
2494 register unsigned i;
2495 register unsigned num_allocated;
2496 if (decl_id >= decl_die_table_allocated)
2498 num_allocated = (((decl_id + 1)
2499 + DECL_DIE_TABLE_INCREMENT - 1)
2500 / DECL_DIE_TABLE_INCREMENT)
2501 * DECL_DIE_TABLE_INCREMENT;
2502 decl_die_table = (dw_die_ref *) xrealloc (decl_die_table,
2503 sizeof (dw_die_ref) * num_allocated);
2504 bzero (&decl_die_table[decl_die_table_allocated],
2505 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
2506 decl_die_table_allocated = num_allocated;
2508 if (decl_id >= decl_die_table_in_use)
2510 decl_die_table_in_use = (decl_id + 1);
2512 decl_die_table[decl_id] = decl_die;
2515 /* Return a pointer to a newly allocated location description. Location
2516 descriptions are simple expression terms that can be strung
2517 together to form more complicated location (address) descriptions. */
2518 inline dw_loc_descr_ref
2519 new_loc_descr (op, oprnd1, oprnd2)
2520 register enum dwarf_location_atom op;
2521 register unsigned long oprnd1;
2522 register unsigned long oprnd2;
2524 register dw_loc_descr_ref descr =
2525 (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
2528 descr->dw_loc_next = NULL;
2529 descr->dw_loc_opc = op;
2530 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2531 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2532 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2533 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2538 /* Add a location description term to a location description expression. */
2540 add_loc_descr (list_head, descr)
2541 register dw_loc_descr_ref *list_head;
2542 register dw_loc_descr_ref descr;
2544 register dw_loc_descr_ref *d;
2545 /* find the end of the chain. */
2546 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2553 /* Return a pointer to a newly allocated Call Frame Instruction. */
2557 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
2560 cfi->dw_cfi_next = NULL;
2561 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
2562 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
2567 /* Add a Call Frame Instruction to list of instructions. */
2569 add_cfi (list_head, cfi)
2570 register dw_cfi_ref *list_head;
2571 register dw_cfi_ref cfi;
2573 register dw_cfi_ref *p;
2574 /* find the end of the chain. */
2575 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
2582 /********* Print DWARF Internal Representation (debugging aids) ***************/
2584 /* Keep track of the number of spaces used to indent the
2585 output of the debugging routines that print the structure of
2586 the DIE internal representation. */
2587 static int print_indent;
2589 /* Indent the line the number of spaces given by print_indent. */
2591 print_spaces (outfile)
2594 fprintf (outfile, "%*s", print_indent, "");
2597 /* Print the information assoaciated with a given DIE, and its children.
2598 This routine is a debugging aid only. */
2600 print_die (die, outfile)
2604 register dw_attr_ref a;
2605 register dw_die_ref c;
2606 print_spaces (outfile);
2607 fprintf (outfile, "DIE %4u: %s\n",
2608 die->die_offset, dwarf_tag_name (die->die_tag));
2609 print_spaces (outfile);
2610 fprintf (outfile, " abbrev id: %u", die->die_abbrev);
2611 fprintf (outfile, " offset: %u\n", die->die_offset);
2612 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2614 print_spaces (outfile);
2615 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
2616 switch (a->dw_attr_val.val_class)
2618 case dw_val_class_addr:
2619 fprintf (outfile, "address");
2621 case dw_val_class_loc:
2622 fprintf (outfile, "location descriptor");
2624 case dw_val_class_const:
2625 fprintf (outfile, "%d", a->dw_attr_val.v.val_int);
2627 case dw_val_class_unsigned_const:
2628 fprintf (outfile, "%u", a->dw_attr_val.v.val_unsigned);
2630 case dw_val_class_double_const:
2631 fprintf (outfile, "constant (%u,%u)",
2632 a->dw_attr_val.v.val_dbl_const.dw_dbl_hi,
2633 a->dw_attr_val.v.val_dbl_const.dw_dbl_low);
2635 case dw_val_class_flag:
2636 fprintf (outfile, "%u", a->dw_attr_val.v.val_flag);
2638 case dw_val_class_die_ref:
2639 if (a->dw_attr_val.v.val_die_ref != NULL)
2641 fprintf (outfile, "die -> %u",
2642 a->dw_attr_val.v.val_die_ref->die_offset);
2646 fprintf (outfile, "die -> <null>");
2649 case dw_val_class_lbl_id:
2650 fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id);
2652 case dw_val_class_section_offset:
2653 fprintf (outfile, "section: %s", a->dw_attr_val.v.val_section);
2655 case dw_val_class_str:
2656 if (a->dw_attr_val.v.val_str != NULL)
2658 fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str);
2662 fprintf (outfile, "<null>");
2666 fprintf (outfile, "\n");
2668 if (die->die_child != NULL)
2671 for (c = die->die_child; c != NULL; c = c->die_sib)
2673 print_die (c, outfile);
2679 /* Print the contents of the source code line number correspondence table.
2680 This routine is a debugging aid only. */
2682 print_dwarf_line_table (outfile)
2685 register unsigned i;
2686 register dw_line_info_ref line_info;
2687 fprintf (outfile, "\n\nDWARF source line information\n");
2688 for (i = 1; i < line_info_table_in_use; ++i)
2690 line_info = &line_info_table[i];
2691 fprintf (outfile, "%5d: ", i);
2692 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
2693 fprintf (outfile, "%6d", line_info->dw_line_num);
2694 fprintf (outfile, "\n");
2696 fprintf (outfile, "\n\n");
2699 /* Print the information collected for a given DIE. */
2701 debug_dwarf_die (die)
2704 print_die (die, stderr);
2707 /* Print all DWARF informaiton collected for the compilation unit.
2708 This routine is a debugging aid only. */
2713 print_die (comp_unit_die, stderr);
2714 print_dwarf_line_table (stderr);
2718 /***************** DWARF Information Construction Support *********************/
2720 /* Traverse the DIE, and add a sibling attribute if it may have the
2721 effect of speeding up access to siblings. To save some space,
2722 avoid generating sibling attributes for DIE's without children. */
2724 add_sibling_attributes(die)
2725 register dw_die_ref die;
2727 register dw_die_ref c;
2728 register dw_attr_ref attr;
2729 if (die != comp_unit_die && die->die_child != NULL)
2731 attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2734 attr->dw_attr_next = NULL;
2735 attr->dw_attr = DW_AT_sibling;
2736 attr->dw_attr_val.val_class = dw_val_class_die_ref;
2737 attr->dw_attr_val.v.val_die_ref = die->die_sib;
2739 /* add the sibling link to the front of the attribute list. */
2740 attr->dw_attr_next = die->die_attr;
2741 if (die->die_attr == NULL)
2743 die->die_attr_last = attr;
2745 die->die_attr = attr;
2747 for (c = die->die_child; c != NULL; c = c->die_sib)
2749 add_sibling_attributes (c);
2753 /* The format of each DIE (and its attribute value pairs)
2754 is encoded in an abbreviation table. This routine builds the
2755 abbreviation table and assigns a unique abbreviation id for
2756 each abbreviation entry. The children of each die are visited
2759 build_abbrev_table (die)
2760 register dw_die_ref die;
2762 register unsigned long abbrev_id;
2763 register unsigned long n_alloc;
2764 register dw_die_ref c;
2765 register dw_attr_ref d_attr, a_attr;
2766 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
2768 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
2769 if (abbrev->die_tag == die->die_tag)
2771 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
2773 a_attr = abbrev->die_attr;
2774 d_attr = die->die_attr;
2775 while (a_attr != NULL && d_attr != NULL)
2777 if ((a_attr->dw_attr != d_attr->dw_attr)
2778 || (a_attr->dw_attr_val.val_class
2779 != d_attr->dw_attr_val.val_class)
2780 || (a_attr->dw_attr_val.val_class
2781 == dw_val_class_unsigned_const
2782 && (constant_size (a_attr->dw_attr_val
2784 != constant_size (d_attr->dw_attr_val
2789 a_attr = a_attr->dw_attr_next;
2790 d_attr = d_attr->dw_attr_next;
2792 if (a_attr == NULL && d_attr == NULL)
2799 if (abbrev_id >= abbrev_die_table_in_use)
2801 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
2803 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
2804 abbrev_die_table = (dw_die_ref *)
2805 xmalloc (abbrev_die_table,
2806 sizeof (dw_die_ref) * n_alloc);
2807 bzero (&abbrev_die_table[abbrev_die_table_allocated],
2808 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
2809 abbrev_die_table_allocated = n_alloc;
2811 ++abbrev_die_table_in_use;
2812 abbrev_die_table[abbrev_id] = die;
2814 die->die_abbrev = abbrev_id;
2815 for (c = die->die_child; c != NULL; c = c->die_sib)
2817 build_abbrev_table (c);
2822 /********************** DWARF Information Sizing *****************************/
2824 /* Return the size of an unsigned LEB128 quantity. */
2825 inline unsigned long
2826 size_of_uleb128 (value)
2827 register unsigned long value;
2829 register unsigned long size = 0;
2830 register unsigned byte;
2833 byte = (value & 0x7f);
2841 /* Return the size of a signed LEB128 quantity. */
2842 inline unsigned long
2843 size_of_sleb128 (value)
2844 register long value;
2846 register unsigned long size = 0;
2847 register unsigned byte;
2850 byte = (value & 0x7f);
2854 while (!(((value == 0) && ((byte & 0x40) == 0))
2855 || ((value == -1) && ((byte & 0x40) != 0))));
2859 /* Return the size of a string, including the null byte. */
2860 static unsigned long
2861 size_of_string (str)
2864 register unsigned long size = 0;
2865 register unsigned long slen = strlen (str);
2866 register unsigned long i;
2867 register unsigned c;
2868 for (i = 0; i < slen; ++i)
2877 /* Null terminator. */
2882 /* Return the size of a location descriptor. */
2883 static unsigned long
2884 size_of_loc_descr (loc)
2885 register dw_loc_descr_ref loc;
2887 register unsigned long size = 1;
2888 switch (loc->dw_loc_opc)
2910 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2913 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2918 case DW_OP_plus_uconst:
2919 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2957 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2960 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2963 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2966 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2967 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2970 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2972 case DW_OP_deref_size:
2973 case DW_OP_xderef_size:
2982 /* Return the power-of-two number of bytes necessary to represent VALUE. */
2984 constant_size (value)
2985 long unsigned value;
2992 log = floor_log2 (value);
2995 log = 1 << (floor_log2 (log) + 1);
3000 /* Return the size of a DIE, as it is represented in the
3001 .debug_info section. */
3002 static unsigned long
3004 register dw_die_ref die;
3006 register unsigned long size = 0;
3007 register dw_attr_ref a;
3008 register dw_loc_descr_ref loc;
3009 size += size_of_uleb128 (die->die_abbrev);
3010 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3012 switch (a->dw_attr_val.val_class)
3014 case dw_val_class_addr:
3017 case dw_val_class_loc:
3020 for (loc = a->dw_attr_val.v.val_loc; loc != NULL;
3021 loc = loc->dw_loc_next)
3023 size += size_of_loc_descr (loc);
3026 case dw_val_class_const:
3029 case dw_val_class_unsigned_const:
3030 size += constant_size (a->dw_attr_val.v.val_unsigned);
3032 case dw_val_class_double_const:
3035 case dw_val_class_flag:
3038 case dw_val_class_die_ref:
3039 size += DWARF_OFFSET_SIZE;
3041 case dw_val_class_fde_ref:
3042 size += DWARF_OFFSET_SIZE;
3044 case dw_val_class_lbl_id:
3047 case dw_val_class_section_offset:
3048 size += DWARF_OFFSET_SIZE;
3050 case dw_val_class_str:
3051 size += size_of_string (a->dw_attr_val.v.val_str);
3060 /* Size the debgging information associted with a given DIE.
3061 Visits the DIE's children recursively. Updates the global
3062 variable next_die_offset, on each time through. Uses the
3063 current value of next_die_offset to updete the die_offset
3064 field in each DIE. */
3066 calc_die_sizes (die)
3069 register dw_die_ref c;
3070 register unsigned long die_size;
3071 die->die_offset = next_die_offset;
3072 next_die_offset += size_of_die (die);
3073 for (c = die->die_child; c != NULL; c = c->die_sib)
3077 if (die->die_child != NULL)
3079 /* Count the null byte used to terminate sibling lists. */
3080 next_die_offset += 1;
3084 /* Return the size of the line information prolog generated for the
3085 compilation unit. */
3086 static unsigned long
3087 size_of_line_prolog ()
3089 register unsigned long size;
3090 register unsigned opc;
3091 register unsigned n_op_args;
3092 register unsigned long ft_index;
3093 size = DWARF_LINE_PROLOG_HEADER_SIZE;
3094 /* Count the size of the table giving number of args for each
3096 size += DWARF_LINE_OPCODE_BASE - 1;
3097 /* Include directory table is empty (at present). Count only the
3098 the null byte used to terminate the table. */
3100 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
3102 /* File name entry. */
3103 size += size_of_string (file_table[ft_index]);
3104 /* Include directory index. */
3105 size += size_of_uleb128 (0);
3106 /* Modification time. */
3107 size += size_of_uleb128 (0);
3108 /* File length in bytes. */
3109 size += size_of_uleb128 (0);
3111 /* Count the file table terminator. */
3116 /* Return the size of the line information generated for this
3117 compilation unit. */
3118 static unsigned long
3119 size_of_line_info ()
3121 register unsigned long size;
3122 register unsigned long lt_index;
3123 register unsigned long current_line;
3124 register long line_offset;
3125 register long line_delta;
3126 register unsigned long current_file;
3127 register unsigned long function;
3128 /* Version number. */
3130 /* Prolog length specifier. */
3131 size += DWARF_OFFSET_SIZE;
3133 size += size_of_line_prolog ();
3134 /* Set address register instruction. */
3135 size += 1 + size_of_uleb128 (1 + PTR_SIZE)
3139 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
3141 register dw_line_info_ref line_info;
3142 /* Advance pc instruction. */
3144 line_info = &line_info_table[lt_index];
3145 if (line_info->dw_file_num != current_file)
3147 /* Set file number instruction. */
3149 current_file = line_info->dw_file_num;
3150 size += size_of_uleb128 (current_file);
3152 if (line_info->dw_line_num != current_line)
3154 line_offset = line_info->dw_line_num - current_line;
3155 line_delta = line_offset - DWARF_LINE_BASE;
3156 current_line = line_info->dw_line_num;
3157 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
3159 /* 1-byte special line number instruction. */
3164 /* Advance line instruction. */
3166 size += size_of_sleb128 (line_offset);
3167 /* Generate line entry instruction. */
3172 /* Advance pc instruction. */
3174 /* End of line number info. marker. */
3175 size += 1 + size_of_uleb128 (1) + 1;
3179 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
3181 register dw_separate_line_info_ref line_info
3182 = &separate_line_info_table[lt_index];
3183 if (function != line_info->function)
3185 function = line_info->function;
3186 /* Set address register instruction. */
3187 size += 1 + size_of_uleb128 (1 + PTR_SIZE)
3192 /* Advance pc instruction. */
3195 if (line_info->dw_file_num != current_file)
3197 /* Set file number instruction. */
3199 current_file = line_info->dw_file_num;
3200 size += size_of_uleb128 (current_file);
3202 if (line_info->dw_line_num != current_line)
3204 line_offset = line_info->dw_line_num - current_line;
3205 line_delta = line_offset - DWARF_LINE_BASE;
3206 current_line = line_info->dw_line_num;
3207 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
3209 /* 1-byte special line number instruction. */
3214 /* Advance line instruction. */
3216 size += size_of_sleb128 (line_offset);
3217 /* Generate line entry instruction. */
3223 /* If we're done with a function, end its sequence. */
3224 if (lt_index == separate_line_info_table_in_use
3225 || separate_line_info_table[lt_index].function != function)
3229 /* Advance pc instruction. */
3231 /* End of line number info. marker. */
3232 size += 1 + size_of_uleb128 (1) + 1;
3238 /* Return the size of the .debug_pubnames table generated for the
3239 compilation unit. */
3240 static unsigned long
3243 register unsigned long size;
3244 register unsigned i;
3246 size = DWARF_PUBNAMES_HEADER_SIZE;
3247 for (i = 0; i < pubname_table_in_use; ++i)
3249 register pubname_ref p = &pubname_table[i];
3250 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
3252 size += DWARF_OFFSET_SIZE;
3256 /* Return the size of the information in the .debug_aranges seciton. */
3257 static unsigned long
3260 register unsigned long size;
3261 size = DWARF_ARANGES_HEADER_SIZE;
3262 /* Count the address/length pair for this compilation unit. */
3263 size += 2 * PTR_SIZE;
3264 size += 2 * PTR_SIZE * arange_table_in_use;
3265 /* Count the two zero words used to terminated the address range table. */
3266 size += 2 * PTR_SIZE;
3270 /**************** DWARF Debug Information Output *****************************/
3272 /* Output an unsigned LEB128 quantity. */
3274 output_uleb128 (value)
3275 register unsigned long value;
3277 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
3280 register unsigned byte = (value & 0x7f);
3284 /* More bytes to follow. */
3287 fprintf (asm_out_file, "0x%x", byte);
3290 fprintf (asm_out_file, ",");
3296 /* Output an signed LEB128 quantity. */
3298 output_sleb128 (value)
3299 register long value;
3302 register unsigned byte;
3303 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
3306 byte = (value & 0x7f);
3307 /* arithmetic shift */
3309 more = !((((value == 0) && ((byte & 0x40) == 0))
3310 || ((value == -1) && ((byte & 0x40) != 0))));
3315 fprintf (asm_out_file, "0x%x", byte);
3318 fprintf (asm_out_file, ",");
3324 /* Output the encoding of an attribute value. */
3326 output_value_format (v)
3329 enum dwarf_form form;
3330 switch (v->val_class)
3332 case dw_val_class_addr:
3333 form = DW_FORM_addr;
3335 case dw_val_class_loc:
3336 form = DW_FORM_block2;
3338 case dw_val_class_const:
3339 form = DW_FORM_data4;
3341 case dw_val_class_unsigned_const:
3342 switch (constant_size (v->v.val_unsigned))
3345 form = DW_FORM_data1;
3348 form = DW_FORM_data2;
3351 form = DW_FORM_data4;
3357 case dw_val_class_double_const:
3358 form = DW_FORM_data8;
3360 case dw_val_class_flag:
3361 form = DW_FORM_flag;
3363 case dw_val_class_die_ref:
3366 case dw_val_class_fde_ref:
3367 form = DW_FORM_data;
3369 case dw_val_class_lbl_id:
3370 form = DW_FORM_addr;
3372 case dw_val_class_section_offset:
3373 form = DW_FORM_data;
3375 case dw_val_class_str:
3376 form = DW_FORM_string;
3381 output_uleb128 (form);
3382 if (flag_verbose_asm)
3384 fprintf (asm_out_file, "\t%s %s",
3385 ASM_COMMENT_START, dwarf_form_name (form));
3387 fputc ('\n', asm_out_file);
3390 /* Output the .debug_abbrev section which defines the DIE abbreviation
3393 output_abbrev_section ()
3395 unsigned long abbrev_id;
3397 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
3399 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
3400 output_uleb128 (abbrev_id);
3401 if (flag_verbose_asm)
3403 fprintf (asm_out_file, "\t%s abbrev code = %u",
3404 ASM_COMMENT_START, abbrev_id);
3406 fputc ('\n', asm_out_file);
3407 output_uleb128 (abbrev->die_tag);
3408 if (flag_verbose_asm)
3410 fprintf (asm_out_file, "\t%s TAG: %s",
3411 ASM_COMMENT_START, dwarf_tag_name (abbrev->die_tag));
3413 fputc ('\n', asm_out_file);
3414 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
3415 (abbrev->die_child != NULL)
3416 ? DW_children_yes : DW_children_no);
3417 if (flag_verbose_asm)
3419 fprintf (asm_out_file, "\t%s %s",
3421 (abbrev->die_child != NULL)
3422 ? "DW_children_yes" : "DW_children_no");
3424 fputc ('\n', asm_out_file);
3425 for (a_attr = abbrev->die_attr; a_attr != NULL;
3426 a_attr = a_attr->dw_attr_next)
3428 output_uleb128 (a_attr->dw_attr);
3429 if (flag_verbose_asm)
3431 fprintf (asm_out_file, "\t%s %s",
3433 dwarf_attr_name (a_attr->dw_attr));
3435 fputc ('\n', asm_out_file);
3436 output_value_format (&a_attr->dw_attr_val);
3438 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
3442 /* Output location description stack opcode's operands (if any). */
3444 output_loc_operands (loc)
3445 register dw_loc_descr_ref loc;
3447 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
3448 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
3449 switch (loc->dw_loc_opc)
3452 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
3453 fputc ('\n', asm_out_file);
3457 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
3458 fputc ('\n', asm_out_file);
3462 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
3463 fputc ('\n', asm_out_file);
3467 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
3468 fputc ('\n', asm_out_file);
3472 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
3473 val1->v.val_dbl_const.dw_dbl_hi,
3474 val2->v.val_dbl_const.dw_dbl_low);
3475 fputc ('\n', asm_out_file);
3478 output_uleb128 (val1->v.val_unsigned);
3479 fputc ('\n', asm_out_file);
3482 output_sleb128 (val1->v.val_unsigned);
3483 fputc ('\n', asm_out_file);
3486 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
3487 fputc ('\n', asm_out_file);
3489 case DW_OP_plus_uconst:
3490 output_uleb128 (val1->v.val_unsigned);
3491 fputc ('\n', asm_out_file);
3495 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
3496 fputc ('\n', asm_out_file);
3530 output_sleb128 (val1->v.val_int);
3531 fputc ('\n', asm_out_file);
3534 output_uleb128 (val1->v.val_unsigned);
3535 fputc ('\n', asm_out_file);
3538 output_sleb128 (val1->v.val_unsigned);
3539 fputc ('\n', asm_out_file);
3542 output_uleb128 (val1->v.val_unsigned);
3543 fputc ('\n', asm_out_file);
3544 output_sleb128 (val2->v.val_unsigned);
3545 fputc ('\n', asm_out_file);
3548 output_uleb128 (val1->v.val_unsigned);
3549 fputc ('\n', asm_out_file);
3551 case DW_OP_deref_size:
3552 case DW_OP_xderef_size:
3553 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
3554 fputc ('\n', asm_out_file);
3561 /* Compute the offset of a sibling. */
3562 static unsigned long
3563 sibling_offset (die)
3566 unsigned long offset;
3567 if (die->die_child_last == NULL)
3569 offset = die->die_offset + size_of_die (die);
3573 offset = sibling_offset (die->die_child_last) + 1;
3578 /* Output the DIE and its attributes. Called recursively to generate
3579 the definitions of each child DIE. */
3582 register dw_die_ref die;
3584 register dw_attr_ref a;
3585 register dw_die_ref c;
3586 register unsigned long ref_offset;
3587 register unsigned long size;
3588 register dw_loc_descr_ref loc;
3589 output_uleb128 (die->die_abbrev);
3590 if (flag_verbose_asm)
3592 fprintf (asm_out_file, "\t%s DIE (0x%x) %s",
3595 dwarf_tag_name (die->die_tag));
3597 fputc ('\n', asm_out_file);
3598 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3600 switch (a->dw_attr_val.val_class)
3602 case dw_val_class_addr:
3603 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
3604 a->dw_attr_val.v.val_addr);
3606 case dw_val_class_loc:
3608 for (loc = a->dw_attr_val.v.val_loc; loc != NULL;
3609 loc = loc->dw_loc_next)
3611 size += size_of_loc_descr (loc);
3613 /* Output the block length for this list of location operations. */
3614 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
3615 if (flag_verbose_asm)
3617 fprintf (asm_out_file, "\t%s %s",
3618 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
3620 fputc ('\n', asm_out_file);
3621 for (loc = a->dw_attr_val.v.val_loc; loc != NULL;
3622 loc = loc->dw_loc_next)
3624 /* Output the opcode. */
3625 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
3626 if (flag_verbose_asm)
3628 fprintf (asm_out_file, "\t%s %s",
3630 dwarf_stack_op_name (loc->dw_loc_opc));
3632 fputc ('\n', asm_out_file);
3633 /* Output the operand(s) (if any). */
3634 output_loc_operands (loc);
3637 case dw_val_class_const:
3638 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_int);
3640 case dw_val_class_unsigned_const:
3641 switch (constant_size (a->dw_attr_val.v.val_unsigned))
3644 ASM_OUTPUT_DWARF_DATA1
3645 (asm_out_file, a->dw_attr_val.v.val_unsigned);
3648 ASM_OUTPUT_DWARF_DATA2
3649 (asm_out_file, a->dw_attr_val.v.val_unsigned);
3652 ASM_OUTPUT_DWARF_DATA4
3653 (asm_out_file, a->dw_attr_val.v.val_unsigned);
3659 case dw_val_class_double_const:
3660 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
3661 a->dw_attr_val.v.val_dbl_const.dw_dbl_hi,
3662 a->dw_attr_val.v.val_dbl_const.dw_dbl_low);
3664 case dw_val_class_flag:
3665 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, a->dw_attr_val.v.val_flag);
3667 case dw_val_class_die_ref:
3668 if (a->dw_attr_val.v.val_die_ref != NULL)
3670 ref_offset = a->dw_attr_val.v.val_die_ref->die_offset;
3672 else if (a->dw_attr == DW_AT_sibling)
3674 ref_offset = sibling_offset(die);
3680 ASM_OUTPUT_DWARF_DATA (asm_out_file, ref_offset);
3682 case dw_val_class_fde_ref:
3683 ref_offset = fde_table[a->dw_attr_val.v.val_fde_index].dw_fde_offset;
3684 fprintf (asm_out_file, "\t%s\t%s+0x%x", UNALIGNED_OFFSET_ASM_OP,
3685 stripattributes (FRAME_SECTION), ref_offset);
3687 case dw_val_class_lbl_id:
3688 ASM_OUTPUT_DWARF_ADDR (asm_out_file, a->dw_attr_val.v.val_lbl_id);
3690 case dw_val_class_section_offset:
3691 ASM_OUTPUT_DWARF_OFFSET
3692 (asm_out_file, stripattributes (a->dw_attr_val.v.val_section));
3694 case dw_val_class_str:
3695 ASM_OUTPUT_DWARF_STRING (asm_out_file, a->dw_attr_val.v.val_str);
3700 if (a->dw_attr_val.val_class != dw_val_class_loc)
3702 if (flag_verbose_asm)
3704 fprintf (asm_out_file, "\t%s %s",
3705 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
3707 fputc ('\n', asm_out_file);
3710 for (c = die->die_child; c != NULL; c = c->die_sib)
3714 if (die->die_child != NULL)
3716 /* Add null byte to terminate sibling list. */
3717 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
3718 fputc ('\n', asm_out_file);
3722 /* Output the compilation unit that appears at the beginning of the
3723 .debug_info section, and precedes the DIE descriptions. */
3725 output_compilation_unit_header ()
3727 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
3728 if (flag_verbose_asm)
3730 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
3733 fputc ('\n', asm_out_file);
3734 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
3735 if (flag_verbose_asm)
3737 fprintf (asm_out_file, "\t%s DWARF version number",
3740 fputc ('\n', asm_out_file);
3741 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (ABBREV_SECTION));
3742 if (flag_verbose_asm)
3744 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
3747 fputc ('\n', asm_out_file);
3748 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
3749 if (flag_verbose_asm)
3751 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)",
3754 fputc ('\n', asm_out_file);
3757 /* Return the size of a Call Frame Instruction. */
3758 static unsigned long
3762 register unsigned long size;
3763 /* count the 1-byte opcode */
3765 switch (cfi->dw_cfi_opc)
3768 size += size_of_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset);
3770 case DW_CFA_set_loc:
3773 case DW_CFA_advance_loc1:
3776 case DW_CFA_advance_loc2:
3779 case DW_CFA_advance_loc4:
3782 #ifdef MIPS_DEBUGGING_INFO
3783 case DW_CFA_MIPS_advance_loc8:
3787 case DW_CFA_offset_extended:
3788 case DW_CFA_def_cfa:
3789 size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3790 size += size_of_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset);
3792 case DW_CFA_restore_extended:
3793 case DW_CFA_undefined:
3794 size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3796 case DW_CFA_same_value:
3797 case DW_CFA_def_cfa_register:
3798 size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3800 case DW_CFA_register:
3801 size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3802 size += size_of_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
3804 case DW_CFA_def_cfa_offset:
3805 size += size_of_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_offset);
3813 /* Return the size of an FDE sans the length word. */
3814 inline unsigned long
3815 size_of_fde (fde, npad)
3817 unsigned long *npad;
3819 register dw_cfi_ref cfi;
3820 register unsigned long aligned_size;
3821 register unsigned long size;
3822 size = DWARF_FDE_HEADER_SIZE;
3823 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3825 size += size_of_cfi(cfi);
3827 /* Round the size up to a word boundary. */
3828 aligned_size = DWARF_ROUND (size, PTR_SIZE);
3829 *npad = aligned_size - size;
3830 return aligned_size;
3833 /* Calculate the size of the FDE table, and establish the offset
3834 of each FDE in the .debug_frame section. */
3838 register unsigned long i;
3839 register dw_fde_ref fde;
3840 register unsigned long fde_size;
3841 unsigned long fde_pad;
3842 for (i = 0; i < fde_table_in_use; ++i)
3844 fde = &fde_table[i];
3845 fde->dw_fde_offset = next_fde_offset;
3846 fde_size = size_of_fde (fde, &fde_pad);
3847 next_fde_offset += fde_size;
3851 /* Output a Call Frame Information opcode and its operand(s). */
3853 output_cfi (cfi, fde)
3854 register dw_cfi_ref cfi;
3855 register dw_fde_ref fde;
3857 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3859 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
3861 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
3862 if (flag_verbose_asm)
3864 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc", ASM_COMMENT_START);
3866 fputc ('\n', asm_out_file);
3868 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3870 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
3872 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
3873 if (flag_verbose_asm)
3875 fprintf (asm_out_file, "\t%s DW_CFA_offset", ASM_COMMENT_START);
3877 fputc ('\n', asm_out_file);
3878 output_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset);
3879 fputc ('\n', asm_out_file);
3881 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3883 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
3885 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
3886 if (flag_verbose_asm)
3888 fprintf (asm_out_file, "\t%s DW_CFA_restore", ASM_COMMENT_START);
3890 fputc ('\n', asm_out_file);
3894 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
3895 if (flag_verbose_asm)
3897 fprintf (asm_out_file, "\t%s %s",
3899 dwarf_cfi_name (cfi->dw_cfi_opc));
3901 fputc ('\n', asm_out_file);
3902 switch (cfi->dw_cfi_opc)
3904 case DW_CFA_set_loc:
3905 ASM_OUTPUT_DWARF_ADDR (asm_out_file,
3906 cfi->dw_cfi_oprnd1.dw_cfi_addr);
3907 fputc ('\n', asm_out_file);
3909 case DW_CFA_advance_loc1:
3910 /* TODO: not currently implemented. */
3913 case DW_CFA_advance_loc2:
3914 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
3915 cfi->dw_cfi_oprnd1.dw_cfi_addr,
3917 fputc ('\n', asm_out_file);
3919 case DW_CFA_advance_loc4:
3920 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
3921 cfi->dw_cfi_oprnd1.dw_cfi_addr,
3923 fputc ('\n', asm_out_file);
3925 #ifdef MIPS_DEBUGGING_INFO
3926 case DW_CFA_MIPS_advance_loc8:
3927 /* TODO: not currently implemented. */
3931 case DW_CFA_offset_extended:
3932 case DW_CFA_def_cfa:
3933 output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3934 fputc ('\n', asm_out_file);
3935 output_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_offset);
3936 fputc ('\n', asm_out_file);
3938 case DW_CFA_restore_extended:
3939 case DW_CFA_undefined:
3940 output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3941 fputc ('\n', asm_out_file);
3943 case DW_CFA_same_value:
3944 case DW_CFA_def_cfa_register:
3945 output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3946 fputc ('\n', asm_out_file);
3948 case DW_CFA_register:
3949 output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3950 fputc ('\n', asm_out_file);
3951 output_uleb128(cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
3952 fputc ('\n', asm_out_file);
3954 case DW_CFA_def_cfa_offset:
3955 output_uleb128(cfi->dw_cfi_oprnd1.dw_cfi_offset);
3956 fputc ('\n', asm_out_file);
3964 /* Output the call frame information used to used to record information
3965 that relates to calculating the frame pointer, and records the
3966 location of saved registers. */
3968 output_call_frame_info ()
3970 register unsigned long i, j;
3971 register dw_fde_ref fde;
3972 register unsigned long fde_size;
3973 dw_cfi_node cfi_node;
3974 register dw_cfi_ref cfi;
3975 unsigned long fde_pad;
3977 /* Output the CIE. */
3978 ASM_OUTPUT_DWARF_DATA (asm_out_file, DWARF_CIE_SIZE - DWARF_OFFSET_SIZE);
3979 if (flag_verbose_asm)
3981 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
3984 fputc ('\n', asm_out_file);
3985 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
3986 if (flag_verbose_asm)
3988 fprintf (asm_out_file, "\t%s CIE Identifier Tag",
3991 fputc ('\n', asm_out_file);
3992 if (DWARF_OFFSET_SIZE == 8)
3994 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
3995 fputc ('\n', asm_out_file);
3997 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
3998 if (flag_verbose_asm)
4000 fprintf (asm_out_file, "\t%s CIE Version",
4003 fputc ('\n', asm_out_file);
4004 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4005 if (flag_verbose_asm)
4007 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
4010 fputc ('\n', asm_out_file);
4012 if (flag_verbose_asm)
4014 fprintf (asm_out_file, "\t%s CIE Code Alignment Factor",
4017 fputc ('\n', asm_out_file);
4018 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
4019 if (flag_verbose_asm)
4021 fprintf (asm_out_file, "\t%s CIE Data Alignment Factor",
4024 fputc ('\n', asm_out_file);
4025 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_FRAME_RA_COL);
4026 if (flag_verbose_asm)
4028 fprintf (asm_out_file, "\t%s CIE RA Column",
4031 fputc ('\n', asm_out_file);
4033 /* Output the CFA instructions common to all FDE's. */
4035 #ifdef MIPS_DEBUGGING_INFO
4037 /* Set the RA on entry to be the contents of r31. */
4038 bzero (&cfi_node, sizeof (dw_cfi_node));
4040 cfi->dw_cfi_opc = DW_CFA_register;
4041 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DW_FRAME_RA_COL;
4042 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = DW_FRAME_REG31;
4047 /* Pad the CIE out to an address sized boundary. */
4048 for (i = DWARF_CIE_HEADER_SIZE; i < DWARF_CIE_SIZE; ++i)
4050 /* Pad out to a pointer size boundary */
4051 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CFA_nop);
4052 if (flag_verbose_asm)
4054 fprintf (asm_out_file, "\t%s CIE DW_CFA_nop (pad)",
4057 fputc ('\n', asm_out_file);
4060 /* Loop through all of the FDE's. */
4061 for (i = 0; i < fde_table_in_use; ++i)
4063 fde = &fde_table[i];
4064 fde_size = size_of_fde (fde, &fde_pad);
4065 ASM_OUTPUT_DWARF_DATA (asm_out_file, fde_size - DWARF_OFFSET_SIZE);
4066 if (flag_verbose_asm)
4068 fprintf (asm_out_file, "\t%s FDE Length",
4071 fputc ('\n', asm_out_file);
4072 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
4073 if (flag_verbose_asm)
4075 fprintf (asm_out_file, "\t%s FDE CIE offset",
4078 fputc ('\n', asm_out_file);
4079 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
4080 if (flag_verbose_asm)
4082 fprintf (asm_out_file, "\t%s FDE initial location",
4085 fputc ('\n', asm_out_file);
4086 ASM_OUTPUT_DWARF_ADDR_DELTA
4087 (asm_out_file, fde->dw_fde_end, fde->dw_fde_begin);
4088 if (flag_verbose_asm)
4090 fprintf (asm_out_file, "\t%s FDE address range",
4093 fputc ('\n', asm_out_file);
4095 /* Loop through the Call Frame Instructions associated with
4097 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
4099 output_cfi (cfi, fde);
4102 /* Pad to a double word boundary. */
4103 for (j = 0; j < fde_pad; ++j)
4105 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CFA_nop);
4106 if (flag_verbose_asm)
4108 fprintf (asm_out_file, "\t%s CIE DW_CFA_nop (pad)",
4111 fputc ('\n', asm_out_file);
4116 /* Add a new entry to .debug_pubnames if appropriate. */
4118 add_pubname (decl, die)
4124 if (! TREE_PUBLIC (decl))
4127 if (pubname_table_in_use == pubname_table_allocated)
4129 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
4130 pubname_table = (pubname_ref) xrealloc
4131 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
4133 p = &pubname_table[pubname_table_in_use++];
4135 p->name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4138 /* Output the public names table used to speed up access to externally
4139 visible names. For now, only generate entries for externally
4140 visible procedures. */
4144 register unsigned i;
4146 register unsigned long pubnames_length = size_of_pubnames ();
4147 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
4149 if (flag_verbose_asm)
4151 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
4154 fputc ('\n', asm_out_file);
4155 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4156 if (flag_verbose_asm)
4158 fprintf (asm_out_file, "\t%s DWARF Version",
4161 fputc ('\n', asm_out_file);
4162 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_SECTION));
4163 if (flag_verbose_asm)
4165 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
4168 fputc ('\n', asm_out_file);
4169 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
4170 if (flag_verbose_asm)
4172 fprintf (asm_out_file, "\t%s Compilation Unit Length",
4175 fputc ('\n', asm_out_file);
4176 for (i = 0; i < pubname_table_in_use; ++i)
4178 register pubname_ref pub = &pubname_table[i];
4179 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
4180 if (flag_verbose_asm)
4182 fprintf (asm_out_file, "\t%s DIE offset",
4185 fputc ('\n', asm_out_file);
4187 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
4188 if (flag_verbose_asm)
4190 fprintf (asm_out_file, "%s external name",
4193 fputc ('\n', asm_out_file);
4195 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
4196 fputc ('\n', asm_out_file);
4199 /* Add a new entry to .debug_aranges if appropriate. */
4201 add_arange (decl, die)
4205 if (! DECL_SECTION_NAME (decl))
4208 if (arange_table_in_use == arange_table_allocated)
4210 arange_table_allocated += ARANGE_TABLE_INCREMENT;
4211 arange_table = (arange_ref) xrealloc
4212 (arange_table, arange_table_allocated * sizeof (dw_die_ref));
4214 arange_table[arange_table_in_use++] = die;
4217 /* Output the information that goes into the .debug_aranges table.
4218 Namely, define the beginning and ending address range of the
4219 text section generated for this compilation unit. */
4223 register unsigned i;
4225 register unsigned long aranges_length = size_of_aranges ();
4226 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
4228 if (flag_verbose_asm)
4230 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
4233 fputc ('\n', asm_out_file);
4234 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4235 if (flag_verbose_asm)
4237 fprintf (asm_out_file, "\t%s DWARF Version",
4240 fputc ('\n', asm_out_file);
4241 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_SECTION));
4242 if (flag_verbose_asm)
4244 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
4247 fputc ('\n', asm_out_file);
4248 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
4249 if (flag_verbose_asm)
4251 fprintf (asm_out_file, "\t%s Size of Address",
4254 fputc ('\n', asm_out_file);
4255 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4256 if (flag_verbose_asm)
4258 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
4261 fputc ('\n', asm_out_file);
4262 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
4264 fprintf (asm_out_file, ",0,0");
4265 if (flag_verbose_asm)
4267 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
4268 ASM_COMMENT_START, 2 * PTR_SIZE);
4270 fputc ('\n', asm_out_file);
4271 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
4272 if (flag_verbose_asm)
4274 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
4276 fputc ('\n', asm_out_file);
4277 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, TEXT_END_LABEL, TEXT_SECTION);
4278 if (flag_verbose_asm)
4280 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
4282 fputc ('\n', asm_out_file);
4283 for (i = 0; i < arange_table_in_use; ++i)
4285 dw_die_ref a = arange_table[i];
4286 if (a->die_tag == DW_TAG_subprogram)
4287 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (a));
4289 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_string (a, DW_AT_name));
4290 if (flag_verbose_asm)
4292 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
4294 fputc ('\n', asm_out_file);
4295 if (a->die_tag == DW_TAG_subprogram)
4296 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (a),
4299 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
4300 get_AT_unsigned (a, DW_AT_byte_size));
4301 if (flag_verbose_asm)
4303 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
4305 fputc ('\n', asm_out_file);
4307 /* Output the terminator words. */
4308 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
4309 fputc ('\n', asm_out_file);
4310 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
4311 fputc ('\n', asm_out_file);
4314 /* Output the source line number correspondence information. This
4315 information goes into the .debug_line section. */
4319 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
4320 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
4321 register unsigned opc;
4322 register unsigned n_op_args;
4323 register unsigned long ft_index;
4324 register unsigned long lt_index;
4325 register unsigned long current_line;
4326 register long line_offset;
4327 register long line_delta;
4328 register unsigned long current_file;
4329 register unsigned long function;
4330 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_info ());
4331 if (flag_verbose_asm)
4333 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
4336 fputc ('\n', asm_out_file);
4337 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4338 if (flag_verbose_asm)
4340 fprintf (asm_out_file, "\t%s DWARF Version",
4343 fputc ('\n', asm_out_file);
4344 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
4345 if (flag_verbose_asm)
4347 fprintf (asm_out_file, "\t%s Prolog Length",
4350 fputc ('\n', asm_out_file);
4351 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
4352 if (flag_verbose_asm)
4354 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
4357 fputc ('\n', asm_out_file);
4358 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
4359 if (flag_verbose_asm)
4361 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
4364 fputc ('\n', asm_out_file);
4365 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
4366 if (flag_verbose_asm)
4368 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
4371 fputc ('\n', asm_out_file);
4372 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
4373 if (flag_verbose_asm)
4375 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
4378 fputc ('\n', asm_out_file);
4379 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
4380 if (flag_verbose_asm)
4382 fprintf (asm_out_file, "\t%s Special Opcode Base",
4385 fputc ('\n', asm_out_file);
4386 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
4390 case DW_LNS_advance_pc:
4391 case DW_LNS_advance_line:
4392 case DW_LNS_set_file:
4393 case DW_LNS_set_column:
4394 case DW_LNS_fixed_advance_pc:
4401 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
4402 if (flag_verbose_asm)
4404 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
4405 ASM_COMMENT_START, opc, n_op_args);
4407 fputc ('\n', asm_out_file);
4409 if (flag_verbose_asm)
4411 fprintf (asm_out_file, "%s Include Directory Table\n",
4414 /* Include directory table is empty, at present */
4415 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4416 fputc ('\n', asm_out_file);
4417 if (flag_verbose_asm)
4419 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
4421 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
4423 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
4424 if (flag_verbose_asm)
4426 fprintf (asm_out_file, "%s File Entry: 0x%x",
4427 ASM_COMMENT_START, ft_index);
4429 fputc ('\n', asm_out_file);
4430 /* Include directory index */
4432 fputc ('\n', asm_out_file);
4433 /* Modification time */
4435 fputc ('\n', asm_out_file);
4436 /* File length in bytes */
4438 fputc ('\n', asm_out_file);
4440 /* Terminate the file name table */
4441 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4442 fputc ('\n', asm_out_file);
4444 /* Set the address register to the first location in the text section */
4445 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4446 if (flag_verbose_asm)
4448 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
4450 fputc ('\n', asm_out_file);
4451 output_uleb128 (1 + PTR_SIZE);
4452 fputc ('\n', asm_out_file);
4453 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
4454 fputc ('\n', asm_out_file);
4455 ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
4456 fputc ('\n', asm_out_file);
4458 /* Generate the line number to PC correspondence table, encoded as
4459 a series of state machine operations. */
4462 strcpy (prev_line_label, TEXT_SECTION);
4463 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
4465 register dw_line_info_ref line_info;
4466 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
4467 if (flag_verbose_asm)
4469 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
4472 fputc ('\n', asm_out_file);
4473 sprintf (line_label, LINE_CODE_LABEL_FMT, lt_index);
4474 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
4475 fputc ('\n', asm_out_file);
4476 line_info = &line_info_table[lt_index];
4477 if (line_info->dw_file_num != current_file)
4479 current_file = line_info->dw_file_num;
4480 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
4481 if (flag_verbose_asm)
4483 fprintf (asm_out_file,
4484 "\t%s DW_LNS_set_file", ASM_COMMENT_START);
4486 fputc ('\n', asm_out_file);
4487 output_uleb128 (current_file);
4488 if (flag_verbose_asm)
4490 fprintf (asm_out_file, "\t%s \"%s\"",
4491 ASM_COMMENT_START, file_table[current_file]);
4493 fputc ('\n', asm_out_file);
4495 if (line_info->dw_line_num != current_line)
4497 line_offset = line_info->dw_line_num - current_line;
4498 line_delta = line_offset - DWARF_LINE_BASE;
4499 current_line = line_info->dw_line_num;
4500 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4502 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
4503 DWARF_LINE_OPCODE_BASE + line_delta);
4504 if (flag_verbose_asm)
4506 fprintf (asm_out_file,
4507 "\t%s line %d", ASM_COMMENT_START, current_line);
4509 fputc ('\n', asm_out_file);
4513 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
4514 if (flag_verbose_asm)
4516 fprintf (asm_out_file,
4517 "\t%s advance to line %d",
4518 ASM_COMMENT_START, current_line);
4520 fputc ('\n', asm_out_file);
4521 output_sleb128 (line_offset);
4522 fputc ('\n', asm_out_file);
4523 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
4524 fputc ('\n', asm_out_file);
4527 strcpy (prev_line_label, line_label);
4530 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
4531 if (flag_verbose_asm)
4533 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
4536 fputc ('\n', asm_out_file);
4537 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, TEXT_END_LABEL, prev_line_label);
4538 fputc ('\n', asm_out_file);
4540 /* Output the marker for the end of the line number info. */
4541 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4542 if (flag_verbose_asm)
4544 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
4546 fputc ('\n', asm_out_file);
4548 fputc ('\n', asm_out_file);
4549 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
4550 fputc ('\n', asm_out_file);
4555 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
4557 register dw_separate_line_info_ref line_info
4558 = &separate_line_info_table[lt_index];
4559 sprintf (line_label, SEPARATE_LINE_CODE_LABEL_FMT, lt_index);
4560 if (function != line_info->function)
4562 function = line_info->function;
4563 /* Set the address register to the first line in the function */
4564 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4565 if (flag_verbose_asm)
4566 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
4568 fputc ('\n', asm_out_file);
4569 output_uleb128 (1 + PTR_SIZE);
4570 fputc ('\n', asm_out_file);
4571 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
4572 fputc ('\n', asm_out_file);
4573 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
4574 fputc ('\n', asm_out_file);
4578 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
4579 if (flag_verbose_asm)
4580 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
4582 fputc ('\n', asm_out_file);
4583 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
4584 fputc ('\n', asm_out_file);
4586 if (line_info->dw_file_num != current_file)
4588 current_file = line_info->dw_file_num;
4589 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
4590 if (flag_verbose_asm)
4592 fprintf (asm_out_file,
4593 "\t%s DW_LNS_set_file", ASM_COMMENT_START);
4595 fputc ('\n', asm_out_file);
4596 output_uleb128 (current_file);
4597 if (flag_verbose_asm)
4599 fprintf (asm_out_file, "\t%s \"%s\"",
4600 ASM_COMMENT_START, file_table[current_file]);
4602 fputc ('\n', asm_out_file);
4604 if (line_info->dw_line_num != current_line)
4606 line_offset = line_info->dw_line_num - current_line;
4607 line_delta = line_offset - DWARF_LINE_BASE;
4608 current_line = line_info->dw_line_num;
4609 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
4611 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
4612 DWARF_LINE_OPCODE_BASE + line_delta);
4613 if (flag_verbose_asm)
4615 fprintf (asm_out_file,
4616 "\t%s line %d", ASM_COMMENT_START, current_line);
4618 fputc ('\n', asm_out_file);
4622 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
4623 if (flag_verbose_asm)
4625 fprintf (asm_out_file,
4626 "\t%s advance to line %d",
4627 ASM_COMMENT_START, current_line);
4629 fputc ('\n', asm_out_file);
4630 output_sleb128 (line_offset);
4631 fputc ('\n', asm_out_file);
4632 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
4633 fputc ('\n', asm_out_file);
4637 strcpy (prev_line_label, line_label);
4639 /* If we're done with a function, end its sequence. */
4640 if (lt_index == separate_line_info_table_in_use
4641 || separate_line_info_table[lt_index].function != function)
4645 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
4646 if (flag_verbose_asm)
4647 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
4649 fputc ('\n', asm_out_file);
4650 sprintf (line_label, FUNC_END_LABEL_FMT, function);
4651 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
4652 fputc ('\n', asm_out_file);
4654 /* Output the marker for the end of this sequence. */
4655 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4656 if (flag_verbose_asm)
4657 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
4659 fputc ('\n', asm_out_file);
4661 fputc ('\n', asm_out_file);
4662 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
4663 fputc ('\n', asm_out_file);
4668 /**************** attribute support utilities ********************************/
4671 * Given a pointer to a BLOCK node return non-zero if (and only if) the node
4672 * in question represents the outermost pair of curly braces (i.e. the "body
4673 * block") of a function or method.
4675 * For any BLOCK node representing a "body block" of a function or method, the
4676 * BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
4677 * represents the outermost (function) scope for the function or method (i.e.
4678 * the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of
4679 * *that* node in turn will point to the relevant FUNCTION_DECL node.
4682 is_body_block (stmt)
4685 if (TREE_CODE (stmt) == BLOCK)
4687 register tree parent = BLOCK_SUPERCONTEXT (stmt);
4689 if (TREE_CODE (parent) == BLOCK)
4691 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
4693 if (TREE_CODE (grandparent) == FUNCTION_DECL)
4700 /* Reset the base type to DIE table, and build a special predefined
4701 base type entry for the "int" signed integer base type. The
4702 "int" base type is used to construct subscript index range
4703 definitions, in situations where an anonymous integer type
4706 init_base_type_table ()
4709 register base_type_ref bt;
4710 for (i = 0; i < NUM_BASE_TYPES; ++i)
4712 base_type_die_table[i] = NULL;
4714 assert (comp_unit_die != 0);
4715 for (i = 0; i < NUM_BASE_TYPES; ++i)
4717 bt = &base_type_table[i];
4718 if (strcmp (bt->bt_name, "int") == 0)
4720 int_base_type_die = new_die (DW_TAG_base_type, comp_unit_die);
4721 base_type_die_table[i] = int_base_type_die;
4722 add_AT_string (int_base_type_die, DW_AT_name, bt->bt_name);
4723 add_AT_unsigned (int_base_type_die,
4724 DW_AT_byte_size, bt->bt_size / 8);
4725 add_AT_unsigned (int_base_type_die, DW_AT_encoding, bt->bt_type);
4731 /* Given a pointer to a tree node for some base type, return a pointer to
4732 a DIE that describes the given type.
4734 This routine must only be called for GCC type nodes that correspond to
4735 Dwarf base (fundamental) types. */
4737 base_type_die (type)
4740 register dw_die_ref base_type_result = NULL;
4741 register char *type_name = NULL;
4742 register int type_index = 0;
4743 register base_type_ref bt;
4746 if (TREE_CODE (type) == ERROR_MARK)
4749 switch (TREE_CODE (type))
4756 /* Carefully distinguish all the standard types of C, without messing
4757 up if the language is not C. Note that we check only for the names
4758 that contain spaces; other names might occur by coincidence in other
4760 if (TYPE_NAME (type) != 0
4761 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
4762 && DECL_NAME (TYPE_NAME (type)) != 0
4763 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
4765 type_name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
4766 for (i = 0; i < NUM_BASE_TYPES; ++i)
4768 bt = &base_type_table[i];
4769 if (strcmp (type_name, bt->bt_name) == 0)
4777 /* Most integer types will be sorted out above, however, for the sake
4778 of special `array index' integer types, the following code is also
4780 if (type_index == 0)
4782 for (i = 0; i < NUM_BASE_TYPES; ++i)
4784 bt = &base_type_table[i];
4785 if (bt->bt_size == TYPE_PRECISION (type)
4786 && (TREE_UNSIGNED (type) == 0) == bt->bt_is_signed)
4796 /* Carefully distinguish all the standard types of C, without messing
4797 up if the language is not C. */
4798 for (i = 0; i < NUM_BASE_TYPES; ++i)
4800 bt = &base_type_table[i];
4801 if ((bt->bt_type == DW_ATE_float)
4802 && (bt->bt_size == TYPE_PRECISION (type)))
4811 for (i = 0; i < NUM_BASE_TYPES; ++i)
4813 bt = &base_type_table[i];
4814 if ((bt->bt_type == DW_ATE_complex_float)
4815 && (bt->bt_size == TYPE_PRECISION (type)))
4824 /* GNU Pascal/Ada CHAR type. Not used in C. */
4825 for (i = 0; i < NUM_BASE_TYPES; ++i)
4827 bt = &base_type_table[i];
4828 if (bt->bt_type == DW_ATE_signed_char
4829 || bt->bt_type == DW_ATE_unsigned_char)
4831 if (bt->bt_size == TYPE_PRECISION (type)
4832 && ((TREE_UNSIGNED (type) == 0) == bt->bt_is_signed))
4842 /* GNU FORTRAN/Ada BOOLEAN type. */
4843 for (i = 0; i < NUM_BASE_TYPES; ++i)
4845 bt = &base_type_table[i];
4846 if (bt->bt_type == DW_ATE_boolean
4847 && bt->bt_size == TYPE_PRECISION (type))
4856 abort (); /* No other TREE_CODEs are Dwarf fundamental
4860 if (type_index == 0)
4862 base_type_result = NULL;
4866 base_type_result = base_type_die_table[type_index];
4867 if (base_type_result == NULL)
4869 bt = &base_type_table[type_index];
4870 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
4871 base_type_die_table[type_index] = base_type_result;
4872 add_AT_string (base_type_result, DW_AT_name, bt->bt_name);
4873 add_AT_unsigned (base_type_result, DW_AT_byte_size, bt->bt_size / 8);
4874 add_AT_unsigned (base_type_result, DW_AT_encoding, bt->bt_type);
4879 return base_type_result;
4882 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
4883 the Dwarf "root" type for the given input type. The Dwarf "root" type of
4884 a given type is generally the same as the given type, except that if the
4885 given type is a pointer or reference type, then the root type of the given
4886 type is the root type of the "basis" type for the pointer or reference
4887 type. (This definition of the "root" type is recursive.) Also, the root
4888 type of a `const' qualified type or a `volatile' qualified type is the
4889 root type of the given type without the qualifiers. */
4894 if (TREE_CODE (type) == ERROR_MARK)
4895 return error_mark_node;
4897 switch (TREE_CODE (type))
4900 return error_mark_node;
4903 case REFERENCE_TYPE:
4904 return type_main_variant (root_type (TREE_TYPE (type)));
4907 return type_main_variant (type);
4911 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
4912 given input type is a Dwarf "fundamental" type. Otherwise return null. */
4917 switch (TREE_CODE (type))
4932 case QUAL_UNION_TYPE:
4937 case REFERENCE_TYPE:
4949 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
4950 entry that chains various modifiers in front of the given type. */
4952 modified_type_die (type, is_const_type, is_volatile_type, context_die)
4954 register int is_const_type;
4955 register int is_volatile_type;
4956 register dw_die_ref context_die;
4958 register enum tree_code code = TREE_CODE (type);
4959 register dw_die_ref mod_type_die = NULL;
4960 register dw_die_ref sub_die = NULL;
4961 register tree item_type;
4963 if (code != ERROR_MARK)
4965 type = build_type_variant (type, is_const_type, is_volatile_type);
4967 mod_type_die = lookup_type_die (type);
4969 return mod_type_die;
4973 mod_type_die = new_die (DW_TAG_const_type, context_die);
4974 sub_die = modified_type_die
4975 (build_type_variant (type, 0, is_volatile_type),
4976 0, is_volatile_type, context_die);
4978 else if (is_volatile_type)
4980 mod_type_die = new_die (DW_TAG_volatile_type, context_die);
4981 sub_die = modified_type_die
4982 (TYPE_MAIN_VARIANT (type), 0, 0, context_die);
4984 else if (code == POINTER_TYPE)
4986 mod_type_die = new_die (DW_TAG_pointer_type, context_die);
4987 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
4988 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
4989 item_type = TREE_TYPE (type);
4990 sub_die = modified_type_die (item_type,
4991 TYPE_READONLY (item_type),
4992 TYPE_VOLATILE (item_type),
4995 else if (code == REFERENCE_TYPE)
4997 mod_type_die = new_die (DW_TAG_reference_type, context_die);
4998 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
4999 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
5000 item_type = TREE_TYPE (type);
5001 sub_die = modified_type_die (item_type,
5002 TYPE_READONLY (item_type),
5003 TYPE_VOLATILE (item_type),
5006 else if (is_base_type (type))
5008 mod_type_die = base_type_die (type);
5012 gen_type_die (type, context_die);
5014 /* We have to get the type_main_variant here (and pass that to the
5015 `lookup_type_die' routine) because the ..._TYPE node we have
5016 might simply be a *copy* of some original type node (where the
5017 copy was created to help us keep track of typedef names) and
5018 that copy might have a different TYPE_UID from the original
5019 ..._TYPE node. (Note that when `equate_type_number_to_die' is
5020 labeling a given type DIE for future reference, it always only
5021 handles DIEs representing *main variants*, and it never even
5022 knows about non-main-variants.). */
5023 mod_type_die = lookup_type_die (type_main_variant (type));
5024 if (mod_type_die == NULL)
5028 if (sub_die != NULL)
5030 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
5032 equate_type_number_to_die (type, mod_type_die);
5033 return mod_type_die;
5036 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
5037 an enumerated type. */
5042 return TREE_CODE (type) == ENUMERAL_TYPE;
5045 /* Return the register number described by a given RTL node. */
5050 register unsigned regno = REGNO (rtl);
5052 if (regno >= FIRST_PSEUDO_REGISTER)
5054 warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
5058 regno = DBX_REGISTER_NUMBER (regno);
5062 /* Return a location descriptor that designates a machine register. */
5063 static dw_loc_descr_ref
5064 reg_loc_descriptor (rtl)
5067 register dw_loc_descr_ref loc_result = NULL;
5068 register unsigned reg = reg_number (rtl);
5069 if (reg >= 0 && reg <= 31)
5071 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0);
5075 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
5080 /* Return a location descriptor that designates a base+offset location. */
5081 static dw_loc_descr_ref
5082 based_loc_descr (reg, offset)
5086 register dw_loc_descr_ref loc_result;
5087 register unsigned fp_reg = (frame_pointer_needed)
5088 ? FRAME_POINTER_REGNUM
5089 : STACK_POINTER_REGNUM;
5092 loc_result = new_loc_descr (DW_OP_fbreg,
5093 offset - current_funcdef_frame_size, 0);
5095 else if (reg >= 0 && reg <= 31)
5097 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset);
5101 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
5106 /* Return true if this RTL expression describes a base+offset calculation. */
5111 return GET_CODE (rtl) == PLUS
5112 && ((GET_CODE (XEXP (rtl, 0)) == REG
5113 && GET_CODE (XEXP (rtl, 1)) == CONST_INT));
5116 /* The following routine converts the RTL for a variable or parameter
5117 (resident in memory) into an equivalent Dwarf representation of a
5118 mechanism for getting the address of that same variable onto the top of a
5119 hypothetical "address evaluation" stack.
5120 When creating memory location descriptors, we are effectively transforming
5121 the RTL for a memory-resident object into its Dwarf postfix expression
5122 equivalent. This routine recursively descends an RTL tree, turning
5123 it into Dwarf postfix code as it goes. */
5124 static dw_loc_descr_ref
5125 mem_loc_descriptor (rtl)
5128 dw_loc_descr_ref mem_loc_result = NULL;
5129 /* Note that for a dynamically sized array, the location we will generate a
5130 description of here will be the lowest numbered location which is
5131 actually within the array. That's *not* necessarily the same as the
5132 zeroth element of the array. */
5133 switch (GET_CODE (rtl))
5136 /* The case of a subreg may arise when we have a local (register)
5137 variable or a formal (register) parameter which doesn't quite fill
5138 up an entire register. For now, just assume that it is
5139 legitimate to make the Dwarf info refer to the whole register which
5140 contains the given subreg. */
5141 rtl = XEXP (rtl, 0);
5145 /* Whenever a register number forms a part of the description of the
5146 method for calculating the (dynamic) address of a memory resident
5147 object, DWARF rules require the register number be referred to as
5148 a "base register". This distinction is not based in any way upon
5149 what category of register the hardware believes the given register
5150 belongs to. This is strictly DWARF terminology we're dealing with
5151 here. Note that in cases where the location of a memory-resident
5152 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
5153 OP_CONST (0)) the actual DWARF location descriptor that we generate
5154 may just be OP_BASEREG (basereg). This may look deceptively like
5155 the object in question was allocated to a register (rather than in
5156 memory) so DWARF consumers need to be aware of the subtle
5157 distinction between OP_REG and OP_BASEREG. */
5158 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
5162 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0));
5163 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
5168 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
5169 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
5170 mem_loc_result->dw_loc_oprnd1.v.val_addr = addr_to_string (rtl);
5174 if (is_based_loc (rtl))
5176 mem_loc_result = based_loc_descr (
5177 reg_number (XEXP (rtl, 0)),
5178 INTVAL (XEXP (rtl, 1)));
5182 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
5183 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
5184 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
5189 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
5195 return mem_loc_result;
5198 /* Output a proper Dwarf location descriptor for a variable or parameter
5199 which is either allocated in a register or in a memory location. For a
5200 register, we just generate an OP_REG and the register number. For a
5201 memory location we provide a Dwarf postfix expression describing how to
5202 generate the (dynamic) address of the object onto the address stack. */
5203 static dw_loc_descr_ref
5204 loc_descriptor (rtl)
5207 dw_loc_descr_ref loc_result = NULL;
5208 switch (GET_CODE (rtl))
5212 /* The case of a subreg may arise when we have a local (register)
5213 variable or a formal (register) parameter which doesn't quite fill
5214 up an entire register. For now, just assume that it is
5215 legitimate to make the Dwarf info refer to the whole register which
5216 contains the given subreg. */
5218 rtl = XEXP (rtl, 0);
5219 loc_result = new_loc_descr (DW_OP_regx, reg_number (rtl), 0);
5223 loc_result = new_loc_descr (DW_OP_regx, reg_number (rtl), 0);
5227 loc_result = mem_loc_descriptor (XEXP (rtl, 0));
5231 abort (); /* Should never happen */
5236 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
5237 which is not less than the value itself. */
5239 ceiling (value, boundary)
5240 register unsigned value;
5241 register unsigned boundary;
5243 return (((value + boundary - 1) / boundary) * boundary);
5246 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
5247 pointer to the declared type for the relevant field variable, or return
5248 `integer_type_node' if the given node turns out to be an
5256 if (TREE_CODE (decl) == ERROR_MARK)
5257 return integer_type_node;
5259 type = DECL_BIT_FIELD_TYPE (decl);
5261 type = TREE_TYPE (decl);
5266 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
5267 node, return the alignment in bits for the type, or else return
5268 BITS_PER_WORD if the node actually turns out to be an
5271 simple_type_align_in_bits (type)
5274 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
5277 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
5278 node, return the size in bits for the type if it is a constant, or else
5279 return the alignment for the type if the type's size is not constant, or
5280 else return BITS_PER_WORD if the type actually turns out to be an
5283 simple_type_size_in_bits (type)
5286 if (TREE_CODE (type) == ERROR_MARK)
5287 return BITS_PER_WORD;
5290 register tree type_size_tree = TYPE_SIZE (type);
5292 if (TREE_CODE (type_size_tree) != INTEGER_CST)
5293 return TYPE_ALIGN (type);
5295 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
5299 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
5300 return the byte offset of the lowest addressed byte of the "containing
5301 object" for the given FIELD_DECL, or return 0 if we are unable to
5302 determine what that offset is, either because the argument turns out to
5303 be a pointer to an ERROR_MARK node, or because the offset is actually
5304 variable. (We can't handle the latter case just yet). */
5306 field_byte_offset (decl)
5309 register unsigned type_align_in_bytes;
5310 register unsigned type_align_in_bits;
5311 register unsigned type_size_in_bits;
5312 register unsigned object_offset_in_align_units;
5313 register unsigned object_offset_in_bits;
5314 register unsigned object_offset_in_bytes;
5316 register tree bitpos_tree;
5317 register tree field_size_tree;
5318 register unsigned bitpos_int;
5319 register unsigned deepest_bitpos;
5320 register unsigned field_size_in_bits;
5322 if (TREE_CODE (decl) == ERROR_MARK)
5325 if (TREE_CODE (decl) != FIELD_DECL)
5328 type = field_type (decl);
5330 bitpos_tree = DECL_FIELD_BITPOS (decl);
5331 field_size_tree = DECL_SIZE (decl);
5333 /* We cannot yet cope with fields whose positions or sizes are variable, so
5334 for now, when we see such things, we simply return 0. Someday, we may
5335 be able to handle such cases, but it will be damn difficult. */
5336 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
5338 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
5340 if (TREE_CODE (field_size_tree) != INTEGER_CST)
5342 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
5344 type_size_in_bits = simple_type_size_in_bits (type);
5346 type_align_in_bits = simple_type_align_in_bits (type);
5347 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
5349 /* Note that the GCC front-end doesn't make any attempt to keep track of
5350 the starting bit offset (relative to the start of the containing
5351 structure type) of the hypothetical "containing object" for a bit-
5352 field. Thus, when computing the byte offset value for the start of the
5353 "containing object" of a bit-field, we must deduce this information on
5354 our own. This can be rather tricky to do in some cases. For example,
5355 handling the following structure type definition when compiling for an
5356 i386/i486 target (which only aligns long long's to 32-bit boundaries)
5359 struct S { int field1; long long field2:31; };
5361 Fortunately, there is a simple rule-of-thumb which can be
5362 used in such cases. When compiling for an i386/i486, GCC will allocate
5363 8 bytes for the structure shown above. It decides to do this based upon
5364 one simple rule for bit-field allocation. Quite simply, GCC allocates
5365 each "containing object" for each bit-field at the first (i.e. lowest
5366 addressed) legitimate alignment boundary (based upon the required
5367 minimum alignment for the declared type of the field) which it can
5368 possibly use, subject to the condition that there is still enough
5369 available space remaining in the containing object (when allocated at
5370 the selected point) to fully accommodate all of the bits of the
5371 bit-field itself. This simple rule makes it obvious why GCC allocates
5372 8 bytes for each object of the structure type shown above. When looking
5373 for a place to allocate the "containing object" for `field2', the
5374 compiler simply tries to allocate a 64-bit "containing object" at each
5375 successive 32-bit boundary (starting at zero) until it finds a place to
5376 allocate that 64- bit field such that at least 31 contiguous (and
5377 previously unallocated) bits remain within that selected 64 bit field.
5378 (As it turns out, for the example above, the compiler finds that it is
5379 OK to allocate the "containing object" 64-bit field at bit-offset zero
5380 within the structure type.) Here we attempt to work backwards from the
5381 limited set of facts we're given, and we try to deduce from those facts,
5382 where GCC must have believed that the containing object started (within
5383 the structure type). The value we deduce is then used (by the callers of
5384 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
5385 for fields (both bit-fields and, in the case of DW_AT_location, regular
5388 /* Figure out the bit-distance from the start of the structure to the
5389 "deepest" bit of the bit-field. */
5390 deepest_bitpos = bitpos_int + field_size_in_bits;
5392 /* This is the tricky part. Use some fancy footwork to deduce where the
5393 lowest addressed bit of the containing object must be. */
5394 object_offset_in_bits
5395 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
5397 /* Compute the offset of the containing object in "alignment units". */
5398 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
5400 /* Compute the offset of the containing object in bytes. */
5401 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
5403 return object_offset_in_bytes;
5408 /****************************** attributes *********************************/
5410 /* The following routines define various Dwarf attributes
5411 (and any data associated with them). */
5414 /* Output the form of location attributes suitable for whole variables and
5415 whole parameters. Note that the location attributes for struct fields are
5416 generated by the routine `data_member_location_attribute' below. */
5418 add_location_attribute (die, rtl)
5422 dw_loc_descr_ref loc_descr = NULL;
5424 /* Handle a special case. If we are about to output a location descriptor
5425 for a variable or parameter which has been optimized out of existence,
5426 don't do that. Instead we output a null location descriptor value as
5427 part of the location attribute. A variable which has been optimized out
5428 of existence will have a DECL_RTL value which denotes a pseudo-reg.
5429 Currently, in some rare cases, variables can have DECL_RTL values which
5430 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
5431 elsewhere in the compiler. We treat such cases as if the variable(s) in
5432 question had been optimized out of existence. Note that in all cases
5433 where we wish to express the fact that a variable has been optimized out
5434 of existence, we do not simply suppress the generation of the entire
5435 location attribute because the absence of a location attribute in
5436 certain kinds of DIEs is used to indicate something else entirely...
5437 i.e. that the DIE represents an object declaration, but not a
5438 definition. So sayeth the PLSIG. */
5439 if (!is_pseudo_reg (rtl)
5440 && (GET_CODE (rtl) != MEM
5441 || !is_pseudo_reg (XEXP (rtl, 0))))
5443 loc_descr = loc_descriptor (eliminate_regs (rtl, 0, NULL_RTX));
5446 #ifdef MIPS_DEBUGGING_INFO
5447 /* ??? SGI's dwarf reader is buggy, and will not accept a zero size
5448 location descriptor. Lets just use r0 for now to represent a
5449 variable that has been optimized away. */
5450 if (loc_descr == NULL)
5452 loc_descr = loc_descriptor (gen_rtx (REG, word_mode, 0));
5456 add_AT_loc (die, DW_AT_location, loc_descr);
5459 /* Attach the specialized form of location attribute used for data
5460 members of struct and union types. In the special case of a
5461 FIELD_DECL node which represents a bit-field, the "offset" part
5462 of this special location descriptor must indicate the distance
5463 in bytes from the lowest-addressed byte of the containing struct
5464 or union type to the lowest-addressed byte of the "containing
5465 object" for the bit-field. (See the `field_byte_offset' function
5466 above).. For any given bit-field, the "containing object" is a
5467 hypothetical object (of some integral or enum type) within which
5468 the given bit-field lives. The type of this hypothetical
5469 "containing object" is always the same as the declared type of
5470 the individual bit-field itself (for GCC anyway... the DWARF
5471 spec doesn't actually mandate this). Note that it is the size
5472 (in bytes) of the hypothetical "containing object" which will
5473 be given in the DW_AT_byte_size attribute for this bit-field.
5474 (See the `byte_size_attribute' function below.) It is also used
5475 when calculating the value of the DW_AT_bit_offset attribute.
5476 (See the `bit_offset_attribute' function below). */
5478 add_data_member_location_attribute (die, decl)
5479 register dw_die_ref die;
5482 register unsigned long offset = field_byte_offset (decl);
5483 register dw_loc_descr_ref loc_descr;
5484 register enum dwarf_location_atom op;
5486 /* The DWARF2 standard says that we should assume that the structure address
5487 is already on the stack, so we can specify a structure field address
5488 by using DW_OP_plus_uconst. */
5489 #ifdef MIPS_DEBUGGING_INFO
5490 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
5491 correctly. It works only if we leave the offset on the stack. */
5494 op = DW_OP_plus_uconst;
5496 loc_descr = new_loc_descr (op, offset, 0);
5497 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
5500 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
5501 does not have a "location" either in memory or in a register. These
5502 things can arise in GNU C when a constant is passed as an actual parameter
5503 to an inlined function. They can also arise in C++ where declared
5504 constants do not necessarily get memory "homes". */
5506 add_const_value_attribute (die, rtl)
5507 register dw_die_ref die;
5510 switch (GET_CODE (rtl))
5513 /* Note that a CONST_INT rtx could represent either an integer or a
5514 floating-point constant. A CONST_INT is used whenever the constant
5515 will fit into a single word. In all such cases, the original mode
5516 of the constant value is wiped out, and the CONST_INT rtx is
5517 assigned VOIDmode. */
5518 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
5522 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
5523 floating-point constant. A CONST_DOUBLE is used whenever the
5524 constant requires more than one word in order to be adequately
5525 represented. In all such cases, the original mode of the constant
5526 value is preserved as the mode of the CONST_DOUBLE rtx, but for
5527 simplicity we always just output CONST_DOUBLEs using 8 bytes. */
5528 add_AT_double (die, DW_AT_const_value,
5529 (unsigned) CONST_DOUBLE_HIGH (rtl),
5530 (unsigned) CONST_DOUBLE_LOW (rtl));
5534 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
5540 add_AT_addr (die, DW_AT_const_value, addr_to_string (rtl));
5544 /* In cases where an inlined instance of an inline function is passed
5545 the address of an `auto' variable (which is local to the caller) we
5546 can get a situation where the DECL_RTL of the artificial local
5547 variable (for the inlining) which acts as a stand-in for the
5548 corresponding formal parameter (of the inline function) will look
5549 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
5550 exactly a compile-time constant expression, but it isn't the address
5551 of the (artificial) local variable either. Rather, it represents the
5552 *value* which the artificial local variable always has during its
5553 lifetime. We currently have no way to represent such quasi-constant
5554 values in Dwarf, so for now we just punt and generate an
5555 DW_AT_const_value attribute with null address. */
5556 add_AT_addr (die, DW_AT_const_value, addr_to_string (const0_rtx));
5560 /* No other kinds of rtx should be possible here. */
5566 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
5567 data attribute for a variable or a parameter. We generate the
5568 DW_AT_const_value attribute only in those cases where the given variable
5569 or parameter does not have a true "location" either in memory or in a
5570 register. This can happen (for example) when a constant is passed as an
5571 actual argument in a call to an inline function. (It's possible that
5572 these things can crop up in other ways also.) Note that one type of
5573 constant value which can be passed into an inlined function is a constant
5574 pointer. This can happen for example if an actual argument in an inlined
5575 function call evaluates to a compile-time constant address. */
5577 add_location_or_const_value_attribute (die, decl)
5578 register dw_die_ref die;
5582 register tree declared_type;
5583 register tree passed_type;
5585 if (TREE_CODE (decl) == ERROR_MARK)
5589 if ((TREE_CODE (decl) != VAR_DECL)
5590 && (TREE_CODE (decl) != PARM_DECL))
5592 /* Should never happen. */
5596 /* Here we have to decide where we are going to say the parameter "lives"
5597 (as far as the debugger is concerned). We only have a couple of
5598 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
5599 DECL_RTL normally indicates where the parameter lives during most of the
5600 activa- tion of the function. If optimization is enabled however, this
5601 could be either NULL or else a pseudo-reg. Both of those cases indicate
5602 that the parameter doesn't really live anywhere (as far as the code
5603 generation parts of GCC are concerned) during most of the function's
5604 activation. That will happen (for example) if the parameter is never
5605 referenced within the function. We could just generate a location
5606 descriptor here for all non-NULL non-pseudo values of DECL_RTL and
5607 ignore all of the rest, but we can be a little nicer than that if we
5608 also consider DECL_INCOMING_RTL in cases where DECL_RTL is NULL or is a
5609 pseudo-reg. Note however that we can only get away with using
5610 DECL_INCOMING_RTL as a backup substitute for DECL_RTL in certain limited
5611 cases. In cases where DECL_ARG_TYPE(decl) indicates the same type as
5612 TREE_TYPE(decl) we can be sure that the parameter was passed using the
5613 same type as it is declared to have within the function, and that its
5614 DECL_INCOMING_RTL points us to a place where a value of that type is
5615 passed. In cases where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are
5616 different types however, we cannot (in general) use DECL_INCOMING_RTL as
5617 a backup substitute for DECL_RTL because in these cases,
5618 DECL_INCOMING_RTL points us to a value of some type which is *different*
5619 from the type of the parameter itself. Thus, if we tried to use
5620 DECL_INCOMING_RTL to generate a location attribute in such cases, the
5621 debugger would end up (for example) trying to fetch a `float' from a
5622 place which actually contains the first part of a `double'. That would
5623 lead to really incorrect and confusing output at debug-time, and we
5624 don't want that now do we? So in general, we DO NOT use
5625 DECL_INCOMING_RTL as a backup for DECL_RTL in cases where
5626 DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a couple of cute
5627 exceptions however. On little-endian machines we can get away with
5628 using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is not the same as
5629 TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is an integral type
5630 which is smaller than TREE_TYPE(decl). These cases arise when (on a
5631 little-endian machine) a non-prototyped function has a parameter
5632 declared to be of type `short' or `char'. In such cases,
5633 TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
5634 `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
5635 passed `int' value. If the debugger then uses that address to fetch a
5636 `short' or a `char' (on a little-endian machine) the result will be the
5637 correct data, so we allow for such exceptional cases below. Note that
5638 our goal here is to describe the place where the given formal parameter
5639 lives during most of the function's activation (i.e. between the end of
5640 the prologue and the start of the epilogue). We'll do that as best as
5641 we can. Note however that if the given formal parameter is modified
5642 sometime during the execution of the function, then a stack backtrace
5643 (at debug-time) will show the function as having been called with the
5644 *new* value rather than the value which was originally passed in. This
5645 happens rarely enough that it is not a major problem, but it *is* a
5646 problem, and I'd like to fix it. A future version of dwarfout.c may
5647 generate two additional attributes for any given DW_TAG_formal_parameter
5648 DIE which will describe the "passed type" and the "passed location" for
5649 the given formal parameter in addition to the attributes we now generate
5650 to indicate the "declared type" and the "active location" for each
5651 parameter. This additional set of attributes could be used by debuggers
5652 for stack backtraces. Separately, note that sometimes DECL_RTL can be
5653 NULL and DECL_INCOMING_RTL can be NULL also. This happens (for example)
5654 for inlined-instances of inline function formal parameters which are
5655 never referenced. This really shouldn't be happening. All PARM_DECL
5656 nodes should get valid non-NULL DECL_INCOMING_RTL values, but
5657 integrate.c doesn't currently generate these values for inlined
5658 instances of inline function parameters, so when we see such cases, we
5659 are just SOL (shit-out-of-luck) for the time being (until integrate.c
5662 /* Use DECL_RTL as the "location" unless we find something better. */
5663 rtl = DECL_RTL (decl);
5665 if (TREE_CODE (decl) == PARM_DECL)
5667 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
5669 declared_type = type_main_variant (TREE_TYPE (decl));
5670 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
5671 /* This decl represents a formal parameter which was
5674 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
5675 all* cases where (rtl == NULL_RTX) just below. */
5676 if (declared_type == passed_type)
5678 rtl = DECL_INCOMING_RTL (decl);
5680 else if (!BYTES_BIG_ENDIAN)
5682 if (TREE_CODE (declared_type) == INTEGER_TYPE)
5684 if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
5686 rtl = DECL_INCOMING_RTL (decl);
5690 if (rtl == NULL_RTX)
5696 switch (GET_CODE (rtl))
5705 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
5706 add_const_value_attribute (die, rtl);
5712 add_location_attribute (die, rtl);
5716 abort (); /* Should never happen. */
5720 /* Generate an DW_AT_name attribute given some string value to be included as
5721 the value of the attribute. */
5723 add_name_attribute (die, name_string)
5724 register dw_die_ref die;
5725 register char *name_string;
5727 if (name_string && *name_string)
5729 add_AT_string (die, DW_AT_name, name_string);
5733 /* Given a tree node describing an array bound (either lower or upper) output
5734 a representation for that bound. */
5736 add_bound_info (subrange_die, bound_attr, bound)
5737 register dw_die_ref subrange_die;
5738 register enum dwarf_attribute bound_attr;
5739 register tree bound;
5741 register dw_loc_descr_ref bound_loc = NULL;
5742 register unsigned bound_value = 0;
5743 switch (TREE_CODE (bound))
5748 /* All fixed-bounds are represented by INTEGER_CST nodes. */
5750 bound_value = TREE_INT_CST_LOW (bound);
5751 /* TODO: we need to check for C language below, or some flag
5752 derived from the language. C implies a lower bound of 0. */
5753 if (!(bound_attr == DW_AT_lower_bound && bound_value == 0))
5755 add_AT_unsigned (subrange_die, bound_attr, bound_value);
5759 /* Dynamic bounds may be represented by NOP_EXPR nodes containing
5762 bound = TREE_OPERAND (bound, 0);
5763 /* ... fall thru... */
5766 /* If optimization is turned on, the SAVE_EXPRs that describe how to
5767 access the upper bound values are essentially bogus. They only
5768 describe (at best) how to get at these values at the points in the
5769 generated code right after they have just been computed. Worse yet,
5770 in the typical case, the upper bound values will not even *be*
5771 computed in the optimized code, so these SAVE_EXPRs are entirely
5772 bogus. In order to compensate for this fact, we check here to see if
5773 optimization is enabled, and if so, we effectively create an empty
5774 location description for the (unknown and unknowable) upper bound.
5775 This should not cause too much trouble for existing (stupid?)
5776 debuggers because they have to deal with empty upper bounds location
5777 descriptions anyway in order to be able to deal with incomplete array
5778 types. Of course an intelligent debugger (GDB?) should be able to
5779 comprehend that a missing upper bound specification in a array type
5780 used for a storage class `auto' local array variable indicates that
5781 the upper bound is both unknown (at compile- time) and unknowable (at
5782 run-time) due to optimization. */
5785 bound_loc = mem_loc_descriptor (
5786 eliminate_regs (SAVE_EXPR_RTL (bound),
5793 add_AT_loc (subrange_die, bound_attr, bound_loc);
5801 /* Note that the block of subscript information for an array type also
5802 includes information about the element type of type given array type. */
5804 add_subscript_info (type_die, type)
5805 register dw_die_ref type_die;
5808 register unsigned dimension_number;
5809 register tree lower, upper;
5810 register dw_die_ref subrange_die;
5812 /* The GNU compilers represent multidimensional array types as sequences of
5813 one dimensional array types whose element types are themselves array
5814 types. Here we squish that down, so that each multidimensional array
5815 type gets only one array_type DIE in the Dwarf debugging info. The draft
5816 Dwarf specification say that we are allowed to do this kind of
5817 compression in C (because there is no difference between an array or
5818 arrays and a multidimensional array in C) but for other source languages
5819 (e.g. Ada) we probably shouldn't do this. */
5820 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
5821 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
5822 We work around this by disabling this feature. See also
5823 gen_array_type_die. */
5824 #ifndef MIPS_DEBUGGING_INFO
5825 for (dimension_number = 0;
5826 TREE_CODE (type) == ARRAY_TYPE;
5827 type = TREE_TYPE (type), dimension_number++)
5830 register tree domain = TYPE_DOMAIN (type);
5832 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
5833 and (in GNU C only) variable bounds. Handle all three forms
5835 subrange_die = new_die (DW_TAG_subrange_type, type_die);
5838 /* We have an array type with specified bounds. */
5839 lower = TYPE_MIN_VALUE (domain);
5840 upper = TYPE_MAX_VALUE (domain);
5842 /* TODO: establish DW_AT_type for the basis type a byte_size
5843 attribute if the byte size is non-standard */
5844 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
5845 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
5849 /* We have an array type with an unspecified length. For C and C++
5850 we can assume that this really means that (a) the index type is
5851 an integral type, and (b) the lower bound is zero. Note that
5852 Dwarf defines the representation of an unspecified (upper) bound
5853 as being a zero-length location description. */
5855 /* define the (assumed) index type. */
5856 add_AT_die_ref (subrange_die, DW_AT_type, int_base_type_die);
5858 /* Add the (assumed) lower bound (constant) value. */
5859 add_AT_unsigned (subrange_die, DW_AT_lower_bound, 0);
5861 /* Add the (empty) location description for the upper bound. */
5862 add_AT_loc (subrange_die, DW_AT_upper_bound, NULL);
5864 #ifndef MIPS_DEBUGGING_INFO
5870 add_byte_size_attribute (die, tree_node)
5872 register tree tree_node;
5874 register unsigned size;
5876 switch (TREE_CODE (tree_node))
5884 case QUAL_UNION_TYPE:
5885 size = int_size_in_bytes (tree_node);
5888 /* For a data member of a struct or union, the DW_AT_byte_size is
5889 generally given as the number of bytes normally allocated for an
5890 object of the *declared* type of the member itself. This is true
5891 even for bit-fields. */
5892 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
5898 /* Note that `size' might be -1 when we get to this point. If it is, that
5899 indicates that the byte size of the entity in question is variable. We
5900 have no good way of expressing this fact in Dwarf at the present time,
5901 so just let the -1 pass on through. */
5903 add_AT_unsigned (die, DW_AT_byte_size, size);
5906 /* For a FIELD_DECL node which represents a bit-field, output an attribute
5907 which specifies the distance in bits from the highest order bit of the
5908 "containing object" for the bit-field to the highest order bit of the
5911 For any given bit-field, the "containing object" is a hypothetical object (of
5912 some integral or enum type) within which the given bit-field lives. The
5913 type of this hypothetical "containing object" is always the same as the
5914 declared type of the individual bit-field itself.
5915 The determination of the exact location of the "containing object" for a
5916 bit-field is rather complicated. It's handled by the `field_byte_offset'
5919 Note that it is the size (in bytes) of the hypothetical "containing object"
5920 which will be given in the DW_AT_byte_size attribute for this bit-field.
5921 (See `byte_size_attribute' above). */
5923 add_bit_offset_attribute (die, decl)
5924 register dw_die_ref die;
5927 register unsigned object_offset_in_bytes = field_byte_offset (decl);
5928 register tree type = DECL_BIT_FIELD_TYPE (decl);
5929 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
5930 register unsigned bitpos_int;
5931 register unsigned highest_order_object_bit_offset;
5932 register unsigned highest_order_field_bit_offset;
5933 register unsigned bit_offset;
5935 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
5936 assert (type); /* Must be a bit field. */
5938 /* We can't yet handle bit-fields whose offsets are variable, so if we
5939 encounter such things, just return without generating any attribute
5941 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
5945 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
5947 /* Note that the bit offset is always the distance (in bits) from the
5948 highest-order bit of the "containing object" to the highest-order bit of
5949 the bit-field itself. Since the "high-order end" of any object or field
5950 is different on big-endian and little-endian machines, the computation
5951 below must take account of these differences. */
5952 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
5953 highest_order_field_bit_offset = bitpos_int;
5955 if (!BYTES_BIG_ENDIAN)
5957 highest_order_field_bit_offset
5958 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
5960 highest_order_object_bit_offset += simple_type_size_in_bits (type);
5964 ? highest_order_object_bit_offset - highest_order_field_bit_offset
5965 : highest_order_field_bit_offset - highest_order_object_bit_offset);
5967 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
5970 /* For a FIELD_DECL node which represents a bit field, output an attribute
5971 which specifies the length in bits of the given field. */
5973 add_bit_size_attribute (die, decl)
5974 register dw_die_ref die;
5977 assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */
5978 assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */
5979 add_AT_unsigned (die, DW_AT_bit_size,
5980 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
5983 /* If the compiled language is GNU C, then add a 'prototyped'
5984 attribute, if arg types are given for the parameters of a function. */
5986 add_prototyped_attribute (die, func_type)
5987 register dw_die_ref die;
5988 register tree func_type;
5990 if ((strcmp (language_string, "GNU C") == 0)
5991 && (TYPE_ARG_TYPES (func_type) != NULL))
5993 add_AT_flag (die, DW_AT_prototyped, 0);
5998 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
5999 by looking in either the type declaration or object declaration
6002 add_abstract_origin_attribute (die, origin)
6003 register dw_die_ref die;
6004 register tree origin;
6006 dw_die_ref origin_die = NULL;
6007 if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd')
6009 origin_die = lookup_decl_die (origin);
6011 else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't')
6013 origin_die = lookup_type_die (origin);
6015 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
6018 /* We do not currently support the pure_virtual attribute. */
6021 add_pure_or_virtual_attribute (die, func_decl)
6022 register dw_die_ref die;
6023 register tree func_decl;
6025 if (DECL_VIRTUAL_P (func_decl))
6027 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
6031 /********************* utility routines for DIEs *************************/
6033 /* Add an DW_AT_name attribute and source coordinate attribute for the
6034 given decl, but only if it actually has a name. */
6036 add_name_and_src_coords_attributes (die, decl)
6037 register dw_die_ref die;
6040 register tree decl_name = DECL_ASSEMBLER_NAME (decl);
6041 register unsigned file_index;
6042 if (decl_name && IDENTIFIER_POINTER (decl_name))
6044 add_name_attribute (die, IDENTIFIER_POINTER (decl_name));
6045 file_index = lookup_filename (DECL_SOURCE_FILE (decl));
6046 add_AT_unsigned (die, DW_AT_decl_file, file_index);
6047 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
6051 /* Push a new declaration scope. */
6053 push_decl_scope (scope)
6056 /* Make room in the decl_scope_table, if necessary. */
6057 if (decl_scope_table_allocated == decl_scope_depth)
6059 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
6060 decl_scope_table = (tree *) xrealloc (decl_scope_table,
6061 decl_scope_table_allocated * sizeof (tree));
6063 decl_scope_table[decl_scope_depth++] = scope;
6066 /* Return the DIE for the scope the immediately contains this declaration. */
6068 scope_die_for_type (type, context_die)
6070 register dw_die_ref context_die;
6072 register dw_die_ref scope_die = NULL;
6073 register tree containing_scope;
6074 register unsigned long i;
6076 /* Walk back up the declaration tree looking for a place to define
6078 containing_scope = TYPE_CONTEXT (type);
6079 if (containing_scope == NULL)
6081 scope_die = comp_unit_die;
6085 for (i = decl_scope_depth - 1, scope_die = context_die;
6087 && scope_die != NULL
6088 && decl_scope_table[i] != containing_scope;
6089 --i, scope_die = scope_die->die_parent)
6093 if (scope_die == NULL)
6095 scope_die = context_die;
6101 /* Pop a declaration scope. */
6105 assert (decl_scope_depth > 0);
6109 /* Many forms of DIEs require a "type description" attribute. This
6110 routine locates the proper "type descriptor" die for the type given
6111 by 'type', and adds an DW_AT_type attribute below the given die. */
6113 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
6114 register dw_die_ref object_die;
6116 register int decl_const;
6117 register int decl_volatile;
6118 register dw_die_ref context_die;
6120 register enum tree_code code = TREE_CODE (type);
6121 register dw_die_ref scope_die = NULL;
6122 register dw_die_ref type_die = NULL;
6124 if (code == ERROR_MARK)
6129 /* Handle a special case. For functions whose return type is void, we
6130 generate *no* type attribute. (Note that no object may have type
6131 `void', so this only applies to function return types). */
6132 if (code == VOID_TYPE)
6137 scope_die = scope_die_for_type (type, context_die);
6138 type_die = modified_type_die (type,
6139 decl_const || TYPE_READONLY (type),
6140 decl_volatile || TYPE_VOLATILE (type),
6142 if (type_die != NULL)
6144 add_AT_die_ref (object_die, DW_AT_type, type_die);
6148 /* Given a tree pointer to a struct, class, union, or enum type node, return
6149 a pointer to the (string) tag name for the given type, or zero if the type
6150 was declared without a tag. */
6155 register char *name = 0;
6157 if (TYPE_NAME (type) != 0)
6159 register tree t = 0;
6161 /* Find the IDENTIFIER_NODE for the type name. */
6162 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
6163 t = TYPE_NAME (type);
6165 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
6166 a TYPE_DECL node, regardless of whether or not a `typedef' was
6168 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
6169 t = DECL_NAME (TYPE_NAME (type));
6171 /* Now get the name as a string, or invent one. */
6174 name = IDENTIFIER_POINTER (t);
6177 return (name == 0 || *name == '\0') ? 0 : name;
6180 /* Return the type associated with a data member, make a special check
6181 for bit field types. */
6183 member_declared_type (member)
6184 register tree member;
6186 return (DECL_BIT_FIELD_TYPE (member))
6187 ? DECL_BIT_FIELD_TYPE (member)
6188 : TREE_TYPE (member);
6191 /* Get the decl's label, as described by its RTL. This may be different
6192 from the DECL_NAME name used in the source file. */
6194 decl_start_label (decl)
6199 x = DECL_RTL (decl);
6200 if (GET_CODE (x) != MEM)
6205 if (GET_CODE (x) != SYMBOL_REF)
6209 fnname = XSTR (x, 0);
6213 /******************************* DIE Generation *************************/
6215 /* These routines generate the internnal representation of the DIE's for
6216 the compilation unit. Debugging information is collected by walking
6217 the declaration trees passed in from dwarfout_file_scope_decl(). */
6220 gen_array_type_die (type, context_die)
6222 register dw_die_ref context_die;
6224 register dw_die_ref scope_die = scope_die_for_type (type, context_die);
6225 register dw_die_ref array_die = lookup_type_die (type);
6226 register tree element_type;
6231 array_die = new_die (DW_TAG_array_type, scope_die);
6233 /* We default the array ordering. SDB will probably do
6234 the right things even if DW_AT_ordering is not present. It's not even
6235 an issue until we start to get into multidimensional arrays anyway. If
6236 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
6237 then we'll have to put the DW_AT_ordering attribute back in. (But if
6238 and when we find out that we need to put these in, we will only do so
6239 for multidimensional arrays. */
6240 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
6243 add_subscript_info (array_die, type);
6245 equate_type_number_to_die (type, array_die);
6247 /* Add representation of the type of the elements of this array type. */
6248 element_type = TREE_TYPE (type);
6249 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
6250 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
6251 We work around this by disabling this feature. See also
6252 add_subscript_info. */
6253 #ifndef MIPS_DEBUGGING_INFO
6254 while (TREE_CODE (element_type) == ARRAY_TYPE)
6256 element_type = TREE_TYPE (element_type);
6259 gen_type_die (element_type, context_die);
6261 add_type_attribute (array_die, element_type, 0, 0, context_die);
6265 gen_set_type_die (type, context_die)
6267 register dw_die_ref context_die;
6269 register dw_die_ref type_die = lookup_type_die (type);
6272 type_die = new_die (DW_TAG_set_type, scope_die_for_type (type, context_die));
6273 equate_type_number_to_die (type, type_die);
6274 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
6278 gen_entry_point_die (decl, context_die)
6280 register dw_die_ref context_die;
6282 register tree origin = decl_ultimate_origin (decl);
6283 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
6286 add_abstract_origin_attribute (decl_die, origin);
6290 add_name_and_src_coords_attributes (decl_die, decl);
6291 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
6294 if (DECL_ABSTRACT (decl))
6296 equate_decl_number_to_die (decl, decl_die);
6300 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
6304 /* Generate a DIE to represent an inlined instance of an enumeration type. */
6306 gen_inlined_enumeration_type_die (type, context_die)
6308 register dw_die_ref context_die;
6310 register dw_die_ref type_die;
6311 type_die = new_die (DW_TAG_enumeration_type,
6312 scope_die_for_type (type, context_die));
6313 assert (TREE_ASM_WRITTEN (type));
6314 add_abstract_origin_attribute (type_die, type);
6317 /* Generate a DIE to represent an inlined instance of a structure type. */
6319 gen_inlined_structure_type_die (type, context_die)
6321 register dw_die_ref context_die;
6323 register dw_die_ref type_die;
6324 type_die = new_die (DW_TAG_structure_type,
6325 scope_die_for_type (type, context_die));
6326 assert (TREE_ASM_WRITTEN (type));
6327 add_abstract_origin_attribute (type_die, type);
6330 /* Generate a DIE to represent an inlined instance of a union type. */
6332 gen_inlined_union_type_die (type, context_die)
6334 register dw_die_ref context_die;
6336 register dw_die_ref type_die;
6337 type_die = new_die (DW_TAG_union_type,
6338 scope_die_for_type (type, context_die));
6339 assert (TREE_ASM_WRITTEN (type));
6340 add_abstract_origin_attribute (type_die, type);
6343 /* Generate a DIE to represent an enumeration type. Note that these DIEs
6344 include all of the information about the enumeration values also. Each
6345 enumerated type name/value is listed as a child of the enumerated type DIE */
6347 gen_enumeration_type_die (type, is_complete, context_die)
6349 register unsigned is_complete;
6350 register dw_die_ref context_die;
6352 register dw_die_ref type_die;
6353 register dw_die_ref enum_die;
6355 type_die = lookup_type_die (type);
6356 if (type_die == NULL)
6358 type_die = new_die (DW_TAG_enumeration_type,
6359 scope_die_for_type (type, context_die));
6360 equate_type_number_to_die (type, type_die);
6361 add_name_attribute (type_die, type_tag (type));
6365 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
6366 given enum type is incomplete, do not generate the DW_AT_byte_size
6367 attribute or the DW_AT_element_list attribute. */
6368 if (TYPE_SIZE (type))
6370 add_byte_size_attribute (type_die, type);
6371 for (link = TYPE_FIELDS (type);
6372 link != NULL; link = TREE_CHAIN (link))
6374 enum_die = new_die (DW_TAG_enumerator, type_die);
6375 add_name_attribute (enum_die,
6376 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
6377 add_AT_unsigned (enum_die, DW_AT_const_value,
6378 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
6385 /* Generate a DIE to represent either a real live formal parameter decl or to
6386 represent just the type of some formal parameter position in some function
6388 Note that this routine is a bit unusual because its argument may be a
6389 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
6390 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
6391 node. If it's the former then this function is being called to output a
6392 DIE to represent a formal parameter object (or some inlining thereof). If
6393 it's the latter, then this function is only being called to output a
6394 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
6395 argument type of some subprogram type. */
6397 gen_formal_parameter_die (node, context_die)
6399 register dw_die_ref context_die;
6401 register dw_die_ref parm_die = new_die (DW_TAG_formal_parameter,
6403 register tree origin;
6404 switch (TREE_CODE_CLASS (TREE_CODE (node)))
6406 /* We were called with some kind of a ..._DECL node. */
6408 origin = decl_ultimate_origin (node);
6411 add_abstract_origin_attribute (parm_die, origin);
6415 add_name_and_src_coords_attributes (parm_die, node);
6416 add_type_attribute (parm_die, TREE_TYPE (node),
6417 TREE_READONLY (node),
6418 TREE_THIS_VOLATILE (node),
6420 if (DECL_ARTIFICIAL (node))
6421 add_AT_flag (parm_die, DW_AT_artificial, 1);
6423 if (DECL_ABSTRACT (node))
6425 equate_decl_number_to_die (node, parm_die);
6429 add_location_or_const_value_attribute (parm_die, node);
6433 /* We were called with some kind of a ..._TYPE node. */
6435 add_type_attribute (parm_die, node, 0, 0, context_die);
6438 /* Should never happen. */
6444 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
6445 at the end of an (ANSI prototyped) formal parameters list. */
6447 gen_unspecified_parameters_die (decl_or_type, context_die)
6448 register tree decl_or_type;
6449 register dw_die_ref context_die;
6451 register dw_die_ref parm_die = new_die (DW_TAG_unspecified_parameters,
6453 /* This kludge is here only for the sake of being compatible with what the
6454 USL CI5 C compiler does. The specification of Dwarf Version 1 doesn't
6455 say that DW_TAG_unspecified_parameters DIEs should contain any
6456 attributes other than the DW_AT_sibling attribute, but they are
6457 certainly allowed to contain additional attributes, and the CI5 compiler
6458 generates DW_AT_name, DW_AT_base_type, and DW_AT_location attributes
6459 within DW_TAG_unspecified_parameters DIEs which appear in the child
6460 lists for DIEs representing function definitions, so we do likewise
6462 if (TREE_CODE (decl_or_type) == FUNCTION_DECL
6463 && DECL_INITIAL (decl_or_type))
6465 add_name_attribute (parm_die, "...");
6466 add_AT_die_ref (parm_die, DW_AT_type, int_base_type_die);
6470 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
6471 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
6472 parameters as specified in some function type specification (except for
6473 those which appear as part of a function *definition*).
6474 Note that we must be careful here to output all of the parameter DIEs before*
6475 we output any DIEs needed to represent the types of the formal parameters.
6476 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
6477 non-parameter DIE it sees ends the formal parameter list. */
6479 gen_formal_types_die (function_or_method_type, context_die)
6480 register tree function_or_method_type;
6481 register dw_die_ref context_die;
6484 register tree formal_type = NULL;
6485 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
6488 /* In the case where we are generating a formal types list for a C++
6489 non-static member function type, skip over the first thing on the
6490 TYPE_ARG_TYPES list because it only represents the type of the hidden
6491 `this pointer'. The debugger should be able to figure out (without
6492 being explicitly told) that this non-static member function type takes a
6493 `this pointer' and should be able to figure what the type of that hidden
6494 parameter is from the DW_AT_member attribute of the parent
6495 DW_TAG_subroutine_type DIE. */
6496 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
6497 first_parm_type = TREE_CHAIN (first_parm_type);
6500 /* Make our first pass over the list of formal parameter types and output a
6501 DW_TAG_formal_parameter DIE for each one. */
6502 for (link = first_parm_type; link; link = TREE_CHAIN (link))
6504 formal_type = TREE_VALUE (link);
6505 if (formal_type == void_type_node)
6508 /* Output a (nameless) DIE to represent the formal parameter itself. */
6509 gen_formal_parameter_die (formal_type, context_die);
6512 /* If this function type has an ellipsis, add a
6513 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
6514 if (formal_type != void_type_node)
6515 gen_unspecified_parameters_die (function_or_method_type, context_die);
6517 /* Make our second (and final) pass over the list of formal parameter types
6518 and output DIEs to represent those types (as necessary). */
6519 for (link = TYPE_ARG_TYPES (function_or_method_type);
6521 link = TREE_CHAIN (link))
6523 formal_type = TREE_VALUE (link);
6524 if (formal_type == void_type_node)
6527 gen_type_die (formal_type, context_die);
6531 /* Generate a DIE to represent a declared function (either file-scope or
6534 gen_subprogram_die (decl, context_die)
6536 register dw_die_ref context_die;
6538 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
6539 register tree origin = decl_ultimate_origin (decl);
6540 register dw_die_ref subr_die;
6541 register dw_loc_descr_ref fp_loc = NULL;
6542 register unsigned fp_reg;
6544 register tree fn_arg_types;
6545 register tree outer_scope;
6546 register tree label;
6547 dw_die_ref old_die = lookup_decl_die (decl);
6551 subr_die = new_die (DW_TAG_subprogram, context_die);
6552 add_abstract_origin_attribute (subr_die, origin);
6556 register unsigned file_index
6557 = lookup_filename (DECL_SOURCE_FILE (decl));
6558 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
6561 /* If the definition comes from the same place as the declaration,
6563 if (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
6564 && (get_AT_unsigned (old_die, DW_AT_decl_line)
6565 == DECL_SOURCE_LINE (decl)))
6569 /* Clear out the declaration attribute and the parm types. */
6570 remove_AT (subr_die, DW_AT_declaration);
6571 remove_children (subr_die);
6575 subr_die = new_die (DW_TAG_subprogram, context_die);
6576 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
6577 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
6578 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
6579 if (get_AT_unsigned (old_die, DW_AT_decl_line)
6580 != DECL_SOURCE_LINE (decl))
6582 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
6587 subr_die = new_die (DW_TAG_subprogram, context_die);
6588 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
6590 add_AT_flag (subr_die, DW_AT_external, 1);
6592 add_name_and_src_coords_attributes (subr_die, decl);
6593 if (DECL_INLINE (decl))
6595 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
6597 type = TREE_TYPE (decl);
6598 add_prototyped_attribute (subr_die, type);
6599 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
6600 add_pure_or_virtual_attribute (subr_die, decl);
6602 /* The first time we see a member function, it is in the context of
6603 the class to which it belongs. We make sure of this by emitting
6604 the class first. The next time is the definition, which is
6605 handled above. The two may come from the same source text. */
6606 if (! DECL_INITIAL (decl))
6607 add_AT_flag (subr_die, DW_AT_declaration, 1);
6609 if (DECL_ABSTRACT (decl) || ! DECL_INITIAL (decl))
6611 equate_decl_number_to_die (decl, subr_die);
6613 else if (!DECL_EXTERNAL (decl))
6616 equate_decl_number_to_die (decl, subr_die);
6617 if (DECL_WEAK (current_function_decl)
6618 || DECL_ONE_ONLY (current_function_decl))
6620 sprintf (label_id, FUNC_BEGIN_LABEL_FMT, current_funcdef_number);
6621 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
6624 add_AT_lbl_id (subr_die, DW_AT_low_pc, decl_start_label (decl));
6625 sprintf (label_id, FUNC_END_LABEL_FMT, current_funcdef_number);
6626 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
6628 add_pubname (decl, subr_die);
6629 add_arange (decl, subr_die);
6631 #ifdef MIPS_DEBUGGING_INFO
6633 /* Add a reference to the FDE for this routine. */
6634 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
6637 /* Define the frame pointer location for this routine. */
6638 fp_reg = (frame_pointer_needed) ? FRAME_POINTER_REGNUM
6639 : STACK_POINTER_REGNUM;
6640 assert (fp_reg >= 0 && fp_reg <= 31);
6641 fp_loc = new_loc_descr (DW_OP_breg0 + fp_reg, current_funcdef_frame_size);
6642 add_AT_loc (subr_die, DW_AT_frame_base, fp_loc);
6644 #ifdef DWARF_GNU_EXTENSIONS
6645 sprintf (label_id, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
6646 add_AT_lbl_id (subr_die, DW_AT_body_begin, label_id);
6647 sprintf (label_id, BODY_END_LABEL_FMT, current_funcdef_number);
6648 add_AT_lbl_id (subr_die, DW_AT_body_end, label_id);
6653 /* Now output descriptions of the arguments for this function. This gets
6654 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
6655 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
6656 `...' at the end of the formal parameter list. In order to find out if
6657 there was a trailing ellipsis or not, we must instead look at the type
6658 associated with the FUNCTION_DECL. This will be a node of type
6659 FUNCTION_TYPE. If the chain of type nodes hanging off of this
6660 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
6661 an ellipsis at the end. */
6663 /* In the case where we are describing a mere function declaration, all we
6664 need to do here (and all we *can* do here) is to describe the *types* of
6665 its formal parameters. */
6666 if (DECL_INITIAL (decl) == NULL_TREE)
6668 gen_formal_types_die (TREE_TYPE (decl), subr_die);
6672 /* Generate DIEs to represent all known formal parameters */
6673 register tree arg_decls = DECL_ARGUMENTS (decl);
6676 /* When generating DIEs, generate the unspecified_parameters DIE
6677 instead if we come across the arg "__builtin_va_alist" */
6678 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
6680 if (TREE_CODE (parm) == PARM_DECL)
6682 if (DECL_NAME (parm) &&
6683 !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
6684 "__builtin_va_alist"))
6686 gen_unspecified_parameters_die (parm, subr_die);
6690 gen_decl_die (parm, subr_die);
6695 /* Decide whether we need a unspecified_parameters DIE at the end.
6696 There are 2 more cases to do this for: 1) the ansi ... declaration -
6697 this is detectable when the end of the arg list is not a
6698 void_type_node 2) an unprototyped function declaration (not a
6699 definition). This just means that we have no info about the
6700 parameters at all. */
6701 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
6704 /* this is the prototyped case, check for ... */
6705 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
6707 gen_unspecified_parameters_die (decl, subr_die);
6712 /* this is unprotoyped, check for undefined (just declaration) */
6713 if (!DECL_INITIAL (decl))
6715 gen_unspecified_parameters_die (decl, subr_die);
6720 /* Output Dwarf info for all of the stuff within the body of the function
6721 (if it has one - it may be just a declaration). */
6722 outer_scope = DECL_INITIAL (decl);
6724 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
6725 node created to represent a function. This outermost BLOCK actually
6726 represents the outermost binding contour for the function, i.e. the
6727 contour in which the function's formal parameters and labels get
6728 declared. Curiously, it appears that the front end doesn't actually
6729 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
6730 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
6731 list for the function instead.) The BLOCK_VARS list for the
6732 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
6733 the function however, and we output DWARF info for those in
6734 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
6735 node representing the function's outermost pair of curly braces, and
6736 any blocks used for the base and member initializers of a C++
6737 constructor function. */
6738 if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
6740 current_function_has_inlines = 0;
6741 decls_for_scope (outer_scope, subr_die, 0);
6742 #if 0 && defined (MIPS_DEBUGGING_INFO)
6743 if (current_function_has_inlines)
6745 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
6746 if (! comp_unit_has_inlines)
6748 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
6749 comp_unit_has_inlines = 1;
6756 /* Generate a DIE to represent a declared data object. */
6758 gen_variable_die (decl, context_die)
6760 register dw_die_ref context_die;
6762 register tree origin = decl_ultimate_origin (decl);
6763 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
6764 dw_die_ref old_die = lookup_decl_die (decl);
6768 add_abstract_origin_attribute (var_die, origin);
6772 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
6774 add_AT_die_ref (var_die, DW_AT_specification, old_die);
6775 if (DECL_NAME (decl))
6777 register unsigned file_index
6778 = lookup_filename (DECL_SOURCE_FILE (decl));
6779 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
6780 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
6781 if (get_AT_unsigned (old_die, DW_AT_decl_line)
6782 != DECL_SOURCE_LINE (decl))
6784 (var_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
6789 add_name_and_src_coords_attributes (var_die, decl);
6790 add_type_attribute (var_die, TREE_TYPE (decl),
6791 TREE_READONLY (decl),
6792 TREE_THIS_VOLATILE (decl), context_die);
6793 if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
6795 add_AT_flag (var_die, DW_AT_external, 1);
6798 if (DECL_ABSTRACT (decl))
6800 equate_decl_number_to_die (decl, var_die);
6802 else if (!DECL_EXTERNAL (decl))
6804 if (TREE_STATIC (decl))
6805 equate_decl_number_to_die (decl, var_die);
6806 add_location_or_const_value_attribute (var_die, decl);
6807 add_pubname (decl, var_die);
6809 else if (decl_class_context (decl))
6811 equate_decl_number_to_die (decl, var_die);
6812 add_AT_flag (var_die, DW_AT_declaration, 1);
6816 /* Generate a DIE to represent a label identifier. */
6818 gen_label_die (decl, context_die)
6820 register dw_die_ref context_die;
6822 register tree origin = decl_ultimate_origin (decl);
6823 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
6825 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6828 add_abstract_origin_attribute (lbl_die, origin);
6832 add_name_and_src_coords_attributes (lbl_die, decl);
6834 if (DECL_ABSTRACT (decl))
6836 equate_decl_number_to_die (decl, lbl_die);
6840 insn = DECL_RTL (decl);
6841 if (GET_CODE (insn) == CODE_LABEL)
6843 /* When optimization is enabled (via -O) some parts of the compiler
6844 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
6845 represent source-level labels which were explicitly declared by
6846 the user. This really shouldn't be happening though, so catch
6847 it if it ever does happen. */
6848 if (INSN_DELETED_P (insn))
6850 abort (); /* Should never happen. */
6852 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
6853 (unsigned) INSN_UID (insn));
6854 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
6859 /* Generate a DIE for a lexical block. */
6861 gen_lexical_block_die (stmt, context_die, depth)
6863 register dw_die_ref context_die;
6866 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
6867 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6868 if (!BLOCK_ABSTRACT (stmt))
6870 sprintf (label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
6871 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
6872 sprintf (label, BLOCK_END_LABEL_FMT, next_block_number);
6873 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
6875 decls_for_scope (stmt, stmt_die, depth);
6878 /* Generate a DIE for an inlined subprogram. */
6880 gen_inlined_subroutine_die (stmt, context_die, depth)
6882 register dw_die_ref context_die;
6885 if (!BLOCK_ABSTRACT (stmt))
6887 register dw_die_ref subr_die = new_die (DW_TAG_inlined_subroutine,
6889 char label[MAX_ARTIFICIAL_LABEL_BYTES];
6890 add_abstract_origin_attribute (subr_die, block_ultimate_origin (stmt));
6891 sprintf (label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
6892 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
6893 sprintf (label, BLOCK_END_LABEL_FMT, next_block_number);
6894 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
6895 decls_for_scope (stmt, subr_die, depth);
6896 current_function_has_inlines = 1;
6900 /* Generate a DIE for a field in a record, or structure. */
6902 gen_field_die (decl, context_die)
6904 register dw_die_ref context_die;
6906 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
6907 add_name_and_src_coords_attributes (decl_die, decl);
6908 add_type_attribute (decl_die, member_declared_type (decl),
6909 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
6911 /* If this is a bit field... */
6912 if (DECL_BIT_FIELD_TYPE (decl))
6914 add_byte_size_attribute (decl_die, decl);
6915 add_bit_size_attribute (decl_die, decl);
6916 add_bit_offset_attribute (decl_die, decl);
6918 add_data_member_location_attribute (decl_die, decl);
6921 /* Don't generate either pointer_type DIEs or reference_type DIEs.
6922 Use modified type DIE's instead.
6923 We keep this code here just in case these types of DIEs may be needed to
6924 represent certain things in other languages (e.g. Pascal) someday. */
6926 gen_pointer_type_die (type, context_die)
6928 register dw_die_ref context_die;
6930 register dw_die_ref ptr_die = lookup_type_die (type);
6933 ptr_die = new_die (DW_TAG_pointer_type, context_die);
6934 equate_type_number_to_die (type, ptr_die);
6935 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
6938 /* Don't generate either pointer_type DIEs or reference_type DIEs.
6939 Use modified type DIE's instead.
6940 We keep this code here just in case these types of DIEs may be needed to
6941 represent certain things in other languages (e.g. Pascal) someday. */
6943 gen_reference_type_die (type, context_die)
6945 register dw_die_ref context_die;
6947 register dw_die_ref ref_die = lookup_type_die (type);
6950 ref_die = new_die (DW_TAG_reference_type, context_die);
6951 equate_type_number_to_die (type, ref_die);
6952 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
6955 /* Generate a DIE for a pointer to a member type. */
6957 gen_ptr_to_mbr_type_die (type, context_die)
6959 register dw_die_ref context_die;
6961 register dw_die_ref ptr_die = lookup_type_die (type);
6964 ptr_die = new_die (DW_TAG_ptr_to_member_type, context_die);
6965 equate_type_number_to_die (type, ptr_die);
6966 add_AT_die_ref (ptr_die, DW_AT_containing_type,
6967 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
6968 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
6971 /* Generate the DIE for the compilation unit. */
6973 gen_compile_unit_die (main_input_filename)
6974 register char *main_input_filename;
6977 char *wd = getpwd ();
6979 comp_unit_die = new_die (DW_TAG_compile_unit, NULL);
6981 add_name_attribute (comp_unit_die, main_input_filename);
6985 add_AT_string (comp_unit_die, DW_AT_comp_dir, wd);
6988 sprintf (producer, "%s %s", language_string, version_string);
6990 #ifdef MIPS_DEBUGGING_INFO
6991 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
6992 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
6993 not appear in the producer string, the debugger reaches the conclusion
6994 that the object file is stripped and has no debugging information.
6995 To get the MIPS/SGI debugger to believe that there is debugging
6996 information in the object file, we add a -g to the producer string. */
6997 if (write_symbols != NO_DEBUG)
6999 strcat (producer, " -g");
7004 add_AT_string (comp_unit_die, DW_AT_producer, producer);
7005 if (strcmp (language_string, "GNU C++") == 0)
7007 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C_plus_plus);
7009 else if (strcmp (language_string, "GNU Ada") == 0)
7011 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Ada83);
7013 else if (flag_traditional)
7015 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C);
7019 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C89);
7021 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
7023 add_AT_unsigned (comp_unit_die, DW_AT_macro_info, 0);
7027 /* Generate a DIE for a string type. */
7029 gen_string_type_die (type, context_die)
7031 register dw_die_ref context_die;
7033 register dw_die_ref type_die = lookup_type_die (type);
7036 type_die = new_die (DW_TAG_string_type,
7037 scope_die_for_type (type, context_die));
7038 equate_type_number_to_die (type, type_die);
7040 /* Fudge the string length attribute for now. */
7042 /* TODO: add string length info.
7043 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
7044 bound_representation (upper_bound, 0, 'u'); */
7047 /* Genearate a DIE for a class member. */
7049 gen_member_die (type, context_die)
7051 register dw_die_ref context_die;
7053 register tree normal_member;
7054 register tree first_func_member;
7055 register tree func_member;
7056 /* If this is not an incomplete type, output descriptions of each of its
7057 members. Note that as we output the DIEs necessary to represent the
7058 members of this record or union type, we will also be trying to output
7059 DIEs to represent the *types* of those members. However the `type'
7060 function (above) will specifically avoid generating type DIEs for member
7061 types *within* the list of member DIEs for this (containing) type execpt
7062 for those types (of members) which are explicitly marked as also being
7063 members of this (containing) type themselves. The g++ front- end can
7064 force any given type to be treated as a member of some other
7065 (containing) type by setting the TYPE_CONTEXT of the given (member) type
7066 to point to the TREE node representing the appropriate (containing)
7069 /* First output info about the data members and type members. */
7070 for (normal_member = TYPE_FIELDS (type);
7072 normal_member = TREE_CHAIN (normal_member))
7074 gen_decl_die (normal_member, context_die);
7077 /* Now output info about the function members (if any). */
7078 for (func_member = TYPE_METHODS (type);
7080 func_member = TREE_CHAIN (func_member))
7082 gen_decl_die (func_member, context_die);
7086 /* Generate a DIE for a structure or union type. */
7088 gen_struct_or_union_type_die (type, is_complete, context_die)
7090 register unsigned is_complete;
7091 register dw_die_ref context_die;
7093 register dw_die_ref type_die;
7094 type_die = lookup_type_die (type);
7095 if (type_die == NULL)
7097 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
7098 ? DW_TAG_structure_type : DW_TAG_union_type,
7099 scope_die_for_type (type, context_die));
7100 equate_type_number_to_die (type, type_die);
7101 add_name_attribute (type_die, type_tag (type));
7103 else if (is_complete)
7104 remove_AT (type_die, DW_AT_declaration);
7108 /* If this type has been completed, then give it a byte_size attribute and
7109 then give a list of members. */
7112 /* Prevent infinite recursion in cases where the type of some member of
7113 this type is expressed in terms of this type itself. */
7114 TREE_ASM_WRITTEN (type) = 1;
7115 if (TYPE_SIZE (type))
7117 add_byte_size_attribute (type_die, type);
7118 gen_member_die (type, type_die);
7122 add_AT_flag (type_die, DW_AT_declaration, 1);
7125 /* Generate a DIE for a subroutine _type_. */
7127 gen_subroutine_type_die (type, context_die)
7129 register dw_die_ref context_die;
7131 register tree return_type = TREE_TYPE (type);
7132 register dw_die_ref subr_die = lookup_type_die (type);
7135 subr_die = new_die (DW_TAG_subroutine_type, context_die);
7136 equate_type_number_to_die (type, subr_die);
7137 add_prototyped_attribute (subr_die, type);
7138 add_type_attribute (subr_die, return_type, 0, 0, context_die);
7139 gen_formal_types_die (type, context_die);
7142 /* Generate a DIE for a type definition */
7144 gen_typedef_die (decl, context_die)
7146 register dw_die_ref context_die;
7148 register tree origin = decl_ultimate_origin (decl);
7149 register dw_die_ref type_die;
7150 type_die = new_die (DW_TAG_typedef,
7151 scope_die_for_type (decl, context_die));
7154 add_abstract_origin_attribute (type_die, origin);
7158 add_name_and_src_coords_attributes (type_die, decl);
7159 add_type_attribute (type_die, TREE_TYPE (decl),
7160 TREE_READONLY (decl),
7161 TREE_THIS_VOLATILE (decl),
7164 if (DECL_ABSTRACT (decl))
7166 equate_decl_number_to_die (decl, type_die);
7170 /* Generate a type description DIE. */
7172 gen_type_die (type, context_die)
7174 register dw_die_ref context_die;
7176 register unsigned is_complete;
7177 if (type == 0 || type == error_mark_node)
7182 /* We are going to output a DIE to represent the unqualified version of of
7183 this type (i.e. without any const or volatile qualifiers) so get the
7184 main variant (i.e. the unqualified version) of this type now. */
7185 type = type_main_variant (type);
7187 if (TREE_ASM_WRITTEN (type))
7192 switch (TREE_CODE (type))
7198 case REFERENCE_TYPE:
7199 /* For these types, all that is required is that we output a DIE (or a
7200 set of DIEs) to represent the "basis" type. */
7201 gen_type_die (TREE_TYPE (type), context_die);
7205 /* This code is used for C++ pointer-to-data-member types. */
7206 /* Output a description of the relevant class type. */
7207 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
7208 /* Output a description of the type of the object pointed to. */
7209 gen_type_die (TREE_TYPE (type), context_die);
7210 /* Now output a DIE to represent this pointer-to-data-member type
7212 gen_ptr_to_mbr_type_die (type, context_die);
7216 gen_type_die (TYPE_DOMAIN (type), context_die);
7217 gen_set_type_die (type, context_die);
7221 gen_type_die (TREE_TYPE (type), context_die);
7222 abort (); /* No way to represent these in Dwarf yet! */
7226 /* Force out return type (in case it wasn't forced out already). */
7227 gen_type_die (TREE_TYPE (type), context_die);
7228 gen_subroutine_type_die (type, context_die);
7232 /* Force out return type (in case it wasn't forced out already). */
7233 gen_type_die (TREE_TYPE (type), context_die);
7234 gen_subroutine_type_die (type, context_die);
7238 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
7240 gen_type_die (TREE_TYPE (type), context_die);
7241 gen_string_type_die (type, context_die);
7245 gen_array_type_die (type, context_die);
7252 case QUAL_UNION_TYPE:
7253 /* For a function-scope tagged type, we can always go ahead and output
7254 a Dwarf description of this type right now, even if the type in
7255 question is still incomplete, because if this local type *was* ever
7256 completed anywhere within its scope, that complete definition would
7257 already have been attached to this RECORD_TYPE, UNION_TYPE,
7258 QUAL_UNION_TYPE or ENUMERAL_TYPE node by the time we reach this
7259 point. That's true because of the way the front-end does its
7260 processing of file-scope declarations (of functions and class types)
7261 within which other types might be nested. The C and C++ front-ends
7262 always gobble up such "local scope" things en-mass before they try
7263 to output *any* debugging information for any of the stuff contained
7264 inside them and thus, we get the benefit here of what is (in effect)
7265 a pre-resolution of forward references to tagged types in local
7266 scopes. Note however that for file-scope tagged types we cannot
7267 assume that such pre-resolution of forward references has taken
7268 place. A given file-scope tagged type may appear to be incomplete
7269 when we reach this point, but it may yet be given a full definition
7270 (at file-scope) later on during compilation. In order to avoid
7271 generating a premature (and possibly incorrect) set of Dwarf DIEs
7272 for such (as yet incomplete) file-scope tagged types, we generate
7273 nothing at all for as-yet incomplete file-scope tagged types here
7274 unless we are making our special "finalization" pass for file-scope
7275 things at the very end of compilation. At that time, we will
7276 certainly know as much about each file-scope tagged type as we are
7277 ever going to know, so at that point in time, we can safely generate
7278 correct Dwarf descriptions for these file-scope tagged types. */
7279 is_complete = TYPE_SIZE (type) != 0
7280 || (TYPE_CONTEXT (type) != NULL
7281 && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) != 't')
7283 if (TREE_CODE (type) == ENUMERAL_TYPE)
7285 gen_enumeration_type_die (type, is_complete, context_die);
7289 gen_struct_or_union_type_die (type, is_complete, context_die);
7292 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
7293 it up if it is ever completed. */
7304 /* No DIEs needed for fundamental types. */
7308 /* No Dwarf representation currently defined. */
7315 TREE_ASM_WRITTEN (type) = 1;
7318 /* Generate a DIE for a tagged type instantiation. */
7320 gen_tagged_type_instantiation_die (type, context_die)
7322 register dw_die_ref context_die;
7324 if (type == 0 || type == error_mark_node)
7329 /* We are going to output a DIE to represent the unqualified version of of
7330 this type (i.e. without any const or volatile qualifiers) so make sure
7331 that we have the main variant (i.e. the unqualified version) of this
7333 assert (type == type_main_variant (type));
7334 assert (TREE_ASM_WRITTEN (type));
7336 switch (TREE_CODE (type))
7342 gen_inlined_enumeration_type_die (type, context_die);
7346 gen_inlined_structure_type_die (type, context_die);
7350 case QUAL_UNION_TYPE:
7351 gen_inlined_union_type_die (type, context_die);
7355 abort (); /* Should never happen. */
7359 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
7360 things which are local to the given block. */
7362 gen_block_die (stmt, context_die, depth)
7364 register dw_die_ref context_die;
7367 register int must_output_die = 0;
7368 register tree origin;
7370 register enum tree_code origin_code;
7372 /* Ignore blocks never really used to make RTL. */
7374 if (!stmt || !TREE_USED (stmt))
7379 /* Determine the "ultimate origin" of this block. This block may be an
7380 inlined instance of an inlined instance of inline function, so we have
7381 to trace all of the way back through the origin chain to find out what
7382 sort of node actually served as the original seed for the creation of
7383 the current block. */
7384 origin = block_ultimate_origin (stmt);
7385 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
7387 /* Determine if we need to output any Dwarf DIEs at all to represent this
7389 if (origin_code == FUNCTION_DECL)
7391 /* The outer scopes for inlinings *must* always be represented. We
7392 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
7393 must_output_die = 1;
7397 /* In the case where the current block represents an inlining of the
7398 "body block" of an inline function, we must *NOT* output any DIE for
7399 this block because we have already output a DIE to represent the
7400 whole inlined function scope and the "body block" of any function
7401 doesn't really represent a different scope according to ANSI C
7402 rules. So we check here to make sure that this block does not
7403 represent a "body block inlining" before trying to set the
7404 `must_output_die' flag. */
7405 if (! is_body_block (origin ? origin : stmt))
7407 /* Determine if this block directly contains any "significant"
7408 local declarations which we will need to output DIEs for. */
7409 if (debug_info_level > DINFO_LEVEL_TERSE)
7411 /* We are not in terse mode so *any* local declaration counts
7412 as being a "significant" one. */
7413 must_output_die = (BLOCK_VARS (stmt) != NULL);
7417 /* We are in terse mode, so only local (nested) function
7418 definitions count as "significant" local declarations. */
7419 for (decl = BLOCK_VARS (stmt);
7420 decl != NULL; decl = TREE_CHAIN (decl))
7422 if (TREE_CODE (decl) == FUNCTION_DECL
7423 && DECL_INITIAL (decl))
7425 must_output_die = 1;
7433 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
7434 DIE for any block which contains no significant local declarations at
7435 all. Rather, in such cases we just call `decls_for_scope' so that any
7436 needed Dwarf info for any sub-blocks will get properly generated. Note
7437 that in terse mode, our definition of what constitutes a "significant"
7438 local declaration gets restricted to include only inlined function
7439 instances and local (nested) function definitions. */
7440 if (must_output_die)
7442 if (origin_code == FUNCTION_DECL)
7444 gen_inlined_subroutine_die (stmt, context_die, depth);
7448 gen_lexical_block_die (stmt, context_die, depth);
7452 decls_for_scope (stmt, context_die, depth);
7455 /* Generate all of the decls declared within a given scope and (recursively)
7456 all of it's sub-blocks. */
7458 decls_for_scope (stmt, context_die, depth)
7460 register dw_die_ref context_die;
7464 register tree subblocks;
7465 /* Ignore blocks never really used to make RTL. */
7466 if (!stmt || !TREE_USED (stmt))
7470 if (!BLOCK_ABSTRACT (stmt) && depth > 0)
7472 next_block_number++;
7475 /* Output the DIEs to represent all of the data objects, functions,
7476 typedefs, and tagged types declared directly within this block but not
7477 within any nested sub-blocks. */
7478 for (decl = BLOCK_VARS (stmt);
7479 decl != NULL; decl = TREE_CHAIN (decl))
7481 gen_decl_die (decl, context_die);
7484 /* Output the DIEs to represent all sub-blocks (and the items declared
7485 therein) of this block. */
7486 for (subblocks = BLOCK_SUBBLOCKS (stmt);
7488 subblocks = BLOCK_CHAIN (subblocks))
7490 gen_block_die (subblocks, context_die, depth + 1);
7494 /* Generate Dwarf debug information for a decl described by DECL. */
7496 gen_decl_die (decl, context_die)
7498 register dw_die_ref context_die;
7500 register tree origin;
7501 /* Make a note of the decl node we are going to be working on. We may need
7502 to give the user the source coordinates of where it appeared in case we
7503 notice (later on) that something about it looks screwy. */
7504 dwarf_last_decl = decl;
7506 if (TREE_CODE (decl) == ERROR_MARK)
7511 /* If this ..._DECL node is marked to be ignored, then ignore it. But don't
7512 ignore a function definition, since that would screw up our count of
7513 blocks, and that it turn will completely screw up the the labels we will
7514 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
7515 subsequent blocks). */
7516 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
7521 push_decl_scope (DECL_CONTEXT (decl));
7522 switch (TREE_CODE (decl))
7525 /* The individual enumerators of an enum type get output when we output
7526 the Dwarf representation of the relevant enum type itself. */
7530 /* If we are in terse mode, don't output any DIEs to represent mere
7531 function declarations, unless they are class members. */
7532 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE)
7537 /* Before we describe the FUNCTION_DECL itself, make sure that we have
7538 described its return type. */
7539 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
7541 /* Now output a DIE to represent the function itself. */
7542 gen_subprogram_die (decl, context_die);
7546 /* If we are in terse mode, don't generate any DIEs to represent any
7547 actual typedefs. Note that even when we are in terse mode, we must
7548 still output DIEs to represent those tagged types which are used
7549 (directly or indirectly) in the specification of either a return
7550 type or a formal parameter type of some function. */
7551 if (debug_info_level <= DINFO_LEVEL_TERSE)
7553 if (DECL_NAME (decl) != NULL
7554 || !TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
7560 /* In the special case of a null-named TYPE_DECL node (representing the
7561 declaration of some type tag), if the given TYPE_DECL is marked as
7562 having been instantiated from some other (original) TYPE_DECL node
7563 (e.g. one which was generated within the original definition of an
7564 inline function) we have to generate a special (abbreviated)
7565 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration-type
7567 if (!DECL_NAME (decl) && DECL_ABSTRACT_ORIGIN (decl))
7569 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
7572 gen_type_die (TREE_TYPE (decl), context_die);
7574 /* Note that unlike the gcc front end (which generates a NULL named
7575 TYPE_DECL node for each complete tagged type, each array type, and
7576 each function type node created) the g++ front end generates a
7577 _named_ TYPE_DECL node for each tagged type node created.
7578 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
7579 generate a DW_TAG_typedef DIE for them. */
7580 if (DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
7582 /* Output a DIE to represent the typedef itself. */
7583 gen_typedef_die (decl, context_die);
7588 if (debug_info_level >= DINFO_LEVEL_NORMAL)
7590 gen_label_die (decl, context_die);
7595 /* If we are in terse mode, don't generate any DIEs to represent any
7596 variable declarations or definitions. */
7597 if (debug_info_level <= DINFO_LEVEL_TERSE)
7602 /* Output any DIEs that are needed to specify the type of this data
7604 gen_type_die (TREE_TYPE (decl), context_die);
7606 /* Now output the DIE to represent the data object itself. This gets
7607 complicated because of the possibility that the VAR_DECL really
7608 represents an inlined instance of a formal parameter for an inline
7610 origin = decl_ultimate_origin (decl);
7611 if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
7613 gen_formal_parameter_die (decl, context_die);
7617 gen_variable_die (decl, context_die);
7622 /* Ignore the nameless fields that are used to skip bits. */
7623 if (DECL_NAME (decl) != 0)
7625 gen_type_die (member_declared_type (decl), context_die);
7626 gen_field_die (decl, context_die);
7631 gen_type_die (TREE_TYPE (decl), context_die);
7632 gen_formal_parameter_die (decl, context_die);
7641 /***************** Debug Information Generation Hooks ***********************/
7643 dwarfout_file_scope_decl (decl, set_finalizing)
7645 register int set_finalizing;
7647 if (TREE_CODE (decl) == ERROR_MARK)
7652 /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta
7653 hope that the node in question doesn't represent a function definition.
7654 If it does, then totally ignoring it is bound to screw up our count of
7655 blocks, and that it turn will completely screw up the the labels we will
7656 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
7657 subsequent blocks). (It's too bad that BLOCK nodes don't carry their
7658 own sequence numbers with them!) */
7659 if (DECL_IGNORED_P (decl))
7661 if (TREE_CODE (decl) == FUNCTION_DECL
7662 && DECL_INITIAL (decl) != NULL)
7669 switch (TREE_CODE (decl))
7672 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
7673 builtin function. Explicit programmer-supplied declarations of
7674 these same functions should NOT be ignored however. */
7675 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
7680 /* What we would really like to do here is to filter out all mere
7681 file-scope declarations of file-scope functions which are never
7682 referenced later within this translation unit (and keep all of ones
7683 that *are* referenced later on) but we aren't clarvoiant, so we have
7684 no idea which functions will be referenced in the future (i.e. later
7685 on within the current translation unit). So here we just ignore all
7686 file-scope function declarations which are not also definitions. If
7687 and when the debugger needs to know something about these funcstion,
7688 it wil have to hunt around and find the DWARF information associated
7689 with the definition of the function. Note that we can't just check
7690 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
7691 definitions and which ones represent mere declarations. We have to
7692 check `DECL_INITIAL' instead. That's because the C front-end
7693 supports some weird semantics for "extern inline" function
7694 definitions. These can get inlined within the current translation
7695 unit (an thus, we need to generate DWARF info for their abstract
7696 instances so that the DWARF info for the concrete inlined instances
7697 can have something to refer to) but the compiler never generates any
7698 out-of-lines instances of such things (despite the fact that they
7699 *are* definitions). The important point is that the C front-end
7700 marks these "extern inline" functions as DECL_EXTERNAL, but we need
7701 to generate DWARf for them anyway. Note that the C++ front-end also
7702 plays some similar games for inline function definitions appearing
7703 within include files which also contain
7704 `#pragma interface' pragmas. */
7705 if (DECL_INITIAL (decl) == NULL_TREE)
7712 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
7713 declaration and if the declaration was never even referenced from
7714 within this entire compilation unit. We suppress these DIEs in
7715 order to save space in the .debug section (by eliminating entries
7716 which are probably useless). Note that we must not suppress
7717 block-local extern declarations (whether used or not) because that
7718 would screw-up the debugger's name lookup mechanism and cause it to
7719 miss things which really ought to be in scope at a given point. */
7720 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
7725 /* If we are in terse mode, don't generate any DIEs to represent any
7726 variable declarations or definitions. */
7727 if (debug_info_level <= DINFO_LEVEL_TERSE)
7734 /* Don't bother trying to generate any DIEs to represent any of the
7735 normal built-in types for the language we are compiling, except in
7736 cases where the types in question are *not* DWARF fundamental types.
7737 We make an exception in the case of non-fundamental types for the
7738 sake of objective C (and perhaps C++) because the GNU front-ends for
7739 these languages may in fact create certain "built-in" types which
7740 are (for example) RECORD_TYPEs. In such cases, we really need to
7741 output these (non-fundamental) types because other DIEs may contain
7742 references to them. */
7743 if (DECL_SOURCE_LINE (decl) == 0
7744 && is_base_type (TREE_TYPE (decl)))
7749 /* If we are in terse mode, don't generate any DIEs to represent any
7750 actual typedefs. Note that even when we are in terse mode, we must
7751 still output DIEs to represent those tagged types which are used
7752 (directly or indirectly) in the specification of either a return
7753 type or a formal parameter type of some function. */
7754 if (debug_info_level <= DINFO_LEVEL_TERSE)
7756 if (DECL_NAME (decl) != NULL
7757 || !TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
7768 finalizing = set_finalizing;
7769 gen_decl_die (decl, comp_unit_die);
7771 if (TREE_CODE (decl) == FUNCTION_DECL
7772 && DECL_INITIAL (decl) != NULL)
7774 current_funcdef_number++;
7779 /* Output a marker (i.e. a label) for the beginning of the generated code for
7782 dwarfout_begin_block (blocknum)
7783 register unsigned blocknum;
7785 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7787 function_section (current_function_decl);
7788 sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
7789 ASM_OUTPUT_LABEL (asm_out_file, label);
7792 /* Output a marker (i.e. a label) for the end of the generated code for a
7795 dwarfout_end_block (blocknum)
7796 register unsigned blocknum;
7798 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7800 function_section (current_function_decl);
7801 sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
7802 ASM_OUTPUT_LABEL (asm_out_file, label);
7805 /* Output a marker (i.e. a label) at a point in the assembly code which
7806 corresponds to a given source level label. */
7808 dwarfout_label (insn)
7811 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7812 if (debug_info_level >= DINFO_LEVEL_NORMAL)
7814 function_section (current_function_decl);
7815 sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
7816 (unsigned) INSN_UID (insn));
7817 ASM_OUTPUT_LABEL (asm_out_file, label);
7821 /* Output a marker (i.e. a label) for the beginning of a function, before
7824 dwarfout_begin_prologue ()
7826 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7827 register dw_fde_ref fde;
7828 register dw_cfi_ref cfi;
7830 function_section (current_function_decl);
7831 sprintf (label, FUNC_BEGIN_LABEL_FMT, current_funcdef_number);
7832 ASM_OUTPUT_LABEL (asm_out_file, label);
7834 /* Expand the fde table if necessary. */
7835 if (fde_table_in_use == fde_table_allocated)
7837 fde_table_allocated += FDE_TABLE_INCREMENT;
7838 fde_table = (dw_fde_ref) xrealloc (fde_table,
7839 fde_table_allocated * sizeof (dw_fde_node));
7842 /* Record the FDE associated with this function. */
7843 current_funcdef_fde = fde_table_in_use;
7845 /* Add the new FDE at the end of the fde_table. */
7846 fde = &fde_table[fde_table_in_use++];
7847 if (DECL_WEAK (current_function_decl)
7848 || DECL_ONE_ONLY (current_function_decl))
7849 fde->dw_fde_begin = xstrdup (label);
7851 fde->dw_fde_begin = xstrdup (decl_start_label (current_function_decl));
7852 fde->dw_fde_end_prolog = NULL;
7853 fde->dw_fde_begin_epilogue = NULL;
7854 fde->dw_fde_end = NULL;
7855 fde->dw_fde_cfi = NULL;
7858 /* Output a marker (i.e. a label) for the point in the generated code where
7859 the real body of the function begins (after parameters have been moved to
7860 their home locations). */
7862 dwarfout_begin_function ()
7864 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7865 register long int offset;
7866 register dw_fde_ref fde;
7867 register dw_cfi_ref cfi;
7869 function_section (current_function_decl);
7870 sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
7871 ASM_OUTPUT_LABEL (asm_out_file, label);
7873 /* Record the end-of-prolog location in the FDE. */
7874 fde = &fde_table[fde_table_in_use - 1];
7875 fde->dw_fde_end_prolog = xstrdup (label);
7877 #ifdef MIPS_DEBUGGING_INFO
7879 /* On entry, the Call Frame Address is in the stack pointer register. */
7881 cfi->dw_cfi_opc = DW_CFA_def_cfa;
7882 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = STACK_POINTER_REGNUM;
7883 cfi->dw_cfi_oprnd2.dw_cfi_offset = 0;
7884 add_cfi (&fde->dw_fde_cfi, cfi);
7886 /* Set the location counter to the end of the function prolog. */
7888 cfi->dw_cfi_opc = DW_CFA_advance_loc4;
7889 cfi->dw_cfi_oprnd1.dw_cfi_addr = xstrdup (label);
7890 add_cfi (&fde->dw_fde_cfi, cfi);
7892 /* Define the CFA as either an explicit frame pointer register,
7893 or an offset from the stack pointer. */
7895 cfi->dw_cfi_opc = DW_CFA_def_cfa;
7896 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = (frame_pointer_needed)
7897 ? FRAME_POINTER_REGNUM
7898 : STACK_POINTER_REGNUM;
7899 offset = current_frame_info.total_size;
7900 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
7901 add_cfi (&fde->dw_fde_cfi, cfi);
7903 /* record the frame size for later definition of the DW_AT_frame_base
7905 current_funcdef_frame_size = offset;
7907 /* Define the rule for restoring the stack pointer. */
7908 if (frame_pointer_needed)
7910 /* Restore the stack register from the frame pointer. */
7912 cfi->dw_cfi_opc = DW_CFA_register;
7913 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = STACK_POINTER_REGNUM;
7914 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = FRAME_POINTER_REGNUM;
7915 add_cfi (&fde->dw_fde_cfi, cfi);
7918 /* If RA is saved on the stack, define it here. */
7919 if (regs_ever_live[31])
7921 offset = current_frame_info.gp_save_offset / DWARF_CIE_DATA_ALIGNMENT;
7922 assert (offset >= 0);
7924 cfi->dw_cfi_opc = DW_CFA_offset_extended;
7925 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DW_FRAME_RA_COL;
7926 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
7927 add_cfi (&fde->dw_fde_cfi, cfi);
7930 /* If FP is saved on the stack, define it here. */
7931 if (current_frame_info.mask & (1 << 30))
7933 offset = (current_frame_info.gp_save_offset
7934 - (((current_frame_info.mask >> 31) & 1) * UNITS_PER_WORD))
7935 / DWARF_CIE_DATA_ALIGNMENT;
7936 assert (offset >= 0);
7938 cfi->dw_cfi_opc = DW_CFA_offset;
7939 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = FRAME_POINTER_REGNUM;
7940 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
7941 add_cfi (&fde->dw_fde_cfi, cfi);
7948 /* Output a marker (i.e. a label) for the point in the generated code where
7949 the real body of the function ends (just before the epilogue code). */
7951 dwarfout_end_function ()
7954 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7955 function_section (current_function_decl);
7956 sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
7957 ASM_OUTPUT_LABEL (asm_out_file, label);
7958 /* Record the ending code location in the FDE. */
7959 fde = &fde_table[fde_table_in_use - 1];
7960 fde->dw_fde_begin_epilogue = xstrdup(label);
7963 /* Output a marker (i.e. a label) for the absolute end of the generated code
7964 for a function definition. This gets called *after* the epilogue code has
7967 dwarfout_end_epilogue ()
7970 char label[MAX_ARTIFICIAL_LABEL_BYTES];
7971 /* Output a label to mark the endpoint of the code generated for this
7973 sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
7974 ASM_OUTPUT_LABEL (asm_out_file, label);
7975 fde = &fde_table[fde_table_in_use - 1];
7976 fde->dw_fde_end = xstrdup (label);
7979 /* Lookup a filename (in the list of filenames that we know about here in
7980 dwarfout.c) and return its "index". The index of each (known) filename is
7981 just a unique number which is associated with only that one filename.
7982 We need such numbers for the sake of generating labels
7983 (in the .debug_sfnames section) and references to those
7984 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
7985 If the filename given as an argument is not found in our current list,
7986 add it to the list and assign it the next available unique index number.
7987 In order to speed up searches, we remember the index of the filename
7988 was looked up last. This handles the majority of all searches. */
7990 lookup_filename (file_name)
7993 static unsigned last_file_lookup_index = 0;
7995 register unsigned i;
7997 /* Check to see if the file name that was searched on the previous call
7998 matches this file name. If so, return the index. */
7999 if (last_file_lookup_index != 0)
8001 fn = file_table[last_file_lookup_index];
8002 if (strcmp (file_name, fn) == 0)
8004 return last_file_lookup_index;
8008 /* Didn't match the previous lookup, search the table */
8009 for (i = 1; i < file_table_in_use; ++i)
8012 if (strcmp (file_name, fn) == 0)
8014 last_file_lookup_index = i;
8019 /* Prepare to add a new table entry by making sure there is enough space in
8020 the table to do so. If not, expand the current table. */
8021 if (file_table_in_use == file_table_allocated)
8023 file_table_allocated += FILE_TABLE_INCREMENT;
8026 xrealloc (file_table, file_table_allocated * sizeof (char *));
8029 /* add the new entry to the end of the filename table. */
8030 file_table[file_table_in_use] = xstrdup (file_name);
8031 last_file_lookup_index = file_table_in_use++;
8032 return last_file_lookup_index;
8035 /* Output a label to mark the beginning of a source code line entry
8036 and record information relating to this source line, in
8037 'line_info_table' for later output of the .debug_line section. */
8039 dwarfout_line (filename, line)
8040 register char *filename;
8041 register unsigned line;
8043 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8044 register unsigned this_file_entry_num = lookup_filename (filename);
8045 if (debug_info_level >= DINFO_LEVEL_NORMAL)
8047 function_section (current_function_decl);
8049 if (DECL_SECTION_NAME (current_function_decl))
8051 register dw_separate_line_info_ref line_info;
8052 sprintf (label, SEPARATE_LINE_CODE_LABEL_FMT,
8053 separate_line_info_table_in_use);
8054 ASM_OUTPUT_LABEL (asm_out_file, label);
8055 fputc ('\n', asm_out_file);
8057 /* expand the line info table if necessary */
8058 if (separate_line_info_table_in_use
8059 == separate_line_info_table_allocated)
8061 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
8062 separate_line_info_table
8063 = (dw_separate_line_info_ref) xrealloc
8064 (separate_line_info_table,
8065 separate_line_info_table_allocated
8066 * sizeof (dw_separate_line_info_entry));
8068 /* add the new entry at the end of the line_info_table. */
8070 = &separate_line_info_table[separate_line_info_table_in_use++];
8071 line_info->dw_file_num = lookup_filename (filename);
8072 line_info->dw_line_num = line;
8073 line_info->function = current_funcdef_number;
8077 register dw_line_info_ref line_info;
8078 sprintf (label, LINE_CODE_LABEL_FMT, line_info_table_in_use);
8079 ASM_OUTPUT_LABEL (asm_out_file, label);
8080 fputc ('\n', asm_out_file);
8082 /* expand the line info table if necessary */
8083 if (line_info_table_in_use == line_info_table_allocated)
8085 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
8087 = (dw_line_info_ref) xrealloc
8089 line_info_table_allocated * sizeof (dw_line_info_entry));
8091 /* add the new entry at the end of the line_info_table. */
8092 line_info = &line_info_table[line_info_table_in_use++];
8093 line_info->dw_file_num = lookup_filename (filename);
8094 line_info->dw_line_num = line;
8099 /* Record the beginning of a new source file, for later output
8100 of the .debug_macinfo section. At present, unimplemented. */
8102 dwarfout_start_new_source_file (filename)
8103 register char *filename;
8107 /* Record the resumption of a source file, for later output
8108 of the .debug_macinfo section. At present, unimplemented. */
8110 dwarfout_resume_previous_source_file (lineno)
8111 register unsigned lineno;
8115 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
8116 the tail part of the directive line, i.e. the part which is past the
8117 initial whitespace, #, whitespace, directive-name, whitespace part. */
8119 dwarfout_define (lineno, buffer)
8120 register unsigned lineno;
8121 register char *buffer;
8123 static int initialized = 0;
8126 dwarfout_start_new_source_file (primary_filename);
8131 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
8132 the tail part of the directive line, i.e. the part which is past the
8133 initial whitespace, #, whitespace, directive-name, whitespace part. */
8135 dwarfout_undef (lineno, buffer)
8136 register unsigned lineno;
8137 register char *buffer;
8141 /* Set up for Dwarf output at the start of compilation. */
8143 dwarfout_init (asm_out_file, main_input_filename)
8144 register FILE *asm_out_file;
8145 register char *main_input_filename;
8148 /* Remember the name of the primary input file. */
8149 primary_filename = main_input_filename;
8151 /* Allocate the initial hunk of the file_table. */
8152 file_table = (char **) xmalloc (FILE_TABLE_INCREMENT * sizeof (char *));
8153 bzero (file_table, FILE_TABLE_INCREMENT * sizeof (char *));
8154 file_table_allocated = FILE_TABLE_INCREMENT;
8155 /* skip the first entry - file numbers begin at 1 */
8156 file_table_in_use = 1;
8158 /* Allocate the initial hunk of the type_die_table. */
8160 = (dw_die_ref *) xmalloc (TYPE_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
8161 bzero (type_die_table, TYPE_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
8162 type_die_table_allocated = TYPE_DIE_TABLE_INCREMENT;
8163 type_die_table_in_use = 0;
8165 /* Allocate the initial hunk of the decl_die_table. */
8167 = (dw_die_ref *) xmalloc (DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
8168 bzero (decl_die_table, DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
8169 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
8170 decl_die_table_in_use = 0;
8172 /* Allocate the initial hunk of the decl_scope_table. */
8174 = (tree *) xmalloc (DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
8175 bzero (decl_scope_table, DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
8176 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
8177 decl_scope_depth = 0;
8179 /* Allocate the initial hunk of the abbrev_die_table. */
8181 = (dw_die_ref *) xmalloc (ABBREV_DIE_TABLE_INCREMENT
8182 * sizeof (dw_die_ref));
8183 bzero (abbrev_die_table, ABBREV_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
8184 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
8185 /* zero-th entry is allocated, but unused */
8186 abbrev_die_table_in_use = 1;
8188 /* Allocate the initial hunk of the line_info_table. */
8190 = (dw_line_info_ref) xmalloc (LINE_INFO_TABLE_INCREMENT
8191 * sizeof (dw_line_info_entry));
8192 bzero (line_info_table, LINE_INFO_TABLE_INCREMENT
8193 * sizeof (dw_line_info_entry));
8194 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
8195 /* zero-th entry is allocated, but unused */
8196 line_info_table_in_use = 1;
8198 /* Allocate the initial hunk of the fde_table. */
8199 fde_table = (dw_fde_ref) xmalloc (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
8200 bzero (fde_table, FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
8201 fde_table_allocated = FDE_TABLE_INCREMENT;
8202 fde_table_in_use = 0;
8205 /* Output a starting label for the .text section. */
8206 fputc ('\n', asm_out_file);
8207 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
8208 ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
8210 /* Output a starting label for the .data section. */
8211 fputc ('\n', asm_out_file);
8212 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
8213 ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
8215 /* Output a starting label for the .rodata section. */
8216 fputc ('\n', asm_out_file);
8217 ASM_OUTPUT_SECTION (asm_out_file, RODATA_SECTION);
8218 ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
8220 /* Output a starting label for the .bss section. */
8221 fputc ('\n', asm_out_file);
8222 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
8223 ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
8226 /* Generate the initial DIE for the .debug section. Note that the (string)
8227 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
8228 will (typically) be a relative pathname and that this pathname should be
8229 taken as being relative to the directory from which the compiler was
8230 invoked when the given (base) source file was compiled. */
8231 gen_compile_unit_die (main_input_filename);
8233 /* clear the association between base types and their DIE's */
8234 init_base_type_table ();
8237 /* Output stuff that dwarf requires at the end of every file,
8238 and generate the DWARF-2 debugging info. */
8242 /* Traverse the DIE tree and add sibling attributes to those DIE's
8243 that have children. */
8244 add_sibling_attributes (comp_unit_die);
8246 /* Output a terminator label for the .text section. */
8247 fputc ('\n', asm_out_file);
8248 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
8249 ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
8252 /* Output a terminator label for the .data section. */
8253 fputc ('\n', asm_out_file);
8254 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
8255 ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
8257 /* Output a terminator label for the .rodata section. */
8258 fputc ('\n', asm_out_file);
8259 ASM_OUTPUT_SECTION (asm_out_file, RODATA_SECTION);
8260 ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
8262 /* Output a terminator label for the .bss section. */
8263 fputc ('\n', asm_out_file);
8264 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
8265 ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
8268 /* Output the source line correspondence table. */
8269 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
8271 fputc ('\n', asm_out_file);
8272 ASM_OUTPUT_SECTION (asm_out_file, LINE_SECTION);
8273 output_line_info ();
8275 /* We can only use the low/high_pc attributes if all of the code
8277 if (separate_line_info_table_in_use == 0)
8279 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, TEXT_SECTION);
8280 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, TEXT_END_LABEL);
8282 add_AT_section_offset (comp_unit_die, DW_AT_stmt_list, LINE_SECTION);
8285 /* Output the abbreviation table. */
8286 fputc ('\n', asm_out_file);
8287 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
8288 build_abbrev_table (comp_unit_die);
8289 output_abbrev_section ();
8291 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8292 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8293 calc_die_sizes (comp_unit_die);
8295 /* Initialize the beginning FDE offset - and calculate sizes/offsets. */
8296 next_fde_offset = DWARF_CIE_SIZE;
8299 /* Output debugging information. */
8300 fputc ('\n', asm_out_file);
8301 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_SECTION);
8302 output_compilation_unit_header ();
8303 output_die (comp_unit_die);
8305 if (pubname_table_in_use)
8307 /* Output public names table. */
8308 fputc ('\n', asm_out_file);
8309 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
8313 if (fde_table_in_use)
8315 /* Output call frame information. */
8316 fputc ('\n', asm_out_file);
8317 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
8318 output_call_frame_info ();
8320 /* Output the address range information. */
8321 fputc ('\n', asm_out_file);
8322 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
8326 #endif /* DWARF_DEBUGGING_INFO && DWARF_VERSION == 2 */