1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
10 support in dwarfread.c
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or (at
17 your option) any later version.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. */
35 #include "elf/dwarf2.h"
38 #include "expression.h"
39 #include "filenames.h" /* for DOSish file names */
42 #include "complaints.h"
45 #include "gdb_string.h"
46 #include "gdb_assert.h"
47 #include <sys/types.h>
49 #ifndef DWARF2_REG_TO_REGNUM
50 #define DWARF2_REG_TO_REGNUM(REG) (REG)
54 /* .debug_info header for a compilation unit
55 Because of alignment constraints, this structure has padding and cannot
56 be mapped directly onto the beginning of the .debug_info section. */
57 typedef struct comp_unit_header
59 unsigned int length
; /* length of the .debug_info
61 unsigned short version
; /* version number -- 2 for DWARF
63 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
64 unsigned char addr_size
; /* byte size of an address -- 4 */
67 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
70 /* .debug_pubnames header
71 Because of alignment constraints, this structure has padding and cannot
72 be mapped directly onto the beginning of the .debug_info section. */
73 typedef struct pubnames_header
75 unsigned int length
; /* length of the .debug_pubnames
77 unsigned char version
; /* version number -- 2 for DWARF
79 unsigned int info_offset
; /* offset into .debug_info section */
80 unsigned int info_size
; /* byte size of .debug_info section
84 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
86 /* .debug_pubnames header
87 Because of alignment constraints, this structure has padding and cannot
88 be mapped directly onto the beginning of the .debug_info section. */
89 typedef struct aranges_header
91 unsigned int length
; /* byte len of the .debug_aranges
93 unsigned short version
; /* version number -- 2 for DWARF
95 unsigned int info_offset
; /* offset into .debug_info section */
96 unsigned char addr_size
; /* byte size of an address */
97 unsigned char seg_size
; /* byte size of segment descriptor */
100 #define _ACTUAL_ARANGES_HEADER_SIZE 12
102 /* .debug_line statement program prologue
103 Because of alignment constraints, this structure has padding and cannot
104 be mapped directly onto the beginning of the .debug_info section. */
105 typedef struct statement_prologue
107 unsigned int total_length
; /* byte length of the statement
109 unsigned short version
; /* version number -- 2 for DWARF
111 unsigned int prologue_length
; /* # bytes between prologue &
113 unsigned char minimum_instruction_length
; /* byte size of
115 unsigned char default_is_stmt
; /* initial value of is_stmt
118 unsigned char line_range
;
119 unsigned char opcode_base
; /* number assigned to first special
121 unsigned char *standard_opcode_lengths
;
125 /* offsets and sizes of debugging sections */
127 static file_ptr dwarf_info_offset
;
128 static file_ptr dwarf_abbrev_offset
;
129 static file_ptr dwarf_line_offset
;
130 static file_ptr dwarf_pubnames_offset
;
131 static file_ptr dwarf_aranges_offset
;
132 static file_ptr dwarf_loc_offset
;
133 static file_ptr dwarf_macinfo_offset
;
134 static file_ptr dwarf_str_offset
;
136 static unsigned int dwarf_info_size
;
137 static unsigned int dwarf_abbrev_size
;
138 static unsigned int dwarf_line_size
;
139 static unsigned int dwarf_pubnames_size
;
140 static unsigned int dwarf_aranges_size
;
141 static unsigned int dwarf_loc_size
;
142 static unsigned int dwarf_macinfo_size
;
143 static unsigned int dwarf_str_size
;
145 /* names of the debugging sections */
147 #define INFO_SECTION ".debug_info"
148 #define ABBREV_SECTION ".debug_abbrev"
149 #define LINE_SECTION ".debug_line"
150 #define PUBNAMES_SECTION ".debug_pubnames"
151 #define ARANGES_SECTION ".debug_aranges"
152 #define LOC_SECTION ".debug_loc"
153 #define MACINFO_SECTION ".debug_macinfo"
154 #define STR_SECTION ".debug_str"
156 /* local data types */
158 /* The data in a compilation unit header, after target2host
159 translation, looks like this. */
160 struct comp_unit_head
162 unsigned long length
;
164 unsigned int abbrev_offset
;
165 unsigned char addr_size
;
166 unsigned char signed_addr_p
;
167 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
168 unsigned int initial_length_size
; /* size of the length field; either
172 /* The data in the .debug_line statement prologue looks like this. */
175 unsigned int total_length
;
176 unsigned short version
;
177 unsigned int prologue_length
;
178 unsigned char minimum_instruction_length
;
179 unsigned char default_is_stmt
;
181 unsigned char line_range
;
182 unsigned char opcode_base
;
183 unsigned char *standard_opcode_lengths
;
186 /* When we construct a partial symbol table entry we only
187 need this much information. */
188 struct partial_die_info
191 unsigned char has_children
;
192 unsigned char is_external
;
193 unsigned char is_declaration
;
194 unsigned char has_type
;
201 struct dwarf_block
*locdesc
;
202 unsigned int language
;
206 /* This data structure holds the information of an abbrev. */
209 unsigned int number
; /* number identifying abbrev */
210 enum dwarf_tag tag
; /* dwarf tag */
211 int has_children
; /* boolean */
212 unsigned int num_attrs
; /* number of attributes */
213 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
214 struct abbrev_info
*next
; /* next in chain */
219 enum dwarf_attribute name
;
220 enum dwarf_form form
;
223 /* This data structure holds a complete die structure. */
226 enum dwarf_tag tag
; /* Tag indicating type of die */
227 unsigned short has_children
; /* Does the die have children */
228 unsigned int abbrev
; /* Abbrev number */
229 unsigned int offset
; /* Offset in .debug_info section */
230 unsigned int num_attrs
; /* Number of attributes */
231 struct attribute
*attrs
; /* An array of attributes */
232 struct die_info
*next_ref
; /* Next die in ref hash table */
233 struct die_info
*next
; /* Next die in linked list */
234 struct type
*type
; /* Cached type information */
237 /* Attributes have a name and a value */
240 enum dwarf_attribute name
;
241 enum dwarf_form form
;
245 struct dwarf_block
*blk
;
253 /* Get at parts of an attribute structure */
255 #define DW_STRING(attr) ((attr)->u.str)
256 #define DW_UNSND(attr) ((attr)->u.unsnd)
257 #define DW_BLOCK(attr) ((attr)->u.blk)
258 #define DW_SND(attr) ((attr)->u.snd)
259 #define DW_ADDR(attr) ((attr)->u.addr)
261 /* Blocks are a bunch of untyped bytes. */
268 /* We only hold one compilation unit's abbrevs in
269 memory at any one time. */
270 #ifndef ABBREV_HASH_SIZE
271 #define ABBREV_HASH_SIZE 121
273 #ifndef ATTR_ALLOC_CHUNK
274 #define ATTR_ALLOC_CHUNK 4
277 static struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
279 /* A hash table of die offsets for following references. */
280 #ifndef REF_HASH_SIZE
281 #define REF_HASH_SIZE 1021
284 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
286 /* Obstack for allocating temporary storage used during symbol reading. */
287 static struct obstack dwarf2_tmp_obstack
;
289 /* Offset to the first byte of the current compilation unit header,
290 for resolving relative reference dies. */
291 static unsigned int cu_header_offset
;
293 /* Allocate fields for structs, unions and enums in this size. */
294 #ifndef DW_FIELD_ALLOC_CHUNK
295 #define DW_FIELD_ALLOC_CHUNK 4
298 /* The language we are debugging. */
299 static enum language cu_language
;
300 static const struct language_defn
*cu_language_defn
;
302 /* Actually data from the sections. */
303 static char *dwarf_info_buffer
;
304 static char *dwarf_abbrev_buffer
;
305 static char *dwarf_line_buffer
;
306 static char *dwarf_str_buffer
;
308 /* A zeroed version of a partial die for initialization purposes. */
309 static struct partial_die_info zeroed_partial_die
;
311 /* The generic symbol table building routines have separate lists for
312 file scope symbols and all all other scopes (local scopes). So
313 we need to select the right one to pass to add_symbol_to_list().
314 We do it by keeping a pointer to the correct list in list_in_scope.
316 FIXME: The original dwarf code just treated the file scope as the first
317 local scope, and all other local scopes as nested local scopes, and worked
318 fine. Check to see if we really need to distinguish these
320 static struct pending
**list_in_scope
= &file_symbols
;
322 /* FIXME: decode_locdesc sets these variables to describe the location
323 to the caller. These ought to be a structure or something. If
324 none of the flags are set, the object lives at the address returned
325 by decode_locdesc. */
327 static int optimized_out
; /* No ops in location in expression,
328 so object was optimized out. */
329 static int isreg
; /* Object lives in register.
330 decode_locdesc's return value is
331 the register number. */
332 static int offreg
; /* Object's address is the sum of the
333 register specified by basereg, plus
334 the offset returned. */
335 static int basereg
; /* See `offreg'. */
336 static int isderef
; /* Value described by flags above is
337 the address of a pointer to the object. */
338 static int islocal
; /* Variable is at the returned offset
339 from the frame start, but there's
340 no identified frame pointer for
341 this function, so we can't say
342 which register it's relative to;
345 /* DW_AT_frame_base values for the current function.
346 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
347 contains the register number for the frame register.
348 frame_base_offset is the offset from the frame register to the
349 virtual stack frame. */
350 static int frame_base_reg
;
351 static CORE_ADDR frame_base_offset
;
353 /* This value is added to each symbol value. FIXME: Generalize to
354 the section_offsets structure used by dbxread (once this is done,
355 pass the appropriate section number to end_symtab). */
356 static CORE_ADDR baseaddr
; /* Add to each symbol value */
358 /* We put a pointer to this structure in the read_symtab_private field
360 The complete dwarf information for an objfile is kept in the
361 psymbol_obstack, so that absolute die references can be handled.
362 Most of the information in this structure is related to an entire
363 object file and could be passed via the sym_private field of the objfile.
364 It is however conceivable that dwarf2 might not be the only type
365 of symbols read from an object file. */
369 /* Pointer to start of dwarf info buffer for the objfile. */
371 char *dwarf_info_buffer
;
373 /* Offset in dwarf_info_buffer for this compilation unit. */
375 unsigned long dwarf_info_offset
;
377 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
379 char *dwarf_abbrev_buffer
;
381 /* Size of dwarf abbreviation section for the objfile. */
383 unsigned int dwarf_abbrev_size
;
385 /* Pointer to start of dwarf line buffer for the objfile. */
387 char *dwarf_line_buffer
;
389 /* Pointer to start of dwarf string buffer for the objfile. */
391 char *dwarf_str_buffer
;
393 /* Size of dwarf string section for the objfile. */
395 unsigned int dwarf_str_size
;
398 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
399 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
400 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
401 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
402 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
403 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
404 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
405 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
407 /* Maintain an array of referenced fundamental types for the current
408 compilation unit being read. For DWARF version 1, we have to construct
409 the fundamental types on the fly, since no information about the
410 fundamental types is supplied. Each such fundamental type is created by
411 calling a language dependent routine to create the type, and then a
412 pointer to that type is then placed in the array at the index specified
413 by it's FT_<TYPENAME> value. The array has a fixed size set by the
414 FT_NUM_MEMBERS compile time constant, which is the number of predefined
415 fundamental types gdb knows how to construct. */
416 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
418 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
419 but this would require a corresponding change in unpack_field_as_long
421 static int bits_per_byte
= 8;
423 /* The routines that read and process dies for a C struct or C++ class
424 pass lists of data member fields and lists of member function fields
425 in an instance of a field_info structure, as defined below. */
428 /* List of data member and baseclasses fields. */
431 struct nextfield
*next
;
438 /* Number of fields. */
441 /* Number of baseclasses. */
444 /* Set if the accesibility of one of the fields is not public. */
445 int non_public_fields
;
447 /* Member function fields array, entries are allocated in the order they
448 are encountered in the object file. */
451 struct nextfnfield
*next
;
452 struct fn_field fnfield
;
456 /* Member function fieldlist array, contains name of possibly overloaded
457 member function, number of overloaded member functions and a pointer
458 to the head of the member function field chain. */
463 struct nextfnfield
*head
;
467 /* Number of entries in the fnfieldlists array. */
471 /* FIXME: Kludge to mark a varargs function type for C++ member function
472 argument processing. */
473 #define TYPE_FLAG_VARARGS (1 << 10)
475 /* Dwarf2 has no clean way to discern C++ static and non-static member
476 functions. G++ helps GDB by marking the first parameter for non-static
477 member functions (which is the this pointer) as artificial.
478 We pass this information between dwarf2_add_member_fn and
479 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
480 #define TYPE_FIELD_ARTIFICIAL TYPE_FIELD_BITPOS
482 /* Various complaints about symbol reading that don't abort the process */
484 static struct complaint dwarf2_const_ignored
=
486 "type qualifier 'const' ignored", 0, 0
488 static struct complaint dwarf2_volatile_ignored
=
490 "type qualifier 'volatile' ignored", 0, 0
492 static struct complaint dwarf2_non_const_array_bound_ignored
=
494 "non-constant array bounds form '%s' ignored", 0, 0
496 static struct complaint dwarf2_missing_line_number_section
=
498 "missing .debug_line section", 0, 0
500 static struct complaint dwarf2_mangled_line_number_section
=
502 "mangled .debug_line section", 0, 0
504 static struct complaint dwarf2_unsupported_die_ref_attr
=
506 "unsupported die ref attribute form: '%s'", 0, 0
508 static struct complaint dwarf2_unsupported_stack_op
=
510 "unsupported stack op: '%s'", 0, 0
512 static struct complaint dwarf2_complex_location_expr
=
514 "location expression too complex", 0, 0
516 static struct complaint dwarf2_unsupported_tag
=
518 "unsupported tag: '%s'", 0, 0
520 static struct complaint dwarf2_unsupported_at_encoding
=
522 "unsupported DW_AT_encoding: '%s'", 0, 0
524 static struct complaint dwarf2_unsupported_at_frame_base
=
526 "unsupported DW_AT_frame_base for function '%s'", 0, 0
528 static struct complaint dwarf2_unexpected_tag
=
530 "unexepected tag in read_type_die: '%s'", 0, 0
532 static struct complaint dwarf2_missing_at_frame_base
=
534 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
536 static struct complaint dwarf2_bad_static_member_name
=
538 "unrecognized static data member name '%s'", 0, 0
540 static struct complaint dwarf2_unsupported_accessibility
=
542 "unsupported accessibility %d", 0, 0
544 static struct complaint dwarf2_bad_member_name_complaint
=
546 "cannot extract member name from '%s'", 0, 0
548 static struct complaint dwarf2_missing_member_fn_type_complaint
=
550 "member function type missing for '%s'", 0, 0
552 static struct complaint dwarf2_vtbl_not_found_complaint
=
554 "virtual function table pointer not found when defining class '%s'", 0, 0
556 static struct complaint dwarf2_absolute_sibling_complaint
=
558 "ignoring absolute DW_AT_sibling", 0, 0
560 static struct complaint dwarf2_const_value_length_mismatch
=
562 "const value length mismatch for '%s', got %d, expected %d", 0, 0
564 static struct complaint dwarf2_unsupported_const_value_attr
=
566 "unsupported const value attribute form: '%s'", 0, 0
569 /* local function prototypes */
571 static void dwarf2_locate_sections (bfd
*, asection
*, PTR
);
574 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
577 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
579 static char *scan_partial_symbols (char *, struct objfile
*,
580 CORE_ADDR
*, CORE_ADDR
*,
581 const struct comp_unit_head
*);
583 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
584 const struct comp_unit_head
*);
586 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
588 static void psymtab_to_symtab_1 (struct partial_symtab
*);
590 static char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int);
592 static void dwarf2_read_abbrevs (bfd
*, unsigned int);
594 static void dwarf2_empty_abbrev_table (PTR
);
596 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int);
598 static char *read_partial_die (struct partial_die_info
*,
600 const struct comp_unit_head
*);
602 static char *read_full_die (struct die_info
**, bfd
*, char *,
603 const struct comp_unit_head
*);
605 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
606 bfd
*, char *, const struct comp_unit_head
*);
608 static unsigned int read_1_byte (bfd
*, char *);
610 static int read_1_signed_byte (bfd
*, char *);
612 static unsigned int read_2_bytes (bfd
*, char *);
614 static unsigned int read_4_bytes (bfd
*, char *);
616 static unsigned long read_8_bytes (bfd
*, char *);
618 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
621 static LONGEST
read_initial_length (bfd
*, char *,
622 struct comp_unit_head
*, int *bytes_read
);
624 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
627 static char *read_n_bytes (bfd
*, char *, unsigned int);
629 static char *read_string (bfd
*, char *, unsigned int *);
631 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
634 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
636 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
638 static void set_cu_language (unsigned int);
640 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
642 static int die_is_declaration (struct die_info
*);
644 static void dwarf_decode_lines (unsigned int, char *, bfd
*,
645 const struct comp_unit_head
*);
647 static void dwarf2_start_subfile (char *, char *);
649 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
650 struct objfile
*, const struct comp_unit_head
*);
652 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
653 struct objfile
*, const struct comp_unit_head
*);
655 static void dwarf2_const_value_data (struct attribute
*attr
,
659 static struct type
*die_type (struct die_info
*, struct objfile
*,
660 const struct comp_unit_head
*);
662 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
663 const struct comp_unit_head
*);
666 static struct type
*type_at_offset (unsigned int, struct objfile
*);
669 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
670 const struct comp_unit_head
*);
672 static void read_type_die (struct die_info
*, struct objfile
*,
673 const struct comp_unit_head
*);
675 static void read_typedef (struct die_info
*, struct objfile
*,
676 const struct comp_unit_head
*);
678 static void read_base_type (struct die_info
*, struct objfile
*);
680 static void read_file_scope (struct die_info
*, struct objfile
*,
681 const struct comp_unit_head
*);
683 static void read_func_scope (struct die_info
*, struct objfile
*,
684 const struct comp_unit_head
*);
686 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
687 const struct comp_unit_head
*);
689 static int dwarf2_get_pc_bounds (struct die_info
*,
690 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*);
692 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
693 struct objfile
*, const struct comp_unit_head
*);
695 static void dwarf2_attach_fields_to_type (struct field_info
*,
696 struct type
*, struct objfile
*);
698 static void dwarf2_add_member_fn (struct field_info
*,
699 struct die_info
*, struct type
*,
700 struct objfile
*objfile
,
701 const struct comp_unit_head
*);
703 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
704 struct type
*, struct objfile
*);
706 static void read_structure_scope (struct die_info
*, struct objfile
*,
707 const struct comp_unit_head
*);
709 static void read_common_block (struct die_info
*, struct objfile
*,
710 const struct comp_unit_head
*);
712 static void read_enumeration (struct die_info
*, struct objfile
*,
713 const struct comp_unit_head
*);
715 static struct type
*dwarf_base_type (int, int, struct objfile
*);
717 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
718 const struct comp_unit_head
*);
720 static void read_array_type (struct die_info
*, struct objfile
*,
721 const struct comp_unit_head
*);
723 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
724 const struct comp_unit_head
*);
726 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
727 const struct comp_unit_head
*);
729 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
730 const struct comp_unit_head
*);
732 static void read_tag_const_type (struct die_info
*, struct objfile
*,
733 const struct comp_unit_head
*);
735 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
736 const struct comp_unit_head
*);
738 static void read_tag_string_type (struct die_info
*, struct objfile
*);
740 static void read_subroutine_type (struct die_info
*, struct objfile
*,
741 const struct comp_unit_head
*);
743 static struct die_info
*read_comp_unit (char *, bfd
*,
744 const struct comp_unit_head
*);
746 static void free_die_list (struct die_info
*);
748 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
750 static void process_die (struct die_info
*, struct objfile
*,
751 const struct comp_unit_head
*);
753 static char *dwarf2_linkage_name (struct die_info
*);
755 static char *dwarf_tag_name (unsigned int);
757 static char *dwarf_attr_name (unsigned int);
759 static char *dwarf_form_name (unsigned int);
761 static char *dwarf_stack_op_name (unsigned int);
763 static char *dwarf_bool_name (unsigned int);
765 static char *dwarf_type_encoding_name (unsigned int);
768 static char *dwarf_cfi_name (unsigned int);
770 struct die_info
*copy_die (struct die_info
*);
773 static struct die_info
*sibling_die (struct die_info
*);
775 static void dump_die (struct die_info
*);
777 static void dump_die_list (struct die_info
*);
779 static void store_in_ref_table (unsigned int, struct die_info
*);
781 static void dwarf2_empty_hash_tables (void);
783 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
785 static struct die_info
*follow_die_ref (unsigned int);
787 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
789 /* memory allocation interface */
791 static void dwarf2_free_tmp_obstack (PTR
);
793 static struct dwarf_block
*dwarf_alloc_block (void);
795 static struct abbrev_info
*dwarf_alloc_abbrev (void);
797 static struct die_info
*dwarf_alloc_die (void);
799 /* Try to locate the sections we need for DWARF 2 debugging
800 information and return true if we have enough to do something. */
803 dwarf2_has_info (bfd
*abfd
)
805 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
806 dwarf_str_offset
= 0;
807 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
808 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
818 /* This function is mapped across the sections and remembers the
819 offset and size of each of the debugging sections we are interested
823 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, PTR ignore_ptr
)
825 if (STREQ (sectp
->name
, INFO_SECTION
))
827 dwarf_info_offset
= sectp
->filepos
;
828 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
830 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
832 dwarf_abbrev_offset
= sectp
->filepos
;
833 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
835 else if (STREQ (sectp
->name
, LINE_SECTION
))
837 dwarf_line_offset
= sectp
->filepos
;
838 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
840 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
842 dwarf_pubnames_offset
= sectp
->filepos
;
843 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
845 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
847 dwarf_aranges_offset
= sectp
->filepos
;
848 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
850 else if (STREQ (sectp
->name
, LOC_SECTION
))
852 dwarf_loc_offset
= sectp
->filepos
;
853 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
855 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
857 dwarf_macinfo_offset
= sectp
->filepos
;
858 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
860 else if (STREQ (sectp
->name
, STR_SECTION
))
862 dwarf_str_offset
= sectp
->filepos
;
863 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
867 /* Build a partial symbol table. */
870 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
873 /* We definitely need the .debug_info and .debug_abbrev sections */
875 dwarf_info_buffer
= dwarf2_read_section (objfile
,
878 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
881 dwarf_line_buffer
= dwarf2_read_section (objfile
,
885 if (dwarf_str_offset
)
886 dwarf_str_buffer
= dwarf2_read_section (objfile
,
890 dwarf_str_buffer
= NULL
;
893 || (objfile
->global_psymbols
.size
== 0
894 && objfile
->static_psymbols
.size
== 0))
896 init_psymbol_list (objfile
, 1024);
900 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
902 /* Things are significantly easier if we have .debug_aranges and
903 .debug_pubnames sections */
905 dwarf2_build_psymtabs_easy (objfile
, mainline
);
909 /* only test this case for now */
911 /* In this case we have to work a bit harder */
912 dwarf2_build_psymtabs_hard (objfile
, mainline
);
917 /* Build the partial symbol table from the information in the
918 .debug_pubnames and .debug_aranges sections. */
921 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
923 bfd
*abfd
= objfile
->obfd
;
924 char *aranges_buffer
, *pubnames_buffer
;
925 char *aranges_ptr
, *pubnames_ptr
;
926 unsigned int entry_length
, version
, info_offset
, info_size
;
928 pubnames_buffer
= dwarf2_read_section (objfile
,
929 dwarf_pubnames_offset
,
930 dwarf_pubnames_size
);
931 pubnames_ptr
= pubnames_buffer
;
932 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
934 struct comp_unit_head cu_header
;
937 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
939 pubnames_ptr
+= bytes_read
;
940 version
= read_1_byte (abfd
, pubnames_ptr
);
942 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
944 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
948 aranges_buffer
= dwarf2_read_section (objfile
,
949 dwarf_aranges_offset
,
955 /* Read in the comp unit header information from the debug_info at
959 read_comp_unit_head (struct comp_unit_head
*cu_header
,
960 char *info_ptr
, bfd
*abfd
)
964 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
966 info_ptr
+= bytes_read
;
967 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
969 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
971 info_ptr
+= bytes_read
;
972 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
974 signed_addr
= bfd_get_sign_extend_vma (abfd
);
976 internal_error (__FILE__
, __LINE__
,
977 "read_comp_unit_head: dwarf from non elf file");
978 cu_header
->signed_addr_p
= signed_addr
;
982 /* Build the partial symbol table by doing a quick pass through the
983 .debug_info and .debug_abbrev sections. */
986 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
988 /* Instead of reading this into a big buffer, we should probably use
989 mmap() on architectures that support it. (FIXME) */
990 bfd
*abfd
= objfile
->obfd
;
991 char *info_ptr
, *abbrev_ptr
;
992 char *beg_of_comp_unit
;
993 struct partial_die_info comp_unit_die
;
994 struct partial_symtab
*pst
;
995 struct cleanup
*back_to
;
996 CORE_ADDR lowpc
, highpc
;
998 info_ptr
= dwarf_info_buffer
;
999 abbrev_ptr
= dwarf_abbrev_buffer
;
1001 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1002 the partial symbol scan, like attribute values.
1004 We could reduce our peak memory consumption during partial symbol
1005 table construction by freeing stuff from this obstack more often
1006 --- say, after processing each compilation unit, or each die ---
1007 but it turns out that this saves almost nothing. For an
1008 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1009 on dwarf2_tmp_obstack. Some investigation showed:
1011 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1012 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1013 all fixed-length values not requiring dynamic allocation.
1015 2) 30% of the attributes used the form DW_FORM_string. For
1016 DW_FORM_string, read_attribute simply hands back a pointer to
1017 the null-terminated string in dwarf_info_buffer, so no dynamic
1018 allocation is needed there either.
1020 3) The remaining 1% of the attributes all used DW_FORM_block1.
1021 75% of those were DW_AT_frame_base location lists for
1022 functions; the rest were DW_AT_location attributes, probably
1023 for the global variables.
1025 Anyway, what this all means is that the memory the dwarf2
1026 reader uses as temporary space reading partial symbols is about
1027 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1029 obstack_init (&dwarf2_tmp_obstack
);
1030 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1032 /* Since the objects we're extracting from dwarf_info_buffer vary in
1033 length, only the individual functions to extract them (like
1034 read_comp_unit_head and read_partial_die) can really know whether
1035 the buffer is large enough to hold another complete object.
1037 At the moment, they don't actually check that. If
1038 dwarf_info_buffer holds just one extra byte after the last
1039 compilation unit's dies, then read_comp_unit_head will happily
1040 read off the end of the buffer. read_partial_die is similarly
1041 casual. Those functions should be fixed.
1043 For this loop condition, simply checking whether there's any data
1044 left at all should be sufficient. */
1045 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1047 struct comp_unit_head cu_header
;
1048 beg_of_comp_unit
= info_ptr
;
1049 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1051 if (cu_header
.version
!= 2)
1053 error ("Dwarf Error: wrong version in compilation unit header.");
1056 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
1058 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
1059 (long) cu_header
.abbrev_offset
,
1060 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1063 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1064 > dwarf_info_buffer
+ dwarf_info_size
)
1066 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
1067 (long) cu_header
.length
,
1068 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1071 /* Read the abbrevs for this compilation unit into a table */
1072 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1073 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1075 /* Read the compilation unit die */
1076 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1079 /* Set the language we're debugging */
1080 set_cu_language (comp_unit_die
.language
);
1082 /* Allocate a new partial symbol table structure */
1083 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1084 comp_unit_die
.name
? comp_unit_die
.name
: "",
1085 comp_unit_die
.lowpc
,
1086 objfile
->global_psymbols
.next
,
1087 objfile
->static_psymbols
.next
);
1089 pst
->read_symtab_private
= (char *)
1090 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1091 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1092 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1093 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1094 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1095 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1096 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1097 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1098 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1099 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1101 /* Store the function that reads in the rest of the symbol table */
1102 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1104 /* Check if comp unit has_children.
1105 If so, read the rest of the partial symbols from this comp unit.
1106 If not, there's no more debug_info for this comp unit. */
1107 if (comp_unit_die
.has_children
)
1109 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1112 /* If the compilation unit didn't have an explicit address range,
1113 then use the information extracted from its child dies. */
1114 if (! comp_unit_die
.has_pc_info
)
1116 comp_unit_die
.lowpc
= lowpc
;
1117 comp_unit_die
.highpc
= highpc
;
1120 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1121 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1123 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1124 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1125 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1126 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1127 sort_pst_symbols (pst
);
1129 /* If there is already a psymtab or symtab for a file of this
1130 name, remove it. (If there is a symtab, more drastic things
1131 also happen.) This happens in VxWorks. */
1132 free_named_symtabs (pst
->filename
);
1134 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1135 + cu_header
.initial_length_size
;
1137 do_cleanups (back_to
);
1140 /* Read in all interesting dies to the end of the compilation unit. */
1143 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1144 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1145 const struct comp_unit_head
*cu_header
)
1147 bfd
*abfd
= objfile
->obfd
;
1148 struct partial_die_info pdi
;
1150 /* This function is called after we've read in the comp_unit_die in
1151 order to read its children. We start the nesting level at 1 since
1152 we have pushed 1 level down in order to read the comp unit's children.
1153 The comp unit itself is at level 0, so we stop reading when we pop
1154 back to that level. */
1156 int nesting_level
= 1;
1158 *lowpc
= ((CORE_ADDR
) -1);
1159 *highpc
= ((CORE_ADDR
) 0);
1161 while (nesting_level
)
1163 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1169 case DW_TAG_subprogram
:
1170 if (pdi
.has_pc_info
)
1172 if (pdi
.lowpc
< *lowpc
)
1176 if (pdi
.highpc
> *highpc
)
1178 *highpc
= pdi
.highpc
;
1180 if ((pdi
.is_external
|| nesting_level
== 1)
1181 && !pdi
.is_declaration
)
1183 add_partial_symbol (&pdi
, objfile
, cu_header
);
1187 case DW_TAG_variable
:
1188 case DW_TAG_typedef
:
1189 case DW_TAG_class_type
:
1190 case DW_TAG_structure_type
:
1191 case DW_TAG_union_type
:
1192 case DW_TAG_enumeration_type
:
1193 if ((pdi
.is_external
|| nesting_level
== 1)
1194 && !pdi
.is_declaration
)
1196 add_partial_symbol (&pdi
, objfile
, cu_header
);
1199 case DW_TAG_enumerator
:
1200 /* File scope enumerators are added to the partial symbol
1202 if (nesting_level
== 2)
1203 add_partial_symbol (&pdi
, objfile
, cu_header
);
1205 case DW_TAG_base_type
:
1206 /* File scope base type definitions are added to the partial
1208 if (nesting_level
== 1)
1209 add_partial_symbol (&pdi
, objfile
, cu_header
);
1216 /* If the die has a sibling, skip to the sibling.
1217 Do not skip enumeration types, we want to record their
1219 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1221 info_ptr
= pdi
.sibling
;
1223 else if (pdi
.has_children
)
1225 /* Die has children, but the optional DW_AT_sibling attribute
1236 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1237 from `maint check'. */
1238 if (*lowpc
== ((CORE_ADDR
) -1))
1244 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1245 const struct comp_unit_head
*cu_header
)
1251 case DW_TAG_subprogram
:
1252 if (pdi
->is_external
)
1254 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1255 mst_text, objfile); */
1256 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1257 VAR_NAMESPACE
, LOC_BLOCK
,
1258 &objfile
->global_psymbols
,
1259 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1263 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1264 mst_file_text, objfile); */
1265 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1266 VAR_NAMESPACE
, LOC_BLOCK
,
1267 &objfile
->static_psymbols
,
1268 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1271 case DW_TAG_variable
:
1272 if (pdi
->is_external
)
1275 Don't enter into the minimal symbol tables as there is
1276 a minimal symbol table entry from the ELF symbols already.
1277 Enter into partial symbol table if it has a location
1278 descriptor or a type.
1279 If the location descriptor is missing, new_symbol will create
1280 a LOC_UNRESOLVED symbol, the address of the variable will then
1281 be determined from the minimal symbol table whenever the variable
1283 The address for the partial symbol table entry is not
1284 used by GDB, but it comes in handy for debugging partial symbol
1288 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1289 if (pdi
->locdesc
|| pdi
->has_type
)
1290 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1291 VAR_NAMESPACE
, LOC_STATIC
,
1292 &objfile
->global_psymbols
,
1293 0, addr
+ baseaddr
, cu_language
, objfile
);
1297 /* Static Variable. Skip symbols without location descriptors. */
1298 if (pdi
->locdesc
== NULL
)
1300 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1301 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1302 mst_file_data, objfile); */
1303 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1304 VAR_NAMESPACE
, LOC_STATIC
,
1305 &objfile
->static_psymbols
,
1306 0, addr
+ baseaddr
, cu_language
, objfile
);
1309 case DW_TAG_typedef
:
1310 case DW_TAG_base_type
:
1311 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1312 VAR_NAMESPACE
, LOC_TYPEDEF
,
1313 &objfile
->static_psymbols
,
1314 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1316 case DW_TAG_class_type
:
1317 case DW_TAG_structure_type
:
1318 case DW_TAG_union_type
:
1319 case DW_TAG_enumeration_type
:
1320 /* Skip aggregate types without children, these are external
1322 if (pdi
->has_children
== 0)
1324 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1325 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1326 &objfile
->static_psymbols
,
1327 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1329 if (cu_language
== language_cplus
)
1331 /* For C++, these implicitly act as typedefs as well. */
1332 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1333 VAR_NAMESPACE
, LOC_TYPEDEF
,
1334 &objfile
->static_psymbols
,
1335 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1338 case DW_TAG_enumerator
:
1339 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1340 VAR_NAMESPACE
, LOC_CONST
,
1341 &objfile
->static_psymbols
,
1342 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1349 /* Expand this partial symbol table into a full symbol table. */
1352 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1354 /* FIXME: This is barely more than a stub. */
1359 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1365 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1366 gdb_flush (gdb_stdout
);
1369 psymtab_to_symtab_1 (pst
);
1371 /* Finish up the debug error message. */
1373 printf_filtered ("done.\n");
1379 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1381 struct objfile
*objfile
= pst
->objfile
;
1382 bfd
*abfd
= objfile
->obfd
;
1383 struct comp_unit_head cu_header
;
1384 struct die_info
*dies
;
1385 unsigned long offset
;
1386 CORE_ADDR lowpc
, highpc
;
1387 struct die_info
*child_die
;
1389 struct symtab
*symtab
;
1390 struct cleanup
*back_to
;
1392 /* Set local variables from the partial symbol table info. */
1393 offset
= DWARF_INFO_OFFSET (pst
);
1394 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1395 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1396 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1397 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1398 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1399 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1400 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1401 cu_header_offset
= offset
;
1402 info_ptr
= dwarf_info_buffer
+ offset
;
1404 obstack_init (&dwarf2_tmp_obstack
);
1405 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1408 make_cleanup (really_free_pendings
, NULL
);
1410 /* read in the comp_unit header */
1411 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1413 /* Read the abbrevs for this compilation unit */
1414 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1415 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1417 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1419 make_cleanup_free_die_list (dies
);
1421 /* Do line number decoding in read_file_scope () */
1422 process_die (dies
, objfile
, &cu_header
);
1424 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1426 /* Some compilers don't define a DW_AT_high_pc attribute for
1427 the compilation unit. If the DW_AT_high_pc is missing,
1428 synthesize it, by scanning the DIE's below the compilation unit. */
1430 if (dies
->has_children
)
1432 child_die
= dies
->next
;
1433 while (child_die
&& child_die
->tag
)
1435 if (child_die
->tag
== DW_TAG_subprogram
)
1437 CORE_ADDR low
, high
;
1439 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1441 highpc
= max (highpc
, high
);
1444 child_die
= sibling_die (child_die
);
1448 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1450 /* Set symtab language to language from DW_AT_language.
1451 If the compilation is from a C file generated by language preprocessors,
1452 do not set the language if it was already deduced by start_subfile. */
1454 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1456 symtab
->language
= cu_language
;
1458 pst
->symtab
= symtab
;
1460 sort_symtab_syms (pst
->symtab
);
1462 do_cleanups (back_to
);
1465 /* Process a die and its children. */
1468 process_die (struct die_info
*die
, struct objfile
*objfile
,
1469 const struct comp_unit_head
*cu_header
)
1473 case DW_TAG_padding
:
1475 case DW_TAG_compile_unit
:
1476 read_file_scope (die
, objfile
, cu_header
);
1478 case DW_TAG_subprogram
:
1479 read_subroutine_type (die
, objfile
, cu_header
);
1480 read_func_scope (die
, objfile
, cu_header
);
1482 case DW_TAG_inlined_subroutine
:
1483 /* FIXME: These are ignored for now.
1484 They could be used to set breakpoints on all inlined instances
1485 of a function and make GDB `next' properly over inlined functions. */
1487 case DW_TAG_lexical_block
:
1488 read_lexical_block_scope (die
, objfile
, cu_header
);
1490 case DW_TAG_class_type
:
1491 case DW_TAG_structure_type
:
1492 case DW_TAG_union_type
:
1493 read_structure_scope (die
, objfile
, cu_header
);
1495 case DW_TAG_enumeration_type
:
1496 read_enumeration (die
, objfile
, cu_header
);
1498 case DW_TAG_subroutine_type
:
1499 read_subroutine_type (die
, objfile
, cu_header
);
1501 case DW_TAG_array_type
:
1502 read_array_type (die
, objfile
, cu_header
);
1504 case DW_TAG_pointer_type
:
1505 read_tag_pointer_type (die
, objfile
, cu_header
);
1507 case DW_TAG_ptr_to_member_type
:
1508 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1510 case DW_TAG_reference_type
:
1511 read_tag_reference_type (die
, objfile
, cu_header
);
1513 case DW_TAG_string_type
:
1514 read_tag_string_type (die
, objfile
);
1516 case DW_TAG_base_type
:
1517 read_base_type (die
, objfile
);
1518 if (dwarf_attr (die
, DW_AT_name
))
1520 /* Add a typedef symbol for the base type definition. */
1521 new_symbol (die
, die
->type
, objfile
, cu_header
);
1524 case DW_TAG_common_block
:
1525 read_common_block (die
, objfile
, cu_header
);
1527 case DW_TAG_common_inclusion
:
1530 new_symbol (die
, NULL
, objfile
, cu_header
);
1536 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1537 const struct comp_unit_head
*cu_header
)
1539 unsigned int line_offset
= 0;
1540 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1541 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1542 struct attribute
*attr
;
1543 char *name
= "<unknown>";
1544 char *comp_dir
= NULL
;
1545 struct die_info
*child_die
;
1546 bfd
*abfd
= objfile
->obfd
;
1548 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1550 if (die
->has_children
)
1552 child_die
= die
->next
;
1553 while (child_die
&& child_die
->tag
)
1555 if (child_die
->tag
== DW_TAG_subprogram
)
1557 CORE_ADDR low
, high
;
1559 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1561 lowpc
= min (lowpc
, low
);
1562 highpc
= max (highpc
, high
);
1565 child_die
= sibling_die (child_die
);
1570 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1571 from finish_block. */
1572 if (lowpc
== ((CORE_ADDR
) -1))
1577 attr
= dwarf_attr (die
, DW_AT_name
);
1580 name
= DW_STRING (attr
);
1582 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1585 comp_dir
= DW_STRING (attr
);
1588 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1589 directory, get rid of it. */
1590 char *cp
= strchr (comp_dir
, ':');
1592 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1597 if (objfile
->ei
.entry_point
>= lowpc
&&
1598 objfile
->ei
.entry_point
< highpc
)
1600 objfile
->ei
.entry_file_lowpc
= lowpc
;
1601 objfile
->ei
.entry_file_highpc
= highpc
;
1604 attr
= dwarf_attr (die
, DW_AT_language
);
1607 set_cu_language (DW_UNSND (attr
));
1610 /* We assume that we're processing GCC output. */
1611 processing_gcc_compilation
= 2;
1613 /* FIXME:Do something here. */
1614 if (dip
->at_producer
!= NULL
)
1616 handle_producer (dip
->at_producer
);
1620 /* The compilation unit may be in a different language or objfile,
1621 zero out all remembered fundamental types. */
1622 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1624 start_symtab (name
, comp_dir
, lowpc
);
1625 record_debugformat ("DWARF 2");
1627 /* Decode line number information if present. */
1628 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1631 line_offset
= DW_UNSND (attr
);
1632 dwarf_decode_lines (line_offset
, comp_dir
, abfd
, cu_header
);
1635 /* Process all dies in compilation unit. */
1636 if (die
->has_children
)
1638 child_die
= die
->next
;
1639 while (child_die
&& child_die
->tag
)
1641 process_die (child_die
, objfile
, cu_header
);
1642 child_die
= sibling_die (child_die
);
1648 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
1649 const struct comp_unit_head
*cu_header
)
1651 register struct context_stack
*new;
1654 struct die_info
*child_die
;
1655 struct attribute
*attr
;
1658 name
= dwarf2_linkage_name (die
);
1660 /* Ignore functions with missing or empty names and functions with
1661 missing or invalid low and high pc attributes. */
1662 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1668 if (objfile
->ei
.entry_point
>= lowpc
&&
1669 objfile
->ei
.entry_point
< highpc
)
1671 objfile
->ei
.entry_func_lowpc
= lowpc
;
1672 objfile
->ei
.entry_func_highpc
= highpc
;
1675 /* Decode DW_AT_frame_base location descriptor if present, keep result
1676 for DW_OP_fbreg operands in decode_locdesc. */
1677 frame_base_reg
= -1;
1678 frame_base_offset
= 0;
1679 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1682 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
1684 complain (&dwarf2_unsupported_at_frame_base
, name
);
1686 frame_base_reg
= addr
;
1689 frame_base_reg
= basereg
;
1690 frame_base_offset
= addr
;
1693 complain (&dwarf2_unsupported_at_frame_base
, name
);
1696 new = push_context (0, lowpc
);
1697 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
1698 list_in_scope
= &local_symbols
;
1700 if (die
->has_children
)
1702 child_die
= die
->next
;
1703 while (child_die
&& child_die
->tag
)
1705 process_die (child_die
, objfile
, cu_header
);
1706 child_die
= sibling_die (child_die
);
1710 new = pop_context ();
1711 /* Make a block for the local symbols within. */
1712 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1713 lowpc
, highpc
, objfile
);
1714 list_in_scope
= &file_symbols
;
1717 /* Process all the DIES contained within a lexical block scope. Start
1718 a new scope, process the dies, and then close the scope. */
1721 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
1722 const struct comp_unit_head
*cu_header
)
1724 register struct context_stack
*new;
1725 CORE_ADDR lowpc
, highpc
;
1726 struct die_info
*child_die
;
1728 /* Ignore blocks with missing or invalid low and high pc attributes. */
1729 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1734 push_context (0, lowpc
);
1735 if (die
->has_children
)
1737 child_die
= die
->next
;
1738 while (child_die
&& child_die
->tag
)
1740 process_die (child_die
, objfile
, cu_header
);
1741 child_die
= sibling_die (child_die
);
1744 new = pop_context ();
1746 if (local_symbols
!= NULL
)
1748 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1751 local_symbols
= new->locals
;
1754 /* Get low and high pc attributes from a die.
1755 Return 1 if the attributes are present and valid, otherwise, return 0. */
1758 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1759 struct objfile
*objfile
)
1761 struct attribute
*attr
;
1765 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1767 low
= DW_ADDR (attr
);
1770 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1772 high
= DW_ADDR (attr
);
1779 /* When using the GNU linker, .gnu.linkonce. sections are used to
1780 eliminate duplicate copies of functions and vtables and such.
1781 The linker will arbitrarily choose one and discard the others.
1782 The AT_*_pc values for such functions refer to local labels in
1783 these sections. If the section from that file was discarded, the
1784 labels are not in the output, so the relocs get a value of 0.
1785 If this is a discarded function, mark the pc bounds as invalid,
1786 so that GDB will ignore it. */
1787 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1795 /* Add an aggregate field to the field list. */
1798 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
1799 struct objfile
*objfile
,
1800 const struct comp_unit_head
*cu_header
)
1802 struct nextfield
*new_field
;
1803 struct attribute
*attr
;
1805 char *fieldname
= "";
1807 /* Allocate a new field list entry and link it in. */
1808 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1809 make_cleanup (xfree
, new_field
);
1810 memset (new_field
, 0, sizeof (struct nextfield
));
1811 new_field
->next
= fip
->fields
;
1812 fip
->fields
= new_field
;
1815 /* Handle accessibility and virtuality of field.
1816 The default accessibility for members is public, the default
1817 accessibility for inheritance is private. */
1818 if (die
->tag
!= DW_TAG_inheritance
)
1819 new_field
->accessibility
= DW_ACCESS_public
;
1821 new_field
->accessibility
= DW_ACCESS_private
;
1822 new_field
->virtuality
= DW_VIRTUALITY_none
;
1824 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1826 new_field
->accessibility
= DW_UNSND (attr
);
1827 if (new_field
->accessibility
!= DW_ACCESS_public
)
1828 fip
->non_public_fields
= 1;
1829 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1831 new_field
->virtuality
= DW_UNSND (attr
);
1833 fp
= &new_field
->field
;
1834 if (die
->tag
== DW_TAG_member
)
1836 /* Get type of field. */
1837 fp
->type
= die_type (die
, objfile
, cu_header
);
1839 /* Get bit size of field (zero if none). */
1840 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1843 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1847 FIELD_BITSIZE (*fp
) = 0;
1850 /* Get bit offset of field. */
1851 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1854 FIELD_BITPOS (*fp
) =
1855 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
1858 FIELD_BITPOS (*fp
) = 0;
1859 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1862 if (BITS_BIG_ENDIAN
)
1864 /* For big endian bits, the DW_AT_bit_offset gives the
1865 additional bit offset from the MSB of the containing
1866 anonymous object to the MSB of the field. We don't
1867 have to do anything special since we don't need to
1868 know the size of the anonymous object. */
1869 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1873 /* For little endian bits, compute the bit offset to the
1874 MSB of the anonymous object, subtract off the number of
1875 bits from the MSB of the field to the MSB of the
1876 object, and then subtract off the number of bits of
1877 the field itself. The result is the bit offset of
1878 the LSB of the field. */
1880 int bit_offset
= DW_UNSND (attr
);
1882 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1885 /* The size of the anonymous object containing
1886 the bit field is explicit, so use the
1887 indicated size (in bytes). */
1888 anonymous_size
= DW_UNSND (attr
);
1892 /* The size of the anonymous object containing
1893 the bit field must be inferred from the type
1894 attribute of the data member containing the
1896 anonymous_size
= TYPE_LENGTH (fp
->type
);
1898 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1899 - bit_offset
- FIELD_BITSIZE (*fp
);
1903 /* Get name of field. */
1904 attr
= dwarf_attr (die
, DW_AT_name
);
1905 if (attr
&& DW_STRING (attr
))
1906 fieldname
= DW_STRING (attr
);
1907 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1908 &objfile
->type_obstack
);
1910 /* Change accessibility for artificial fields (e.g. virtual table
1911 pointer or virtual base class pointer) to private. */
1912 if (dwarf_attr (die
, DW_AT_artificial
))
1914 new_field
->accessibility
= DW_ACCESS_private
;
1915 fip
->non_public_fields
= 1;
1918 else if (die
->tag
== DW_TAG_variable
)
1922 /* C++ static member.
1923 Get name of field. */
1924 attr
= dwarf_attr (die
, DW_AT_name
);
1925 if (attr
&& DW_STRING (attr
))
1926 fieldname
= DW_STRING (attr
);
1930 /* Get physical name. */
1931 physname
= dwarf2_linkage_name (die
);
1933 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1934 &objfile
->type_obstack
));
1935 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1936 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1937 &objfile
->type_obstack
);
1939 else if (die
->tag
== DW_TAG_inheritance
)
1941 /* C++ base class field. */
1942 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1944 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
1946 FIELD_BITSIZE (*fp
) = 0;
1947 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1948 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1949 fip
->nbaseclasses
++;
1953 /* Create the vector of fields, and attach it to the type. */
1956 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
1957 struct objfile
*objfile
)
1959 int nfields
= fip
->nfields
;
1961 /* Record the field count, allocate space for the array of fields,
1962 and create blank accessibility bitfields if necessary. */
1963 TYPE_NFIELDS (type
) = nfields
;
1964 TYPE_FIELDS (type
) = (struct field
*)
1965 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1966 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1968 if (fip
->non_public_fields
)
1970 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1972 TYPE_FIELD_PRIVATE_BITS (type
) =
1973 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1974 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1976 TYPE_FIELD_PROTECTED_BITS (type
) =
1977 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1978 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1980 TYPE_FIELD_IGNORE_BITS (type
) =
1981 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1982 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1985 /* If the type has baseclasses, allocate and clear a bit vector for
1986 TYPE_FIELD_VIRTUAL_BITS. */
1987 if (fip
->nbaseclasses
)
1989 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
1992 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1993 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1994 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1995 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
1996 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
1999 /* Copy the saved-up fields into the field vector. Start from the head
2000 of the list, adding to the tail of the field array, so that they end
2001 up in the same order in the array in which they were added to the list. */
2002 while (nfields
-- > 0)
2004 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2005 switch (fip
->fields
->accessibility
)
2007 case DW_ACCESS_private
:
2008 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2011 case DW_ACCESS_protected
:
2012 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2015 case DW_ACCESS_public
:
2019 /* Unknown accessibility. Complain and treat it as public. */
2021 complain (&dwarf2_unsupported_accessibility
,
2022 fip
->fields
->accessibility
);
2026 if (nfields
< fip
->nbaseclasses
)
2028 switch (fip
->fields
->virtuality
)
2030 case DW_VIRTUALITY_virtual
:
2031 case DW_VIRTUALITY_pure_virtual
:
2032 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2036 fip
->fields
= fip
->fields
->next
;
2040 /* Add a member function to the proper fieldlist. */
2043 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2044 struct type
*type
, struct objfile
*objfile
,
2045 const struct comp_unit_head
*cu_header
)
2047 struct attribute
*attr
;
2048 struct fnfieldlist
*flp
;
2050 struct fn_field
*fnp
;
2053 struct nextfnfield
*new_fnfield
;
2055 /* Get name of member function. */
2056 attr
= dwarf_attr (die
, DW_AT_name
);
2057 if (attr
&& DW_STRING (attr
))
2058 fieldname
= DW_STRING (attr
);
2062 /* Get the mangled name. */
2063 physname
= dwarf2_linkage_name (die
);
2065 /* Look up member function name in fieldlist. */
2066 for (i
= 0; i
< fip
->nfnfields
; i
++)
2068 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2072 /* Create new list element if necessary. */
2073 if (i
< fip
->nfnfields
)
2074 flp
= &fip
->fnfieldlists
[i
];
2077 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2079 fip
->fnfieldlists
= (struct fnfieldlist
*)
2080 xrealloc (fip
->fnfieldlists
,
2081 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2082 * sizeof (struct fnfieldlist
));
2083 if (fip
->nfnfields
== 0)
2084 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2086 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2087 flp
->name
= fieldname
;
2093 /* Create a new member function field and chain it to the field list
2095 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2096 make_cleanup (xfree
, new_fnfield
);
2097 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2098 new_fnfield
->next
= flp
->head
;
2099 flp
->head
= new_fnfield
;
2102 /* Fill in the member function field info. */
2103 fnp
= &new_fnfield
->fnfield
;
2104 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2105 &objfile
->type_obstack
);
2106 fnp
->type
= alloc_type (objfile
);
2107 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2109 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2110 struct type
**arg_types
;
2111 int nparams
= TYPE_NFIELDS (die
->type
);
2114 /* Copy argument types from the subroutine type. */
2115 arg_types
= (struct type
**)
2116 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2117 for (iparams
= 0; iparams
< nparams
; iparams
++)
2118 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2120 /* Set last entry in argument type vector. */
2121 if (TYPE_FLAGS (die
->type
) & TYPE_FLAG_VARARGS
)
2122 arg_types
[nparams
] = NULL
;
2124 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2126 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2128 /* Handle static member functions.
2129 Dwarf2 has no clean way to discern C++ static and non-static
2130 member functions. G++ helps GDB by marking the first
2131 parameter for non-static member functions (which is the
2132 this pointer) as artificial. We obtain this information
2133 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2134 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2135 fnp
->voffset
= VOFFSET_STATIC
;
2138 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2140 /* Get fcontext from DW_AT_containing_type if present. */
2141 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2142 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2144 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2145 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2147 /* Get accessibility. */
2148 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2151 switch (DW_UNSND (attr
))
2153 case DW_ACCESS_private
:
2154 fnp
->is_private
= 1;
2156 case DW_ACCESS_protected
:
2157 fnp
->is_protected
= 1;
2162 /* Get index in virtual function table if it is a virtual member function. */
2163 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2165 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2168 /* Create the vector of member function fields, and attach it to the type. */
2171 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2172 struct objfile
*objfile
)
2174 struct fnfieldlist
*flp
;
2175 int total_length
= 0;
2178 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2179 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2180 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2182 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2184 struct nextfnfield
*nfp
= flp
->head
;
2185 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2188 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2189 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2190 fn_flp
->fn_fields
= (struct fn_field
*)
2191 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2192 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2193 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2195 total_length
+= flp
->length
;
2198 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2199 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2202 /* Called when we find the DIE that starts a structure or union scope
2203 (definition) to process all dies that define the members of the
2206 NOTE: we need to call struct_type regardless of whether or not the
2207 DIE has an at_name attribute, since it might be an anonymous
2208 structure or union. This gets the type entered into our set of
2211 However, if the structure is incomplete (an opaque struct/union)
2212 then suppress creating a symbol table entry for it since gdb only
2213 wants to find the one with the complete definition. Note that if
2214 it is complete, we just call new_symbol, which does it's own
2215 checking about whether the struct/union is anonymous or not (and
2216 suppresses creating a symbol table entry itself). */
2219 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2220 const struct comp_unit_head
*cu_header
)
2223 struct attribute
*attr
;
2225 type
= alloc_type (objfile
);
2227 INIT_CPLUS_SPECIFIC (type
);
2228 attr
= dwarf_attr (die
, DW_AT_name
);
2229 if (attr
&& DW_STRING (attr
))
2231 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2232 strlen (DW_STRING (attr
)),
2233 &objfile
->type_obstack
);
2236 if (die
->tag
== DW_TAG_structure_type
)
2238 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2240 else if (die
->tag
== DW_TAG_union_type
)
2242 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2246 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2248 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2251 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2254 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2258 TYPE_LENGTH (type
) = 0;
2261 /* We need to add the type field to the die immediately so we don't
2262 infinitely recurse when dealing with pointers to the structure
2263 type within the structure itself. */
2266 if (die
->has_children
&& ! die_is_declaration (die
))
2268 struct field_info fi
;
2269 struct die_info
*child_die
;
2270 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2272 memset (&fi
, 0, sizeof (struct field_info
));
2274 child_die
= die
->next
;
2276 while (child_die
&& child_die
->tag
)
2278 if (child_die
->tag
== DW_TAG_member
)
2280 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2282 else if (child_die
->tag
== DW_TAG_variable
)
2284 /* C++ static member. */
2285 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2287 else if (child_die
->tag
== DW_TAG_subprogram
)
2289 /* C++ member function. */
2290 process_die (child_die
, objfile
, cu_header
);
2291 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2293 else if (child_die
->tag
== DW_TAG_inheritance
)
2295 /* C++ base class field. */
2296 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2300 process_die (child_die
, objfile
, cu_header
);
2302 child_die
= sibling_die (child_die
);
2305 /* Attach fields and member functions to the type. */
2307 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2310 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2312 /* Get the type which refers to the base class (possibly this
2313 class itself) which contains the vtable pointer for the current
2314 class from the DW_AT_containing_type attribute. */
2316 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2318 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2320 TYPE_VPTR_BASETYPE (type
) = t
;
2323 static const char vptr_name
[] =
2324 {'_', 'v', 'p', 't', 'r', '\0'};
2327 /* Our own class provides vtbl ptr. */
2328 for (i
= TYPE_NFIELDS (t
) - 1;
2329 i
>= TYPE_N_BASECLASSES (t
);
2332 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2334 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2335 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2337 TYPE_VPTR_FIELDNO (type
) = i
;
2342 /* Complain if virtual function table field not found. */
2343 if (i
< TYPE_N_BASECLASSES (t
))
2344 complain (&dwarf2_vtbl_not_found_complaint
,
2345 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2349 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2354 new_symbol (die
, type
, objfile
, cu_header
);
2356 do_cleanups (back_to
);
2360 /* No children, must be stub. */
2361 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2367 /* Given a pointer to a die which begins an enumeration, process all
2368 the dies that define the members of the enumeration.
2370 This will be much nicer in draft 6 of the DWARF spec when our
2371 members will be dies instead squished into the DW_AT_element_list
2374 NOTE: We reverse the order of the element list. */
2377 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2378 const struct comp_unit_head
*cu_header
)
2380 struct die_info
*child_die
;
2382 struct field
*fields
;
2383 struct attribute
*attr
;
2386 int unsigned_enum
= 1;
2388 type
= alloc_type (objfile
);
2390 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2391 attr
= dwarf_attr (die
, DW_AT_name
);
2392 if (attr
&& DW_STRING (attr
))
2394 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2395 strlen (DW_STRING (attr
)),
2396 &objfile
->type_obstack
);
2399 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2402 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2406 TYPE_LENGTH (type
) = 0;
2411 if (die
->has_children
)
2413 child_die
= die
->next
;
2414 while (child_die
&& child_die
->tag
)
2416 if (child_die
->tag
!= DW_TAG_enumerator
)
2418 process_die (child_die
, objfile
, cu_header
);
2422 attr
= dwarf_attr (child_die
, DW_AT_name
);
2425 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2426 if (SYMBOL_VALUE (sym
) < 0)
2429 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2431 fields
= (struct field
*)
2433 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2434 * sizeof (struct field
));
2437 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2438 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2439 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2440 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2446 child_die
= sibling_die (child_die
);
2451 TYPE_NFIELDS (type
) = num_fields
;
2452 TYPE_FIELDS (type
) = (struct field
*)
2453 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2454 memcpy (TYPE_FIELDS (type
), fields
,
2455 sizeof (struct field
) * num_fields
);
2459 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2462 new_symbol (die
, type
, objfile
, cu_header
);
2465 /* Extract all information from a DW_TAG_array_type DIE and put it in
2466 the DIE's type field. For now, this only handles one dimensional
2470 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
2471 const struct comp_unit_head
*cu_header
)
2473 struct die_info
*child_die
;
2474 struct type
*type
= NULL
;
2475 struct type
*element_type
, *range_type
, *index_type
;
2476 struct type
**range_types
= NULL
;
2477 struct attribute
*attr
;
2479 struct cleanup
*back_to
;
2481 /* Return if we've already decoded this type. */
2487 element_type
= die_type (die
, objfile
, cu_header
);
2489 /* Irix 6.2 native cc creates array types without children for
2490 arrays with unspecified length. */
2491 if (die
->has_children
== 0)
2493 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2494 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2495 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2499 back_to
= make_cleanup (null_cleanup
, NULL
);
2500 child_die
= die
->next
;
2501 while (child_die
&& child_die
->tag
)
2503 if (child_die
->tag
== DW_TAG_subrange_type
)
2505 unsigned int low
, high
;
2507 /* Default bounds to an array with unspecified length. */
2510 if (cu_language
== language_fortran
)
2512 /* FORTRAN implies a lower bound of 1, if not given. */
2516 index_type
= die_type (child_die
, objfile
, cu_header
);
2517 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2520 if (attr
->form
== DW_FORM_sdata
)
2522 low
= DW_SND (attr
);
2524 else if (attr
->form
== DW_FORM_udata
2525 || attr
->form
== DW_FORM_data1
2526 || attr
->form
== DW_FORM_data2
2527 || attr
->form
== DW_FORM_data4
)
2529 low
= DW_UNSND (attr
);
2533 complain (&dwarf2_non_const_array_bound_ignored
,
2534 dwarf_form_name (attr
->form
));
2536 die
->type
= lookup_pointer_type (element_type
);
2543 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2546 if (attr
->form
== DW_FORM_sdata
)
2548 high
= DW_SND (attr
);
2550 else if (attr
->form
== DW_FORM_udata
2551 || attr
->form
== DW_FORM_data1
2552 || attr
->form
== DW_FORM_data2
2553 || attr
->form
== DW_FORM_data4
)
2555 high
= DW_UNSND (attr
);
2557 else if (attr
->form
== DW_FORM_block1
)
2559 /* GCC encodes arrays with unspecified or dynamic length
2560 with a DW_FORM_block1 attribute.
2561 FIXME: GDB does not yet know how to handle dynamic
2562 arrays properly, treat them as arrays with unspecified
2568 complain (&dwarf2_non_const_array_bound_ignored
,
2569 dwarf_form_name (attr
->form
));
2571 die
->type
= lookup_pointer_type (element_type
);
2579 /* Create a range type and save it for array type creation. */
2580 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2582 range_types
= (struct type
**)
2583 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2584 * sizeof (struct type
*));
2586 make_cleanup (free_current_contents
, &range_types
);
2588 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2590 child_die
= sibling_die (child_die
);
2593 /* Dwarf2 dimensions are output from left to right, create the
2594 necessary array types in backwards order. */
2595 type
= element_type
;
2597 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2599 do_cleanups (back_to
);
2601 /* Install the type in the die. */
2605 /* First cut: install each common block member as a global variable. */
2608 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
2609 const struct comp_unit_head
*cu_header
)
2611 struct die_info
*child_die
;
2612 struct attribute
*attr
;
2614 CORE_ADDR base
= (CORE_ADDR
) 0;
2616 attr
= dwarf_attr (die
, DW_AT_location
);
2619 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2621 if (die
->has_children
)
2623 child_die
= die
->next
;
2624 while (child_die
&& child_die
->tag
)
2626 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
2627 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2630 SYMBOL_VALUE_ADDRESS (sym
) =
2631 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2632 add_symbol_to_list (sym
, &global_symbols
);
2634 child_die
= sibling_die (child_die
);
2639 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2640 the user defined type vector. */
2643 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
2644 const struct comp_unit_head
*cu_header
)
2647 struct attribute
*attr
;
2654 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
2655 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2658 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2662 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2667 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2668 the user defined type vector. */
2671 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
2672 const struct comp_unit_head
*cu_header
)
2675 struct type
*to_type
;
2676 struct type
*domain
;
2683 type
= alloc_type (objfile
);
2684 to_type
= die_type (die
, objfile
, cu_header
);
2685 domain
= die_containing_type (die
, objfile
, cu_header
);
2686 smash_to_member_type (type
, domain
, to_type
);
2691 /* Extract all information from a DW_TAG_reference_type DIE and add to
2692 the user defined type vector. */
2695 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
2696 const struct comp_unit_head
*cu_header
)
2699 struct attribute
*attr
;
2706 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
2707 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2710 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2714 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2720 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
2721 const struct comp_unit_head
*cu_header
)
2723 struct type
*base_type
;
2730 base_type
= die_type (die
, objfile
, cu_header
);
2731 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
2735 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
2736 const struct comp_unit_head
*cu_header
)
2738 struct type
*base_type
;
2745 base_type
= die_type (die
, objfile
, cu_header
);
2746 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
2749 /* Extract all information from a DW_TAG_string_type DIE and add to
2750 the user defined type vector. It isn't really a user defined type,
2751 but it behaves like one, with other DIE's using an AT_user_def_type
2752 attribute to reference it. */
2755 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
2757 struct type
*type
, *range_type
, *index_type
, *char_type
;
2758 struct attribute
*attr
;
2759 unsigned int length
;
2766 attr
= dwarf_attr (die
, DW_AT_string_length
);
2769 length
= DW_UNSND (attr
);
2775 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2776 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2777 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2778 type
= create_string_type (char_type
, range_type
);
2782 /* Handle DIES due to C code like:
2786 int (*funcp)(int a, long l);
2790 ('funcp' generates a DW_TAG_subroutine_type DIE)
2794 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
2795 const struct comp_unit_head
*cu_header
)
2797 struct type
*type
; /* Type that this function returns */
2798 struct type
*ftype
; /* Function that returns above type */
2799 struct attribute
*attr
;
2801 /* Decode the type that this subroutine returns */
2806 type
= die_type (die
, objfile
, cu_header
);
2807 ftype
= lookup_function_type (type
);
2809 /* All functions in C++ have prototypes. */
2810 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2811 if ((attr
&& (DW_UNSND (attr
) != 0))
2812 || cu_language
== language_cplus
)
2813 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2815 if (die
->has_children
)
2817 struct die_info
*child_die
;
2821 /* Count the number of parameters.
2822 FIXME: GDB currently ignores vararg functions, but knows about
2823 vararg member functions. */
2824 child_die
= die
->next
;
2825 while (child_die
&& child_die
->tag
)
2827 if (child_die
->tag
== DW_TAG_formal_parameter
)
2829 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2830 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2831 child_die
= sibling_die (child_die
);
2834 /* Allocate storage for parameters and fill them in. */
2835 TYPE_NFIELDS (ftype
) = nparams
;
2836 TYPE_FIELDS (ftype
) = (struct field
*)
2837 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2839 child_die
= die
->next
;
2840 while (child_die
&& child_die
->tag
)
2842 if (child_die
->tag
== DW_TAG_formal_parameter
)
2844 /* Dwarf2 has no clean way to discern C++ static and non-static
2845 member functions. G++ helps GDB by marking the first
2846 parameter for non-static member functions (which is the
2847 this pointer) as artificial. We pass this information
2848 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2849 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2851 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2853 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2854 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
2858 child_die
= sibling_die (child_die
);
2866 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
2867 const struct comp_unit_head
*cu_header
)
2873 struct attribute
*attr
;
2876 xtype
= die_type (die
, objfile
, cu_header
);
2878 type
= alloc_type (objfile
);
2879 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2880 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2881 TYPE_TARGET_TYPE (type
) = xtype
;
2882 attr
= dwarf_attr (die
, DW_AT_name
);
2883 if (attr
&& DW_STRING (attr
))
2884 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2885 strlen (DW_STRING (attr
)),
2886 &objfile
->type_obstack
);
2892 /* Find a representation of a given base type and install
2893 it in the TYPE field of the die. */
2896 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
2899 struct attribute
*attr
;
2900 int encoding
= 0, size
= 0;
2902 /* If we've already decoded this die, this is a no-op. */
2908 attr
= dwarf_attr (die
, DW_AT_encoding
);
2911 encoding
= DW_UNSND (attr
);
2913 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2916 size
= DW_UNSND (attr
);
2918 attr
= dwarf_attr (die
, DW_AT_name
);
2919 if (attr
&& DW_STRING (attr
))
2921 enum type_code code
= TYPE_CODE_INT
;
2922 int is_unsigned
= 0;
2926 case DW_ATE_address
:
2927 /* Turn DW_ATE_address into a void * pointer. */
2928 code
= TYPE_CODE_PTR
;
2931 case DW_ATE_boolean
:
2932 code
= TYPE_CODE_BOOL
;
2935 case DW_ATE_complex_float
:
2936 code
= TYPE_CODE_COMPLEX
;
2939 code
= TYPE_CODE_FLT
;
2942 case DW_ATE_signed_char
:
2944 case DW_ATE_unsigned
:
2945 case DW_ATE_unsigned_char
:
2949 complain (&dwarf2_unsupported_at_encoding
,
2950 dwarf_type_encoding_name (encoding
));
2953 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2954 if (encoding
== DW_ATE_address
)
2955 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2959 type
= dwarf_base_type (encoding
, size
, objfile
);
2964 /* Read a whole compilation unit into a linked list of dies. */
2966 static struct die_info
*
2967 read_comp_unit (char *info_ptr
, bfd
*abfd
,
2968 const struct comp_unit_head
*cu_header
)
2970 struct die_info
*first_die
, *last_die
, *die
;
2974 /* Reset die reference table; we are
2975 building new ones now. */
2976 dwarf2_empty_hash_tables ();
2980 first_die
= last_die
= NULL
;
2983 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
2984 if (die
->has_children
)
2995 /* Enter die in reference hash table */
2996 store_in_ref_table (die
->offset
, die
);
3000 first_die
= last_die
= die
;
3004 last_die
->next
= die
;
3008 while (nesting_level
> 0);
3012 /* Free a linked list of dies. */
3015 free_die_list (struct die_info
*dies
)
3017 struct die_info
*die
, *next
;
3030 do_free_die_list_cleanup (void *dies
)
3032 free_die_list (dies
);
3035 static struct cleanup
*
3036 make_cleanup_free_die_list (struct die_info
*dies
)
3038 return make_cleanup (do_free_die_list_cleanup
, dies
);
3042 /* Read the contents of the section at OFFSET and of size SIZE from the
3043 object file specified by OBJFILE into the psymbol_obstack and return it. */
3046 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
3049 bfd
*abfd
= objfile
->obfd
;
3055 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3056 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3057 (bfd_bread (buf
, size
, abfd
) != size
))
3060 error ("Dwarf Error: Can't read DWARF data from '%s'",
3061 bfd_get_filename (abfd
));
3066 /* In DWARF version 2, the description of the debugging information is
3067 stored in a separate .debug_abbrev section. Before we read any
3068 dies from a section we read in all abbreviations and install them
3072 dwarf2_read_abbrevs (bfd
*abfd
, unsigned int offset
)
3075 struct abbrev_info
*cur_abbrev
;
3076 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3077 unsigned int abbrev_form
, hash_number
;
3079 /* empty the table */
3080 dwarf2_empty_abbrev_table (NULL
);
3082 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3083 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3084 abbrev_ptr
+= bytes_read
;
3086 /* loop until we reach an abbrev number of 0 */
3087 while (abbrev_number
)
3089 cur_abbrev
= dwarf_alloc_abbrev ();
3091 /* read in abbrev header */
3092 cur_abbrev
->number
= abbrev_number
;
3093 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3094 abbrev_ptr
+= bytes_read
;
3095 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3098 /* now read in declarations */
3099 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3100 abbrev_ptr
+= bytes_read
;
3101 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3102 abbrev_ptr
+= bytes_read
;
3105 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3107 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3108 xrealloc (cur_abbrev
->attrs
,
3109 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3110 * sizeof (struct attr_abbrev
));
3112 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3113 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3114 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3115 abbrev_ptr
+= bytes_read
;
3116 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3117 abbrev_ptr
+= bytes_read
;
3120 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3121 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3122 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3124 /* Get next abbreviation.
3125 Under Irix6 the abbreviations for a compilation unit are not
3126 always properly terminated with an abbrev number of 0.
3127 Exit loop if we encounter an abbreviation which we have
3128 already read (which means we are about to read the abbreviations
3129 for the next compile unit) or if the end of the abbreviation
3130 table is reached. */
3131 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3132 >= dwarf_abbrev_size
)
3134 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3135 abbrev_ptr
+= bytes_read
;
3136 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3141 /* Empty the abbrev table for a new compilation unit. */
3145 dwarf2_empty_abbrev_table (PTR ignore
)
3148 struct abbrev_info
*abbrev
, *next
;
3150 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3153 abbrev
= dwarf2_abbrevs
[i
];
3156 next
= abbrev
->next
;
3157 xfree (abbrev
->attrs
);
3161 dwarf2_abbrevs
[i
] = NULL
;
3165 /* Lookup an abbrev_info structure in the abbrev hash table. */
3167 static struct abbrev_info
*
3168 dwarf2_lookup_abbrev (unsigned int number
)
3170 unsigned int hash_number
;
3171 struct abbrev_info
*abbrev
;
3173 hash_number
= number
% ABBREV_HASH_SIZE
;
3174 abbrev
= dwarf2_abbrevs
[hash_number
];
3178 if (abbrev
->number
== number
)
3181 abbrev
= abbrev
->next
;
3186 /* Read a minimal amount of information into the minimal die structure. */
3189 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3190 char *info_ptr
, const struct comp_unit_head
*cu_header
)
3192 unsigned int abbrev_number
, bytes_read
, i
;
3193 struct abbrev_info
*abbrev
;
3194 struct attribute attr
;
3195 struct attribute spec_attr
;
3196 int found_spec_attr
= 0;
3197 int has_low_pc_attr
= 0;
3198 int has_high_pc_attr
= 0;
3200 *part_die
= zeroed_partial_die
;
3201 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3202 info_ptr
+= bytes_read
;
3206 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3209 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3211 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3212 part_die
->tag
= abbrev
->tag
;
3213 part_die
->has_children
= abbrev
->has_children
;
3214 part_die
->abbrev
= abbrev_number
;
3216 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3218 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3219 info_ptr
, cu_header
);
3221 /* Store the data if it is of an attribute we want to keep in a
3222 partial symbol table. */
3227 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3228 if (part_die
->name
== NULL
)
3229 part_die
->name
= DW_STRING (&attr
);
3231 case DW_AT_MIPS_linkage_name
:
3232 part_die
->name
= DW_STRING (&attr
);
3235 has_low_pc_attr
= 1;
3236 part_die
->lowpc
= DW_ADDR (&attr
);
3239 has_high_pc_attr
= 1;
3240 part_die
->highpc
= DW_ADDR (&attr
);
3242 case DW_AT_location
:
3243 part_die
->locdesc
= DW_BLOCK (&attr
);
3245 case DW_AT_language
:
3246 part_die
->language
= DW_UNSND (&attr
);
3248 case DW_AT_external
:
3249 part_die
->is_external
= DW_UNSND (&attr
);
3251 case DW_AT_declaration
:
3252 part_die
->is_declaration
= DW_UNSND (&attr
);
3255 part_die
->has_type
= 1;
3257 case DW_AT_abstract_origin
:
3258 case DW_AT_specification
:
3259 found_spec_attr
= 1;
3263 /* Ignore absolute siblings, they might point outside of
3264 the current compile unit. */
3265 if (attr
.form
== DW_FORM_ref_addr
)
3266 complain (&dwarf2_absolute_sibling_complaint
);
3269 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3276 /* If we found a reference attribute and the die has no name, try
3277 to find a name in the referred to die. */
3279 if (found_spec_attr
&& part_die
->name
== NULL
)
3281 struct partial_die_info spec_die
;
3285 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3286 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu_header
);
3289 part_die
->name
= spec_die
.name
;
3291 /* Copy DW_AT_external attribute if it is set. */
3292 if (spec_die
.is_external
)
3293 part_die
->is_external
= spec_die
.is_external
;
3297 /* When using the GNU linker, .gnu.linkonce. sections are used to
3298 eliminate duplicate copies of functions and vtables and such.
3299 The linker will arbitrarily choose one and discard the others.
3300 The AT_*_pc values for such functions refer to local labels in
3301 these sections. If the section from that file was discarded, the
3302 labels are not in the output, so the relocs get a value of 0.
3303 If this is a discarded function, mark the pc bounds as invalid,
3304 so that GDB will ignore it. */
3305 if (has_low_pc_attr
&& has_high_pc_attr
3306 && part_die
->lowpc
< part_die
->highpc
3307 && (part_die
->lowpc
!= 0
3308 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3309 part_die
->has_pc_info
= 1;
3313 /* Read the die from the .debug_info section buffer. And set diep to
3314 point to a newly allocated die with its information. */
3317 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3318 const struct comp_unit_head
*cu_header
)
3320 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3321 struct abbrev_info
*abbrev
;
3322 struct die_info
*die
;
3324 offset
= info_ptr
- dwarf_info_buffer
;
3325 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3326 info_ptr
+= bytes_read
;
3329 die
= dwarf_alloc_die ();
3331 die
->abbrev
= abbrev_number
;
3337 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3340 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3342 die
= dwarf_alloc_die ();
3343 die
->offset
= offset
;
3344 die
->tag
= abbrev
->tag
;
3345 die
->has_children
= abbrev
->has_children
;
3346 die
->abbrev
= abbrev_number
;
3349 die
->num_attrs
= abbrev
->num_attrs
;
3350 die
->attrs
= (struct attribute
*)
3351 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3353 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3355 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3356 abfd
, info_ptr
, cu_header
);
3363 /* Read an attribute described by an abbreviated attribute. */
3366 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
3367 bfd
*abfd
, char *info_ptr
,
3368 const struct comp_unit_head
*cu_header
)
3370 unsigned int bytes_read
;
3371 struct dwarf_block
*blk
;
3373 attr
->name
= abbrev
->name
;
3374 attr
->form
= abbrev
->form
;
3375 switch (abbrev
->form
)
3378 case DW_FORM_ref_addr
:
3379 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3380 info_ptr
+= bytes_read
;
3382 case DW_FORM_block2
:
3383 blk
= dwarf_alloc_block ();
3384 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3386 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3387 info_ptr
+= blk
->size
;
3388 DW_BLOCK (attr
) = blk
;
3390 case DW_FORM_block4
:
3391 blk
= dwarf_alloc_block ();
3392 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3394 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3395 info_ptr
+= blk
->size
;
3396 DW_BLOCK (attr
) = blk
;
3399 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3403 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3407 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3410 case DW_FORM_string
:
3411 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3412 info_ptr
+= bytes_read
;
3415 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
3417 info_ptr
+= bytes_read
;
3420 blk
= dwarf_alloc_block ();
3421 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3422 info_ptr
+= bytes_read
;
3423 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3424 info_ptr
+= blk
->size
;
3425 DW_BLOCK (attr
) = blk
;
3427 case DW_FORM_block1
:
3428 blk
= dwarf_alloc_block ();
3429 blk
->size
= read_1_byte (abfd
, info_ptr
);
3431 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3432 info_ptr
+= blk
->size
;
3433 DW_BLOCK (attr
) = blk
;
3436 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3440 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3444 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3445 info_ptr
+= bytes_read
;
3448 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3449 info_ptr
+= bytes_read
;
3452 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3456 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3460 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3464 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3467 case DW_FORM_ref_udata
:
3468 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3469 info_ptr
+= bytes_read
;
3471 case DW_FORM_indirect
:
3473 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3474 dwarf_form_name (abbrev
->form
));
3479 /* read dwarf information from a buffer */
3482 read_1_byte (bfd
*abfd
, char *buf
)
3484 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3488 read_1_signed_byte (bfd
*abfd
, char *buf
)
3490 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3494 read_2_bytes (bfd
*abfd
, char *buf
)
3496 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3500 read_2_signed_bytes (bfd
*abfd
, char *buf
)
3502 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3506 read_4_bytes (bfd
*abfd
, char *buf
)
3508 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3512 read_4_signed_bytes (bfd
*abfd
, char *buf
)
3514 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3517 static unsigned long
3518 read_8_bytes (bfd
*abfd
, char *buf
)
3520 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3524 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3527 CORE_ADDR retval
= 0;
3529 if (cu_header
->signed_addr_p
)
3531 switch (cu_header
->addr_size
)
3534 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3537 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3540 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
3543 internal_error (__FILE__
, __LINE__
,
3544 "read_address: bad switch, signed");
3549 switch (cu_header
->addr_size
)
3552 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3555 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3558 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3561 internal_error (__FILE__
, __LINE__
,
3562 "read_address: bad switch, unsigned");
3566 *bytes_read
= cu_header
->addr_size
;
3570 /* Reads the initial length from a section. The (draft) DWARF 2.1
3571 specification allows the initial length to take up either 4 bytes
3572 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
3573 bytes describe the length and all offsets will be 8 bytes in length
3576 The value returned via bytes_read should be used to increment
3577 the relevant pointer after calling read_initial_length().
3579 As a side effect, this function sets the fields initial_length_size
3580 and offset_size in cu_header to the values appropriate for the
3581 length field. (The format of the initial length field determines
3582 the width of file offsets to be fetched later with fetch_offset().)
3584 [ Note: read_initial_length() and read_offset() are based on the
3585 document entitled "DWARF Debugging Information Format", revision
3586 2.1, draft 4, dated July 20, 2000. This document was obtained
3589 http://reality.sgi.com/dehnert_engr/dwarf/dwarf2p1-draft4-000720.pdf
3591 This document is only a draft and is subject to change. (So beware.)
3593 - Kevin, Aug 4, 2000
3597 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
3602 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3604 if (retval
== 0xffffffff)
3606 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
3608 if (cu_header
!= NULL
)
3610 cu_header
->initial_length_size
= 12;
3611 cu_header
->offset_size
= 8;
3617 if (cu_header
!= NULL
)
3619 cu_header
->initial_length_size
= 4;
3620 cu_header
->offset_size
= 4;
3627 /* Read an offset from the data stream. The size of the offset is
3628 given by cu_header->offset_size. */
3631 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3636 switch (cu_header
->offset_size
)
3639 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3643 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3647 internal_error (__FILE__
, __LINE__
,
3648 "read_offset: bad switch");
3655 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
3657 /* If the size of a host char is 8 bits, we can return a pointer
3658 to the buffer, otherwise we have to copy the data to a buffer
3659 allocated on the temporary obstack. */
3660 gdb_assert (HOST_CHAR_BIT
== 8);
3665 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3667 /* If the size of a host char is 8 bits, we can return a pointer
3668 to the string, otherwise we have to copy the string to a buffer
3669 allocated on the temporary obstack. */
3670 gdb_assert (HOST_CHAR_BIT
== 8);
3673 *bytes_read_ptr
= 1;
3676 *bytes_read_ptr
= strlen (buf
) + 1;
3681 read_indirect_string (bfd
*abfd
, char *buf
,
3682 const struct comp_unit_head
*cu_header
,
3683 unsigned int *bytes_read_ptr
)
3685 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
3686 (int *) bytes_read_ptr
);
3688 if (dwarf_str_buffer
== NULL
)
3690 error ("DW_FORM_strp used without .debug_str section");
3693 if (str_offset
>= dwarf_str_size
)
3695 error ("DW_FORM_strp pointing outside of .debug_str section");
3698 gdb_assert (HOST_CHAR_BIT
== 8);
3699 if (dwarf_str_buffer
[str_offset
] == '\0')
3701 return dwarf_str_buffer
+ str_offset
;
3704 static unsigned long
3705 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3707 unsigned long result
;
3708 unsigned int num_read
;
3718 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3721 result
|= ((unsigned long)(byte
& 127) << shift
);
3722 if ((byte
& 128) == 0)
3728 *bytes_read_ptr
= num_read
;
3733 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3736 int i
, shift
, size
, num_read
;
3746 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3749 result
|= ((long)(byte
& 127) << shift
);
3751 if ((byte
& 128) == 0)
3756 if ((shift
< size
) && (byte
& 0x40))
3758 result
|= -(1 << shift
);
3760 *bytes_read_ptr
= num_read
;
3765 set_cu_language (unsigned int lang
)
3771 cu_language
= language_c
;
3773 case DW_LANG_C_plus_plus
:
3774 cu_language
= language_cplus
;
3776 case DW_LANG_Fortran77
:
3777 case DW_LANG_Fortran90
:
3778 cu_language
= language_fortran
;
3780 case DW_LANG_Mips_Assembler
:
3781 cu_language
= language_asm
;
3784 cu_language
= language_java
;
3787 case DW_LANG_Cobol74
:
3788 case DW_LANG_Cobol85
:
3789 case DW_LANG_Pascal83
:
3790 case DW_LANG_Modula2
:
3792 cu_language
= language_unknown
;
3795 cu_language_defn
= language_def (cu_language
);
3798 /* Return the named attribute or NULL if not there. */
3800 static struct attribute
*
3801 dwarf_attr (struct die_info
*die
, unsigned int name
)
3804 struct attribute
*spec
= NULL
;
3806 for (i
= 0; i
< die
->num_attrs
; ++i
)
3808 if (die
->attrs
[i
].name
== name
)
3810 return &die
->attrs
[i
];
3812 if (die
->attrs
[i
].name
== DW_AT_specification
3813 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3814 spec
= &die
->attrs
[i
];
3818 struct die_info
*ref_die
=
3819 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3822 return dwarf_attr (ref_die
, name
);
3829 die_is_declaration (struct die_info
*die
)
3831 return (dwarf_attr (die
, DW_AT_declaration
)
3832 && ! dwarf_attr (die
, DW_AT_specification
));
3835 /* Decode the line number information for the compilation unit whose
3836 line number info is at OFFSET in the .debug_line section.
3837 The compilation directory of the file is passed in COMP_DIR. */
3841 unsigned int num_files
;
3854 unsigned int num_dirs
;
3859 dwarf_decode_lines (unsigned int offset
, char *comp_dir
, bfd
*abfd
,
3860 const struct comp_unit_head
*cu_header
)
3864 struct line_head lh
;
3865 struct cleanup
*back_to
;
3866 unsigned int i
, bytes_read
;
3867 char *cur_file
, *cur_dir
;
3868 unsigned char op_code
, extended_op
, adj_opcode
;
3870 #define FILE_ALLOC_CHUNK 5
3871 #define DIR_ALLOC_CHUNK 5
3873 struct filenames files
;
3874 struct directories dirs
;
3876 if (dwarf_line_buffer
== NULL
)
3878 complain (&dwarf2_missing_line_number_section
);
3882 files
.num_files
= 0;
3888 line_ptr
= dwarf_line_buffer
+ offset
;
3890 /* read in the prologue */
3891 lh
.total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
3892 line_ptr
+= bytes_read
;
3893 line_end
= line_ptr
+ lh
.total_length
;
3894 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3896 lh
.prologue_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
3897 line_ptr
+= bytes_read
;
3898 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3900 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3902 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3904 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3906 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3908 lh
.standard_opcode_lengths
= (unsigned char *)
3909 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3910 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
3912 lh
.standard_opcode_lengths
[0] = 1;
3913 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3915 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3919 /* Read directory table */
3920 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3922 line_ptr
+= bytes_read
;
3923 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3925 dirs
.dirs
= (char **)
3926 xrealloc (dirs
.dirs
,
3927 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3928 if (dirs
.num_dirs
== 0)
3929 make_cleanup (free_current_contents
, &dirs
.dirs
);
3931 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3933 line_ptr
+= bytes_read
;
3935 /* Read file name table */
3936 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3938 line_ptr
+= bytes_read
;
3939 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3941 files
.files
= (struct fileinfo
*)
3942 xrealloc (files
.files
,
3943 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3944 * sizeof (struct fileinfo
));
3945 if (files
.num_files
== 0)
3946 make_cleanup (free_current_contents
, &files
.files
);
3948 files
.files
[files
.num_files
].name
= cur_file
;
3949 files
.files
[files
.num_files
].dir
=
3950 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3951 line_ptr
+= bytes_read
;
3952 files
.files
[files
.num_files
].time
=
3953 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3954 line_ptr
+= bytes_read
;
3955 files
.files
[files
.num_files
].size
=
3956 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3957 line_ptr
+= bytes_read
;
3960 line_ptr
+= bytes_read
;
3962 /* Read the statement sequences until there's nothing left. */
3963 while (line_ptr
< line_end
)
3965 /* state machine registers */
3966 CORE_ADDR address
= 0;
3967 unsigned int file
= 1;
3968 unsigned int line
= 1;
3969 unsigned int column
= 0;
3970 int is_stmt
= lh
.default_is_stmt
;
3971 int basic_block
= 0;
3972 int end_sequence
= 0;
3974 /* Start a subfile for the current file of the state machine. */
3975 if (files
.num_files
>= file
)
3977 /* The file and directory tables are 0 based, the references
3979 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3980 (files
.files
[file
- 1].dir
3981 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3985 /* Decode the table. */
3986 while (!end_sequence
)
3988 op_code
= read_1_byte (abfd
, line_ptr
);
3991 if (op_code
>= lh
.opcode_base
)
3992 { /* Special operand. */
3993 adj_opcode
= op_code
- lh
.opcode_base
;
3994 address
+= (adj_opcode
/ lh
.line_range
)
3995 * lh
.minimum_instruction_length
;
3996 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
3997 /* append row to matrix using current values */
3998 record_line (current_subfile
, line
, address
);
4001 else switch (op_code
)
4003 case DW_LNS_extended_op
:
4004 line_ptr
+= 1; /* ignore length */
4005 extended_op
= read_1_byte (abfd
, line_ptr
);
4007 switch (extended_op
)
4009 case DW_LNE_end_sequence
:
4011 /* Don't call record_line here. The end_sequence
4012 instruction provides the address of the first byte
4013 *after* the last line in the sequence; it's not the
4014 address of any real source line. However, the GDB
4015 linetable structure only records the starts of lines,
4016 not the ends. This is a weakness of GDB. */
4018 case DW_LNE_set_address
:
4019 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
4020 line_ptr
+= bytes_read
;
4021 address
+= baseaddr
;
4023 case DW_LNE_define_file
:
4024 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
4025 line_ptr
+= bytes_read
;
4026 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
4028 files
.files
= (struct fileinfo
*)
4029 xrealloc (files
.files
,
4030 (files
.num_files
+ FILE_ALLOC_CHUNK
)
4031 * sizeof (struct fileinfo
));
4032 if (files
.num_files
== 0)
4033 make_cleanup (free_current_contents
, &files
.files
);
4035 files
.files
[files
.num_files
].name
= cur_file
;
4036 files
.files
[files
.num_files
].dir
=
4037 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4038 line_ptr
+= bytes_read
;
4039 files
.files
[files
.num_files
].time
=
4040 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4041 line_ptr
+= bytes_read
;
4042 files
.files
[files
.num_files
].size
=
4043 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4044 line_ptr
+= bytes_read
;
4048 complain (&dwarf2_mangled_line_number_section
);
4053 record_line (current_subfile
, line
, address
);
4056 case DW_LNS_advance_pc
:
4057 address
+= lh
.minimum_instruction_length
4058 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4059 line_ptr
+= bytes_read
;
4061 case DW_LNS_advance_line
:
4062 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
4063 line_ptr
+= bytes_read
;
4065 case DW_LNS_set_file
:
4066 /* The file and directory tables are 0 based, the references
4068 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4069 line_ptr
+= bytes_read
;
4070 dwarf2_start_subfile
4071 (files
.files
[file
- 1].name
,
4072 (files
.files
[file
- 1].dir
4073 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
4076 case DW_LNS_set_column
:
4077 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4078 line_ptr
+= bytes_read
;
4080 case DW_LNS_negate_stmt
:
4081 is_stmt
= (!is_stmt
);
4083 case DW_LNS_set_basic_block
:
4086 /* Add to the address register of the state machine the
4087 address increment value corresponding to special opcode
4088 255. Ie, this value is scaled by the minimum instruction
4089 length since special opcode 255 would have scaled the
4091 case DW_LNS_const_add_pc
:
4092 address
+= (lh
.minimum_instruction_length
4093 * ((255 - lh
.opcode_base
) / lh
.line_range
));
4095 case DW_LNS_fixed_advance_pc
:
4096 address
+= read_2_bytes (abfd
, line_ptr
);
4100 { /* Unknown standard opcode, ignore it. */
4102 for (i
= 0; i
< lh
.standard_opcode_lengths
[op_code
]; i
++)
4104 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4105 line_ptr
+= bytes_read
;
4112 do_cleanups (back_to
);
4115 /* Start a subfile for DWARF. FILENAME is the name of the file and
4116 DIRNAME the name of the source directory which contains FILENAME
4117 or NULL if not known.
4118 This routine tries to keep line numbers from identical absolute and
4119 relative file names in a common subfile.
4121 Using the `list' example from the GDB testsuite, which resides in
4122 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4123 of /srcdir/list0.c yields the following debugging information for list0.c:
4125 DW_AT_name: /srcdir/list0.c
4126 DW_AT_comp_dir: /compdir
4127 files.files[0].name: list0.h
4128 files.files[0].dir: /srcdir
4129 files.files[1].name: list0.c
4130 files.files[1].dir: /srcdir
4132 The line number information for list0.c has to end up in a single
4133 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4136 dwarf2_start_subfile (char *filename
, char *dirname
)
4138 /* If the filename isn't absolute, try to match an existing subfile
4139 with the full pathname. */
4141 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
4143 struct subfile
*subfile
;
4144 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4146 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4148 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
4150 current_subfile
= subfile
;
4157 start_subfile (filename
, dirname
);
4160 /* Given a pointer to a DWARF information entry, figure out if we need
4161 to make a symbol table entry for it, and if so, create a new entry
4162 and return a pointer to it.
4163 If TYPE is NULL, determine symbol type from the die, otherwise
4164 used the passed type. */
4166 static struct symbol
*
4167 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
4168 const struct comp_unit_head
*cu_header
)
4170 struct symbol
*sym
= NULL
;
4172 struct attribute
*attr
= NULL
;
4173 struct attribute
*attr2
= NULL
;
4176 name
= dwarf2_linkage_name (die
);
4179 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4180 sizeof (struct symbol
));
4181 OBJSTAT (objfile
, n_syms
++);
4182 memset (sym
, 0, sizeof (struct symbol
));
4183 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4184 &objfile
->symbol_obstack
);
4186 /* Default assumptions.
4187 Use the passed type or decode it from the die. */
4188 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4189 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4191 SYMBOL_TYPE (sym
) = type
;
4193 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
4194 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4197 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4200 /* If this symbol is from a C++ compilation, then attempt to
4201 cache the demangled form for future reference. This is a
4202 typical time versus space tradeoff, that was decided in favor
4203 of time because it sped up C++ symbol lookups by a factor of
4206 SYMBOL_LANGUAGE (sym
) = cu_language
;
4207 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4211 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4214 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4216 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4218 case DW_TAG_subprogram
:
4219 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4221 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4222 attr2
= dwarf_attr (die
, DW_AT_external
);
4223 if (attr2
&& (DW_UNSND (attr2
) != 0))
4225 add_symbol_to_list (sym
, &global_symbols
);
4229 add_symbol_to_list (sym
, list_in_scope
);
4232 case DW_TAG_variable
:
4233 /* Compilation with minimal debug info may result in variables
4234 with missing type entries. Change the misleading `void' type
4235 to something sensible. */
4236 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4237 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4238 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4239 "<variable, no debug info>",
4241 attr
= dwarf_attr (die
, DW_AT_const_value
);
4244 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4245 attr2
= dwarf_attr (die
, DW_AT_external
);
4246 if (attr2
&& (DW_UNSND (attr2
) != 0))
4247 add_symbol_to_list (sym
, &global_symbols
);
4249 add_symbol_to_list (sym
, list_in_scope
);
4252 attr
= dwarf_attr (die
, DW_AT_location
);
4255 attr2
= dwarf_attr (die
, DW_AT_external
);
4256 if (attr2
&& (DW_UNSND (attr2
) != 0))
4258 SYMBOL_VALUE_ADDRESS (sym
) =
4259 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4260 add_symbol_to_list (sym
, &global_symbols
);
4262 /* In shared libraries the address of the variable
4263 in the location descriptor might still be relocatable,
4264 so its value could be zero.
4265 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4266 value is zero, the address of the variable will then
4267 be determined from the minimal symbol table whenever
4268 the variable is referenced. */
4269 if (SYMBOL_VALUE_ADDRESS (sym
))
4271 fixup_symbol_section (sym
, objfile
);
4272 SYMBOL_VALUE_ADDRESS (sym
) +=
4273 ANOFFSET (objfile
->section_offsets
,
4274 SYMBOL_SECTION (sym
));
4275 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4278 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4282 SYMBOL_VALUE (sym
) = addr
=
4283 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4284 add_symbol_to_list (sym
, list_in_scope
);
4287 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4291 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4292 SYMBOL_VALUE (sym
) =
4293 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4297 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4298 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4302 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4306 fixup_symbol_section (sym
, objfile
);
4307 SYMBOL_VALUE_ADDRESS (sym
) =
4308 addr
+ ANOFFSET (objfile
->section_offsets
,
4309 SYMBOL_SECTION (sym
));
4310 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4316 /* We do not know the address of this symbol.
4317 If it is an external symbol and we have type information
4318 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4319 The address of the variable will then be determined from
4320 the minimal symbol table whenever the variable is
4322 attr2
= dwarf_attr (die
, DW_AT_external
);
4323 if (attr2
&& (DW_UNSND (attr2
) != 0)
4324 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4326 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4327 add_symbol_to_list (sym
, &global_symbols
);
4331 case DW_TAG_formal_parameter
:
4332 attr
= dwarf_attr (die
, DW_AT_location
);
4335 SYMBOL_VALUE (sym
) =
4336 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4339 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4340 SYMBOL_VALUE (sym
) =
4341 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4347 if (basereg
!= frame_base_reg
)
4348 complain (&dwarf2_complex_location_expr
);
4349 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4353 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4354 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4359 SYMBOL_CLASS (sym
) = LOC_ARG
;
4362 attr
= dwarf_attr (die
, DW_AT_const_value
);
4365 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4367 add_symbol_to_list (sym
, list_in_scope
);
4369 case DW_TAG_unspecified_parameters
:
4370 /* From varargs functions; gdb doesn't seem to have any
4371 interest in this information, so just ignore it for now.
4374 case DW_TAG_class_type
:
4375 case DW_TAG_structure_type
:
4376 case DW_TAG_union_type
:
4377 case DW_TAG_enumeration_type
:
4378 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4379 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4380 add_symbol_to_list (sym
, list_in_scope
);
4382 /* The semantics of C++ state that "struct foo { ... }" also
4383 defines a typedef for "foo". Synthesize a typedef symbol so
4384 that "ptype foo" works as expected. */
4385 if (cu_language
== language_cplus
)
4387 struct symbol
*typedef_sym
= (struct symbol
*)
4388 obstack_alloc (&objfile
->symbol_obstack
,
4389 sizeof (struct symbol
));
4390 *typedef_sym
= *sym
;
4391 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4392 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4393 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4394 obsavestring (SYMBOL_NAME (sym
),
4395 strlen (SYMBOL_NAME (sym
)),
4396 &objfile
->type_obstack
);
4397 add_symbol_to_list (typedef_sym
, list_in_scope
);
4400 case DW_TAG_typedef
:
4401 case DW_TAG_base_type
:
4402 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4403 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4404 add_symbol_to_list (sym
, list_in_scope
);
4406 case DW_TAG_enumerator
:
4407 attr
= dwarf_attr (die
, DW_AT_const_value
);
4410 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4412 add_symbol_to_list (sym
, list_in_scope
);
4415 /* Not a tag we recognize. Hopefully we aren't processing
4416 trash data, but since we must specifically ignore things
4417 we don't recognize, there is nothing else we should do at
4419 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4426 /* Copy constant value from an attribute to a symbol. */
4429 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
4430 struct objfile
*objfile
,
4431 const struct comp_unit_head
*cu_header
)
4433 struct dwarf_block
*blk
;
4438 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
4439 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4440 cu_header
->addr_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4441 SYMBOL_VALUE_BYTES (sym
) = (char *)
4442 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
4443 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
4445 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4447 case DW_FORM_block1
:
4448 case DW_FORM_block2
:
4449 case DW_FORM_block4
:
4451 blk
= DW_BLOCK (attr
);
4452 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4453 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4454 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4455 SYMBOL_VALUE_BYTES (sym
) = (char *)
4456 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4457 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4458 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4461 /* The DW_AT_const_value attributes are supposed to carry the
4462 symbol's value "represented as it would be on the target
4463 architecture." By the time we get here, it's already been
4464 converted to host endianness, so we just need to sign- or
4465 zero-extend it as appropriate. */
4467 dwarf2_const_value_data (attr
, sym
, 8);
4470 dwarf2_const_value_data (attr
, sym
, 16);
4473 dwarf2_const_value_data (attr
, sym
, 32);
4476 dwarf2_const_value_data (attr
, sym
, 64);
4480 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4481 SYMBOL_CLASS (sym
) = LOC_CONST
;
4485 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4486 SYMBOL_CLASS (sym
) = LOC_CONST
;
4490 complain (&dwarf2_unsupported_const_value_attr
,
4491 dwarf_form_name (attr
->form
));
4492 SYMBOL_VALUE (sym
) = 0;
4493 SYMBOL_CLASS (sym
) = LOC_CONST
;
4499 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4500 or zero-extend it as appropriate for the symbol's type. */
4502 dwarf2_const_value_data (struct attribute
*attr
,
4506 LONGEST l
= DW_UNSND (attr
);
4508 if (bits
< sizeof (l
) * 8)
4510 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4511 l
&= ((LONGEST
) 1 << bits
) - 1;
4513 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4516 SYMBOL_VALUE (sym
) = l
;
4517 SYMBOL_CLASS (sym
) = LOC_CONST
;
4521 /* Return the type of the die in question using its DW_AT_type attribute. */
4523 static struct type
*
4524 die_type (struct die_info
*die
, struct objfile
*objfile
,
4525 const struct comp_unit_head
*cu_header
)
4528 struct attribute
*type_attr
;
4529 struct die_info
*type_die
;
4532 type_attr
= dwarf_attr (die
, DW_AT_type
);
4535 /* A missing DW_AT_type represents a void type. */
4536 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4540 ref
= dwarf2_get_ref_die_offset (type_attr
);
4541 type_die
= follow_die_ref (ref
);
4544 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4548 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4551 dump_die (type_die
);
4552 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4557 /* Return the containing type of the die in question using its
4558 DW_AT_containing_type attribute. */
4560 static struct type
*
4561 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
4562 const struct comp_unit_head
*cu_header
)
4564 struct type
*type
= NULL
;
4565 struct attribute
*type_attr
;
4566 struct die_info
*type_die
= NULL
;
4569 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4572 ref
= dwarf2_get_ref_die_offset (type_attr
);
4573 type_die
= follow_die_ref (ref
);
4576 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4579 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4584 dump_die (type_die
);
4585 error ("Dwarf Error: Problem turning containing type into gdb type.");
4591 static struct type
*
4592 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
4594 struct die_info
*die
;
4597 die
= follow_die_ref (offset
);
4600 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4603 type
= tag_type_to_type (die
, objfile
);
4608 static struct type
*
4609 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
4610 const struct comp_unit_head
*cu_header
)
4618 read_type_die (die
, objfile
, cu_header
);
4622 error ("Dwarf Error: Cannot find type of die.");
4629 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
4630 const struct comp_unit_head
*cu_header
)
4634 case DW_TAG_class_type
:
4635 case DW_TAG_structure_type
:
4636 case DW_TAG_union_type
:
4637 read_structure_scope (die
, objfile
, cu_header
);
4639 case DW_TAG_enumeration_type
:
4640 read_enumeration (die
, objfile
, cu_header
);
4642 case DW_TAG_subprogram
:
4643 case DW_TAG_subroutine_type
:
4644 read_subroutine_type (die
, objfile
, cu_header
);
4646 case DW_TAG_array_type
:
4647 read_array_type (die
, objfile
, cu_header
);
4649 case DW_TAG_pointer_type
:
4650 read_tag_pointer_type (die
, objfile
, cu_header
);
4652 case DW_TAG_ptr_to_member_type
:
4653 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
4655 case DW_TAG_reference_type
:
4656 read_tag_reference_type (die
, objfile
, cu_header
);
4658 case DW_TAG_const_type
:
4659 read_tag_const_type (die
, objfile
, cu_header
);
4661 case DW_TAG_volatile_type
:
4662 read_tag_volatile_type (die
, objfile
, cu_header
);
4664 case DW_TAG_string_type
:
4665 read_tag_string_type (die
, objfile
);
4667 case DW_TAG_typedef
:
4668 read_typedef (die
, objfile
, cu_header
);
4670 case DW_TAG_base_type
:
4671 read_base_type (die
, objfile
);
4674 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4679 static struct type
*
4680 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
4682 /* FIXME - this should not produce a new (struct type *)
4683 every time. It should cache base types. */
4687 case DW_ATE_address
:
4688 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4690 case DW_ATE_boolean
:
4691 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4693 case DW_ATE_complex_float
:
4696 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4700 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4706 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4710 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4717 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4720 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4724 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4728 case DW_ATE_signed_char
:
4729 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4731 case DW_ATE_unsigned
:
4735 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4738 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4742 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4746 case DW_ATE_unsigned_char
:
4747 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4750 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4757 copy_die (struct die_info
*old_die
)
4759 struct die_info
*new_die
;
4762 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4763 memset (new_die
, 0, sizeof (struct die_info
));
4765 new_die
->tag
= old_die
->tag
;
4766 new_die
->has_children
= old_die
->has_children
;
4767 new_die
->abbrev
= old_die
->abbrev
;
4768 new_die
->offset
= old_die
->offset
;
4769 new_die
->type
= NULL
;
4771 num_attrs
= old_die
->num_attrs
;
4772 new_die
->num_attrs
= num_attrs
;
4773 new_die
->attrs
= (struct attribute
*)
4774 xmalloc (num_attrs
* sizeof (struct attribute
));
4776 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4778 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4779 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4780 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4783 new_die
->next
= NULL
;
4788 /* Return sibling of die, NULL if no sibling. */
4790 static struct die_info
*
4791 sibling_die (struct die_info
*die
)
4793 int nesting_level
= 0;
4795 if (!die
->has_children
)
4797 if (die
->next
&& (die
->next
->tag
== 0))
4810 if (die
->has_children
)
4820 while (nesting_level
);
4821 if (die
&& (die
->tag
== 0))
4832 /* Get linkage name of a die, return NULL if not found. */
4835 dwarf2_linkage_name (struct die_info
*die
)
4837 struct attribute
*attr
;
4839 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4840 if (attr
&& DW_STRING (attr
))
4841 return DW_STRING (attr
);
4842 attr
= dwarf_attr (die
, DW_AT_name
);
4843 if (attr
&& DW_STRING (attr
))
4844 return DW_STRING (attr
);
4848 /* Convert a DIE tag into its string name. */
4851 dwarf_tag_name (register unsigned tag
)
4855 case DW_TAG_padding
:
4856 return "DW_TAG_padding";
4857 case DW_TAG_array_type
:
4858 return "DW_TAG_array_type";
4859 case DW_TAG_class_type
:
4860 return "DW_TAG_class_type";
4861 case DW_TAG_entry_point
:
4862 return "DW_TAG_entry_point";
4863 case DW_TAG_enumeration_type
:
4864 return "DW_TAG_enumeration_type";
4865 case DW_TAG_formal_parameter
:
4866 return "DW_TAG_formal_parameter";
4867 case DW_TAG_imported_declaration
:
4868 return "DW_TAG_imported_declaration";
4870 return "DW_TAG_label";
4871 case DW_TAG_lexical_block
:
4872 return "DW_TAG_lexical_block";
4874 return "DW_TAG_member";
4875 case DW_TAG_pointer_type
:
4876 return "DW_TAG_pointer_type";
4877 case DW_TAG_reference_type
:
4878 return "DW_TAG_reference_type";
4879 case DW_TAG_compile_unit
:
4880 return "DW_TAG_compile_unit";
4881 case DW_TAG_string_type
:
4882 return "DW_TAG_string_type";
4883 case DW_TAG_structure_type
:
4884 return "DW_TAG_structure_type";
4885 case DW_TAG_subroutine_type
:
4886 return "DW_TAG_subroutine_type";
4887 case DW_TAG_typedef
:
4888 return "DW_TAG_typedef";
4889 case DW_TAG_union_type
:
4890 return "DW_TAG_union_type";
4891 case DW_TAG_unspecified_parameters
:
4892 return "DW_TAG_unspecified_parameters";
4893 case DW_TAG_variant
:
4894 return "DW_TAG_variant";
4895 case DW_TAG_common_block
:
4896 return "DW_TAG_common_block";
4897 case DW_TAG_common_inclusion
:
4898 return "DW_TAG_common_inclusion";
4899 case DW_TAG_inheritance
:
4900 return "DW_TAG_inheritance";
4901 case DW_TAG_inlined_subroutine
:
4902 return "DW_TAG_inlined_subroutine";
4904 return "DW_TAG_module";
4905 case DW_TAG_ptr_to_member_type
:
4906 return "DW_TAG_ptr_to_member_type";
4907 case DW_TAG_set_type
:
4908 return "DW_TAG_set_type";
4909 case DW_TAG_subrange_type
:
4910 return "DW_TAG_subrange_type";
4911 case DW_TAG_with_stmt
:
4912 return "DW_TAG_with_stmt";
4913 case DW_TAG_access_declaration
:
4914 return "DW_TAG_access_declaration";
4915 case DW_TAG_base_type
:
4916 return "DW_TAG_base_type";
4917 case DW_TAG_catch_block
:
4918 return "DW_TAG_catch_block";
4919 case DW_TAG_const_type
:
4920 return "DW_TAG_const_type";
4921 case DW_TAG_constant
:
4922 return "DW_TAG_constant";
4923 case DW_TAG_enumerator
:
4924 return "DW_TAG_enumerator";
4925 case DW_TAG_file_type
:
4926 return "DW_TAG_file_type";
4928 return "DW_TAG_friend";
4929 case DW_TAG_namelist
:
4930 return "DW_TAG_namelist";
4931 case DW_TAG_namelist_item
:
4932 return "DW_TAG_namelist_item";
4933 case DW_TAG_packed_type
:
4934 return "DW_TAG_packed_type";
4935 case DW_TAG_subprogram
:
4936 return "DW_TAG_subprogram";
4937 case DW_TAG_template_type_param
:
4938 return "DW_TAG_template_type_param";
4939 case DW_TAG_template_value_param
:
4940 return "DW_TAG_template_value_param";
4941 case DW_TAG_thrown_type
:
4942 return "DW_TAG_thrown_type";
4943 case DW_TAG_try_block
:
4944 return "DW_TAG_try_block";
4945 case DW_TAG_variant_part
:
4946 return "DW_TAG_variant_part";
4947 case DW_TAG_variable
:
4948 return "DW_TAG_variable";
4949 case DW_TAG_volatile_type
:
4950 return "DW_TAG_volatile_type";
4951 case DW_TAG_MIPS_loop
:
4952 return "DW_TAG_MIPS_loop";
4953 case DW_TAG_format_label
:
4954 return "DW_TAG_format_label";
4955 case DW_TAG_function_template
:
4956 return "DW_TAG_function_template";
4957 case DW_TAG_class_template
:
4958 return "DW_TAG_class_template";
4960 return "DW_TAG_<unknown>";
4964 /* Convert a DWARF attribute code into its string name. */
4967 dwarf_attr_name (register unsigned attr
)
4972 return "DW_AT_sibling";
4973 case DW_AT_location
:
4974 return "DW_AT_location";
4976 return "DW_AT_name";
4977 case DW_AT_ordering
:
4978 return "DW_AT_ordering";
4979 case DW_AT_subscr_data
:
4980 return "DW_AT_subscr_data";
4981 case DW_AT_byte_size
:
4982 return "DW_AT_byte_size";
4983 case DW_AT_bit_offset
:
4984 return "DW_AT_bit_offset";
4985 case DW_AT_bit_size
:
4986 return "DW_AT_bit_size";
4987 case DW_AT_element_list
:
4988 return "DW_AT_element_list";
4989 case DW_AT_stmt_list
:
4990 return "DW_AT_stmt_list";
4992 return "DW_AT_low_pc";
4994 return "DW_AT_high_pc";
4995 case DW_AT_language
:
4996 return "DW_AT_language";
4998 return "DW_AT_member";
5000 return "DW_AT_discr";
5001 case DW_AT_discr_value
:
5002 return "DW_AT_discr_value";
5003 case DW_AT_visibility
:
5004 return "DW_AT_visibility";
5006 return "DW_AT_import";
5007 case DW_AT_string_length
:
5008 return "DW_AT_string_length";
5009 case DW_AT_common_reference
:
5010 return "DW_AT_common_reference";
5011 case DW_AT_comp_dir
:
5012 return "DW_AT_comp_dir";
5013 case DW_AT_const_value
:
5014 return "DW_AT_const_value";
5015 case DW_AT_containing_type
:
5016 return "DW_AT_containing_type";
5017 case DW_AT_default_value
:
5018 return "DW_AT_default_value";
5020 return "DW_AT_inline";
5021 case DW_AT_is_optional
:
5022 return "DW_AT_is_optional";
5023 case DW_AT_lower_bound
:
5024 return "DW_AT_lower_bound";
5025 case DW_AT_producer
:
5026 return "DW_AT_producer";
5027 case DW_AT_prototyped
:
5028 return "DW_AT_prototyped";
5029 case DW_AT_return_addr
:
5030 return "DW_AT_return_addr";
5031 case DW_AT_start_scope
:
5032 return "DW_AT_start_scope";
5033 case DW_AT_stride_size
:
5034 return "DW_AT_stride_size";
5035 case DW_AT_upper_bound
:
5036 return "DW_AT_upper_bound";
5037 case DW_AT_abstract_origin
:
5038 return "DW_AT_abstract_origin";
5039 case DW_AT_accessibility
:
5040 return "DW_AT_accessibility";
5041 case DW_AT_address_class
:
5042 return "DW_AT_address_class";
5043 case DW_AT_artificial
:
5044 return "DW_AT_artificial";
5045 case DW_AT_base_types
:
5046 return "DW_AT_base_types";
5047 case DW_AT_calling_convention
:
5048 return "DW_AT_calling_convention";
5050 return "DW_AT_count";
5051 case DW_AT_data_member_location
:
5052 return "DW_AT_data_member_location";
5053 case DW_AT_decl_column
:
5054 return "DW_AT_decl_column";
5055 case DW_AT_decl_file
:
5056 return "DW_AT_decl_file";
5057 case DW_AT_decl_line
:
5058 return "DW_AT_decl_line";
5059 case DW_AT_declaration
:
5060 return "DW_AT_declaration";
5061 case DW_AT_discr_list
:
5062 return "DW_AT_discr_list";
5063 case DW_AT_encoding
:
5064 return "DW_AT_encoding";
5065 case DW_AT_external
:
5066 return "DW_AT_external";
5067 case DW_AT_frame_base
:
5068 return "DW_AT_frame_base";
5070 return "DW_AT_friend";
5071 case DW_AT_identifier_case
:
5072 return "DW_AT_identifier_case";
5073 case DW_AT_macro_info
:
5074 return "DW_AT_macro_info";
5075 case DW_AT_namelist_items
:
5076 return "DW_AT_namelist_items";
5077 case DW_AT_priority
:
5078 return "DW_AT_priority";
5080 return "DW_AT_segment";
5081 case DW_AT_specification
:
5082 return "DW_AT_specification";
5083 case DW_AT_static_link
:
5084 return "DW_AT_static_link";
5086 return "DW_AT_type";
5087 case DW_AT_use_location
:
5088 return "DW_AT_use_location";
5089 case DW_AT_variable_parameter
:
5090 return "DW_AT_variable_parameter";
5091 case DW_AT_virtuality
:
5092 return "DW_AT_virtuality";
5093 case DW_AT_vtable_elem_location
:
5094 return "DW_AT_vtable_elem_location";
5097 case DW_AT_MIPS_fde
:
5098 return "DW_AT_MIPS_fde";
5099 case DW_AT_MIPS_loop_begin
:
5100 return "DW_AT_MIPS_loop_begin";
5101 case DW_AT_MIPS_tail_loop_begin
:
5102 return "DW_AT_MIPS_tail_loop_begin";
5103 case DW_AT_MIPS_epilog_begin
:
5104 return "DW_AT_MIPS_epilog_begin";
5105 case DW_AT_MIPS_loop_unroll_factor
:
5106 return "DW_AT_MIPS_loop_unroll_factor";
5107 case DW_AT_MIPS_software_pipeline_depth
:
5108 return "DW_AT_MIPS_software_pipeline_depth";
5109 case DW_AT_MIPS_linkage_name
:
5110 return "DW_AT_MIPS_linkage_name";
5113 case DW_AT_sf_names
:
5114 return "DW_AT_sf_names";
5115 case DW_AT_src_info
:
5116 return "DW_AT_src_info";
5117 case DW_AT_mac_info
:
5118 return "DW_AT_mac_info";
5119 case DW_AT_src_coords
:
5120 return "DW_AT_src_coords";
5121 case DW_AT_body_begin
:
5122 return "DW_AT_body_begin";
5123 case DW_AT_body_end
:
5124 return "DW_AT_body_end";
5126 return "DW_AT_<unknown>";
5130 /* Convert a DWARF value form code into its string name. */
5133 dwarf_form_name (register unsigned form
)
5138 return "DW_FORM_addr";
5139 case DW_FORM_block2
:
5140 return "DW_FORM_block2";
5141 case DW_FORM_block4
:
5142 return "DW_FORM_block4";
5144 return "DW_FORM_data2";
5146 return "DW_FORM_data4";
5148 return "DW_FORM_data8";
5149 case DW_FORM_string
:
5150 return "DW_FORM_string";
5152 return "DW_FORM_block";
5153 case DW_FORM_block1
:
5154 return "DW_FORM_block1";
5156 return "DW_FORM_data1";
5158 return "DW_FORM_flag";
5160 return "DW_FORM_sdata";
5162 return "DW_FORM_strp";
5164 return "DW_FORM_udata";
5165 case DW_FORM_ref_addr
:
5166 return "DW_FORM_ref_addr";
5168 return "DW_FORM_ref1";
5170 return "DW_FORM_ref2";
5172 return "DW_FORM_ref4";
5174 return "DW_FORM_ref8";
5175 case DW_FORM_ref_udata
:
5176 return "DW_FORM_ref_udata";
5177 case DW_FORM_indirect
:
5178 return "DW_FORM_indirect";
5180 return "DW_FORM_<unknown>";
5184 /* Convert a DWARF stack opcode into its string name. */
5187 dwarf_stack_op_name (register unsigned op
)
5192 return "DW_OP_addr";
5194 return "DW_OP_deref";
5196 return "DW_OP_const1u";
5198 return "DW_OP_const1s";
5200 return "DW_OP_const2u";
5202 return "DW_OP_const2s";
5204 return "DW_OP_const4u";
5206 return "DW_OP_const4s";
5208 return "DW_OP_const8u";
5210 return "DW_OP_const8s";
5212 return "DW_OP_constu";
5214 return "DW_OP_consts";
5218 return "DW_OP_drop";
5220 return "DW_OP_over";
5222 return "DW_OP_pick";
5224 return "DW_OP_swap";
5228 return "DW_OP_xderef";
5236 return "DW_OP_minus";
5248 return "DW_OP_plus";
5249 case DW_OP_plus_uconst
:
5250 return "DW_OP_plus_uconst";
5256 return "DW_OP_shra";
5274 return "DW_OP_skip";
5276 return "DW_OP_lit0";
5278 return "DW_OP_lit1";
5280 return "DW_OP_lit2";
5282 return "DW_OP_lit3";
5284 return "DW_OP_lit4";
5286 return "DW_OP_lit5";
5288 return "DW_OP_lit6";
5290 return "DW_OP_lit7";
5292 return "DW_OP_lit8";
5294 return "DW_OP_lit9";
5296 return "DW_OP_lit10";
5298 return "DW_OP_lit11";
5300 return "DW_OP_lit12";
5302 return "DW_OP_lit13";
5304 return "DW_OP_lit14";
5306 return "DW_OP_lit15";
5308 return "DW_OP_lit16";
5310 return "DW_OP_lit17";
5312 return "DW_OP_lit18";
5314 return "DW_OP_lit19";
5316 return "DW_OP_lit20";
5318 return "DW_OP_lit21";
5320 return "DW_OP_lit22";
5322 return "DW_OP_lit23";
5324 return "DW_OP_lit24";
5326 return "DW_OP_lit25";
5328 return "DW_OP_lit26";
5330 return "DW_OP_lit27";
5332 return "DW_OP_lit28";
5334 return "DW_OP_lit29";
5336 return "DW_OP_lit30";
5338 return "DW_OP_lit31";
5340 return "DW_OP_reg0";
5342 return "DW_OP_reg1";
5344 return "DW_OP_reg2";
5346 return "DW_OP_reg3";
5348 return "DW_OP_reg4";
5350 return "DW_OP_reg5";
5352 return "DW_OP_reg6";
5354 return "DW_OP_reg7";
5356 return "DW_OP_reg8";
5358 return "DW_OP_reg9";
5360 return "DW_OP_reg10";
5362 return "DW_OP_reg11";
5364 return "DW_OP_reg12";
5366 return "DW_OP_reg13";
5368 return "DW_OP_reg14";
5370 return "DW_OP_reg15";
5372 return "DW_OP_reg16";
5374 return "DW_OP_reg17";
5376 return "DW_OP_reg18";
5378 return "DW_OP_reg19";
5380 return "DW_OP_reg20";
5382 return "DW_OP_reg21";
5384 return "DW_OP_reg22";
5386 return "DW_OP_reg23";
5388 return "DW_OP_reg24";
5390 return "DW_OP_reg25";
5392 return "DW_OP_reg26";
5394 return "DW_OP_reg27";
5396 return "DW_OP_reg28";
5398 return "DW_OP_reg29";
5400 return "DW_OP_reg30";
5402 return "DW_OP_reg31";
5404 return "DW_OP_breg0";
5406 return "DW_OP_breg1";
5408 return "DW_OP_breg2";
5410 return "DW_OP_breg3";
5412 return "DW_OP_breg4";
5414 return "DW_OP_breg5";
5416 return "DW_OP_breg6";
5418 return "DW_OP_breg7";
5420 return "DW_OP_breg8";
5422 return "DW_OP_breg9";
5424 return "DW_OP_breg10";
5426 return "DW_OP_breg11";
5428 return "DW_OP_breg12";
5430 return "DW_OP_breg13";
5432 return "DW_OP_breg14";
5434 return "DW_OP_breg15";
5436 return "DW_OP_breg16";
5438 return "DW_OP_breg17";
5440 return "DW_OP_breg18";
5442 return "DW_OP_breg19";
5444 return "DW_OP_breg20";
5446 return "DW_OP_breg21";
5448 return "DW_OP_breg22";
5450 return "DW_OP_breg23";
5452 return "DW_OP_breg24";
5454 return "DW_OP_breg25";
5456 return "DW_OP_breg26";
5458 return "DW_OP_breg27";
5460 return "DW_OP_breg28";
5462 return "DW_OP_breg29";
5464 return "DW_OP_breg30";
5466 return "DW_OP_breg31";
5468 return "DW_OP_regx";
5470 return "DW_OP_fbreg";
5472 return "DW_OP_bregx";
5474 return "DW_OP_piece";
5475 case DW_OP_deref_size
:
5476 return "DW_OP_deref_size";
5477 case DW_OP_xderef_size
:
5478 return "DW_OP_xderef_size";
5482 return "OP_<unknown>";
5487 dwarf_bool_name (unsigned mybool
)
5495 /* Convert a DWARF type code into its string name. */
5498 dwarf_type_encoding_name (register unsigned enc
)
5502 case DW_ATE_address
:
5503 return "DW_ATE_address";
5504 case DW_ATE_boolean
:
5505 return "DW_ATE_boolean";
5506 case DW_ATE_complex_float
:
5507 return "DW_ATE_complex_float";
5509 return "DW_ATE_float";
5511 return "DW_ATE_signed";
5512 case DW_ATE_signed_char
:
5513 return "DW_ATE_signed_char";
5514 case DW_ATE_unsigned
:
5515 return "DW_ATE_unsigned";
5516 case DW_ATE_unsigned_char
:
5517 return "DW_ATE_unsigned_char";
5519 return "DW_ATE_<unknown>";
5523 /* Convert a DWARF call frame info operation to its string name. */
5527 dwarf_cfi_name (register unsigned cfi_opc
)
5531 case DW_CFA_advance_loc
:
5532 return "DW_CFA_advance_loc";
5534 return "DW_CFA_offset";
5535 case DW_CFA_restore
:
5536 return "DW_CFA_restore";
5538 return "DW_CFA_nop";
5539 case DW_CFA_set_loc
:
5540 return "DW_CFA_set_loc";
5541 case DW_CFA_advance_loc1
:
5542 return "DW_CFA_advance_loc1";
5543 case DW_CFA_advance_loc2
:
5544 return "DW_CFA_advance_loc2";
5545 case DW_CFA_advance_loc4
:
5546 return "DW_CFA_advance_loc4";
5547 case DW_CFA_offset_extended
:
5548 return "DW_CFA_offset_extended";
5549 case DW_CFA_restore_extended
:
5550 return "DW_CFA_restore_extended";
5551 case DW_CFA_undefined
:
5552 return "DW_CFA_undefined";
5553 case DW_CFA_same_value
:
5554 return "DW_CFA_same_value";
5555 case DW_CFA_register
:
5556 return "DW_CFA_register";
5557 case DW_CFA_remember_state
:
5558 return "DW_CFA_remember_state";
5559 case DW_CFA_restore_state
:
5560 return "DW_CFA_restore_state";
5561 case DW_CFA_def_cfa
:
5562 return "DW_CFA_def_cfa";
5563 case DW_CFA_def_cfa_register
:
5564 return "DW_CFA_def_cfa_register";
5565 case DW_CFA_def_cfa_offset
:
5566 return "DW_CFA_def_cfa_offset";
5567 /* SGI/MIPS specific */
5568 case DW_CFA_MIPS_advance_loc8
:
5569 return "DW_CFA_MIPS_advance_loc8";
5571 return "DW_CFA_<unknown>";
5577 dump_die (struct die_info
*die
)
5581 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5582 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5583 fprintf (stderr
, "\thas children: %s\n",
5584 dwarf_bool_name (die
->has_children
));
5586 fprintf (stderr
, "\tattributes:\n");
5587 for (i
= 0; i
< die
->num_attrs
; ++i
)
5589 fprintf (stderr
, "\t\t%s (%s) ",
5590 dwarf_attr_name (die
->attrs
[i
].name
),
5591 dwarf_form_name (die
->attrs
[i
].form
));
5592 switch (die
->attrs
[i
].form
)
5594 case DW_FORM_ref_addr
:
5596 fprintf (stderr
, "address: ");
5597 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5599 case DW_FORM_block2
:
5600 case DW_FORM_block4
:
5602 case DW_FORM_block1
:
5603 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5614 fprintf (stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
5616 case DW_FORM_string
:
5618 fprintf (stderr
, "string: \"%s\"",
5619 DW_STRING (&die
->attrs
[i
])
5620 ? DW_STRING (&die
->attrs
[i
]) : "");
5623 if (DW_UNSND (&die
->attrs
[i
]))
5624 fprintf (stderr
, "flag: TRUE");
5626 fprintf (stderr
, "flag: FALSE");
5628 case DW_FORM_indirect
: /* we do not handle indirect yet */
5630 fprintf (stderr
, "unsupported attribute form: %d.",
5631 die
->attrs
[i
].form
);
5633 fprintf (stderr
, "\n");
5638 dump_die_list (struct die_info
*die
)
5648 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
5651 struct die_info
*old
;
5653 h
= (offset
% REF_HASH_SIZE
);
5654 old
= die_ref_table
[h
];
5655 die
->next_ref
= old
;
5656 die_ref_table
[h
] = die
;
5661 dwarf2_empty_hash_tables (void)
5663 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5667 dwarf2_get_ref_die_offset (struct attribute
*attr
)
5669 unsigned int result
= 0;
5673 case DW_FORM_ref_addr
:
5674 result
= DW_ADDR (attr
);
5680 case DW_FORM_ref_udata
:
5681 result
= cu_header_offset
+ DW_UNSND (attr
);
5684 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5689 static struct die_info
*
5690 follow_die_ref (unsigned int offset
)
5692 struct die_info
*die
;
5695 h
= (offset
% REF_HASH_SIZE
);
5696 die
= die_ref_table
[h
];
5699 if (die
->offset
== offset
)
5703 die
= die
->next_ref
;
5708 static struct type
*
5709 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
5711 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5713 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5717 /* Look for this particular type in the fundamental type vector. If
5718 one is not found, create and install one appropriate for the
5719 current language and the current target machine. */
5721 if (ftypes
[typeid] == NULL
)
5723 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5726 return (ftypes
[typeid]);
5729 /* Decode simple location descriptions.
5730 Given a pointer to a dwarf block that defines a location, compute
5731 the location and return the value.
5733 FIXME: This is a kludge until we figure out a better
5734 way to handle the location descriptions.
5735 Gdb's design does not mesh well with the DWARF2 notion of a location
5736 computing interpreter, which is a shame because the flexibility goes unused.
5737 FIXME: Implement more operations as necessary.
5739 A location description containing no operations indicates that the
5740 object is optimized out. The global optimized_out flag is set for
5741 those, the return value is meaningless.
5743 When the result is a register number, the global isreg flag is set,
5744 otherwise it is cleared.
5746 When the result is a base register offset, the global offreg flag is set
5747 and the register number is returned in basereg, otherwise it is cleared.
5749 When the DW_OP_fbreg operation is encountered without a corresponding
5750 DW_AT_frame_base attribute, the global islocal flag is set.
5751 Hopefully the machine dependent code knows how to set up a virtual
5752 frame pointer for the local references.
5754 Note that stack[0] is unused except as a default error return.
5755 Note that stack overflow is not yet handled. */
5758 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
5759 const struct comp_unit_head
*cu_header
)
5762 int size
= blk
->size
;
5763 char *data
= blk
->data
;
5764 CORE_ADDR stack
[64];
5766 unsigned int bytes_read
, unsnd
;
5817 stack
[++stacki
] = op
- DW_OP_reg0
;
5822 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5824 #if defined(HARRIS_TARGET) && defined(_M88K)
5825 /* The Harris 88110 gdb ports have long kept their special reg
5826 numbers between their gp-regs and their x-regs. This is
5827 not how our dwarf is generated. Punt. */
5830 stack
[++stacki
] = unsnd
;
5866 basereg
= op
- DW_OP_breg0
;
5867 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5873 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5875 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5880 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5882 if (frame_base_reg
>= 0)
5885 basereg
= frame_base_reg
;
5886 stack
[stacki
] += frame_base_offset
;
5890 complain (&dwarf2_missing_at_frame_base
);
5896 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
5897 cu_header
, &bytes_read
);
5902 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5907 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5912 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5917 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5922 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5927 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5932 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5938 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5943 stack
[stacki
- 1] += stack
[stacki
];
5947 case DW_OP_plus_uconst
:
5948 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5953 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5959 /* If we're not the last op, then we definitely can't encode
5960 this using GDB's address_class enum. */
5962 complain (&dwarf2_complex_location_expr
);
5966 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
5967 return (stack
[stacki
]);
5970 return (stack
[stacki
]);
5973 /* memory allocation interface */
5977 dwarf2_free_tmp_obstack (PTR ignore
)
5979 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5982 static struct dwarf_block
*
5983 dwarf_alloc_block (void)
5985 struct dwarf_block
*blk
;
5987 blk
= (struct dwarf_block
*)
5988 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5992 static struct abbrev_info
*
5993 dwarf_alloc_abbrev (void)
5995 struct abbrev_info
*abbrev
;
5997 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5998 memset (abbrev
, 0, sizeof (struct abbrev_info
));
6002 static struct die_info
*
6003 dwarf_alloc_die (void)
6005 struct die_info
*die
;
6007 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6008 memset (die
, 0, sizeof (struct die_info
));