1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
10 support in dwarfread.c
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or (at
17 your option) any later version.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. */
35 #include "elf/dwarf2.h"
38 #include "expression.h"
39 #include "filenames.h" /* for DOSish file names */
42 #include "complaints.h"
45 #include "gdb_string.h"
46 #include <sys/types.h>
48 #ifndef DWARF2_REG_TO_REGNUM
49 #define DWARF2_REG_TO_REGNUM(REG) (REG)
53 /* .debug_info header for a compilation unit
54 Because of alignment constraints, this structure has padding and cannot
55 be mapped directly onto the beginning of the .debug_info section. */
56 typedef struct comp_unit_header
58 unsigned int length
; /* length of the .debug_info
60 unsigned short version
; /* version number -- 2 for DWARF
62 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
63 unsigned char addr_size
; /* byte size of an address -- 4 */
66 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
69 /* .debug_pubnames header
70 Because of alignment constraints, this structure has padding and cannot
71 be mapped directly onto the beginning of the .debug_info section. */
72 typedef struct pubnames_header
74 unsigned int length
; /* length of the .debug_pubnames
76 unsigned char version
; /* version number -- 2 for DWARF
78 unsigned int info_offset
; /* offset into .debug_info section */
79 unsigned int info_size
; /* byte size of .debug_info section
83 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
85 /* .debug_pubnames header
86 Because of alignment constraints, this structure has padding and cannot
87 be mapped directly onto the beginning of the .debug_info section. */
88 typedef struct aranges_header
90 unsigned int length
; /* byte len of the .debug_aranges
92 unsigned short version
; /* version number -- 2 for DWARF
94 unsigned int info_offset
; /* offset into .debug_info section */
95 unsigned char addr_size
; /* byte size of an address */
96 unsigned char seg_size
; /* byte size of segment descriptor */
99 #define _ACTUAL_ARANGES_HEADER_SIZE 12
101 /* .debug_line statement program prologue
102 Because of alignment constraints, this structure has padding and cannot
103 be mapped directly onto the beginning of the .debug_info section. */
104 typedef struct statement_prologue
106 unsigned int total_length
; /* byte length of the statement
108 unsigned short version
; /* version number -- 2 for DWARF
110 unsigned int prologue_length
; /* # bytes between prologue &
112 unsigned char minimum_instruction_length
; /* byte size of
114 unsigned char default_is_stmt
; /* initial value of is_stmt
117 unsigned char line_range
;
118 unsigned char opcode_base
; /* number assigned to first special
120 unsigned char *standard_opcode_lengths
;
124 /* offsets and sizes of debugging sections */
126 static file_ptr dwarf_info_offset
;
127 static file_ptr dwarf_abbrev_offset
;
128 static file_ptr dwarf_line_offset
;
129 static file_ptr dwarf_pubnames_offset
;
130 static file_ptr dwarf_aranges_offset
;
131 static file_ptr dwarf_loc_offset
;
132 static file_ptr dwarf_macinfo_offset
;
133 static file_ptr dwarf_str_offset
;
135 static unsigned int dwarf_info_size
;
136 static unsigned int dwarf_abbrev_size
;
137 static unsigned int dwarf_line_size
;
138 static unsigned int dwarf_pubnames_size
;
139 static unsigned int dwarf_aranges_size
;
140 static unsigned int dwarf_loc_size
;
141 static unsigned int dwarf_macinfo_size
;
142 static unsigned int dwarf_str_size
;
144 /* names of the debugging sections */
146 #define INFO_SECTION ".debug_info"
147 #define ABBREV_SECTION ".debug_abbrev"
148 #define LINE_SECTION ".debug_line"
149 #define PUBNAMES_SECTION ".debug_pubnames"
150 #define ARANGES_SECTION ".debug_aranges"
151 #define LOC_SECTION ".debug_loc"
152 #define MACINFO_SECTION ".debug_macinfo"
153 #define STR_SECTION ".debug_str"
155 /* local data types */
157 /* The data in a compilation unit header, after target2host
158 translation, looks like this. */
159 struct comp_unit_head
161 unsigned long length
;
163 unsigned int abbrev_offset
;
164 unsigned char addr_size
;
165 unsigned char signed_addr_p
;
166 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
167 unsigned int initial_length_size
; /* size of the length field; either
171 /* The data in the .debug_line statement prologue looks like this. */
174 unsigned int total_length
;
175 unsigned short version
;
176 unsigned int prologue_length
;
177 unsigned char minimum_instruction_length
;
178 unsigned char default_is_stmt
;
180 unsigned char line_range
;
181 unsigned char opcode_base
;
182 unsigned char *standard_opcode_lengths
;
185 /* When we construct a partial symbol table entry we only
186 need this much information. */
187 struct partial_die_info
190 unsigned char has_children
;
191 unsigned char is_external
;
192 unsigned char is_declaration
;
193 unsigned char has_type
;
200 struct dwarf_block
*locdesc
;
201 unsigned int language
;
205 /* This data structure holds the information of an abbrev. */
208 unsigned int number
; /* number identifying abbrev */
209 enum dwarf_tag tag
; /* dwarf tag */
210 int has_children
; /* boolean */
211 unsigned int num_attrs
; /* number of attributes */
212 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
213 struct abbrev_info
*next
; /* next in chain */
218 enum dwarf_attribute name
;
219 enum dwarf_form form
;
222 /* This data structure holds a complete die structure. */
225 enum dwarf_tag tag
; /* Tag indicating type of die */
226 unsigned short has_children
; /* Does the die have children */
227 unsigned int abbrev
; /* Abbrev number */
228 unsigned int offset
; /* Offset in .debug_info section */
229 unsigned int num_attrs
; /* Number of attributes */
230 struct attribute
*attrs
; /* An array of attributes */
231 struct die_info
*next_ref
; /* Next die in ref hash table */
232 struct die_info
*next
; /* Next die in linked list */
233 struct type
*type
; /* Cached type information */
236 /* Attributes have a name and a value */
239 enum dwarf_attribute name
;
240 enum dwarf_form form
;
244 struct dwarf_block
*blk
;
252 /* Get at parts of an attribute structure */
254 #define DW_STRING(attr) ((attr)->u.str)
255 #define DW_UNSND(attr) ((attr)->u.unsnd)
256 #define DW_BLOCK(attr) ((attr)->u.blk)
257 #define DW_SND(attr) ((attr)->u.snd)
258 #define DW_ADDR(attr) ((attr)->u.addr)
260 /* Blocks are a bunch of untyped bytes. */
267 /* We only hold one compilation unit's abbrevs in
268 memory at any one time. */
269 #ifndef ABBREV_HASH_SIZE
270 #define ABBREV_HASH_SIZE 121
272 #ifndef ATTR_ALLOC_CHUNK
273 #define ATTR_ALLOC_CHUNK 4
276 static struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
278 /* A hash table of die offsets for following references. */
279 #ifndef REF_HASH_SIZE
280 #define REF_HASH_SIZE 1021
283 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
285 /* Obstack for allocating temporary storage used during symbol reading. */
286 static struct obstack dwarf2_tmp_obstack
;
288 /* Offset to the first byte of the current compilation unit header,
289 for resolving relative reference dies. */
290 static unsigned int cu_header_offset
;
292 /* Allocate fields for structs, unions and enums in this size. */
293 #ifndef DW_FIELD_ALLOC_CHUNK
294 #define DW_FIELD_ALLOC_CHUNK 4
297 /* The language we are debugging. */
298 static enum language cu_language
;
299 static const struct language_defn
*cu_language_defn
;
301 /* Actually data from the sections. */
302 static char *dwarf_info_buffer
;
303 static char *dwarf_abbrev_buffer
;
304 static char *dwarf_line_buffer
;
306 /* A zeroed version of a partial die for initialization purposes. */
307 static struct partial_die_info zeroed_partial_die
;
309 /* The generic symbol table building routines have separate lists for
310 file scope symbols and all all other scopes (local scopes). So
311 we need to select the right one to pass to add_symbol_to_list().
312 We do it by keeping a pointer to the correct list in list_in_scope.
314 FIXME: The original dwarf code just treated the file scope as the first
315 local scope, and all other local scopes as nested local scopes, and worked
316 fine. Check to see if we really need to distinguish these
318 static struct pending
**list_in_scope
= &file_symbols
;
320 /* FIXME: decode_locdesc sets these variables to describe the location
321 to the caller. These ought to be a structure or something. If
322 none of the flags are set, the object lives at the address returned
323 by decode_locdesc. */
325 static int optimized_out
; /* No ops in location in expression,
326 so object was optimized out. */
327 static int isreg
; /* Object lives in register.
328 decode_locdesc's return value is
329 the register number. */
330 static int offreg
; /* Object's address is the sum of the
331 register specified by basereg, plus
332 the offset returned. */
333 static int basereg
; /* See `offreg'. */
334 static int isderef
; /* Value described by flags above is
335 the address of a pointer to the object. */
336 static int islocal
; /* Variable is at the returned offset
337 from the frame start, but there's
338 no identified frame pointer for
339 this function, so we can't say
340 which register it's relative to;
343 /* DW_AT_frame_base values for the current function.
344 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
345 contains the register number for the frame register.
346 frame_base_offset is the offset from the frame register to the
347 virtual stack frame. */
348 static int frame_base_reg
;
349 static CORE_ADDR frame_base_offset
;
351 /* This value is added to each symbol value. FIXME: Generalize to
352 the section_offsets structure used by dbxread (once this is done,
353 pass the appropriate section number to end_symtab). */
354 static CORE_ADDR baseaddr
; /* Add to each symbol value */
356 /* We put a pointer to this structure in the read_symtab_private field
358 The complete dwarf information for an objfile is kept in the
359 psymbol_obstack, so that absolute die references can be handled.
360 Most of the information in this structure is related to an entire
361 object file and could be passed via the sym_private field of the objfile.
362 It is however conceivable that dwarf2 might not be the only type
363 of symbols read from an object file. */
367 /* Pointer to start of dwarf info buffer for the objfile. */
369 char *dwarf_info_buffer
;
371 /* Offset in dwarf_info_buffer for this compilation unit. */
373 unsigned long dwarf_info_offset
;
375 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
377 char *dwarf_abbrev_buffer
;
379 /* Size of dwarf abbreviation section for the objfile. */
381 unsigned int dwarf_abbrev_size
;
383 /* Pointer to start of dwarf line buffer for the objfile. */
385 char *dwarf_line_buffer
;
388 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
389 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
390 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
391 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
392 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
393 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
395 /* Maintain an array of referenced fundamental types for the current
396 compilation unit being read. For DWARF version 1, we have to construct
397 the fundamental types on the fly, since no information about the
398 fundamental types is supplied. Each such fundamental type is created by
399 calling a language dependent routine to create the type, and then a
400 pointer to that type is then placed in the array at the index specified
401 by it's FT_<TYPENAME> value. The array has a fixed size set by the
402 FT_NUM_MEMBERS compile time constant, which is the number of predefined
403 fundamental types gdb knows how to construct. */
404 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
406 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
407 but this would require a corresponding change in unpack_field_as_long
409 static int bits_per_byte
= 8;
411 /* The routines that read and process dies for a C struct or C++ class
412 pass lists of data member fields and lists of member function fields
413 in an instance of a field_info structure, as defined below. */
416 /* List of data member and baseclasses fields. */
419 struct nextfield
*next
;
426 /* Number of fields. */
429 /* Number of baseclasses. */
432 /* Set if the accesibility of one of the fields is not public. */
433 int non_public_fields
;
435 /* Member function fields array, entries are allocated in the order they
436 are encountered in the object file. */
439 struct nextfnfield
*next
;
440 struct fn_field fnfield
;
444 /* Member function fieldlist array, contains name of possibly overloaded
445 member function, number of overloaded member functions and a pointer
446 to the head of the member function field chain. */
451 struct nextfnfield
*head
;
455 /* Number of entries in the fnfieldlists array. */
459 /* FIXME: Kludge to mark a varargs function type for C++ member function
460 argument processing. */
461 #define TYPE_FLAG_VARARGS (1 << 10)
463 /* Dwarf2 has no clean way to discern C++ static and non-static member
464 functions. G++ helps GDB by marking the first parameter for non-static
465 member functions (which is the this pointer) as artificial.
466 We pass this information between dwarf2_add_member_fn and
467 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
468 #define TYPE_FIELD_ARTIFICIAL TYPE_FIELD_BITPOS
470 /* Various complaints about symbol reading that don't abort the process */
472 static struct complaint dwarf2_const_ignored
=
474 "type qualifier 'const' ignored", 0, 0
476 static struct complaint dwarf2_volatile_ignored
=
478 "type qualifier 'volatile' ignored", 0, 0
480 static struct complaint dwarf2_non_const_array_bound_ignored
=
482 "non-constant array bounds form '%s' ignored", 0, 0
484 static struct complaint dwarf2_missing_line_number_section
=
486 "missing .debug_line section", 0, 0
488 static struct complaint dwarf2_mangled_line_number_section
=
490 "mangled .debug_line section", 0, 0
492 static struct complaint dwarf2_unsupported_die_ref_attr
=
494 "unsupported die ref attribute form: '%s'", 0, 0
496 static struct complaint dwarf2_unsupported_stack_op
=
498 "unsupported stack op: '%s'", 0, 0
500 static struct complaint dwarf2_complex_location_expr
=
502 "location expression too complex", 0, 0
504 static struct complaint dwarf2_unsupported_tag
=
506 "unsupported tag: '%s'", 0, 0
508 static struct complaint dwarf2_unsupported_at_encoding
=
510 "unsupported DW_AT_encoding: '%s'", 0, 0
512 static struct complaint dwarf2_unsupported_at_frame_base
=
514 "unsupported DW_AT_frame_base for function '%s'", 0, 0
516 static struct complaint dwarf2_unexpected_tag
=
518 "unexepected tag in read_type_die: '%s'", 0, 0
520 static struct complaint dwarf2_missing_at_frame_base
=
522 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
524 static struct complaint dwarf2_bad_static_member_name
=
526 "unrecognized static data member name '%s'", 0, 0
528 static struct complaint dwarf2_unsupported_accessibility
=
530 "unsupported accessibility %d", 0, 0
532 static struct complaint dwarf2_bad_member_name_complaint
=
534 "cannot extract member name from '%s'", 0, 0
536 static struct complaint dwarf2_missing_member_fn_type_complaint
=
538 "member function type missing for '%s'", 0, 0
540 static struct complaint dwarf2_vtbl_not_found_complaint
=
542 "virtual function table pointer not found when defining class '%s'", 0, 0
544 static struct complaint dwarf2_absolute_sibling_complaint
=
546 "ignoring absolute DW_AT_sibling", 0, 0
548 static struct complaint dwarf2_const_value_length_mismatch
=
550 "const value length mismatch for '%s', got %d, expected %d", 0, 0
552 static struct complaint dwarf2_unsupported_const_value_attr
=
554 "unsupported const value attribute form: '%s'", 0, 0
557 /* Externals references. */
558 extern int info_verbose
; /* From main.c; nonzero => verbose */
560 /* local function prototypes */
562 static void dwarf2_locate_sections (bfd
*, asection
*, PTR
);
565 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
568 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
570 static char *scan_partial_symbols (char *, struct objfile
*,
571 CORE_ADDR
*, CORE_ADDR
*,
572 const struct comp_unit_head
*);
574 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
575 const struct comp_unit_head
*);
577 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
579 static void psymtab_to_symtab_1 (struct partial_symtab
*);
581 static char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int);
583 static void dwarf2_read_abbrevs (bfd
*, unsigned int);
585 static void dwarf2_empty_abbrev_table (PTR
);
587 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int);
589 static char *read_partial_die (struct partial_die_info
*,
591 const struct comp_unit_head
*);
593 static char *read_full_die (struct die_info
**, bfd
*, char *,
594 const struct comp_unit_head
*);
596 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
597 bfd
*, char *, const struct comp_unit_head
*);
599 static unsigned int read_1_byte (bfd
*, char *);
601 static int read_1_signed_byte (bfd
*, char *);
603 static unsigned int read_2_bytes (bfd
*, char *);
605 static unsigned int read_4_bytes (bfd
*, char *);
607 static unsigned long read_8_bytes (bfd
*, char *);
609 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
612 static LONGEST
read_initial_length (bfd
*, char *,
613 struct comp_unit_head
*, int *bytes_read
);
615 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
618 static char *read_n_bytes (bfd
*, char *, unsigned int);
620 static char *read_string (bfd
*, char *, unsigned int *);
622 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
624 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
626 static void set_cu_language (unsigned int);
628 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
630 static int die_is_declaration (struct die_info
*);
632 static void dwarf_decode_lines (unsigned int, char *, bfd
*,
633 const struct comp_unit_head
*);
635 static void dwarf2_start_subfile (char *, char *);
637 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
638 struct objfile
*, const struct comp_unit_head
*);
640 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
641 struct objfile
*, const struct comp_unit_head
*);
643 static void dwarf2_const_value_data (struct attribute
*attr
,
647 static struct type
*die_type (struct die_info
*, struct objfile
*,
648 const struct comp_unit_head
*);
650 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
651 const struct comp_unit_head
*);
654 static struct type
*type_at_offset (unsigned int, struct objfile
*);
657 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
658 const struct comp_unit_head
*);
660 static void read_type_die (struct die_info
*, struct objfile
*,
661 const struct comp_unit_head
*);
663 static void read_typedef (struct die_info
*, struct objfile
*,
664 const struct comp_unit_head
*);
666 static void read_base_type (struct die_info
*, struct objfile
*);
668 static void read_file_scope (struct die_info
*, struct objfile
*,
669 const struct comp_unit_head
*);
671 static void read_func_scope (struct die_info
*, struct objfile
*,
672 const struct comp_unit_head
*);
674 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
675 const struct comp_unit_head
*);
677 static int dwarf2_get_pc_bounds (struct die_info
*,
678 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*);
680 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
681 struct objfile
*, const struct comp_unit_head
*);
683 static void dwarf2_attach_fields_to_type (struct field_info
*,
684 struct type
*, struct objfile
*);
686 static void dwarf2_add_member_fn (struct field_info
*,
687 struct die_info
*, struct type
*,
688 struct objfile
*objfile
,
689 const struct comp_unit_head
*);
691 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
692 struct type
*, struct objfile
*);
694 static void read_structure_scope (struct die_info
*, struct objfile
*,
695 const struct comp_unit_head
*);
697 static void read_common_block (struct die_info
*, struct objfile
*,
698 const struct comp_unit_head
*);
700 static void read_enumeration (struct die_info
*, struct objfile
*,
701 const struct comp_unit_head
*);
703 static struct type
*dwarf_base_type (int, int, struct objfile
*);
705 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
706 const struct comp_unit_head
*);
708 static void read_array_type (struct die_info
*, struct objfile
*,
709 const struct comp_unit_head
*);
711 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
712 const struct comp_unit_head
*);
714 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
715 const struct comp_unit_head
*);
717 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
718 const struct comp_unit_head
*);
720 static void read_tag_const_type (struct die_info
*, struct objfile
*,
721 const struct comp_unit_head
*);
723 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
724 const struct comp_unit_head
*);
726 static void read_tag_string_type (struct die_info
*, struct objfile
*);
728 static void read_subroutine_type (struct die_info
*, struct objfile
*,
729 const struct comp_unit_head
*);
731 static struct die_info
*read_comp_unit (char *, bfd
*,
732 const struct comp_unit_head
*);
734 static void free_die_list (struct die_info
*);
736 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
738 static void process_die (struct die_info
*, struct objfile
*,
739 const struct comp_unit_head
*);
741 static char *dwarf2_linkage_name (struct die_info
*);
743 static char *dwarf_tag_name (unsigned int);
745 static char *dwarf_attr_name (unsigned int);
747 static char *dwarf_form_name (unsigned int);
749 static char *dwarf_stack_op_name (unsigned int);
751 static char *dwarf_bool_name (unsigned int);
753 static char *dwarf_type_encoding_name (unsigned int);
756 static char *dwarf_cfi_name (unsigned int);
758 struct die_info
*copy_die (struct die_info
*);
761 static struct die_info
*sibling_die (struct die_info
*);
763 static void dump_die (struct die_info
*);
765 static void dump_die_list (struct die_info
*);
767 static void store_in_ref_table (unsigned int, struct die_info
*);
769 static void dwarf2_empty_hash_tables (void);
771 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
773 static struct die_info
*follow_die_ref (unsigned int);
775 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
777 /* memory allocation interface */
779 static void dwarf2_free_tmp_obstack (PTR
);
781 static struct dwarf_block
*dwarf_alloc_block (void);
783 static struct abbrev_info
*dwarf_alloc_abbrev (void);
785 static struct die_info
*dwarf_alloc_die (void);
787 /* Try to locate the sections we need for DWARF 2 debugging
788 information and return true if we have enough to do something. */
791 dwarf2_has_info (bfd
*abfd
)
793 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
794 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
795 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
805 /* This function is mapped across the sections and remembers the
806 offset and size of each of the debugging sections we are interested
810 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, PTR ignore_ptr
)
812 if (STREQ (sectp
->name
, INFO_SECTION
))
814 dwarf_info_offset
= sectp
->filepos
;
815 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
817 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
819 dwarf_abbrev_offset
= sectp
->filepos
;
820 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
822 else if (STREQ (sectp
->name
, LINE_SECTION
))
824 dwarf_line_offset
= sectp
->filepos
;
825 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
827 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
829 dwarf_pubnames_offset
= sectp
->filepos
;
830 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
832 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
834 dwarf_aranges_offset
= sectp
->filepos
;
835 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
837 else if (STREQ (sectp
->name
, LOC_SECTION
))
839 dwarf_loc_offset
= sectp
->filepos
;
840 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
842 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
844 dwarf_macinfo_offset
= sectp
->filepos
;
845 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
847 else if (STREQ (sectp
->name
, STR_SECTION
))
849 dwarf_str_offset
= sectp
->filepos
;
850 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
854 /* Build a partial symbol table. */
857 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
860 /* We definitely need the .debug_info and .debug_abbrev sections */
862 dwarf_info_buffer
= dwarf2_read_section (objfile
,
865 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
868 dwarf_line_buffer
= dwarf2_read_section (objfile
,
872 if (mainline
|| objfile
->global_psymbols
.size
== 0 ||
873 objfile
->static_psymbols
.size
== 0)
875 init_psymbol_list (objfile
, 1024);
879 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
881 /* Things are significantly easier if we have .debug_aranges and
882 .debug_pubnames sections */
884 dwarf2_build_psymtabs_easy (objfile
, mainline
);
888 /* only test this case for now */
890 /* In this case we have to work a bit harder */
891 dwarf2_build_psymtabs_hard (objfile
, mainline
);
896 /* Build the partial symbol table from the information in the
897 .debug_pubnames and .debug_aranges sections. */
900 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
902 bfd
*abfd
= objfile
->obfd
;
903 char *aranges_buffer
, *pubnames_buffer
;
904 char *aranges_ptr
, *pubnames_ptr
;
905 unsigned int entry_length
, version
, info_offset
, info_size
;
907 pubnames_buffer
= dwarf2_read_section (objfile
,
908 dwarf_pubnames_offset
,
909 dwarf_pubnames_size
);
910 pubnames_ptr
= pubnames_buffer
;
911 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
913 struct comp_unit_head cu_header
;
916 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
918 pubnames_ptr
+= bytes_read
;
919 version
= read_1_byte (abfd
, pubnames_ptr
);
921 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
923 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
927 aranges_buffer
= dwarf2_read_section (objfile
,
928 dwarf_aranges_offset
,
934 /* Read in the comp unit header information from the debug_info at
938 read_comp_unit_head (struct comp_unit_head
*cu_header
,
939 char *info_ptr
, bfd
*abfd
)
943 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
945 info_ptr
+= bytes_read
;
946 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
948 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
950 info_ptr
+= bytes_read
;
951 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
953 signed_addr
= bfd_get_sign_extend_vma (abfd
);
955 internal_error (__FILE__
, __LINE__
,
956 "read_comp_unit_head: dwarf from non elf file");
957 cu_header
->signed_addr_p
= signed_addr
;
961 /* Build the partial symbol table by doing a quick pass through the
962 .debug_info and .debug_abbrev sections. */
965 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
967 /* Instead of reading this into a big buffer, we should probably use
968 mmap() on architectures that support it. (FIXME) */
969 bfd
*abfd
= objfile
->obfd
;
970 char *info_ptr
, *abbrev_ptr
;
971 char *beg_of_comp_unit
;
972 struct partial_die_info comp_unit_die
;
973 struct partial_symtab
*pst
;
974 struct cleanup
*back_to
;
975 CORE_ADDR lowpc
, highpc
;
977 info_ptr
= dwarf_info_buffer
;
978 abbrev_ptr
= dwarf_abbrev_buffer
;
980 obstack_init (&dwarf2_tmp_obstack
);
981 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
983 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
985 struct comp_unit_head cu_header
;
986 beg_of_comp_unit
= info_ptr
;
987 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
989 if (cu_header
.version
!= 2)
991 error ("Dwarf Error: wrong version in compilation unit header.");
994 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
996 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
997 (long) cu_header
.abbrev_offset
,
998 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1001 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1002 > dwarf_info_buffer
+ dwarf_info_size
)
1004 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
1005 (long) cu_header
.length
,
1006 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1009 /* Read the abbrevs for this compilation unit into a table */
1010 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1011 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1013 /* Read the compilation unit die */
1014 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1017 /* Set the language we're debugging */
1018 set_cu_language (comp_unit_die
.language
);
1020 /* Allocate a new partial symbol table structure */
1021 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1022 comp_unit_die
.name
? comp_unit_die
.name
: "",
1023 comp_unit_die
.lowpc
,
1024 objfile
->global_psymbols
.next
,
1025 objfile
->static_psymbols
.next
);
1027 pst
->read_symtab_private
= (char *)
1028 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1029 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1030 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1031 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1032 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1033 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1034 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1035 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1037 /* Store the function that reads in the rest of the symbol table */
1038 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1040 /* Check if comp unit has_children.
1041 If so, read the rest of the partial symbols from this comp unit.
1042 If not, there's no more debug_info for this comp unit. */
1043 if (comp_unit_die
.has_children
)
1045 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1048 /* If the compilation unit didn't have an explicit address range,
1049 then use the information extracted from its child dies. */
1050 if (! comp_unit_die
.has_pc_info
)
1052 comp_unit_die
.lowpc
= lowpc
;
1053 comp_unit_die
.highpc
= highpc
;
1056 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1057 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1059 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1060 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1061 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1062 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1063 sort_pst_symbols (pst
);
1065 /* If there is already a psymtab or symtab for a file of this
1066 name, remove it. (If there is a symtab, more drastic things
1067 also happen.) This happens in VxWorks. */
1068 free_named_symtabs (pst
->filename
);
1070 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1071 + cu_header
.initial_length_size
;
1073 do_cleanups (back_to
);
1076 /* Read in all interesting dies to the end of the compilation unit. */
1079 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1080 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1081 const struct comp_unit_head
*cu_header
)
1083 bfd
*abfd
= objfile
->obfd
;
1084 struct partial_die_info pdi
;
1086 /* This function is called after we've read in the comp_unit_die in
1087 order to read its children. We start the nesting level at 1 since
1088 we have pushed 1 level down in order to read the comp unit's children.
1089 The comp unit itself is at level 0, so we stop reading when we pop
1090 back to that level. */
1092 int nesting_level
= 1;
1094 *lowpc
= ((CORE_ADDR
) -1);
1095 *highpc
= ((CORE_ADDR
) 0);
1097 while (nesting_level
)
1099 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1105 case DW_TAG_subprogram
:
1106 if (pdi
.has_pc_info
)
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 (xfree
, 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 (xfree
, 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
)
2657 struct type
*base_type
;
2664 base_type
= die_type (die
, objfile
, cu_header
);
2665 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
2669 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
2670 const struct comp_unit_head
*cu_header
)
2672 struct type
*base_type
;
2679 base_type
= die_type (die
, objfile
, cu_header
);
2680 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
2683 /* Extract all information from a DW_TAG_string_type DIE and add to
2684 the user defined type vector. It isn't really a user defined type,
2685 but it behaves like one, with other DIE's using an AT_user_def_type
2686 attribute to reference it. */
2689 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
2691 struct type
*type
, *range_type
, *index_type
, *char_type
;
2692 struct attribute
*attr
;
2693 unsigned int length
;
2700 attr
= dwarf_attr (die
, DW_AT_string_length
);
2703 length
= DW_UNSND (attr
);
2709 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2710 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2711 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2712 type
= create_string_type (char_type
, range_type
);
2716 /* Handle DIES due to C code like:
2720 int (*funcp)(int a, long l);
2724 ('funcp' generates a DW_TAG_subroutine_type DIE)
2728 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
2729 const struct comp_unit_head
*cu_header
)
2731 struct type
*type
; /* Type that this function returns */
2732 struct type
*ftype
; /* Function that returns above type */
2733 struct attribute
*attr
;
2735 /* Decode the type that this subroutine returns */
2740 type
= die_type (die
, objfile
, cu_header
);
2741 ftype
= lookup_function_type (type
);
2743 /* All functions in C++ have prototypes. */
2744 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2745 if ((attr
&& (DW_UNSND (attr
) != 0))
2746 || cu_language
== language_cplus
)
2747 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2749 if (die
->has_children
)
2751 struct die_info
*child_die
;
2755 /* Count the number of parameters.
2756 FIXME: GDB currently ignores vararg functions, but knows about
2757 vararg member functions. */
2758 child_die
= die
->next
;
2759 while (child_die
&& child_die
->tag
)
2761 if (child_die
->tag
== DW_TAG_formal_parameter
)
2763 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2764 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2765 child_die
= sibling_die (child_die
);
2768 /* Allocate storage for parameters and fill them in. */
2769 TYPE_NFIELDS (ftype
) = nparams
;
2770 TYPE_FIELDS (ftype
) = (struct field
*)
2771 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2773 child_die
= die
->next
;
2774 while (child_die
&& child_die
->tag
)
2776 if (child_die
->tag
== DW_TAG_formal_parameter
)
2778 /* Dwarf2 has no clean way to discern C++ static and non-static
2779 member functions. G++ helps GDB by marking the first
2780 parameter for non-static member functions (which is the
2781 this pointer) as artificial. We pass this information
2782 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2783 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2785 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2787 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2788 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
2792 child_die
= sibling_die (child_die
);
2800 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
2801 const struct comp_unit_head
*cu_header
)
2807 struct attribute
*attr
;
2810 xtype
= die_type (die
, objfile
, cu_header
);
2812 type
= alloc_type (objfile
);
2813 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2814 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2815 TYPE_TARGET_TYPE (type
) = xtype
;
2816 attr
= dwarf_attr (die
, DW_AT_name
);
2817 if (attr
&& DW_STRING (attr
))
2818 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2819 strlen (DW_STRING (attr
)),
2820 &objfile
->type_obstack
);
2826 /* Find a representation of a given base type and install
2827 it in the TYPE field of the die. */
2830 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
2833 struct attribute
*attr
;
2834 int encoding
= 0, size
= 0;
2836 /* If we've already decoded this die, this is a no-op. */
2842 attr
= dwarf_attr (die
, DW_AT_encoding
);
2845 encoding
= DW_UNSND (attr
);
2847 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2850 size
= DW_UNSND (attr
);
2852 attr
= dwarf_attr (die
, DW_AT_name
);
2853 if (attr
&& DW_STRING (attr
))
2855 enum type_code code
= TYPE_CODE_INT
;
2856 int is_unsigned
= 0;
2860 case DW_ATE_address
:
2861 /* Turn DW_ATE_address into a void * pointer. */
2862 code
= TYPE_CODE_PTR
;
2865 case DW_ATE_boolean
:
2866 code
= TYPE_CODE_BOOL
;
2869 case DW_ATE_complex_float
:
2870 code
= TYPE_CODE_COMPLEX
;
2873 code
= TYPE_CODE_FLT
;
2876 case DW_ATE_signed_char
:
2878 case DW_ATE_unsigned
:
2879 case DW_ATE_unsigned_char
:
2883 complain (&dwarf2_unsupported_at_encoding
,
2884 dwarf_type_encoding_name (encoding
));
2887 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2888 if (encoding
== DW_ATE_address
)
2889 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2893 type
= dwarf_base_type (encoding
, size
, objfile
);
2898 /* Read a whole compilation unit into a linked list of dies. */
2900 static struct die_info
*
2901 read_comp_unit (char *info_ptr
, bfd
*abfd
,
2902 const struct comp_unit_head
*cu_header
)
2904 struct die_info
*first_die
, *last_die
, *die
;
2908 /* Reset die reference table; we are
2909 building new ones now. */
2910 dwarf2_empty_hash_tables ();
2914 first_die
= last_die
= NULL
;
2917 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
2918 if (die
->has_children
)
2929 /* Enter die in reference hash table */
2930 store_in_ref_table (die
->offset
, die
);
2934 first_die
= last_die
= die
;
2938 last_die
->next
= die
;
2942 while (nesting_level
> 0);
2946 /* Free a linked list of dies. */
2949 free_die_list (struct die_info
*dies
)
2951 struct die_info
*die
, *next
;
2964 do_free_die_list_cleanup (void *dies
)
2966 free_die_list (dies
);
2969 static struct cleanup
*
2970 make_cleanup_free_die_list (struct die_info
*dies
)
2972 return make_cleanup (do_free_die_list_cleanup
, dies
);
2976 /* Read the contents of the section at OFFSET and of size SIZE from the
2977 object file specified by OBJFILE into the psymbol_obstack and return it. */
2980 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
2983 bfd
*abfd
= objfile
->obfd
;
2989 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
2990 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
2991 (bfd_read (buf
, size
, 1, abfd
) != size
))
2994 error ("Dwarf Error: Can't read DWARF data from '%s'",
2995 bfd_get_filename (abfd
));
3000 /* In DWARF version 2, the description of the debugging information is
3001 stored in a separate .debug_abbrev section. Before we read any
3002 dies from a section we read in all abbreviations and install them
3006 dwarf2_read_abbrevs (bfd
*abfd
, unsigned int offset
)
3009 struct abbrev_info
*cur_abbrev
;
3010 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3011 unsigned int abbrev_form
, hash_number
;
3013 /* empty the table */
3014 dwarf2_empty_abbrev_table (NULL
);
3016 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3017 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3018 abbrev_ptr
+= bytes_read
;
3020 /* loop until we reach an abbrev number of 0 */
3021 while (abbrev_number
)
3023 cur_abbrev
= dwarf_alloc_abbrev ();
3025 /* read in abbrev header */
3026 cur_abbrev
->number
= abbrev_number
;
3027 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3028 abbrev_ptr
+= bytes_read
;
3029 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3032 /* now read in declarations */
3033 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3034 abbrev_ptr
+= bytes_read
;
3035 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3036 abbrev_ptr
+= bytes_read
;
3039 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3041 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3042 xrealloc (cur_abbrev
->attrs
,
3043 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3044 * sizeof (struct attr_abbrev
));
3046 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3047 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3048 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3049 abbrev_ptr
+= bytes_read
;
3050 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3051 abbrev_ptr
+= bytes_read
;
3054 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3055 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3056 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3058 /* Get next abbreviation.
3059 Under Irix6 the abbreviations for a compilation unit are not
3060 always properly terminated with an abbrev number of 0.
3061 Exit loop if we encounter an abbreviation which we have
3062 already read (which means we are about to read the abbreviations
3063 for the next compile unit) or if the end of the abbreviation
3064 table is reached. */
3065 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3066 >= dwarf_abbrev_size
)
3068 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3069 abbrev_ptr
+= bytes_read
;
3070 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3075 /* Empty the abbrev table for a new compilation unit. */
3079 dwarf2_empty_abbrev_table (PTR ignore
)
3082 struct abbrev_info
*abbrev
, *next
;
3084 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3087 abbrev
= dwarf2_abbrevs
[i
];
3090 next
= abbrev
->next
;
3091 xfree (abbrev
->attrs
);
3095 dwarf2_abbrevs
[i
] = NULL
;
3099 /* Lookup an abbrev_info structure in the abbrev hash table. */
3101 static struct abbrev_info
*
3102 dwarf2_lookup_abbrev (unsigned int number
)
3104 unsigned int hash_number
;
3105 struct abbrev_info
*abbrev
;
3107 hash_number
= number
% ABBREV_HASH_SIZE
;
3108 abbrev
= dwarf2_abbrevs
[hash_number
];
3112 if (abbrev
->number
== number
)
3115 abbrev
= abbrev
->next
;
3120 /* Read a minimal amount of information into the minimal die structure. */
3123 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3124 char *info_ptr
, const struct comp_unit_head
*cu_header
)
3126 unsigned int abbrev_number
, bytes_read
, i
;
3127 struct abbrev_info
*abbrev
;
3128 struct attribute attr
;
3129 struct attribute spec_attr
;
3130 int found_spec_attr
= 0;
3131 int has_low_pc_attr
= 0;
3132 int has_high_pc_attr
= 0;
3134 *part_die
= zeroed_partial_die
;
3135 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3136 info_ptr
+= bytes_read
;
3140 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3143 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3145 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3146 part_die
->tag
= abbrev
->tag
;
3147 part_die
->has_children
= abbrev
->has_children
;
3148 part_die
->abbrev
= abbrev_number
;
3150 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3152 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3153 info_ptr
, cu_header
);
3155 /* Store the data if it is of an attribute we want to keep in a
3156 partial symbol table. */
3161 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3162 if (part_die
->name
== NULL
)
3163 part_die
->name
= DW_STRING (&attr
);
3165 case DW_AT_MIPS_linkage_name
:
3166 part_die
->name
= DW_STRING (&attr
);
3169 has_low_pc_attr
= 1;
3170 part_die
->lowpc
= DW_ADDR (&attr
);
3173 has_high_pc_attr
= 1;
3174 part_die
->highpc
= DW_ADDR (&attr
);
3176 case DW_AT_location
:
3177 part_die
->locdesc
= DW_BLOCK (&attr
);
3179 case DW_AT_language
:
3180 part_die
->language
= DW_UNSND (&attr
);
3182 case DW_AT_external
:
3183 part_die
->is_external
= DW_UNSND (&attr
);
3185 case DW_AT_declaration
:
3186 part_die
->is_declaration
= DW_UNSND (&attr
);
3189 part_die
->has_type
= 1;
3191 case DW_AT_abstract_origin
:
3192 case DW_AT_specification
:
3193 found_spec_attr
= 1;
3197 /* Ignore absolute siblings, they might point outside of
3198 the current compile unit. */
3199 if (attr
.form
== DW_FORM_ref_addr
)
3200 complain (&dwarf2_absolute_sibling_complaint
);
3203 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3210 /* If we found a reference attribute and the die has no name, try
3211 to find a name in the referred to die. */
3213 if (found_spec_attr
&& part_die
->name
== NULL
)
3215 struct partial_die_info spec_die
;
3219 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3220 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu_header
);
3223 part_die
->name
= spec_die
.name
;
3225 /* Copy DW_AT_external attribute if it is set. */
3226 if (spec_die
.is_external
)
3227 part_die
->is_external
= spec_die
.is_external
;
3231 /* When using the GNU linker, .gnu.linkonce. sections are used to
3232 eliminate duplicate copies of functions and vtables and such.
3233 The linker will arbitrarily choose one and discard the others.
3234 The AT_*_pc values for such functions refer to local labels in
3235 these sections. If the section from that file was discarded, the
3236 labels are not in the output, so the relocs get a value of 0.
3237 If this is a discarded function, mark the pc bounds as invalid,
3238 so that GDB will ignore it. */
3239 if (has_low_pc_attr
&& has_high_pc_attr
3240 && part_die
->lowpc
< part_die
->highpc
3241 && (part_die
->lowpc
!= 0
3242 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3243 part_die
->has_pc_info
= 1;
3247 /* Read the die from the .debug_info section buffer. And set diep to
3248 point to a newly allocated die with its information. */
3251 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3252 const struct comp_unit_head
*cu_header
)
3254 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3255 struct abbrev_info
*abbrev
;
3256 struct die_info
*die
;
3258 offset
= info_ptr
- dwarf_info_buffer
;
3259 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3260 info_ptr
+= bytes_read
;
3263 die
= dwarf_alloc_die ();
3265 die
->abbrev
= abbrev_number
;
3271 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3274 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3276 die
= dwarf_alloc_die ();
3277 die
->offset
= offset
;
3278 die
->tag
= abbrev
->tag
;
3279 die
->has_children
= abbrev
->has_children
;
3280 die
->abbrev
= abbrev_number
;
3283 die
->num_attrs
= abbrev
->num_attrs
;
3284 die
->attrs
= (struct attribute
*)
3285 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3287 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3289 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3290 abfd
, info_ptr
, cu_header
);
3297 /* Read an attribute described by an abbreviated attribute. */
3300 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
3301 bfd
*abfd
, char *info_ptr
,
3302 const struct comp_unit_head
*cu_header
)
3304 unsigned int bytes_read
;
3305 struct dwarf_block
*blk
;
3307 attr
->name
= abbrev
->name
;
3308 attr
->form
= abbrev
->form
;
3309 switch (abbrev
->form
)
3312 case DW_FORM_ref_addr
:
3313 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3314 info_ptr
+= bytes_read
;
3316 case DW_FORM_block2
:
3317 blk
= dwarf_alloc_block ();
3318 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3320 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3321 info_ptr
+= blk
->size
;
3322 DW_BLOCK (attr
) = blk
;
3324 case DW_FORM_block4
:
3325 blk
= dwarf_alloc_block ();
3326 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3328 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3329 info_ptr
+= blk
->size
;
3330 DW_BLOCK (attr
) = blk
;
3333 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3337 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3341 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3344 case DW_FORM_string
:
3345 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3346 info_ptr
+= bytes_read
;
3349 blk
= dwarf_alloc_block ();
3350 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3351 info_ptr
+= bytes_read
;
3352 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3353 info_ptr
+= blk
->size
;
3354 DW_BLOCK (attr
) = blk
;
3356 case DW_FORM_block1
:
3357 blk
= dwarf_alloc_block ();
3358 blk
->size
= read_1_byte (abfd
, info_ptr
);
3360 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3361 info_ptr
+= blk
->size
;
3362 DW_BLOCK (attr
) = blk
;
3365 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3369 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3373 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3374 info_ptr
+= bytes_read
;
3377 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3378 info_ptr
+= bytes_read
;
3381 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3385 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3389 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3393 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3396 case DW_FORM_ref_udata
:
3397 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3398 info_ptr
+= bytes_read
;
3401 case DW_FORM_indirect
:
3403 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3404 dwarf_form_name (abbrev
->form
));
3409 /* read dwarf information from a buffer */
3412 read_1_byte (bfd
*abfd
, char *buf
)
3414 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3418 read_1_signed_byte (bfd
*abfd
, char *buf
)
3420 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3424 read_2_bytes (bfd
*abfd
, char *buf
)
3426 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3430 read_2_signed_bytes (bfd
*abfd
, char *buf
)
3432 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3436 read_4_bytes (bfd
*abfd
, char *buf
)
3438 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3442 read_4_signed_bytes (bfd
*abfd
, char *buf
)
3444 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3447 static unsigned long
3448 read_8_bytes (bfd
*abfd
, char *buf
)
3450 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3454 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3457 CORE_ADDR retval
= 0;
3459 if (cu_header
->signed_addr_p
)
3461 switch (cu_header
->addr_size
)
3464 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3467 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3470 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
3473 internal_error (__FILE__
, __LINE__
,
3474 "read_address: bad switch, signed");
3479 switch (cu_header
->addr_size
)
3482 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3485 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3488 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3491 internal_error (__FILE__
, __LINE__
,
3492 "read_address: bad switch, unsigned");
3496 *bytes_read
= cu_header
->addr_size
;
3500 /* Reads the initial length from a section. The (draft) DWARF 2.1
3501 specification allows the initial length to take up either 4 bytes
3502 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
3503 bytes describe the length and all offsets will be 8 bytes in length
3506 The value returned via bytes_read should be used to increment
3507 the relevant pointer after calling read_initial_length().
3509 As a side effect, this function sets the fields initial_length_size
3510 and offset_size in cu_header to the values appropriate for the
3511 length field. (The format of the initial length field determines
3512 the width of file offsets to be fetched later with fetch_offset().)
3514 [ Note: read_initial_length() and read_offset() are based on the
3515 document entitled "DWARF Debugging Information Format", revision
3516 2.1, draft 4, dated July 20, 2000. This document was obtained
3519 http://reality.sgi.com/dehnert_engr/dwarf/dwarf2p1-draft4-000720.pdf
3521 This document is only a draft and is subject to change. (So beware.)
3523 - Kevin, Aug 4, 2000
3527 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
3532 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3534 if (retval
== 0xffffffff)
3536 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
3538 if (cu_header
!= NULL
)
3540 cu_header
->initial_length_size
= 12;
3541 cu_header
->offset_size
= 8;
3547 if (cu_header
!= NULL
)
3549 cu_header
->initial_length_size
= 4;
3550 cu_header
->offset_size
= 4;
3557 /* Read an offset from the data stream. The size of the offset is
3558 given by cu_header->offset_size. */
3561 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3566 switch (cu_header
->offset_size
)
3569 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3573 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3577 internal_error (__FILE__
, __LINE__
,
3578 "read_offset: bad switch");
3585 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
3587 /* If the size of a host char is 8 bits, we can return a pointer
3588 to the buffer, otherwise we have to copy the data to a buffer
3589 allocated on the temporary obstack. */
3590 #if HOST_CHAR_BIT == 8
3596 ret
= obstack_alloc (&dwarf2_tmp_obstack
, size
);
3597 for (i
= 0; i
< size
; ++i
)
3599 ret
[i
] = bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3607 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3609 /* If the size of a host char is 8 bits, we can return a pointer
3610 to the string, otherwise we have to copy the string to a buffer
3611 allocated on the temporary obstack. */
3612 #if HOST_CHAR_BIT == 8
3615 *bytes_read_ptr
= 1;
3618 *bytes_read_ptr
= strlen (buf
) + 1;
3624 while ((byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
)) != 0)
3626 obstack_1grow (&dwarf2_tmp_obstack
, byte
);
3632 *bytes_read_ptr
= 1;
3635 obstack_1grow (&dwarf2_tmp_obstack
, '\0');
3636 *bytes_read_ptr
= i
+ 1;
3637 return obstack_finish (&dwarf2_tmp_obstack
);
3641 static unsigned long
3642 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3644 unsigned long result
;
3645 unsigned int num_read
;
3655 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3658 result
|= ((unsigned long)(byte
& 127) << shift
);
3659 if ((byte
& 128) == 0)
3665 *bytes_read_ptr
= num_read
;
3670 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3673 int i
, shift
, size
, num_read
;
3683 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3686 result
|= ((long)(byte
& 127) << shift
);
3688 if ((byte
& 128) == 0)
3693 if ((shift
< size
) && (byte
& 0x40))
3695 result
|= -(1 << shift
);
3697 *bytes_read_ptr
= num_read
;
3702 set_cu_language (unsigned int lang
)
3708 cu_language
= language_c
;
3710 case DW_LANG_C_plus_plus
:
3711 cu_language
= language_cplus
;
3713 case DW_LANG_Fortran77
:
3714 case DW_LANG_Fortran90
:
3715 cu_language
= language_fortran
;
3717 case DW_LANG_Mips_Assembler
:
3718 cu_language
= language_asm
;
3721 cu_language
= language_java
;
3724 case DW_LANG_Cobol74
:
3725 case DW_LANG_Cobol85
:
3726 case DW_LANG_Pascal83
:
3727 case DW_LANG_Modula2
:
3729 cu_language
= language_unknown
;
3732 cu_language_defn
= language_def (cu_language
);
3735 /* Return the named attribute or NULL if not there. */
3737 static struct attribute
*
3738 dwarf_attr (struct die_info
*die
, unsigned int name
)
3741 struct attribute
*spec
= NULL
;
3743 for (i
= 0; i
< die
->num_attrs
; ++i
)
3745 if (die
->attrs
[i
].name
== name
)
3747 return &die
->attrs
[i
];
3749 if (die
->attrs
[i
].name
== DW_AT_specification
3750 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3751 spec
= &die
->attrs
[i
];
3755 struct die_info
*ref_die
=
3756 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3759 return dwarf_attr (ref_die
, name
);
3766 die_is_declaration (struct die_info
*die
)
3768 return (dwarf_attr (die
, DW_AT_declaration
)
3769 && ! dwarf_attr (die
, DW_AT_specification
));
3772 /* Decode the line number information for the compilation unit whose
3773 line number info is at OFFSET in the .debug_line section.
3774 The compilation directory of the file is passed in COMP_DIR. */
3778 unsigned int num_files
;
3791 unsigned int num_dirs
;
3796 dwarf_decode_lines (unsigned int offset
, char *comp_dir
, bfd
*abfd
,
3797 const struct comp_unit_head
*cu_header
)
3801 struct line_head lh
;
3802 struct cleanup
*back_to
;
3803 unsigned int i
, bytes_read
;
3804 char *cur_file
, *cur_dir
;
3805 unsigned char op_code
, extended_op
, adj_opcode
;
3807 #define FILE_ALLOC_CHUNK 5
3808 #define DIR_ALLOC_CHUNK 5
3810 struct filenames files
;
3811 struct directories dirs
;
3813 if (dwarf_line_buffer
== NULL
)
3815 complain (&dwarf2_missing_line_number_section
);
3819 files
.num_files
= 0;
3825 line_ptr
= dwarf_line_buffer
+ offset
;
3827 /* read in the prologue */
3828 lh
.total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
3829 line_ptr
+= bytes_read
;
3830 line_end
= line_ptr
+ lh
.total_length
;
3831 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3833 lh
.prologue_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
3834 line_ptr
+= bytes_read
;
3835 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3837 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3839 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3841 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3843 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3845 lh
.standard_opcode_lengths
= (unsigned char *)
3846 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3847 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
3849 lh
.standard_opcode_lengths
[0] = 1;
3850 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3852 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3856 /* Read directory table */
3857 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3859 line_ptr
+= bytes_read
;
3860 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3862 dirs
.dirs
= (char **)
3863 xrealloc (dirs
.dirs
,
3864 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3865 if (dirs
.num_dirs
== 0)
3866 make_cleanup (free_current_contents
, &dirs
.dirs
);
3868 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3870 line_ptr
+= bytes_read
;
3872 /* Read file name table */
3873 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3875 line_ptr
+= bytes_read
;
3876 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3878 files
.files
= (struct fileinfo
*)
3879 xrealloc (files
.files
,
3880 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3881 * sizeof (struct fileinfo
));
3882 if (files
.num_files
== 0)
3883 make_cleanup (free_current_contents
, &files
.files
);
3885 files
.files
[files
.num_files
].name
= cur_file
;
3886 files
.files
[files
.num_files
].dir
=
3887 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3888 line_ptr
+= bytes_read
;
3889 files
.files
[files
.num_files
].time
=
3890 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3891 line_ptr
+= bytes_read
;
3892 files
.files
[files
.num_files
].size
=
3893 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3894 line_ptr
+= bytes_read
;
3897 line_ptr
+= bytes_read
;
3899 /* Read the statement sequences until there's nothing left. */
3900 while (line_ptr
< line_end
)
3902 /* state machine registers */
3903 CORE_ADDR address
= 0;
3904 unsigned int file
= 1;
3905 unsigned int line
= 1;
3906 unsigned int column
= 0;
3907 int is_stmt
= lh
.default_is_stmt
;
3908 int basic_block
= 0;
3909 int end_sequence
= 0;
3911 /* Start a subfile for the current file of the state machine. */
3912 if (files
.num_files
>= file
)
3914 /* The file and directory tables are 0 based, the references
3916 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3917 (files
.files
[file
- 1].dir
3918 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3922 /* Decode the table. */
3923 while (!end_sequence
)
3925 op_code
= read_1_byte (abfd
, line_ptr
);
3929 case DW_LNS_extended_op
:
3930 line_ptr
+= 1; /* ignore length */
3931 extended_op
= read_1_byte (abfd
, line_ptr
);
3933 switch (extended_op
)
3935 case DW_LNE_end_sequence
:
3937 /* Don't call record_line here. The end_sequence
3938 instruction provides the address of the first byte
3939 *after* the last line in the sequence; it's not the
3940 address of any real source line. However, the GDB
3941 linetable structure only records the starts of lines,
3942 not the ends. This is a weakness of GDB. */
3944 case DW_LNE_set_address
:
3945 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
3946 line_ptr
+= bytes_read
;
3947 address
+= baseaddr
;
3949 case DW_LNE_define_file
:
3950 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
3951 line_ptr
+= bytes_read
;
3952 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3954 files
.files
= (struct fileinfo
*)
3955 xrealloc (files
.files
,
3956 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3957 * sizeof (struct fileinfo
));
3958 if (files
.num_files
== 0)
3959 make_cleanup (free_current_contents
, &files
.files
);
3961 files
.files
[files
.num_files
].name
= cur_file
;
3962 files
.files
[files
.num_files
].dir
=
3963 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3964 line_ptr
+= bytes_read
;
3965 files
.files
[files
.num_files
].time
=
3966 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3967 line_ptr
+= bytes_read
;
3968 files
.files
[files
.num_files
].size
=
3969 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3970 line_ptr
+= bytes_read
;
3974 complain (&dwarf2_mangled_line_number_section
);
3979 record_line (current_subfile
, line
, address
);
3982 case DW_LNS_advance_pc
:
3983 address
+= lh
.minimum_instruction_length
3984 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3985 line_ptr
+= bytes_read
;
3987 case DW_LNS_advance_line
:
3988 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
3989 line_ptr
+= bytes_read
;
3991 case DW_LNS_set_file
:
3992 /* The file and directory tables are 0 based, the references
3994 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3995 line_ptr
+= bytes_read
;
3996 dwarf2_start_subfile
3997 (files
.files
[file
- 1].name
,
3998 (files
.files
[file
- 1].dir
3999 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
4002 case DW_LNS_set_column
:
4003 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4004 line_ptr
+= bytes_read
;
4006 case DW_LNS_negate_stmt
:
4007 is_stmt
= (!is_stmt
);
4009 case DW_LNS_set_basic_block
:
4012 /* Add to the address register of the state machine the
4013 address increment value corresponding to special opcode
4014 255. Ie, this value is scaled by the minimum instruction
4015 length since special opcode 255 would have scaled the
4017 case DW_LNS_const_add_pc
:
4018 address
+= (lh
.minimum_instruction_length
4019 * ((255 - lh
.opcode_base
) / lh
.line_range
));
4021 case DW_LNS_fixed_advance_pc
:
4022 address
+= read_2_bytes (abfd
, line_ptr
);
4025 default: /* special operand */
4026 adj_opcode
= op_code
- lh
.opcode_base
;
4027 address
+= (adj_opcode
/ lh
.line_range
)
4028 * lh
.minimum_instruction_length
;
4029 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
4030 /* append row to matrix using current values */
4031 record_line (current_subfile
, line
, address
);
4037 do_cleanups (back_to
);
4040 /* Start a subfile for DWARF. FILENAME is the name of the file and
4041 DIRNAME the name of the source directory which contains FILENAME
4042 or NULL if not known.
4043 This routine tries to keep line numbers from identical absolute and
4044 relative file names in a common subfile.
4046 Using the `list' example from the GDB testsuite, which resides in
4047 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4048 of /srcdir/list0.c yields the following debugging information for list0.c:
4050 DW_AT_name: /srcdir/list0.c
4051 DW_AT_comp_dir: /compdir
4052 files.files[0].name: list0.h
4053 files.files[0].dir: /srcdir
4054 files.files[1].name: list0.c
4055 files.files[1].dir: /srcdir
4057 The line number information for list0.c has to end up in a single
4058 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4061 dwarf2_start_subfile (char *filename
, char *dirname
)
4063 /* If the filename isn't absolute, try to match an existing subfile
4064 with the full pathname. */
4066 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
4068 struct subfile
*subfile
;
4069 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4071 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4073 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
4075 current_subfile
= subfile
;
4082 start_subfile (filename
, dirname
);
4085 /* Given a pointer to a DWARF information entry, figure out if we need
4086 to make a symbol table entry for it, and if so, create a new entry
4087 and return a pointer to it.
4088 If TYPE is NULL, determine symbol type from the die, otherwise
4089 used the passed type. */
4091 static struct symbol
*
4092 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
4093 const struct comp_unit_head
*cu_header
)
4095 struct symbol
*sym
= NULL
;
4097 struct attribute
*attr
= NULL
;
4098 struct attribute
*attr2
= NULL
;
4101 name
= dwarf2_linkage_name (die
);
4104 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4105 sizeof (struct symbol
));
4106 OBJSTAT (objfile
, n_syms
++);
4107 memset (sym
, 0, sizeof (struct symbol
));
4108 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4109 &objfile
->symbol_obstack
);
4111 /* Default assumptions.
4112 Use the passed type or decode it from the die. */
4113 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4114 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4116 SYMBOL_TYPE (sym
) = type
;
4118 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
4119 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4122 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4125 /* If this symbol is from a C++ compilation, then attempt to
4126 cache the demangled form for future reference. This is a
4127 typical time versus space tradeoff, that was decided in favor
4128 of time because it sped up C++ symbol lookups by a factor of
4131 SYMBOL_LANGUAGE (sym
) = cu_language
;
4132 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4136 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4139 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4141 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4143 case DW_TAG_subprogram
:
4144 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4146 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4147 attr2
= dwarf_attr (die
, DW_AT_external
);
4148 if (attr2
&& (DW_UNSND (attr2
) != 0))
4150 add_symbol_to_list (sym
, &global_symbols
);
4154 add_symbol_to_list (sym
, list_in_scope
);
4157 case DW_TAG_variable
:
4158 /* Compilation with minimal debug info may result in variables
4159 with missing type entries. Change the misleading `void' type
4160 to something sensible. */
4161 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4162 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4163 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4164 "<variable, no debug info>",
4166 attr
= dwarf_attr (die
, DW_AT_const_value
);
4169 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4170 attr2
= dwarf_attr (die
, DW_AT_external
);
4171 if (attr2
&& (DW_UNSND (attr2
) != 0))
4172 add_symbol_to_list (sym
, &global_symbols
);
4174 add_symbol_to_list (sym
, list_in_scope
);
4177 attr
= dwarf_attr (die
, DW_AT_location
);
4180 attr2
= dwarf_attr (die
, DW_AT_external
);
4181 if (attr2
&& (DW_UNSND (attr2
) != 0))
4183 SYMBOL_VALUE_ADDRESS (sym
) =
4184 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4185 add_symbol_to_list (sym
, &global_symbols
);
4187 /* In shared libraries the address of the variable
4188 in the location descriptor might still be relocatable,
4189 so its value could be zero.
4190 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4191 value is zero, the address of the variable will then
4192 be determined from the minimal symbol table whenever
4193 the variable is referenced. */
4194 if (SYMBOL_VALUE_ADDRESS (sym
))
4196 fixup_symbol_section (sym
, objfile
);
4197 SYMBOL_VALUE_ADDRESS (sym
) +=
4198 ANOFFSET (objfile
->section_offsets
,
4199 SYMBOL_SECTION (sym
));
4200 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4203 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4207 SYMBOL_VALUE (sym
) = addr
=
4208 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4209 add_symbol_to_list (sym
, list_in_scope
);
4212 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4216 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4217 SYMBOL_VALUE (sym
) =
4218 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4222 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4223 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4227 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4231 fixup_symbol_section (sym
, objfile
);
4232 SYMBOL_VALUE_ADDRESS (sym
) =
4233 addr
+ ANOFFSET (objfile
->section_offsets
,
4234 SYMBOL_SECTION (sym
));
4235 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4241 /* We do not know the address of this symbol.
4242 If it is an external symbol and we have type information
4243 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4244 The address of the variable will then be determined from
4245 the minimal symbol table whenever the variable is
4247 attr2
= dwarf_attr (die
, DW_AT_external
);
4248 if (attr2
&& (DW_UNSND (attr2
) != 0)
4249 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4251 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4252 add_symbol_to_list (sym
, &global_symbols
);
4256 case DW_TAG_formal_parameter
:
4257 attr
= dwarf_attr (die
, DW_AT_location
);
4260 SYMBOL_VALUE (sym
) =
4261 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4264 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4265 SYMBOL_VALUE (sym
) =
4266 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4272 if (basereg
!= frame_base_reg
)
4273 complain (&dwarf2_complex_location_expr
);
4274 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4278 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4279 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4284 SYMBOL_CLASS (sym
) = LOC_ARG
;
4287 attr
= dwarf_attr (die
, DW_AT_const_value
);
4290 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4292 add_symbol_to_list (sym
, list_in_scope
);
4294 case DW_TAG_unspecified_parameters
:
4295 /* From varargs functions; gdb doesn't seem to have any
4296 interest in this information, so just ignore it for now.
4299 case DW_TAG_class_type
:
4300 case DW_TAG_structure_type
:
4301 case DW_TAG_union_type
:
4302 case DW_TAG_enumeration_type
:
4303 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4304 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4305 add_symbol_to_list (sym
, list_in_scope
);
4307 /* The semantics of C++ state that "struct foo { ... }" also
4308 defines a typedef for "foo". Synthesize a typedef symbol so
4309 that "ptype foo" works as expected. */
4310 if (cu_language
== language_cplus
)
4312 struct symbol
*typedef_sym
= (struct symbol
*)
4313 obstack_alloc (&objfile
->symbol_obstack
,
4314 sizeof (struct symbol
));
4315 *typedef_sym
= *sym
;
4316 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4317 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4318 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4319 obsavestring (SYMBOL_NAME (sym
),
4320 strlen (SYMBOL_NAME (sym
)),
4321 &objfile
->type_obstack
);
4322 add_symbol_to_list (typedef_sym
, list_in_scope
);
4325 case DW_TAG_typedef
:
4326 case DW_TAG_base_type
:
4327 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4328 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4329 add_symbol_to_list (sym
, list_in_scope
);
4331 case DW_TAG_enumerator
:
4332 attr
= dwarf_attr (die
, DW_AT_const_value
);
4335 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4337 add_symbol_to_list (sym
, list_in_scope
);
4340 /* Not a tag we recognize. Hopefully we aren't processing
4341 trash data, but since we must specifically ignore things
4342 we don't recognize, there is nothing else we should do at
4344 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4351 /* Copy constant value from an attribute to a symbol. */
4354 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
4355 struct objfile
*objfile
,
4356 const struct comp_unit_head
*cu_header
)
4358 struct dwarf_block
*blk
;
4363 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
4364 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4365 cu_header
->addr_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4366 SYMBOL_VALUE_BYTES (sym
) = (char *)
4367 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
4368 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
4370 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4372 case DW_FORM_block1
:
4373 case DW_FORM_block2
:
4374 case DW_FORM_block4
:
4376 blk
= DW_BLOCK (attr
);
4377 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4378 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4379 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4380 SYMBOL_VALUE_BYTES (sym
) = (char *)
4381 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4382 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4383 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4386 /* The DW_AT_const_value attributes are supposed to carry the
4387 symbol's value "represented as it would be on the target
4388 architecture." By the time we get here, it's already been
4389 converted to host endianness, so we just need to sign- or
4390 zero-extend it as appropriate. */
4392 dwarf2_const_value_data (attr
, sym
, 8);
4395 dwarf2_const_value_data (attr
, sym
, 16);
4398 dwarf2_const_value_data (attr
, sym
, 32);
4401 dwarf2_const_value_data (attr
, sym
, 64);
4405 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4406 SYMBOL_CLASS (sym
) = LOC_CONST
;
4410 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4411 SYMBOL_CLASS (sym
) = LOC_CONST
;
4415 complain (&dwarf2_unsupported_const_value_attr
,
4416 dwarf_form_name (attr
->form
));
4417 SYMBOL_VALUE (sym
) = 0;
4418 SYMBOL_CLASS (sym
) = LOC_CONST
;
4424 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4425 or zero-extend it as appropriate for the symbol's type. */
4427 dwarf2_const_value_data (struct attribute
*attr
,
4431 LONGEST l
= DW_UNSND (attr
);
4433 if (bits
< sizeof (l
) * 8)
4435 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4436 l
&= ((LONGEST
) 1 << bits
) - 1;
4438 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4441 SYMBOL_VALUE (sym
) = l
;
4442 SYMBOL_CLASS (sym
) = LOC_CONST
;
4446 /* Return the type of the die in question using its DW_AT_type attribute. */
4448 static struct type
*
4449 die_type (struct die_info
*die
, struct objfile
*objfile
,
4450 const struct comp_unit_head
*cu_header
)
4453 struct attribute
*type_attr
;
4454 struct die_info
*type_die
;
4457 type_attr
= dwarf_attr (die
, DW_AT_type
);
4460 /* A missing DW_AT_type represents a void type. */
4461 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4465 ref
= dwarf2_get_ref_die_offset (type_attr
);
4466 type_die
= follow_die_ref (ref
);
4469 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4473 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4476 dump_die (type_die
);
4477 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4482 /* Return the containing type of the die in question using its
4483 DW_AT_containing_type attribute. */
4485 static struct type
*
4486 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
4487 const struct comp_unit_head
*cu_header
)
4489 struct type
*type
= NULL
;
4490 struct attribute
*type_attr
;
4491 struct die_info
*type_die
= NULL
;
4494 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4497 ref
= dwarf2_get_ref_die_offset (type_attr
);
4498 type_die
= follow_die_ref (ref
);
4501 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4504 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4509 dump_die (type_die
);
4510 error ("Dwarf Error: Problem turning containing type into gdb type.");
4516 static struct type
*
4517 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
4519 struct die_info
*die
;
4522 die
= follow_die_ref (offset
);
4525 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4528 type
= tag_type_to_type (die
, objfile
);
4533 static struct type
*
4534 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
4535 const struct comp_unit_head
*cu_header
)
4543 read_type_die (die
, objfile
, cu_header
);
4547 error ("Dwarf Error: Cannot find type of die.");
4554 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
4555 const struct comp_unit_head
*cu_header
)
4559 case DW_TAG_class_type
:
4560 case DW_TAG_structure_type
:
4561 case DW_TAG_union_type
:
4562 read_structure_scope (die
, objfile
, cu_header
);
4564 case DW_TAG_enumeration_type
:
4565 read_enumeration (die
, objfile
, cu_header
);
4567 case DW_TAG_subprogram
:
4568 case DW_TAG_subroutine_type
:
4569 read_subroutine_type (die
, objfile
, cu_header
);
4571 case DW_TAG_array_type
:
4572 read_array_type (die
, objfile
, cu_header
);
4574 case DW_TAG_pointer_type
:
4575 read_tag_pointer_type (die
, objfile
, cu_header
);
4577 case DW_TAG_ptr_to_member_type
:
4578 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
4580 case DW_TAG_reference_type
:
4581 read_tag_reference_type (die
, objfile
, cu_header
);
4583 case DW_TAG_const_type
:
4584 read_tag_const_type (die
, objfile
, cu_header
);
4586 case DW_TAG_volatile_type
:
4587 read_tag_volatile_type (die
, objfile
, cu_header
);
4589 case DW_TAG_string_type
:
4590 read_tag_string_type (die
, objfile
);
4592 case DW_TAG_typedef
:
4593 read_typedef (die
, objfile
, cu_header
);
4595 case DW_TAG_base_type
:
4596 read_base_type (die
, objfile
);
4599 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4604 static struct type
*
4605 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
4607 /* FIXME - this should not produce a new (struct type *)
4608 every time. It should cache base types. */
4612 case DW_ATE_address
:
4613 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4615 case DW_ATE_boolean
:
4616 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4618 case DW_ATE_complex_float
:
4621 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4625 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4631 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4635 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4642 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4645 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4649 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4653 case DW_ATE_signed_char
:
4654 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4656 case DW_ATE_unsigned
:
4660 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4663 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4667 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4671 case DW_ATE_unsigned_char
:
4672 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4675 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4682 copy_die (struct die_info
*old_die
)
4684 struct die_info
*new_die
;
4687 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4688 memset (new_die
, 0, sizeof (struct die_info
));
4690 new_die
->tag
= old_die
->tag
;
4691 new_die
->has_children
= old_die
->has_children
;
4692 new_die
->abbrev
= old_die
->abbrev
;
4693 new_die
->offset
= old_die
->offset
;
4694 new_die
->type
= NULL
;
4696 num_attrs
= old_die
->num_attrs
;
4697 new_die
->num_attrs
= num_attrs
;
4698 new_die
->attrs
= (struct attribute
*)
4699 xmalloc (num_attrs
* sizeof (struct attribute
));
4701 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4703 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4704 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4705 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4708 new_die
->next
= NULL
;
4713 /* Return sibling of die, NULL if no sibling. */
4715 static struct die_info
*
4716 sibling_die (struct die_info
*die
)
4718 int nesting_level
= 0;
4720 if (!die
->has_children
)
4722 if (die
->next
&& (die
->next
->tag
== 0))
4735 if (die
->has_children
)
4745 while (nesting_level
);
4746 if (die
&& (die
->tag
== 0))
4757 /* Get linkage name of a die, return NULL if not found. */
4760 dwarf2_linkage_name (struct die_info
*die
)
4762 struct attribute
*attr
;
4764 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4765 if (attr
&& DW_STRING (attr
))
4766 return DW_STRING (attr
);
4767 attr
= dwarf_attr (die
, DW_AT_name
);
4768 if (attr
&& DW_STRING (attr
))
4769 return DW_STRING (attr
);
4773 /* Convert a DIE tag into its string name. */
4776 dwarf_tag_name (register unsigned tag
)
4780 case DW_TAG_padding
:
4781 return "DW_TAG_padding";
4782 case DW_TAG_array_type
:
4783 return "DW_TAG_array_type";
4784 case DW_TAG_class_type
:
4785 return "DW_TAG_class_type";
4786 case DW_TAG_entry_point
:
4787 return "DW_TAG_entry_point";
4788 case DW_TAG_enumeration_type
:
4789 return "DW_TAG_enumeration_type";
4790 case DW_TAG_formal_parameter
:
4791 return "DW_TAG_formal_parameter";
4792 case DW_TAG_imported_declaration
:
4793 return "DW_TAG_imported_declaration";
4795 return "DW_TAG_label";
4796 case DW_TAG_lexical_block
:
4797 return "DW_TAG_lexical_block";
4799 return "DW_TAG_member";
4800 case DW_TAG_pointer_type
:
4801 return "DW_TAG_pointer_type";
4802 case DW_TAG_reference_type
:
4803 return "DW_TAG_reference_type";
4804 case DW_TAG_compile_unit
:
4805 return "DW_TAG_compile_unit";
4806 case DW_TAG_string_type
:
4807 return "DW_TAG_string_type";
4808 case DW_TAG_structure_type
:
4809 return "DW_TAG_structure_type";
4810 case DW_TAG_subroutine_type
:
4811 return "DW_TAG_subroutine_type";
4812 case DW_TAG_typedef
:
4813 return "DW_TAG_typedef";
4814 case DW_TAG_union_type
:
4815 return "DW_TAG_union_type";
4816 case DW_TAG_unspecified_parameters
:
4817 return "DW_TAG_unspecified_parameters";
4818 case DW_TAG_variant
:
4819 return "DW_TAG_variant";
4820 case DW_TAG_common_block
:
4821 return "DW_TAG_common_block";
4822 case DW_TAG_common_inclusion
:
4823 return "DW_TAG_common_inclusion";
4824 case DW_TAG_inheritance
:
4825 return "DW_TAG_inheritance";
4826 case DW_TAG_inlined_subroutine
:
4827 return "DW_TAG_inlined_subroutine";
4829 return "DW_TAG_module";
4830 case DW_TAG_ptr_to_member_type
:
4831 return "DW_TAG_ptr_to_member_type";
4832 case DW_TAG_set_type
:
4833 return "DW_TAG_set_type";
4834 case DW_TAG_subrange_type
:
4835 return "DW_TAG_subrange_type";
4836 case DW_TAG_with_stmt
:
4837 return "DW_TAG_with_stmt";
4838 case DW_TAG_access_declaration
:
4839 return "DW_TAG_access_declaration";
4840 case DW_TAG_base_type
:
4841 return "DW_TAG_base_type";
4842 case DW_TAG_catch_block
:
4843 return "DW_TAG_catch_block";
4844 case DW_TAG_const_type
:
4845 return "DW_TAG_const_type";
4846 case DW_TAG_constant
:
4847 return "DW_TAG_constant";
4848 case DW_TAG_enumerator
:
4849 return "DW_TAG_enumerator";
4850 case DW_TAG_file_type
:
4851 return "DW_TAG_file_type";
4853 return "DW_TAG_friend";
4854 case DW_TAG_namelist
:
4855 return "DW_TAG_namelist";
4856 case DW_TAG_namelist_item
:
4857 return "DW_TAG_namelist_item";
4858 case DW_TAG_packed_type
:
4859 return "DW_TAG_packed_type";
4860 case DW_TAG_subprogram
:
4861 return "DW_TAG_subprogram";
4862 case DW_TAG_template_type_param
:
4863 return "DW_TAG_template_type_param";
4864 case DW_TAG_template_value_param
:
4865 return "DW_TAG_template_value_param";
4866 case DW_TAG_thrown_type
:
4867 return "DW_TAG_thrown_type";
4868 case DW_TAG_try_block
:
4869 return "DW_TAG_try_block";
4870 case DW_TAG_variant_part
:
4871 return "DW_TAG_variant_part";
4872 case DW_TAG_variable
:
4873 return "DW_TAG_variable";
4874 case DW_TAG_volatile_type
:
4875 return "DW_TAG_volatile_type";
4876 case DW_TAG_MIPS_loop
:
4877 return "DW_TAG_MIPS_loop";
4878 case DW_TAG_format_label
:
4879 return "DW_TAG_format_label";
4880 case DW_TAG_function_template
:
4881 return "DW_TAG_function_template";
4882 case DW_TAG_class_template
:
4883 return "DW_TAG_class_template";
4885 return "DW_TAG_<unknown>";
4889 /* Convert a DWARF attribute code into its string name. */
4892 dwarf_attr_name (register unsigned attr
)
4897 return "DW_AT_sibling";
4898 case DW_AT_location
:
4899 return "DW_AT_location";
4901 return "DW_AT_name";
4902 case DW_AT_ordering
:
4903 return "DW_AT_ordering";
4904 case DW_AT_subscr_data
:
4905 return "DW_AT_subscr_data";
4906 case DW_AT_byte_size
:
4907 return "DW_AT_byte_size";
4908 case DW_AT_bit_offset
:
4909 return "DW_AT_bit_offset";
4910 case DW_AT_bit_size
:
4911 return "DW_AT_bit_size";
4912 case DW_AT_element_list
:
4913 return "DW_AT_element_list";
4914 case DW_AT_stmt_list
:
4915 return "DW_AT_stmt_list";
4917 return "DW_AT_low_pc";
4919 return "DW_AT_high_pc";
4920 case DW_AT_language
:
4921 return "DW_AT_language";
4923 return "DW_AT_member";
4925 return "DW_AT_discr";
4926 case DW_AT_discr_value
:
4927 return "DW_AT_discr_value";
4928 case DW_AT_visibility
:
4929 return "DW_AT_visibility";
4931 return "DW_AT_import";
4932 case DW_AT_string_length
:
4933 return "DW_AT_string_length";
4934 case DW_AT_common_reference
:
4935 return "DW_AT_common_reference";
4936 case DW_AT_comp_dir
:
4937 return "DW_AT_comp_dir";
4938 case DW_AT_const_value
:
4939 return "DW_AT_const_value";
4940 case DW_AT_containing_type
:
4941 return "DW_AT_containing_type";
4942 case DW_AT_default_value
:
4943 return "DW_AT_default_value";
4945 return "DW_AT_inline";
4946 case DW_AT_is_optional
:
4947 return "DW_AT_is_optional";
4948 case DW_AT_lower_bound
:
4949 return "DW_AT_lower_bound";
4950 case DW_AT_producer
:
4951 return "DW_AT_producer";
4952 case DW_AT_prototyped
:
4953 return "DW_AT_prototyped";
4954 case DW_AT_return_addr
:
4955 return "DW_AT_return_addr";
4956 case DW_AT_start_scope
:
4957 return "DW_AT_start_scope";
4958 case DW_AT_stride_size
:
4959 return "DW_AT_stride_size";
4960 case DW_AT_upper_bound
:
4961 return "DW_AT_upper_bound";
4962 case DW_AT_abstract_origin
:
4963 return "DW_AT_abstract_origin";
4964 case DW_AT_accessibility
:
4965 return "DW_AT_accessibility";
4966 case DW_AT_address_class
:
4967 return "DW_AT_address_class";
4968 case DW_AT_artificial
:
4969 return "DW_AT_artificial";
4970 case DW_AT_base_types
:
4971 return "DW_AT_base_types";
4972 case DW_AT_calling_convention
:
4973 return "DW_AT_calling_convention";
4975 return "DW_AT_count";
4976 case DW_AT_data_member_location
:
4977 return "DW_AT_data_member_location";
4978 case DW_AT_decl_column
:
4979 return "DW_AT_decl_column";
4980 case DW_AT_decl_file
:
4981 return "DW_AT_decl_file";
4982 case DW_AT_decl_line
:
4983 return "DW_AT_decl_line";
4984 case DW_AT_declaration
:
4985 return "DW_AT_declaration";
4986 case DW_AT_discr_list
:
4987 return "DW_AT_discr_list";
4988 case DW_AT_encoding
:
4989 return "DW_AT_encoding";
4990 case DW_AT_external
:
4991 return "DW_AT_external";
4992 case DW_AT_frame_base
:
4993 return "DW_AT_frame_base";
4995 return "DW_AT_friend";
4996 case DW_AT_identifier_case
:
4997 return "DW_AT_identifier_case";
4998 case DW_AT_macro_info
:
4999 return "DW_AT_macro_info";
5000 case DW_AT_namelist_items
:
5001 return "DW_AT_namelist_items";
5002 case DW_AT_priority
:
5003 return "DW_AT_priority";
5005 return "DW_AT_segment";
5006 case DW_AT_specification
:
5007 return "DW_AT_specification";
5008 case DW_AT_static_link
:
5009 return "DW_AT_static_link";
5011 return "DW_AT_type";
5012 case DW_AT_use_location
:
5013 return "DW_AT_use_location";
5014 case DW_AT_variable_parameter
:
5015 return "DW_AT_variable_parameter";
5016 case DW_AT_virtuality
:
5017 return "DW_AT_virtuality";
5018 case DW_AT_vtable_elem_location
:
5019 return "DW_AT_vtable_elem_location";
5022 case DW_AT_MIPS_fde
:
5023 return "DW_AT_MIPS_fde";
5024 case DW_AT_MIPS_loop_begin
:
5025 return "DW_AT_MIPS_loop_begin";
5026 case DW_AT_MIPS_tail_loop_begin
:
5027 return "DW_AT_MIPS_tail_loop_begin";
5028 case DW_AT_MIPS_epilog_begin
:
5029 return "DW_AT_MIPS_epilog_begin";
5030 case DW_AT_MIPS_loop_unroll_factor
:
5031 return "DW_AT_MIPS_loop_unroll_factor";
5032 case DW_AT_MIPS_software_pipeline_depth
:
5033 return "DW_AT_MIPS_software_pipeline_depth";
5034 case DW_AT_MIPS_linkage_name
:
5035 return "DW_AT_MIPS_linkage_name";
5038 case DW_AT_sf_names
:
5039 return "DW_AT_sf_names";
5040 case DW_AT_src_info
:
5041 return "DW_AT_src_info";
5042 case DW_AT_mac_info
:
5043 return "DW_AT_mac_info";
5044 case DW_AT_src_coords
:
5045 return "DW_AT_src_coords";
5046 case DW_AT_body_begin
:
5047 return "DW_AT_body_begin";
5048 case DW_AT_body_end
:
5049 return "DW_AT_body_end";
5051 return "DW_AT_<unknown>";
5055 /* Convert a DWARF value form code into its string name. */
5058 dwarf_form_name (register unsigned form
)
5063 return "DW_FORM_addr";
5064 case DW_FORM_block2
:
5065 return "DW_FORM_block2";
5066 case DW_FORM_block4
:
5067 return "DW_FORM_block4";
5069 return "DW_FORM_data2";
5071 return "DW_FORM_data4";
5073 return "DW_FORM_data8";
5074 case DW_FORM_string
:
5075 return "DW_FORM_string";
5077 return "DW_FORM_block";
5078 case DW_FORM_block1
:
5079 return "DW_FORM_block1";
5081 return "DW_FORM_data1";
5083 return "DW_FORM_flag";
5085 return "DW_FORM_sdata";
5087 return "DW_FORM_strp";
5089 return "DW_FORM_udata";
5090 case DW_FORM_ref_addr
:
5091 return "DW_FORM_ref_addr";
5093 return "DW_FORM_ref1";
5095 return "DW_FORM_ref2";
5097 return "DW_FORM_ref4";
5099 return "DW_FORM_ref8";
5100 case DW_FORM_ref_udata
:
5101 return "DW_FORM_ref_udata";
5102 case DW_FORM_indirect
:
5103 return "DW_FORM_indirect";
5105 return "DW_FORM_<unknown>";
5109 /* Convert a DWARF stack opcode into its string name. */
5112 dwarf_stack_op_name (register unsigned op
)
5117 return "DW_OP_addr";
5119 return "DW_OP_deref";
5121 return "DW_OP_const1u";
5123 return "DW_OP_const1s";
5125 return "DW_OP_const2u";
5127 return "DW_OP_const2s";
5129 return "DW_OP_const4u";
5131 return "DW_OP_const4s";
5133 return "DW_OP_const8u";
5135 return "DW_OP_const8s";
5137 return "DW_OP_constu";
5139 return "DW_OP_consts";
5143 return "DW_OP_drop";
5145 return "DW_OP_over";
5147 return "DW_OP_pick";
5149 return "DW_OP_swap";
5153 return "DW_OP_xderef";
5161 return "DW_OP_minus";
5173 return "DW_OP_plus";
5174 case DW_OP_plus_uconst
:
5175 return "DW_OP_plus_uconst";
5181 return "DW_OP_shra";
5199 return "DW_OP_skip";
5201 return "DW_OP_lit0";
5203 return "DW_OP_lit1";
5205 return "DW_OP_lit2";
5207 return "DW_OP_lit3";
5209 return "DW_OP_lit4";
5211 return "DW_OP_lit5";
5213 return "DW_OP_lit6";
5215 return "DW_OP_lit7";
5217 return "DW_OP_lit8";
5219 return "DW_OP_lit9";
5221 return "DW_OP_lit10";
5223 return "DW_OP_lit11";
5225 return "DW_OP_lit12";
5227 return "DW_OP_lit13";
5229 return "DW_OP_lit14";
5231 return "DW_OP_lit15";
5233 return "DW_OP_lit16";
5235 return "DW_OP_lit17";
5237 return "DW_OP_lit18";
5239 return "DW_OP_lit19";
5241 return "DW_OP_lit20";
5243 return "DW_OP_lit21";
5245 return "DW_OP_lit22";
5247 return "DW_OP_lit23";
5249 return "DW_OP_lit24";
5251 return "DW_OP_lit25";
5253 return "DW_OP_lit26";
5255 return "DW_OP_lit27";
5257 return "DW_OP_lit28";
5259 return "DW_OP_lit29";
5261 return "DW_OP_lit30";
5263 return "DW_OP_lit31";
5265 return "DW_OP_reg0";
5267 return "DW_OP_reg1";
5269 return "DW_OP_reg2";
5271 return "DW_OP_reg3";
5273 return "DW_OP_reg4";
5275 return "DW_OP_reg5";
5277 return "DW_OP_reg6";
5279 return "DW_OP_reg7";
5281 return "DW_OP_reg8";
5283 return "DW_OP_reg9";
5285 return "DW_OP_reg10";
5287 return "DW_OP_reg11";
5289 return "DW_OP_reg12";
5291 return "DW_OP_reg13";
5293 return "DW_OP_reg14";
5295 return "DW_OP_reg15";
5297 return "DW_OP_reg16";
5299 return "DW_OP_reg17";
5301 return "DW_OP_reg18";
5303 return "DW_OP_reg19";
5305 return "DW_OP_reg20";
5307 return "DW_OP_reg21";
5309 return "DW_OP_reg22";
5311 return "DW_OP_reg23";
5313 return "DW_OP_reg24";
5315 return "DW_OP_reg25";
5317 return "DW_OP_reg26";
5319 return "DW_OP_reg27";
5321 return "DW_OP_reg28";
5323 return "DW_OP_reg29";
5325 return "DW_OP_reg30";
5327 return "DW_OP_reg31";
5329 return "DW_OP_breg0";
5331 return "DW_OP_breg1";
5333 return "DW_OP_breg2";
5335 return "DW_OP_breg3";
5337 return "DW_OP_breg4";
5339 return "DW_OP_breg5";
5341 return "DW_OP_breg6";
5343 return "DW_OP_breg7";
5345 return "DW_OP_breg8";
5347 return "DW_OP_breg9";
5349 return "DW_OP_breg10";
5351 return "DW_OP_breg11";
5353 return "DW_OP_breg12";
5355 return "DW_OP_breg13";
5357 return "DW_OP_breg14";
5359 return "DW_OP_breg15";
5361 return "DW_OP_breg16";
5363 return "DW_OP_breg17";
5365 return "DW_OP_breg18";
5367 return "DW_OP_breg19";
5369 return "DW_OP_breg20";
5371 return "DW_OP_breg21";
5373 return "DW_OP_breg22";
5375 return "DW_OP_breg23";
5377 return "DW_OP_breg24";
5379 return "DW_OP_breg25";
5381 return "DW_OP_breg26";
5383 return "DW_OP_breg27";
5385 return "DW_OP_breg28";
5387 return "DW_OP_breg29";
5389 return "DW_OP_breg30";
5391 return "DW_OP_breg31";
5393 return "DW_OP_regx";
5395 return "DW_OP_fbreg";
5397 return "DW_OP_bregx";
5399 return "DW_OP_piece";
5400 case DW_OP_deref_size
:
5401 return "DW_OP_deref_size";
5402 case DW_OP_xderef_size
:
5403 return "DW_OP_xderef_size";
5407 return "OP_<unknown>";
5412 dwarf_bool_name (unsigned mybool
)
5420 /* Convert a DWARF type code into its string name. */
5423 dwarf_type_encoding_name (register unsigned enc
)
5427 case DW_ATE_address
:
5428 return "DW_ATE_address";
5429 case DW_ATE_boolean
:
5430 return "DW_ATE_boolean";
5431 case DW_ATE_complex_float
:
5432 return "DW_ATE_complex_float";
5434 return "DW_ATE_float";
5436 return "DW_ATE_signed";
5437 case DW_ATE_signed_char
:
5438 return "DW_ATE_signed_char";
5439 case DW_ATE_unsigned
:
5440 return "DW_ATE_unsigned";
5441 case DW_ATE_unsigned_char
:
5442 return "DW_ATE_unsigned_char";
5444 return "DW_ATE_<unknown>";
5448 /* Convert a DWARF call frame info operation to its string name. */
5452 dwarf_cfi_name (register unsigned cfi_opc
)
5456 case DW_CFA_advance_loc
:
5457 return "DW_CFA_advance_loc";
5459 return "DW_CFA_offset";
5460 case DW_CFA_restore
:
5461 return "DW_CFA_restore";
5463 return "DW_CFA_nop";
5464 case DW_CFA_set_loc
:
5465 return "DW_CFA_set_loc";
5466 case DW_CFA_advance_loc1
:
5467 return "DW_CFA_advance_loc1";
5468 case DW_CFA_advance_loc2
:
5469 return "DW_CFA_advance_loc2";
5470 case DW_CFA_advance_loc4
:
5471 return "DW_CFA_advance_loc4";
5472 case DW_CFA_offset_extended
:
5473 return "DW_CFA_offset_extended";
5474 case DW_CFA_restore_extended
:
5475 return "DW_CFA_restore_extended";
5476 case DW_CFA_undefined
:
5477 return "DW_CFA_undefined";
5478 case DW_CFA_same_value
:
5479 return "DW_CFA_same_value";
5480 case DW_CFA_register
:
5481 return "DW_CFA_register";
5482 case DW_CFA_remember_state
:
5483 return "DW_CFA_remember_state";
5484 case DW_CFA_restore_state
:
5485 return "DW_CFA_restore_state";
5486 case DW_CFA_def_cfa
:
5487 return "DW_CFA_def_cfa";
5488 case DW_CFA_def_cfa_register
:
5489 return "DW_CFA_def_cfa_register";
5490 case DW_CFA_def_cfa_offset
:
5491 return "DW_CFA_def_cfa_offset";
5492 /* SGI/MIPS specific */
5493 case DW_CFA_MIPS_advance_loc8
:
5494 return "DW_CFA_MIPS_advance_loc8";
5496 return "DW_CFA_<unknown>";
5502 dump_die (struct die_info
*die
)
5506 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5507 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5508 fprintf (stderr
, "\thas children: %s\n",
5509 dwarf_bool_name (die
->has_children
));
5511 fprintf (stderr
, "\tattributes:\n");
5512 for (i
= 0; i
< die
->num_attrs
; ++i
)
5514 fprintf (stderr
, "\t\t%s (%s) ",
5515 dwarf_attr_name (die
->attrs
[i
].name
),
5516 dwarf_form_name (die
->attrs
[i
].form
));
5517 switch (die
->attrs
[i
].form
)
5519 case DW_FORM_ref_addr
:
5521 fprintf (stderr
, "address: ");
5522 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5524 case DW_FORM_block2
:
5525 case DW_FORM_block4
:
5527 case DW_FORM_block1
:
5528 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5539 fprintf (stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
5541 case DW_FORM_string
:
5542 fprintf (stderr
, "string: \"%s\"",
5543 DW_STRING (&die
->attrs
[i
])
5544 ? DW_STRING (&die
->attrs
[i
]) : "");
5547 if (DW_UNSND (&die
->attrs
[i
]))
5548 fprintf (stderr
, "flag: TRUE");
5550 fprintf (stderr
, "flag: FALSE");
5552 case DW_FORM_strp
: /* we do not support separate string
5554 case DW_FORM_indirect
: /* we do not handle indirect yet */
5556 fprintf (stderr
, "unsupported attribute form: %d.",
5557 die
->attrs
[i
].form
);
5559 fprintf (stderr
, "\n");
5564 dump_die_list (struct die_info
*die
)
5574 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
5577 struct die_info
*old
;
5579 h
= (offset
% REF_HASH_SIZE
);
5580 old
= die_ref_table
[h
];
5581 die
->next_ref
= old
;
5582 die_ref_table
[h
] = die
;
5587 dwarf2_empty_hash_tables (void)
5589 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5593 dwarf2_get_ref_die_offset (struct attribute
*attr
)
5595 unsigned int result
= 0;
5599 case DW_FORM_ref_addr
:
5600 result
= DW_ADDR (attr
);
5606 case DW_FORM_ref_udata
:
5607 result
= cu_header_offset
+ DW_UNSND (attr
);
5610 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5615 static struct die_info
*
5616 follow_die_ref (unsigned int offset
)
5618 struct die_info
*die
;
5621 h
= (offset
% REF_HASH_SIZE
);
5622 die
= die_ref_table
[h
];
5625 if (die
->offset
== offset
)
5629 die
= die
->next_ref
;
5634 static struct type
*
5635 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
5637 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5639 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5643 /* Look for this particular type in the fundamental type vector. If
5644 one is not found, create and install one appropriate for the
5645 current language and the current target machine. */
5647 if (ftypes
[typeid] == NULL
)
5649 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5652 return (ftypes
[typeid]);
5655 /* Decode simple location descriptions.
5656 Given a pointer to a dwarf block that defines a location, compute
5657 the location and return the value.
5659 FIXME: This is a kludge until we figure out a better
5660 way to handle the location descriptions.
5661 Gdb's design does not mesh well with the DWARF2 notion of a location
5662 computing interpreter, which is a shame because the flexibility goes unused.
5663 FIXME: Implement more operations as necessary.
5665 A location description containing no operations indicates that the
5666 object is optimized out. The global optimized_out flag is set for
5667 those, the return value is meaningless.
5669 When the result is a register number, the global isreg flag is set,
5670 otherwise it is cleared.
5672 When the result is a base register offset, the global offreg flag is set
5673 and the register number is returned in basereg, otherwise it is cleared.
5675 When the DW_OP_fbreg operation is encountered without a corresponding
5676 DW_AT_frame_base attribute, the global islocal flag is set.
5677 Hopefully the machine dependent code knows how to set up a virtual
5678 frame pointer for the local references.
5680 Note that stack[0] is unused except as a default error return.
5681 Note that stack overflow is not yet handled. */
5684 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
5685 const struct comp_unit_head
*cu_header
)
5688 int size
= blk
->size
;
5689 char *data
= blk
->data
;
5690 CORE_ADDR stack
[64];
5692 unsigned int bytes_read
, unsnd
;
5743 stack
[++stacki
] = op
- DW_OP_reg0
;
5748 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5750 #if defined(HARRIS_TARGET) && defined(_M88K)
5751 /* The Harris 88110 gdb ports have long kept their special reg
5752 numbers between their gp-regs and their x-regs. This is
5753 not how our dwarf is generated. Punt. */
5756 stack
[++stacki
] = unsnd
;
5792 basereg
= op
- DW_OP_breg0
;
5793 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5799 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5801 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5806 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5808 if (frame_base_reg
>= 0)
5811 basereg
= frame_base_reg
;
5812 stack
[stacki
] += frame_base_offset
;
5816 complain (&dwarf2_missing_at_frame_base
);
5822 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
5823 cu_header
, &bytes_read
);
5828 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5833 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5838 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5843 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5848 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5853 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5858 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5864 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5869 stack
[stacki
- 1] += stack
[stacki
];
5873 case DW_OP_plus_uconst
:
5874 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5879 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5885 /* If we're not the last op, then we definitely can't encode
5886 this using GDB's address_class enum. */
5888 complain (&dwarf2_complex_location_expr
);
5892 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
5893 return (stack
[stacki
]);
5896 return (stack
[stacki
]);
5899 /* memory allocation interface */
5903 dwarf2_free_tmp_obstack (PTR ignore
)
5905 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5908 static struct dwarf_block
*
5909 dwarf_alloc_block (void)
5911 struct dwarf_block
*blk
;
5913 blk
= (struct dwarf_block
*)
5914 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5918 static struct abbrev_info
*
5919 dwarf_alloc_abbrev (void)
5921 struct abbrev_info
*abbrev
;
5923 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5924 memset (abbrev
, 0, sizeof (struct abbrev_info
));
5928 static struct die_info
*
5929 dwarf_alloc_die (void)
5931 struct die_info
*die
;
5933 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5934 memset (die
, 0, sizeof (struct die_info
));