1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
3 Contributed by Gary Funck (gary@intrepid.com). Derived from the
4 DWARF 1 implementation written by Ron Guilmette (rfg@monkeys.com).
5 Extensively modified by Jason Merrill (jason@cygnus.com).
7 This file is part of GNU CC.
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #ifdef DWARF2_DEBUGGING_INFO
32 #include "hard-reg-set.h"
34 #include "insn-config.h"
40 /* #define NDEBUG 1 */
43 extern char *getpwd ();
45 /* NOTE: In the comments in this file, many references are made to
46 "Debugging Information Entries". This term is abbreviated as `DIE'
47 throughout the remainder of this file. */
53 /* An internal representation of the DWARF output is built, and then
54 walked to generate the DWARF debugging info. The walk of the internal
55 representation is done after the entire program has been compiled.
56 The types below are used to describe the internal representation. */
58 /* Each DIE may have a series of attribute/value pairs. Values
59 can take on several forms. The forms that are used in this
60 implementation are listed below. */
67 dw_val_class_unsigned_const,
68 dw_val_class_long_long,
74 dw_val_class_section_offset,
79 /* Various DIE's use offsets relative to the beginning of the
80 .debug_info section to refer to each other. */
82 typedef long int dw_offset;
84 /* Define typedefs here to avoid circular dependencies. */
86 typedef struct die_struct *dw_die_ref;
87 typedef struct dw_attr_struct *dw_attr_ref;
88 typedef struct dw_val_struct *dw_val_ref;
89 typedef struct dw_line_info_struct *dw_line_info_ref;
90 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
91 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
92 typedef struct dw_cfi_struct *dw_cfi_ref;
93 typedef struct dw_fde_struct *dw_fde_ref;
94 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
95 typedef struct pubname_struct *pubname_ref;
96 typedef dw_die_ref *arange_ref;
98 /* Describe a double word constant value. */
100 typedef struct dw_long_long_struct
107 /* Describe a floating point constant value. */
109 typedef struct dw_fp_struct
116 /* Each entry in the line_info_table maintains the file and
117 line nuber associated with the label generated for that
118 entry. The label gives the PC value associated with
119 the line number entry. */
121 typedef struct dw_line_info_struct
123 unsigned long dw_file_num;
124 unsigned long dw_line_num;
128 /* Line information for functions in separate sections; each one gets its
130 typedef struct dw_separate_line_info_struct
132 unsigned long dw_file_num;
133 unsigned long dw_line_num;
134 unsigned long function;
136 dw_separate_line_info_entry;
138 /* The dw_val_node describes an attibute's value, as it is
139 represented internally. */
141 typedef struct dw_val_struct
143 dw_val_class val_class;
147 dw_loc_descr_ref val_loc;
149 long unsigned val_unsigned;
150 dw_long_long_const val_long_long;
151 dw_float_const val_float;
152 dw_die_ref val_die_ref;
153 unsigned val_fde_index;
157 unsigned char val_flag;
163 /* Locations in memory are described using a sequence of stack machine
166 typedef struct dw_loc_descr_struct
168 dw_loc_descr_ref dw_loc_next;
169 enum dwarf_location_atom dw_loc_opc;
170 dw_val_node dw_loc_oprnd1;
171 dw_val_node dw_loc_oprnd2;
175 /* Each DIE attribute has a field specifying the attribute kind,
176 a link to the next attribute in the chain, and an attribute value.
177 Attributes are typically linked below the DIE they modify. */
179 typedef struct dw_attr_struct
181 enum dwarf_attribute dw_attr;
182 dw_attr_ref dw_attr_next;
183 dw_val_node dw_attr_val;
187 /* Call frames are described using a sequence of Call Frame
188 Information instructions. The register number, offset
189 and address fields are provided as possible operands;
190 their use is selected by the opcode field. */
192 typedef union dw_cfi_oprnd_struct
194 unsigned long dw_cfi_reg_num;
195 long int dw_cfi_offset;
200 typedef struct dw_cfi_struct
202 dw_cfi_ref dw_cfi_next;
203 enum dwarf_call_frame_info dw_cfi_opc;
204 dw_cfi_oprnd dw_cfi_oprnd1;
205 dw_cfi_oprnd dw_cfi_oprnd2;
209 /* All call frame descriptions (FDE's) in the GCC generated DWARF
210 refer to a single Common Information Entry (CIE), defined at
211 the beginning of the .debug_frame section. This used of a single
212 CIE obviates the need to keep track of multiple CIE's
213 in the DWARF generation routines below. */
215 typedef struct dw_fde_struct
217 unsigned long dw_fde_offset;
219 char *dw_fde_current_label;
221 dw_cfi_ref dw_fde_cfi;
225 /* The Debugging Information Entry (DIE) structure */
227 typedef struct die_struct
229 enum dwarf_tag die_tag;
230 dw_attr_ref die_attr;
231 dw_attr_ref die_attr_last;
232 dw_die_ref die_parent;
233 dw_die_ref die_child;
234 dw_die_ref die_child_last;
236 dw_offset die_offset;
237 unsigned long die_abbrev;
241 /* 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 a TYPE_DECL which was
256 implicitly generated for a tagged type.
258 Note that unlike the gcc front end (which generates a NULL named
259 TYPE_DECL node for each complete tagged type, each array type, and
260 each function type node created) the g++ front end generates a
261 _named_ TYPE_DECL node for each tagged type node created.
262 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
263 generate a DW_TAG_typedef DIE for them. */
265 #define TYPE_DECL_IS_STUB(decl) \
266 (DECL_NAME (decl) == NULL_TREE \
267 || (DECL_ARTIFICIAL (decl) \
268 && is_tagged_type (TREE_TYPE (decl)) \
269 && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
271 /* Information concerning the compilation unit's programming
272 language, and compiler version. */
274 extern int flag_traditional;
275 extern char *version_string;
276 extern char *language_string;
278 /* Maximum size (in bytes) of an artificially generated label. */
279 #define MAX_ARTIFICIAL_LABEL_BYTES 30
281 /* Make sure we know the sizes of the various types dwarf can describe. These
282 are only defaults. If the sizes are different for your target, you should
283 override these values by defining the appropriate symbols in your tm.h
286 #ifndef CHAR_TYPE_SIZE
287 #define CHAR_TYPE_SIZE BITS_PER_UNIT
290 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
293 /* The size in bytes of a DWARF field indicating an offset or length
294 relative to a debug info section, specified to be 4 bytes in the DWARF-2
295 specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */
297 #ifndef DWARF_OFFSET_SIZE
298 #define DWARF_OFFSET_SIZE 4
301 #define DWARF_VERSION 2
303 /* Fixed size portion of the DWARF compilation unit header. */
304 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
306 /* Fixed size portion of debugging line information prolog. */
307 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
309 /* Fixed size portion of public names info. */
310 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
312 /* Round SIZE up to the nearest BOUNDARY. */
313 #define DWARF_ROUND(SIZE,BOUNDARY) \
314 (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
316 /* Fixed size portion of the address range info. */
317 #define DWARF_ARANGES_HEADER_SIZE \
318 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
320 /* Fixed size portion of the CIE (including the length field). */
321 #define DWARF_CIE_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 5)
323 /* The un-padded size of the CIE. Initialized in calc_fde_sizes, used
324 in output_call_frame_info. */
325 static unsigned cie_size;
327 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
328 #ifdef STACK_GROWS_DOWNWARD
329 #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD)
331 #define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD
334 /* Fixed size portion of the FDE. */
335 #define DWARF_FDE_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2 * PTR_SIZE)
337 /* Define the architecture-dependent minimum instruction length (in bytes).
338 In this implementation of DWARF, this field is used for information
339 purposes only. Since GCC generates assembly language, we have
340 no a priori knowledge of how many instruction bytes are generated
341 for each source line, and therefore can use only the DW_LNE_set_address
342 and DW_LNS_fixed_advance_pc line information commands. */
344 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
345 #define DWARF_LINE_MIN_INSTR_LENGTH 4
348 /* Minimum line offset in a special line info. opcode.
349 This value was chosen to give a reasonable range of values. */
350 #define DWARF_LINE_BASE -10
352 /* First special line opcde - leave room for the standard opcodes. */
353 #define DWARF_LINE_OPCODE_BASE 10
355 /* Range of line offsets in a special line info. opcode. */
356 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
358 /* Flag that indicates the initial value of the is_stmt_start flag.
359 In the present implementation, we do not mark any lines as
360 the beginning of a source statement, because that information
361 is not made available by the GCC front-end. */
362 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
364 /* This location is used by calc_die_sizes() to keep track
365 the offset of each DIE within the .debug_info section. */
366 static unsigned long next_die_offset;
368 /* This location is used by calc_fde_sizes() to keep track
369 the offset of each FDE within the .debug_frame section. */
370 static unsigned long next_fde_offset;
372 /* Record the root of the DIE's built for the current compilation unit. */
373 static dw_die_ref comp_unit_die;
375 /* The number of DIEs with a NULL parent waiting to be relocated. */
376 static int limbo_die_count;
378 /* Pointer to an array of filenames referenced by this compilation unit. */
379 static char **file_table;
381 /* Total number of entries in the table (i.e. array) pointed to by
382 `file_table'. This is the *total* and includes both used and unused
384 static unsigned file_table_allocated;
386 /* Number of entries in the file_table which are actually in use. */
387 static unsigned file_table_in_use;
389 /* Size (in elements) of increments by which we may expand the filename
391 #define FILE_TABLE_INCREMENT 64
393 /* Local pointer to the name of the main input file. Initialized in
395 static char *primary_filename;
397 /* For Dwarf output, we must assign lexical-blocks id numbers in the order in
398 which their beginnings are encountered. We output Dwarf debugging info
399 that refers to the beginnings and ends of the ranges of code for each
400 lexical block. The labels themselves are generated in final.c, which
401 assigns numbers to the blocks in the same way. */
402 static unsigned next_block_number = 2;
404 /* A pointer to the base of a table of references to DIE's that describe
405 declarations. The table is indexed by DECL_UID() which is a unique
406 number, indentifying each decl. */
407 static dw_die_ref *decl_die_table;
409 /* Number of elements currently allocated for the decl_die_table. */
410 static unsigned decl_die_table_allocated;
412 /* Number of elements in decl_die_table currently in use. */
413 static unsigned decl_die_table_in_use;
415 /* Size (in elements) of increments by which we may expand the
417 #define DECL_DIE_TABLE_INCREMENT 256
419 /* A pointer to the base of a table of references to declaration
420 scopes. This table is a display which tracks the nesting
421 of declaration scopes at the current scope and containing
422 scopes. This table is used to find the proper place to
423 define type declaration DIE's. */
424 static tree *decl_scope_table;
426 /* Number of elements currently allocated for the decl_scope_table. */
427 static unsigned decl_scope_table_allocated;
429 /* Current level of nesting of declataion scopes. */
430 static unsigned decl_scope_depth;
432 /* Size (in elements) of increments by which we may expand the
434 #define DECL_SCOPE_TABLE_INCREMENT 64
436 /* A pointer to the base of a list of references to DIE's that
437 are uniquely identified by their tag, presence/absence of
438 children DIE's, and list of attribute/value pairs. */
439 static dw_die_ref *abbrev_die_table;
441 /* Number of elements currently allocated for abbrev_die_table. */
442 static unsigned abbrev_die_table_allocated;
444 /* Number of elements in type_die_table currently in use. */
445 static unsigned abbrev_die_table_in_use;
447 /* Size (in elements) of increments by which we may expand the
449 #define ABBREV_DIE_TABLE_INCREMENT 256
451 /* A pointer to the base of a table that contains line information
452 for each source code line in .text in the compilation unit. */
453 static dw_line_info_ref line_info_table;
455 /* Number of elements currently allocated for line_info_table. */
456 static unsigned line_info_table_allocated;
458 /* Number of elements in separate_line_info_table currently in use. */
459 static unsigned separate_line_info_table_in_use;
461 /* A pointer to the base of a table that contains line information
462 for each source code line outside of .text in the compilation unit. */
463 static dw_separate_line_info_ref separate_line_info_table;
465 /* Number of elements currently allocated for separate_line_info_table. */
466 static unsigned separate_line_info_table_allocated;
468 /* Number of elements in line_info_table currently in use. */
469 static unsigned line_info_table_in_use;
471 /* Size (in elements) of increments by which we may expand the
473 #define LINE_INFO_TABLE_INCREMENT 1024
475 /* A pointer to the base of a table that contains frame description
476 information for each routine. */
477 static dw_fde_ref fde_table;
479 /* Number of elements currently allocated for fde_table. */
480 static unsigned fde_table_allocated;
482 /* Number of elements in fde_table currently in use. */
483 static unsigned fde_table_in_use;
485 /* Size (in elements) of increments by which we may expand the
487 #define FDE_TABLE_INCREMENT 256
489 /* A list of call frame insns for the CIE. */
490 static dw_cfi_ref cie_cfi_head;
492 /* A pointer to the base of a table that contains a list of publicly
494 static pubname_ref pubname_table;
496 /* Number of elements currently allocated for pubname_table. */
497 static unsigned pubname_table_allocated;
499 /* Number of elements in pubname_table currently in use. */
500 static unsigned pubname_table_in_use;
502 /* Size (in elements) of increments by which we may expand the
504 #define PUBNAME_TABLE_INCREMENT 64
506 /* A pointer to the base of a table that contains a list of publicly
508 static arange_ref arange_table;
510 /* Number of elements currently allocated for arange_table. */
511 static unsigned arange_table_allocated;
513 /* Number of elements in arange_table currently in use. */
514 static unsigned arange_table_in_use;
516 /* Size (in elements) of increments by which we may expand the
518 #define ARANGE_TABLE_INCREMENT 64
520 /* A pointer to the base of a list of pending types which we haven't
521 generated DIEs for yet, but which we will have to come back to
524 static tree *pending_types_list;
526 /* Number of elements currently allocated for the pending_types_list. */
527 static unsigned pending_types_allocated;
529 /* Number of elements of pending_types_list currently in use. */
530 static unsigned pending_types;
532 /* Size (in elements) of increments by which we may expand the pending
533 types list. Actually, a single hunk of space of this size should
534 be enough for most typical programs. */
535 #define PENDING_TYPES_INCREMENT 64
537 /* The number of the current function definition for which debugging
538 information is being generated. These numbers range from 1 up to the
539 maximum number of function definitions contained within the current
540 compilation unit. These numbers are used to create unique label id's
541 unique to each function definition. */
542 static unsigned current_funcdef_number = 1;
544 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
545 attribute that accelerates the lookup of the FDE associated
546 with the subprogram. This variable holds the table index of the FDE
547 associated with the current function (body) definition. */
548 static unsigned current_funcdef_fde;
550 /* Record whether the function being analyzed contains inlined functions. */
551 static int current_function_has_inlines;
552 static int comp_unit_has_inlines;
554 /* A pointer to the ..._DECL node which we have most recently been working
555 on. We keep this around just in case something about it looks screwy and
556 we want to tell the user what the source coordinates for the actual
558 static tree dwarf_last_decl;
560 /* Forward declarations for functions defined in this file. */
562 static char *stripattributes PROTO((char *));
563 static void addr_const_to_string PROTO((char *, rtx));
564 static char *addr_to_string PROTO((rtx));
565 static int is_pseudo_reg PROTO((rtx));
566 static tree type_main_variant PROTO((tree));
567 static int is_tagged_type PROTO((tree));
568 static char *dwarf_tag_name PROTO((unsigned));
569 static char *dwarf_attr_name PROTO((unsigned));
570 static char *dwarf_form_name PROTO((unsigned));
571 static char *dwarf_stack_op_name PROTO((unsigned));
572 static char *dwarf_type_encoding_name PROTO((unsigned));
573 static char *dward_cfi_name PROTO((unsigned));
574 static tree decl_ultimate_origin PROTO((tree));
575 static tree block_ultimate_origin PROTO((tree));
576 static tree decl_class_context PROTO((tree));
577 static void add_dwarf_attr PROTO((dw_die_ref, dw_attr_ref));
578 static void add_AT_flag PROTO((dw_die_ref,
579 enum dwarf_attribute,
581 static void add_AT_int PROTO((dw_die_ref,
582 enum dwarf_attribute, long));
583 static void add_AT_unsigned PROTO((dw_die_ref,
584 enum dwarf_attribute,
586 static void add_AT_long_long PROTO((dw_die_ref,
587 enum dwarf_attribute,
588 unsigned long, unsigned long));
589 static void add_AT_float PROTO((dw_die_ref,
590 enum dwarf_attribute,
592 static void add_AT_string PROTO((dw_die_ref,
593 enum dwarf_attribute, char *));
594 static void add_AT_die_ref PROTO((dw_die_ref,
595 enum dwarf_attribute,
597 static void add_AT_fde_ref PROTO((dw_die_ref,
598 enum dwarf_attribute,
600 static void add_AT_loc PROTO((dw_die_ref,
601 enum dwarf_attribute,
603 static void add_AT_addr PROTO((dw_die_ref,
604 enum dwarf_attribute, char *));
605 static void add_AT_lbl_id PROTO((dw_die_ref,
606 enum dwarf_attribute, char *));
607 static void add_AT_setion_offset PROTO((dw_die_ref,
608 enum dwarf_attribute, char *));
609 static int is_extern_subr_die PROTO((dw_die_ref));
610 static dw_attr_ref get_AT PROTO((dw_die_ref,
611 enum dwarf_attribute));
612 static char *get_AT_low_pc PROTO((dw_die_ref));
613 static char *get_AT_hi_pc PROTO((dw_die_ref));
614 static char *get_AT_string PROTO((dw_die_ref,
615 enum dwarf_attribute));
616 static int get_AT_flag PROTO((dw_die_ref,
617 enum dwarf_attribute));
618 static unsigned get_AT_unsigned PROTO((dw_die_ref,
619 enum dwarf_attribute));
620 static int is_c_family PROTO((void));
621 static int is_fortran PROTO((void));
622 static void remove_AT PROTO((dw_die_ref,
623 enum dwarf_attribute));
624 static void remove_children PROTO((dw_die_ref));
625 static void add_child_die PROTO((dw_die_ref, dw_die_ref));
626 static dw_die_ref new_die PROTO((enum dwarf_tag, dw_die_ref));
627 static dw_die_ref lookup_type_die PROTO((tree));
628 static void equate_type_number_to_die PROTO((tree, dw_die_ref));
629 static dw_die_ref lookup_decl_die PROTO((tree));
630 static void equate_decl_number_to_die PROTO((tree, dw_die_ref));
631 static dw_loc_descr_ref new_loc_descr PROTO((enum dwarf_location_atom,
632 unsigned long, unsigned long));
633 static void add_loc_descr PROTO((dw_loc_descr_ref *,
635 static dw_cfi_ref new_cfe PROTO((void));
636 static void add_cfe PROTO((dw_cfi_ref *, dw_cfi_ref));
637 static void print_spaces PROTO((FILE *));
638 static void print_die PROTO((dw_die_ref, FILE *));
639 static void print_dwarf_line_table PROTO((FILE *));
640 static void add_sibling_atttributes PROTO((dw_die_ref));
641 static void build_abbrev_table PROTO((dw_die_ref));
642 static unsigned long size_of_uleb128 PROTO((unsigned long));
643 static unsigned long size_of_sleb128 PROTO((long));
644 static unsigned long size_of_string PROTO((char *));
645 static unsigned long size_of_loc_descr PROTO((dw_loc_descr_ref));
646 static unsigned long size_of_locs PROTO((dw_loc_descr_ref));
647 static int constant_size PROTO((long unsigned));
648 static unsigned long size_of_die PROTO((dw_die_ref));
649 static void calc_die_sizes PROTO((dw_die_ref));
650 static unsigned long size_of_prolog PROTO((void));
651 static unsigned long size_of_line_info PROTO((void));
652 static unsigned long size_of_pubnames PROTO((void));
653 static unsigned long size_of_aranges PROTO((void));
654 static void output_uleb128 PROTO((unsigned long));
655 static void output_sleb128 PROTO((long));
656 static enum dwarf_form value_format PROTO((dw_val_ref));
657 static void output_value_format PROTO((dw_val_ref));
658 static void output_abbrev_section PROTO((void));
659 static void output_loc_operands PROTO((dw_loc_descr_ref));
660 static unsigned long sibling_offset PROTO((dw_die_ref));
661 static void output_die PROTO((dw_die_ref));
662 static void output_compilation_unit_header PROTO((void));
663 static char *dwarf2out_cfi_label PROTO((void));
664 static void add_fde_cfi PROTO((char *, dw_cfi_ref));
665 static void lookup_cfa_1 PROTO((dw_cfi_ref, unsigned long *,
667 static void lookup_cfa PROTO((unsigned long *, long *));
668 static void reg_save PROTO((char *, unsigned, unsigned,
670 static void initial_return_save PROTO((rtx));
671 static unsigned long size_of_cfi PROTO((dw_cfi_ref));
672 static unsigned long size_of_fde PROTO((dw_fde_ref, unsigned long *));
673 static void calc_fde_sizes PROTO((void));
674 static void output_cfi PROTO((dw_cfi_ref, dw_fde_ref));
675 static void output_call_frame_info PROTO((void));
676 static char *dwarf2_name PROTO((tree, int));
677 static void add_pubname PROTO((tree, dw_die_ref));
678 static void output_pubnames PROTO((void));
679 static void add_arrange PROTO((tree, dw_die_ref));
680 static void output_arranges PROTO((void));
681 static void output_line_info PROTO((void));
682 static int is_body_block PROTO((tree));
683 static dw_die_ref base_type_die PROTO((tree));
684 static tree root_type PROTO((tree));
685 static int is_base_type PROTO((tree));
686 static dw_die_ref modified_type_die PROTO((tree, int, int, dw_die_ref));
687 static int type_is_enum PROTO((tree));
688 static unsigned reg_number PROTO((rtx));
689 static dw_loc_descr_ref reg_loc_descr_ref PROTO((rtx));
690 static dw_loc_descr_ref based_loc_descr PROTO((unsigned, long));
691 static int is_based_loc PROTO((rtx));
692 static dw_loc_descr_ref mem_loc_descriptor PROTO((rtx));
693 static dw_loc_descr_ref loc_descriptor PROTO((rtx));
694 static unsigned ceiling PROTO((unsigned, unsigned));
695 static tree field_type PROTO((tree));
696 static unsigned simple_type_align_in_bits PROTO((tree));
697 static unsigned simple_type_size_in_bits PROTO((tree));
698 static unsigned field_byte_offset PROTO((tree));
699 static void add_location_attribute PROTO((dw_die_ref, rtx));
700 static void add_data_member_location_attribute PROTO((dw_die_ref, tree));
701 static void add_const_value_attribute PROTO((dw_die_ref, rtx));
702 static void add_location_or_const_value_attribute PROTO((dw_die_ref, tree));
703 static void add_name_attribute PROTO((dw_die_ref, char *));
704 static void add_bound_info PROTO((dw_die_ref,
705 enum dwarf_attribute, tree));
706 static void add_subscript_info PROTO((dw_die_ref, tree));
707 static void add_byte_size_attribute PROTO((dw_die_ref, tree));
708 static void add_bit_offset_attribute PROTO((dw_die_ref, tree));
709 static void add_bit_size_attribute PROTO((dw_die_ref, tree));
710 static void add_prototyped_attribute PROTO((dw_die_ref, tree));
711 static void add_abstract_origin_attribute PROTO((dw_die_ref, tree));
712 static void add_pure_or_virtual_attribute PROTO((dw_die_ref, tree));
713 static void add_src_coords_attributes PROTO((dw_die_ref, tree));
714 static void ad_name_and_src_coords_attributes PROTO((dw_die_ref, tree));
715 static void push_decl_scope PROTO((tree));
716 static dw_die_ref scope_die_for PROTO((tree, dw_die_ref));
717 static void pop_decl_scope PROTO((void));
718 static void add_type_attribute PROTO((dw_die_ref, tree, int, int,
720 static char *type_tag PROTO((tree));
721 static tree member_declared_type PROTO((tree));
722 static char *decl_start_label PROTO((tree));
723 static void gen_arrqay_type_die PROTO((tree, dw_die_ref));
724 static void gen_set_type_die PROTO((tree, dw_die_ref));
725 static void gen_entry_point_die PROTO((tree, dw_die_ref));
726 static void pend_type PROTO((tree));
727 static void output_pending_types_for_scope PROTO((dw_die_ref));
728 static void gen_inlined_enumeration_type_die PROTO((tree, dw_die_ref));
729 static void gen_inlined_structure_type_die PROTO((tree, dw_die_ref));
730 static void gen_inlined_union_type_die PROTO((tree, dw_die_ref));
731 static void gen_enumeration_type_die PROTO((tree, dw_die_ref));
732 static dw_die_ref gen_formal_parameter_die PROTO((tree, dw_die_ref));
733 static void gen_unspecified_parameters_die PROTO((tree, dw_die_ref));
734 static void gen_formal_types_die PROTO((tree, dw_die_ref));
735 static void gen_subprogram_die PROTO((tree, dw_die_ref));
736 static void gen_variable_die PROTO((tree, dw_die_ref));
737 static void gen_labeld_die PROTO((tree, dw_die_ref));
738 static void gen_lexical_block_die PROTO((tree, dw_die_ref, int));
739 static void gen_inlined_subprogram_die PROTO((tree, dw_die_ref, int));
740 static void gen_field_die PROTO((tree, dw_die_ref));
741 static void gen_ptr_to_mbr_type_die PROTO((tree, dw_die_ref));
742 static void gen_compile_unit_die PROTO((char *));
743 static void gen_string_type_die PROTO((tree, dw_die_ref));
744 static void gen_inheritance_die PROTO((tree, dw_die_ref));
745 static void gen_member_die PROTO((tree, dw_die_ref));
746 static void gen_struct_or_union_type_die PROTO((tree, dw_die_ref));
747 static void gen_subroutine_type_die PROTO((tree, dw_die_ref));
748 static void gen_typedef_die PROTO((tree, dw_die_ref));
749 static void gen_type_die PROTO((tree, dw_die_ref));
750 static void gen_tagged_type_instantiation_die PROTO((tree, dw_die_ref));
751 static void gen_block_die PROTO((tree, dw_die_ref, int));
752 static void decls_for_scope PROTO((tree, dw_die_ref, int));
753 static int is_redundant_typedef PROTO((tree));
754 static void gen_decl_die PROTO((tree, dw_die_ref));
755 static unsigned lookup_filename PROTO((char *));
757 /* Definitions of defaults for assembler-dependent names of various
758 pseudo-ops and section names.
759 Theses may be overridden in the tm.h file (if necessary) for a particular
762 #ifndef UNALIGNED_SHORT_ASM_OP
763 #define UNALIGNED_SHORT_ASM_OP ".2byte"
765 #ifndef UNALIGNED_INT_ASM_OP
766 #define UNALIGNED_INT_ASM_OP ".4byte"
768 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
769 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
772 #define ASM_BYTE_OP ".byte"
775 #ifndef UNALIGNED_OFFSET_ASM_OP
776 #define UNALIGNED_OFFSET_ASM_OP \
777 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
780 #ifndef UNALIGNED_WORD_ASM_OP
781 #define UNALIGNED_WORD_ASM_OP \
782 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
785 /* Data and reference forms for relocatable data. */
786 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
787 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
789 /* Pseudo-op for defining a new section. */
790 #ifndef SECTION_ASM_OP
791 #define SECTION_ASM_OP ".section"
794 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
795 print the SECTION_ASM_OP and the section name. The default here works for
796 almost all svr4 assemblers, except for the sparc, where the section name
797 must be enclosed in double quotes. (See sparcv4.h). */
798 #ifndef SECTION_FORMAT
799 #define SECTION_FORMAT "\t%s\t%s\n"
802 /* Section names used to hold DWARF debugging information. */
803 #ifndef DEBUG_SECTION
804 #define DEBUG_SECTION ".debug_info"
806 #ifndef ABBREV_SECTION
807 #define ABBREV_SECTION ".debug_abbrev"
809 #ifndef ARANGES_SECTION
810 #define ARANGES_SECTION ".debug_aranges"
812 #ifndef DW_MACINFO_SECTION
813 #define DW_MACINFO_SECTION ".debug_macinfo"
815 #ifndef FRAME_SECTION
816 #define FRAME_SECTION ".debug_frame"
819 #define LINE_SECTION ".debug_line"
822 #define LOC_SECTION ".debug_loc"
824 #ifndef PUBNAMES_SECTION
825 #define PUBNAMES_SECTION ".debug_pubnames"
828 #define STR_SECTION ".debug_str"
831 /* Standerd ELF section names for compiled code and data. */
833 #define TEXT_SECTION ".text"
836 #define DATA_SECTION ".data"
839 #define BSS_SECTION ".bss"
843 /* Definitions of defaults for formats and names of various special
844 (artificial) labels which may be generated within this file (when the -g
845 options is used and DWARF_DEBUGGING_INFO is in effect.
846 If necessary, these may be overridden from within the tm.h file, but
847 typically, overriding these defaults is unnecessary. */
849 char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
851 #ifndef TEXT_END_LABEL
852 #define TEXT_END_LABEL "Letext"
854 #ifndef DATA_END_LABEL
855 #define DATA_END_LABEL "Ledata"
857 #ifndef BSS_END_LABEL
858 #define BSS_END_LABEL "Lebss"
860 #ifndef INSN_LABEL_FMT
861 #define INSN_LABEL_FMT "LI%u_"
863 #ifndef BLOCK_BEGIN_LABEL
864 #define BLOCK_BEGIN_LABEL "LBB"
866 #ifndef BLOCK_END_LABEL
867 #define BLOCK_END_LABEL "LBE"
869 #ifndef BODY_BEGIN_LABEL
870 #define BODY_BEGIN_LABEL "Lbb"
872 #ifndef BODY_END_LABEL
873 #define BODY_END_LABEL "Lbe"
875 #ifndef FUNC_BEGIN_LABEL
876 #define FUNC_BEGIN_LABEL "LFB"
878 #ifndef FUNC_END_LABEL
879 #define FUNC_END_LABEL "LFE"
881 #ifndef LINE_CODE_LABEL
882 #define LINE_CODE_LABEL "LM"
884 #ifndef SEPARATE_LINE_CODE_LABEL
885 #define SEPARATE_LINE_CODE_LABEL "LSM"
888 /* Definitions of defaults for various types of primitive assembly language
889 output operations. These may be overridden from within the tm.h file,
890 but typically, that is unecessary. */
892 #ifndef ASM_OUTPUT_SECTION
893 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
894 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
897 #ifndef ASM_OUTPUT_DWARF_DELTA2
898 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
899 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
900 assemble_name (FILE, LABEL1); \
901 fprintf (FILE, "-"); \
902 assemble_name (FILE, LABEL2); \
906 #ifndef ASM_OUTPUT_DWARF_DELTA4
907 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
908 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
909 assemble_name (FILE, LABEL1); \
910 fprintf (FILE, "-"); \
911 assemble_name (FILE, LABEL2); \
915 #ifndef ASM_OUTPUT_DWARF_DELTA
916 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
917 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
918 assemble_name (FILE, LABEL1); \
919 fprintf (FILE, "-"); \
920 assemble_name (FILE, LABEL2); \
924 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
925 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
926 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
927 assemble_name (FILE, LABEL1); \
928 fprintf (FILE, "-"); \
929 assemble_name (FILE, LABEL2); \
933 #ifndef ASM_OUTPUT_DWARF_ADDR
934 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
935 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
936 assemble_name (FILE, LABEL); \
940 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
941 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
942 fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR))
945 #ifndef ASM_OUTPUT_DWARF_OFFSET
946 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
947 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
948 assemble_name (FILE, LABEL); \
952 #ifndef ASM_OUTPUT_DWARF_DATA1
953 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
954 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, VALUE)
957 #ifndef ASM_OUTPUT_DWARF_DATA2
958 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
959 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
962 #ifndef ASM_OUTPUT_DWARF_DATA4
963 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
964 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
967 #ifndef ASM_OUTPUT_DWARF_DATA
968 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
969 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
970 (unsigned long) VALUE)
973 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
974 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
975 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
976 (unsigned long) VALUE)
979 #ifndef ASM_OUTPUT_DWARF_DATA8
980 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
982 if (WORDS_BIG_ENDIAN) \
984 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
985 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
989 fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
990 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
995 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
996 newline is produced. When flag_verbose_asm is asserted, we add commnetary
997 at the end of the line, so we must avoid output of a newline here. */
998 #ifndef ASM_OUTPUT_DWARF_STRING
999 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
1001 register int slen = strlen(P); \
1002 register char *p = (P); \
1004 fprintf (FILE, "\t.ascii \""); \
1005 for (i = 0; i < slen; i++) \
1007 register int c = p[i]; \
1008 if (c == '\"' || c == '\\') \
1009 putc ('\\', FILE); \
1010 if (c >= ' ' && c < 0177) \
1014 fprintf (FILE, "\\%o", c); \
1017 fprintf (FILE, "\\0\""); \
1022 /* Convert a reference to the assembler name of a C-level name. This
1023 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
1024 a string rather than writing to a file. */
1025 #ifndef ASM_NAME_TO_STRING
1026 #define ASM_NAME_TO_STRING(STR, NAME) \
1028 if ((NAME)[0] == '*') \
1029 strcpy (STR, NAME+1); \
1031 strcpy (STR, NAME); \
1036 /* The DWARF 2 CFA column which tracks the return address. Normally this
1037 is the column for PC, or the first column after all of the hard
1039 #ifndef DWARF_FRAME_RETURN_COLUMN
1041 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
1043 #define DWARF_FRAME_RETURN_COLUMN FIRST_PSEUDO_REGISTER
1047 /* The mapping from gcc register number to DWARF 2 CFA column number. By
1048 default, we just provide columns for all registers. */
1049 #ifndef DWARF_FRAME_REGNUM
1050 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
1053 /* Return a pointer to a copy of the section string name S with all
1054 attributes stripped off. */
1056 static inline char *
1060 char *stripped = xstrdup (s);
1063 while (*p && *p != ',')
1070 /* Convert an integer constant expression into assembler syntax. Addition
1071 and subtraction are the only arithmetic that may appear in these
1072 expressions. This is an adaptation of output_addr_const in final.c.
1073 Here, the target of the conversion is a string buffer. We can't use
1074 output_addr_const directly, because it writes to a file. */
1077 addr_const_to_string (str, x)
1086 switch (GET_CODE (x))
1096 ASM_NAME_TO_STRING (buf1, XSTR (x, 0));
1101 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
1102 ASM_NAME_TO_STRING (buf2, buf1);
1107 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
1108 ASM_NAME_TO_STRING (buf2, buf1);
1113 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
1118 /* This used to output parentheses around the expression, but that does
1119 not work on the 386 (either ATT or BSD assembler). */
1120 addr_const_to_string (buf1, XEXP (x, 0));
1125 if (GET_MODE (x) == VOIDmode)
1127 /* We can use %d if the number is one word and positive. */
1128 if (CONST_DOUBLE_HIGH (x))
1129 sprintf (buf1, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
1130 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
1131 else if (CONST_DOUBLE_LOW (x) < 0)
1132 sprintf (buf1, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
1134 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC,
1135 CONST_DOUBLE_LOW (x));
1139 /* We can't handle floating point constants; PRINT_OPERAND must
1141 output_operand_lossage ("floating constant misused");
1145 /* Some assemblers need integer constants to appear last (eg masm). */
1146 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
1148 addr_const_to_string (buf1, XEXP (x, 1));
1150 if (INTVAL (XEXP (x, 0)) >= 0)
1153 addr_const_to_string (buf1, XEXP (x, 0));
1158 addr_const_to_string (buf1, XEXP (x, 0));
1160 if (INTVAL (XEXP (x, 1)) >= 0)
1163 addr_const_to_string (buf1, XEXP (x, 1));
1169 /* Avoid outputting things like x-x or x+5-x, since some assemblers
1170 can't handle that. */
1171 x = simplify_subtraction (x);
1172 if (GET_CODE (x) != MINUS)
1175 addr_const_to_string (buf1, XEXP (x, 0));
1178 if (GET_CODE (XEXP (x, 1)) == CONST_INT
1179 && INTVAL (XEXP (x, 1)) < 0)
1181 strcat (str, ASM_OPEN_PAREN);
1182 addr_const_to_string (buf1, XEXP (x, 1));
1184 strcat (str, ASM_CLOSE_PAREN);
1188 addr_const_to_string (buf1, XEXP (x, 1));
1195 addr_const_to_string (buf1, XEXP (x, 0));
1200 output_operand_lossage ("invalid expression as operand");
1204 /* Convert an address constant to a string, and return a pointer to
1205 a copy of the result, located on the heap. */
1212 addr_const_to_string (buf, x);
1213 return xstrdup (buf);
1216 /* Test if rtl node points to a psuedo register. */
1222 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
1223 || ((GET_CODE (rtl) == SUBREG)
1224 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
1227 /* Return a reference to a type, with its const and volatile qualifiers
1231 type_main_variant (type)
1234 type = TYPE_MAIN_VARIANT (type);
1236 /* There really should be only one main variant among any group of variants
1237 of a given type (and all of the MAIN_VARIANT values for all members of
1238 the group should point to that one type) but sometimes the C front-end
1239 messes this up for array types, so we work around that bug here. */
1241 if (TREE_CODE (type) == ARRAY_TYPE)
1242 while (type != TYPE_MAIN_VARIANT (type))
1243 type = TYPE_MAIN_VARIANT (type);
1248 /* Return non-zero if the given type node represents a tagged type. */
1251 is_tagged_type (type)
1254 register enum tree_code code = TREE_CODE (type);
1256 return (code == RECORD_TYPE || code == UNION_TYPE
1257 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
1260 /* Convert a DIE tag into its string name. */
1263 dwarf_tag_name (tag)
1264 register unsigned tag;
1268 case DW_TAG_padding:
1269 return "DW_TAG_padding";
1270 case DW_TAG_array_type:
1271 return "DW_TAG_array_type";
1272 case DW_TAG_class_type:
1273 return "DW_TAG_class_type";
1274 case DW_TAG_entry_point:
1275 return "DW_TAG_entry_point";
1276 case DW_TAG_enumeration_type:
1277 return "DW_TAG_enumeration_type";
1278 case DW_TAG_formal_parameter:
1279 return "DW_TAG_formal_parameter";
1280 case DW_TAG_imported_declaration:
1281 return "DW_TAG_imported_declaration";
1283 return "DW_TAG_label";
1284 case DW_TAG_lexical_block:
1285 return "DW_TAG_lexical_block";
1287 return "DW_TAG_member";
1288 case DW_TAG_pointer_type:
1289 return "DW_TAG_pointer_type";
1290 case DW_TAG_reference_type:
1291 return "DW_TAG_reference_type";
1292 case DW_TAG_compile_unit:
1293 return "DW_TAG_compile_unit";
1294 case DW_TAG_string_type:
1295 return "DW_TAG_string_type";
1296 case DW_TAG_structure_type:
1297 return "DW_TAG_structure_type";
1298 case DW_TAG_subroutine_type:
1299 return "DW_TAG_subroutine_type";
1300 case DW_TAG_typedef:
1301 return "DW_TAG_typedef";
1302 case DW_TAG_union_type:
1303 return "DW_TAG_union_type";
1304 case DW_TAG_unspecified_parameters:
1305 return "DW_TAG_unspecified_parameters";
1306 case DW_TAG_variant:
1307 return "DW_TAG_variant";
1308 case DW_TAG_common_block:
1309 return "DW_TAG_common_block";
1310 case DW_TAG_common_inclusion:
1311 return "DW_TAG_common_inclusion";
1312 case DW_TAG_inheritance:
1313 return "DW_TAG_inheritance";
1314 case DW_TAG_inlined_subroutine:
1315 return "DW_TAG_inlined_subroutine";
1317 return "DW_TAG_module";
1318 case DW_TAG_ptr_to_member_type:
1319 return "DW_TAG_ptr_to_member_type";
1320 case DW_TAG_set_type:
1321 return "DW_TAG_set_type";
1322 case DW_TAG_subrange_type:
1323 return "DW_TAG_subrange_type";
1324 case DW_TAG_with_stmt:
1325 return "DW_TAG_with_stmt";
1326 case DW_TAG_access_declaration:
1327 return "DW_TAG_access_declaration";
1328 case DW_TAG_base_type:
1329 return "DW_TAG_base_type";
1330 case DW_TAG_catch_block:
1331 return "DW_TAG_catch_block";
1332 case DW_TAG_const_type:
1333 return "DW_TAG_const_type";
1334 case DW_TAG_constant:
1335 return "DW_TAG_constant";
1336 case DW_TAG_enumerator:
1337 return "DW_TAG_enumerator";
1338 case DW_TAG_file_type:
1339 return "DW_TAG_file_type";
1341 return "DW_TAG_friend";
1342 case DW_TAG_namelist:
1343 return "DW_TAG_namelist";
1344 case DW_TAG_namelist_item:
1345 return "DW_TAG_namelist_item";
1346 case DW_TAG_packed_type:
1347 return "DW_TAG_packed_type";
1348 case DW_TAG_subprogram:
1349 return "DW_TAG_subprogram";
1350 case DW_TAG_template_type_param:
1351 return "DW_TAG_template_type_param";
1352 case DW_TAG_template_value_param:
1353 return "DW_TAG_template_value_param";
1354 case DW_TAG_thrown_type:
1355 return "DW_TAG_thrown_type";
1356 case DW_TAG_try_block:
1357 return "DW_TAG_try_block";
1358 case DW_TAG_variant_part:
1359 return "DW_TAG_variant_part";
1360 case DW_TAG_variable:
1361 return "DW_TAG_variable";
1362 case DW_TAG_volatile_type:
1363 return "DW_TAG_volatile_type";
1364 case DW_TAG_MIPS_loop:
1365 return "DW_TAG_MIPS_loop";
1366 case DW_TAG_format_label:
1367 return "DW_TAG_format_label";
1368 case DW_TAG_function_template:
1369 return "DW_TAG_function_template";
1370 case DW_TAG_class_template:
1371 return "DW_TAG_class_template";
1373 return "DW_TAG_<unknown>";
1377 /* Convert a DWARF attribute code into its string name. */
1380 dwarf_attr_name (attr)
1381 register unsigned attr;
1386 return "DW_AT_sibling";
1387 case DW_AT_location:
1388 return "DW_AT_location";
1390 return "DW_AT_name";
1391 case DW_AT_ordering:
1392 return "DW_AT_ordering";
1393 case DW_AT_subscr_data:
1394 return "DW_AT_subscr_data";
1395 case DW_AT_byte_size:
1396 return "DW_AT_byte_size";
1397 case DW_AT_bit_offset:
1398 return "DW_AT_bit_offset";
1399 case DW_AT_bit_size:
1400 return "DW_AT_bit_size";
1401 case DW_AT_element_list:
1402 return "DW_AT_element_list";
1403 case DW_AT_stmt_list:
1404 return "DW_AT_stmt_list";
1406 return "DW_AT_low_pc";
1408 return "DW_AT_high_pc";
1409 case DW_AT_language:
1410 return "DW_AT_language";
1412 return "DW_AT_member";
1414 return "DW_AT_discr";
1415 case DW_AT_discr_value:
1416 return "DW_AT_discr_value";
1417 case DW_AT_visibility:
1418 return "DW_AT_visibility";
1420 return "DW_AT_import";
1421 case DW_AT_string_length:
1422 return "DW_AT_string_length";
1423 case DW_AT_common_reference:
1424 return "DW_AT_common_reference";
1425 case DW_AT_comp_dir:
1426 return "DW_AT_comp_dir";
1427 case DW_AT_const_value:
1428 return "DW_AT_const_value";
1429 case DW_AT_containing_type:
1430 return "DW_AT_containing_type";
1431 case DW_AT_default_value:
1432 return "DW_AT_default_value";
1434 return "DW_AT_inline";
1435 case DW_AT_is_optional:
1436 return "DW_AT_is_optional";
1437 case DW_AT_lower_bound:
1438 return "DW_AT_lower_bound";
1439 case DW_AT_producer:
1440 return "DW_AT_producer";
1441 case DW_AT_prototyped:
1442 return "DW_AT_prototyped";
1443 case DW_AT_return_addr:
1444 return "DW_AT_return_addr";
1445 case DW_AT_start_scope:
1446 return "DW_AT_start_scope";
1447 case DW_AT_stride_size:
1448 return "DW_AT_stride_size";
1449 case DW_AT_upper_bound:
1450 return "DW_AT_upper_bound";
1451 case DW_AT_abstract_origin:
1452 return "DW_AT_abstract_origin";
1453 case DW_AT_accessibility:
1454 return "DW_AT_accessibility";
1455 case DW_AT_address_class:
1456 return "DW_AT_address_class";
1457 case DW_AT_artificial:
1458 return "DW_AT_artificial";
1459 case DW_AT_base_types:
1460 return "DW_AT_base_types";
1461 case DW_AT_calling_convention:
1462 return "DW_AT_calling_convention";
1464 return "DW_AT_count";
1465 case DW_AT_data_member_location:
1466 return "DW_AT_data_member_location";
1467 case DW_AT_decl_column:
1468 return "DW_AT_decl_column";
1469 case DW_AT_decl_file:
1470 return "DW_AT_decl_file";
1471 case DW_AT_decl_line:
1472 return "DW_AT_decl_line";
1473 case DW_AT_declaration:
1474 return "DW_AT_declaration";
1475 case DW_AT_discr_list:
1476 return "DW_AT_discr_list";
1477 case DW_AT_encoding:
1478 return "DW_AT_encoding";
1479 case DW_AT_external:
1480 return "DW_AT_external";
1481 case DW_AT_frame_base:
1482 return "DW_AT_frame_base";
1484 return "DW_AT_friend";
1485 case DW_AT_identifier_case:
1486 return "DW_AT_identifier_case";
1487 case DW_AT_macro_info:
1488 return "DW_AT_macro_info";
1489 case DW_AT_namelist_items:
1490 return "DW_AT_namelist_items";
1491 case DW_AT_priority:
1492 return "DW_AT_priority";
1494 return "DW_AT_segment";
1495 case DW_AT_specification:
1496 return "DW_AT_specification";
1497 case DW_AT_static_link:
1498 return "DW_AT_static_link";
1500 return "DW_AT_type";
1501 case DW_AT_use_location:
1502 return "DW_AT_use_location";
1503 case DW_AT_variable_parameter:
1504 return "DW_AT_variable_parameter";
1505 case DW_AT_virtuality:
1506 return "DW_AT_virtuality";
1507 case DW_AT_vtable_elem_location:
1508 return "DW_AT_vtable_elem_location";
1510 case DW_AT_MIPS_fde:
1511 return "DW_AT_MIPS_fde";
1512 case DW_AT_MIPS_loop_begin:
1513 return "DW_AT_MIPS_loop_begin";
1514 case DW_AT_MIPS_tail_loop_begin:
1515 return "DW_AT_MIPS_tail_loop_begin";
1516 case DW_AT_MIPS_epilog_begin:
1517 return "DW_AT_MIPS_epilog_begin";
1518 case DW_AT_MIPS_loop_unroll_factor:
1519 return "DW_AT_MIPS_loop_unroll_factor";
1520 case DW_AT_MIPS_software_pipeline_depth:
1521 return "DW_AT_MIPS_software_pipeline_depth";
1522 case DW_AT_MIPS_linkage_name:
1523 return "DW_AT_MIPS_linkage_name";
1524 case DW_AT_MIPS_stride:
1525 return "DW_AT_MIPS_stride";
1526 case DW_AT_MIPS_abstract_name:
1527 return "DW_AT_MIPS_abstract_name";
1528 case DW_AT_MIPS_clone_origin:
1529 return "DW_AT_MIPS_clone_origin";
1530 case DW_AT_MIPS_has_inlines:
1531 return "DW_AT_MIPS_has_inlines";
1533 case DW_AT_sf_names:
1534 return "DW_AT_sf_names";
1535 case DW_AT_src_info:
1536 return "DW_AT_src_info";
1537 case DW_AT_mac_info:
1538 return "DW_AT_mac_info";
1539 case DW_AT_src_coords:
1540 return "DW_AT_src_coords";
1541 case DW_AT_body_begin:
1542 return "DW_AT_body_begin";
1543 case DW_AT_body_end:
1544 return "DW_AT_body_end";
1546 return "DW_AT_<unknown>";
1550 /* Convert a DWARF value form code into its string name. */
1553 dwarf_form_name (form)
1554 register unsigned form;
1559 return "DW_FORM_addr";
1560 case DW_FORM_block2:
1561 return "DW_FORM_block2";
1562 case DW_FORM_block4:
1563 return "DW_FORM_block4";
1565 return "DW_FORM_data2";
1567 return "DW_FORM_data4";
1569 return "DW_FORM_data8";
1570 case DW_FORM_string:
1571 return "DW_FORM_string";
1573 return "DW_FORM_block";
1574 case DW_FORM_block1:
1575 return "DW_FORM_block1";
1577 return "DW_FORM_data1";
1579 return "DW_FORM_flag";
1581 return "DW_FORM_sdata";
1583 return "DW_FORM_strp";
1585 return "DW_FORM_udata";
1586 case DW_FORM_ref_addr:
1587 return "DW_FORM_ref_addr";
1589 return "DW_FORM_ref1";
1591 return "DW_FORM_ref2";
1593 return "DW_FORM_ref4";
1595 return "DW_FORM_ref8";
1596 case DW_FORM_ref_udata:
1597 return "DW_FORM_ref_udata";
1598 case DW_FORM_indirect:
1599 return "DW_FORM_indirect";
1601 return "DW_FORM_<unknown>";
1605 /* Convert a DWARF stack opcode into its string name. */
1608 dwarf_stack_op_name (op)
1609 register unsigned op;
1614 return "DW_OP_addr";
1616 return "DW_OP_deref";
1618 return "DW_OP_const1u";
1620 return "DW_OP_const1s";
1622 return "DW_OP_const2u";
1624 return "DW_OP_const2s";
1626 return "DW_OP_const4u";
1628 return "DW_OP_const4s";
1630 return "DW_OP_const8u";
1632 return "DW_OP_const8s";
1634 return "DW_OP_constu";
1636 return "DW_OP_consts";
1640 return "DW_OP_drop";
1642 return "DW_OP_over";
1644 return "DW_OP_pick";
1646 return "DW_OP_swap";
1650 return "DW_OP_xderef";
1658 return "DW_OP_minus";
1670 return "DW_OP_plus";
1671 case DW_OP_plus_uconst:
1672 return "DW_OP_plus_uconst";
1678 return "DW_OP_shra";
1696 return "DW_OP_skip";
1698 return "DW_OP_lit0";
1700 return "DW_OP_lit1";
1702 return "DW_OP_lit2";
1704 return "DW_OP_lit3";
1706 return "DW_OP_lit4";
1708 return "DW_OP_lit5";
1710 return "DW_OP_lit6";
1712 return "DW_OP_lit7";
1714 return "DW_OP_lit8";
1716 return "DW_OP_lit9";
1718 return "DW_OP_lit10";
1720 return "DW_OP_lit11";
1722 return "DW_OP_lit12";
1724 return "DW_OP_lit13";
1726 return "DW_OP_lit14";
1728 return "DW_OP_lit15";
1730 return "DW_OP_lit16";
1732 return "DW_OP_lit17";
1734 return "DW_OP_lit18";
1736 return "DW_OP_lit19";
1738 return "DW_OP_lit20";
1740 return "DW_OP_lit21";
1742 return "DW_OP_lit22";
1744 return "DW_OP_lit23";
1746 return "DW_OP_lit24";
1748 return "DW_OP_lit25";
1750 return "DW_OP_lit26";
1752 return "DW_OP_lit27";
1754 return "DW_OP_lit28";
1756 return "DW_OP_lit29";
1758 return "DW_OP_lit30";
1760 return "DW_OP_lit31";
1762 return "DW_OP_reg0";
1764 return "DW_OP_reg1";
1766 return "DW_OP_reg2";
1768 return "DW_OP_reg3";
1770 return "DW_OP_reg4";
1772 return "DW_OP_reg5";
1774 return "DW_OP_reg6";
1776 return "DW_OP_reg7";
1778 return "DW_OP_reg8";
1780 return "DW_OP_reg9";
1782 return "DW_OP_reg10";
1784 return "DW_OP_reg11";
1786 return "DW_OP_reg12";
1788 return "DW_OP_reg13";
1790 return "DW_OP_reg14";
1792 return "DW_OP_reg15";
1794 return "DW_OP_reg16";
1796 return "DW_OP_reg17";
1798 return "DW_OP_reg18";
1800 return "DW_OP_reg19";
1802 return "DW_OP_reg20";
1804 return "DW_OP_reg21";
1806 return "DW_OP_reg22";
1808 return "DW_OP_reg23";
1810 return "DW_OP_reg24";
1812 return "DW_OP_reg25";
1814 return "DW_OP_reg26";
1816 return "DW_OP_reg27";
1818 return "DW_OP_reg28";
1820 return "DW_OP_reg29";
1822 return "DW_OP_reg30";
1824 return "DW_OP_reg31";
1826 return "DW_OP_breg0";
1828 return "DW_OP_breg1";
1830 return "DW_OP_breg2";
1832 return "DW_OP_breg3";
1834 return "DW_OP_breg4";
1836 return "DW_OP_breg5";
1838 return "DW_OP_breg6";
1840 return "DW_OP_breg7";
1842 return "DW_OP_breg8";
1844 return "DW_OP_breg9";
1846 return "DW_OP_breg10";
1848 return "DW_OP_breg11";
1850 return "DW_OP_breg12";
1852 return "DW_OP_breg13";
1854 return "DW_OP_breg14";
1856 return "DW_OP_breg15";
1858 return "DW_OP_breg16";
1860 return "DW_OP_breg17";
1862 return "DW_OP_breg18";
1864 return "DW_OP_breg19";
1866 return "DW_OP_breg20";
1868 return "DW_OP_breg21";
1870 return "DW_OP_breg22";
1872 return "DW_OP_breg23";
1874 return "DW_OP_breg24";
1876 return "DW_OP_breg25";
1878 return "DW_OP_breg26";
1880 return "DW_OP_breg27";
1882 return "DW_OP_breg28";
1884 return "DW_OP_breg29";
1886 return "DW_OP_breg30";
1888 return "DW_OP_breg31";
1890 return "DW_OP_regx";
1892 return "DW_OP_fbreg";
1894 return "DW_OP_bregx";
1896 return "DW_OP_piece";
1897 case DW_OP_deref_size:
1898 return "DW_OP_deref_size";
1899 case DW_OP_xderef_size:
1900 return "DW_OP_xderef_size";
1904 return "OP_<unknown>";
1908 /* Convert a DWARF type code into its string name. */
1911 dwarf_type_encoding_name (enc)
1912 register unsigned enc;
1916 case DW_ATE_address:
1917 return "DW_ATE_address";
1918 case DW_ATE_boolean:
1919 return "DW_ATE_boolean";
1920 case DW_ATE_complex_float:
1921 return "DW_ATE_complex_float";
1923 return "DW_ATE_float";
1925 return "DW_ATE_signed";
1926 case DW_ATE_signed_char:
1927 return "DW_ATE_signed_char";
1928 case DW_ATE_unsigned:
1929 return "DW_ATE_unsigned";
1930 case DW_ATE_unsigned_char:
1931 return "DW_ATE_unsigned_char";
1933 return "DW_ATE_<unknown>";
1937 /* Convert a DWARF call frame info. operation to its string name */
1940 dwarf_cfi_name (cfi_opc)
1941 register unsigned cfi_opc;
1945 case DW_CFA_advance_loc:
1946 return "DW_CFA_advance_loc";
1948 return "DW_CFA_offset";
1949 case DW_CFA_restore:
1950 return "DW_CFA_restore";
1952 return "DW_CFA_nop";
1953 case DW_CFA_set_loc:
1954 return "DW_CFA_set_loc";
1955 case DW_CFA_advance_loc1:
1956 return "DW_CFA_advance_loc1";
1957 case DW_CFA_advance_loc2:
1958 return "DW_CFA_advance_loc2";
1959 case DW_CFA_advance_loc4:
1960 return "DW_CFA_advance_loc4";
1961 case DW_CFA_offset_extended:
1962 return "DW_CFA_offset_extended";
1963 case DW_CFA_restore_extended:
1964 return "DW_CFA_restore_extended";
1965 case DW_CFA_undefined:
1966 return "DW_CFA_undefined";
1967 case DW_CFA_same_value:
1968 return "DW_CFA_same_value";
1969 case DW_CFA_register:
1970 return "DW_CFA_register";
1971 case DW_CFA_remember_state:
1972 return "DW_CFA_remember_state";
1973 case DW_CFA_restore_state:
1974 return "DW_CFA_restore_state";
1975 case DW_CFA_def_cfa:
1976 return "DW_CFA_def_cfa";
1977 case DW_CFA_def_cfa_register:
1978 return "DW_CFA_def_cfa_register";
1979 case DW_CFA_def_cfa_offset:
1980 return "DW_CFA_def_cfa_offset";
1981 /* SGI/MIPS specific */
1982 case DW_CFA_MIPS_advance_loc8:
1983 return "DW_CFA_MIPS_advance_loc8";
1985 return "DW_CFA_<unknown>";
1989 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
1990 instance of an inlined instance of a decl which is local to an inline
1991 function, so we have to trace all of the way back through the origin chain
1992 to find out what sort of node actually served as the original seed for the
1996 decl_ultimate_origin (decl)
1999 register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
2001 if (immediate_origin == NULL_TREE || immediate_origin == decl)
2005 register tree ret_val;
2006 register tree lookahead = immediate_origin;
2010 ret_val = lookahead;
2011 lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
2013 while (lookahead != NULL && lookahead != ret_val);
2019 /* Determine the "ultimate origin" of a block. The block may be an inlined
2020 instance of an inlined instance of a block which is local to an inline
2021 function, so we have to trace all of the way back through the origin chain
2022 to find out what sort of node actually served as the original seed for the
2026 block_ultimate_origin (block)
2027 register tree block;
2029 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
2031 if (immediate_origin == NULL_TREE)
2035 register tree ret_val;
2036 register tree lookahead = immediate_origin;
2040 ret_val = lookahead;
2041 lookahead = (TREE_CODE (ret_val) == BLOCK)
2042 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
2045 while (lookahead != NULL && lookahead != ret_val);
2051 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
2052 of a virtual function may refer to a base class, so we check the 'this'
2056 decl_class_context (decl)
2059 tree context = NULL_TREE;
2061 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
2062 context = DECL_CONTEXT (decl);
2064 context = TYPE_MAIN_VARIANT
2065 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
2067 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
2068 context = NULL_TREE;
2073 /* Add an attribute/value pair to a DIE */
2076 add_dwarf_attr (die, attr)
2077 register dw_die_ref die;
2078 register dw_attr_ref attr;
2080 if (die != NULL && attr != NULL)
2082 if (die->die_attr == NULL)
2084 die->die_attr = attr;
2085 die->die_attr_last = attr;
2089 die->die_attr_last->dw_attr_next = attr;
2090 die->die_attr_last = attr;
2095 /* Add a flag value attribute to a DIE. */
2098 add_AT_flag (die, attr_kind, flag)
2099 register dw_die_ref die;
2100 register enum dwarf_attribute attr_kind;
2101 register unsigned flag;
2103 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2105 attr->dw_attr_next = NULL;
2106 attr->dw_attr = attr_kind;
2107 attr->dw_attr_val.val_class = dw_val_class_flag;
2108 attr->dw_attr_val.v.val_flag = flag;
2109 add_dwarf_attr (die, attr);
2112 /* Add a signed integer attribute value to a DIE. */
2115 add_AT_int (die, attr_kind, int_val)
2116 register dw_die_ref die;
2117 register enum dwarf_attribute attr_kind;
2118 register long int int_val;
2120 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2122 attr->dw_attr_next = NULL;
2123 attr->dw_attr = attr_kind;
2124 attr->dw_attr_val.val_class = dw_val_class_const;
2125 attr->dw_attr_val.v.val_int = int_val;
2126 add_dwarf_attr (die, attr);
2129 /* Add an unsigned integer attribute value to a DIE. */
2132 add_AT_unsigned (die, attr_kind, unsigned_val)
2133 register dw_die_ref die;
2134 register enum dwarf_attribute attr_kind;
2135 register unsigned long unsigned_val;
2137 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2139 attr->dw_attr_next = NULL;
2140 attr->dw_attr = attr_kind;
2141 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
2142 attr->dw_attr_val.v.val_unsigned = unsigned_val;
2143 add_dwarf_attr (die, attr);
2146 /* Add an unsigned double integer attribute value to a DIE. */
2149 add_AT_long_long (die, attr_kind, val_hi, val_low)
2150 register dw_die_ref die;
2151 register enum dwarf_attribute attr_kind;
2152 register unsigned long val_hi;
2153 register unsigned long val_low;
2155 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2157 attr->dw_attr_next = NULL;
2158 attr->dw_attr = attr_kind;
2159 attr->dw_attr_val.val_class = dw_val_class_long_long;
2160 attr->dw_attr_val.v.val_long_long.hi = val_hi;
2161 attr->dw_attr_val.v.val_long_long.low = val_low;
2162 add_dwarf_attr (die, attr);
2165 /* Add a floating point attribute value to a DIE and return it. */
2168 add_AT_float (die, attr_kind, length, array)
2169 register dw_die_ref die;
2170 register enum dwarf_attribute attr_kind;
2171 register unsigned length;
2172 register long *array;
2174 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2176 attr->dw_attr_next = NULL;
2177 attr->dw_attr = attr_kind;
2178 attr->dw_attr_val.val_class = dw_val_class_float;
2179 attr->dw_attr_val.v.val_float.length = length;
2180 attr->dw_attr_val.v.val_float.array = array;
2181 add_dwarf_attr (die, attr);
2184 /* Add a string attribute value to a DIE. */
2187 add_AT_string (die, attr_kind, str)
2188 register dw_die_ref die;
2189 register enum dwarf_attribute attr_kind;
2192 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2194 attr->dw_attr_next = NULL;
2195 attr->dw_attr = attr_kind;
2196 attr->dw_attr_val.val_class = dw_val_class_str;
2197 attr->dw_attr_val.v.val_str = xstrdup (str);
2198 add_dwarf_attr (die, attr);
2201 /* Add a DIE reference attribute value to a DIE. */
2204 add_AT_die_ref (die, attr_kind, targ_die)
2205 register dw_die_ref die;
2206 register enum dwarf_attribute attr_kind;
2207 register dw_die_ref targ_die;
2209 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2211 attr->dw_attr_next = NULL;
2212 attr->dw_attr = attr_kind;
2213 attr->dw_attr_val.val_class = dw_val_class_die_ref;
2214 attr->dw_attr_val.v.val_die_ref = targ_die;
2215 add_dwarf_attr (die, attr);
2218 /* Add an FDE reference attribute value to a DIE. */
2221 add_AT_fde_ref (die, attr_kind, targ_fde)
2222 register dw_die_ref die;
2223 register enum dwarf_attribute attr_kind;
2224 register unsigned targ_fde;
2226 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2228 attr->dw_attr_next = NULL;
2229 attr->dw_attr = attr_kind;
2230 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
2231 attr->dw_attr_val.v.val_fde_index = targ_fde;
2232 add_dwarf_attr (die, attr);
2235 /* Add a location description attribute value to a DIE. */
2238 add_AT_loc (die, attr_kind, loc)
2239 register dw_die_ref die;
2240 register enum dwarf_attribute attr_kind;
2241 register dw_loc_descr_ref loc;
2243 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2245 attr->dw_attr_next = NULL;
2246 attr->dw_attr = attr_kind;
2247 attr->dw_attr_val.val_class = dw_val_class_loc;
2248 attr->dw_attr_val.v.val_loc = loc;
2249 add_dwarf_attr (die, attr);
2252 /* Add an address constant attribute value to a DIE. */
2255 add_AT_addr (die, attr_kind, addr)
2256 register dw_die_ref die;
2257 register enum dwarf_attribute attr_kind;
2260 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2262 attr->dw_attr_next = NULL;
2263 attr->dw_attr = attr_kind;
2264 attr->dw_attr_val.val_class = dw_val_class_addr;
2265 attr->dw_attr_val.v.val_addr = addr;
2266 add_dwarf_attr (die, attr);
2269 /* Add a label identifier attribute value to a DIE. */
2272 add_AT_lbl_id (die, attr_kind, lbl_id)
2273 register dw_die_ref die;
2274 register enum dwarf_attribute attr_kind;
2275 register char *lbl_id;
2277 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2279 attr->dw_attr_next = NULL;
2280 attr->dw_attr = attr_kind;
2281 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
2282 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
2283 add_dwarf_attr (die, attr);
2286 /* Add a section offset attribute value to a DIE. */
2289 add_AT_section_offset (die, attr_kind, section)
2290 register dw_die_ref die;
2291 register enum dwarf_attribute attr_kind;
2292 register char *section;
2294 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2296 attr->dw_attr_next = NULL;
2297 attr->dw_attr = attr_kind;
2298 attr->dw_attr_val.val_class = dw_val_class_section_offset;
2299 attr->dw_attr_val.v.val_section = section;
2300 add_dwarf_attr (die, attr);
2304 /* Test if die refers to an external subroutine. */
2307 is_extern_subr_die (die)
2308 register dw_die_ref die;
2310 register dw_attr_ref a;
2311 register int is_subr = FALSE;
2312 register int is_extern = FALSE;
2314 if (die != NULL && die->die_tag == DW_TAG_subprogram)
2317 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2319 if (a->dw_attr == DW_AT_external
2320 && a->dw_attr_val.val_class == dw_val_class_flag
2321 && a->dw_attr_val.v.val_flag != 0)
2329 return is_subr && is_extern;
2332 /* Get the attribute of type attr_kind. */
2334 static inline dw_attr_ref
2335 get_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_die_ref spec = NULL;
2344 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2346 if (a->dw_attr == attr_kind)
2349 if (a->dw_attr == DW_AT_specification
2350 || a->dw_attr == DW_AT_abstract_origin)
2351 spec = a->dw_attr_val.v.val_die_ref;
2355 return get_AT (spec, attr_kind);
2361 /* Return the "low pc" attribute value, typically associated with
2362 a subprogram DIE. Return null if the "low pc" attribute is
2363 either not prsent, or if it cannot be represented as an
2364 assembler label identifier. */
2366 static inline char *
2368 register dw_die_ref die;
2370 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
2372 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
2373 return a->dw_attr_val.v.val_lbl_id;
2378 /* Return the "high pc" attribute value, typically associated with
2379 a subprogram DIE. Return null if the "high pc" attribute is
2380 either not prsent, or if it cannot be represented as an
2381 assembler label identifier. */
2383 static inline char *
2385 register dw_die_ref die;
2387 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
2389 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
2390 return a->dw_attr_val.v.val_lbl_id;
2395 /* Return the value of the string attribute designated by ATTR_KIND, or
2396 NULL if it is not present. */
2398 static inline char *
2399 get_AT_string (die, attr_kind)
2400 register dw_die_ref die;
2401 register enum dwarf_attribute attr_kind;
2403 register dw_attr_ref a = get_AT (die, attr_kind);
2405 if (a && a->dw_attr_val.val_class == dw_val_class_str)
2406 return a->dw_attr_val.v.val_str;
2411 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
2412 if it is not present. */
2415 get_AT_flag (die, attr_kind)
2416 register dw_die_ref die;
2417 register enum dwarf_attribute attr_kind;
2419 register dw_attr_ref a = get_AT (die, attr_kind);
2421 if (a && a->dw_attr_val.val_class == dw_val_class_flag)
2422 return a->dw_attr_val.v.val_flag;
2427 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
2428 if it is not present. */
2430 static inline unsigned
2431 get_AT_unsigned (die, attr_kind)
2432 register dw_die_ref die;
2433 register enum dwarf_attribute attr_kind;
2435 register dw_attr_ref a = get_AT (die, attr_kind);
2437 if (a && a->dw_attr_val.val_class == dw_val_class_unsigned_const)
2438 return a->dw_attr_val.v.val_unsigned;
2446 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
2448 return (lang == DW_LANG_C || lang == DW_LANG_C89
2449 || lang == DW_LANG_C_plus_plus);
2455 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
2457 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
2460 /* Remove the specified attribute if present. */
2463 remove_AT (die, attr_kind)
2464 register dw_die_ref die;
2465 register enum dwarf_attribute attr_kind;
2467 register dw_attr_ref a;
2468 register dw_attr_ref removed = NULL;;
2472 if (die->die_attr->dw_attr == attr_kind)
2474 removed = die->die_attr;
2475 if (die->die_attr_last == die->die_attr)
2476 die->die_attr_last = NULL;
2478 die->die_attr = die->die_attr->dw_attr_next;
2482 for (a = die->die_attr; a->dw_attr_next != NULL;
2483 a = a->dw_attr_next)
2484 if (a->dw_attr_next->dw_attr == attr_kind)
2486 removed = a->dw_attr_next;
2487 if (die->die_attr_last == a->dw_attr_next)
2488 die->die_attr_last = a;
2490 a->dw_attr_next = a->dw_attr_next->dw_attr_next;
2499 /* Discard the children of this DIE. */
2502 remove_children (die)
2503 register dw_die_ref die;
2505 register dw_die_ref child_die = die->die_child;
2507 die->die_child = NULL;
2508 die->die_child_last = NULL;
2510 while (child_die != NULL)
2512 register dw_die_ref tmp_die = child_die;
2513 register dw_attr_ref a;
2515 child_die = child_die->die_sib;
2517 for (a = tmp_die->die_attr; a != NULL; )
2519 register dw_attr_ref tmp_a = a;
2521 a = a->dw_attr_next;
2529 /* Add a child DIE below its parent. */
2532 add_child_die (die, child_die)
2533 register dw_die_ref die;
2534 register dw_die_ref child_die;
2536 if (die != NULL && child_die != NULL)
2538 assert (die != child_die);
2539 child_die->die_parent = die;
2540 child_die->die_sib = NULL;
2542 if (die->die_child == NULL)
2544 die->die_child = child_die;
2545 die->die_child_last = child_die;
2549 die->die_child_last->die_sib = child_die;
2550 die->die_child_last = child_die;
2555 /* Return a pointer to a newly created DIE node. */
2557 static inline dw_die_ref
2558 new_die (tag_value, parent_die)
2559 register enum dwarf_tag tag_value;
2560 register dw_die_ref parent_die;
2562 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
2564 die->die_tag = tag_value;
2565 die->die_abbrev = 0;
2566 die->die_offset = 0;
2567 die->die_child = NULL;
2568 die->die_parent = NULL;
2569 die->die_sib = NULL;
2570 die->die_child_last = NULL;
2571 die->die_attr = NULL;
2572 die->die_attr_last = NULL;
2574 if (parent_die != NULL)
2575 add_child_die (parent_die, die);
2582 /* Return the DIE associated with the given type specifier. */
2584 static inline dw_die_ref
2585 lookup_type_die (type)
2588 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
2591 /* Equate a DIE to a given type specifier. */
2594 equate_type_number_to_die (type, type_die)
2596 register dw_die_ref type_die;
2598 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
2601 /* Return the DIE associated with a given declaration. */
2603 static inline dw_die_ref
2604 lookup_decl_die (decl)
2607 register unsigned decl_id = DECL_UID (decl);
2609 return (decl_id < decl_die_table_in_use
2610 ? decl_die_table[decl_id] : NULL);
2613 /* Equate a DIE to a particular declaration. */
2616 equate_decl_number_to_die (decl, decl_die)
2618 register dw_die_ref decl_die;
2620 register unsigned decl_id = DECL_UID (decl);
2621 register unsigned i;
2622 register unsigned num_allocated;
2624 if (decl_id >= decl_die_table_allocated)
2627 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
2628 / DECL_DIE_TABLE_INCREMENT)
2629 * DECL_DIE_TABLE_INCREMENT;
2632 = (dw_die_ref *) xrealloc (decl_die_table,
2633 sizeof (dw_die_ref) * num_allocated);
2635 bzero ((char *) &decl_die_table[decl_die_table_allocated],
2636 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
2637 decl_die_table_allocated = num_allocated;
2640 if (decl_id >= decl_die_table_in_use)
2641 decl_die_table_in_use = (decl_id + 1);
2643 decl_die_table[decl_id] = decl_die;
2646 /* Return a pointer to a newly allocated location description. Location
2647 descriptions are simple expression terms that can be strung
2648 together to form more complicated location (address) descriptions. */
2650 static inline dw_loc_descr_ref
2651 new_loc_descr (op, oprnd1, oprnd2)
2652 register enum dwarf_location_atom op;
2653 register unsigned long oprnd1;
2654 register unsigned long oprnd2;
2656 register dw_loc_descr_ref descr
2657 = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
2659 descr->dw_loc_next = NULL;
2660 descr->dw_loc_opc = op;
2661 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2662 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2663 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2664 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2669 /* Add a location description term to a location description expression. */
2672 add_loc_descr (list_head, descr)
2673 register dw_loc_descr_ref *list_head;
2674 register dw_loc_descr_ref descr;
2676 register dw_loc_descr_ref *d;
2678 /* Find the end of the chain. */
2679 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2685 /* Return a pointer to a newly allocated Call Frame Instruction. */
2687 static inline dw_cfi_ref
2690 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
2692 cfi->dw_cfi_next = NULL;
2693 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
2694 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
2699 /* Add a Call Frame Instruction to list of instructions. */
2702 add_cfi (list_head, cfi)
2703 register dw_cfi_ref *list_head;
2704 register dw_cfi_ref cfi;
2706 register dw_cfi_ref *p;
2708 /* Find the end of the chain. */
2709 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
2715 /* Keep track of the number of spaces used to indent the
2716 output of the debugging routines that print the structure of
2717 the DIE internal representation. */
2718 static int print_indent;
2720 /* Indent the line the number of spaces given by print_indent. */
2723 print_spaces (outfile)
2726 fprintf (outfile, "%*s", print_indent, "");
2729 /* Print the information assoaciated with a given DIE, and its children.
2730 This routine is a debugging aid only. */
2733 print_die (die, outfile)
2737 register dw_attr_ref a;
2738 register dw_die_ref c;
2740 print_spaces (outfile);
2741 fprintf (outfile, "DIE %4u: %s\n",
2742 die->die_offset, dwarf_tag_name (die->die_tag));
2743 print_spaces (outfile);
2744 fprintf (outfile, " abbrev id: %u", die->die_abbrev);
2745 fprintf (outfile, " offset: %u\n", die->die_offset);
2747 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2749 print_spaces (outfile);
2750 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
2752 switch (a->dw_attr_val.val_class)
2754 case dw_val_class_addr:
2755 fprintf (outfile, "address");
2757 case dw_val_class_loc:
2758 fprintf (outfile, "location descriptor");
2760 case dw_val_class_const:
2761 fprintf (outfile, "%d", a->dw_attr_val.v.val_int);
2763 case dw_val_class_unsigned_const:
2764 fprintf (outfile, "%u", a->dw_attr_val.v.val_unsigned);
2766 case dw_val_class_long_long:
2767 fprintf (outfile, "constant (%u,%u)",
2768 a->dw_attr_val.v.val_long_long.hi,
2769 a->dw_attr_val.v.val_long_long.low);
2771 case dw_val_class_float:
2772 fprintf (outfile, "floating-point constant");
2774 case dw_val_class_flag:
2775 fprintf (outfile, "%u", a->dw_attr_val.v.val_flag);
2777 case dw_val_class_die_ref:
2778 if (a->dw_attr_val.v.val_die_ref != NULL)
2779 fprintf (outfile, "die -> %u",
2780 a->dw_attr_val.v.val_die_ref->die_offset);
2782 fprintf (outfile, "die -> <null>");
2784 case dw_val_class_lbl_id:
2785 fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id);
2787 case dw_val_class_section_offset:
2788 fprintf (outfile, "section: %s", a->dw_attr_val.v.val_section);
2790 case dw_val_class_str:
2791 if (a->dw_attr_val.v.val_str != NULL)
2792 fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str);
2794 fprintf (outfile, "<null>");
2798 fprintf (outfile, "\n");
2801 if (die->die_child != NULL)
2804 for (c = die->die_child; c != NULL; c = c->die_sib)
2805 print_die (c, outfile);
2811 /* Print the contents of the source code line number correspondence table.
2812 This routine is a debugging aid only. */
2815 print_dwarf_line_table (outfile)
2818 register unsigned i;
2819 register dw_line_info_ref line_info;
2821 fprintf (outfile, "\n\nDWARF source line information\n");
2822 for (i = 1; i < line_info_table_in_use; ++i)
2824 line_info = &line_info_table[i];
2825 fprintf (outfile, "%5d: ", i);
2826 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
2827 fprintf (outfile, "%6d", line_info->dw_line_num);
2828 fprintf (outfile, "\n");
2831 fprintf (outfile, "\n\n");
2834 /* Print the information collected for a given DIE. */
2837 debug_dwarf_die (die)
2840 print_die (die, stderr);
2843 /* Print all DWARF information collected for the compilation unit.
2844 This routine is a debugging aid only. */
2850 print_die (comp_unit_die, stderr);
2851 print_dwarf_line_table (stderr);
2854 /* Traverse the DIE, and add a sibling attribute if it may have the
2855 effect of speeding up access to siblings. To save some space,
2856 avoid generating sibling attributes for DIE's without children. */
2859 add_sibling_attributes(die)
2860 register dw_die_ref die;
2862 register dw_die_ref c;
2863 register dw_attr_ref attr;
2864 if (die != comp_unit_die && die->die_child != NULL)
2866 attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2867 attr->dw_attr_next = NULL;
2868 attr->dw_attr = DW_AT_sibling;
2869 attr->dw_attr_val.val_class = dw_val_class_die_ref;
2870 attr->dw_attr_val.v.val_die_ref = die->die_sib;
2872 /* Add the sibling link to the front of the attribute list. */
2873 attr->dw_attr_next = die->die_attr;
2874 if (die->die_attr == NULL)
2875 die->die_attr_last = attr;
2877 die->die_attr = attr;
2880 for (c = die->die_child; c != NULL; c = c->die_sib)
2881 add_sibling_attributes (c);
2884 /* The format of each DIE (and its attribute value pairs)
2885 is encoded in an abbreviation table. This routine builds the
2886 abbreviation table and assigns a unique abbreviation id for
2887 each abbreviation entry. The children of each die are visited
2891 build_abbrev_table (die)
2892 register dw_die_ref die;
2894 register unsigned long abbrev_id;
2895 register unsigned long n_alloc;
2896 register dw_die_ref c;
2897 register dw_attr_ref d_attr, a_attr;
2898 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
2900 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
2902 if (abbrev->die_tag == die->die_tag)
2904 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
2906 a_attr = abbrev->die_attr;
2907 d_attr = die->die_attr;
2909 while (a_attr != NULL && d_attr != NULL)
2911 if ((a_attr->dw_attr != d_attr->dw_attr)
2912 || (value_format (&a_attr->dw_attr_val)
2913 != value_format (&d_attr->dw_attr_val)))
2916 a_attr = a_attr->dw_attr_next;
2917 d_attr = d_attr->dw_attr_next;
2920 if (a_attr == NULL && d_attr == NULL)
2926 if (abbrev_id >= abbrev_die_table_in_use)
2928 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
2930 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
2932 = (dw_die_ref *) xmalloc (abbrev_die_table,
2933 sizeof (dw_die_ref) * n_alloc);
2935 bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
2936 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
2937 abbrev_die_table_allocated = n_alloc;
2940 ++abbrev_die_table_in_use;
2941 abbrev_die_table[abbrev_id] = die;
2944 die->die_abbrev = abbrev_id;
2945 for (c = die->die_child; c != NULL; c = c->die_sib)
2946 build_abbrev_table (c);
2949 /* Return the size of an unsigned LEB128 quantity. */
2951 static inline unsigned long
2952 size_of_uleb128 (value)
2953 register unsigned long value;
2955 register unsigned long size = 0;
2956 register unsigned byte;
2960 byte = (value & 0x7f);
2969 /* Return the size of a signed LEB128 quantity. */
2971 static inline unsigned long
2972 size_of_sleb128 (value)
2973 register long value;
2975 register unsigned long size = 0;
2976 register unsigned byte;
2980 byte = (value & 0x7f);
2984 while (!(((value == 0) && ((byte & 0x40) == 0))
2985 || ((value == -1) && ((byte & 0x40) != 0))));
2990 /* Return the size of a string, including the null byte. */
2992 static unsigned long
2993 size_of_string (str)
2996 register unsigned long size = 0;
2997 register unsigned long slen = strlen (str);
2998 register unsigned long i;
2999 register unsigned c;
3001 for (i = 0; i < slen; ++i)
3010 /* Null terminator. */
3015 /* Return the size of a location descriptor. */
3017 static unsigned long
3018 size_of_loc_descr (loc)
3019 register dw_loc_descr_ref loc;
3021 register unsigned long size = 1;
3023 switch (loc->dw_loc_opc)
3045 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3048 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3053 case DW_OP_plus_uconst:
3054 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3092 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3095 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3098 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3101 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3102 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3105 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3107 case DW_OP_deref_size:
3108 case DW_OP_xderef_size:
3118 /* Return the size of a series of location descriptors. */
3120 static unsigned long
3122 register dw_loc_descr_ref loc;
3124 register unsigned long size = 0;
3126 for (; loc != NULL; loc = loc->dw_loc_next)
3127 size += size_of_loc_descr (loc);
3132 /* Return the power-of-two number of bytes necessary to represent VALUE. */
3135 constant_size (value)
3136 long unsigned value;
3143 log = floor_log2 (value);
3146 log = 1 << (floor_log2 (log) + 1);
3148 return MIN (log, 4);
3151 /* Return the size of a DIE, as it is represented in the
3152 .debug_info section. */
3154 static unsigned long
3156 register dw_die_ref die;
3158 register unsigned long size = 0;
3159 register dw_attr_ref a;
3161 size += size_of_uleb128 (die->die_abbrev);
3162 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3164 switch (a->dw_attr_val.val_class)
3166 case dw_val_class_addr:
3169 case dw_val_class_loc:
3171 register unsigned long lsize
3172 = size_of_locs (a->dw_attr_val.v.val_loc);
3175 size += constant_size (lsize);
3179 case dw_val_class_const:
3182 case dw_val_class_unsigned_const:
3183 size += constant_size (a->dw_attr_val.v.val_unsigned);
3185 case dw_val_class_long_long:
3186 size += 1 + 8; /* block */
3188 case dw_val_class_float:
3189 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
3191 case dw_val_class_flag:
3194 case dw_val_class_die_ref:
3195 size += DWARF_OFFSET_SIZE;
3197 case dw_val_class_fde_ref:
3198 size += DWARF_OFFSET_SIZE;
3200 case dw_val_class_lbl_id:
3203 case dw_val_class_section_offset:
3204 size += DWARF_OFFSET_SIZE;
3206 case dw_val_class_str:
3207 size += size_of_string (a->dw_attr_val.v.val_str);
3217 /* Size the debgging information associted with a given DIE.
3218 Visits the DIE's children recursively. Updates the global
3219 variable next_die_offset, on each time through. Uses the
3220 current value of next_die_offset to updete the die_offset
3221 field in each DIE. */
3224 calc_die_sizes (die)
3227 register dw_die_ref c;
3228 die->die_offset = next_die_offset;
3229 next_die_offset += size_of_die (die);
3231 for (c = die->die_child; c != NULL; c = c->die_sib)
3234 if (die->die_child != NULL)
3235 /* Count the null byte used to terminate sibling lists. */
3236 next_die_offset += 1;
3239 /* Return the size of the line information prolog generated for the
3240 compilation unit. */
3242 static unsigned long
3243 size_of_line_prolog ()
3245 register unsigned long size;
3246 register unsigned long ft_index;
3248 size = DWARF_LINE_PROLOG_HEADER_SIZE;
3250 /* Count the size of the table giving number of args for each
3252 size += DWARF_LINE_OPCODE_BASE - 1;
3254 /* Include directory table is empty (at present). Count only the
3255 the null byte used to terminate the table. */
3258 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
3260 /* File name entry. */
3261 size += size_of_string (file_table[ft_index]);
3263 /* Include directory index. */
3264 size += size_of_uleb128 (0);
3266 /* Modification time. */
3267 size += size_of_uleb128 (0);
3269 /* File length in bytes. */
3270 size += size_of_uleb128 (0);
3273 /* Count the file table terminator. */
3278 /* Return the size of the line information generated for this
3279 compilation unit. */
3281 static unsigned long
3282 size_of_line_info ()
3284 register unsigned long size;
3285 register unsigned long lt_index;
3286 register unsigned long current_line;
3287 register long line_offset;
3288 register long line_delta;
3289 register unsigned long current_file;
3290 register unsigned long function;
3292 /* Version number. */
3295 /* Prolog length specifier. */
3296 size += DWARF_OFFSET_SIZE;
3299 size += size_of_line_prolog ();
3301 /* Set address register instruction. */
3302 size += 1 + size_of_uleb128 (1 + PTR_SIZE) + 1 + PTR_SIZE;
3306 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
3308 register dw_line_info_ref line_info;
3310 /* Advance pc instruction. */
3312 line_info = &line_info_table[lt_index];
3313 if (line_info->dw_file_num != current_file)
3315 /* Set file number instruction. */
3317 current_file = line_info->dw_file_num;
3318 size += size_of_uleb128 (current_file);
3321 if (line_info->dw_line_num != current_line)
3323 line_offset = line_info->dw_line_num - current_line;
3324 line_delta = line_offset - DWARF_LINE_BASE;
3325 current_line = line_info->dw_line_num;
3326 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
3327 /* 1-byte special line number instruction. */
3331 /* Advance line instruction. */
3333 size += size_of_sleb128 (line_offset);
3334 /* Generate line entry instruction. */
3340 /* Advance pc instruction. */
3343 /* End of line number info. marker. */
3344 size += 1 + size_of_uleb128 (1) + 1;
3349 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
3351 register dw_separate_line_info_ref line_info
3352 = &separate_line_info_table[lt_index];
3353 if (function != line_info->function)
3355 function = line_info->function;
3356 /* Set address register instruction. */
3357 size += 1 + size_of_uleb128 (1 + PTR_SIZE) + 1 + PTR_SIZE;
3360 /* Advance pc instruction. */
3363 if (line_info->dw_file_num != current_file)
3365 /* Set file number instruction. */
3367 current_file = line_info->dw_file_num;
3368 size += size_of_uleb128 (current_file);
3371 if (line_info->dw_line_num != current_line)
3373 line_offset = line_info->dw_line_num - current_line;
3374 line_delta = line_offset - DWARF_LINE_BASE;
3375 current_line = line_info->dw_line_num;
3376 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
3377 /* 1-byte special line number instruction. */
3381 /* Advance line instruction. */
3383 size += size_of_sleb128 (line_offset);
3385 /* Generate line entry instruction. */
3392 /* If we're done with a function, end its sequence. */
3393 if (lt_index == separate_line_info_table_in_use
3394 || separate_line_info_table[lt_index].function != function)
3399 /* Advance pc instruction. */
3402 /* End of line number info. marker. */
3403 size += 1 + size_of_uleb128 (1) + 1;
3410 /* Return the size of the .debug_pubnames table generated for the
3411 compilation unit. */
3413 static unsigned long
3416 register unsigned long size;
3417 register unsigned i;
3419 size = DWARF_PUBNAMES_HEADER_SIZE;
3420 for (i = 0; i < pubname_table_in_use; ++i)
3422 register pubname_ref p = &pubname_table[i];
3423 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
3426 size += DWARF_OFFSET_SIZE;
3430 /* Return the size of the information in the .debug_aranges seciton. */
3432 static unsigned long
3435 register unsigned long size;
3437 size = DWARF_ARANGES_HEADER_SIZE;
3439 /* Count the address/length pair for this compilation unit. */
3440 size += 2 * PTR_SIZE;
3441 size += 2 * PTR_SIZE * arange_table_in_use;
3443 /* Count the two zero words used to terminated the address range table. */
3444 size += 2 * PTR_SIZE;
3448 /* Output an unsigned LEB128 quantity. */
3451 output_uleb128 (value)
3452 register unsigned long value;
3454 unsigned long save_value = value;
3456 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
3459 register unsigned byte = (value & 0x7f);
3462 /* More bytes to follow. */
3465 fprintf (asm_out_file, "0x%x", byte);
3467 fprintf (asm_out_file, ",");
3471 if (flag_verbose_asm)
3472 fprintf (asm_out_file, "\t%s ULEB128 0x%x", ASM_COMMENT_START, save_value);
3475 /* Output an signed LEB128 quantity. */
3478 output_sleb128 (value)
3479 register long value;
3482 register unsigned byte;
3483 long save_value = value;
3485 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
3488 byte = (value & 0x7f);
3489 /* arithmetic shift */
3491 more = !((((value == 0) && ((byte & 0x40) == 0))
3492 || ((value == -1) && ((byte & 0x40) != 0))));
3496 fprintf (asm_out_file, "0x%x", byte);
3498 fprintf (asm_out_file, ",");
3502 if (flag_verbose_asm)
3503 fprintf (asm_out_file, "\t%s SLEB128 %d", ASM_COMMENT_START, save_value);
3506 /* Select the encoding of an attribute value. */
3508 static enum dwarf_form
3512 switch (v->val_class)
3514 case dw_val_class_addr:
3515 return DW_FORM_addr;
3516 case dw_val_class_loc:
3517 switch (constant_size (size_of_locs (v->v.val_loc)))
3520 return DW_FORM_block1;
3522 return DW_FORM_block2;
3526 case dw_val_class_const:
3527 return DW_FORM_data4;
3528 case dw_val_class_unsigned_const:
3529 switch (constant_size (v->v.val_unsigned))
3532 return DW_FORM_data1;
3534 return DW_FORM_data2;
3536 return DW_FORM_data4;
3538 return DW_FORM_data8;
3542 case dw_val_class_long_long:
3543 return DW_FORM_block1;
3544 case dw_val_class_float:
3545 return DW_FORM_block1;
3546 case dw_val_class_flag:
3547 return DW_FORM_flag;
3548 case dw_val_class_die_ref:
3550 case dw_val_class_fde_ref:
3551 return DW_FORM_data;
3552 case dw_val_class_lbl_id:
3553 return DW_FORM_addr;
3554 case dw_val_class_section_offset:
3555 return DW_FORM_data;
3556 case dw_val_class_str:
3557 return DW_FORM_string;
3563 /* Output the encoding of an attribute value. */
3566 output_value_format (v)
3569 enum dwarf_form form = value_format (v);
3571 output_uleb128 (form);
3572 if (flag_verbose_asm)
3573 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
3575 fputc ('\n', asm_out_file);
3578 /* Output the .debug_abbrev section which defines the DIE abbreviation
3582 output_abbrev_section ()
3584 unsigned long abbrev_id;
3587 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
3589 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
3591 output_uleb128 (abbrev_id);
3592 if (flag_verbose_asm)
3593 fprintf (asm_out_file, " (abbrev code)");
3595 fputc ('\n', asm_out_file);
3596 output_uleb128 (abbrev->die_tag);
3597 if (flag_verbose_asm)
3598 fprintf (asm_out_file, " (TAG: %s)",
3599 dwarf_tag_name (abbrev->die_tag));
3601 fputc ('\n', asm_out_file);
3602 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
3603 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
3605 if (flag_verbose_asm)
3606 fprintf (asm_out_file, "\t%s %s",
3608 (abbrev->die_child != NULL
3609 ? "DW_children_yes" : "DW_children_no"));
3611 fputc ('\n', asm_out_file);
3613 for (a_attr = abbrev->die_attr; a_attr != NULL;
3614 a_attr = a_attr->dw_attr_next)
3616 output_uleb128 (a_attr->dw_attr);
3617 if (flag_verbose_asm)
3618 fprintf (asm_out_file, " (%s)",
3619 dwarf_attr_name (a_attr->dw_attr));
3621 fputc ('\n', asm_out_file);
3622 output_value_format (&a_attr->dw_attr_val);
3625 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
3629 /* Output location description stack opcode's operands (if any). */
3632 output_loc_operands (loc)
3633 register dw_loc_descr_ref loc;
3635 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
3636 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
3638 switch (loc->dw_loc_opc)
3641 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
3642 fputc ('\n', asm_out_file);
3646 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
3647 fputc ('\n', asm_out_file);