1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
4 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
5 Inc. with support from Florida State University (under contract
6 with the Ada Joint Program Office), and Silicon Graphics, Inc.
7 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
8 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
11 This file is part of GDB.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or (at
16 your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. */
34 #include "elf/dwarf2.h"
37 #include "expression.h"
40 #include "complaints.h"
43 #include "gdb_string.h"
44 #include <sys/types.h>
47 /* .debug_info header for a compilation unit
48 Because of alignment constraints, this structure has padding and cannot
49 be mapped directly onto the beginning of the .debug_info section. */
50 typedef struct comp_unit_header
52 unsigned int length
; /* length of the .debug_info
54 unsigned short version
; /* version number -- 2 for DWARF
56 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
57 unsigned char addr_size
; /* byte size of an address -- 4 */
60 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
63 /* .debug_pubnames header
64 Because of alignment constraints, this structure has padding and cannot
65 be mapped directly onto the beginning of the .debug_info section. */
66 typedef struct pubnames_header
68 unsigned int length
; /* length of the .debug_pubnames
70 unsigned char version
; /* version number -- 2 for DWARF
72 unsigned int info_offset
; /* offset into .debug_info section */
73 unsigned int info_size
; /* byte size of .debug_info section
77 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
79 /* .debug_pubnames header
80 Because of alignment constraints, this structure has padding and cannot
81 be mapped directly onto the beginning of the .debug_info section. */
82 typedef struct aranges_header
84 unsigned int length
; /* byte len of the .debug_aranges
86 unsigned short version
; /* version number -- 2 for DWARF
88 unsigned int info_offset
; /* offset into .debug_info section */
89 unsigned char addr_size
; /* byte size of an address */
90 unsigned char seg_size
; /* byte size of segment descriptor */
93 #define _ACTUAL_ARANGES_HEADER_SIZE 12
95 /* .debug_line statement program prologue
96 Because of alignment constraints, this structure has padding and cannot
97 be mapped directly onto the beginning of the .debug_info section. */
98 typedef struct statement_prologue
100 unsigned int total_length
; /* byte length of the statement
102 unsigned short version
; /* version number -- 2 for DWARF
104 unsigned int prologue_length
; /* # bytes between prologue &
106 unsigned char minimum_instruction_length
; /* byte size of
108 unsigned char default_is_stmt
; /* initial value of is_stmt
111 unsigned char line_range
;
112 unsigned char opcode_base
; /* number assigned to first special
114 unsigned char *standard_opcode_lengths
;
118 /* offsets and sizes of debugging sections */
120 static file_ptr dwarf_info_offset
;
121 static file_ptr dwarf_abbrev_offset
;
122 static file_ptr dwarf_line_offset
;
123 static file_ptr dwarf_pubnames_offset
;
124 static file_ptr dwarf_aranges_offset
;
125 static file_ptr dwarf_loc_offset
;
126 static file_ptr dwarf_macinfo_offset
;
127 static file_ptr dwarf_str_offset
;
129 static unsigned int dwarf_info_size
;
130 static unsigned int dwarf_abbrev_size
;
131 static unsigned int dwarf_line_size
;
132 static unsigned int dwarf_pubnames_size
;
133 static unsigned int dwarf_aranges_size
;
134 static unsigned int dwarf_loc_size
;
135 static unsigned int dwarf_macinfo_size
;
136 static unsigned int dwarf_str_size
;
138 /* names of the debugging sections */
140 #define INFO_SECTION ".debug_info"
141 #define ABBREV_SECTION ".debug_abbrev"
142 #define LINE_SECTION ".debug_line"
143 #define PUBNAMES_SECTION ".debug_pubnames"
144 #define ARANGES_SECTION ".debug_aranges"
145 #define LOC_SECTION ".debug_loc"
146 #define MACINFO_SECTION ".debug_macinfo"
147 #define STR_SECTION ".debug_str"
149 /* local data types */
151 /* The data in a compilation unit header, after target2host
152 translation, looks like this. */
153 struct comp_unit_head
155 unsigned long length
;
157 unsigned int abbrev_offset
;
158 unsigned char addr_size
;
159 unsigned char signed_addr_p
;
160 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
161 unsigned int initial_length_size
; /* size of the length field; either
165 /* The data in the .debug_line statement prologue looks like this. */
168 unsigned int total_length
;
169 unsigned short version
;
170 unsigned int prologue_length
;
171 unsigned char minimum_instruction_length
;
172 unsigned char default_is_stmt
;
174 unsigned char line_range
;
175 unsigned char opcode_base
;
176 unsigned char *standard_opcode_lengths
;
179 /* When we construct a partial symbol table entry we only
180 need this much information. */
181 struct partial_die_info
184 unsigned char has_children
;
185 unsigned char is_external
;
186 unsigned char is_declaration
;
187 unsigned char has_type
;
193 struct dwarf_block
*locdesc
;
194 unsigned int language
;
198 /* This data structure holds the information of an abbrev. */
201 unsigned int number
; /* number identifying abbrev */
202 enum dwarf_tag tag
; /* dwarf tag */
203 int has_children
; /* boolean */
204 unsigned int num_attrs
; /* number of attributes */
205 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
206 struct abbrev_info
*next
; /* next in chain */
211 enum dwarf_attribute name
;
212 enum dwarf_form form
;
215 /* This data structure holds a complete die structure. */
218 enum dwarf_tag tag
; /* Tag indicating type of die */
219 unsigned short has_children
; /* Does the die have children */
220 unsigned int abbrev
; /* Abbrev number */
221 unsigned int offset
; /* Offset in .debug_info section */
222 unsigned int num_attrs
; /* Number of attributes */
223 struct attribute
*attrs
; /* An array of attributes */
224 struct die_info
*next_ref
; /* Next die in ref hash table */
225 struct die_info
*next
; /* Next die in linked list */
226 struct type
*type
; /* Cached type information */
229 /* Attributes have a name and a value */
232 enum dwarf_attribute name
;
233 enum dwarf_form form
;
237 struct dwarf_block
*blk
;
245 /* Get at parts of an attribute structure */
247 #define DW_STRING(attr) ((attr)->u.str)
248 #define DW_UNSND(attr) ((attr)->u.unsnd)
249 #define DW_BLOCK(attr) ((attr)->u.blk)
250 #define DW_SND(attr) ((attr)->u.snd)
251 #define DW_ADDR(attr) ((attr)->u.addr)
253 /* Blocks are a bunch of untyped bytes. */
260 /* We only hold one compilation unit's abbrevs in
261 memory at any one time. */
262 #ifndef ABBREV_HASH_SIZE
263 #define ABBREV_HASH_SIZE 121
265 #ifndef ATTR_ALLOC_CHUNK
266 #define ATTR_ALLOC_CHUNK 4
269 static struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
271 /* A hash table of die offsets for following references. */
272 #ifndef REF_HASH_SIZE
273 #define REF_HASH_SIZE 1021
276 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
278 #ifndef TYPE_HASH_SIZE
279 #define TYPE_HASH_SIZE 4096
281 static struct type
*dwarf2_cached_types
[TYPE_HASH_SIZE
];
283 /* Obstack for allocating temporary storage used during symbol reading. */
284 static struct obstack dwarf2_tmp_obstack
;
286 /* Offset to the first byte of the current compilation unit header,
287 for resolving relative reference dies. */
288 static unsigned int cu_header_offset
;
290 /* Allocate fields for structs, unions and enums in this size. */
291 #ifndef DW_FIELD_ALLOC_CHUNK
292 #define DW_FIELD_ALLOC_CHUNK 4
295 /* The language we are debugging. */
296 static enum language cu_language
;
297 static const struct language_defn
*cu_language_defn
;
299 /* Actually data from the sections. */
300 static char *dwarf_info_buffer
;
301 static char *dwarf_abbrev_buffer
;
302 static char *dwarf_line_buffer
;
304 /* A zeroed version of a partial die for initialization purposes. */
305 static struct partial_die_info zeroed_partial_die
;
307 /* The generic symbol table building routines have separate lists for
308 file scope symbols and all all other scopes (local scopes). So
309 we need to select the right one to pass to add_symbol_to_list().
310 We do it by keeping a pointer to the correct list in list_in_scope.
312 FIXME: The original dwarf code just treated the file scope as the first
313 local scope, and all other local scopes as nested local scopes, and worked
314 fine. Check to see if we really need to distinguish these
316 static struct pending
**list_in_scope
= &file_symbols
;
318 /* FIXME: decode_locdesc sets these variables to describe the location
319 to the caller. These ought to be a structure or something. If
320 none of the flags are set, the object lives at the address returned
321 by decode_locdesc. */
323 static int optimized_out
; /* No ops in location in expression,
324 so object was optimized out. */
325 static int isreg
; /* Object lives in register.
326 decode_locdesc's return value is
327 the register number. */
328 static int offreg
; /* Object's address is the sum of the
329 register specified by basereg, plus
330 the offset returned. */
331 static int basereg
; /* See `offreg'. */
332 static int isderef
; /* Value described by flags above is
333 the address of a pointer to the object. */
334 static int islocal
; /* Variable is at the returned offset
335 from the frame start, but there's
336 no identified frame pointer for
337 this function, so we can't say
338 which register it's relative to;
341 /* DW_AT_frame_base values for the current function.
342 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
343 contains the register number for the frame register.
344 frame_base_offset is the offset from the frame register to the
345 virtual stack frame. */
346 static int frame_base_reg
;
347 static CORE_ADDR frame_base_offset
;
349 /* This value is added to each symbol value. FIXME: Generalize to
350 the section_offsets structure used by dbxread (once this is done,
351 pass the appropriate section number to end_symtab). */
352 static CORE_ADDR baseaddr
; /* Add to each symbol value */
354 /* We put a pointer to this structure in the read_symtab_private field
356 The complete dwarf information for an objfile is kept in the
357 psymbol_obstack, so that absolute die references can be handled.
358 Most of the information in this structure is related to an entire
359 object file and could be passed via the sym_private field of the objfile.
360 It is however conceivable that dwarf2 might not be the only type
361 of symbols read from an object file. */
365 /* Pointer to start of dwarf info buffer for the objfile. */
367 char *dwarf_info_buffer
;
369 /* Offset in dwarf_info_buffer for this compilation unit. */
371 unsigned long dwarf_info_offset
;
373 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
375 char *dwarf_abbrev_buffer
;
377 /* Size of dwarf abbreviation section for the objfile. */
379 unsigned int dwarf_abbrev_size
;
381 /* Pointer to start of dwarf line buffer for the objfile. */
383 char *dwarf_line_buffer
;
386 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
387 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
388 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
389 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
390 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
391 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
393 /* Maintain an array of referenced fundamental types for the current
394 compilation unit being read. For DWARF version 1, we have to construct
395 the fundamental types on the fly, since no information about the
396 fundamental types is supplied. Each such fundamental type is created by
397 calling a language dependent routine to create the type, and then a
398 pointer to that type is then placed in the array at the index specified
399 by it's FT_<TYPENAME> value. The array has a fixed size set by the
400 FT_NUM_MEMBERS compile time constant, which is the number of predefined
401 fundamental types gdb knows how to construct. */
402 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
404 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
405 but this would require a corresponding change in unpack_field_as_long
407 static int bits_per_byte
= 8;
409 /* The routines that read and process dies for a C struct or C++ class
410 pass lists of data member fields and lists of member function fields
411 in an instance of a field_info structure, as defined below. */
414 /* List of data member and baseclasses fields. */
417 struct nextfield
*next
;
424 /* Number of fields. */
427 /* Number of baseclasses. */
430 /* Set if the accesibility of one of the fields is not public. */
431 int non_public_fields
;
433 /* Member function fields array, entries are allocated in the order they
434 are encountered in the object file. */
437 struct nextfnfield
*next
;
438 struct fn_field fnfield
;
442 /* Member function fieldlist array, contains name of possibly overloaded
443 member function, number of overloaded member functions and a pointer
444 to the head of the member function field chain. */
449 struct nextfnfield
*head
;
453 /* Number of entries in the fnfieldlists array. */
457 /* FIXME: Kludge to mark a varargs function type for C++ member function
458 argument processing. */
459 #define TYPE_FLAG_VARARGS (1 << 10)
461 /* Dwarf2 has no clean way to discern C++ static and non-static member
462 functions. G++ helps GDB by marking the first parameter for non-static
463 member functions (which is the this pointer) as artificial.
464 We pass this information between dwarf2_add_member_fn and
465 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
466 #define TYPE_FIELD_ARTIFICIAL TYPE_FIELD_BITPOS
468 /* Various complaints about symbol reading that don't abort the process */
470 static struct complaint dwarf2_const_ignored
=
472 "type qualifier 'const' ignored", 0, 0
474 static struct complaint dwarf2_volatile_ignored
=
476 "type qualifier 'volatile' ignored", 0, 0
478 static struct complaint dwarf2_non_const_array_bound_ignored
=
480 "non-constant array bounds form '%s' ignored", 0, 0
482 static struct complaint dwarf2_missing_line_number_section
=
484 "missing .debug_line section", 0, 0
486 static struct complaint dwarf2_mangled_line_number_section
=
488 "mangled .debug_line section", 0, 0
490 static struct complaint dwarf2_unsupported_die_ref_attr
=
492 "unsupported die ref attribute form: '%s'", 0, 0
494 static struct complaint dwarf2_unsupported_stack_op
=
496 "unsupported stack op: '%s'", 0, 0
498 static struct complaint dwarf2_complex_location_expr
=
500 "location expression too complex", 0, 0
502 static struct complaint dwarf2_unsupported_tag
=
504 "unsupported tag: '%s'", 0, 0
506 static struct complaint dwarf2_unsupported_at_encoding
=
508 "unsupported DW_AT_encoding: '%s'", 0, 0
510 static struct complaint dwarf2_unsupported_at_frame_base
=
512 "unsupported DW_AT_frame_base for function '%s'", 0, 0
514 static struct complaint dwarf2_unexpected_tag
=
516 "unexepected tag in read_type_die: '%s'", 0, 0
518 static struct complaint dwarf2_missing_at_frame_base
=
520 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
522 static struct complaint dwarf2_bad_static_member_name
=
524 "unrecognized static data member name '%s'", 0, 0
526 static struct complaint dwarf2_unsupported_accessibility
=
528 "unsupported accessibility %d", 0, 0
530 static struct complaint dwarf2_bad_member_name_complaint
=
532 "cannot extract member name from '%s'", 0, 0
534 static struct complaint dwarf2_missing_member_fn_type_complaint
=
536 "member function type missing for '%s'", 0, 0
538 static struct complaint dwarf2_vtbl_not_found_complaint
=
540 "virtual function table pointer not found when defining class '%s'", 0, 0
542 static struct complaint dwarf2_absolute_sibling_complaint
=
544 "ignoring absolute DW_AT_sibling", 0, 0
546 static struct complaint dwarf2_const_value_length_mismatch
=
548 "const value length mismatch for '%s', got %d, expected %d", 0, 0
550 static struct complaint dwarf2_unsupported_const_value_attr
=
552 "unsupported const value attribute form: '%s'", 0, 0
555 /* Externals references. */
556 extern int info_verbose
; /* From main.c; nonzero => verbose */
558 /* local function prototypes */
560 static void dwarf2_locate_sections (bfd
*, asection
*, PTR
);
563 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
566 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
568 static char *scan_partial_symbols (char *, struct objfile
*,
569 CORE_ADDR
*, CORE_ADDR
*,
570 const struct comp_unit_head
*);
572 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
573 const struct comp_unit_head
*);
575 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
577 static void psymtab_to_symtab_1 (struct partial_symtab
*);
579 static char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int);
581 static void dwarf2_read_abbrevs (bfd
*, unsigned int);
583 static void dwarf2_empty_abbrev_table (PTR
);
585 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int);
587 static char *read_partial_die (struct partial_die_info
*,
588 bfd
*, char *, int *,
589 const struct comp_unit_head
*);
591 static char *read_full_die (struct die_info
**, bfd
*, char *,
592 const struct comp_unit_head
*);
594 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
595 bfd
*, char *, const struct comp_unit_head
*);
597 static unsigned int read_1_byte (bfd
*, char *);
599 static int read_1_signed_byte (bfd
*, char *);
601 static unsigned int read_2_bytes (bfd
*, char *);
603 static unsigned int read_4_bytes (bfd
*, char *);
605 static unsigned long read_8_bytes (bfd
*, char *);
607 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
610 static LONGEST
read_initial_length (bfd
*, char *,
611 struct comp_unit_head
*, int *bytes_read
);
613 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
616 static char *read_n_bytes (bfd
*, char *, unsigned int);
618 static char *read_string (bfd
*, char *, unsigned int *);
620 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
622 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
624 static void set_cu_language (unsigned int);
626 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
628 static int die_is_declaration (struct die_info
*);
630 static void dwarf_decode_lines (unsigned int, char *, bfd
*,
631 const struct comp_unit_head
*);
633 static void dwarf2_start_subfile (char *, char *);
635 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
636 struct objfile
*, const struct comp_unit_head
*);
638 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
639 struct objfile
*, const struct comp_unit_head
*);
641 static void dwarf2_const_value_data (struct attribute
*attr
,
645 static struct type
*die_type (struct die_info
*, struct objfile
*,
646 const struct comp_unit_head
*);
648 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
649 const struct comp_unit_head
*);
652 static struct type
*type_at_offset (unsigned int, struct objfile
*);
655 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
656 const struct comp_unit_head
*);
658 static void read_type_die (struct die_info
*, struct objfile
*,
659 const struct comp_unit_head
*);
661 static void read_typedef (struct die_info
*, struct objfile
*,
662 const struct comp_unit_head
*);
664 static void read_base_type (struct die_info
*, struct objfile
*);
666 static void read_file_scope (struct die_info
*, struct objfile
*,
667 const struct comp_unit_head
*);
669 static void read_func_scope (struct die_info
*, struct objfile
*,
670 const struct comp_unit_head
*);
672 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
673 const struct comp_unit_head
*);
675 static int dwarf2_get_pc_bounds (struct die_info
*,
676 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*);
678 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
679 struct objfile
*, const struct comp_unit_head
*);
681 static void dwarf2_attach_fields_to_type (struct field_info
*,
682 struct type
*, struct objfile
*);
684 static void dwarf2_add_member_fn (struct field_info
*,
685 struct die_info
*, struct type
*,
686 struct objfile
*objfile
,
687 const struct comp_unit_head
*);
689 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
690 struct type
*, struct objfile
*);
692 static void read_structure_scope (struct die_info
*, struct objfile
*,
693 const struct comp_unit_head
*);
695 static void read_common_block (struct die_info
*, struct objfile
*,
696 const struct comp_unit_head
*);
698 static void read_enumeration (struct die_info
*, struct objfile
*,
699 const struct comp_unit_head
*);
701 static struct type
*dwarf_base_type (int, int, struct objfile
*);
703 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
704 const struct comp_unit_head
*);
706 static void read_array_type (struct die_info
*, struct objfile
*,
707 const struct comp_unit_head
*);
709 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
710 const struct comp_unit_head
*);
712 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
713 const struct comp_unit_head
*);
715 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
716 const struct comp_unit_head
*);
718 static void read_tag_const_type (struct die_info
*, struct objfile
*,
719 const struct comp_unit_head
*);
721 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
722 const struct comp_unit_head
*);
724 static void read_tag_string_type (struct die_info
*, struct objfile
*);
726 static void read_subroutine_type (struct die_info
*, struct objfile
*,
727 const struct comp_unit_head
*);
729 struct die_info
*read_comp_unit (char *, bfd
*, const struct comp_unit_head
*);
731 static void free_die_list (struct die_info
*);
733 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
735 static void process_die (struct die_info
*, struct objfile
*,
736 const struct comp_unit_head
*);
738 static char *dwarf2_linkage_name (struct die_info
*);
740 static char *dwarf_tag_name (unsigned int);
742 static char *dwarf_attr_name (unsigned int);
744 static char *dwarf_form_name (unsigned int);
746 static char *dwarf_stack_op_name (unsigned int);
748 static char *dwarf_bool_name (unsigned int);
750 static char *dwarf_type_encoding_name (unsigned int);
753 static char *dwarf_cfi_name (unsigned int);
755 struct die_info
*copy_die (struct die_info
*);
758 struct die_info
*sibling_die (struct die_info
*);
760 void dump_die (struct die_info
*);
762 void dump_die_list (struct die_info
*);
764 void store_in_ref_table (unsigned int, struct die_info
*);
766 static void dwarf2_empty_hash_tables (void);
768 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
770 struct die_info
*follow_die_ref (unsigned int);
772 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
774 /* memory allocation interface */
776 static void dwarf2_free_tmp_obstack (PTR
);
778 static struct dwarf_block
*dwarf_alloc_block (void);
780 static struct abbrev_info
*dwarf_alloc_abbrev (void);
782 static struct die_info
*dwarf_alloc_die (void);
784 /* Try to locate the sections we need for DWARF 2 debugging
785 information and return true if we have enough to do something. */
788 dwarf2_has_info (bfd
*abfd
)
790 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
791 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
792 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
802 /* This function is mapped across the sections and remembers the
803 offset and size of each of the debugging sections we are interested
807 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, PTR ignore_ptr
)
809 if (STREQ (sectp
->name
, INFO_SECTION
))
811 dwarf_info_offset
= sectp
->filepos
;
812 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
814 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
816 dwarf_abbrev_offset
= sectp
->filepos
;
817 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
819 else if (STREQ (sectp
->name
, LINE_SECTION
))
821 dwarf_line_offset
= sectp
->filepos
;
822 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
824 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
826 dwarf_pubnames_offset
= sectp
->filepos
;
827 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
829 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
831 dwarf_aranges_offset
= sectp
->filepos
;
832 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
834 else if (STREQ (sectp
->name
, LOC_SECTION
))
836 dwarf_loc_offset
= sectp
->filepos
;
837 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
839 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
841 dwarf_macinfo_offset
= sectp
->filepos
;
842 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
844 else if (STREQ (sectp
->name
, STR_SECTION
))
846 dwarf_str_offset
= sectp
->filepos
;
847 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
851 /* Build a partial symbol table. */
854 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
857 /* We definitely need the .debug_info and .debug_abbrev sections */
859 dwarf_info_buffer
= dwarf2_read_section (objfile
,
862 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
865 dwarf_line_buffer
= dwarf2_read_section (objfile
,
869 if (mainline
|| objfile
->global_psymbols
.size
== 0 ||
870 objfile
->static_psymbols
.size
== 0)
872 init_psymbol_list (objfile
, 1024);
876 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
878 /* Things are significantly easier if we have .debug_aranges and
879 .debug_pubnames sections */
881 dwarf2_build_psymtabs_easy (objfile
, mainline
);
885 /* only test this case for now */
887 /* In this case we have to work a bit harder */
888 dwarf2_build_psymtabs_hard (objfile
, mainline
);
893 /* Build the partial symbol table from the information in the
894 .debug_pubnames and .debug_aranges sections. */
897 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
899 bfd
*abfd
= objfile
->obfd
;
900 char *aranges_buffer
, *pubnames_buffer
;
901 char *aranges_ptr
, *pubnames_ptr
;
902 unsigned int entry_length
, version
, info_offset
, info_size
;
904 pubnames_buffer
= dwarf2_read_section (objfile
,
905 dwarf_pubnames_offset
,
906 dwarf_pubnames_size
);
907 pubnames_ptr
= pubnames_buffer
;
908 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
910 struct comp_unit_head cu_header
;
913 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
915 pubnames_ptr
+= bytes_read
;
916 version
= read_1_byte (abfd
, pubnames_ptr
);
918 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
920 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
924 aranges_buffer
= dwarf2_read_section (objfile
,
925 dwarf_aranges_offset
,
931 /* Read in the comp unit header information from the debug_info at
935 read_comp_unit_head (struct comp_unit_head
*cu_header
,
936 char *info_ptr
, bfd
*abfd
)
940 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
942 info_ptr
+= bytes_read
;
943 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
945 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
947 info_ptr
+= bytes_read
;
948 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
950 signed_addr
= bfd_get_sign_extend_vma (abfd
);
952 internal_error ("read_comp_unit_head: dwarf from non elf file");
953 cu_header
->signed_addr_p
= signed_addr
;
957 /* Build the partial symbol table by doing a quick pass through the
958 .debug_info and .debug_abbrev sections. */
961 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
963 /* Instead of reading this into a big buffer, we should probably use
964 mmap() on architectures that support it. (FIXME) */
965 bfd
*abfd
= objfile
->obfd
;
966 char *info_ptr
, *abbrev_ptr
;
967 char *beg_of_comp_unit
;
968 struct partial_die_info comp_unit_die
;
969 struct partial_symtab
*pst
;
970 struct cleanup
*back_to
;
971 int comp_unit_has_pc_info
;
972 CORE_ADDR lowpc
, highpc
;
974 info_ptr
= dwarf_info_buffer
;
975 abbrev_ptr
= dwarf_abbrev_buffer
;
977 obstack_init (&dwarf2_tmp_obstack
);
978 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
980 while ((unsigned int) (info_ptr
- dwarf_info_buffer
)
981 + ((info_ptr
- dwarf_info_buffer
) % 4) < dwarf_info_size
)
983 struct comp_unit_head cu_header
;
984 beg_of_comp_unit
= info_ptr
;
985 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
987 if (cu_header
.version
!= 2)
989 error ("Dwarf Error: wrong version in compilation unit header.");
992 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
994 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
995 (long) cu_header
.abbrev_offset
,
996 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
999 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1000 > dwarf_info_buffer
+ dwarf_info_size
)
1002 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
1003 (long) cu_header
.length
,
1004 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1007 /* Read the abbrevs for this compilation unit into a table */
1008 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1009 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1011 /* Read the compilation unit die */
1012 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1013 &comp_unit_has_pc_info
, &cu_header
);
1015 /* Set the language we're debugging */
1016 set_cu_language (comp_unit_die
.language
);
1018 /* Allocate a new partial symbol table structure */
1019 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1020 comp_unit_die
.name
? comp_unit_die
.name
: "",
1021 comp_unit_die
.lowpc
,
1022 objfile
->global_psymbols
.next
,
1023 objfile
->static_psymbols
.next
);
1025 pst
->read_symtab_private
= (char *)
1026 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1027 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1028 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1029 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1030 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1031 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1032 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1033 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1035 /* Store the function that reads in the rest of the symbol table */
1036 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1038 /* Check if comp unit has_children.
1039 If so, read the rest of the partial symbols from this comp unit.
1040 If not, there's no more debug_info for this comp unit. */
1041 if (comp_unit_die
.has_children
)
1043 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1046 /* If the compilation unit didn't have an explicit address range,
1047 then use the information extracted from its child dies. */
1048 if (!comp_unit_has_pc_info
)
1050 comp_unit_die
.lowpc
= lowpc
;
1051 comp_unit_die
.highpc
= highpc
;
1054 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1055 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1057 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1058 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1059 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1060 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1061 sort_pst_symbols (pst
);
1063 /* If there is already a psymtab or symtab for a file of this
1064 name, remove it. (If there is a symtab, more drastic things
1065 also happen.) This happens in VxWorks. */
1066 free_named_symtabs (pst
->filename
);
1068 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1069 + cu_header
.initial_length_size
;
1071 do_cleanups (back_to
);
1074 /* Read in all interesting dies to the end of the compilation unit. */
1077 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1078 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1079 const struct comp_unit_head
*cu_header
)
1081 bfd
*abfd
= objfile
->obfd
;
1082 struct partial_die_info pdi
;
1084 /* This function is called after we've read in the comp_unit_die in
1085 order to read its children. We start the nesting level at 1 since
1086 we have pushed 1 level down in order to read the comp unit's children.
1087 The comp unit itself is at level 0, so we stop reading when we pop
1088 back to that level. */
1090 int nesting_level
= 1;
1093 *lowpc
= ((CORE_ADDR
) -1);
1094 *highpc
= ((CORE_ADDR
) 0);
1096 while (nesting_level
)
1098 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
,
1099 &has_pc_info
, cu_header
);
1105 case DW_TAG_subprogram
:
1108 if (pdi
.lowpc
< *lowpc
)
1112 if (pdi
.highpc
> *highpc
)
1114 *highpc
= pdi
.highpc
;
1116 if ((pdi
.is_external
|| nesting_level
== 1)
1117 && !pdi
.is_declaration
)
1119 add_partial_symbol (&pdi
, objfile
, cu_header
);
1123 case DW_TAG_variable
:
1124 case DW_TAG_typedef
:
1125 case DW_TAG_class_type
:
1126 case DW_TAG_structure_type
:
1127 case DW_TAG_union_type
:
1128 case DW_TAG_enumeration_type
:
1129 if ((pdi
.is_external
|| nesting_level
== 1)
1130 && !pdi
.is_declaration
)
1132 add_partial_symbol (&pdi
, objfile
, cu_header
);
1135 case DW_TAG_enumerator
:
1136 /* File scope enumerators are added to the partial symbol
1138 if (nesting_level
== 2)
1139 add_partial_symbol (&pdi
, objfile
, cu_header
);
1141 case DW_TAG_base_type
:
1142 /* File scope base type definitions are added to the partial
1144 if (nesting_level
== 1)
1145 add_partial_symbol (&pdi
, objfile
, cu_header
);
1152 /* If the die has a sibling, skip to the sibling.
1153 Do not skip enumeration types, we want to record their
1155 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1157 info_ptr
= pdi
.sibling
;
1159 else if (pdi
.has_children
)
1161 /* Die has children, but the optional DW_AT_sibling attribute
1172 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1173 from `maint check'. */
1174 if (*lowpc
== ((CORE_ADDR
) -1))
1180 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1181 const struct comp_unit_head
*cu_header
)
1187 case DW_TAG_subprogram
:
1188 if (pdi
->is_external
)
1190 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1191 mst_text, objfile); */
1192 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1193 VAR_NAMESPACE
, LOC_BLOCK
,
1194 &objfile
->global_psymbols
,
1195 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1199 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1200 mst_file_text, objfile); */
1201 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1202 VAR_NAMESPACE
, LOC_BLOCK
,
1203 &objfile
->static_psymbols
,
1204 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1207 case DW_TAG_variable
:
1208 if (pdi
->is_external
)
1211 Don't enter into the minimal symbol tables as there is
1212 a minimal symbol table entry from the ELF symbols already.
1213 Enter into partial symbol table if it has a location
1214 descriptor or a type.
1215 If the location descriptor is missing, new_symbol will create
1216 a LOC_UNRESOLVED symbol, the address of the variable will then
1217 be determined from the minimal symbol table whenever the variable
1219 The address for the partial symbol table entry is not
1220 used by GDB, but it comes in handy for debugging partial symbol
1224 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1225 if (pdi
->locdesc
|| pdi
->has_type
)
1226 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1227 VAR_NAMESPACE
, LOC_STATIC
,
1228 &objfile
->global_psymbols
,
1229 0, addr
+ baseaddr
, cu_language
, objfile
);
1233 /* Static Variable. Skip symbols without location descriptors. */
1234 if (pdi
->locdesc
== NULL
)
1236 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1237 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1238 mst_file_data, objfile); */
1239 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1240 VAR_NAMESPACE
, LOC_STATIC
,
1241 &objfile
->static_psymbols
,
1242 0, addr
+ baseaddr
, cu_language
, objfile
);
1245 case DW_TAG_typedef
:
1246 case DW_TAG_base_type
:
1247 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1248 VAR_NAMESPACE
, LOC_TYPEDEF
,
1249 &objfile
->static_psymbols
,
1250 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1252 case DW_TAG_class_type
:
1253 case DW_TAG_structure_type
:
1254 case DW_TAG_union_type
:
1255 case DW_TAG_enumeration_type
:
1256 /* Skip aggregate types without children, these are external
1258 if (pdi
->has_children
== 0)
1260 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1261 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1262 &objfile
->static_psymbols
,
1263 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1265 if (cu_language
== language_cplus
)
1267 /* For C++, these implicitly act as typedefs as well. */
1268 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1269 VAR_NAMESPACE
, LOC_TYPEDEF
,
1270 &objfile
->static_psymbols
,
1271 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1274 case DW_TAG_enumerator
:
1275 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1276 VAR_NAMESPACE
, LOC_CONST
,
1277 &objfile
->static_psymbols
,
1278 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1285 /* Expand this partial symbol table into a full symbol table. */
1288 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1290 /* FIXME: This is barely more than a stub. */
1295 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1301 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1302 gdb_flush (gdb_stdout
);
1305 psymtab_to_symtab_1 (pst
);
1307 /* Finish up the debug error message. */
1309 printf_filtered ("done.\n");
1315 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1317 struct objfile
*objfile
= pst
->objfile
;
1318 bfd
*abfd
= objfile
->obfd
;
1319 struct comp_unit_head cu_header
;
1320 struct die_info
*dies
;
1321 unsigned long offset
;
1322 CORE_ADDR lowpc
, highpc
;
1323 struct die_info
*child_die
;
1325 struct symtab
*symtab
;
1326 struct cleanup
*back_to
;
1328 /* Set local variables from the partial symbol table info. */
1329 offset
= DWARF_INFO_OFFSET (pst
);
1330 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1331 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1332 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1333 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1334 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1335 cu_header_offset
= offset
;
1336 info_ptr
= dwarf_info_buffer
+ offset
;
1338 obstack_init (&dwarf2_tmp_obstack
);
1339 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1342 make_cleanup (really_free_pendings
, NULL
);
1344 /* read in the comp_unit header */
1345 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1347 /* Read the abbrevs for this compilation unit */
1348 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1349 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1351 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1353 make_cleanup_free_die_list (dies
);
1355 /* Do line number decoding in read_file_scope () */
1356 process_die (dies
, objfile
, &cu_header
);
1358 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1360 /* Some compilers don't define a DW_AT_high_pc attribute for
1361 the compilation unit. If the DW_AT_high_pc is missing,
1362 synthesize it, by scanning the DIE's below the compilation unit. */
1364 if (dies
->has_children
)
1366 child_die
= dies
->next
;
1367 while (child_die
&& child_die
->tag
)
1369 if (child_die
->tag
== DW_TAG_subprogram
)
1371 CORE_ADDR low
, high
;
1373 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1375 highpc
= max (highpc
, high
);
1378 child_die
= sibling_die (child_die
);
1382 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1384 /* Set symtab language to language from DW_AT_language.
1385 If the compilation is from a C file generated by language preprocessors,
1386 do not set the language if it was already deduced by start_subfile. */
1388 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1390 symtab
->language
= cu_language
;
1392 pst
->symtab
= symtab
;
1394 sort_symtab_syms (pst
->symtab
);
1396 do_cleanups (back_to
);
1399 /* Process a die and its children. */
1402 process_die (struct die_info
*die
, struct objfile
*objfile
,
1403 const struct comp_unit_head
*cu_header
)
1407 case DW_TAG_padding
:
1409 case DW_TAG_compile_unit
:
1410 read_file_scope (die
, objfile
, cu_header
);
1412 case DW_TAG_subprogram
:
1413 read_subroutine_type (die
, objfile
, cu_header
);
1414 read_func_scope (die
, objfile
, cu_header
);
1416 case DW_TAG_inlined_subroutine
:
1417 /* FIXME: These are ignored for now.
1418 They could be used to set breakpoints on all inlined instances
1419 of a function and make GDB `next' properly over inlined functions. */
1421 case DW_TAG_lexical_block
:
1422 read_lexical_block_scope (die
, objfile
, cu_header
);
1424 case DW_TAG_class_type
:
1425 case DW_TAG_structure_type
:
1426 case DW_TAG_union_type
:
1427 read_structure_scope (die
, objfile
, cu_header
);
1429 case DW_TAG_enumeration_type
:
1430 read_enumeration (die
, objfile
, cu_header
);
1432 case DW_TAG_subroutine_type
:
1433 read_subroutine_type (die
, objfile
, cu_header
);
1435 case DW_TAG_array_type
:
1436 read_array_type (die
, objfile
, cu_header
);
1438 case DW_TAG_pointer_type
:
1439 read_tag_pointer_type (die
, objfile
, cu_header
);
1441 case DW_TAG_ptr_to_member_type
:
1442 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1444 case DW_TAG_reference_type
:
1445 read_tag_reference_type (die
, objfile
, cu_header
);
1447 case DW_TAG_string_type
:
1448 read_tag_string_type (die
, objfile
);
1450 case DW_TAG_base_type
:
1451 read_base_type (die
, objfile
);
1452 if (dwarf_attr (die
, DW_AT_name
))
1454 /* Add a typedef symbol for the base type definition. */
1455 new_symbol (die
, die
->type
, objfile
, cu_header
);
1458 case DW_TAG_common_block
:
1459 read_common_block (die
, objfile
, cu_header
);
1461 case DW_TAG_common_inclusion
:
1464 new_symbol (die
, NULL
, objfile
, cu_header
);
1470 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1471 const struct comp_unit_head
*cu_header
)
1473 unsigned int line_offset
= 0;
1474 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1475 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1476 struct attribute
*attr
;
1477 char *name
= "<unknown>";
1478 char *comp_dir
= NULL
;
1479 struct die_info
*child_die
;
1480 bfd
*abfd
= objfile
->obfd
;
1482 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1484 if (die
->has_children
)
1486 child_die
= die
->next
;
1487 while (child_die
&& child_die
->tag
)
1489 if (child_die
->tag
== DW_TAG_subprogram
)
1491 CORE_ADDR low
, high
;
1493 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1495 lowpc
= min (lowpc
, low
);
1496 highpc
= max (highpc
, high
);
1499 child_die
= sibling_die (child_die
);
1504 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1505 from finish_block. */
1506 if (lowpc
== ((CORE_ADDR
) -1))
1511 attr
= dwarf_attr (die
, DW_AT_name
);
1514 name
= DW_STRING (attr
);
1516 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1519 comp_dir
= DW_STRING (attr
);
1522 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1523 directory, get rid of it. */
1524 char *cp
= strchr (comp_dir
, ':');
1526 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1531 if (objfile
->ei
.entry_point
>= lowpc
&&
1532 objfile
->ei
.entry_point
< highpc
)
1534 objfile
->ei
.entry_file_lowpc
= lowpc
;
1535 objfile
->ei
.entry_file_highpc
= highpc
;
1538 attr
= dwarf_attr (die
, DW_AT_language
);
1541 set_cu_language (DW_UNSND (attr
));
1544 /* We assume that we're processing GCC output. */
1545 processing_gcc_compilation
= 2;
1547 /* FIXME:Do something here. */
1548 if (dip
->at_producer
!= NULL
)
1550 handle_producer (dip
->at_producer
);
1554 /* The compilation unit may be in a different language or objfile,
1555 zero out all remembered fundamental types. */
1556 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1558 start_symtab (name
, comp_dir
, lowpc
);
1559 record_debugformat ("DWARF 2");
1561 /* Decode line number information if present. */
1562 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1565 line_offset
= DW_UNSND (attr
);
1566 dwarf_decode_lines (line_offset
, comp_dir
, abfd
, cu_header
);
1569 /* Process all dies in compilation unit. */
1570 if (die
->has_children
)
1572 child_die
= die
->next
;
1573 while (child_die
&& child_die
->tag
)
1575 process_die (child_die
, objfile
, cu_header
);
1576 child_die
= sibling_die (child_die
);
1582 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
1583 const struct comp_unit_head
*cu_header
)
1585 register struct context_stack
*new;
1588 struct die_info
*child_die
;
1589 struct attribute
*attr
;
1592 name
= dwarf2_linkage_name (die
);
1594 /* Ignore functions with missing or empty names and functions with
1595 missing or invalid low and high pc attributes. */
1596 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1602 if (objfile
->ei
.entry_point
>= lowpc
&&
1603 objfile
->ei
.entry_point
< highpc
)
1605 objfile
->ei
.entry_func_lowpc
= lowpc
;
1606 objfile
->ei
.entry_func_highpc
= highpc
;
1609 /* Decode DW_AT_frame_base location descriptor if present, keep result
1610 for DW_OP_fbreg operands in decode_locdesc. */
1611 frame_base_reg
= -1;
1612 frame_base_offset
= 0;
1613 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1616 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
1618 complain (&dwarf2_unsupported_at_frame_base
, name
);
1620 frame_base_reg
= addr
;
1623 frame_base_reg
= basereg
;
1624 frame_base_offset
= addr
;
1627 complain (&dwarf2_unsupported_at_frame_base
, name
);
1630 new = push_context (0, lowpc
);
1631 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
1632 list_in_scope
= &local_symbols
;
1634 if (die
->has_children
)
1636 child_die
= die
->next
;
1637 while (child_die
&& child_die
->tag
)
1639 process_die (child_die
, objfile
, cu_header
);
1640 child_die
= sibling_die (child_die
);
1644 new = pop_context ();
1645 /* Make a block for the local symbols within. */
1646 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1647 lowpc
, highpc
, objfile
);
1648 list_in_scope
= &file_symbols
;
1651 /* Process all the DIES contained within a lexical block scope. Start
1652 a new scope, process the dies, and then close the scope. */
1655 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
1656 const struct comp_unit_head
*cu_header
)
1658 register struct context_stack
*new;
1659 CORE_ADDR lowpc
, highpc
;
1660 struct die_info
*child_die
;
1662 /* Ignore blocks with missing or invalid low and high pc attributes. */
1663 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1668 push_context (0, lowpc
);
1669 if (die
->has_children
)
1671 child_die
= die
->next
;
1672 while (child_die
&& child_die
->tag
)
1674 process_die (child_die
, objfile
, cu_header
);
1675 child_die
= sibling_die (child_die
);
1678 new = pop_context ();
1680 if (local_symbols
!= NULL
)
1682 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1685 local_symbols
= new->locals
;
1688 /* Get low and high pc attributes from a die.
1689 Return 1 if the attributes are present and valid, otherwise, return 0. */
1692 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1693 struct objfile
*objfile
)
1695 struct attribute
*attr
;
1699 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1701 low
= DW_ADDR (attr
);
1704 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1706 high
= DW_ADDR (attr
);
1713 /* When using the GNU linker, .gnu.linkonce. sections are used to
1714 eliminate duplicate copies of functions and vtables and such.
1715 The linker will arbitrarily choose one and discard the others.
1716 The AT_*_pc values for such functions refer to local labels in
1717 these sections. If the section from that file was discarded, the
1718 labels are not in the output, so the relocs get a value of 0.
1719 If this is a discarded function, mark the pc bounds as invalid,
1720 so that GDB will ignore it. */
1721 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1729 /* Add an aggregate field to the field list. */
1732 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
1733 struct objfile
*objfile
,
1734 const struct comp_unit_head
*cu_header
)
1736 struct nextfield
*new_field
;
1737 struct attribute
*attr
;
1739 char *fieldname
= "";
1741 /* Allocate a new field list entry and link it in. */
1742 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1743 make_cleanup (free
, new_field
);
1744 memset (new_field
, 0, sizeof (struct nextfield
));
1745 new_field
->next
= fip
->fields
;
1746 fip
->fields
= new_field
;
1749 /* Handle accessibility and virtuality of field.
1750 The default accessibility for members is public, the default
1751 accessibility for inheritance is private. */
1752 if (die
->tag
!= DW_TAG_inheritance
)
1753 new_field
->accessibility
= DW_ACCESS_public
;
1755 new_field
->accessibility
= DW_ACCESS_private
;
1756 new_field
->virtuality
= DW_VIRTUALITY_none
;
1758 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1760 new_field
->accessibility
= DW_UNSND (attr
);
1761 if (new_field
->accessibility
!= DW_ACCESS_public
)
1762 fip
->non_public_fields
= 1;
1763 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1765 new_field
->virtuality
= DW_UNSND (attr
);
1767 fp
= &new_field
->field
;
1768 if (die
->tag
== DW_TAG_member
)
1770 /* Get type of field. */
1771 fp
->type
= die_type (die
, objfile
, cu_header
);
1773 /* Get bit size of field (zero if none). */
1774 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1777 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1781 FIELD_BITSIZE (*fp
) = 0;
1784 /* Get bit offset of field. */
1785 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1788 FIELD_BITPOS (*fp
) =
1789 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
1792 FIELD_BITPOS (*fp
) = 0;
1793 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1796 if (BITS_BIG_ENDIAN
)
1798 /* For big endian bits, the DW_AT_bit_offset gives the
1799 additional bit offset from the MSB of the containing
1800 anonymous object to the MSB of the field. We don't
1801 have to do anything special since we don't need to
1802 know the size of the anonymous object. */
1803 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1807 /* For little endian bits, compute the bit offset to the
1808 MSB of the anonymous object, subtract off the number of
1809 bits from the MSB of the field to the MSB of the
1810 object, and then subtract off the number of bits of
1811 the field itself. The result is the bit offset of
1812 the LSB of the field. */
1814 int bit_offset
= DW_UNSND (attr
);
1816 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1819 /* The size of the anonymous object containing
1820 the bit field is explicit, so use the
1821 indicated size (in bytes). */
1822 anonymous_size
= DW_UNSND (attr
);
1826 /* The size of the anonymous object containing
1827 the bit field must be inferred from the type
1828 attribute of the data member containing the
1830 anonymous_size
= TYPE_LENGTH (fp
->type
);
1832 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1833 - bit_offset
- FIELD_BITSIZE (*fp
);
1837 /* Get name of field. */
1838 attr
= dwarf_attr (die
, DW_AT_name
);
1839 if (attr
&& DW_STRING (attr
))
1840 fieldname
= DW_STRING (attr
);
1841 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1842 &objfile
->type_obstack
);
1844 /* Change accessibility for artificial fields (e.g. virtual table
1845 pointer or virtual base class pointer) to private. */
1846 if (dwarf_attr (die
, DW_AT_artificial
))
1848 new_field
->accessibility
= DW_ACCESS_private
;
1849 fip
->non_public_fields
= 1;
1852 else if (die
->tag
== DW_TAG_variable
)
1856 /* C++ static member.
1857 Get name of field. */
1858 attr
= dwarf_attr (die
, DW_AT_name
);
1859 if (attr
&& DW_STRING (attr
))
1860 fieldname
= DW_STRING (attr
);
1864 /* Get physical name. */
1865 physname
= dwarf2_linkage_name (die
);
1867 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1868 &objfile
->type_obstack
));
1869 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1870 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1871 &objfile
->type_obstack
);
1873 else if (die
->tag
== DW_TAG_inheritance
)
1875 /* C++ base class field. */
1876 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1878 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
1880 FIELD_BITSIZE (*fp
) = 0;
1881 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1882 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1883 fip
->nbaseclasses
++;
1887 /* Create the vector of fields, and attach it to the type. */
1890 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
1891 struct objfile
*objfile
)
1893 int nfields
= fip
->nfields
;
1895 /* Record the field count, allocate space for the array of fields,
1896 and create blank accessibility bitfields if necessary. */
1897 TYPE_NFIELDS (type
) = nfields
;
1898 TYPE_FIELDS (type
) = (struct field
*)
1899 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1900 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1902 if (fip
->non_public_fields
)
1904 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1906 TYPE_FIELD_PRIVATE_BITS (type
) =
1907 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1908 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1910 TYPE_FIELD_PROTECTED_BITS (type
) =
1911 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1912 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1914 TYPE_FIELD_IGNORE_BITS (type
) =
1915 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1916 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1919 /* If the type has baseclasses, allocate and clear a bit vector for
1920 TYPE_FIELD_VIRTUAL_BITS. */
1921 if (fip
->nbaseclasses
)
1923 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
1926 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1927 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1928 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1929 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
1930 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
1933 /* Copy the saved-up fields into the field vector. Start from the head
1934 of the list, adding to the tail of the field array, so that they end
1935 up in the same order in the array in which they were added to the list. */
1936 while (nfields
-- > 0)
1938 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
1939 switch (fip
->fields
->accessibility
)
1941 case DW_ACCESS_private
:
1942 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
1945 case DW_ACCESS_protected
:
1946 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
1949 case DW_ACCESS_public
:
1953 /* Unknown accessibility. Complain and treat it as public. */
1955 complain (&dwarf2_unsupported_accessibility
,
1956 fip
->fields
->accessibility
);
1960 if (nfields
< fip
->nbaseclasses
)
1962 switch (fip
->fields
->virtuality
)
1964 case DW_VIRTUALITY_virtual
:
1965 case DW_VIRTUALITY_pure_virtual
:
1966 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
1970 fip
->fields
= fip
->fields
->next
;
1974 /* Add a member function to the proper fieldlist. */
1977 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
1978 struct type
*type
, struct objfile
*objfile
,
1979 const struct comp_unit_head
*cu_header
)
1981 struct attribute
*attr
;
1982 struct fnfieldlist
*flp
;
1984 struct fn_field
*fnp
;
1987 struct nextfnfield
*new_fnfield
;
1989 /* Get name of member function. */
1990 attr
= dwarf_attr (die
, DW_AT_name
);
1991 if (attr
&& DW_STRING (attr
))
1992 fieldname
= DW_STRING (attr
);
1996 /* Get the mangled name. */
1997 physname
= dwarf2_linkage_name (die
);
1999 /* Look up member function name in fieldlist. */
2000 for (i
= 0; i
< fip
->nfnfields
; i
++)
2002 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2006 /* Create new list element if necessary. */
2007 if (i
< fip
->nfnfields
)
2008 flp
= &fip
->fnfieldlists
[i
];
2011 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2013 fip
->fnfieldlists
= (struct fnfieldlist
*)
2014 xrealloc (fip
->fnfieldlists
,
2015 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2016 * sizeof (struct fnfieldlist
));
2017 if (fip
->nfnfields
== 0)
2018 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2020 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2021 flp
->name
= fieldname
;
2027 /* Create a new member function field and chain it to the field list
2029 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2030 make_cleanup (free
, new_fnfield
);
2031 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2032 new_fnfield
->next
= flp
->head
;
2033 flp
->head
= new_fnfield
;
2036 /* Fill in the member function field info. */
2037 fnp
= &new_fnfield
->fnfield
;
2038 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2039 &objfile
->type_obstack
);
2040 fnp
->type
= alloc_type (objfile
);
2041 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2043 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2044 struct type
**arg_types
;
2045 int nparams
= TYPE_NFIELDS (die
->type
);
2048 /* Copy argument types from the subroutine type. */
2049 arg_types
= (struct type
**)
2050 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2051 for (iparams
= 0; iparams
< nparams
; iparams
++)
2052 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2054 /* Set last entry in argument type vector. */
2055 if (TYPE_FLAGS (die
->type
) & TYPE_FLAG_VARARGS
)
2056 arg_types
[nparams
] = NULL
;
2058 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2060 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2062 /* Handle static member functions.
2063 Dwarf2 has no clean way to discern C++ static and non-static
2064 member functions. G++ helps GDB by marking the first
2065 parameter for non-static member functions (which is the
2066 this pointer) as artificial. We obtain this information
2067 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2068 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2069 fnp
->voffset
= VOFFSET_STATIC
;
2072 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2074 /* Get fcontext from DW_AT_containing_type if present. */
2075 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2076 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2078 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2079 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2081 /* Get accessibility. */
2082 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2085 switch (DW_UNSND (attr
))
2087 case DW_ACCESS_private
:
2088 fnp
->is_private
= 1;
2090 case DW_ACCESS_protected
:
2091 fnp
->is_protected
= 1;
2096 /* Get index in virtual function table if it is a virtual member function. */
2097 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2099 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2102 /* Create the vector of member function fields, and attach it to the type. */
2105 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2106 struct objfile
*objfile
)
2108 struct fnfieldlist
*flp
;
2109 int total_length
= 0;
2112 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2113 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2114 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2116 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2118 struct nextfnfield
*nfp
= flp
->head
;
2119 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2122 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2123 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2124 fn_flp
->fn_fields
= (struct fn_field
*)
2125 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2126 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2127 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2129 total_length
+= flp
->length
;
2132 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2133 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2136 /* Called when we find the DIE that starts a structure or union scope
2137 (definition) to process all dies that define the members of the
2140 NOTE: we need to call struct_type regardless of whether or not the
2141 DIE has an at_name attribute, since it might be an anonymous
2142 structure or union. This gets the type entered into our set of
2145 However, if the structure is incomplete (an opaque struct/union)
2146 then suppress creating a symbol table entry for it since gdb only
2147 wants to find the one with the complete definition. Note that if
2148 it is complete, we just call new_symbol, which does it's own
2149 checking about whether the struct/union is anonymous or not (and
2150 suppresses creating a symbol table entry itself). */
2153 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2154 const struct comp_unit_head
*cu_header
)
2157 struct attribute
*attr
;
2159 type
= alloc_type (objfile
);
2161 INIT_CPLUS_SPECIFIC (type
);
2162 attr
= dwarf_attr (die
, DW_AT_name
);
2163 if (attr
&& DW_STRING (attr
))
2165 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2166 strlen (DW_STRING (attr
)),
2167 &objfile
->type_obstack
);
2170 if (die
->tag
== DW_TAG_structure_type
)
2172 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2174 else if (die
->tag
== DW_TAG_union_type
)
2176 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2180 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2182 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2185 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2188 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2192 TYPE_LENGTH (type
) = 0;
2195 /* We need to add the type field to the die immediately so we don't
2196 infinitely recurse when dealing with pointers to the structure
2197 type within the structure itself. */
2200 if (die
->has_children
&& ! die_is_declaration (die
))
2202 struct field_info fi
;
2203 struct die_info
*child_die
;
2204 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2206 memset (&fi
, 0, sizeof (struct field_info
));
2208 child_die
= die
->next
;
2210 while (child_die
&& child_die
->tag
)
2212 if (child_die
->tag
== DW_TAG_member
)
2214 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2216 else if (child_die
->tag
== DW_TAG_variable
)
2218 /* C++ static member. */
2219 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2221 else if (child_die
->tag
== DW_TAG_subprogram
)
2223 /* C++ member function. */
2224 process_die (child_die
, objfile
, cu_header
);
2225 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2227 else if (child_die
->tag
== DW_TAG_inheritance
)
2229 /* C++ base class field. */
2230 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2234 process_die (child_die
, objfile
, cu_header
);
2236 child_die
= sibling_die (child_die
);
2239 /* Attach fields and member functions to the type. */
2241 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2244 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2246 /* Get the type which refers to the base class (possibly this
2247 class itself) which contains the vtable pointer for the current
2248 class from the DW_AT_containing_type attribute. */
2250 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2252 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2254 TYPE_VPTR_BASETYPE (type
) = t
;
2257 static const char vptr_name
[] =
2258 {'_', 'v', 'p', 't', 'r', '\0'};
2261 /* Our own class provides vtbl ptr. */
2262 for (i
= TYPE_NFIELDS (t
) - 1;
2263 i
>= TYPE_N_BASECLASSES (t
);
2266 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2268 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2269 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2271 TYPE_VPTR_FIELDNO (type
) = i
;
2276 /* Complain if virtual function table field not found. */
2277 if (i
< TYPE_N_BASECLASSES (t
))
2278 complain (&dwarf2_vtbl_not_found_complaint
,
2279 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2283 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2288 new_symbol (die
, type
, objfile
, cu_header
);
2290 do_cleanups (back_to
);
2294 /* No children, must be stub. */
2295 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2301 /* Given a pointer to a die which begins an enumeration, process all
2302 the dies that define the members of the enumeration.
2304 This will be much nicer in draft 6 of the DWARF spec when our
2305 members will be dies instead squished into the DW_AT_element_list
2308 NOTE: We reverse the order of the element list. */
2311 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2312 const struct comp_unit_head
*cu_header
)
2314 struct die_info
*child_die
;
2316 struct field
*fields
;
2317 struct attribute
*attr
;
2320 int unsigned_enum
= 1;
2322 type
= alloc_type (objfile
);
2324 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2325 attr
= dwarf_attr (die
, DW_AT_name
);
2326 if (attr
&& DW_STRING (attr
))
2328 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2329 strlen (DW_STRING (attr
)),
2330 &objfile
->type_obstack
);
2333 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2336 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2340 TYPE_LENGTH (type
) = 0;
2345 if (die
->has_children
)
2347 child_die
= die
->next
;
2348 while (child_die
&& child_die
->tag
)
2350 if (child_die
->tag
!= DW_TAG_enumerator
)
2352 process_die (child_die
, objfile
, cu_header
);
2356 attr
= dwarf_attr (child_die
, DW_AT_name
);
2359 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2360 if (SYMBOL_VALUE (sym
) < 0)
2363 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2365 fields
= (struct field
*)
2367 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2368 * sizeof (struct field
));
2371 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2372 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2373 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2374 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2380 child_die
= sibling_die (child_die
);
2385 TYPE_NFIELDS (type
) = num_fields
;
2386 TYPE_FIELDS (type
) = (struct field
*)
2387 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2388 memcpy (TYPE_FIELDS (type
), fields
,
2389 sizeof (struct field
) * num_fields
);
2393 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2396 new_symbol (die
, type
, objfile
, cu_header
);
2399 /* Extract all information from a DW_TAG_array_type DIE and put it in
2400 the DIE's type field. For now, this only handles one dimensional
2404 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
2405 const struct comp_unit_head
*cu_header
)
2407 struct die_info
*child_die
;
2408 struct type
*type
= NULL
;
2409 struct type
*element_type
, *range_type
, *index_type
;
2410 struct type
**range_types
= NULL
;
2411 struct attribute
*attr
;
2413 struct cleanup
*back_to
;
2415 /* Return if we've already decoded this type. */
2421 element_type
= die_type (die
, objfile
, cu_header
);
2423 /* Irix 6.2 native cc creates array types without children for
2424 arrays with unspecified length. */
2425 if (die
->has_children
== 0)
2427 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2428 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2429 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2433 back_to
= make_cleanup (null_cleanup
, NULL
);
2434 child_die
= die
->next
;
2435 while (child_die
&& child_die
->tag
)
2437 if (child_die
->tag
== DW_TAG_subrange_type
)
2439 unsigned int low
, high
;
2441 /* Default bounds to an array with unspecified length. */
2444 if (cu_language
== language_fortran
)
2446 /* FORTRAN implies a lower bound of 1, if not given. */
2450 index_type
= die_type (child_die
, objfile
, cu_header
);
2451 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2454 if (attr
->form
== DW_FORM_sdata
)
2456 low
= DW_SND (attr
);
2458 else if (attr
->form
== DW_FORM_udata
2459 || attr
->form
== DW_FORM_data1
2460 || attr
->form
== DW_FORM_data2
2461 || attr
->form
== DW_FORM_data4
)
2463 low
= DW_UNSND (attr
);
2467 complain (&dwarf2_non_const_array_bound_ignored
,
2468 dwarf_form_name (attr
->form
));
2470 die
->type
= lookup_pointer_type (element_type
);
2477 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2480 if (attr
->form
== DW_FORM_sdata
)
2482 high
= DW_SND (attr
);
2484 else if (attr
->form
== DW_FORM_udata
2485 || attr
->form
== DW_FORM_data1
2486 || attr
->form
== DW_FORM_data2
2487 || attr
->form
== DW_FORM_data4
)
2489 high
= DW_UNSND (attr
);
2491 else if (attr
->form
== DW_FORM_block1
)
2493 /* GCC encodes arrays with unspecified or dynamic length
2494 with a DW_FORM_block1 attribute.
2495 FIXME: GDB does not yet know how to handle dynamic
2496 arrays properly, treat them as arrays with unspecified
2502 complain (&dwarf2_non_const_array_bound_ignored
,
2503 dwarf_form_name (attr
->form
));
2505 die
->type
= lookup_pointer_type (element_type
);
2513 /* Create a range type and save it for array type creation. */
2514 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2516 range_types
= (struct type
**)
2517 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2518 * sizeof (struct type
*));
2520 make_cleanup (free_current_contents
, &range_types
);
2522 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2524 child_die
= sibling_die (child_die
);
2527 /* Dwarf2 dimensions are output from left to right, create the
2528 necessary array types in backwards order. */
2529 type
= element_type
;
2531 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2533 do_cleanups (back_to
);
2535 /* Install the type in the die. */
2539 /* First cut: install each common block member as a global variable. */
2542 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
2543 const struct comp_unit_head
*cu_header
)
2545 struct die_info
*child_die
;
2546 struct attribute
*attr
;
2548 CORE_ADDR base
= (CORE_ADDR
) 0;
2550 attr
= dwarf_attr (die
, DW_AT_location
);
2553 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2555 if (die
->has_children
)
2557 child_die
= die
->next
;
2558 while (child_die
&& child_die
->tag
)
2560 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
2561 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2564 SYMBOL_VALUE_ADDRESS (sym
) =
2565 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2566 add_symbol_to_list (sym
, &global_symbols
);
2568 child_die
= sibling_die (child_die
);
2573 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2574 the user defined type vector. */
2577 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
2578 const struct comp_unit_head
*cu_header
)
2581 struct attribute
*attr
;
2588 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
2589 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2592 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2596 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2601 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2602 the user defined type vector. */
2605 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
2606 const struct comp_unit_head
*cu_header
)
2609 struct type
*to_type
;
2610 struct type
*domain
;
2617 type
= alloc_type (objfile
);
2618 to_type
= die_type (die
, objfile
, cu_header
);
2619 domain
= die_containing_type (die
, objfile
, cu_header
);
2620 smash_to_member_type (type
, domain
, to_type
);
2625 /* Extract all information from a DW_TAG_reference_type DIE and add to
2626 the user defined type vector. */
2629 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
2630 const struct comp_unit_head
*cu_header
)
2633 struct attribute
*attr
;
2640 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
2641 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2644 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2648 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2654 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
2655 const struct comp_unit_head
*cu_header
)
2662 complain (&dwarf2_const_ignored
);
2663 die
->type
= die_type (die
, objfile
, cu_header
);
2667 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
2668 const struct comp_unit_head
*cu_header
)
2675 complain (&dwarf2_volatile_ignored
);
2676 die
->type
= die_type (die
, objfile
, cu_header
);
2679 /* Extract all information from a DW_TAG_string_type DIE and add to
2680 the user defined type vector. It isn't really a user defined type,
2681 but it behaves like one, with other DIE's using an AT_user_def_type
2682 attribute to reference it. */
2685 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
2687 struct type
*type
, *range_type
, *index_type
, *char_type
;
2688 struct attribute
*attr
;
2689 unsigned int length
;
2696 attr
= dwarf_attr (die
, DW_AT_string_length
);
2699 length
= DW_UNSND (attr
);
2705 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2706 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2707 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2708 type
= create_string_type (char_type
, range_type
);
2712 /* Handle DIES due to C code like:
2716 int (*funcp)(int a, long l);
2720 ('funcp' generates a DW_TAG_subroutine_type DIE)
2724 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
2725 const struct comp_unit_head
*cu_header
)
2727 struct type
*type
; /* Type that this function returns */
2728 struct type
*ftype
; /* Function that returns above type */
2729 struct attribute
*attr
;
2731 /* Decode the type that this subroutine returns */
2736 type
= die_type (die
, objfile
, cu_header
);
2737 ftype
= lookup_function_type (type
);
2739 /* All functions in C++ have prototypes. */
2740 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2741 if ((attr
&& (DW_UNSND (attr
) != 0))
2742 || cu_language
== language_cplus
)
2743 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2745 if (die
->has_children
)
2747 struct die_info
*child_die
;
2751 /* Count the number of parameters.
2752 FIXME: GDB currently ignores vararg functions, but knows about
2753 vararg member functions. */
2754 child_die
= die
->next
;
2755 while (child_die
&& child_die
->tag
)
2757 if (child_die
->tag
== DW_TAG_formal_parameter
)
2759 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2760 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2761 child_die
= sibling_die (child_die
);
2764 /* Allocate storage for parameters and fill them in. */
2765 TYPE_NFIELDS (ftype
) = nparams
;
2766 TYPE_FIELDS (ftype
) = (struct field
*)
2767 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2769 child_die
= die
->next
;
2770 while (child_die
&& child_die
->tag
)
2772 if (child_die
->tag
== DW_TAG_formal_parameter
)
2774 /* Dwarf2 has no clean way to discern C++ static and non-static
2775 member functions. G++ helps GDB by marking the first
2776 parameter for non-static member functions (which is the
2777 this pointer) as artificial. We pass this information
2778 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2779 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2781 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2783 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2784 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
2788 child_die
= sibling_die (child_die
);
2796 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
2797 const struct comp_unit_head
*cu_header
)
2803 struct attribute
*attr
;
2806 xtype
= die_type (die
, objfile
, cu_header
);
2808 type
= alloc_type (objfile
);
2809 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2810 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2811 TYPE_TARGET_TYPE (type
) = xtype
;
2812 attr
= dwarf_attr (die
, DW_AT_name
);
2813 if (attr
&& DW_STRING (attr
))
2814 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2815 strlen (DW_STRING (attr
)),
2816 &objfile
->type_obstack
);
2822 /* Find a representation of a given base type and install
2823 it in the TYPE field of the die. */
2826 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
2829 struct attribute
*attr
;
2830 int encoding
= 0, size
= 0;
2832 /* If we've already decoded this die, this is a no-op. */
2838 attr
= dwarf_attr (die
, DW_AT_encoding
);
2841 encoding
= DW_UNSND (attr
);
2843 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2846 size
= DW_UNSND (attr
);
2848 attr
= dwarf_attr (die
, DW_AT_name
);
2849 if (attr
&& DW_STRING (attr
))
2851 enum type_code code
= TYPE_CODE_INT
;
2852 int is_unsigned
= 0;
2856 case DW_ATE_address
:
2857 /* Turn DW_ATE_address into a void * pointer. */
2858 code
= TYPE_CODE_PTR
;
2861 case DW_ATE_boolean
:
2862 code
= TYPE_CODE_BOOL
;
2865 case DW_ATE_complex_float
:
2866 code
= TYPE_CODE_COMPLEX
;
2869 code
= TYPE_CODE_FLT
;
2872 case DW_ATE_signed_char
:
2874 case DW_ATE_unsigned
:
2875 case DW_ATE_unsigned_char
:
2879 complain (&dwarf2_unsupported_at_encoding
,
2880 dwarf_type_encoding_name (encoding
));
2883 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2884 if (encoding
== DW_ATE_address
)
2885 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2889 type
= dwarf_base_type (encoding
, size
, objfile
);
2894 /* Read a whole compilation unit into a linked list of dies. */
2897 read_comp_unit (char *info_ptr
, bfd
*abfd
,
2898 const struct comp_unit_head
*cu_header
)
2900 struct die_info
*first_die
, *last_die
, *die
;
2904 /* Reset die reference table and cached types table; we are
2905 building new ones now. */
2906 dwarf2_empty_hash_tables ();
2910 first_die
= last_die
= NULL
;
2913 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
2914 if (die
->has_children
)
2925 /* Enter die in reference hash table */
2926 store_in_ref_table (die
->offset
, die
);
2930 first_die
= last_die
= die
;
2934 last_die
->next
= die
;
2938 while (nesting_level
> 0);
2942 /* Free a linked list of dies. */
2945 free_die_list (struct die_info
*dies
)
2947 struct die_info
*die
, *next
;
2960 do_free_die_list_cleanup (void *dies
)
2962 free_die_list (dies
);
2965 static struct cleanup
*
2966 make_cleanup_free_die_list (struct die_info
*dies
)
2968 return make_cleanup (do_free_die_list_cleanup
, dies
);
2972 /* Read the contents of the section at OFFSET and of size SIZE from the
2973 object file specified by OBJFILE into the psymbol_obstack and return it. */
2976 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
2979 bfd
*abfd
= objfile
->obfd
;
2985 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
2986 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
2987 (bfd_read (buf
, size
, 1, abfd
) != size
))
2990 error ("Dwarf Error: Can't read DWARF data from '%s'",
2991 bfd_get_filename (abfd
));
2996 /* In DWARF version 2, the description of the debugging information is
2997 stored in a separate .debug_abbrev section. Before we read any
2998 dies from a section we read in all abbreviations and install them
3002 dwarf2_read_abbrevs (bfd
*abfd
, unsigned int offset
)
3005 struct abbrev_info
*cur_abbrev
;
3006 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3007 unsigned int abbrev_form
, hash_number
;
3009 /* empty the table */
3010 dwarf2_empty_abbrev_table (NULL
);
3012 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3013 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3014 abbrev_ptr
+= bytes_read
;
3016 /* loop until we reach an abbrev number of 0 */
3017 while (abbrev_number
)
3019 cur_abbrev
= dwarf_alloc_abbrev ();
3021 /* read in abbrev header */
3022 cur_abbrev
->number
= abbrev_number
;
3023 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3024 abbrev_ptr
+= bytes_read
;
3025 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3028 /* now read in declarations */
3029 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3030 abbrev_ptr
+= bytes_read
;
3031 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3032 abbrev_ptr
+= bytes_read
;
3035 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3037 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3038 xrealloc (cur_abbrev
->attrs
,
3039 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3040 * sizeof (struct attr_abbrev
));
3042 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3043 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3044 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3045 abbrev_ptr
+= bytes_read
;
3046 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3047 abbrev_ptr
+= bytes_read
;
3050 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3051 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3052 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3054 /* Get next abbreviation.
3055 Under Irix6 the abbreviations for a compilation unit are not
3056 always properly terminated with an abbrev number of 0.
3057 Exit loop if we encounter an abbreviation which we have
3058 already read (which means we are about to read the abbreviations
3059 for the next compile unit) or if the end of the abbreviation
3060 table is reached. */
3061 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3062 >= dwarf_abbrev_size
)
3064 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3065 abbrev_ptr
+= bytes_read
;
3066 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3071 /* Empty the abbrev table for a new compilation unit. */
3075 dwarf2_empty_abbrev_table (PTR ignore
)
3078 struct abbrev_info
*abbrev
, *next
;
3080 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3083 abbrev
= dwarf2_abbrevs
[i
];
3086 next
= abbrev
->next
;
3087 free (abbrev
->attrs
);
3091 dwarf2_abbrevs
[i
] = NULL
;
3095 /* Lookup an abbrev_info structure in the abbrev hash table. */
3097 static struct abbrev_info
*
3098 dwarf2_lookup_abbrev (unsigned int number
)
3100 unsigned int hash_number
;
3101 struct abbrev_info
*abbrev
;
3103 hash_number
= number
% ABBREV_HASH_SIZE
;
3104 abbrev
= dwarf2_abbrevs
[hash_number
];
3108 if (abbrev
->number
== number
)
3111 abbrev
= abbrev
->next
;
3116 /* Read a minimal amount of information into the minimal die structure. */
3119 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3120 char *info_ptr
, int *has_pc_info
,
3121 const struct comp_unit_head
*cu_header
)
3123 unsigned int abbrev_number
, bytes_read
, i
;
3124 struct abbrev_info
*abbrev
;
3125 struct attribute attr
;
3126 struct attribute spec_attr
;
3127 int found_spec_attr
= 0;
3128 int has_low_pc_attr
= 0;
3129 int has_high_pc_attr
= 0;
3131 *part_die
= zeroed_partial_die
;
3133 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3134 info_ptr
+= bytes_read
;
3138 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3141 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3143 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3144 part_die
->tag
= abbrev
->tag
;
3145 part_die
->has_children
= abbrev
->has_children
;
3146 part_die
->abbrev
= abbrev_number
;
3148 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3150 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3151 info_ptr
, cu_header
);
3153 /* Store the data if it is of an attribute we want to keep in a
3154 partial symbol table. */
3159 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3160 if (part_die
->name
== NULL
)
3161 part_die
->name
= DW_STRING (&attr
);
3163 case DW_AT_MIPS_linkage_name
:
3164 part_die
->name
= DW_STRING (&attr
);
3167 has_low_pc_attr
= 1;
3168 part_die
->lowpc
= DW_ADDR (&attr
);
3171 has_high_pc_attr
= 1;
3172 part_die
->highpc
= DW_ADDR (&attr
);
3174 case DW_AT_location
:
3175 part_die
->locdesc
= DW_BLOCK (&attr
);
3177 case DW_AT_language
:
3178 part_die
->language
= DW_UNSND (&attr
);
3180 case DW_AT_external
:
3181 part_die
->is_external
= DW_UNSND (&attr
);
3183 case DW_AT_declaration
:
3184 part_die
->is_declaration
= DW_UNSND (&attr
);
3187 part_die
->has_type
= 1;
3189 case DW_AT_abstract_origin
:
3190 case DW_AT_specification
:
3191 found_spec_attr
= 1;
3195 /* Ignore absolute siblings, they might point outside of
3196 the current compile unit. */
3197 if (attr
.form
== DW_FORM_ref_addr
)
3198 complain (&dwarf2_absolute_sibling_complaint
);
3201 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3208 /* If we found a reference attribute and the die has no name, try
3209 to find a name in the referred to die. */
3211 if (found_spec_attr
&& part_die
->name
== NULL
)
3213 struct partial_die_info spec_die
;
3217 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3218 read_partial_die (&spec_die
, abfd
, spec_ptr
, &dummy
, cu_header
);
3221 part_die
->name
= spec_die
.name
;
3223 /* Copy DW_AT_external attribute if it is set. */
3224 if (spec_die
.is_external
)
3225 part_die
->is_external
= spec_die
.is_external
;
3229 /* When using the GNU linker, .gnu.linkonce. sections are used to
3230 eliminate duplicate copies of functions and vtables and such.
3231 The linker will arbitrarily choose one and discard the others.
3232 The AT_*_pc values for such functions refer to local labels in
3233 these sections. If the section from that file was discarded, the
3234 labels are not in the output, so the relocs get a value of 0.
3235 If this is a discarded function, mark the pc bounds as invalid,
3236 so that GDB will ignore it. */
3237 if (has_low_pc_attr
&& has_high_pc_attr
3238 && part_die
->lowpc
< part_die
->highpc
3239 && (part_die
->lowpc
!= 0
3240 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3245 /* Read the die from the .debug_info section buffer. And set diep to
3246 point to a newly allocated die with its information. */
3249 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3250 const struct comp_unit_head
*cu_header
)
3252 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3253 struct abbrev_info
*abbrev
;
3254 struct die_info
*die
;
3256 offset
= info_ptr
- dwarf_info_buffer
;
3257 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3258 info_ptr
+= bytes_read
;
3261 die
= dwarf_alloc_die ();
3263 die
->abbrev
= abbrev_number
;
3269 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3272 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3274 die
= dwarf_alloc_die ();
3275 die
->offset
= offset
;
3276 die
->tag
= abbrev
->tag
;
3277 die
->has_children
= abbrev
->has_children
;
3278 die
->abbrev
= abbrev_number
;
3281 die
->num_attrs
= abbrev
->num_attrs
;
3282 die
->attrs
= (struct attribute
*)
3283 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3285 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3287 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3288 abfd
, info_ptr
, cu_header
);
3295 /* Read an attribute described by an abbreviated attribute. */
3298 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
3299 bfd
*abfd
, char *info_ptr
,
3300 const struct comp_unit_head
*cu_header
)
3302 unsigned int bytes_read
;
3303 struct dwarf_block
*blk
;
3305 attr
->name
= abbrev
->name
;
3306 attr
->form
= abbrev
->form
;
3307 switch (abbrev
->form
)
3310 case DW_FORM_ref_addr
:
3311 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3312 info_ptr
+= bytes_read
;
3314 case DW_FORM_block2
:
3315 blk
= dwarf_alloc_block ();
3316 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3318 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3319 info_ptr
+= blk
->size
;
3320 DW_BLOCK (attr
) = blk
;
3322 case DW_FORM_block4
:
3323 blk
= dwarf_alloc_block ();
3324 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3326 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3327 info_ptr
+= blk
->size
;
3328 DW_BLOCK (attr
) = blk
;
3331 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3335 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3339 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3342 case DW_FORM_string
:
3343 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3344 info_ptr
+= bytes_read
;
3347 blk
= dwarf_alloc_block ();
3348 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3349 info_ptr
+= bytes_read
;
3350 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3351 info_ptr
+= blk
->size
;
3352 DW_BLOCK (attr
) = blk
;
3354 case DW_FORM_block1
:
3355 blk
= dwarf_alloc_block ();
3356 blk
->size
= read_1_byte (abfd
, info_ptr
);
3358 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3359 info_ptr
+= blk
->size
;
3360 DW_BLOCK (attr
) = blk
;
3363 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3367 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3371 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3372 info_ptr
+= bytes_read
;
3375 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3376 info_ptr
+= bytes_read
;
3379 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3383 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3387 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3391 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3394 case DW_FORM_ref_udata
:
3395 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3396 info_ptr
+= bytes_read
;
3399 case DW_FORM_indirect
:
3401 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3402 dwarf_form_name (abbrev
->form
));
3407 /* read dwarf information from a buffer */
3410 read_1_byte (bfd
*abfd
, char *buf
)
3412 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3416 read_1_signed_byte (bfd
*abfd
, char *buf
)
3418 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3422 read_2_bytes (bfd
*abfd
, char *buf
)
3424 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3428 read_2_signed_bytes (bfd
*abfd
, char *buf
)
3430 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3434 read_4_bytes (bfd
*abfd
, char *buf
)
3436 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3440 read_4_signed_bytes (bfd
*abfd
, char *buf
)
3442 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3445 static unsigned long
3446 read_8_bytes (bfd
*abfd
, char *buf
)
3448 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3452 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3455 CORE_ADDR retval
= 0;
3457 if (cu_header
->signed_addr_p
)
3459 switch (cu_header
->addr_size
)
3462 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3465 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3468 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
3471 internal_error ("read_address: bad switch, signed");
3476 switch (cu_header
->addr_size
)
3479 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3482 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3485 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3488 internal_error ("read_address: bad switch, unsigned");
3492 *bytes_read
= cu_header
->addr_size
;
3496 /* Reads the initial length from a section. The (draft) DWARF 2.1
3497 specification allows the initial length to take up either 4 bytes
3498 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
3499 bytes describe the length and all offsets will be 8 bytes in length
3502 The value returned via bytes_read should be used to increment
3503 the relevant pointer after calling read_initial_length().
3505 As a side effect, this function sets the fields initial_length_size
3506 and offset_size in cu_header to the values appropriate for the
3507 length field. (The format of the initial length field determines
3508 the width of file offsets to be fetched later with fetch_offset().)
3510 [ Note: read_initial_length() and read_offset() are based on the
3511 document entitled "DWARF Debugging Information Format", revision
3512 2.1, draft 4, dated July 20, 2000. This document was obtained
3515 http://reality.sgi.com/dehnert_engr/dwarf/dwarf2p1-draft4-000720.pdf
3517 This document is only a draft and is subject to change. (So beware.)
3519 - Kevin, Aug 4, 2000
3523 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
3528 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3530 if (retval
== 0xffffffff)
3532 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
3534 if (cu_header
!= NULL
)
3536 cu_header
->initial_length_size
= 12;
3537 cu_header
->offset_size
= 8;
3543 if (cu_header
!= NULL
)
3545 cu_header
->initial_length_size
= 4;
3546 cu_header
->offset_size
= 4;
3553 /* Read an offset from the data stream. The size of the offset is
3554 given by cu_header->offset_size. */
3557 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3562 switch (cu_header
->offset_size
)
3565 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3569 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3573 internal_error ("read_offset: bad switch");
3580 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
3582 /* If the size of a host char is 8 bits, we can return a pointer
3583 to the buffer, otherwise we have to copy the data to a buffer
3584 allocated on the temporary obstack. */
3585 #if HOST_CHAR_BIT == 8
3591 ret
= obstack_alloc (&dwarf2_tmp_obstack
, size
);
3592 for (i
= 0; i
< size
; ++i
)
3594 ret
[i
] = bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3602 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3604 /* If the size of a host char is 8 bits, we can return a pointer
3605 to the string, otherwise we have to copy the string to a buffer
3606 allocated on the temporary obstack. */
3607 #if HOST_CHAR_BIT == 8
3610 *bytes_read_ptr
= 1;
3613 *bytes_read_ptr
= strlen (buf
) + 1;
3619 while ((byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
)) != 0)
3621 obstack_1grow (&dwarf2_tmp_obstack
, byte
);
3627 *bytes_read_ptr
= 1;
3630 obstack_1grow (&dwarf2_tmp_obstack
, '\0');
3631 *bytes_read_ptr
= i
+ 1;
3632 return obstack_finish (&dwarf2_tmp_obstack
);
3636 static unsigned long
3637 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3639 unsigned long result
;
3640 unsigned int num_read
;
3650 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3653 result
|= ((unsigned long)(byte
& 127) << shift
);
3654 if ((byte
& 128) == 0)
3660 *bytes_read_ptr
= num_read
;
3665 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3668 int i
, shift
, size
, num_read
;
3678 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3681 result
|= ((long)(byte
& 127) << shift
);
3683 if ((byte
& 128) == 0)
3688 if ((shift
< size
) && (byte
& 0x40))
3690 result
|= -(1 << shift
);
3692 *bytes_read_ptr
= num_read
;
3697 set_cu_language (unsigned int lang
)
3703 cu_language
= language_c
;
3705 case DW_LANG_C_plus_plus
:
3706 cu_language
= language_cplus
;
3708 case DW_LANG_Fortran77
:
3709 case DW_LANG_Fortran90
:
3710 cu_language
= language_fortran
;
3712 case DW_LANG_Mips_Assembler
:
3713 cu_language
= language_asm
;
3716 case DW_LANG_Cobol74
:
3717 case DW_LANG_Cobol85
:
3718 case DW_LANG_Pascal83
:
3719 case DW_LANG_Modula2
:
3721 cu_language
= language_unknown
;
3724 cu_language_defn
= language_def (cu_language
);
3727 /* Return the named attribute or NULL if not there. */
3729 static struct attribute
*
3730 dwarf_attr (struct die_info
*die
, unsigned int name
)
3733 struct attribute
*spec
= NULL
;
3735 for (i
= 0; i
< die
->num_attrs
; ++i
)
3737 if (die
->attrs
[i
].name
== name
)
3739 return &die
->attrs
[i
];
3741 if (die
->attrs
[i
].name
== DW_AT_specification
3742 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3743 spec
= &die
->attrs
[i
];
3747 struct die_info
*ref_die
=
3748 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3751 return dwarf_attr (ref_die
, name
);
3758 die_is_declaration (struct die_info
*die
)
3760 return (dwarf_attr (die
, DW_AT_declaration
)
3761 && ! dwarf_attr (die
, DW_AT_specification
));
3764 /* Decode the line number information for the compilation unit whose
3765 line number info is at OFFSET in the .debug_line section.
3766 The compilation directory of the file is passed in COMP_DIR. */
3770 unsigned int num_files
;
3783 unsigned int num_dirs
;
3788 dwarf_decode_lines (unsigned int offset
, char *comp_dir
, bfd
*abfd
,
3789 const struct comp_unit_head
*cu_header
)
3793 struct line_head lh
;
3794 struct cleanup
*back_to
;
3795 unsigned int i
, bytes_read
;
3796 char *cur_file
, *cur_dir
;
3797 unsigned char op_code
, extended_op
, adj_opcode
;
3799 #define FILE_ALLOC_CHUNK 5
3800 #define DIR_ALLOC_CHUNK 5
3802 struct filenames files
;
3803 struct directories dirs
;
3805 if (dwarf_line_buffer
== NULL
)
3807 complain (&dwarf2_missing_line_number_section
);
3811 files
.num_files
= 0;
3817 line_ptr
= dwarf_line_buffer
+ offset
;
3819 /* read in the prologue */
3820 lh
.total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
3821 line_ptr
+= bytes_read
;
3822 line_end
= line_ptr
+ lh
.total_length
;
3823 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3825 lh
.prologue_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
3826 line_ptr
+= bytes_read
;
3827 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3829 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3831 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3833 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3835 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3837 lh
.standard_opcode_lengths
= (unsigned char *)
3838 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3839 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
3841 lh
.standard_opcode_lengths
[0] = 1;
3842 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3844 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3848 /* Read directory table */
3849 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3851 line_ptr
+= bytes_read
;
3852 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3854 dirs
.dirs
= (char **)
3855 xrealloc (dirs
.dirs
,
3856 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3857 if (dirs
.num_dirs
== 0)
3858 make_cleanup (free_current_contents
, &dirs
.dirs
);
3860 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3862 line_ptr
+= bytes_read
;
3864 /* Read file name table */
3865 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3867 line_ptr
+= bytes_read
;
3868 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3870 files
.files
= (struct fileinfo
*)
3871 xrealloc (files
.files
,
3872 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3873 * sizeof (struct fileinfo
));
3874 if (files
.num_files
== 0)
3875 make_cleanup (free_current_contents
, &files
.files
);
3877 files
.files
[files
.num_files
].name
= cur_file
;
3878 files
.files
[files
.num_files
].dir
=
3879 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3880 line_ptr
+= bytes_read
;
3881 files
.files
[files
.num_files
].time
=
3882 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3883 line_ptr
+= bytes_read
;
3884 files
.files
[files
.num_files
].size
=
3885 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3886 line_ptr
+= bytes_read
;
3889 line_ptr
+= bytes_read
;
3891 /* Read the statement sequences until there's nothing left. */
3892 while (line_ptr
< line_end
)
3894 /* state machine registers */
3895 CORE_ADDR address
= 0;
3896 unsigned int file
= 1;
3897 unsigned int line
= 1;
3898 unsigned int column
= 0;
3899 int is_stmt
= lh
.default_is_stmt
;
3900 int basic_block
= 0;
3901 int end_sequence
= 0;
3903 /* Start a subfile for the current file of the state machine. */
3904 if (files
.num_files
>= file
)
3906 /* The file and directory tables are 0 based, the references
3908 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3909 (files
.files
[file
- 1].dir
3910 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3914 /* Decode the table. */
3915 while (!end_sequence
)
3917 op_code
= read_1_byte (abfd
, line_ptr
);
3921 case DW_LNS_extended_op
:
3922 line_ptr
+= 1; /* ignore length */
3923 extended_op
= read_1_byte (abfd
, line_ptr
);
3925 switch (extended_op
)
3927 case DW_LNE_end_sequence
:
3929 /* Don't call record_line here. The end_sequence
3930 instruction provides the address of the first byte
3931 *after* the last line in the sequence; it's not the
3932 address of any real source line. However, the GDB
3933 linetable structure only records the starts of lines,
3934 not the ends. This is a weakness of GDB. */
3936 case DW_LNE_set_address
:
3937 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
3938 line_ptr
+= bytes_read
;
3939 address
+= baseaddr
;
3941 case DW_LNE_define_file
:
3942 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
3943 line_ptr
+= bytes_read
;
3944 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3946 files
.files
= (struct fileinfo
*)
3947 xrealloc (files
.files
,
3948 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3949 * sizeof (struct fileinfo
));
3950 if (files
.num_files
== 0)
3951 make_cleanup (free_current_contents
, &files
.files
);
3953 files
.files
[files
.num_files
].name
= cur_file
;
3954 files
.files
[files
.num_files
].dir
=
3955 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3956 line_ptr
+= bytes_read
;
3957 files
.files
[files
.num_files
].time
=
3958 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3959 line_ptr
+= bytes_read
;
3960 files
.files
[files
.num_files
].size
=
3961 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3962 line_ptr
+= bytes_read
;
3966 complain (&dwarf2_mangled_line_number_section
);
3971 record_line (current_subfile
, line
, address
);
3974 case DW_LNS_advance_pc
:
3975 address
+= lh
.minimum_instruction_length
3976 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3977 line_ptr
+= bytes_read
;
3979 case DW_LNS_advance_line
:
3980 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
3981 line_ptr
+= bytes_read
;
3983 case DW_LNS_set_file
:
3984 /* The file and directory tables are 0 based, the references
3986 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3987 line_ptr
+= bytes_read
;
3988 dwarf2_start_subfile
3989 (files
.files
[file
- 1].name
,
3990 (files
.files
[file
- 1].dir
3991 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3994 case DW_LNS_set_column
:
3995 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3996 line_ptr
+= bytes_read
;
3998 case DW_LNS_negate_stmt
:
3999 is_stmt
= (!is_stmt
);
4001 case DW_LNS_set_basic_block
:
4004 /* Add to the address register of the state machine the
4005 address increment value corresponding to special opcode
4006 255. Ie, this value is scaled by the minimum instruction
4007 length since special opcode 255 would have scaled the
4009 case DW_LNS_const_add_pc
:
4010 address
+= (lh
.minimum_instruction_length
4011 * ((255 - lh
.opcode_base
) / lh
.line_range
));
4013 case DW_LNS_fixed_advance_pc
:
4014 address
+= read_2_bytes (abfd
, line_ptr
);
4017 default: /* special operand */
4018 adj_opcode
= op_code
- lh
.opcode_base
;
4019 address
+= (adj_opcode
/ lh
.line_range
)
4020 * lh
.minimum_instruction_length
;
4021 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
4022 /* append row to matrix using current values */
4023 record_line (current_subfile
, line
, address
);
4029 do_cleanups (back_to
);
4032 /* Start a subfile for DWARF. FILENAME is the name of the file and
4033 DIRNAME the name of the source directory which contains FILENAME
4034 or NULL if not known.
4035 This routine tries to keep line numbers from identical absolute and
4036 relative file names in a common subfile.
4038 Using the `list' example from the GDB testsuite, which resides in
4039 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4040 of /srcdir/list0.c yields the following debugging information for list0.c:
4042 DW_AT_name: /srcdir/list0.c
4043 DW_AT_comp_dir: /compdir
4044 files.files[0].name: list0.h
4045 files.files[0].dir: /srcdir
4046 files.files[1].name: list0.c
4047 files.files[1].dir: /srcdir
4049 The line number information for list0.c has to end up in a single
4050 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4053 dwarf2_start_subfile (char *filename
, char *dirname
)
4055 /* If the filename isn't absolute, try to match an existing subfile
4056 with the full pathname. */
4058 if (*filename
!= '/' && dirname
!= NULL
)
4060 struct subfile
*subfile
;
4061 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4063 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4065 if (STREQ (subfile
->name
, fullname
))
4067 current_subfile
= subfile
;
4074 start_subfile (filename
, dirname
);
4077 /* Given a pointer to a DWARF information entry, figure out if we need
4078 to make a symbol table entry for it, and if so, create a new entry
4079 and return a pointer to it.
4080 If TYPE is NULL, determine symbol type from the die, otherwise
4081 used the passed type. */
4083 static struct symbol
*
4084 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
4085 const struct comp_unit_head
*cu_header
)
4087 struct symbol
*sym
= NULL
;
4089 struct attribute
*attr
= NULL
;
4090 struct attribute
*attr2
= NULL
;
4093 name
= dwarf2_linkage_name (die
);
4096 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4097 sizeof (struct symbol
));
4098 OBJSTAT (objfile
, n_syms
++);
4099 memset (sym
, 0, sizeof (struct symbol
));
4100 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4101 &objfile
->symbol_obstack
);
4103 /* Default assumptions.
4104 Use the passed type or decode it from the die. */
4105 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4106 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4108 SYMBOL_TYPE (sym
) = type
;
4110 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
4111 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4114 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4117 /* If this symbol is from a C++ compilation, then attempt to
4118 cache the demangled form for future reference. This is a
4119 typical time versus space tradeoff, that was decided in favor
4120 of time because it sped up C++ symbol lookups by a factor of
4123 SYMBOL_LANGUAGE (sym
) = cu_language
;
4124 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4128 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4131 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4133 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4135 case DW_TAG_subprogram
:
4136 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4138 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4139 attr2
= dwarf_attr (die
, DW_AT_external
);
4140 if (attr2
&& (DW_UNSND (attr2
) != 0))
4142 add_symbol_to_list (sym
, &global_symbols
);
4146 add_symbol_to_list (sym
, list_in_scope
);
4149 case DW_TAG_variable
:
4150 /* Compilation with minimal debug info may result in variables
4151 with missing type entries. Change the misleading `void' type
4152 to something sensible. */
4153 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4154 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4155 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4156 "<variable, no debug info>",
4158 attr
= dwarf_attr (die
, DW_AT_const_value
);
4161 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4162 attr2
= dwarf_attr (die
, DW_AT_external
);
4163 if (attr2
&& (DW_UNSND (attr2
) != 0))
4164 add_symbol_to_list (sym
, &global_symbols
);
4166 add_symbol_to_list (sym
, list_in_scope
);
4169 attr
= dwarf_attr (die
, DW_AT_location
);
4172 attr2
= dwarf_attr (die
, DW_AT_external
);
4173 if (attr2
&& (DW_UNSND (attr2
) != 0))
4175 SYMBOL_VALUE_ADDRESS (sym
) =
4176 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4177 add_symbol_to_list (sym
, &global_symbols
);
4179 /* In shared libraries the address of the variable
4180 in the location descriptor might still be relocatable,
4181 so its value could be zero.
4182 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4183 value is zero, the address of the variable will then
4184 be determined from the minimal symbol table whenever
4185 the variable is referenced. */
4186 if (SYMBOL_VALUE_ADDRESS (sym
))
4188 SYMBOL_VALUE_ADDRESS (sym
) += baseaddr
;
4189 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4192 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4196 SYMBOL_VALUE (sym
) = addr
=
4197 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4198 add_symbol_to_list (sym
, list_in_scope
);
4201 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4205 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4209 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4210 SYMBOL_BASEREG (sym
) = basereg
;
4214 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4218 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4219 SYMBOL_VALUE_ADDRESS (sym
) = addr
+ baseaddr
;
4225 /* We do not know the address of this symbol.
4226 If it is an external symbol and we have type information
4227 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4228 The address of the variable will then be determined from
4229 the minimal symbol table whenever the variable is
4231 attr2
= dwarf_attr (die
, DW_AT_external
);
4232 if (attr2
&& (DW_UNSND (attr2
) != 0)
4233 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4235 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4236 add_symbol_to_list (sym
, &global_symbols
);
4240 case DW_TAG_formal_parameter
:
4241 attr
= dwarf_attr (die
, DW_AT_location
);
4244 SYMBOL_VALUE (sym
) =
4245 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4248 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4254 if (basereg
!= frame_base_reg
)
4255 complain (&dwarf2_complex_location_expr
);
4256 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4260 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4261 SYMBOL_BASEREG (sym
) = basereg
;
4266 SYMBOL_CLASS (sym
) = LOC_ARG
;
4269 attr
= dwarf_attr (die
, DW_AT_const_value
);
4272 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4274 add_symbol_to_list (sym
, list_in_scope
);
4276 case DW_TAG_unspecified_parameters
:
4277 /* From varargs functions; gdb doesn't seem to have any
4278 interest in this information, so just ignore it for now.
4281 case DW_TAG_class_type
:
4282 case DW_TAG_structure_type
:
4283 case DW_TAG_union_type
:
4284 case DW_TAG_enumeration_type
:
4285 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4286 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4287 add_symbol_to_list (sym
, list_in_scope
);
4289 /* The semantics of C++ state that "struct foo { ... }" also
4290 defines a typedef for "foo". Synthesize a typedef symbol so
4291 that "ptype foo" works as expected. */
4292 if (cu_language
== language_cplus
)
4294 struct symbol
*typedef_sym
= (struct symbol
*)
4295 obstack_alloc (&objfile
->symbol_obstack
,
4296 sizeof (struct symbol
));
4297 *typedef_sym
= *sym
;
4298 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4299 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4300 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4301 obsavestring (SYMBOL_NAME (sym
),
4302 strlen (SYMBOL_NAME (sym
)),
4303 &objfile
->type_obstack
);
4304 add_symbol_to_list (typedef_sym
, list_in_scope
);
4307 case DW_TAG_typedef
:
4308 case DW_TAG_base_type
:
4309 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4310 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4311 add_symbol_to_list (sym
, list_in_scope
);
4313 case DW_TAG_enumerator
:
4314 attr
= dwarf_attr (die
, DW_AT_const_value
);
4317 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4319 add_symbol_to_list (sym
, list_in_scope
);
4322 /* Not a tag we recognize. Hopefully we aren't processing
4323 trash data, but since we must specifically ignore things
4324 we don't recognize, there is nothing else we should do at
4326 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4333 /* Copy constant value from an attribute to a symbol. */
4336 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
4337 struct objfile
*objfile
,
4338 const struct comp_unit_head
*cu_header
)
4340 struct dwarf_block
*blk
;
4345 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
4346 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4347 cu_header
->addr_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4348 SYMBOL_VALUE_BYTES (sym
) = (char *)
4349 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
4350 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
4352 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4354 case DW_FORM_block1
:
4355 case DW_FORM_block2
:
4356 case DW_FORM_block4
:
4358 blk
= DW_BLOCK (attr
);
4359 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4360 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4361 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4362 SYMBOL_VALUE_BYTES (sym
) = (char *)
4363 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4364 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4365 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4368 /* The DW_AT_const_value attributes are supposed to carry the
4369 symbol's value "represented as it would be on the target
4370 architecture." By the time we get here, it's already been
4371 converted to host endianness, so we just need to sign- or
4372 zero-extend it as appropriate. */
4374 dwarf2_const_value_data (attr
, sym
, 8);
4377 dwarf2_const_value_data (attr
, sym
, 16);
4380 dwarf2_const_value_data (attr
, sym
, 32);
4383 dwarf2_const_value_data (attr
, sym
, 64);
4387 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4388 SYMBOL_CLASS (sym
) = LOC_CONST
;
4392 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4393 SYMBOL_CLASS (sym
) = LOC_CONST
;
4397 complain (&dwarf2_unsupported_const_value_attr
,
4398 dwarf_form_name (attr
->form
));
4399 SYMBOL_VALUE (sym
) = 0;
4400 SYMBOL_CLASS (sym
) = LOC_CONST
;
4406 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4407 or zero-extend it as appropriate for the symbol's type. */
4409 dwarf2_const_value_data (struct attribute
*attr
,
4413 LONGEST l
= DW_UNSND (attr
);
4415 if (bits
< sizeof (l
) * 8)
4417 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4418 l
&= ((LONGEST
) 1 << bits
) - 1;
4420 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4423 SYMBOL_VALUE (sym
) = l
;
4424 SYMBOL_CLASS (sym
) = LOC_CONST
;
4428 /* Return the type of the die in question using its DW_AT_type attribute. */
4430 static struct type
*
4431 die_type (struct die_info
*die
, struct objfile
*objfile
,
4432 const struct comp_unit_head
*cu_header
)
4435 struct attribute
*type_attr
;
4436 struct die_info
*type_die
;
4439 type_attr
= dwarf_attr (die
, DW_AT_type
);
4442 /* A missing DW_AT_type represents a void type. */
4443 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4447 ref
= dwarf2_get_ref_die_offset (type_attr
);
4448 type_die
= follow_die_ref (ref
);
4451 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4455 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4458 dump_die (type_die
);
4459 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4464 /* Return the containing type of the die in question using its
4465 DW_AT_containing_type attribute. */
4467 static struct type
*
4468 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
4469 const struct comp_unit_head
*cu_header
)
4471 struct type
*type
= NULL
;
4472 struct attribute
*type_attr
;
4473 struct die_info
*type_die
= NULL
;
4476 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4479 ref
= dwarf2_get_ref_die_offset (type_attr
);
4480 type_die
= follow_die_ref (ref
);
4483 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4486 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4491 dump_die (type_die
);
4492 error ("Dwarf Error: Problem turning containing type into gdb type.");
4498 static struct type
*
4499 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
4501 struct die_info
*die
;
4504 die
= follow_die_ref (offset
);
4507 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4510 type
= tag_type_to_type (die
, objfile
);
4515 static struct type
*
4516 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
4517 const struct comp_unit_head
*cu_header
)
4525 struct attribute
*attr
;
4526 attr
= dwarf_attr (die
, DW_AT_name
);
4527 if (attr
&& DW_STRING (attr
))
4529 char *attrname
=DW_STRING (attr
);
4530 unsigned long hashval
=hash(attrname
, strlen(attrname
)) % TYPE_HASH_SIZE
;
4532 if (dwarf2_cached_types
[hashval
] != NULL
)
4534 const char *nameoftype
;
4535 nameoftype
= TYPE_NAME(dwarf2_cached_types
[hashval
]) == NULL
? TYPE_TAG_NAME(dwarf2_cached_types
[hashval
]) : TYPE_NAME(dwarf2_cached_types
[hashval
]);
4536 if (strcmp(attrname
, nameoftype
) == 0)
4538 die
->type
=dwarf2_cached_types
[hashval
];
4542 read_type_die (die
, objfile
, cu_header
);
4543 dwarf2_cached_types
[hashval
] = die
->type
;
4548 read_type_die (die
, objfile
, cu_header
);
4549 dwarf2_cached_types
[hashval
] = die
->type
;
4554 read_type_die (die
, objfile
, cu_header
);
4560 error ("Dwarf Error: Cannot find type of die.");
4567 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
4568 const struct comp_unit_head
*cu_header
)
4572 case DW_TAG_class_type
:
4573 case DW_TAG_structure_type
:
4574 case DW_TAG_union_type
:
4575 read_structure_scope (die
, objfile
, cu_header
);
4577 case DW_TAG_enumeration_type
:
4578 read_enumeration (die
, objfile
, cu_header
);
4580 case DW_TAG_subprogram
:
4581 case DW_TAG_subroutine_type
:
4582 read_subroutine_type (die
, objfile
, cu_header
);
4584 case DW_TAG_array_type
:
4585 read_array_type (die
, objfile
, cu_header
);
4587 case DW_TAG_pointer_type
:
4588 read_tag_pointer_type (die
, objfile
, cu_header
);
4590 case DW_TAG_ptr_to_member_type
:
4591 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
4593 case DW_TAG_reference_type
:
4594 read_tag_reference_type (die
, objfile
, cu_header
);
4596 case DW_TAG_const_type
:
4597 read_tag_const_type (die
, objfile
, cu_header
);
4599 case DW_TAG_volatile_type
:
4600 read_tag_volatile_type (die
, objfile
, cu_header
);
4602 case DW_TAG_string_type
:
4603 read_tag_string_type (die
, objfile
);
4605 case DW_TAG_typedef
:
4606 read_typedef (die
, objfile
, cu_header
);
4608 case DW_TAG_base_type
:
4609 read_base_type (die
, objfile
);
4612 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4617 static struct type
*
4618 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
4620 /* FIXME - this should not produce a new (struct type *)
4621 every time. It should cache base types. */
4625 case DW_ATE_address
:
4626 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4628 case DW_ATE_boolean
:
4629 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4631 case DW_ATE_complex_float
:
4634 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4638 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4644 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4648 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4655 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4658 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4662 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4666 case DW_ATE_signed_char
:
4667 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4669 case DW_ATE_unsigned
:
4673 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4676 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4680 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4684 case DW_ATE_unsigned_char
:
4685 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4688 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4695 copy_die (struct die_info
*old_die
)
4697 struct die_info
*new_die
;
4700 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4701 memset (new_die
, 0, sizeof (struct die_info
));
4703 new_die
->tag
= old_die
->tag
;
4704 new_die
->has_children
= old_die
->has_children
;
4705 new_die
->abbrev
= old_die
->abbrev
;
4706 new_die
->offset
= old_die
->offset
;
4707 new_die
->type
= NULL
;
4709 num_attrs
= old_die
->num_attrs
;
4710 new_die
->num_attrs
= num_attrs
;
4711 new_die
->attrs
= (struct attribute
*)
4712 xmalloc (num_attrs
* sizeof (struct attribute
));
4714 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4716 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4717 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4718 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4721 new_die
->next
= NULL
;
4726 /* Return sibling of die, NULL if no sibling. */
4729 sibling_die (struct die_info
*die
)
4731 int nesting_level
= 0;
4733 if (!die
->has_children
)
4735 if (die
->next
&& (die
->next
->tag
== 0))
4748 if (die
->has_children
)
4758 while (nesting_level
);
4759 if (die
&& (die
->tag
== 0))
4770 /* Get linkage name of a die, return NULL if not found. */
4773 dwarf2_linkage_name (struct die_info
*die
)
4775 struct attribute
*attr
;
4777 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4778 if (attr
&& DW_STRING (attr
))
4779 return DW_STRING (attr
);
4780 attr
= dwarf_attr (die
, DW_AT_name
);
4781 if (attr
&& DW_STRING (attr
))
4782 return DW_STRING (attr
);
4786 /* Convert a DIE tag into its string name. */
4789 dwarf_tag_name (register unsigned tag
)
4793 case DW_TAG_padding
:
4794 return "DW_TAG_padding";
4795 case DW_TAG_array_type
:
4796 return "DW_TAG_array_type";
4797 case DW_TAG_class_type
:
4798 return "DW_TAG_class_type";
4799 case DW_TAG_entry_point
:
4800 return "DW_TAG_entry_point";
4801 case DW_TAG_enumeration_type
:
4802 return "DW_TAG_enumeration_type";
4803 case DW_TAG_formal_parameter
:
4804 return "DW_TAG_formal_parameter";
4805 case DW_TAG_imported_declaration
:
4806 return "DW_TAG_imported_declaration";
4808 return "DW_TAG_label";
4809 case DW_TAG_lexical_block
:
4810 return "DW_TAG_lexical_block";
4812 return "DW_TAG_member";
4813 case DW_TAG_pointer_type
:
4814 return "DW_TAG_pointer_type";
4815 case DW_TAG_reference_type
:
4816 return "DW_TAG_reference_type";
4817 case DW_TAG_compile_unit
:
4818 return "DW_TAG_compile_unit";
4819 case DW_TAG_string_type
:
4820 return "DW_TAG_string_type";
4821 case DW_TAG_structure_type
:
4822 return "DW_TAG_structure_type";
4823 case DW_TAG_subroutine_type
:
4824 return "DW_TAG_subroutine_type";
4825 case DW_TAG_typedef
:
4826 return "DW_TAG_typedef";
4827 case DW_TAG_union_type
:
4828 return "DW_TAG_union_type";
4829 case DW_TAG_unspecified_parameters
:
4830 return "DW_TAG_unspecified_parameters";
4831 case DW_TAG_variant
:
4832 return "DW_TAG_variant";
4833 case DW_TAG_common_block
:
4834 return "DW_TAG_common_block";
4835 case DW_TAG_common_inclusion
:
4836 return "DW_TAG_common_inclusion";
4837 case DW_TAG_inheritance
:
4838 return "DW_TAG_inheritance";
4839 case DW_TAG_inlined_subroutine
:
4840 return "DW_TAG_inlined_subroutine";
4842 return "DW_TAG_module";
4843 case DW_TAG_ptr_to_member_type
:
4844 return "DW_TAG_ptr_to_member_type";
4845 case DW_TAG_set_type
:
4846 return "DW_TAG_set_type";
4847 case DW_TAG_subrange_type
:
4848 return "DW_TAG_subrange_type";
4849 case DW_TAG_with_stmt
:
4850 return "DW_TAG_with_stmt";
4851 case DW_TAG_access_declaration
:
4852 return "DW_TAG_access_declaration";
4853 case DW_TAG_base_type
:
4854 return "DW_TAG_base_type";
4855 case DW_TAG_catch_block
:
4856 return "DW_TAG_catch_block";
4857 case DW_TAG_const_type
:
4858 return "DW_TAG_const_type";
4859 case DW_TAG_constant
:
4860 return "DW_TAG_constant";
4861 case DW_TAG_enumerator
:
4862 return "DW_TAG_enumerator";
4863 case DW_TAG_file_type
:
4864 return "DW_TAG_file_type";
4866 return "DW_TAG_friend";
4867 case DW_TAG_namelist
:
4868 return "DW_TAG_namelist";
4869 case DW_TAG_namelist_item
:
4870 return "DW_TAG_namelist_item";
4871 case DW_TAG_packed_type
:
4872 return "DW_TAG_packed_type";
4873 case DW_TAG_subprogram
:
4874 return "DW_TAG_subprogram";
4875 case DW_TAG_template_type_param
:
4876 return "DW_TAG_template_type_param";
4877 case DW_TAG_template_value_param
:
4878 return "DW_TAG_template_value_param";
4879 case DW_TAG_thrown_type
:
4880 return "DW_TAG_thrown_type";
4881 case DW_TAG_try_block
:
4882 return "DW_TAG_try_block";
4883 case DW_TAG_variant_part
:
4884 return "DW_TAG_variant_part";
4885 case DW_TAG_variable
:
4886 return "DW_TAG_variable";
4887 case DW_TAG_volatile_type
:
4888 return "DW_TAG_volatile_type";
4889 case DW_TAG_MIPS_loop
:
4890 return "DW_TAG_MIPS_loop";
4891 case DW_TAG_format_label
:
4892 return "DW_TAG_format_label";
4893 case DW_TAG_function_template
:
4894 return "DW_TAG_function_template";
4895 case DW_TAG_class_template
:
4896 return "DW_TAG_class_template";
4898 return "DW_TAG_<unknown>";
4902 /* Convert a DWARF attribute code into its string name. */
4905 dwarf_attr_name (register unsigned attr
)
4910 return "DW_AT_sibling";
4911 case DW_AT_location
:
4912 return "DW_AT_location";
4914 return "DW_AT_name";
4915 case DW_AT_ordering
:
4916 return "DW_AT_ordering";
4917 case DW_AT_subscr_data
:
4918 return "DW_AT_subscr_data";
4919 case DW_AT_byte_size
:
4920 return "DW_AT_byte_size";
4921 case DW_AT_bit_offset
:
4922 return "DW_AT_bit_offset";
4923 case DW_AT_bit_size
:
4924 return "DW_AT_bit_size";
4925 case DW_AT_element_list
:
4926 return "DW_AT_element_list";
4927 case DW_AT_stmt_list
:
4928 return "DW_AT_stmt_list";
4930 return "DW_AT_low_pc";
4932 return "DW_AT_high_pc";
4933 case DW_AT_language
:
4934 return "DW_AT_language";
4936 return "DW_AT_member";
4938 return "DW_AT_discr";
4939 case DW_AT_discr_value
:
4940 return "DW_AT_discr_value";
4941 case DW_AT_visibility
:
4942 return "DW_AT_visibility";
4944 return "DW_AT_import";
4945 case DW_AT_string_length
:
4946 return "DW_AT_string_length";
4947 case DW_AT_common_reference
:
4948 return "DW_AT_common_reference";
4949 case DW_AT_comp_dir
:
4950 return "DW_AT_comp_dir";
4951 case DW_AT_const_value
:
4952 return "DW_AT_const_value";
4953 case DW_AT_containing_type
:
4954 return "DW_AT_containing_type";
4955 case DW_AT_default_value
:
4956 return "DW_AT_default_value";
4958 return "DW_AT_inline";
4959 case DW_AT_is_optional
:
4960 return "DW_AT_is_optional";
4961 case DW_AT_lower_bound
:
4962 return "DW_AT_lower_bound";
4963 case DW_AT_producer
:
4964 return "DW_AT_producer";
4965 case DW_AT_prototyped
:
4966 return "DW_AT_prototyped";
4967 case DW_AT_return_addr
:
4968 return "DW_AT_return_addr";
4969 case DW_AT_start_scope
:
4970 return "DW_AT_start_scope";
4971 case DW_AT_stride_size
:
4972 return "DW_AT_stride_size";
4973 case DW_AT_upper_bound
:
4974 return "DW_AT_upper_bound";
4975 case DW_AT_abstract_origin
:
4976 return "DW_AT_abstract_origin";
4977 case DW_AT_accessibility
:
4978 return "DW_AT_accessibility";
4979 case DW_AT_address_class
:
4980 return "DW_AT_address_class";
4981 case DW_AT_artificial
:
4982 return "DW_AT_artificial";
4983 case DW_AT_base_types
:
4984 return "DW_AT_base_types";
4985 case DW_AT_calling_convention
:
4986 return "DW_AT_calling_convention";
4988 return "DW_AT_count";
4989 case DW_AT_data_member_location
:
4990 return "DW_AT_data_member_location";
4991 case DW_AT_decl_column
:
4992 return "DW_AT_decl_column";
4993 case DW_AT_decl_file
:
4994 return "DW_AT_decl_file";
4995 case DW_AT_decl_line
:
4996 return "DW_AT_decl_line";
4997 case DW_AT_declaration
:
4998 return "DW_AT_declaration";
4999 case DW_AT_discr_list
:
5000 return "DW_AT_discr_list";
5001 case DW_AT_encoding
:
5002 return "DW_AT_encoding";
5003 case DW_AT_external
:
5004 return "DW_AT_external";
5005 case DW_AT_frame_base
:
5006 return "DW_AT_frame_base";
5008 return "DW_AT_friend";
5009 case DW_AT_identifier_case
:
5010 return "DW_AT_identifier_case";
5011 case DW_AT_macro_info
:
5012 return "DW_AT_macro_info";
5013 case DW_AT_namelist_items
:
5014 return "DW_AT_namelist_items";
5015 case DW_AT_priority
:
5016 return "DW_AT_priority";
5018 return "DW_AT_segment";
5019 case DW_AT_specification
:
5020 return "DW_AT_specification";
5021 case DW_AT_static_link
:
5022 return "DW_AT_static_link";
5024 return "DW_AT_type";
5025 case DW_AT_use_location
:
5026 return "DW_AT_use_location";
5027 case DW_AT_variable_parameter
:
5028 return "DW_AT_variable_parameter";
5029 case DW_AT_virtuality
:
5030 return "DW_AT_virtuality";
5031 case DW_AT_vtable_elem_location
:
5032 return "DW_AT_vtable_elem_location";
5035 case DW_AT_MIPS_fde
:
5036 return "DW_AT_MIPS_fde";
5037 case DW_AT_MIPS_loop_begin
:
5038 return "DW_AT_MIPS_loop_begin";
5039 case DW_AT_MIPS_tail_loop_begin
:
5040 return "DW_AT_MIPS_tail_loop_begin";
5041 case DW_AT_MIPS_epilog_begin
:
5042 return "DW_AT_MIPS_epilog_begin";
5043 case DW_AT_MIPS_loop_unroll_factor
:
5044 return "DW_AT_MIPS_loop_unroll_factor";
5045 case DW_AT_MIPS_software_pipeline_depth
:
5046 return "DW_AT_MIPS_software_pipeline_depth";
5047 case DW_AT_MIPS_linkage_name
:
5048 return "DW_AT_MIPS_linkage_name";
5051 case DW_AT_sf_names
:
5052 return "DW_AT_sf_names";
5053 case DW_AT_src_info
:
5054 return "DW_AT_src_info";
5055 case DW_AT_mac_info
:
5056 return "DW_AT_mac_info";
5057 case DW_AT_src_coords
:
5058 return "DW_AT_src_coords";
5059 case DW_AT_body_begin
:
5060 return "DW_AT_body_begin";
5061 case DW_AT_body_end
:
5062 return "DW_AT_body_end";
5064 return "DW_AT_<unknown>";
5068 /* Convert a DWARF value form code into its string name. */
5071 dwarf_form_name (register unsigned form
)
5076 return "DW_FORM_addr";
5077 case DW_FORM_block2
:
5078 return "DW_FORM_block2";
5079 case DW_FORM_block4
:
5080 return "DW_FORM_block4";
5082 return "DW_FORM_data2";
5084 return "DW_FORM_data4";
5086 return "DW_FORM_data8";
5087 case DW_FORM_string
:
5088 return "DW_FORM_string";
5090 return "DW_FORM_block";
5091 case DW_FORM_block1
:
5092 return "DW_FORM_block1";
5094 return "DW_FORM_data1";
5096 return "DW_FORM_flag";
5098 return "DW_FORM_sdata";
5100 return "DW_FORM_strp";
5102 return "DW_FORM_udata";
5103 case DW_FORM_ref_addr
:
5104 return "DW_FORM_ref_addr";
5106 return "DW_FORM_ref1";
5108 return "DW_FORM_ref2";
5110 return "DW_FORM_ref4";
5112 return "DW_FORM_ref8";
5113 case DW_FORM_ref_udata
:
5114 return "DW_FORM_ref_udata";
5115 case DW_FORM_indirect
:
5116 return "DW_FORM_indirect";
5118 return "DW_FORM_<unknown>";
5122 /* Convert a DWARF stack opcode into its string name. */
5125 dwarf_stack_op_name (register unsigned op
)
5130 return "DW_OP_addr";
5132 return "DW_OP_deref";
5134 return "DW_OP_const1u";
5136 return "DW_OP_const1s";
5138 return "DW_OP_const2u";
5140 return "DW_OP_const2s";
5142 return "DW_OP_const4u";
5144 return "DW_OP_const4s";
5146 return "DW_OP_const8u";
5148 return "DW_OP_const8s";
5150 return "DW_OP_constu";
5152 return "DW_OP_consts";
5156 return "DW_OP_drop";
5158 return "DW_OP_over";
5160 return "DW_OP_pick";
5162 return "DW_OP_swap";
5166 return "DW_OP_xderef";
5174 return "DW_OP_minus";
5186 return "DW_OP_plus";
5187 case DW_OP_plus_uconst
:
5188 return "DW_OP_plus_uconst";
5194 return "DW_OP_shra";
5212 return "DW_OP_skip";
5214 return "DW_OP_lit0";
5216 return "DW_OP_lit1";
5218 return "DW_OP_lit2";
5220 return "DW_OP_lit3";
5222 return "DW_OP_lit4";
5224 return "DW_OP_lit5";
5226 return "DW_OP_lit6";
5228 return "DW_OP_lit7";
5230 return "DW_OP_lit8";
5232 return "DW_OP_lit9";
5234 return "DW_OP_lit10";
5236 return "DW_OP_lit11";
5238 return "DW_OP_lit12";
5240 return "DW_OP_lit13";
5242 return "DW_OP_lit14";
5244 return "DW_OP_lit15";
5246 return "DW_OP_lit16";
5248 return "DW_OP_lit17";
5250 return "DW_OP_lit18";
5252 return "DW_OP_lit19";
5254 return "DW_OP_lit20";
5256 return "DW_OP_lit21";
5258 return "DW_OP_lit22";
5260 return "DW_OP_lit23";
5262 return "DW_OP_lit24";
5264 return "DW_OP_lit25";
5266 return "DW_OP_lit26";
5268 return "DW_OP_lit27";
5270 return "DW_OP_lit28";
5272 return "DW_OP_lit29";
5274 return "DW_OP_lit30";
5276 return "DW_OP_lit31";
5278 return "DW_OP_reg0";
5280 return "DW_OP_reg1";
5282 return "DW_OP_reg2";
5284 return "DW_OP_reg3";
5286 return "DW_OP_reg4";
5288 return "DW_OP_reg5";
5290 return "DW_OP_reg6";
5292 return "DW_OP_reg7";
5294 return "DW_OP_reg8";
5296 return "DW_OP_reg9";
5298 return "DW_OP_reg10";
5300 return "DW_OP_reg11";
5302 return "DW_OP_reg12";
5304 return "DW_OP_reg13";
5306 return "DW_OP_reg14";
5308 return "DW_OP_reg15";
5310 return "DW_OP_reg16";
5312 return "DW_OP_reg17";
5314 return "DW_OP_reg18";
5316 return "DW_OP_reg19";
5318 return "DW_OP_reg20";
5320 return "DW_OP_reg21";
5322 return "DW_OP_reg22";
5324 return "DW_OP_reg23";
5326 return "DW_OP_reg24";
5328 return "DW_OP_reg25";
5330 return "DW_OP_reg26";
5332 return "DW_OP_reg27";
5334 return "DW_OP_reg28";
5336 return "DW_OP_reg29";
5338 return "DW_OP_reg30";
5340 return "DW_OP_reg31";
5342 return "DW_OP_breg0";
5344 return "DW_OP_breg1";
5346 return "DW_OP_breg2";
5348 return "DW_OP_breg3";
5350 return "DW_OP_breg4";
5352 return "DW_OP_breg5";
5354 return "DW_OP_breg6";
5356 return "DW_OP_breg7";
5358 return "DW_OP_breg8";
5360 return "DW_OP_breg9";
5362 return "DW_OP_breg10";
5364 return "DW_OP_breg11";
5366 return "DW_OP_breg12";
5368 return "DW_OP_breg13";
5370 return "DW_OP_breg14";
5372 return "DW_OP_breg15";
5374 return "DW_OP_breg16";
5376 return "DW_OP_breg17";
5378 return "DW_OP_breg18";
5380 return "DW_OP_breg19";
5382 return "DW_OP_breg20";
5384 return "DW_OP_breg21";
5386 return "DW_OP_breg22";
5388 return "DW_OP_breg23";
5390 return "DW_OP_breg24";
5392 return "DW_OP_breg25";
5394 return "DW_OP_breg26";
5396 return "DW_OP_breg27";
5398 return "DW_OP_breg28";
5400 return "DW_OP_breg29";
5402 return "DW_OP_breg30";
5404 return "DW_OP_breg31";
5406 return "DW_OP_regx";
5408 return "DW_OP_fbreg";
5410 return "DW_OP_bregx";
5412 return "DW_OP_piece";
5413 case DW_OP_deref_size
:
5414 return "DW_OP_deref_size";
5415 case DW_OP_xderef_size
:
5416 return "DW_OP_xderef_size";
5420 return "OP_<unknown>";
5425 dwarf_bool_name (unsigned mybool
)
5433 /* Convert a DWARF type code into its string name. */
5436 dwarf_type_encoding_name (register unsigned enc
)
5440 case DW_ATE_address
:
5441 return "DW_ATE_address";
5442 case DW_ATE_boolean
:
5443 return "DW_ATE_boolean";
5444 case DW_ATE_complex_float
:
5445 return "DW_ATE_complex_float";
5447 return "DW_ATE_float";
5449 return "DW_ATE_signed";
5450 case DW_ATE_signed_char
:
5451 return "DW_ATE_signed_char";
5452 case DW_ATE_unsigned
:
5453 return "DW_ATE_unsigned";
5454 case DW_ATE_unsigned_char
:
5455 return "DW_ATE_unsigned_char";
5457 return "DW_ATE_<unknown>";
5461 /* Convert a DWARF call frame info operation to its string name. */
5465 dwarf_cfi_name (register unsigned cfi_opc
)
5469 case DW_CFA_advance_loc
:
5470 return "DW_CFA_advance_loc";
5472 return "DW_CFA_offset";
5473 case DW_CFA_restore
:
5474 return "DW_CFA_restore";
5476 return "DW_CFA_nop";
5477 case DW_CFA_set_loc
:
5478 return "DW_CFA_set_loc";
5479 case DW_CFA_advance_loc1
:
5480 return "DW_CFA_advance_loc1";
5481 case DW_CFA_advance_loc2
:
5482 return "DW_CFA_advance_loc2";
5483 case DW_CFA_advance_loc4
:
5484 return "DW_CFA_advance_loc4";
5485 case DW_CFA_offset_extended
:
5486 return "DW_CFA_offset_extended";
5487 case DW_CFA_restore_extended
:
5488 return "DW_CFA_restore_extended";
5489 case DW_CFA_undefined
:
5490 return "DW_CFA_undefined";
5491 case DW_CFA_same_value
:
5492 return "DW_CFA_same_value";
5493 case DW_CFA_register
:
5494 return "DW_CFA_register";
5495 case DW_CFA_remember_state
:
5496 return "DW_CFA_remember_state";
5497 case DW_CFA_restore_state
:
5498 return "DW_CFA_restore_state";
5499 case DW_CFA_def_cfa
:
5500 return "DW_CFA_def_cfa";
5501 case DW_CFA_def_cfa_register
:
5502 return "DW_CFA_def_cfa_register";
5503 case DW_CFA_def_cfa_offset
:
5504 return "DW_CFA_def_cfa_offset";
5505 /* SGI/MIPS specific */
5506 case DW_CFA_MIPS_advance_loc8
:
5507 return "DW_CFA_MIPS_advance_loc8";
5509 return "DW_CFA_<unknown>";
5515 dump_die (struct die_info
*die
)
5519 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5520 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5521 fprintf (stderr
, "\thas children: %s\n",
5522 dwarf_bool_name (die
->has_children
));
5524 fprintf (stderr
, "\tattributes:\n");
5525 for (i
= 0; i
< die
->num_attrs
; ++i
)
5527 fprintf (stderr
, "\t\t%s (%s) ",
5528 dwarf_attr_name (die
->attrs
[i
].name
),
5529 dwarf_form_name (die
->attrs
[i
].form
));
5530 switch (die
->attrs
[i
].form
)
5532 case DW_FORM_ref_addr
:
5534 fprintf (stderr
, "address: ");
5535 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5537 case DW_FORM_block2
:
5538 case DW_FORM_block4
:
5540 case DW_FORM_block1
:
5541 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5552 fprintf (stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
5554 case DW_FORM_string
:
5555 fprintf (stderr
, "string: \"%s\"",
5556 DW_STRING (&die
->attrs
[i
])
5557 ? DW_STRING (&die
->attrs
[i
]) : "");
5560 if (DW_UNSND (&die
->attrs
[i
]))
5561 fprintf (stderr
, "flag: TRUE");
5563 fprintf (stderr
, "flag: FALSE");
5565 case DW_FORM_strp
: /* we do not support separate string
5567 case DW_FORM_indirect
: /* we do not handle indirect yet */
5569 fprintf (stderr
, "unsupported attribute form: %d.",
5570 die
->attrs
[i
].form
);
5572 fprintf (stderr
, "\n");
5577 dump_die_list (struct die_info
*die
)
5587 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
5590 struct die_info
*old
;
5592 h
= (offset
% REF_HASH_SIZE
);
5593 old
= die_ref_table
[h
];
5594 die
->next_ref
= old
;
5595 die_ref_table
[h
] = die
;
5600 dwarf2_empty_hash_tables (void)
5602 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5603 memset (dwarf2_cached_types
, 0, sizeof(dwarf2_cached_types
));
5607 dwarf2_get_ref_die_offset (struct attribute
*attr
)
5609 unsigned int result
= 0;
5613 case DW_FORM_ref_addr
:
5614 result
= DW_ADDR (attr
);
5620 case DW_FORM_ref_udata
:
5621 result
= cu_header_offset
+ DW_UNSND (attr
);
5624 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5630 follow_die_ref (unsigned int offset
)
5632 struct die_info
*die
;
5635 h
= (offset
% REF_HASH_SIZE
);
5636 die
= die_ref_table
[h
];
5639 if (die
->offset
== offset
)
5643 die
= die
->next_ref
;
5648 static struct type
*
5649 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
5651 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5653 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5657 /* Look for this particular type in the fundamental type vector. If
5658 one is not found, create and install one appropriate for the
5659 current language and the current target machine. */
5661 if (ftypes
[typeid] == NULL
)
5663 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5666 return (ftypes
[typeid]);
5669 /* Decode simple location descriptions.
5670 Given a pointer to a dwarf block that defines a location, compute
5671 the location and return the value.
5673 FIXME: This is a kludge until we figure out a better
5674 way to handle the location descriptions.
5675 Gdb's design does not mesh well with the DWARF2 notion of a location
5676 computing interpreter, which is a shame because the flexibility goes unused.
5677 FIXME: Implement more operations as necessary.
5679 A location description containing no operations indicates that the
5680 object is optimized out. The global optimized_out flag is set for
5681 those, the return value is meaningless.
5683 When the result is a register number, the global isreg flag is set,
5684 otherwise it is cleared.
5686 When the result is a base register offset, the global offreg flag is set
5687 and the register number is returned in basereg, otherwise it is cleared.
5689 When the DW_OP_fbreg operation is encountered without a corresponding
5690 DW_AT_frame_base attribute, the global islocal flag is set.
5691 Hopefully the machine dependent code knows how to set up a virtual
5692 frame pointer for the local references.
5694 Note that stack[0] is unused except as a default error return.
5695 Note that stack overflow is not yet handled. */
5698 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
5699 const struct comp_unit_head
*cu_header
)
5702 int size
= blk
->size
;
5703 char *data
= blk
->data
;
5704 CORE_ADDR stack
[64];
5706 unsigned int bytes_read
, unsnd
;
5757 stack
[++stacki
] = op
- DW_OP_reg0
;
5762 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5764 #if defined(HARRIS_TARGET) && defined(_M88K)
5765 /* The Harris 88110 gdb ports have long kept their special reg
5766 numbers between their gp-regs and their x-regs. This is
5767 not how our dwarf is generated. Punt. */
5770 stack
[++stacki
] = unsnd
;
5806 basereg
= op
- DW_OP_breg0
;
5807 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5813 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5815 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5820 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5822 if (frame_base_reg
>= 0)
5825 basereg
= frame_base_reg
;
5826 stack
[stacki
] += frame_base_offset
;
5830 complain (&dwarf2_missing_at_frame_base
);
5836 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
5837 cu_header
, &bytes_read
);
5842 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5847 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5852 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5857 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5862 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5867 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5872 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5878 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5883 stack
[stacki
- 1] += stack
[stacki
];
5887 case DW_OP_plus_uconst
:
5888 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5893 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5899 /* If we're not the last op, then we definitely can't encode
5900 this using GDB's address_class enum. */
5902 complain (&dwarf2_complex_location_expr
);
5906 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
5907 return (stack
[stacki
]);
5910 return (stack
[stacki
]);
5913 /* memory allocation interface */
5917 dwarf2_free_tmp_obstack (PTR ignore
)
5919 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5922 static struct dwarf_block
*
5923 dwarf_alloc_block (void)
5925 struct dwarf_block
*blk
;
5927 blk
= (struct dwarf_block
*)
5928 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5932 static struct abbrev_info
*
5933 dwarf_alloc_abbrev (void)
5935 struct abbrev_info
*abbrev
;
5937 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5938 memset (abbrev
, 0, sizeof (struct abbrev_info
));
5942 static struct die_info
*
5943 dwarf_alloc_die (void)
5945 struct die_info
*die
;
5947 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5948 memset (die
, 0, sizeof (struct die_info
));