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 char *read_attribute_value (struct attribute
*, unsigned,
609 bfd
*, char *, const struct comp_unit_head
*);
611 static unsigned int read_1_byte (bfd
*, char *);
613 static int read_1_signed_byte (bfd
*, char *);
615 static unsigned int read_2_bytes (bfd
*, char *);
617 static unsigned int read_4_bytes (bfd
*, char *);
619 static unsigned long read_8_bytes (bfd
*, char *);
621 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
624 static LONGEST
read_initial_length (bfd
*, char *,
625 struct comp_unit_head
*, int *bytes_read
);
627 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
630 static char *read_n_bytes (bfd
*, char *, unsigned int);
632 static char *read_string (bfd
*, char *, unsigned int *);
634 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
637 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
639 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
641 static void set_cu_language (unsigned int);
643 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
645 static int die_is_declaration (struct die_info
*);
647 static void dwarf_decode_lines (unsigned int, char *, bfd
*,
648 const struct comp_unit_head
*);
650 static void dwarf2_start_subfile (char *, char *);
652 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
653 struct objfile
*, const struct comp_unit_head
*);
655 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
656 struct objfile
*, const struct comp_unit_head
*);
658 static void dwarf2_const_value_data (struct attribute
*attr
,
662 static struct type
*die_type (struct die_info
*, struct objfile
*,
663 const struct comp_unit_head
*);
665 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
666 const struct comp_unit_head
*);
669 static struct type
*type_at_offset (unsigned int, struct objfile
*);
672 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
673 const struct comp_unit_head
*);
675 static void read_type_die (struct die_info
*, struct objfile
*,
676 const struct comp_unit_head
*);
678 static void read_typedef (struct die_info
*, struct objfile
*,
679 const struct comp_unit_head
*);
681 static void read_base_type (struct die_info
*, struct objfile
*);
683 static void read_file_scope (struct die_info
*, struct objfile
*,
684 const struct comp_unit_head
*);
686 static void read_func_scope (struct die_info
*, struct objfile
*,
687 const struct comp_unit_head
*);
689 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
690 const struct comp_unit_head
*);
692 static int dwarf2_get_pc_bounds (struct die_info
*,
693 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*);
695 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
696 struct objfile
*, const struct comp_unit_head
*);
698 static void dwarf2_attach_fields_to_type (struct field_info
*,
699 struct type
*, struct objfile
*);
701 static void dwarf2_add_member_fn (struct field_info
*,
702 struct die_info
*, struct type
*,
703 struct objfile
*objfile
,
704 const struct comp_unit_head
*);
706 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
707 struct type
*, struct objfile
*);
709 static void read_structure_scope (struct die_info
*, struct objfile
*,
710 const struct comp_unit_head
*);
712 static void read_common_block (struct die_info
*, struct objfile
*,
713 const struct comp_unit_head
*);
715 static void read_enumeration (struct die_info
*, struct objfile
*,
716 const struct comp_unit_head
*);
718 static struct type
*dwarf_base_type (int, int, struct objfile
*);
720 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
721 const struct comp_unit_head
*);
723 static void read_array_type (struct die_info
*, struct objfile
*,
724 const struct comp_unit_head
*);
726 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
727 const struct comp_unit_head
*);
729 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
730 const struct comp_unit_head
*);
732 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
733 const struct comp_unit_head
*);
735 static void read_tag_const_type (struct die_info
*, struct objfile
*,
736 const struct comp_unit_head
*);
738 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
739 const struct comp_unit_head
*);
741 static void read_tag_string_type (struct die_info
*, struct objfile
*);
743 static void read_subroutine_type (struct die_info
*, struct objfile
*,
744 const struct comp_unit_head
*);
746 static struct die_info
*read_comp_unit (char *, bfd
*,
747 const struct comp_unit_head
*);
749 static void free_die_list (struct die_info
*);
751 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
753 static void process_die (struct die_info
*, struct objfile
*,
754 const struct comp_unit_head
*);
756 static char *dwarf2_linkage_name (struct die_info
*);
758 static char *dwarf_tag_name (unsigned int);
760 static char *dwarf_attr_name (unsigned int);
762 static char *dwarf_form_name (unsigned int);
764 static char *dwarf_stack_op_name (unsigned int);
766 static char *dwarf_bool_name (unsigned int);
768 static char *dwarf_type_encoding_name (unsigned int);
771 static char *dwarf_cfi_name (unsigned int);
773 struct die_info
*copy_die (struct die_info
*);
776 static struct die_info
*sibling_die (struct die_info
*);
778 static void dump_die (struct die_info
*);
780 static void dump_die_list (struct die_info
*);
782 static void store_in_ref_table (unsigned int, struct die_info
*);
784 static void dwarf2_empty_hash_tables (void);
786 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
788 static struct die_info
*follow_die_ref (unsigned int);
790 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
792 /* memory allocation interface */
794 static void dwarf2_free_tmp_obstack (PTR
);
796 static struct dwarf_block
*dwarf_alloc_block (void);
798 static struct abbrev_info
*dwarf_alloc_abbrev (void);
800 static struct die_info
*dwarf_alloc_die (void);
802 /* Try to locate the sections we need for DWARF 2 debugging
803 information and return true if we have enough to do something. */
806 dwarf2_has_info (bfd
*abfd
)
808 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
809 dwarf_str_offset
= 0;
810 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
811 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
821 /* This function is mapped across the sections and remembers the
822 offset and size of each of the debugging sections we are interested
826 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, PTR ignore_ptr
)
828 if (STREQ (sectp
->name
, INFO_SECTION
))
830 dwarf_info_offset
= sectp
->filepos
;
831 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
833 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
835 dwarf_abbrev_offset
= sectp
->filepos
;
836 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
838 else if (STREQ (sectp
->name
, LINE_SECTION
))
840 dwarf_line_offset
= sectp
->filepos
;
841 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
843 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
845 dwarf_pubnames_offset
= sectp
->filepos
;
846 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
848 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
850 dwarf_aranges_offset
= sectp
->filepos
;
851 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
853 else if (STREQ (sectp
->name
, LOC_SECTION
))
855 dwarf_loc_offset
= sectp
->filepos
;
856 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
858 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
860 dwarf_macinfo_offset
= sectp
->filepos
;
861 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
863 else if (STREQ (sectp
->name
, STR_SECTION
))
865 dwarf_str_offset
= sectp
->filepos
;
866 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
870 /* Build a partial symbol table. */
873 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
876 /* We definitely need the .debug_info and .debug_abbrev sections */
878 dwarf_info_buffer
= dwarf2_read_section (objfile
,
881 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
884 dwarf_line_buffer
= dwarf2_read_section (objfile
,
888 if (dwarf_str_offset
)
889 dwarf_str_buffer
= dwarf2_read_section (objfile
,
893 dwarf_str_buffer
= NULL
;
896 || (objfile
->global_psymbols
.size
== 0
897 && objfile
->static_psymbols
.size
== 0))
899 init_psymbol_list (objfile
, 1024);
903 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
905 /* Things are significantly easier if we have .debug_aranges and
906 .debug_pubnames sections */
908 dwarf2_build_psymtabs_easy (objfile
, mainline
);
912 /* only test this case for now */
914 /* In this case we have to work a bit harder */
915 dwarf2_build_psymtabs_hard (objfile
, mainline
);
920 /* Build the partial symbol table from the information in the
921 .debug_pubnames and .debug_aranges sections. */
924 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
926 bfd
*abfd
= objfile
->obfd
;
927 char *aranges_buffer
, *pubnames_buffer
;
928 char *aranges_ptr
, *pubnames_ptr
;
929 unsigned int entry_length
, version
, info_offset
, info_size
;
931 pubnames_buffer
= dwarf2_read_section (objfile
,
932 dwarf_pubnames_offset
,
933 dwarf_pubnames_size
);
934 pubnames_ptr
= pubnames_buffer
;
935 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
937 struct comp_unit_head cu_header
;
940 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
942 pubnames_ptr
+= bytes_read
;
943 version
= read_1_byte (abfd
, pubnames_ptr
);
945 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
947 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
951 aranges_buffer
= dwarf2_read_section (objfile
,
952 dwarf_aranges_offset
,
958 /* Read in the comp unit header information from the debug_info at
962 read_comp_unit_head (struct comp_unit_head
*cu_header
,
963 char *info_ptr
, bfd
*abfd
)
967 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
969 info_ptr
+= bytes_read
;
970 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
972 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
974 info_ptr
+= bytes_read
;
975 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
977 signed_addr
= bfd_get_sign_extend_vma (abfd
);
979 internal_error (__FILE__
, __LINE__
,
980 "read_comp_unit_head: dwarf from non elf file");
981 cu_header
->signed_addr_p
= signed_addr
;
985 /* Build the partial symbol table by doing a quick pass through the
986 .debug_info and .debug_abbrev sections. */
989 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
991 /* Instead of reading this into a big buffer, we should probably use
992 mmap() on architectures that support it. (FIXME) */
993 bfd
*abfd
= objfile
->obfd
;
994 char *info_ptr
, *abbrev_ptr
;
995 char *beg_of_comp_unit
;
996 struct partial_die_info comp_unit_die
;
997 struct partial_symtab
*pst
;
998 struct cleanup
*back_to
;
999 CORE_ADDR lowpc
, highpc
;
1001 info_ptr
= dwarf_info_buffer
;
1002 abbrev_ptr
= dwarf_abbrev_buffer
;
1004 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1005 the partial symbol scan, like attribute values.
1007 We could reduce our peak memory consumption during partial symbol
1008 table construction by freeing stuff from this obstack more often
1009 --- say, after processing each compilation unit, or each die ---
1010 but it turns out that this saves almost nothing. For an
1011 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1012 on dwarf2_tmp_obstack. Some investigation showed:
1014 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1015 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1016 all fixed-length values not requiring dynamic allocation.
1018 2) 30% of the attributes used the form DW_FORM_string. For
1019 DW_FORM_string, read_attribute simply hands back a pointer to
1020 the null-terminated string in dwarf_info_buffer, so no dynamic
1021 allocation is needed there either.
1023 3) The remaining 1% of the attributes all used DW_FORM_block1.
1024 75% of those were DW_AT_frame_base location lists for
1025 functions; the rest were DW_AT_location attributes, probably
1026 for the global variables.
1028 Anyway, what this all means is that the memory the dwarf2
1029 reader uses as temporary space reading partial symbols is about
1030 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1032 obstack_init (&dwarf2_tmp_obstack
);
1033 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1035 /* Since the objects we're extracting from dwarf_info_buffer vary in
1036 length, only the individual functions to extract them (like
1037 read_comp_unit_head and read_partial_die) can really know whether
1038 the buffer is large enough to hold another complete object.
1040 At the moment, they don't actually check that. If
1041 dwarf_info_buffer holds just one extra byte after the last
1042 compilation unit's dies, then read_comp_unit_head will happily
1043 read off the end of the buffer. read_partial_die is similarly
1044 casual. Those functions should be fixed.
1046 For this loop condition, simply checking whether there's any data
1047 left at all should be sufficient. */
1048 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1050 struct comp_unit_head cu_header
;
1051 beg_of_comp_unit
= info_ptr
;
1052 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1054 if (cu_header
.version
!= 2)
1056 error ("Dwarf Error: wrong version in compilation unit header.");
1059 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
1061 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
1062 (long) cu_header
.abbrev_offset
,
1063 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1066 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1067 > dwarf_info_buffer
+ dwarf_info_size
)
1069 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
1070 (long) cu_header
.length
,
1071 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1074 /* Read the abbrevs for this compilation unit into a table */
1075 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1076 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1078 /* Read the compilation unit die */
1079 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1082 /* Set the language we're debugging */
1083 set_cu_language (comp_unit_die
.language
);
1085 /* Allocate a new partial symbol table structure */
1086 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1087 comp_unit_die
.name
? comp_unit_die
.name
: "",
1088 comp_unit_die
.lowpc
,
1089 objfile
->global_psymbols
.next
,
1090 objfile
->static_psymbols
.next
);
1092 pst
->read_symtab_private
= (char *)
1093 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1094 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1095 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1096 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1097 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1098 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1099 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1100 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1101 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1102 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1104 /* Store the function that reads in the rest of the symbol table */
1105 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1107 /* Check if comp unit has_children.
1108 If so, read the rest of the partial symbols from this comp unit.
1109 If not, there's no more debug_info for this comp unit. */
1110 if (comp_unit_die
.has_children
)
1112 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1115 /* If the compilation unit didn't have an explicit address range,
1116 then use the information extracted from its child dies. */
1117 if (! comp_unit_die
.has_pc_info
)
1119 comp_unit_die
.lowpc
= lowpc
;
1120 comp_unit_die
.highpc
= highpc
;
1123 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1124 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1126 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1127 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1128 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1129 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1130 sort_pst_symbols (pst
);
1132 /* If there is already a psymtab or symtab for a file of this
1133 name, remove it. (If there is a symtab, more drastic things
1134 also happen.) This happens in VxWorks. */
1135 free_named_symtabs (pst
->filename
);
1137 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1138 + cu_header
.initial_length_size
;
1140 do_cleanups (back_to
);
1143 /* Read in all interesting dies to the end of the compilation unit. */
1146 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1147 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1148 const struct comp_unit_head
*cu_header
)
1150 bfd
*abfd
= objfile
->obfd
;
1151 struct partial_die_info pdi
;
1153 /* This function is called after we've read in the comp_unit_die in
1154 order to read its children. We start the nesting level at 1 since
1155 we have pushed 1 level down in order to read the comp unit's children.
1156 The comp unit itself is at level 0, so we stop reading when we pop
1157 back to that level. */
1159 int nesting_level
= 1;
1161 *lowpc
= ((CORE_ADDR
) -1);
1162 *highpc
= ((CORE_ADDR
) 0);
1164 while (nesting_level
)
1166 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1172 case DW_TAG_subprogram
:
1173 if (pdi
.has_pc_info
)
1175 if (pdi
.lowpc
< *lowpc
)
1179 if (pdi
.highpc
> *highpc
)
1181 *highpc
= pdi
.highpc
;
1183 if ((pdi
.is_external
|| nesting_level
== 1)
1184 && !pdi
.is_declaration
)
1186 add_partial_symbol (&pdi
, objfile
, cu_header
);
1190 case DW_TAG_variable
:
1191 case DW_TAG_typedef
:
1192 case DW_TAG_class_type
:
1193 case DW_TAG_structure_type
:
1194 case DW_TAG_union_type
:
1195 case DW_TAG_enumeration_type
:
1196 if ((pdi
.is_external
|| nesting_level
== 1)
1197 && !pdi
.is_declaration
)
1199 add_partial_symbol (&pdi
, objfile
, cu_header
);
1202 case DW_TAG_enumerator
:
1203 /* File scope enumerators are added to the partial symbol
1205 if (nesting_level
== 2)
1206 add_partial_symbol (&pdi
, objfile
, cu_header
);
1208 case DW_TAG_base_type
:
1209 /* File scope base type definitions are added to the partial
1211 if (nesting_level
== 1)
1212 add_partial_symbol (&pdi
, objfile
, cu_header
);
1219 /* If the die has a sibling, skip to the sibling.
1220 Do not skip enumeration types, we want to record their
1222 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1224 info_ptr
= pdi
.sibling
;
1226 else if (pdi
.has_children
)
1228 /* Die has children, but the optional DW_AT_sibling attribute
1239 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1240 from `maint check'. */
1241 if (*lowpc
== ((CORE_ADDR
) -1))
1247 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1248 const struct comp_unit_head
*cu_header
)
1254 case DW_TAG_subprogram
:
1255 if (pdi
->is_external
)
1257 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1258 mst_text, objfile); */
1259 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1260 VAR_NAMESPACE
, LOC_BLOCK
,
1261 &objfile
->global_psymbols
,
1262 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1266 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1267 mst_file_text, objfile); */
1268 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1269 VAR_NAMESPACE
, LOC_BLOCK
,
1270 &objfile
->static_psymbols
,
1271 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1274 case DW_TAG_variable
:
1275 if (pdi
->is_external
)
1278 Don't enter into the minimal symbol tables as there is
1279 a minimal symbol table entry from the ELF symbols already.
1280 Enter into partial symbol table if it has a location
1281 descriptor or a type.
1282 If the location descriptor is missing, new_symbol will create
1283 a LOC_UNRESOLVED symbol, the address of the variable will then
1284 be determined from the minimal symbol table whenever the variable
1286 The address for the partial symbol table entry is not
1287 used by GDB, but it comes in handy for debugging partial symbol
1291 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1292 if (pdi
->locdesc
|| pdi
->has_type
)
1293 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1294 VAR_NAMESPACE
, LOC_STATIC
,
1295 &objfile
->global_psymbols
,
1296 0, addr
+ baseaddr
, cu_language
, objfile
);
1300 /* Static Variable. Skip symbols without location descriptors. */
1301 if (pdi
->locdesc
== NULL
)
1303 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1304 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1305 mst_file_data, objfile); */
1306 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1307 VAR_NAMESPACE
, LOC_STATIC
,
1308 &objfile
->static_psymbols
,
1309 0, addr
+ baseaddr
, cu_language
, objfile
);
1312 case DW_TAG_typedef
:
1313 case DW_TAG_base_type
:
1314 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1315 VAR_NAMESPACE
, LOC_TYPEDEF
,
1316 &objfile
->static_psymbols
,
1317 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1319 case DW_TAG_class_type
:
1320 case DW_TAG_structure_type
:
1321 case DW_TAG_union_type
:
1322 case DW_TAG_enumeration_type
:
1323 /* Skip aggregate types without children, these are external
1325 if (pdi
->has_children
== 0)
1327 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1328 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1329 &objfile
->static_psymbols
,
1330 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1332 if (cu_language
== language_cplus
)
1334 /* For C++, these implicitly act as typedefs as well. */
1335 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1336 VAR_NAMESPACE
, LOC_TYPEDEF
,
1337 &objfile
->static_psymbols
,
1338 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1341 case DW_TAG_enumerator
:
1342 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1343 VAR_NAMESPACE
, LOC_CONST
,
1344 &objfile
->static_psymbols
,
1345 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1352 /* Expand this partial symbol table into a full symbol table. */
1355 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1357 /* FIXME: This is barely more than a stub. */
1362 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1368 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1369 gdb_flush (gdb_stdout
);
1372 psymtab_to_symtab_1 (pst
);
1374 /* Finish up the debug error message. */
1376 printf_filtered ("done.\n");
1382 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1384 struct objfile
*objfile
= pst
->objfile
;
1385 bfd
*abfd
= objfile
->obfd
;
1386 struct comp_unit_head cu_header
;
1387 struct die_info
*dies
;
1388 unsigned long offset
;
1389 CORE_ADDR lowpc
, highpc
;
1390 struct die_info
*child_die
;
1392 struct symtab
*symtab
;
1393 struct cleanup
*back_to
;
1395 /* Set local variables from the partial symbol table info. */
1396 offset
= DWARF_INFO_OFFSET (pst
);
1397 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1398 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1399 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1400 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1401 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1402 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1403 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1404 cu_header_offset
= offset
;
1405 info_ptr
= dwarf_info_buffer
+ offset
;
1407 obstack_init (&dwarf2_tmp_obstack
);
1408 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1411 make_cleanup (really_free_pendings
, NULL
);
1413 /* read in the comp_unit header */
1414 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1416 /* Read the abbrevs for this compilation unit */
1417 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1418 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1420 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1422 make_cleanup_free_die_list (dies
);
1424 /* Do line number decoding in read_file_scope () */
1425 process_die (dies
, objfile
, &cu_header
);
1427 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1429 /* Some compilers don't define a DW_AT_high_pc attribute for
1430 the compilation unit. If the DW_AT_high_pc is missing,
1431 synthesize it, by scanning the DIE's below the compilation unit. */
1433 if (dies
->has_children
)
1435 child_die
= dies
->next
;
1436 while (child_die
&& child_die
->tag
)
1438 if (child_die
->tag
== DW_TAG_subprogram
)
1440 CORE_ADDR low
, high
;
1442 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1444 highpc
= max (highpc
, high
);
1447 child_die
= sibling_die (child_die
);
1451 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1453 /* Set symtab language to language from DW_AT_language.
1454 If the compilation is from a C file generated by language preprocessors,
1455 do not set the language if it was already deduced by start_subfile. */
1457 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1459 symtab
->language
= cu_language
;
1461 pst
->symtab
= symtab
;
1463 sort_symtab_syms (pst
->symtab
);
1465 do_cleanups (back_to
);
1468 /* Process a die and its children. */
1471 process_die (struct die_info
*die
, struct objfile
*objfile
,
1472 const struct comp_unit_head
*cu_header
)
1476 case DW_TAG_padding
:
1478 case DW_TAG_compile_unit
:
1479 read_file_scope (die
, objfile
, cu_header
);
1481 case DW_TAG_subprogram
:
1482 read_subroutine_type (die
, objfile
, cu_header
);
1483 read_func_scope (die
, objfile
, cu_header
);
1485 case DW_TAG_inlined_subroutine
:
1486 /* FIXME: These are ignored for now.
1487 They could be used to set breakpoints on all inlined instances
1488 of a function and make GDB `next' properly over inlined functions. */
1490 case DW_TAG_lexical_block
:
1491 read_lexical_block_scope (die
, objfile
, cu_header
);
1493 case DW_TAG_class_type
:
1494 case DW_TAG_structure_type
:
1495 case DW_TAG_union_type
:
1496 read_structure_scope (die
, objfile
, cu_header
);
1498 case DW_TAG_enumeration_type
:
1499 read_enumeration (die
, objfile
, cu_header
);
1501 case DW_TAG_subroutine_type
:
1502 read_subroutine_type (die
, objfile
, cu_header
);
1504 case DW_TAG_array_type
:
1505 read_array_type (die
, objfile
, cu_header
);
1507 case DW_TAG_pointer_type
:
1508 read_tag_pointer_type (die
, objfile
, cu_header
);
1510 case DW_TAG_ptr_to_member_type
:
1511 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1513 case DW_TAG_reference_type
:
1514 read_tag_reference_type (die
, objfile
, cu_header
);
1516 case DW_TAG_string_type
:
1517 read_tag_string_type (die
, objfile
);
1519 case DW_TAG_base_type
:
1520 read_base_type (die
, objfile
);
1521 if (dwarf_attr (die
, DW_AT_name
))
1523 /* Add a typedef symbol for the base type definition. */
1524 new_symbol (die
, die
->type
, objfile
, cu_header
);
1527 case DW_TAG_common_block
:
1528 read_common_block (die
, objfile
, cu_header
);
1530 case DW_TAG_common_inclusion
:
1533 new_symbol (die
, NULL
, objfile
, cu_header
);
1539 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1540 const struct comp_unit_head
*cu_header
)
1542 unsigned int line_offset
= 0;
1543 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1544 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1545 struct attribute
*attr
;
1546 char *name
= "<unknown>";
1547 char *comp_dir
= NULL
;
1548 struct die_info
*child_die
;
1549 bfd
*abfd
= objfile
->obfd
;
1551 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1553 if (die
->has_children
)
1555 child_die
= die
->next
;
1556 while (child_die
&& child_die
->tag
)
1558 if (child_die
->tag
== DW_TAG_subprogram
)
1560 CORE_ADDR low
, high
;
1562 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1564 lowpc
= min (lowpc
, low
);
1565 highpc
= max (highpc
, high
);
1568 child_die
= sibling_die (child_die
);
1573 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1574 from finish_block. */
1575 if (lowpc
== ((CORE_ADDR
) -1))
1580 attr
= dwarf_attr (die
, DW_AT_name
);
1583 name
= DW_STRING (attr
);
1585 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1588 comp_dir
= DW_STRING (attr
);
1591 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1592 directory, get rid of it. */
1593 char *cp
= strchr (comp_dir
, ':');
1595 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1600 if (objfile
->ei
.entry_point
>= lowpc
&&
1601 objfile
->ei
.entry_point
< highpc
)
1603 objfile
->ei
.entry_file_lowpc
= lowpc
;
1604 objfile
->ei
.entry_file_highpc
= highpc
;
1607 attr
= dwarf_attr (die
, DW_AT_language
);
1610 set_cu_language (DW_UNSND (attr
));
1613 /* We assume that we're processing GCC output. */
1614 processing_gcc_compilation
= 2;
1616 /* FIXME:Do something here. */
1617 if (dip
->at_producer
!= NULL
)
1619 handle_producer (dip
->at_producer
);
1623 /* The compilation unit may be in a different language or objfile,
1624 zero out all remembered fundamental types. */
1625 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1627 start_symtab (name
, comp_dir
, lowpc
);
1628 record_debugformat ("DWARF 2");
1630 /* Decode line number information if present. */
1631 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1634 line_offset
= DW_UNSND (attr
);
1635 dwarf_decode_lines (line_offset
, comp_dir
, abfd
, cu_header
);
1638 /* Process all dies in compilation unit. */
1639 if (die
->has_children
)
1641 child_die
= die
->next
;
1642 while (child_die
&& child_die
->tag
)
1644 process_die (child_die
, objfile
, cu_header
);
1645 child_die
= sibling_die (child_die
);
1651 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
1652 const struct comp_unit_head
*cu_header
)
1654 register struct context_stack
*new;
1657 struct die_info
*child_die
;
1658 struct attribute
*attr
;
1661 name
= dwarf2_linkage_name (die
);
1663 /* Ignore functions with missing or empty names and functions with
1664 missing or invalid low and high pc attributes. */
1665 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1671 if (objfile
->ei
.entry_point
>= lowpc
&&
1672 objfile
->ei
.entry_point
< highpc
)
1674 objfile
->ei
.entry_func_lowpc
= lowpc
;
1675 objfile
->ei
.entry_func_highpc
= highpc
;
1678 /* Decode DW_AT_frame_base location descriptor if present, keep result
1679 for DW_OP_fbreg operands in decode_locdesc. */
1680 frame_base_reg
= -1;
1681 frame_base_offset
= 0;
1682 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1685 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
1687 complain (&dwarf2_unsupported_at_frame_base
, name
);
1689 frame_base_reg
= addr
;
1692 frame_base_reg
= basereg
;
1693 frame_base_offset
= addr
;
1696 complain (&dwarf2_unsupported_at_frame_base
, name
);
1699 new = push_context (0, lowpc
);
1700 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
1701 list_in_scope
= &local_symbols
;
1703 if (die
->has_children
)
1705 child_die
= die
->next
;
1706 while (child_die
&& child_die
->tag
)
1708 process_die (child_die
, objfile
, cu_header
);
1709 child_die
= sibling_die (child_die
);
1713 new = pop_context ();
1714 /* Make a block for the local symbols within. */
1715 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1716 lowpc
, highpc
, objfile
);
1717 list_in_scope
= &file_symbols
;
1720 /* Process all the DIES contained within a lexical block scope. Start
1721 a new scope, process the dies, and then close the scope. */
1724 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
1725 const struct comp_unit_head
*cu_header
)
1727 register struct context_stack
*new;
1728 CORE_ADDR lowpc
, highpc
;
1729 struct die_info
*child_die
;
1731 /* Ignore blocks with missing or invalid low and high pc attributes. */
1732 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1737 push_context (0, lowpc
);
1738 if (die
->has_children
)
1740 child_die
= die
->next
;
1741 while (child_die
&& child_die
->tag
)
1743 process_die (child_die
, objfile
, cu_header
);
1744 child_die
= sibling_die (child_die
);
1747 new = pop_context ();
1749 if (local_symbols
!= NULL
)
1751 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1754 local_symbols
= new->locals
;
1757 /* Get low and high pc attributes from a die.
1758 Return 1 if the attributes are present and valid, otherwise, return 0. */
1761 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1762 struct objfile
*objfile
)
1764 struct attribute
*attr
;
1768 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1770 low
= DW_ADDR (attr
);
1773 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1775 high
= DW_ADDR (attr
);
1782 /* When using the GNU linker, .gnu.linkonce. sections are used to
1783 eliminate duplicate copies of functions and vtables and such.
1784 The linker will arbitrarily choose one and discard the others.
1785 The AT_*_pc values for such functions refer to local labels in
1786 these sections. If the section from that file was discarded, the
1787 labels are not in the output, so the relocs get a value of 0.
1788 If this is a discarded function, mark the pc bounds as invalid,
1789 so that GDB will ignore it. */
1790 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1798 /* Add an aggregate field to the field list. */
1801 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
1802 struct objfile
*objfile
,
1803 const struct comp_unit_head
*cu_header
)
1805 struct nextfield
*new_field
;
1806 struct attribute
*attr
;
1808 char *fieldname
= "";
1810 /* Allocate a new field list entry and link it in. */
1811 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1812 make_cleanup (xfree
, new_field
);
1813 memset (new_field
, 0, sizeof (struct nextfield
));
1814 new_field
->next
= fip
->fields
;
1815 fip
->fields
= new_field
;
1818 /* Handle accessibility and virtuality of field.
1819 The default accessibility for members is public, the default
1820 accessibility for inheritance is private. */
1821 if (die
->tag
!= DW_TAG_inheritance
)
1822 new_field
->accessibility
= DW_ACCESS_public
;
1824 new_field
->accessibility
= DW_ACCESS_private
;
1825 new_field
->virtuality
= DW_VIRTUALITY_none
;
1827 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1829 new_field
->accessibility
= DW_UNSND (attr
);
1830 if (new_field
->accessibility
!= DW_ACCESS_public
)
1831 fip
->non_public_fields
= 1;
1832 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1834 new_field
->virtuality
= DW_UNSND (attr
);
1836 fp
= &new_field
->field
;
1837 if (die
->tag
== DW_TAG_member
)
1839 /* Get type of field. */
1840 fp
->type
= die_type (die
, objfile
, cu_header
);
1842 /* Get bit size of field (zero if none). */
1843 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1846 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1850 FIELD_BITSIZE (*fp
) = 0;
1853 /* Get bit offset of field. */
1854 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1857 FIELD_BITPOS (*fp
) =
1858 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
1861 FIELD_BITPOS (*fp
) = 0;
1862 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1865 if (BITS_BIG_ENDIAN
)
1867 /* For big endian bits, the DW_AT_bit_offset gives the
1868 additional bit offset from the MSB of the containing
1869 anonymous object to the MSB of the field. We don't
1870 have to do anything special since we don't need to
1871 know the size of the anonymous object. */
1872 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1876 /* For little endian bits, compute the bit offset to the
1877 MSB of the anonymous object, subtract off the number of
1878 bits from the MSB of the field to the MSB of the
1879 object, and then subtract off the number of bits of
1880 the field itself. The result is the bit offset of
1881 the LSB of the field. */
1883 int bit_offset
= DW_UNSND (attr
);
1885 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1888 /* The size of the anonymous object containing
1889 the bit field is explicit, so use the
1890 indicated size (in bytes). */
1891 anonymous_size
= DW_UNSND (attr
);
1895 /* The size of the anonymous object containing
1896 the bit field must be inferred from the type
1897 attribute of the data member containing the
1899 anonymous_size
= TYPE_LENGTH (fp
->type
);
1901 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1902 - bit_offset
- FIELD_BITSIZE (*fp
);
1906 /* Get name of field. */
1907 attr
= dwarf_attr (die
, DW_AT_name
);
1908 if (attr
&& DW_STRING (attr
))
1909 fieldname
= DW_STRING (attr
);
1910 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1911 &objfile
->type_obstack
);
1913 /* Change accessibility for artificial fields (e.g. virtual table
1914 pointer or virtual base class pointer) to private. */
1915 if (dwarf_attr (die
, DW_AT_artificial
))
1917 new_field
->accessibility
= DW_ACCESS_private
;
1918 fip
->non_public_fields
= 1;
1921 else if (die
->tag
== DW_TAG_variable
)
1925 /* C++ static member.
1926 Get name of field. */
1927 attr
= dwarf_attr (die
, DW_AT_name
);
1928 if (attr
&& DW_STRING (attr
))
1929 fieldname
= DW_STRING (attr
);
1933 /* Get physical name. */
1934 physname
= dwarf2_linkage_name (die
);
1936 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1937 &objfile
->type_obstack
));
1938 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1939 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1940 &objfile
->type_obstack
);
1942 else if (die
->tag
== DW_TAG_inheritance
)
1944 /* C++ base class field. */
1945 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1947 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
1949 FIELD_BITSIZE (*fp
) = 0;
1950 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1951 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1952 fip
->nbaseclasses
++;
1956 /* Create the vector of fields, and attach it to the type. */
1959 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
1960 struct objfile
*objfile
)
1962 int nfields
= fip
->nfields
;
1964 /* Record the field count, allocate space for the array of fields,
1965 and create blank accessibility bitfields if necessary. */
1966 TYPE_NFIELDS (type
) = nfields
;
1967 TYPE_FIELDS (type
) = (struct field
*)
1968 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1969 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1971 if (fip
->non_public_fields
)
1973 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1975 TYPE_FIELD_PRIVATE_BITS (type
) =
1976 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1977 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1979 TYPE_FIELD_PROTECTED_BITS (type
) =
1980 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1981 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1983 TYPE_FIELD_IGNORE_BITS (type
) =
1984 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1985 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1988 /* If the type has baseclasses, allocate and clear a bit vector for
1989 TYPE_FIELD_VIRTUAL_BITS. */
1990 if (fip
->nbaseclasses
)
1992 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
1995 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1996 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1997 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1998 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
1999 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2002 /* Copy the saved-up fields into the field vector. Start from the head
2003 of the list, adding to the tail of the field array, so that they end
2004 up in the same order in the array in which they were added to the list. */
2005 while (nfields
-- > 0)
2007 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2008 switch (fip
->fields
->accessibility
)
2010 case DW_ACCESS_private
:
2011 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2014 case DW_ACCESS_protected
:
2015 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2018 case DW_ACCESS_public
:
2022 /* Unknown accessibility. Complain and treat it as public. */
2024 complain (&dwarf2_unsupported_accessibility
,
2025 fip
->fields
->accessibility
);
2029 if (nfields
< fip
->nbaseclasses
)
2031 switch (fip
->fields
->virtuality
)
2033 case DW_VIRTUALITY_virtual
:
2034 case DW_VIRTUALITY_pure_virtual
:
2035 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2039 fip
->fields
= fip
->fields
->next
;
2043 /* Add a member function to the proper fieldlist. */
2046 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2047 struct type
*type
, struct objfile
*objfile
,
2048 const struct comp_unit_head
*cu_header
)
2050 struct attribute
*attr
;
2051 struct fnfieldlist
*flp
;
2053 struct fn_field
*fnp
;
2056 struct nextfnfield
*new_fnfield
;
2058 /* Get name of member function. */
2059 attr
= dwarf_attr (die
, DW_AT_name
);
2060 if (attr
&& DW_STRING (attr
))
2061 fieldname
= DW_STRING (attr
);
2065 /* Get the mangled name. */
2066 physname
= dwarf2_linkage_name (die
);
2068 /* Look up member function name in fieldlist. */
2069 for (i
= 0; i
< fip
->nfnfields
; i
++)
2071 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2075 /* Create new list element if necessary. */
2076 if (i
< fip
->nfnfields
)
2077 flp
= &fip
->fnfieldlists
[i
];
2080 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2082 fip
->fnfieldlists
= (struct fnfieldlist
*)
2083 xrealloc (fip
->fnfieldlists
,
2084 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2085 * sizeof (struct fnfieldlist
));
2086 if (fip
->nfnfields
== 0)
2087 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2089 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2090 flp
->name
= fieldname
;
2096 /* Create a new member function field and chain it to the field list
2098 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2099 make_cleanup (xfree
, new_fnfield
);
2100 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2101 new_fnfield
->next
= flp
->head
;
2102 flp
->head
= new_fnfield
;
2105 /* Fill in the member function field info. */
2106 fnp
= &new_fnfield
->fnfield
;
2107 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2108 &objfile
->type_obstack
);
2109 fnp
->type
= alloc_type (objfile
);
2110 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2112 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2113 struct type
**arg_types
;
2114 int nparams
= TYPE_NFIELDS (die
->type
);
2117 /* Copy argument types from the subroutine type. */
2118 arg_types
= (struct type
**)
2119 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2120 for (iparams
= 0; iparams
< nparams
; iparams
++)
2121 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2123 /* Set last entry in argument type vector. */
2124 if (TYPE_FLAGS (die
->type
) & TYPE_FLAG_VARARGS
)
2125 arg_types
[nparams
] = NULL
;
2127 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2129 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2131 /* Handle static member functions.
2132 Dwarf2 has no clean way to discern C++ static and non-static
2133 member functions. G++ helps GDB by marking the first
2134 parameter for non-static member functions (which is the
2135 this pointer) as artificial. We obtain this information
2136 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2137 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2138 fnp
->voffset
= VOFFSET_STATIC
;
2141 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2143 /* Get fcontext from DW_AT_containing_type if present. */
2144 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2145 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2147 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2148 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2150 /* Get accessibility. */
2151 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2154 switch (DW_UNSND (attr
))
2156 case DW_ACCESS_private
:
2157 fnp
->is_private
= 1;
2159 case DW_ACCESS_protected
:
2160 fnp
->is_protected
= 1;
2165 /* Get index in virtual function table if it is a virtual member function. */
2166 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2168 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2171 /* Create the vector of member function fields, and attach it to the type. */
2174 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2175 struct objfile
*objfile
)
2177 struct fnfieldlist
*flp
;
2178 int total_length
= 0;
2181 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2182 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2183 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2185 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2187 struct nextfnfield
*nfp
= flp
->head
;
2188 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2191 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2192 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2193 fn_flp
->fn_fields
= (struct fn_field
*)
2194 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2195 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2196 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2198 total_length
+= flp
->length
;
2201 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2202 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2205 /* Called when we find the DIE that starts a structure or union scope
2206 (definition) to process all dies that define the members of the
2209 NOTE: we need to call struct_type regardless of whether or not the
2210 DIE has an at_name attribute, since it might be an anonymous
2211 structure or union. This gets the type entered into our set of
2214 However, if the structure is incomplete (an opaque struct/union)
2215 then suppress creating a symbol table entry for it since gdb only
2216 wants to find the one with the complete definition. Note that if
2217 it is complete, we just call new_symbol, which does it's own
2218 checking about whether the struct/union is anonymous or not (and
2219 suppresses creating a symbol table entry itself). */
2222 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2223 const struct comp_unit_head
*cu_header
)
2226 struct attribute
*attr
;
2228 type
= alloc_type (objfile
);
2230 INIT_CPLUS_SPECIFIC (type
);
2231 attr
= dwarf_attr (die
, DW_AT_name
);
2232 if (attr
&& DW_STRING (attr
))
2234 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2235 strlen (DW_STRING (attr
)),
2236 &objfile
->type_obstack
);
2239 if (die
->tag
== DW_TAG_structure_type
)
2241 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2243 else if (die
->tag
== DW_TAG_union_type
)
2245 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2249 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2251 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2254 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2257 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2261 TYPE_LENGTH (type
) = 0;
2264 /* We need to add the type field to the die immediately so we don't
2265 infinitely recurse when dealing with pointers to the structure
2266 type within the structure itself. */
2269 if (die
->has_children
&& ! die_is_declaration (die
))
2271 struct field_info fi
;
2272 struct die_info
*child_die
;
2273 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2275 memset (&fi
, 0, sizeof (struct field_info
));
2277 child_die
= die
->next
;
2279 while (child_die
&& child_die
->tag
)
2281 if (child_die
->tag
== DW_TAG_member
)
2283 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2285 else if (child_die
->tag
== DW_TAG_variable
)
2287 /* C++ static member. */
2288 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2290 else if (child_die
->tag
== DW_TAG_subprogram
)
2292 /* C++ member function. */
2293 process_die (child_die
, objfile
, cu_header
);
2294 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2296 else if (child_die
->tag
== DW_TAG_inheritance
)
2298 /* C++ base class field. */
2299 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2303 process_die (child_die
, objfile
, cu_header
);
2305 child_die
= sibling_die (child_die
);
2308 /* Attach fields and member functions to the type. */
2310 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2313 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2315 /* Get the type which refers to the base class (possibly this
2316 class itself) which contains the vtable pointer for the current
2317 class from the DW_AT_containing_type attribute. */
2319 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2321 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2323 TYPE_VPTR_BASETYPE (type
) = t
;
2326 static const char vptr_name
[] =
2327 {'_', 'v', 'p', 't', 'r', '\0'};
2330 /* Our own class provides vtbl ptr. */
2331 for (i
= TYPE_NFIELDS (t
) - 1;
2332 i
>= TYPE_N_BASECLASSES (t
);
2335 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2337 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2338 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2340 TYPE_VPTR_FIELDNO (type
) = i
;
2345 /* Complain if virtual function table field not found. */
2346 if (i
< TYPE_N_BASECLASSES (t
))
2347 complain (&dwarf2_vtbl_not_found_complaint
,
2348 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2352 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2357 new_symbol (die
, type
, objfile
, cu_header
);
2359 do_cleanups (back_to
);
2363 /* No children, must be stub. */
2364 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2370 /* Given a pointer to a die which begins an enumeration, process all
2371 the dies that define the members of the enumeration.
2373 This will be much nicer in draft 6 of the DWARF spec when our
2374 members will be dies instead squished into the DW_AT_element_list
2377 NOTE: We reverse the order of the element list. */
2380 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2381 const struct comp_unit_head
*cu_header
)
2383 struct die_info
*child_die
;
2385 struct field
*fields
;
2386 struct attribute
*attr
;
2389 int unsigned_enum
= 1;
2391 type
= alloc_type (objfile
);
2393 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2394 attr
= dwarf_attr (die
, DW_AT_name
);
2395 if (attr
&& DW_STRING (attr
))
2397 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2398 strlen (DW_STRING (attr
)),
2399 &objfile
->type_obstack
);
2402 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2405 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2409 TYPE_LENGTH (type
) = 0;
2414 if (die
->has_children
)
2416 child_die
= die
->next
;
2417 while (child_die
&& child_die
->tag
)
2419 if (child_die
->tag
!= DW_TAG_enumerator
)
2421 process_die (child_die
, objfile
, cu_header
);
2425 attr
= dwarf_attr (child_die
, DW_AT_name
);
2428 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2429 if (SYMBOL_VALUE (sym
) < 0)
2432 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2434 fields
= (struct field
*)
2436 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2437 * sizeof (struct field
));
2440 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2441 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2442 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2443 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2449 child_die
= sibling_die (child_die
);
2454 TYPE_NFIELDS (type
) = num_fields
;
2455 TYPE_FIELDS (type
) = (struct field
*)
2456 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2457 memcpy (TYPE_FIELDS (type
), fields
,
2458 sizeof (struct field
) * num_fields
);
2462 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2465 new_symbol (die
, type
, objfile
, cu_header
);
2468 /* Extract all information from a DW_TAG_array_type DIE and put it in
2469 the DIE's type field. For now, this only handles one dimensional
2473 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
2474 const struct comp_unit_head
*cu_header
)
2476 struct die_info
*child_die
;
2477 struct type
*type
= NULL
;
2478 struct type
*element_type
, *range_type
, *index_type
;
2479 struct type
**range_types
= NULL
;
2480 struct attribute
*attr
;
2482 struct cleanup
*back_to
;
2484 /* Return if we've already decoded this type. */
2490 element_type
= die_type (die
, objfile
, cu_header
);
2492 /* Irix 6.2 native cc creates array types without children for
2493 arrays with unspecified length. */
2494 if (die
->has_children
== 0)
2496 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2497 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2498 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2502 back_to
= make_cleanup (null_cleanup
, NULL
);
2503 child_die
= die
->next
;
2504 while (child_die
&& child_die
->tag
)
2506 if (child_die
->tag
== DW_TAG_subrange_type
)
2508 unsigned int low
, high
;
2510 /* Default bounds to an array with unspecified length. */
2513 if (cu_language
== language_fortran
)
2515 /* FORTRAN implies a lower bound of 1, if not given. */
2519 index_type
= die_type (child_die
, objfile
, cu_header
);
2520 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2523 if (attr
->form
== DW_FORM_sdata
)
2525 low
= DW_SND (attr
);
2527 else if (attr
->form
== DW_FORM_udata
2528 || attr
->form
== DW_FORM_data1
2529 || attr
->form
== DW_FORM_data2
2530 || attr
->form
== DW_FORM_data4
)
2532 low
= DW_UNSND (attr
);
2536 complain (&dwarf2_non_const_array_bound_ignored
,
2537 dwarf_form_name (attr
->form
));
2539 die
->type
= lookup_pointer_type (element_type
);
2546 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2549 if (attr
->form
== DW_FORM_sdata
)
2551 high
= DW_SND (attr
);
2553 else if (attr
->form
== DW_FORM_udata
2554 || attr
->form
== DW_FORM_data1
2555 || attr
->form
== DW_FORM_data2
2556 || attr
->form
== DW_FORM_data4
)
2558 high
= DW_UNSND (attr
);
2560 else if (attr
->form
== DW_FORM_block1
)
2562 /* GCC encodes arrays with unspecified or dynamic length
2563 with a DW_FORM_block1 attribute.
2564 FIXME: GDB does not yet know how to handle dynamic
2565 arrays properly, treat them as arrays with unspecified
2571 complain (&dwarf2_non_const_array_bound_ignored
,
2572 dwarf_form_name (attr
->form
));
2574 die
->type
= lookup_pointer_type (element_type
);
2582 /* Create a range type and save it for array type creation. */
2583 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2585 range_types
= (struct type
**)
2586 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2587 * sizeof (struct type
*));
2589 make_cleanup (free_current_contents
, &range_types
);
2591 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2593 child_die
= sibling_die (child_die
);
2596 /* Dwarf2 dimensions are output from left to right, create the
2597 necessary array types in backwards order. */
2598 type
= element_type
;
2600 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2602 do_cleanups (back_to
);
2604 /* Install the type in the die. */
2608 /* First cut: install each common block member as a global variable. */
2611 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
2612 const struct comp_unit_head
*cu_header
)
2614 struct die_info
*child_die
;
2615 struct attribute
*attr
;
2617 CORE_ADDR base
= (CORE_ADDR
) 0;
2619 attr
= dwarf_attr (die
, DW_AT_location
);
2622 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2624 if (die
->has_children
)
2626 child_die
= die
->next
;
2627 while (child_die
&& child_die
->tag
)
2629 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
2630 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2633 SYMBOL_VALUE_ADDRESS (sym
) =
2634 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2635 add_symbol_to_list (sym
, &global_symbols
);
2637 child_die
= sibling_die (child_die
);
2642 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2643 the user defined type vector. */
2646 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
2647 const struct comp_unit_head
*cu_header
)
2650 struct attribute
*attr
;
2657 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
2658 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2661 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2665 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2670 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2671 the user defined type vector. */
2674 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
2675 const struct comp_unit_head
*cu_header
)
2678 struct type
*to_type
;
2679 struct type
*domain
;
2686 type
= alloc_type (objfile
);
2687 to_type
= die_type (die
, objfile
, cu_header
);
2688 domain
= die_containing_type (die
, objfile
, cu_header
);
2689 smash_to_member_type (type
, domain
, to_type
);
2694 /* Extract all information from a DW_TAG_reference_type DIE and add to
2695 the user defined type vector. */
2698 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
2699 const struct comp_unit_head
*cu_header
)
2702 struct attribute
*attr
;
2709 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
2710 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2713 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2717 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2723 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
2724 const struct comp_unit_head
*cu_header
)
2726 struct type
*base_type
;
2733 base_type
= die_type (die
, objfile
, cu_header
);
2734 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
2738 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
2739 const struct comp_unit_head
*cu_header
)
2741 struct type
*base_type
;
2748 base_type
= die_type (die
, objfile
, cu_header
);
2749 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
2752 /* Extract all information from a DW_TAG_string_type DIE and add to
2753 the user defined type vector. It isn't really a user defined type,
2754 but it behaves like one, with other DIE's using an AT_user_def_type
2755 attribute to reference it. */
2758 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
2760 struct type
*type
, *range_type
, *index_type
, *char_type
;
2761 struct attribute
*attr
;
2762 unsigned int length
;
2769 attr
= dwarf_attr (die
, DW_AT_string_length
);
2772 length
= DW_UNSND (attr
);
2778 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2779 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2780 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2781 type
= create_string_type (char_type
, range_type
);
2785 /* Handle DIES due to C code like:
2789 int (*funcp)(int a, long l);
2793 ('funcp' generates a DW_TAG_subroutine_type DIE)
2797 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
2798 const struct comp_unit_head
*cu_header
)
2800 struct type
*type
; /* Type that this function returns */
2801 struct type
*ftype
; /* Function that returns above type */
2802 struct attribute
*attr
;
2804 /* Decode the type that this subroutine returns */
2809 type
= die_type (die
, objfile
, cu_header
);
2810 ftype
= lookup_function_type (type
);
2812 /* All functions in C++ have prototypes. */
2813 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2814 if ((attr
&& (DW_UNSND (attr
) != 0))
2815 || cu_language
== language_cplus
)
2816 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2818 if (die
->has_children
)
2820 struct die_info
*child_die
;
2824 /* Count the number of parameters.
2825 FIXME: GDB currently ignores vararg functions, but knows about
2826 vararg member functions. */
2827 child_die
= die
->next
;
2828 while (child_die
&& child_die
->tag
)
2830 if (child_die
->tag
== DW_TAG_formal_parameter
)
2832 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2833 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2834 child_die
= sibling_die (child_die
);
2837 /* Allocate storage for parameters and fill them in. */
2838 TYPE_NFIELDS (ftype
) = nparams
;
2839 TYPE_FIELDS (ftype
) = (struct field
*)
2840 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2842 child_die
= die
->next
;
2843 while (child_die
&& child_die
->tag
)
2845 if (child_die
->tag
== DW_TAG_formal_parameter
)
2847 /* Dwarf2 has no clean way to discern C++ static and non-static
2848 member functions. G++ helps GDB by marking the first
2849 parameter for non-static member functions (which is the
2850 this pointer) as artificial. We pass this information
2851 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2852 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2854 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2856 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2857 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
2861 child_die
= sibling_die (child_die
);
2869 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
2870 const struct comp_unit_head
*cu_header
)
2876 struct attribute
*attr
;
2879 xtype
= die_type (die
, objfile
, cu_header
);
2881 type
= alloc_type (objfile
);
2882 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2883 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2884 TYPE_TARGET_TYPE (type
) = xtype
;
2885 attr
= dwarf_attr (die
, DW_AT_name
);
2886 if (attr
&& DW_STRING (attr
))
2887 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2888 strlen (DW_STRING (attr
)),
2889 &objfile
->type_obstack
);
2895 /* Find a representation of a given base type and install
2896 it in the TYPE field of the die. */
2899 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
2902 struct attribute
*attr
;
2903 int encoding
= 0, size
= 0;
2905 /* If we've already decoded this die, this is a no-op. */
2911 attr
= dwarf_attr (die
, DW_AT_encoding
);
2914 encoding
= DW_UNSND (attr
);
2916 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2919 size
= DW_UNSND (attr
);
2921 attr
= dwarf_attr (die
, DW_AT_name
);
2922 if (attr
&& DW_STRING (attr
))
2924 enum type_code code
= TYPE_CODE_INT
;
2925 int is_unsigned
= 0;
2929 case DW_ATE_address
:
2930 /* Turn DW_ATE_address into a void * pointer. */
2931 code
= TYPE_CODE_PTR
;
2934 case DW_ATE_boolean
:
2935 code
= TYPE_CODE_BOOL
;
2938 case DW_ATE_complex_float
:
2939 code
= TYPE_CODE_COMPLEX
;
2942 code
= TYPE_CODE_FLT
;
2945 case DW_ATE_signed_char
:
2947 case DW_ATE_unsigned
:
2948 case DW_ATE_unsigned_char
:
2952 complain (&dwarf2_unsupported_at_encoding
,
2953 dwarf_type_encoding_name (encoding
));
2956 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2957 if (encoding
== DW_ATE_address
)
2958 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2962 type
= dwarf_base_type (encoding
, size
, objfile
);
2967 /* Read a whole compilation unit into a linked list of dies. */
2969 static struct die_info
*
2970 read_comp_unit (char *info_ptr
, bfd
*abfd
,
2971 const struct comp_unit_head
*cu_header
)
2973 struct die_info
*first_die
, *last_die
, *die
;
2977 /* Reset die reference table; we are
2978 building new ones now. */
2979 dwarf2_empty_hash_tables ();
2983 first_die
= last_die
= NULL
;
2986 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
2987 if (die
->has_children
)
2998 /* Enter die in reference hash table */
2999 store_in_ref_table (die
->offset
, die
);
3003 first_die
= last_die
= die
;
3007 last_die
->next
= die
;
3011 while (nesting_level
> 0);
3015 /* Free a linked list of dies. */
3018 free_die_list (struct die_info
*dies
)
3020 struct die_info
*die
, *next
;
3033 do_free_die_list_cleanup (void *dies
)
3035 free_die_list (dies
);
3038 static struct cleanup
*
3039 make_cleanup_free_die_list (struct die_info
*dies
)
3041 return make_cleanup (do_free_die_list_cleanup
, dies
);
3045 /* Read the contents of the section at OFFSET and of size SIZE from the
3046 object file specified by OBJFILE into the psymbol_obstack and return it. */
3049 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
3052 bfd
*abfd
= objfile
->obfd
;
3058 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3059 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3060 (bfd_bread (buf
, size
, abfd
) != size
))
3063 error ("Dwarf Error: Can't read DWARF data from '%s'",
3064 bfd_get_filename (abfd
));
3069 /* In DWARF version 2, the description of the debugging information is
3070 stored in a separate .debug_abbrev section. Before we read any
3071 dies from a section we read in all abbreviations and install them
3075 dwarf2_read_abbrevs (bfd
*abfd
, unsigned int offset
)
3078 struct abbrev_info
*cur_abbrev
;
3079 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3080 unsigned int abbrev_form
, hash_number
;
3082 /* empty the table */
3083 dwarf2_empty_abbrev_table (NULL
);
3085 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3086 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3087 abbrev_ptr
+= bytes_read
;
3089 /* loop until we reach an abbrev number of 0 */
3090 while (abbrev_number
)
3092 cur_abbrev
= dwarf_alloc_abbrev ();
3094 /* read in abbrev header */
3095 cur_abbrev
->number
= abbrev_number
;
3096 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3097 abbrev_ptr
+= bytes_read
;
3098 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3101 /* now read in declarations */
3102 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3103 abbrev_ptr
+= bytes_read
;
3104 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3105 abbrev_ptr
+= bytes_read
;
3108 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3110 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3111 xrealloc (cur_abbrev
->attrs
,
3112 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3113 * sizeof (struct attr_abbrev
));
3115 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3116 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3117 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3118 abbrev_ptr
+= bytes_read
;
3119 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3120 abbrev_ptr
+= bytes_read
;
3123 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3124 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3125 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3127 /* Get next abbreviation.
3128 Under Irix6 the abbreviations for a compilation unit are not
3129 always properly terminated with an abbrev number of 0.
3130 Exit loop if we encounter an abbreviation which we have
3131 already read (which means we are about to read the abbreviations
3132 for the next compile unit) or if the end of the abbreviation
3133 table is reached. */
3134 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3135 >= dwarf_abbrev_size
)
3137 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3138 abbrev_ptr
+= bytes_read
;
3139 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3144 /* Empty the abbrev table for a new compilation unit. */
3148 dwarf2_empty_abbrev_table (PTR ignore
)
3151 struct abbrev_info
*abbrev
, *next
;
3153 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3156 abbrev
= dwarf2_abbrevs
[i
];
3159 next
= abbrev
->next
;
3160 xfree (abbrev
->attrs
);
3164 dwarf2_abbrevs
[i
] = NULL
;
3168 /* Lookup an abbrev_info structure in the abbrev hash table. */
3170 static struct abbrev_info
*
3171 dwarf2_lookup_abbrev (unsigned int number
)
3173 unsigned int hash_number
;
3174 struct abbrev_info
*abbrev
;
3176 hash_number
= number
% ABBREV_HASH_SIZE
;
3177 abbrev
= dwarf2_abbrevs
[hash_number
];
3181 if (abbrev
->number
== number
)
3184 abbrev
= abbrev
->next
;
3189 /* Read a minimal amount of information into the minimal die structure. */
3192 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3193 char *info_ptr
, const struct comp_unit_head
*cu_header
)
3195 unsigned int abbrev_number
, bytes_read
, i
;
3196 struct abbrev_info
*abbrev
;
3197 struct attribute attr
;
3198 struct attribute spec_attr
;
3199 int found_spec_attr
= 0;
3200 int has_low_pc_attr
= 0;
3201 int has_high_pc_attr
= 0;
3203 *part_die
= zeroed_partial_die
;
3204 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3205 info_ptr
+= bytes_read
;
3209 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3212 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3214 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3215 part_die
->tag
= abbrev
->tag
;
3216 part_die
->has_children
= abbrev
->has_children
;
3217 part_die
->abbrev
= abbrev_number
;
3219 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3221 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3222 info_ptr
, cu_header
);
3224 /* Store the data if it is of an attribute we want to keep in a
3225 partial symbol table. */
3230 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3231 if (part_die
->name
== NULL
)
3232 part_die
->name
= DW_STRING (&attr
);
3234 case DW_AT_MIPS_linkage_name
:
3235 part_die
->name
= DW_STRING (&attr
);
3238 has_low_pc_attr
= 1;
3239 part_die
->lowpc
= DW_ADDR (&attr
);
3242 has_high_pc_attr
= 1;
3243 part_die
->highpc
= DW_ADDR (&attr
);
3245 case DW_AT_location
:
3246 part_die
->locdesc
= DW_BLOCK (&attr
);
3248 case DW_AT_language
:
3249 part_die
->language
= DW_UNSND (&attr
);
3251 case DW_AT_external
:
3252 part_die
->is_external
= DW_UNSND (&attr
);
3254 case DW_AT_declaration
:
3255 part_die
->is_declaration
= DW_UNSND (&attr
);
3258 part_die
->has_type
= 1;
3260 case DW_AT_abstract_origin
:
3261 case DW_AT_specification
:
3262 found_spec_attr
= 1;
3266 /* Ignore absolute siblings, they might point outside of
3267 the current compile unit. */
3268 if (attr
.form
== DW_FORM_ref_addr
)
3269 complain (&dwarf2_absolute_sibling_complaint
);
3272 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3279 /* If we found a reference attribute and the die has no name, try
3280 to find a name in the referred to die. */
3282 if (found_spec_attr
&& part_die
->name
== NULL
)
3284 struct partial_die_info spec_die
;
3288 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3289 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu_header
);
3292 part_die
->name
= spec_die
.name
;
3294 /* Copy DW_AT_external attribute if it is set. */
3295 if (spec_die
.is_external
)
3296 part_die
->is_external
= spec_die
.is_external
;
3300 /* When using the GNU linker, .gnu.linkonce. sections are used to
3301 eliminate duplicate copies of functions and vtables and such.
3302 The linker will arbitrarily choose one and discard the others.
3303 The AT_*_pc values for such functions refer to local labels in
3304 these sections. If the section from that file was discarded, the
3305 labels are not in the output, so the relocs get a value of 0.
3306 If this is a discarded function, mark the pc bounds as invalid,
3307 so that GDB will ignore it. */
3308 if (has_low_pc_attr
&& has_high_pc_attr
3309 && part_die
->lowpc
< part_die
->highpc
3310 && (part_die
->lowpc
!= 0
3311 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3312 part_die
->has_pc_info
= 1;
3316 /* Read the die from the .debug_info section buffer. And set diep to
3317 point to a newly allocated die with its information. */
3320 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3321 const struct comp_unit_head
*cu_header
)
3323 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3324 struct abbrev_info
*abbrev
;
3325 struct die_info
*die
;
3327 offset
= info_ptr
- dwarf_info_buffer
;
3328 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3329 info_ptr
+= bytes_read
;
3332 die
= dwarf_alloc_die ();
3334 die
->abbrev
= abbrev_number
;
3340 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3343 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3345 die
= dwarf_alloc_die ();
3346 die
->offset
= offset
;
3347 die
->tag
= abbrev
->tag
;
3348 die
->has_children
= abbrev
->has_children
;
3349 die
->abbrev
= abbrev_number
;
3352 die
->num_attrs
= abbrev
->num_attrs
;
3353 die
->attrs
= (struct attribute
*)
3354 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3356 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3358 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3359 abfd
, info_ptr
, cu_header
);
3366 /* Read an attribute value described by an attribute form. */
3369 read_attribute_value (struct attribute
*attr
, unsigned form
,
3370 bfd
*abfd
, char *info_ptr
,
3371 const struct comp_unit_head
*cu_header
)
3373 unsigned int bytes_read
;
3374 struct dwarf_block
*blk
;
3380 case DW_FORM_ref_addr
:
3381 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3382 info_ptr
+= bytes_read
;
3384 case DW_FORM_block2
:
3385 blk
= dwarf_alloc_block ();
3386 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3388 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3389 info_ptr
+= blk
->size
;
3390 DW_BLOCK (attr
) = blk
;
3392 case DW_FORM_block4
:
3393 blk
= dwarf_alloc_block ();
3394 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3396 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3397 info_ptr
+= blk
->size
;
3398 DW_BLOCK (attr
) = blk
;
3401 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3405 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3409 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3412 case DW_FORM_string
:
3413 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3414 info_ptr
+= bytes_read
;
3417 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
3419 info_ptr
+= bytes_read
;
3422 blk
= dwarf_alloc_block ();
3423 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3424 info_ptr
+= bytes_read
;
3425 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3426 info_ptr
+= blk
->size
;
3427 DW_BLOCK (attr
) = blk
;
3429 case DW_FORM_block1
:
3430 blk
= dwarf_alloc_block ();
3431 blk
->size
= read_1_byte (abfd
, info_ptr
);
3433 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3434 info_ptr
+= blk
->size
;
3435 DW_BLOCK (attr
) = blk
;
3438 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3442 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3446 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3447 info_ptr
+= bytes_read
;
3450 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3451 info_ptr
+= bytes_read
;
3454 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3458 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3462 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3466 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3469 case DW_FORM_ref_udata
:
3470 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3471 info_ptr
+= bytes_read
;
3473 case DW_FORM_indirect
:
3474 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3475 info_ptr
+= bytes_read
;
3476 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu_header
);
3479 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3480 dwarf_form_name (form
));
3485 /* Read an attribute described by an abbreviated attribute. */
3488 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
3489 bfd
*abfd
, char *info_ptr
,
3490 const struct comp_unit_head
*cu_header
)
3492 attr
->name
= abbrev
->name
;
3493 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu_header
);
3496 /* read dwarf information from a buffer */
3499 read_1_byte (bfd
*abfd
, char *buf
)
3501 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3505 read_1_signed_byte (bfd
*abfd
, char *buf
)
3507 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3511 read_2_bytes (bfd
*abfd
, char *buf
)
3513 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3517 read_2_signed_bytes (bfd
*abfd
, char *buf
)
3519 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3523 read_4_bytes (bfd
*abfd
, char *buf
)
3525 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3529 read_4_signed_bytes (bfd
*abfd
, char *buf
)
3531 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3534 static unsigned long
3535 read_8_bytes (bfd
*abfd
, char *buf
)
3537 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3541 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3544 CORE_ADDR retval
= 0;
3546 if (cu_header
->signed_addr_p
)
3548 switch (cu_header
->addr_size
)
3551 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3554 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3557 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
3560 internal_error (__FILE__
, __LINE__
,
3561 "read_address: bad switch, signed");
3566 switch (cu_header
->addr_size
)
3569 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3572 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3575 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3578 internal_error (__FILE__
, __LINE__
,
3579 "read_address: bad switch, unsigned");
3583 *bytes_read
= cu_header
->addr_size
;
3587 /* Reads the initial length from a section. The (draft) DWARF 2.1
3588 specification allows the initial length to take up either 4 bytes
3589 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
3590 bytes describe the length and all offsets will be 8 bytes in length
3593 The value returned via bytes_read should be used to increment
3594 the relevant pointer after calling read_initial_length().
3596 As a side effect, this function sets the fields initial_length_size
3597 and offset_size in cu_header to the values appropriate for the
3598 length field. (The format of the initial length field determines
3599 the width of file offsets to be fetched later with fetch_offset().)
3601 [ Note: read_initial_length() and read_offset() are based on the
3602 document entitled "DWARF Debugging Information Format", revision
3603 2.1, draft 4, dated July 20, 2000. This document was obtained
3606 http://reality.sgi.com/dehnert_engr/dwarf/dwarf2p1-draft4-000720.pdf
3608 This document is only a draft and is subject to change. (So beware.)
3610 - Kevin, Aug 4, 2000
3614 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
3619 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3621 if (retval
== 0xffffffff)
3623 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
3625 if (cu_header
!= NULL
)
3627 cu_header
->initial_length_size
= 12;
3628 cu_header
->offset_size
= 8;
3634 if (cu_header
!= NULL
)
3636 cu_header
->initial_length_size
= 4;
3637 cu_header
->offset_size
= 4;
3644 /* Read an offset from the data stream. The size of the offset is
3645 given by cu_header->offset_size. */
3648 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3653 switch (cu_header
->offset_size
)
3656 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3660 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3664 internal_error (__FILE__
, __LINE__
,
3665 "read_offset: bad switch");
3672 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
3674 /* If the size of a host char is 8 bits, we can return a pointer
3675 to the buffer, otherwise we have to copy the data to a buffer
3676 allocated on the temporary obstack. */
3677 gdb_assert (HOST_CHAR_BIT
== 8);
3682 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3684 /* If the size of a host char is 8 bits, we can return a pointer
3685 to the string, otherwise we have to copy the string to a buffer
3686 allocated on the temporary obstack. */
3687 gdb_assert (HOST_CHAR_BIT
== 8);
3690 *bytes_read_ptr
= 1;
3693 *bytes_read_ptr
= strlen (buf
) + 1;
3698 read_indirect_string (bfd
*abfd
, char *buf
,
3699 const struct comp_unit_head
*cu_header
,
3700 unsigned int *bytes_read_ptr
)
3702 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
3703 (int *) bytes_read_ptr
);
3705 if (dwarf_str_buffer
== NULL
)
3707 error ("DW_FORM_strp used without .debug_str section");
3710 if (str_offset
>= dwarf_str_size
)
3712 error ("DW_FORM_strp pointing outside of .debug_str section");
3715 gdb_assert (HOST_CHAR_BIT
== 8);
3716 if (dwarf_str_buffer
[str_offset
] == '\0')
3718 return dwarf_str_buffer
+ str_offset
;
3721 static unsigned long
3722 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3724 unsigned long result
;
3725 unsigned int num_read
;
3735 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3738 result
|= ((unsigned long)(byte
& 127) << shift
);
3739 if ((byte
& 128) == 0)
3745 *bytes_read_ptr
= num_read
;
3750 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3753 int i
, shift
, size
, num_read
;
3763 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3766 result
|= ((long)(byte
& 127) << shift
);
3768 if ((byte
& 128) == 0)
3773 if ((shift
< size
) && (byte
& 0x40))
3775 result
|= -(1 << shift
);
3777 *bytes_read_ptr
= num_read
;
3782 set_cu_language (unsigned int lang
)
3788 cu_language
= language_c
;
3790 case DW_LANG_C_plus_plus
:
3791 cu_language
= language_cplus
;
3793 case DW_LANG_Fortran77
:
3794 case DW_LANG_Fortran90
:
3795 cu_language
= language_fortran
;
3797 case DW_LANG_Mips_Assembler
:
3798 cu_language
= language_asm
;
3801 cu_language
= language_java
;
3804 case DW_LANG_Cobol74
:
3805 case DW_LANG_Cobol85
:
3806 case DW_LANG_Pascal83
:
3807 case DW_LANG_Modula2
:
3809 cu_language
= language_unknown
;
3812 cu_language_defn
= language_def (cu_language
);
3815 /* Return the named attribute or NULL if not there. */
3817 static struct attribute
*
3818 dwarf_attr (struct die_info
*die
, unsigned int name
)
3821 struct attribute
*spec
= NULL
;
3823 for (i
= 0; i
< die
->num_attrs
; ++i
)
3825 if (die
->attrs
[i
].name
== name
)
3827 return &die
->attrs
[i
];
3829 if (die
->attrs
[i
].name
== DW_AT_specification
3830 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3831 spec
= &die
->attrs
[i
];
3835 struct die_info
*ref_die
=
3836 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3839 return dwarf_attr (ref_die
, name
);
3846 die_is_declaration (struct die_info
*die
)
3848 return (dwarf_attr (die
, DW_AT_declaration
)
3849 && ! dwarf_attr (die
, DW_AT_specification
));
3852 /* Decode the line number information for the compilation unit whose
3853 line number info is at OFFSET in the .debug_line section.
3854 The compilation directory of the file is passed in COMP_DIR. */
3858 unsigned int num_files
;
3871 unsigned int num_dirs
;
3876 dwarf_decode_lines (unsigned int offset
, char *comp_dir
, bfd
*abfd
,
3877 const struct comp_unit_head
*cu_header
)
3881 struct line_head lh
;
3882 struct cleanup
*back_to
;
3883 unsigned int i
, bytes_read
;
3884 char *cur_file
, *cur_dir
;
3885 unsigned char op_code
, extended_op
, adj_opcode
;
3887 #define FILE_ALLOC_CHUNK 5
3888 #define DIR_ALLOC_CHUNK 5
3890 struct filenames files
;
3891 struct directories dirs
;
3893 if (dwarf_line_buffer
== NULL
)
3895 complain (&dwarf2_missing_line_number_section
);
3899 files
.num_files
= 0;
3905 line_ptr
= dwarf_line_buffer
+ offset
;
3907 /* read in the prologue */
3908 lh
.total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
3909 line_ptr
+= bytes_read
;
3910 line_end
= line_ptr
+ lh
.total_length
;
3911 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3913 lh
.prologue_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
3914 line_ptr
+= bytes_read
;
3915 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3917 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3919 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3921 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3923 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3925 lh
.standard_opcode_lengths
= (unsigned char *)
3926 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3927 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
3929 lh
.standard_opcode_lengths
[0] = 1;
3930 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3932 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3936 /* Read directory table */
3937 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3939 line_ptr
+= bytes_read
;
3940 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3942 dirs
.dirs
= (char **)
3943 xrealloc (dirs
.dirs
,
3944 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3945 if (dirs
.num_dirs
== 0)
3946 make_cleanup (free_current_contents
, &dirs
.dirs
);
3948 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3950 line_ptr
+= bytes_read
;
3952 /* Read file name table */
3953 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3955 line_ptr
+= bytes_read
;
3956 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3958 files
.files
= (struct fileinfo
*)
3959 xrealloc (files
.files
,
3960 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3961 * sizeof (struct fileinfo
));
3962 if (files
.num_files
== 0)
3963 make_cleanup (free_current_contents
, &files
.files
);
3965 files
.files
[files
.num_files
].name
= cur_file
;
3966 files
.files
[files
.num_files
].dir
=
3967 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3968 line_ptr
+= bytes_read
;
3969 files
.files
[files
.num_files
].time
=
3970 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3971 line_ptr
+= bytes_read
;
3972 files
.files
[files
.num_files
].size
=
3973 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3974 line_ptr
+= bytes_read
;
3977 line_ptr
+= bytes_read
;
3979 /* Read the statement sequences until there's nothing left. */
3980 while (line_ptr
< line_end
)
3982 /* state machine registers */
3983 CORE_ADDR address
= 0;
3984 unsigned int file
= 1;
3985 unsigned int line
= 1;
3986 unsigned int column
= 0;
3987 int is_stmt
= lh
.default_is_stmt
;
3988 int basic_block
= 0;
3989 int end_sequence
= 0;
3991 /* Start a subfile for the current file of the state machine. */
3992 if (files
.num_files
>= file
)
3994 /* The file and directory tables are 0 based, the references
3996 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3997 (files
.files
[file
- 1].dir
3998 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
4002 /* Decode the table. */
4003 while (!end_sequence
)
4005 op_code
= read_1_byte (abfd
, line_ptr
);
4008 if (op_code
>= lh
.opcode_base
)
4009 { /* Special operand. */
4010 adj_opcode
= op_code
- lh
.opcode_base
;
4011 address
+= (adj_opcode
/ lh
.line_range
)
4012 * lh
.minimum_instruction_length
;
4013 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
4014 /* append row to matrix using current values */
4015 record_line (current_subfile
, line
, address
);
4018 else switch (op_code
)
4020 case DW_LNS_extended_op
:
4021 line_ptr
+= 1; /* ignore length */
4022 extended_op
= read_1_byte (abfd
, line_ptr
);
4024 switch (extended_op
)
4026 case DW_LNE_end_sequence
:
4028 /* Don't call record_line here. The end_sequence
4029 instruction provides the address of the first byte
4030 *after* the last line in the sequence; it's not the
4031 address of any real source line. However, the GDB
4032 linetable structure only records the starts of lines,
4033 not the ends. This is a weakness of GDB. */
4035 case DW_LNE_set_address
:
4036 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
4037 line_ptr
+= bytes_read
;
4038 address
+= baseaddr
;
4040 case DW_LNE_define_file
:
4041 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
4042 line_ptr
+= bytes_read
;
4043 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
4045 files
.files
= (struct fileinfo
*)
4046 xrealloc (files
.files
,
4047 (files
.num_files
+ FILE_ALLOC_CHUNK
)
4048 * sizeof (struct fileinfo
));
4049 if (files
.num_files
== 0)
4050 make_cleanup (free_current_contents
, &files
.files
);
4052 files
.files
[files
.num_files
].name
= cur_file
;
4053 files
.files
[files
.num_files
].dir
=
4054 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4055 line_ptr
+= bytes_read
;
4056 files
.files
[files
.num_files
].time
=
4057 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4058 line_ptr
+= bytes_read
;
4059 files
.files
[files
.num_files
].size
=
4060 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4061 line_ptr
+= bytes_read
;
4065 complain (&dwarf2_mangled_line_number_section
);
4070 record_line (current_subfile
, line
, address
);
4073 case DW_LNS_advance_pc
:
4074 address
+= lh
.minimum_instruction_length
4075 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4076 line_ptr
+= bytes_read
;
4078 case DW_LNS_advance_line
:
4079 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
4080 line_ptr
+= bytes_read
;
4082 case DW_LNS_set_file
:
4083 /* The file and directory tables are 0 based, the references
4085 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4086 line_ptr
+= bytes_read
;
4087 dwarf2_start_subfile
4088 (files
.files
[file
- 1].name
,
4089 (files
.files
[file
- 1].dir
4090 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
4093 case DW_LNS_set_column
:
4094 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4095 line_ptr
+= bytes_read
;
4097 case DW_LNS_negate_stmt
:
4098 is_stmt
= (!is_stmt
);
4100 case DW_LNS_set_basic_block
:
4103 /* Add to the address register of the state machine the
4104 address increment value corresponding to special opcode
4105 255. Ie, this value is scaled by the minimum instruction
4106 length since special opcode 255 would have scaled the
4108 case DW_LNS_const_add_pc
:
4109 address
+= (lh
.minimum_instruction_length
4110 * ((255 - lh
.opcode_base
) / lh
.line_range
));
4112 case DW_LNS_fixed_advance_pc
:
4113 address
+= read_2_bytes (abfd
, line_ptr
);
4117 { /* Unknown standard opcode, ignore it. */
4119 for (i
= 0; i
< lh
.standard_opcode_lengths
[op_code
]; i
++)
4121 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4122 line_ptr
+= bytes_read
;
4129 do_cleanups (back_to
);
4132 /* Start a subfile for DWARF. FILENAME is the name of the file and
4133 DIRNAME the name of the source directory which contains FILENAME
4134 or NULL if not known.
4135 This routine tries to keep line numbers from identical absolute and
4136 relative file names in a common subfile.
4138 Using the `list' example from the GDB testsuite, which resides in
4139 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4140 of /srcdir/list0.c yields the following debugging information for list0.c:
4142 DW_AT_name: /srcdir/list0.c
4143 DW_AT_comp_dir: /compdir
4144 files.files[0].name: list0.h
4145 files.files[0].dir: /srcdir
4146 files.files[1].name: list0.c
4147 files.files[1].dir: /srcdir
4149 The line number information for list0.c has to end up in a single
4150 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4153 dwarf2_start_subfile (char *filename
, char *dirname
)
4155 /* If the filename isn't absolute, try to match an existing subfile
4156 with the full pathname. */
4158 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
4160 struct subfile
*subfile
;
4161 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4163 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4165 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
4167 current_subfile
= subfile
;
4174 start_subfile (filename
, dirname
);
4177 /* Given a pointer to a DWARF information entry, figure out if we need
4178 to make a symbol table entry for it, and if so, create a new entry
4179 and return a pointer to it.
4180 If TYPE is NULL, determine symbol type from the die, otherwise
4181 used the passed type. */
4183 static struct symbol
*
4184 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
4185 const struct comp_unit_head
*cu_header
)
4187 struct symbol
*sym
= NULL
;
4189 struct attribute
*attr
= NULL
;
4190 struct attribute
*attr2
= NULL
;
4193 name
= dwarf2_linkage_name (die
);
4196 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4197 sizeof (struct symbol
));
4198 OBJSTAT (objfile
, n_syms
++);
4199 memset (sym
, 0, sizeof (struct symbol
));
4200 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4201 &objfile
->symbol_obstack
);
4203 /* Default assumptions.
4204 Use the passed type or decode it from the die. */
4205 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4206 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4208 SYMBOL_TYPE (sym
) = type
;
4210 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
4211 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4214 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4217 /* If this symbol is from a C++ compilation, then attempt to
4218 cache the demangled form for future reference. This is a
4219 typical time versus space tradeoff, that was decided in favor
4220 of time because it sped up C++ symbol lookups by a factor of
4223 SYMBOL_LANGUAGE (sym
) = cu_language
;
4224 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4228 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4231 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4233 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4235 case DW_TAG_subprogram
:
4236 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4238 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4239 attr2
= dwarf_attr (die
, DW_AT_external
);
4240 if (attr2
&& (DW_UNSND (attr2
) != 0))
4242 add_symbol_to_list (sym
, &global_symbols
);
4246 add_symbol_to_list (sym
, list_in_scope
);
4249 case DW_TAG_variable
:
4250 /* Compilation with minimal debug info may result in variables
4251 with missing type entries. Change the misleading `void' type
4252 to something sensible. */
4253 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4254 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4255 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4256 "<variable, no debug info>",
4258 attr
= dwarf_attr (die
, DW_AT_const_value
);
4261 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4262 attr2
= dwarf_attr (die
, DW_AT_external
);
4263 if (attr2
&& (DW_UNSND (attr2
) != 0))
4264 add_symbol_to_list (sym
, &global_symbols
);
4266 add_symbol_to_list (sym
, list_in_scope
);
4269 attr
= dwarf_attr (die
, DW_AT_location
);
4272 attr2
= dwarf_attr (die
, DW_AT_external
);
4273 if (attr2
&& (DW_UNSND (attr2
) != 0))
4275 SYMBOL_VALUE_ADDRESS (sym
) =
4276 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4277 add_symbol_to_list (sym
, &global_symbols
);
4279 /* In shared libraries the address of the variable
4280 in the location descriptor might still be relocatable,
4281 so its value could be zero.
4282 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4283 value is zero, the address of the variable will then
4284 be determined from the minimal symbol table whenever
4285 the variable is referenced. */
4286 if (SYMBOL_VALUE_ADDRESS (sym
))
4288 fixup_symbol_section (sym
, objfile
);
4289 SYMBOL_VALUE_ADDRESS (sym
) +=
4290 ANOFFSET (objfile
->section_offsets
,
4291 SYMBOL_SECTION (sym
));
4292 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4295 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4299 SYMBOL_VALUE (sym
) = addr
=
4300 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4301 add_symbol_to_list (sym
, list_in_scope
);
4304 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4308 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4309 SYMBOL_VALUE (sym
) =
4310 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4314 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4315 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4319 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4323 fixup_symbol_section (sym
, objfile
);
4324 SYMBOL_VALUE_ADDRESS (sym
) =
4325 addr
+ ANOFFSET (objfile
->section_offsets
,
4326 SYMBOL_SECTION (sym
));
4327 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4333 /* We do not know the address of this symbol.
4334 If it is an external symbol and we have type information
4335 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4336 The address of the variable will then be determined from
4337 the minimal symbol table whenever the variable is
4339 attr2
= dwarf_attr (die
, DW_AT_external
);
4340 if (attr2
&& (DW_UNSND (attr2
) != 0)
4341 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4343 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4344 add_symbol_to_list (sym
, &global_symbols
);
4348 case DW_TAG_formal_parameter
:
4349 attr
= dwarf_attr (die
, DW_AT_location
);
4352 SYMBOL_VALUE (sym
) =
4353 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4356 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4357 SYMBOL_VALUE (sym
) =
4358 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4364 if (basereg
!= frame_base_reg
)
4365 complain (&dwarf2_complex_location_expr
);
4366 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4370 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4371 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4376 SYMBOL_CLASS (sym
) = LOC_ARG
;
4379 attr
= dwarf_attr (die
, DW_AT_const_value
);
4382 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4384 add_symbol_to_list (sym
, list_in_scope
);
4386 case DW_TAG_unspecified_parameters
:
4387 /* From varargs functions; gdb doesn't seem to have any
4388 interest in this information, so just ignore it for now.
4391 case DW_TAG_class_type
:
4392 case DW_TAG_structure_type
:
4393 case DW_TAG_union_type
:
4394 case DW_TAG_enumeration_type
:
4395 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4396 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4397 add_symbol_to_list (sym
, list_in_scope
);
4399 /* The semantics of C++ state that "struct foo { ... }" also
4400 defines a typedef for "foo". Synthesize a typedef symbol so
4401 that "ptype foo" works as expected. */
4402 if (cu_language
== language_cplus
)
4404 struct symbol
*typedef_sym
= (struct symbol
*)
4405 obstack_alloc (&objfile
->symbol_obstack
,
4406 sizeof (struct symbol
));
4407 *typedef_sym
= *sym
;
4408 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4409 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4410 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4411 obsavestring (SYMBOL_NAME (sym
),
4412 strlen (SYMBOL_NAME (sym
)),
4413 &objfile
->type_obstack
);
4414 add_symbol_to_list (typedef_sym
, list_in_scope
);
4417 case DW_TAG_typedef
:
4418 case DW_TAG_base_type
:
4419 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4420 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4421 add_symbol_to_list (sym
, list_in_scope
);
4423 case DW_TAG_enumerator
:
4424 attr
= dwarf_attr (die
, DW_AT_const_value
);
4427 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4429 add_symbol_to_list (sym
, list_in_scope
);
4432 /* Not a tag we recognize. Hopefully we aren't processing
4433 trash data, but since we must specifically ignore things
4434 we don't recognize, there is nothing else we should do at
4436 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4443 /* Copy constant value from an attribute to a symbol. */
4446 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
4447 struct objfile
*objfile
,
4448 const struct comp_unit_head
*cu_header
)
4450 struct dwarf_block
*blk
;
4455 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
4456 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4457 cu_header
->addr_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4458 SYMBOL_VALUE_BYTES (sym
) = (char *)
4459 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
4460 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
4462 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4464 case DW_FORM_block1
:
4465 case DW_FORM_block2
:
4466 case DW_FORM_block4
:
4468 blk
= DW_BLOCK (attr
);
4469 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4470 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4471 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4472 SYMBOL_VALUE_BYTES (sym
) = (char *)
4473 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4474 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4475 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4478 /* The DW_AT_const_value attributes are supposed to carry the
4479 symbol's value "represented as it would be on the target
4480 architecture." By the time we get here, it's already been
4481 converted to host endianness, so we just need to sign- or
4482 zero-extend it as appropriate. */
4484 dwarf2_const_value_data (attr
, sym
, 8);
4487 dwarf2_const_value_data (attr
, sym
, 16);
4490 dwarf2_const_value_data (attr
, sym
, 32);
4493 dwarf2_const_value_data (attr
, sym
, 64);
4497 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4498 SYMBOL_CLASS (sym
) = LOC_CONST
;
4502 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4503 SYMBOL_CLASS (sym
) = LOC_CONST
;
4507 complain (&dwarf2_unsupported_const_value_attr
,
4508 dwarf_form_name (attr
->form
));
4509 SYMBOL_VALUE (sym
) = 0;
4510 SYMBOL_CLASS (sym
) = LOC_CONST
;
4516 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4517 or zero-extend it as appropriate for the symbol's type. */
4519 dwarf2_const_value_data (struct attribute
*attr
,
4523 LONGEST l
= DW_UNSND (attr
);
4525 if (bits
< sizeof (l
) * 8)
4527 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4528 l
&= ((LONGEST
) 1 << bits
) - 1;
4530 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4533 SYMBOL_VALUE (sym
) = l
;
4534 SYMBOL_CLASS (sym
) = LOC_CONST
;
4538 /* Return the type of the die in question using its DW_AT_type attribute. */
4540 static struct type
*
4541 die_type (struct die_info
*die
, struct objfile
*objfile
,
4542 const struct comp_unit_head
*cu_header
)
4545 struct attribute
*type_attr
;
4546 struct die_info
*type_die
;
4549 type_attr
= dwarf_attr (die
, DW_AT_type
);
4552 /* A missing DW_AT_type represents a void type. */
4553 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4557 ref
= dwarf2_get_ref_die_offset (type_attr
);
4558 type_die
= follow_die_ref (ref
);
4561 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4565 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4568 dump_die (type_die
);
4569 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4574 /* Return the containing type of the die in question using its
4575 DW_AT_containing_type attribute. */
4577 static struct type
*
4578 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
4579 const struct comp_unit_head
*cu_header
)
4581 struct type
*type
= NULL
;
4582 struct attribute
*type_attr
;
4583 struct die_info
*type_die
= NULL
;
4586 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4589 ref
= dwarf2_get_ref_die_offset (type_attr
);
4590 type_die
= follow_die_ref (ref
);
4593 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4596 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4601 dump_die (type_die
);
4602 error ("Dwarf Error: Problem turning containing type into gdb type.");
4608 static struct type
*
4609 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
4611 struct die_info
*die
;
4614 die
= follow_die_ref (offset
);
4617 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4620 type
= tag_type_to_type (die
, objfile
);
4625 static struct type
*
4626 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
4627 const struct comp_unit_head
*cu_header
)
4635 read_type_die (die
, objfile
, cu_header
);
4639 error ("Dwarf Error: Cannot find type of die.");
4646 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
4647 const struct comp_unit_head
*cu_header
)
4651 case DW_TAG_class_type
:
4652 case DW_TAG_structure_type
:
4653 case DW_TAG_union_type
:
4654 read_structure_scope (die
, objfile
, cu_header
);
4656 case DW_TAG_enumeration_type
:
4657 read_enumeration (die
, objfile
, cu_header
);
4659 case DW_TAG_subprogram
:
4660 case DW_TAG_subroutine_type
:
4661 read_subroutine_type (die
, objfile
, cu_header
);
4663 case DW_TAG_array_type
:
4664 read_array_type (die
, objfile
, cu_header
);
4666 case DW_TAG_pointer_type
:
4667 read_tag_pointer_type (die
, objfile
, cu_header
);
4669 case DW_TAG_ptr_to_member_type
:
4670 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
4672 case DW_TAG_reference_type
:
4673 read_tag_reference_type (die
, objfile
, cu_header
);
4675 case DW_TAG_const_type
:
4676 read_tag_const_type (die
, objfile
, cu_header
);
4678 case DW_TAG_volatile_type
:
4679 read_tag_volatile_type (die
, objfile
, cu_header
);
4681 case DW_TAG_string_type
:
4682 read_tag_string_type (die
, objfile
);
4684 case DW_TAG_typedef
:
4685 read_typedef (die
, objfile
, cu_header
);
4687 case DW_TAG_base_type
:
4688 read_base_type (die
, objfile
);
4691 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4696 static struct type
*
4697 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
4699 /* FIXME - this should not produce a new (struct type *)
4700 every time. It should cache base types. */
4704 case DW_ATE_address
:
4705 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4707 case DW_ATE_boolean
:
4708 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4710 case DW_ATE_complex_float
:
4713 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4717 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4723 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4727 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4734 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4737 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4741 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4745 case DW_ATE_signed_char
:
4746 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4748 case DW_ATE_unsigned
:
4752 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4755 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4759 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4763 case DW_ATE_unsigned_char
:
4764 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4767 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4774 copy_die (struct die_info
*old_die
)
4776 struct die_info
*new_die
;
4779 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4780 memset (new_die
, 0, sizeof (struct die_info
));
4782 new_die
->tag
= old_die
->tag
;
4783 new_die
->has_children
= old_die
->has_children
;
4784 new_die
->abbrev
= old_die
->abbrev
;
4785 new_die
->offset
= old_die
->offset
;
4786 new_die
->type
= NULL
;
4788 num_attrs
= old_die
->num_attrs
;
4789 new_die
->num_attrs
= num_attrs
;
4790 new_die
->attrs
= (struct attribute
*)
4791 xmalloc (num_attrs
* sizeof (struct attribute
));
4793 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4795 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4796 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4797 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4800 new_die
->next
= NULL
;
4805 /* Return sibling of die, NULL if no sibling. */
4807 static struct die_info
*
4808 sibling_die (struct die_info
*die
)
4810 int nesting_level
= 0;
4812 if (!die
->has_children
)
4814 if (die
->next
&& (die
->next
->tag
== 0))
4827 if (die
->has_children
)
4837 while (nesting_level
);
4838 if (die
&& (die
->tag
== 0))
4849 /* Get linkage name of a die, return NULL if not found. */
4852 dwarf2_linkage_name (struct die_info
*die
)
4854 struct attribute
*attr
;
4856 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4857 if (attr
&& DW_STRING (attr
))
4858 return DW_STRING (attr
);
4859 attr
= dwarf_attr (die
, DW_AT_name
);
4860 if (attr
&& DW_STRING (attr
))
4861 return DW_STRING (attr
);
4865 /* Convert a DIE tag into its string name. */
4868 dwarf_tag_name (register unsigned tag
)
4872 case DW_TAG_padding
:
4873 return "DW_TAG_padding";
4874 case DW_TAG_array_type
:
4875 return "DW_TAG_array_type";
4876 case DW_TAG_class_type
:
4877 return "DW_TAG_class_type";
4878 case DW_TAG_entry_point
:
4879 return "DW_TAG_entry_point";
4880 case DW_TAG_enumeration_type
:
4881 return "DW_TAG_enumeration_type";
4882 case DW_TAG_formal_parameter
:
4883 return "DW_TAG_formal_parameter";
4884 case DW_TAG_imported_declaration
:
4885 return "DW_TAG_imported_declaration";
4887 return "DW_TAG_label";
4888 case DW_TAG_lexical_block
:
4889 return "DW_TAG_lexical_block";
4891 return "DW_TAG_member";
4892 case DW_TAG_pointer_type
:
4893 return "DW_TAG_pointer_type";
4894 case DW_TAG_reference_type
:
4895 return "DW_TAG_reference_type";
4896 case DW_TAG_compile_unit
:
4897 return "DW_TAG_compile_unit";
4898 case DW_TAG_string_type
:
4899 return "DW_TAG_string_type";
4900 case DW_TAG_structure_type
:
4901 return "DW_TAG_structure_type";
4902 case DW_TAG_subroutine_type
:
4903 return "DW_TAG_subroutine_type";
4904 case DW_TAG_typedef
:
4905 return "DW_TAG_typedef";
4906 case DW_TAG_union_type
:
4907 return "DW_TAG_union_type";
4908 case DW_TAG_unspecified_parameters
:
4909 return "DW_TAG_unspecified_parameters";
4910 case DW_TAG_variant
:
4911 return "DW_TAG_variant";
4912 case DW_TAG_common_block
:
4913 return "DW_TAG_common_block";
4914 case DW_TAG_common_inclusion
:
4915 return "DW_TAG_common_inclusion";
4916 case DW_TAG_inheritance
:
4917 return "DW_TAG_inheritance";
4918 case DW_TAG_inlined_subroutine
:
4919 return "DW_TAG_inlined_subroutine";
4921 return "DW_TAG_module";
4922 case DW_TAG_ptr_to_member_type
:
4923 return "DW_TAG_ptr_to_member_type";
4924 case DW_TAG_set_type
:
4925 return "DW_TAG_set_type";
4926 case DW_TAG_subrange_type
:
4927 return "DW_TAG_subrange_type";
4928 case DW_TAG_with_stmt
:
4929 return "DW_TAG_with_stmt";
4930 case DW_TAG_access_declaration
:
4931 return "DW_TAG_access_declaration";
4932 case DW_TAG_base_type
:
4933 return "DW_TAG_base_type";
4934 case DW_TAG_catch_block
:
4935 return "DW_TAG_catch_block";
4936 case DW_TAG_const_type
:
4937 return "DW_TAG_const_type";
4938 case DW_TAG_constant
:
4939 return "DW_TAG_constant";
4940 case DW_TAG_enumerator
:
4941 return "DW_TAG_enumerator";
4942 case DW_TAG_file_type
:
4943 return "DW_TAG_file_type";
4945 return "DW_TAG_friend";
4946 case DW_TAG_namelist
:
4947 return "DW_TAG_namelist";
4948 case DW_TAG_namelist_item
:
4949 return "DW_TAG_namelist_item";
4950 case DW_TAG_packed_type
:
4951 return "DW_TAG_packed_type";
4952 case DW_TAG_subprogram
:
4953 return "DW_TAG_subprogram";
4954 case DW_TAG_template_type_param
:
4955 return "DW_TAG_template_type_param";
4956 case DW_TAG_template_value_param
:
4957 return "DW_TAG_template_value_param";
4958 case DW_TAG_thrown_type
:
4959 return "DW_TAG_thrown_type";
4960 case DW_TAG_try_block
:
4961 return "DW_TAG_try_block";
4962 case DW_TAG_variant_part
:
4963 return "DW_TAG_variant_part";
4964 case DW_TAG_variable
:
4965 return "DW_TAG_variable";
4966 case DW_TAG_volatile_type
:
4967 return "DW_TAG_volatile_type";
4968 case DW_TAG_MIPS_loop
:
4969 return "DW_TAG_MIPS_loop";
4970 case DW_TAG_format_label
:
4971 return "DW_TAG_format_label";
4972 case DW_TAG_function_template
:
4973 return "DW_TAG_function_template";
4974 case DW_TAG_class_template
:
4975 return "DW_TAG_class_template";
4977 return "DW_TAG_<unknown>";
4981 /* Convert a DWARF attribute code into its string name. */
4984 dwarf_attr_name (register unsigned attr
)
4989 return "DW_AT_sibling";
4990 case DW_AT_location
:
4991 return "DW_AT_location";
4993 return "DW_AT_name";
4994 case DW_AT_ordering
:
4995 return "DW_AT_ordering";
4996 case DW_AT_subscr_data
:
4997 return "DW_AT_subscr_data";
4998 case DW_AT_byte_size
:
4999 return "DW_AT_byte_size";
5000 case DW_AT_bit_offset
:
5001 return "DW_AT_bit_offset";
5002 case DW_AT_bit_size
:
5003 return "DW_AT_bit_size";
5004 case DW_AT_element_list
:
5005 return "DW_AT_element_list";
5006 case DW_AT_stmt_list
:
5007 return "DW_AT_stmt_list";
5009 return "DW_AT_low_pc";
5011 return "DW_AT_high_pc";
5012 case DW_AT_language
:
5013 return "DW_AT_language";
5015 return "DW_AT_member";
5017 return "DW_AT_discr";
5018 case DW_AT_discr_value
:
5019 return "DW_AT_discr_value";
5020 case DW_AT_visibility
:
5021 return "DW_AT_visibility";
5023 return "DW_AT_import";
5024 case DW_AT_string_length
:
5025 return "DW_AT_string_length";
5026 case DW_AT_common_reference
:
5027 return "DW_AT_common_reference";
5028 case DW_AT_comp_dir
:
5029 return "DW_AT_comp_dir";
5030 case DW_AT_const_value
:
5031 return "DW_AT_const_value";
5032 case DW_AT_containing_type
:
5033 return "DW_AT_containing_type";
5034 case DW_AT_default_value
:
5035 return "DW_AT_default_value";
5037 return "DW_AT_inline";
5038 case DW_AT_is_optional
:
5039 return "DW_AT_is_optional";
5040 case DW_AT_lower_bound
:
5041 return "DW_AT_lower_bound";
5042 case DW_AT_producer
:
5043 return "DW_AT_producer";
5044 case DW_AT_prototyped
:
5045 return "DW_AT_prototyped";
5046 case DW_AT_return_addr
:
5047 return "DW_AT_return_addr";
5048 case DW_AT_start_scope
:
5049 return "DW_AT_start_scope";
5050 case DW_AT_stride_size
:
5051 return "DW_AT_stride_size";
5052 case DW_AT_upper_bound
:
5053 return "DW_AT_upper_bound";
5054 case DW_AT_abstract_origin
:
5055 return "DW_AT_abstract_origin";
5056 case DW_AT_accessibility
:
5057 return "DW_AT_accessibility";
5058 case DW_AT_address_class
:
5059 return "DW_AT_address_class";
5060 case DW_AT_artificial
:
5061 return "DW_AT_artificial";
5062 case DW_AT_base_types
:
5063 return "DW_AT_base_types";
5064 case DW_AT_calling_convention
:
5065 return "DW_AT_calling_convention";
5067 return "DW_AT_count";
5068 case DW_AT_data_member_location
:
5069 return "DW_AT_data_member_location";
5070 case DW_AT_decl_column
:
5071 return "DW_AT_decl_column";
5072 case DW_AT_decl_file
:
5073 return "DW_AT_decl_file";
5074 case DW_AT_decl_line
:
5075 return "DW_AT_decl_line";
5076 case DW_AT_declaration
:
5077 return "DW_AT_declaration";
5078 case DW_AT_discr_list
:
5079 return "DW_AT_discr_list";
5080 case DW_AT_encoding
:
5081 return "DW_AT_encoding";
5082 case DW_AT_external
:
5083 return "DW_AT_external";
5084 case DW_AT_frame_base
:
5085 return "DW_AT_frame_base";
5087 return "DW_AT_friend";
5088 case DW_AT_identifier_case
:
5089 return "DW_AT_identifier_case";
5090 case DW_AT_macro_info
:
5091 return "DW_AT_macro_info";
5092 case DW_AT_namelist_items
:
5093 return "DW_AT_namelist_items";
5094 case DW_AT_priority
:
5095 return "DW_AT_priority";
5097 return "DW_AT_segment";
5098 case DW_AT_specification
:
5099 return "DW_AT_specification";
5100 case DW_AT_static_link
:
5101 return "DW_AT_static_link";
5103 return "DW_AT_type";
5104 case DW_AT_use_location
:
5105 return "DW_AT_use_location";
5106 case DW_AT_variable_parameter
:
5107 return "DW_AT_variable_parameter";
5108 case DW_AT_virtuality
:
5109 return "DW_AT_virtuality";
5110 case DW_AT_vtable_elem_location
:
5111 return "DW_AT_vtable_elem_location";
5114 case DW_AT_MIPS_fde
:
5115 return "DW_AT_MIPS_fde";
5116 case DW_AT_MIPS_loop_begin
:
5117 return "DW_AT_MIPS_loop_begin";
5118 case DW_AT_MIPS_tail_loop_begin
:
5119 return "DW_AT_MIPS_tail_loop_begin";
5120 case DW_AT_MIPS_epilog_begin
:
5121 return "DW_AT_MIPS_epilog_begin";
5122 case DW_AT_MIPS_loop_unroll_factor
:
5123 return "DW_AT_MIPS_loop_unroll_factor";
5124 case DW_AT_MIPS_software_pipeline_depth
:
5125 return "DW_AT_MIPS_software_pipeline_depth";
5126 case DW_AT_MIPS_linkage_name
:
5127 return "DW_AT_MIPS_linkage_name";
5130 case DW_AT_sf_names
:
5131 return "DW_AT_sf_names";
5132 case DW_AT_src_info
:
5133 return "DW_AT_src_info";
5134 case DW_AT_mac_info
:
5135 return "DW_AT_mac_info";
5136 case DW_AT_src_coords
:
5137 return "DW_AT_src_coords";
5138 case DW_AT_body_begin
:
5139 return "DW_AT_body_begin";
5140 case DW_AT_body_end
:
5141 return "DW_AT_body_end";
5143 return "DW_AT_<unknown>";
5147 /* Convert a DWARF value form code into its string name. */
5150 dwarf_form_name (register unsigned form
)
5155 return "DW_FORM_addr";
5156 case DW_FORM_block2
:
5157 return "DW_FORM_block2";
5158 case DW_FORM_block4
:
5159 return "DW_FORM_block4";
5161 return "DW_FORM_data2";
5163 return "DW_FORM_data4";
5165 return "DW_FORM_data8";
5166 case DW_FORM_string
:
5167 return "DW_FORM_string";
5169 return "DW_FORM_block";
5170 case DW_FORM_block1
:
5171 return "DW_FORM_block1";
5173 return "DW_FORM_data1";
5175 return "DW_FORM_flag";
5177 return "DW_FORM_sdata";
5179 return "DW_FORM_strp";
5181 return "DW_FORM_udata";
5182 case DW_FORM_ref_addr
:
5183 return "DW_FORM_ref_addr";
5185 return "DW_FORM_ref1";
5187 return "DW_FORM_ref2";
5189 return "DW_FORM_ref4";
5191 return "DW_FORM_ref8";
5192 case DW_FORM_ref_udata
:
5193 return "DW_FORM_ref_udata";
5194 case DW_FORM_indirect
:
5195 return "DW_FORM_indirect";
5197 return "DW_FORM_<unknown>";
5201 /* Convert a DWARF stack opcode into its string name. */
5204 dwarf_stack_op_name (register unsigned op
)
5209 return "DW_OP_addr";
5211 return "DW_OP_deref";
5213 return "DW_OP_const1u";
5215 return "DW_OP_const1s";
5217 return "DW_OP_const2u";
5219 return "DW_OP_const2s";
5221 return "DW_OP_const4u";
5223 return "DW_OP_const4s";
5225 return "DW_OP_const8u";
5227 return "DW_OP_const8s";
5229 return "DW_OP_constu";
5231 return "DW_OP_consts";
5235 return "DW_OP_drop";
5237 return "DW_OP_over";
5239 return "DW_OP_pick";
5241 return "DW_OP_swap";
5245 return "DW_OP_xderef";
5253 return "DW_OP_minus";
5265 return "DW_OP_plus";
5266 case DW_OP_plus_uconst
:
5267 return "DW_OP_plus_uconst";
5273 return "DW_OP_shra";
5291 return "DW_OP_skip";
5293 return "DW_OP_lit0";
5295 return "DW_OP_lit1";
5297 return "DW_OP_lit2";
5299 return "DW_OP_lit3";
5301 return "DW_OP_lit4";
5303 return "DW_OP_lit5";
5305 return "DW_OP_lit6";
5307 return "DW_OP_lit7";
5309 return "DW_OP_lit8";
5311 return "DW_OP_lit9";
5313 return "DW_OP_lit10";
5315 return "DW_OP_lit11";
5317 return "DW_OP_lit12";
5319 return "DW_OP_lit13";
5321 return "DW_OP_lit14";
5323 return "DW_OP_lit15";
5325 return "DW_OP_lit16";
5327 return "DW_OP_lit17";
5329 return "DW_OP_lit18";
5331 return "DW_OP_lit19";
5333 return "DW_OP_lit20";
5335 return "DW_OP_lit21";
5337 return "DW_OP_lit22";
5339 return "DW_OP_lit23";
5341 return "DW_OP_lit24";
5343 return "DW_OP_lit25";
5345 return "DW_OP_lit26";
5347 return "DW_OP_lit27";
5349 return "DW_OP_lit28";
5351 return "DW_OP_lit29";
5353 return "DW_OP_lit30";
5355 return "DW_OP_lit31";
5357 return "DW_OP_reg0";
5359 return "DW_OP_reg1";
5361 return "DW_OP_reg2";
5363 return "DW_OP_reg3";
5365 return "DW_OP_reg4";
5367 return "DW_OP_reg5";
5369 return "DW_OP_reg6";
5371 return "DW_OP_reg7";
5373 return "DW_OP_reg8";
5375 return "DW_OP_reg9";
5377 return "DW_OP_reg10";
5379 return "DW_OP_reg11";
5381 return "DW_OP_reg12";
5383 return "DW_OP_reg13";
5385 return "DW_OP_reg14";
5387 return "DW_OP_reg15";
5389 return "DW_OP_reg16";
5391 return "DW_OP_reg17";
5393 return "DW_OP_reg18";
5395 return "DW_OP_reg19";
5397 return "DW_OP_reg20";
5399 return "DW_OP_reg21";
5401 return "DW_OP_reg22";
5403 return "DW_OP_reg23";
5405 return "DW_OP_reg24";
5407 return "DW_OP_reg25";
5409 return "DW_OP_reg26";
5411 return "DW_OP_reg27";
5413 return "DW_OP_reg28";
5415 return "DW_OP_reg29";
5417 return "DW_OP_reg30";
5419 return "DW_OP_reg31";
5421 return "DW_OP_breg0";
5423 return "DW_OP_breg1";
5425 return "DW_OP_breg2";
5427 return "DW_OP_breg3";
5429 return "DW_OP_breg4";
5431 return "DW_OP_breg5";
5433 return "DW_OP_breg6";
5435 return "DW_OP_breg7";
5437 return "DW_OP_breg8";
5439 return "DW_OP_breg9";
5441 return "DW_OP_breg10";
5443 return "DW_OP_breg11";
5445 return "DW_OP_breg12";
5447 return "DW_OP_breg13";
5449 return "DW_OP_breg14";
5451 return "DW_OP_breg15";
5453 return "DW_OP_breg16";
5455 return "DW_OP_breg17";
5457 return "DW_OP_breg18";
5459 return "DW_OP_breg19";
5461 return "DW_OP_breg20";
5463 return "DW_OP_breg21";
5465 return "DW_OP_breg22";
5467 return "DW_OP_breg23";
5469 return "DW_OP_breg24";
5471 return "DW_OP_breg25";
5473 return "DW_OP_breg26";
5475 return "DW_OP_breg27";
5477 return "DW_OP_breg28";
5479 return "DW_OP_breg29";
5481 return "DW_OP_breg30";
5483 return "DW_OP_breg31";
5485 return "DW_OP_regx";
5487 return "DW_OP_fbreg";
5489 return "DW_OP_bregx";
5491 return "DW_OP_piece";
5492 case DW_OP_deref_size
:
5493 return "DW_OP_deref_size";
5494 case DW_OP_xderef_size
:
5495 return "DW_OP_xderef_size";
5499 return "OP_<unknown>";
5504 dwarf_bool_name (unsigned mybool
)
5512 /* Convert a DWARF type code into its string name. */
5515 dwarf_type_encoding_name (register unsigned enc
)
5519 case DW_ATE_address
:
5520 return "DW_ATE_address";
5521 case DW_ATE_boolean
:
5522 return "DW_ATE_boolean";
5523 case DW_ATE_complex_float
:
5524 return "DW_ATE_complex_float";
5526 return "DW_ATE_float";
5528 return "DW_ATE_signed";
5529 case DW_ATE_signed_char
:
5530 return "DW_ATE_signed_char";
5531 case DW_ATE_unsigned
:
5532 return "DW_ATE_unsigned";
5533 case DW_ATE_unsigned_char
:
5534 return "DW_ATE_unsigned_char";
5536 return "DW_ATE_<unknown>";
5540 /* Convert a DWARF call frame info operation to its string name. */
5544 dwarf_cfi_name (register unsigned cfi_opc
)
5548 case DW_CFA_advance_loc
:
5549 return "DW_CFA_advance_loc";
5551 return "DW_CFA_offset";
5552 case DW_CFA_restore
:
5553 return "DW_CFA_restore";
5555 return "DW_CFA_nop";
5556 case DW_CFA_set_loc
:
5557 return "DW_CFA_set_loc";
5558 case DW_CFA_advance_loc1
:
5559 return "DW_CFA_advance_loc1";
5560 case DW_CFA_advance_loc2
:
5561 return "DW_CFA_advance_loc2";
5562 case DW_CFA_advance_loc4
:
5563 return "DW_CFA_advance_loc4";
5564 case DW_CFA_offset_extended
:
5565 return "DW_CFA_offset_extended";
5566 case DW_CFA_restore_extended
:
5567 return "DW_CFA_restore_extended";
5568 case DW_CFA_undefined
:
5569 return "DW_CFA_undefined";
5570 case DW_CFA_same_value
:
5571 return "DW_CFA_same_value";
5572 case DW_CFA_register
:
5573 return "DW_CFA_register";
5574 case DW_CFA_remember_state
:
5575 return "DW_CFA_remember_state";
5576 case DW_CFA_restore_state
:
5577 return "DW_CFA_restore_state";
5578 case DW_CFA_def_cfa
:
5579 return "DW_CFA_def_cfa";
5580 case DW_CFA_def_cfa_register
:
5581 return "DW_CFA_def_cfa_register";
5582 case DW_CFA_def_cfa_offset
:
5583 return "DW_CFA_def_cfa_offset";
5584 /* SGI/MIPS specific */
5585 case DW_CFA_MIPS_advance_loc8
:
5586 return "DW_CFA_MIPS_advance_loc8";
5588 return "DW_CFA_<unknown>";
5594 dump_die (struct die_info
*die
)
5598 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5599 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5600 fprintf (stderr
, "\thas children: %s\n",
5601 dwarf_bool_name (die
->has_children
));
5603 fprintf (stderr
, "\tattributes:\n");
5604 for (i
= 0; i
< die
->num_attrs
; ++i
)
5606 fprintf (stderr
, "\t\t%s (%s) ",
5607 dwarf_attr_name (die
->attrs
[i
].name
),
5608 dwarf_form_name (die
->attrs
[i
].form
));
5609 switch (die
->attrs
[i
].form
)
5611 case DW_FORM_ref_addr
:
5613 fprintf (stderr
, "address: ");
5614 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5616 case DW_FORM_block2
:
5617 case DW_FORM_block4
:
5619 case DW_FORM_block1
:
5620 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5631 fprintf (stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
5633 case DW_FORM_string
:
5635 fprintf (stderr
, "string: \"%s\"",
5636 DW_STRING (&die
->attrs
[i
])
5637 ? DW_STRING (&die
->attrs
[i
]) : "");
5640 if (DW_UNSND (&die
->attrs
[i
]))
5641 fprintf (stderr
, "flag: TRUE");
5643 fprintf (stderr
, "flag: FALSE");
5645 case DW_FORM_indirect
:
5646 /* the reader will have reduced the indirect form to
5647 the "base form" so this form should not occur */
5648 fprintf (stderr
, "unexpected attribute form: DW_FORM_indirect");
5651 fprintf (stderr
, "unsupported attribute form: %d.",
5652 die
->attrs
[i
].form
);
5654 fprintf (stderr
, "\n");
5659 dump_die_list (struct die_info
*die
)
5669 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
5672 struct die_info
*old
;
5674 h
= (offset
% REF_HASH_SIZE
);
5675 old
= die_ref_table
[h
];
5676 die
->next_ref
= old
;
5677 die_ref_table
[h
] = die
;
5682 dwarf2_empty_hash_tables (void)
5684 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5688 dwarf2_get_ref_die_offset (struct attribute
*attr
)
5690 unsigned int result
= 0;
5694 case DW_FORM_ref_addr
:
5695 result
= DW_ADDR (attr
);
5701 case DW_FORM_ref_udata
:
5702 result
= cu_header_offset
+ DW_UNSND (attr
);
5705 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5710 static struct die_info
*
5711 follow_die_ref (unsigned int offset
)
5713 struct die_info
*die
;
5716 h
= (offset
% REF_HASH_SIZE
);
5717 die
= die_ref_table
[h
];
5720 if (die
->offset
== offset
)
5724 die
= die
->next_ref
;
5729 static struct type
*
5730 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
5732 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5734 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5738 /* Look for this particular type in the fundamental type vector. If
5739 one is not found, create and install one appropriate for the
5740 current language and the current target machine. */
5742 if (ftypes
[typeid] == NULL
)
5744 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5747 return (ftypes
[typeid]);
5750 /* Decode simple location descriptions.
5751 Given a pointer to a dwarf block that defines a location, compute
5752 the location and return the value.
5754 FIXME: This is a kludge until we figure out a better
5755 way to handle the location descriptions.
5756 Gdb's design does not mesh well with the DWARF2 notion of a location
5757 computing interpreter, which is a shame because the flexibility goes unused.
5758 FIXME: Implement more operations as necessary.
5760 A location description containing no operations indicates that the
5761 object is optimized out. The global optimized_out flag is set for
5762 those, the return value is meaningless.
5764 When the result is a register number, the global isreg flag is set,
5765 otherwise it is cleared.
5767 When the result is a base register offset, the global offreg flag is set
5768 and the register number is returned in basereg, otherwise it is cleared.
5770 When the DW_OP_fbreg operation is encountered without a corresponding
5771 DW_AT_frame_base attribute, the global islocal flag is set.
5772 Hopefully the machine dependent code knows how to set up a virtual
5773 frame pointer for the local references.
5775 Note that stack[0] is unused except as a default error return.
5776 Note that stack overflow is not yet handled. */
5779 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
5780 const struct comp_unit_head
*cu_header
)
5783 int size
= blk
->size
;
5784 char *data
= blk
->data
;
5785 CORE_ADDR stack
[64];
5787 unsigned int bytes_read
, unsnd
;
5838 stack
[++stacki
] = op
- DW_OP_reg0
;
5843 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5845 #if defined(HARRIS_TARGET) && defined(_M88K)
5846 /* The Harris 88110 gdb ports have long kept their special reg
5847 numbers between their gp-regs and their x-regs. This is
5848 not how our dwarf is generated. Punt. */
5851 stack
[++stacki
] = unsnd
;
5887 basereg
= op
- DW_OP_breg0
;
5888 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5894 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5896 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5901 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5903 if (frame_base_reg
>= 0)
5906 basereg
= frame_base_reg
;
5907 stack
[stacki
] += frame_base_offset
;
5911 complain (&dwarf2_missing_at_frame_base
);
5917 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
5918 cu_header
, &bytes_read
);
5923 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5928 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5933 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5938 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5943 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5948 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5953 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5959 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5964 stack
[stacki
- 1] += stack
[stacki
];
5968 case DW_OP_plus_uconst
:
5969 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5974 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5980 /* If we're not the last op, then we definitely can't encode
5981 this using GDB's address_class enum. */
5983 complain (&dwarf2_complex_location_expr
);
5987 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
5988 return (stack
[stacki
]);
5991 return (stack
[stacki
]);
5994 /* memory allocation interface */
5998 dwarf2_free_tmp_obstack (PTR ignore
)
6000 obstack_free (&dwarf2_tmp_obstack
, NULL
);
6003 static struct dwarf_block
*
6004 dwarf_alloc_block (void)
6006 struct dwarf_block
*blk
;
6008 blk
= (struct dwarf_block
*)
6009 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
6013 static struct abbrev_info
*
6014 dwarf_alloc_abbrev (void)
6016 struct abbrev_info
*abbrev
;
6018 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
6019 memset (abbrev
, 0, sizeof (struct abbrev_info
));
6023 static struct die_info
*
6024 dwarf_alloc_die (void)
6026 struct die_info
*die
;
6028 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6029 memset (die
, 0, sizeof (struct die_info
));