1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
4 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
5 Inc. with support from Florida State University (under contract
6 with the Ada Joint Program Office), and Silicon Graphics, Inc.
7 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
8 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
11 This file is part of GDB.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or (at
16 your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. */
34 #include "elf/dwarf2.h"
37 #include "expression.h"
40 #include "complaints.h"
43 #include "gdb_string.h"
44 #include <sys/types.h>
46 /* .debug_info header for a compilation unit
47 Because of alignment constraints, this structure has padding and cannot
48 be mapped directly onto the beginning of the .debug_info section. */
49 typedef struct comp_unit_header
51 unsigned int length
; /* length of the .debug_info
53 unsigned short version
; /* version number -- 2 for DWARF
55 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
56 unsigned char addr_size
; /* byte size of an address -- 4 */
59 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
61 /* .debug_pubnames header
62 Because of alignment constraints, this structure has padding and cannot
63 be mapped directly onto the beginning of the .debug_info section. */
64 typedef struct pubnames_header
66 unsigned int length
; /* length of the .debug_pubnames
68 unsigned char version
; /* version number -- 2 for DWARF
70 unsigned int info_offset
; /* offset into .debug_info section */
71 unsigned int info_size
; /* byte size of .debug_info section
75 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
77 /* .debug_pubnames header
78 Because of alignment constraints, this structure has padding and cannot
79 be mapped directly onto the beginning of the .debug_info section. */
80 typedef struct aranges_header
82 unsigned int length
; /* byte len of the .debug_aranges
84 unsigned short version
; /* version number -- 2 for DWARF
86 unsigned int info_offset
; /* offset into .debug_info section */
87 unsigned char addr_size
; /* byte size of an address */
88 unsigned char seg_size
; /* byte size of segment descriptor */
91 #define _ACTUAL_ARANGES_HEADER_SIZE 12
93 /* .debug_line statement program prologue
94 Because of alignment constraints, this structure has padding and cannot
95 be mapped directly onto the beginning of the .debug_info section. */
96 typedef struct statement_prologue
98 unsigned int total_length
; /* byte length of the statement
100 unsigned short version
; /* version number -- 2 for DWARF
102 unsigned int prologue_length
; /* # bytes between prologue &
104 unsigned char minimum_instruction_length
; /* byte size of
106 unsigned char default_is_stmt
; /* initial value of is_stmt
109 unsigned char line_range
;
110 unsigned char opcode_base
; /* number assigned to first special
112 unsigned char *standard_opcode_lengths
;
116 /* offsets and sizes of debugging sections */
118 static file_ptr dwarf_info_offset
;
119 static file_ptr dwarf_abbrev_offset
;
120 static file_ptr dwarf_line_offset
;
121 static file_ptr dwarf_pubnames_offset
;
122 static file_ptr dwarf_aranges_offset
;
123 static file_ptr dwarf_loc_offset
;
124 static file_ptr dwarf_macinfo_offset
;
125 static file_ptr dwarf_str_offset
;
127 static unsigned int dwarf_info_size
;
128 static unsigned int dwarf_abbrev_size
;
129 static unsigned int dwarf_line_size
;
130 static unsigned int dwarf_pubnames_size
;
131 static unsigned int dwarf_aranges_size
;
132 static unsigned int dwarf_loc_size
;
133 static unsigned int dwarf_macinfo_size
;
134 static unsigned int dwarf_str_size
;
136 /* names of the debugging sections */
138 #define INFO_SECTION ".debug_info"
139 #define ABBREV_SECTION ".debug_abbrev"
140 #define LINE_SECTION ".debug_line"
141 #define PUBNAMES_SECTION ".debug_pubnames"
142 #define ARANGES_SECTION ".debug_aranges"
143 #define LOC_SECTION ".debug_loc"
144 #define MACINFO_SECTION ".debug_macinfo"
145 #define STR_SECTION ".debug_str"
147 /* local data types */
149 /* The data in a compilation unit header looks like this. */
150 struct comp_unit_head
154 unsigned int abbrev_offset
;
155 unsigned char addr_size
;
158 /* The data in the .debug_line statement prologue looks like this. */
161 unsigned int total_length
;
162 unsigned short version
;
163 unsigned int prologue_length
;
164 unsigned char minimum_instruction_length
;
165 unsigned char default_is_stmt
;
167 unsigned char line_range
;
168 unsigned char opcode_base
;
169 unsigned char *standard_opcode_lengths
;
172 /* When we construct a partial symbol table entry we only
173 need this much information. */
174 struct partial_die_info
177 unsigned char has_children
;
178 unsigned char is_external
;
179 unsigned char is_declaration
;
180 unsigned char has_type
;
186 struct dwarf_block
*locdesc
;
187 unsigned int language
;
191 /* This data structure holds the information of an abbrev. */
194 unsigned int number
; /* number identifying abbrev */
195 enum dwarf_tag tag
; /* dwarf tag */
196 int has_children
; /* boolean */
197 unsigned int num_attrs
; /* number of attributes */
198 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
199 struct abbrev_info
*next
; /* next in chain */
204 enum dwarf_attribute name
;
205 enum dwarf_form form
;
208 /* This data structure holds a complete die structure. */
211 enum dwarf_tag tag
; /* Tag indicating type of die */
212 unsigned short has_children
; /* Does the die have children */
213 unsigned int abbrev
; /* Abbrev number */
214 unsigned int offset
; /* Offset in .debug_info section */
215 unsigned int num_attrs
; /* Number of attributes */
216 struct attribute
*attrs
; /* An array of attributes */
217 struct die_info
*next_ref
; /* Next die in ref hash table */
218 struct die_info
*next
; /* Next die in linked list */
219 struct type
*type
; /* Cached type information */
222 /* Attributes have a name and a value */
225 enum dwarf_attribute name
;
226 enum dwarf_form form
;
230 struct dwarf_block
*blk
;
238 /* Get at parts of an attribute structure */
240 #define DW_STRING(attr) ((attr)->u.str)
241 #define DW_UNSND(attr) ((attr)->u.unsnd)
242 #define DW_BLOCK(attr) ((attr)->u.blk)
243 #define DW_SND(attr) ((attr)->u.snd)
244 #define DW_ADDR(attr) ((attr)->u.addr)
246 /* Blocks are a bunch of untyped bytes. */
253 /* We only hold one compilation unit's abbrevs in
254 memory at any one time. */
255 #ifndef ABBREV_HASH_SIZE
256 #define ABBREV_HASH_SIZE 121
258 #ifndef ATTR_ALLOC_CHUNK
259 #define ATTR_ALLOC_CHUNK 4
262 static struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
264 /* A hash table of die offsets for following references. */
265 #ifndef REF_HASH_SIZE
266 #define REF_HASH_SIZE 1021
269 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
271 #ifndef TYPE_HASH_SIZE
272 #define TYPE_HASH_SIZE 4096
274 static struct type
*dwarf2_cached_types
[TYPE_HASH_SIZE
];
276 /* Obstack for allocating temporary storage used during symbol reading. */
277 static struct obstack dwarf2_tmp_obstack
;
279 /* Offset to the first byte of the current compilation unit header,
280 for resolving relative reference dies. */
281 static unsigned int cu_header_offset
;
283 /* Allocate fields for structs, unions and enums in this size. */
284 #ifndef DW_FIELD_ALLOC_CHUNK
285 #define DW_FIELD_ALLOC_CHUNK 4
288 /* The language we are debugging. */
289 static enum language cu_language
;
290 static const struct language_defn
*cu_language_defn
;
292 /* Actually data from the sections. */
293 static char *dwarf_info_buffer
;
294 static char *dwarf_abbrev_buffer
;
295 static char *dwarf_line_buffer
;
297 /* A zeroed version of a partial die for initialization purposes. */
298 static struct partial_die_info zeroed_partial_die
;
300 /* The generic symbol table building routines have separate lists for
301 file scope symbols and all all other scopes (local scopes). So
302 we need to select the right one to pass to add_symbol_to_list().
303 We do it by keeping a pointer to the correct list in list_in_scope.
305 FIXME: The original dwarf code just treated the file scope as the first
306 local scope, and all other local scopes as nested local scopes, and worked
307 fine. Check to see if we really need to distinguish these
309 static struct pending
**list_in_scope
= &file_symbols
;
311 /* FIXME: decode_locdesc sets these variables to describe the location
312 to the caller. These ought to be a structure or something. If
313 none of the flags are set, the object lives at the address returned
314 by decode_locdesc. */
316 static int optimized_out
; /* No ops in location in expression,
317 so object was optimized out. */
318 static int isreg
; /* Object lives in register.
319 decode_locdesc's return value is
320 the register number. */
321 static int offreg
; /* Object's address is the sum of the
322 register specified by basereg, plus
323 the offset returned. */
324 static int basereg
; /* See `offreg'. */
325 static int isderef
; /* Value described by flags above is
326 the address of a pointer to the object. */
327 static int islocal
; /* Variable is at the returned offset
328 from the frame start, but there's
329 no identified frame pointer for
330 this function, so we can't say
331 which register it's relative to;
334 /* DW_AT_frame_base values for the current function.
335 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
336 contains the register number for the frame register.
337 frame_base_offset is the offset from the frame register to the
338 virtual stack frame. */
339 static int frame_base_reg
;
340 static CORE_ADDR frame_base_offset
;
342 /* This value is added to each symbol value. FIXME: Generalize to
343 the section_offsets structure used by dbxread (once this is done,
344 pass the appropriate section number to end_symtab). */
345 static CORE_ADDR baseaddr
; /* Add to each symbol value */
347 /* We put a pointer to this structure in the read_symtab_private field
349 The complete dwarf information for an objfile is kept in the
350 psymbol_obstack, so that absolute die references can be handled.
351 Most of the information in this structure is related to an entire
352 object file and could be passed via the sym_private field of the objfile.
353 It is however conceivable that dwarf2 might not be the only type
354 of symbols read from an object file. */
358 /* Pointer to start of dwarf info buffer for the objfile. */
360 char *dwarf_info_buffer
;
362 /* Offset in dwarf_info_buffer for this compilation unit. */
364 unsigned long dwarf_info_offset
;
366 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
368 char *dwarf_abbrev_buffer
;
370 /* Size of dwarf abbreviation section for the objfile. */
372 unsigned int dwarf_abbrev_size
;
374 /* Pointer to start of dwarf line buffer for the objfile. */
376 char *dwarf_line_buffer
;
379 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
380 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
381 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
382 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
383 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
384 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
386 /* Maintain an array of referenced fundamental types for the current
387 compilation unit being read. For DWARF version 1, we have to construct
388 the fundamental types on the fly, since no information about the
389 fundamental types is supplied. Each such fundamental type is created by
390 calling a language dependent routine to create the type, and then a
391 pointer to that type is then placed in the array at the index specified
392 by it's FT_<TYPENAME> value. The array has a fixed size set by the
393 FT_NUM_MEMBERS compile time constant, which is the number of predefined
394 fundamental types gdb knows how to construct. */
395 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
397 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
398 but this would require a corresponding change in unpack_field_as_long
400 static int bits_per_byte
= 8;
402 /* The routines that read and process dies for a C struct or C++ class
403 pass lists of data member fields and lists of member function fields
404 in an instance of a field_info structure, as defined below. */
407 /* List of data member and baseclasses fields. */
410 struct nextfield
*next
;
417 /* Number of fields. */
420 /* Number of baseclasses. */
423 /* Set if the accesibility of one of the fields is not public. */
424 int non_public_fields
;
426 /* Member function fields array, entries are allocated in the order they
427 are encountered in the object file. */
430 struct nextfnfield
*next
;
431 struct fn_field fnfield
;
435 /* Member function fieldlist array, contains name of possibly overloaded
436 member function, number of overloaded member functions and a pointer
437 to the head of the member function field chain. */
442 struct nextfnfield
*head
;
446 /* Number of entries in the fnfieldlists array. */
450 /* FIXME: Kludge to mark a varargs function type for C++ member function
451 argument processing. */
452 #define TYPE_FLAG_VARARGS (1 << 10)
454 /* Dwarf2 has no clean way to discern C++ static and non-static member
455 functions. G++ helps GDB by marking the first parameter for non-static
456 member functions (which is the this pointer) as artificial.
457 We pass this information between dwarf2_add_member_fn and
458 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
459 #define TYPE_FIELD_ARTIFICIAL TYPE_FIELD_BITPOS
461 /* Various complaints about symbol reading that don't abort the process */
463 static struct complaint dwarf2_const_ignored
=
465 "type qualifier 'const' ignored", 0, 0
467 static struct complaint dwarf2_volatile_ignored
=
469 "type qualifier 'volatile' ignored", 0, 0
471 static struct complaint dwarf2_non_const_array_bound_ignored
=
473 "non-constant array bounds form '%s' ignored", 0, 0
475 static struct complaint dwarf2_missing_line_number_section
=
477 "missing .debug_line section", 0, 0
479 static struct complaint dwarf2_mangled_line_number_section
=
481 "mangled .debug_line section", 0, 0
483 static struct complaint dwarf2_unsupported_die_ref_attr
=
485 "unsupported die ref attribute form: '%s'", 0, 0
487 static struct complaint dwarf2_unsupported_stack_op
=
489 "unsupported stack op: '%s'", 0, 0
491 static struct complaint dwarf2_complex_location_expr
=
493 "location expression too complex", 0, 0
495 static struct complaint dwarf2_unsupported_tag
=
497 "unsupported tag: '%s'", 0, 0
499 static struct complaint dwarf2_unsupported_at_encoding
=
501 "unsupported DW_AT_encoding: '%s'", 0, 0
503 static struct complaint dwarf2_unsupported_at_frame_base
=
505 "unsupported DW_AT_frame_base for function '%s'", 0, 0
507 static struct complaint dwarf2_unexpected_tag
=
509 "unexepected tag in read_type_die: '%s'", 0, 0
511 static struct complaint dwarf2_missing_at_frame_base
=
513 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
515 static struct complaint dwarf2_bad_static_member_name
=
517 "unrecognized static data member name '%s'", 0, 0
519 static struct complaint dwarf2_unsupported_accessibility
=
521 "unsupported accessibility %d", 0, 0
523 static struct complaint dwarf2_bad_member_name_complaint
=
525 "cannot extract member name from '%s'", 0, 0
527 static struct complaint dwarf2_missing_member_fn_type_complaint
=
529 "member function type missing for '%s'", 0, 0
531 static struct complaint dwarf2_vtbl_not_found_complaint
=
533 "virtual function table pointer not found when defining class '%s'", 0, 0
535 static struct complaint dwarf2_absolute_sibling_complaint
=
537 "ignoring absolute DW_AT_sibling", 0, 0
539 static struct complaint dwarf2_const_value_length_mismatch
=
541 "const value length mismatch for '%s', got %d, expected %d", 0, 0
543 static struct complaint dwarf2_unsupported_const_value_attr
=
545 "unsupported const value attribute form: '%s'", 0, 0
548 /* Remember the addr_size read from the dwarf.
549 If a target expects to link compilation units with differing address
550 sizes, gdb needs to be sure that the appropriate size is here for
551 whatever scope is currently getting read. */
552 static int address_size
;
554 /* Externals references. */
555 extern int info_verbose
; /* From main.c; nonzero => verbose */
557 /* local function prototypes */
559 static void dwarf2_locate_sections (bfd
*, asection
*, PTR
);
562 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
565 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
567 static char *scan_partial_symbols (char *, struct objfile
*,
568 CORE_ADDR
*, CORE_ADDR
*);
570 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*);
572 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
574 static void psymtab_to_symtab_1 (struct partial_symtab
*);
576 static char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int);
578 static void dwarf2_read_abbrevs (bfd
*, unsigned int);
580 static void dwarf2_empty_abbrev_table (PTR
);
582 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int);
584 static char *read_partial_die (struct partial_die_info
*,
585 bfd
*, char *, int *);
587 static char *read_full_die (struct die_info
**, bfd
*, char *);
589 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
592 static unsigned int read_1_byte (bfd
*, char *);
594 static int read_1_signed_byte (bfd
*, char *);
596 static unsigned int read_2_bytes (bfd
*, char *);
598 static unsigned int read_4_bytes (bfd
*, char *);
600 static unsigned long read_8_bytes (bfd
*, char *);
602 static CORE_ADDR
read_address (bfd
*, char *);
604 static char *read_n_bytes (bfd
*, char *, unsigned int);
606 static char *read_string (bfd
*, char *, unsigned int *);
608 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
610 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
612 static void set_cu_language (unsigned int);
614 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
616 static int die_is_declaration (struct die_info
*);
618 static void dwarf_decode_lines (unsigned int, char *, bfd
*);
620 static void dwarf2_start_subfile (char *, char *);
622 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
625 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
628 static void dwarf2_const_value_data (struct attribute
*attr
,
632 static struct type
*die_type (struct die_info
*, struct objfile
*);
634 static struct type
*die_containing_type (struct die_info
*, struct objfile
*);
637 static struct type
*type_at_offset (unsigned int, struct objfile
*);
640 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*);
642 static void read_type_die (struct die_info
*, struct objfile
*);
644 static void read_typedef (struct die_info
*, struct objfile
*);
646 static void read_base_type (struct die_info
*, struct objfile
*);
648 static void read_file_scope (struct die_info
*, struct objfile
*);
650 static void read_func_scope (struct die_info
*, struct objfile
*);
652 static void read_lexical_block_scope (struct die_info
*, struct objfile
*);
654 static int dwarf2_get_pc_bounds (struct die_info
*,
655 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*);
657 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
660 static void dwarf2_attach_fields_to_type (struct field_info
*,
661 struct type
*, struct objfile
*);
663 static void dwarf2_add_member_fn (struct field_info
*,
664 struct die_info
*, struct type
*,
665 struct objfile
*objfile
);
667 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
668 struct type
*, struct objfile
*);
670 static void read_structure_scope (struct die_info
*, struct objfile
*);
672 static void read_common_block (struct die_info
*, struct objfile
*);
674 static void read_enumeration (struct die_info
*, struct objfile
*);
676 static struct type
*dwarf_base_type (int, int, struct objfile
*);
678 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*);
680 static void read_array_type (struct die_info
*, struct objfile
*);
682 static void read_tag_pointer_type (struct die_info
*, struct objfile
*);
684 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*);
686 static void read_tag_reference_type (struct die_info
*, struct objfile
*);
688 static void read_tag_const_type (struct die_info
*, struct objfile
*);
690 static void read_tag_volatile_type (struct die_info
*, struct objfile
*);
692 static void read_tag_string_type (struct die_info
*, struct objfile
*);
694 static void read_subroutine_type (struct die_info
*, struct objfile
*);
696 struct die_info
*read_comp_unit (char *, bfd
*);
698 static void free_die_list (struct die_info
*);
700 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
702 static void process_die (struct die_info
*, struct objfile
*);
704 static char *dwarf2_linkage_name (struct die_info
*);
706 static char *dwarf_tag_name (unsigned int);
708 static char *dwarf_attr_name (unsigned int);
710 static char *dwarf_form_name (unsigned int);
712 static char *dwarf_stack_op_name (unsigned int);
714 static char *dwarf_bool_name (unsigned int);
716 static char *dwarf_type_encoding_name (unsigned int);
719 static char *dwarf_cfi_name (unsigned int);
721 struct die_info
*copy_die (struct die_info
*);
724 struct die_info
*sibling_die (struct die_info
*);
726 void dump_die (struct die_info
*);
728 void dump_die_list (struct die_info
*);
730 void store_in_ref_table (unsigned int, struct die_info
*);
732 static void dwarf2_empty_hash_tables (void);
734 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
736 struct die_info
*follow_die_ref (unsigned int);
738 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
740 /* memory allocation interface */
742 static void dwarf2_free_tmp_obstack (PTR
);
744 static struct dwarf_block
*dwarf_alloc_block (void);
746 static struct abbrev_info
*dwarf_alloc_abbrev (void);
748 static struct die_info
*dwarf_alloc_die (void);
750 /* Try to locate the sections we need for DWARF 2 debugging
751 information and return true if we have enough to do something. */
754 dwarf2_has_info (abfd
)
757 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
758 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
759 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
769 /* This function is mapped across the sections and remembers the
770 offset and size of each of the debugging sections we are interested
774 dwarf2_locate_sections (ignore_abfd
, sectp
, ignore_ptr
)
779 if (STREQ (sectp
->name
, INFO_SECTION
))
781 dwarf_info_offset
= sectp
->filepos
;
782 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
784 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
786 dwarf_abbrev_offset
= sectp
->filepos
;
787 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
789 else if (STREQ (sectp
->name
, LINE_SECTION
))
791 dwarf_line_offset
= sectp
->filepos
;
792 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
794 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
796 dwarf_pubnames_offset
= sectp
->filepos
;
797 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
799 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
801 dwarf_aranges_offset
= sectp
->filepos
;
802 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
804 else if (STREQ (sectp
->name
, LOC_SECTION
))
806 dwarf_loc_offset
= sectp
->filepos
;
807 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
809 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
811 dwarf_macinfo_offset
= sectp
->filepos
;
812 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
814 else if (STREQ (sectp
->name
, STR_SECTION
))
816 dwarf_str_offset
= sectp
->filepos
;
817 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
821 /* Build a partial symbol table. */
824 dwarf2_build_psymtabs (objfile
, mainline
)
825 struct objfile
*objfile
;
829 /* We definitely need the .debug_info and .debug_abbrev sections */
831 dwarf_info_buffer
= dwarf2_read_section (objfile
,
834 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
837 dwarf_line_buffer
= dwarf2_read_section (objfile
,
841 if (mainline
|| objfile
->global_psymbols
.size
== 0 ||
842 objfile
->static_psymbols
.size
== 0)
844 init_psymbol_list (objfile
, 1024);
848 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
850 /* Things are significantly easier if we have .debug_aranges and
851 .debug_pubnames sections */
853 dwarf2_build_psymtabs_easy (objfile
, mainline
);
857 /* only test this case for now */
859 /* In this case we have to work a bit harder */
860 dwarf2_build_psymtabs_hard (objfile
, mainline
);
865 /* Build the partial symbol table from the information in the
866 .debug_pubnames and .debug_aranges sections. */
869 dwarf2_build_psymtabs_easy (objfile
, mainline
)
870 struct objfile
*objfile
;
873 bfd
*abfd
= objfile
->obfd
;
874 char *aranges_buffer
, *pubnames_buffer
;
875 char *aranges_ptr
, *pubnames_ptr
;
876 unsigned int entry_length
, version
, info_offset
, info_size
;
878 pubnames_buffer
= dwarf2_read_section (objfile
,
879 dwarf_pubnames_offset
,
880 dwarf_pubnames_size
);
881 pubnames_ptr
= pubnames_buffer
;
882 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
884 entry_length
= read_4_bytes (abfd
, pubnames_ptr
);
886 version
= read_1_byte (abfd
, pubnames_ptr
);
888 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
890 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
894 aranges_buffer
= dwarf2_read_section (objfile
,
895 dwarf_aranges_offset
,
901 /* Build the partial symbol table by doing a quick pass through the
902 .debug_info and .debug_abbrev sections. */
905 dwarf2_build_psymtabs_hard (objfile
, mainline
)
906 struct objfile
*objfile
;
909 /* Instead of reading this into a big buffer, we should probably use
910 mmap() on architectures that support it. (FIXME) */
911 bfd
*abfd
= objfile
->obfd
;
912 char *info_ptr
, *abbrev_ptr
;
913 char *beg_of_comp_unit
;
914 struct comp_unit_head cu_header
;
915 struct partial_die_info comp_unit_die
;
916 struct partial_symtab
*pst
;
917 struct cleanup
*back_to
;
918 int comp_unit_has_pc_info
;
919 CORE_ADDR lowpc
, highpc
;
921 info_ptr
= dwarf_info_buffer
;
922 abbrev_ptr
= dwarf_abbrev_buffer
;
924 obstack_init (&dwarf2_tmp_obstack
);
925 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
927 while ((unsigned int) (info_ptr
- dwarf_info_buffer
)
928 + ((info_ptr
- dwarf_info_buffer
) % 4) < dwarf_info_size
)
930 beg_of_comp_unit
= info_ptr
;
931 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
933 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
935 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
937 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
939 address_size
= cu_header
.addr_size
;
941 if (cu_header
.version
!= 2)
943 error ("Dwarf Error: wrong version in compilation unit header.");
946 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
948 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
949 (long) cu_header
.abbrev_offset
,
950 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
953 if (beg_of_comp_unit
+ cu_header
.length
+ 4
954 > dwarf_info_buffer
+ dwarf_info_size
)
956 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
957 (long) cu_header
.length
,
958 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
961 /* Read the abbrevs for this compilation unit into a table */
962 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
963 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
965 /* Read the compilation unit die */
966 info_ptr
= read_partial_die (&comp_unit_die
, abfd
,
967 info_ptr
, &comp_unit_has_pc_info
);
969 /* Set the language we're debugging */
970 set_cu_language (comp_unit_die
.language
);
972 /* Allocate a new partial symbol table structure */
973 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
974 comp_unit_die
.name
? comp_unit_die
.name
: "",
976 objfile
->global_psymbols
.next
,
977 objfile
->static_psymbols
.next
);
979 pst
->read_symtab_private
= (char *)
980 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
981 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
982 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
983 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
984 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
985 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
986 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
987 baseaddr
= ANOFFSET (objfile
->section_offsets
, 0);
989 /* Store the function that reads in the rest of the symbol table */
990 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
992 /* Check if comp unit has_children.
993 If so, read the rest of the partial symbols from this comp unit.
994 If not, there's no more debug_info for this comp unit. */
995 if (comp_unit_die
.has_children
)
997 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
);
999 /* If the compilation unit didn't have an explicit address range,
1000 then use the information extracted from its child dies. */
1001 if (!comp_unit_has_pc_info
)
1003 comp_unit_die
.lowpc
= lowpc
;
1004 comp_unit_die
.highpc
= highpc
;
1007 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1008 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1010 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1011 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1012 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1013 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1014 sort_pst_symbols (pst
);
1016 /* If there is already a psymtab or symtab for a file of this
1017 name, remove it. (If there is a symtab, more drastic things
1018 also happen.) This happens in VxWorks. */
1019 free_named_symtabs (pst
->filename
);
1021 info_ptr
= beg_of_comp_unit
+ cu_header
.length
+ 4;
1023 do_cleanups (back_to
);
1026 /* Read in all interesting dies to the end of the compilation unit. */
1029 scan_partial_symbols (info_ptr
, objfile
, lowpc
, highpc
)
1031 struct objfile
*objfile
;
1035 bfd
*abfd
= objfile
->obfd
;
1036 struct partial_die_info pdi
;
1038 /* This function is called after we've read in the comp_unit_die in
1039 order to read its children. We start the nesting level at 1 since
1040 we have pushed 1 level down in order to read the comp unit's children.
1041 The comp unit itself is at level 0, so we stop reading when we pop
1042 back to that level. */
1044 int nesting_level
= 1;
1047 *lowpc
= ((CORE_ADDR
) -1);
1048 *highpc
= ((CORE_ADDR
) 0);
1050 while (nesting_level
)
1052 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, &has_pc_info
);
1058 case DW_TAG_subprogram
:
1061 if (pdi
.lowpc
< *lowpc
)
1065 if (pdi
.highpc
> *highpc
)
1067 *highpc
= pdi
.highpc
;
1069 if ((pdi
.is_external
|| nesting_level
== 1)
1070 && !pdi
.is_declaration
)
1072 add_partial_symbol (&pdi
, objfile
);
1076 case DW_TAG_variable
:
1077 case DW_TAG_typedef
:
1078 case DW_TAG_class_type
:
1079 case DW_TAG_structure_type
:
1080 case DW_TAG_union_type
:
1081 case DW_TAG_enumeration_type
:
1082 if ((pdi
.is_external
|| nesting_level
== 1)
1083 && !pdi
.is_declaration
)
1085 add_partial_symbol (&pdi
, objfile
);
1088 case DW_TAG_enumerator
:
1089 /* File scope enumerators are added to the partial symbol
1091 if (nesting_level
== 2)
1092 add_partial_symbol (&pdi
, objfile
);
1094 case DW_TAG_base_type
:
1095 /* File scope base type definitions are added to the partial
1097 if (nesting_level
== 1)
1098 add_partial_symbol (&pdi
, objfile
);
1105 /* If the die has a sibling, skip to the sibling.
1106 Do not skip enumeration types, we want to record their
1108 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1110 info_ptr
= pdi
.sibling
;
1112 else if (pdi
.has_children
)
1114 /* Die has children, but the optional DW_AT_sibling attribute
1125 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1126 from `maint check'. */
1127 if (*lowpc
== ((CORE_ADDR
) -1))
1133 add_partial_symbol (pdi
, objfile
)
1134 struct partial_die_info
*pdi
;
1135 struct objfile
*objfile
;
1141 case DW_TAG_subprogram
:
1142 if (pdi
->is_external
)
1144 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1145 mst_text, objfile); */
1146 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1147 VAR_NAMESPACE
, LOC_BLOCK
,
1148 &objfile
->global_psymbols
,
1149 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1153 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1154 mst_file_text, objfile); */
1155 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1156 VAR_NAMESPACE
, LOC_BLOCK
,
1157 &objfile
->static_psymbols
,
1158 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1161 case DW_TAG_variable
:
1162 if (pdi
->is_external
)
1165 Don't enter into the minimal symbol tables as there is
1166 a minimal symbol table entry from the ELF symbols already.
1167 Enter into partial symbol table if it has a location
1168 descriptor or a type.
1169 If the location descriptor is missing, new_symbol will create
1170 a LOC_UNRESOLVED symbol, the address of the variable will then
1171 be determined from the minimal symbol table whenever the variable
1173 The address for the partial symbol table entry is not
1174 used by GDB, but it comes in handy for debugging partial symbol
1178 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1179 if (pdi
->locdesc
|| pdi
->has_type
)
1180 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1181 VAR_NAMESPACE
, LOC_STATIC
,
1182 &objfile
->global_psymbols
,
1183 0, addr
+ baseaddr
, cu_language
, objfile
);
1187 /* Static Variable. Skip symbols without location descriptors. */
1188 if (pdi
->locdesc
== NULL
)
1190 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1191 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1192 mst_file_data, objfile); */
1193 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1194 VAR_NAMESPACE
, LOC_STATIC
,
1195 &objfile
->static_psymbols
,
1196 0, addr
+ baseaddr
, cu_language
, objfile
);
1199 case DW_TAG_typedef
:
1200 case DW_TAG_base_type
:
1201 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1202 VAR_NAMESPACE
, LOC_TYPEDEF
,
1203 &objfile
->static_psymbols
,
1204 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1206 case DW_TAG_class_type
:
1207 case DW_TAG_structure_type
:
1208 case DW_TAG_union_type
:
1209 case DW_TAG_enumeration_type
:
1210 /* Skip aggregate types without children, these are external
1212 if (pdi
->has_children
== 0)
1214 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1215 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1216 &objfile
->static_psymbols
,
1217 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1219 if (cu_language
== language_cplus
)
1221 /* For C++, these implicitly act as typedefs as well. */
1222 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1223 VAR_NAMESPACE
, LOC_TYPEDEF
,
1224 &objfile
->static_psymbols
,
1225 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1228 case DW_TAG_enumerator
:
1229 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1230 VAR_NAMESPACE
, LOC_CONST
,
1231 &objfile
->static_psymbols
,
1232 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1239 /* Expand this partial symbol table into a full symbol table. */
1242 dwarf2_psymtab_to_symtab (pst
)
1243 struct partial_symtab
*pst
;
1245 /* FIXME: This is barely more than a stub. */
1250 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1256 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1257 gdb_flush (gdb_stdout
);
1260 psymtab_to_symtab_1 (pst
);
1262 /* Finish up the debug error message. */
1264 printf_filtered ("done.\n");
1270 psymtab_to_symtab_1 (pst
)
1271 struct partial_symtab
*pst
;
1273 struct objfile
*objfile
= pst
->objfile
;
1274 bfd
*abfd
= objfile
->obfd
;
1275 struct comp_unit_head cu_header
;
1276 struct die_info
*dies
;
1277 unsigned long offset
;
1278 CORE_ADDR lowpc
, highpc
;
1279 struct die_info
*child_die
;
1281 struct symtab
*symtab
;
1282 struct cleanup
*back_to
;
1284 /* Set local variables from the partial symbol table info. */
1285 offset
= DWARF_INFO_OFFSET (pst
);
1286 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1287 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1288 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1289 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1290 baseaddr
= ANOFFSET (pst
->section_offsets
, 0);
1291 cu_header_offset
= offset
;
1292 info_ptr
= dwarf_info_buffer
+ offset
;
1294 obstack_init (&dwarf2_tmp_obstack
);
1295 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1298 make_cleanup (really_free_pendings
, NULL
);
1300 /* read in the comp_unit header */
1301 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
1303 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
1305 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
1307 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
1310 /* Read the abbrevs for this compilation unit */
1311 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1312 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1314 dies
= read_comp_unit (info_ptr
, abfd
);
1316 make_cleanup_free_die_list (dies
);
1318 /* Do line number decoding in read_file_scope () */
1319 process_die (dies
, objfile
);
1321 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1323 /* Some compilers don't define a DW_AT_high_pc attribute for
1324 the compilation unit. If the DW_AT_high_pc is missing,
1325 synthesize it, by scanning the DIE's below the compilation unit. */
1327 if (dies
->has_children
)
1329 child_die
= dies
->next
;
1330 while (child_die
&& child_die
->tag
)
1332 if (child_die
->tag
== DW_TAG_subprogram
)
1334 CORE_ADDR low
, high
;
1336 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1338 highpc
= max (highpc
, high
);
1341 child_die
= sibling_die (child_die
);
1345 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, 0);
1347 /* Set symtab language to language from DW_AT_language.
1348 If the compilation is from a C file generated by language preprocessors,
1349 do not set the language if it was already deduced by start_subfile. */
1351 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1353 symtab
->language
= cu_language
;
1355 pst
->symtab
= symtab
;
1357 sort_symtab_syms (pst
->symtab
);
1359 do_cleanups (back_to
);
1362 /* Process a die and its children. */
1365 process_die (die
, objfile
)
1366 struct die_info
*die
;
1367 struct objfile
*objfile
;
1371 case DW_TAG_padding
:
1373 case DW_TAG_compile_unit
:
1374 read_file_scope (die
, objfile
);
1376 case DW_TAG_subprogram
:
1377 read_subroutine_type (die
, objfile
);
1378 read_func_scope (die
, objfile
);
1380 case DW_TAG_inlined_subroutine
:
1381 /* FIXME: These are ignored for now.
1382 They could be used to set breakpoints on all inlined instances
1383 of a function and make GDB `next' properly over inlined functions. */
1385 case DW_TAG_lexical_block
:
1386 read_lexical_block_scope (die
, objfile
);
1388 case DW_TAG_class_type
:
1389 case DW_TAG_structure_type
:
1390 case DW_TAG_union_type
:
1391 read_structure_scope (die
, objfile
);
1393 case DW_TAG_enumeration_type
:
1394 read_enumeration (die
, objfile
);
1396 case DW_TAG_subroutine_type
:
1397 read_subroutine_type (die
, objfile
);
1399 case DW_TAG_array_type
:
1400 read_array_type (die
, objfile
);
1402 case DW_TAG_pointer_type
:
1403 read_tag_pointer_type (die
, objfile
);
1405 case DW_TAG_ptr_to_member_type
:
1406 read_tag_ptr_to_member_type (die
, objfile
);
1408 case DW_TAG_reference_type
:
1409 read_tag_reference_type (die
, objfile
);
1411 case DW_TAG_string_type
:
1412 read_tag_string_type (die
, objfile
);
1414 case DW_TAG_base_type
:
1415 read_base_type (die
, objfile
);
1416 if (dwarf_attr (die
, DW_AT_name
))
1418 /* Add a typedef symbol for the base type definition. */
1419 new_symbol (die
, die
->type
, objfile
);
1422 case DW_TAG_common_block
:
1423 read_common_block (die
, objfile
);
1425 case DW_TAG_common_inclusion
:
1428 new_symbol (die
, NULL
, objfile
);
1434 read_file_scope (die
, objfile
)
1435 struct die_info
*die
;
1436 struct objfile
*objfile
;
1438 unsigned int line_offset
= 0;
1439 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1440 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1441 struct attribute
*attr
;
1442 char *name
= "<unknown>";
1443 char *comp_dir
= NULL
;
1444 struct die_info
*child_die
;
1445 bfd
*abfd
= objfile
->obfd
;
1447 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1449 if (die
->has_children
)
1451 child_die
= die
->next
;
1452 while (child_die
&& child_die
->tag
)
1454 if (child_die
->tag
== DW_TAG_subprogram
)
1456 CORE_ADDR low
, high
;
1458 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1460 lowpc
= min (lowpc
, low
);
1461 highpc
= max (highpc
, high
);
1464 child_die
= sibling_die (child_die
);
1469 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1470 from finish_block. */
1471 if (lowpc
== ((CORE_ADDR
) -1))
1476 attr
= dwarf_attr (die
, DW_AT_name
);
1479 name
= DW_STRING (attr
);
1481 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1484 comp_dir
= DW_STRING (attr
);
1487 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1488 directory, get rid of it. */
1489 char *cp
= strchr (comp_dir
, ':');
1491 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1496 if (objfile
->ei
.entry_point
>= lowpc
&&
1497 objfile
->ei
.entry_point
< highpc
)
1499 objfile
->ei
.entry_file_lowpc
= lowpc
;
1500 objfile
->ei
.entry_file_highpc
= highpc
;
1503 attr
= dwarf_attr (die
, DW_AT_language
);
1506 set_cu_language (DW_UNSND (attr
));
1509 /* We assume that we're processing GCC output. */
1510 processing_gcc_compilation
= 2;
1512 /* FIXME:Do something here. */
1513 if (dip
->at_producer
!= NULL
)
1515 handle_producer (dip
->at_producer
);
1519 /* The compilation unit may be in a different language or objfile,
1520 zero out all remembered fundamental types. */
1521 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1523 start_symtab (name
, comp_dir
, lowpc
);
1524 record_debugformat ("DWARF 2");
1526 /* Decode line number information if present. */
1527 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1530 line_offset
= DW_UNSND (attr
);
1531 dwarf_decode_lines (line_offset
, comp_dir
, abfd
);
1534 /* Process all dies in compilation unit. */
1535 if (die
->has_children
)
1537 child_die
= die
->next
;
1538 while (child_die
&& child_die
->tag
)
1540 process_die (child_die
, objfile
);
1541 child_die
= sibling_die (child_die
);
1547 read_func_scope (die
, objfile
)
1548 struct die_info
*die
;
1549 struct objfile
*objfile
;
1551 register struct context_stack
*new;
1554 struct die_info
*child_die
;
1555 struct attribute
*attr
;
1558 name
= dwarf2_linkage_name (die
);
1560 /* Ignore functions with missing or empty names and functions with
1561 missing or invalid low and high pc attributes. */
1562 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1568 if (objfile
->ei
.entry_point
>= lowpc
&&
1569 objfile
->ei
.entry_point
< highpc
)
1571 objfile
->ei
.entry_func_lowpc
= lowpc
;
1572 objfile
->ei
.entry_func_highpc
= highpc
;
1575 /* Decode DW_AT_frame_base location descriptor if present, keep result
1576 for DW_OP_fbreg operands in decode_locdesc. */
1577 frame_base_reg
= -1;
1578 frame_base_offset
= 0;
1579 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1582 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
);
1584 complain (&dwarf2_unsupported_at_frame_base
, name
);
1586 frame_base_reg
= addr
;
1589 frame_base_reg
= basereg
;
1590 frame_base_offset
= addr
;
1593 complain (&dwarf2_unsupported_at_frame_base
, name
);
1596 new = push_context (0, lowpc
);
1597 new->name
= new_symbol (die
, die
->type
, objfile
);
1598 list_in_scope
= &local_symbols
;
1600 if (die
->has_children
)
1602 child_die
= die
->next
;
1603 while (child_die
&& child_die
->tag
)
1605 process_die (child_die
, objfile
);
1606 child_die
= sibling_die (child_die
);
1610 new = pop_context ();
1611 /* Make a block for the local symbols within. */
1612 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1613 lowpc
, highpc
, objfile
);
1614 list_in_scope
= &file_symbols
;
1617 /* Process all the DIES contained within a lexical block scope. Start
1618 a new scope, process the dies, and then close the scope. */
1621 read_lexical_block_scope (die
, objfile
)
1622 struct die_info
*die
;
1623 struct objfile
*objfile
;
1625 register struct context_stack
*new;
1626 CORE_ADDR lowpc
, highpc
;
1627 struct die_info
*child_die
;
1629 /* Ignore blocks with missing or invalid low and high pc attributes. */
1630 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1635 push_context (0, lowpc
);
1636 if (die
->has_children
)
1638 child_die
= die
->next
;
1639 while (child_die
&& child_die
->tag
)
1641 process_die (child_die
, objfile
);
1642 child_die
= sibling_die (child_die
);
1645 new = pop_context ();
1647 if (local_symbols
!= NULL
)
1649 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1652 local_symbols
= new->locals
;
1655 /* Get low and high pc attributes from a die.
1656 Return 1 if the attributes are present and valid, otherwise, return 0. */
1659 dwarf2_get_pc_bounds (die
, lowpc
, highpc
, objfile
)
1660 struct die_info
*die
;
1663 struct objfile
*objfile
;
1665 struct attribute
*attr
;
1669 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1671 low
= DW_ADDR (attr
);
1674 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1676 high
= DW_ADDR (attr
);
1683 /* When using the GNU linker, .gnu.linkonce. sections are used to
1684 eliminate duplicate copies of functions and vtables and such.
1685 The linker will arbitrarily choose one and discard the others.
1686 The AT_*_pc values for such functions refer to local labels in
1687 these sections. If the section from that file was discarded, the
1688 labels are not in the output, so the relocs get a value of 0.
1689 If this is a discarded function, mark the pc bounds as invalid,
1690 so that GDB will ignore it. */
1691 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1699 /* Add an aggregate field to the field list. */
1702 dwarf2_add_field (fip
, die
, objfile
)
1703 struct field_info
*fip
;
1704 struct die_info
*die
;
1705 struct objfile
*objfile
;
1707 struct nextfield
*new_field
;
1708 struct attribute
*attr
;
1710 char *fieldname
= "";
1712 /* Allocate a new field list entry and link it in. */
1713 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1714 make_cleanup (free
, new_field
);
1715 memset (new_field
, 0, sizeof (struct nextfield
));
1716 new_field
->next
= fip
->fields
;
1717 fip
->fields
= new_field
;
1720 /* Handle accessibility and virtuality of field.
1721 The default accessibility for members is public, the default
1722 accessibility for inheritance is private. */
1723 if (die
->tag
!= DW_TAG_inheritance
)
1724 new_field
->accessibility
= DW_ACCESS_public
;
1726 new_field
->accessibility
= DW_ACCESS_private
;
1727 new_field
->virtuality
= DW_VIRTUALITY_none
;
1729 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1731 new_field
->accessibility
= DW_UNSND (attr
);
1732 if (new_field
->accessibility
!= DW_ACCESS_public
)
1733 fip
->non_public_fields
= 1;
1734 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1736 new_field
->virtuality
= DW_UNSND (attr
);
1738 fp
= &new_field
->field
;
1739 if (die
->tag
== DW_TAG_member
)
1741 /* Get type of field. */
1742 fp
->type
= die_type (die
, objfile
);
1744 /* Get bit size of field (zero if none). */
1745 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1748 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1752 FIELD_BITSIZE (*fp
) = 0;
1755 /* Get bit offset of field. */
1756 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1759 FIELD_BITPOS (*fp
) =
1760 decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1763 FIELD_BITPOS (*fp
) = 0;
1764 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1767 if (BITS_BIG_ENDIAN
)
1769 /* For big endian bits, the DW_AT_bit_offset gives the
1770 additional bit offset from the MSB of the containing
1771 anonymous object to the MSB of the field. We don't
1772 have to do anything special since we don't need to
1773 know the size of the anonymous object. */
1774 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1778 /* For little endian bits, compute the bit offset to the
1779 MSB of the anonymous object, subtract off the number of
1780 bits from the MSB of the field to the MSB of the
1781 object, and then subtract off the number of bits of
1782 the field itself. The result is the bit offset of
1783 the LSB of the field. */
1785 int bit_offset
= DW_UNSND (attr
);
1787 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1790 /* The size of the anonymous object containing
1791 the bit field is explicit, so use the
1792 indicated size (in bytes). */
1793 anonymous_size
= DW_UNSND (attr
);
1797 /* The size of the anonymous object containing
1798 the bit field must be inferred from the type
1799 attribute of the data member containing the
1801 anonymous_size
= TYPE_LENGTH (fp
->type
);
1803 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1804 - bit_offset
- FIELD_BITSIZE (*fp
);
1808 /* Get name of field. */
1809 attr
= dwarf_attr (die
, DW_AT_name
);
1810 if (attr
&& DW_STRING (attr
))
1811 fieldname
= DW_STRING (attr
);
1812 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1813 &objfile
->type_obstack
);
1815 /* Change accessibility for artificial fields (e.g. virtual table
1816 pointer or virtual base class pointer) to private. */
1817 if (dwarf_attr (die
, DW_AT_artificial
))
1819 new_field
->accessibility
= DW_ACCESS_private
;
1820 fip
->non_public_fields
= 1;
1823 else if (die
->tag
== DW_TAG_variable
)
1827 /* C++ static member.
1828 Get name of field. */
1829 attr
= dwarf_attr (die
, DW_AT_name
);
1830 if (attr
&& DW_STRING (attr
))
1831 fieldname
= DW_STRING (attr
);
1835 /* Get physical name. */
1836 physname
= dwarf2_linkage_name (die
);
1838 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1839 &objfile
->type_obstack
));
1840 FIELD_TYPE (*fp
) = die_type (die
, objfile
);
1841 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1842 &objfile
->type_obstack
);
1844 else if (die
->tag
== DW_TAG_inheritance
)
1846 /* C++ base class field. */
1847 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1849 FIELD_BITPOS (*fp
) = decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1850 FIELD_BITSIZE (*fp
) = 0;
1851 FIELD_TYPE (*fp
) = die_type (die
, objfile
);
1852 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1853 fip
->nbaseclasses
++;
1857 /* Create the vector of fields, and attach it to the type. */
1860 dwarf2_attach_fields_to_type (fip
, type
, objfile
)
1861 struct field_info
*fip
;
1863 struct objfile
*objfile
;
1865 int nfields
= fip
->nfields
;
1867 /* Record the field count, allocate space for the array of fields,
1868 and create blank accessibility bitfields if necessary. */
1869 TYPE_NFIELDS (type
) = nfields
;
1870 TYPE_FIELDS (type
) = (struct field
*)
1871 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1872 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1874 if (fip
->non_public_fields
)
1876 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1878 TYPE_FIELD_PRIVATE_BITS (type
) =
1879 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1880 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1882 TYPE_FIELD_PROTECTED_BITS (type
) =
1883 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1884 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1886 TYPE_FIELD_IGNORE_BITS (type
) =
1887 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1888 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1891 /* If the type has baseclasses, allocate and clear a bit vector for
1892 TYPE_FIELD_VIRTUAL_BITS. */
1893 if (fip
->nbaseclasses
)
1895 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
1898 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1899 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1900 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1901 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
1902 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
1905 /* Copy the saved-up fields into the field vector. Start from the head
1906 of the list, adding to the tail of the field array, so that they end
1907 up in the same order in the array in which they were added to the list. */
1908 while (nfields
-- > 0)
1910 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
1911 switch (fip
->fields
->accessibility
)
1913 case DW_ACCESS_private
:
1914 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
1917 case DW_ACCESS_protected
:
1918 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
1921 case DW_ACCESS_public
:
1925 /* Unknown accessibility. Complain and treat it as public. */
1927 complain (&dwarf2_unsupported_accessibility
,
1928 fip
->fields
->accessibility
);
1932 if (nfields
< fip
->nbaseclasses
)
1934 switch (fip
->fields
->virtuality
)
1936 case DW_VIRTUALITY_virtual
:
1937 case DW_VIRTUALITY_pure_virtual
:
1938 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
1942 fip
->fields
= fip
->fields
->next
;
1946 /* Add a member function to the proper fieldlist. */
1949 dwarf2_add_member_fn (fip
, die
, type
, objfile
)
1950 struct field_info
*fip
;
1951 struct die_info
*die
;
1953 struct objfile
*objfile
;
1955 struct attribute
*attr
;
1956 struct fnfieldlist
*flp
;
1958 struct fn_field
*fnp
;
1961 struct nextfnfield
*new_fnfield
;
1963 /* Get name of member function. */
1964 attr
= dwarf_attr (die
, DW_AT_name
);
1965 if (attr
&& DW_STRING (attr
))
1966 fieldname
= DW_STRING (attr
);
1970 /* Get the mangled name. */
1971 physname
= dwarf2_linkage_name (die
);
1973 /* Look up member function name in fieldlist. */
1974 for (i
= 0; i
< fip
->nfnfields
; i
++)
1976 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
1980 /* Create new list element if necessary. */
1981 if (i
< fip
->nfnfields
)
1982 flp
= &fip
->fnfieldlists
[i
];
1985 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
1987 fip
->fnfieldlists
= (struct fnfieldlist
*)
1988 xrealloc (fip
->fnfieldlists
,
1989 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
1990 * sizeof (struct fnfieldlist
));
1991 if (fip
->nfnfields
== 0)
1992 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
1994 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
1995 flp
->name
= fieldname
;
2001 /* Create a new member function field and chain it to the field list
2003 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2004 make_cleanup (free
, new_fnfield
);
2005 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2006 new_fnfield
->next
= flp
->head
;
2007 flp
->head
= new_fnfield
;
2010 /* Fill in the member function field info. */
2011 fnp
= &new_fnfield
->fnfield
;
2012 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2013 &objfile
->type_obstack
);
2014 fnp
->type
= alloc_type (objfile
);
2015 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2017 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2018 struct type
**arg_types
;
2019 int nparams
= TYPE_NFIELDS (die
->type
);
2022 /* Copy argument types from the subroutine type. */
2023 arg_types
= (struct type
**)
2024 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2025 for (iparams
= 0; iparams
< nparams
; iparams
++)
2026 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2028 /* Set last entry in argument type vector. */
2029 if (TYPE_FLAGS (die
->type
) & TYPE_FLAG_VARARGS
)
2030 arg_types
[nparams
] = NULL
;
2032 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2034 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2036 /* Handle static member functions.
2037 Dwarf2 has no clean way to discern C++ static and non-static
2038 member functions. G++ helps GDB by marking the first
2039 parameter for non-static member functions (which is the
2040 this pointer) as artificial. We obtain this information
2041 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2042 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2043 fnp
->voffset
= VOFFSET_STATIC
;
2046 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2048 /* Get fcontext from DW_AT_containing_type if present. */
2049 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2050 fnp
->fcontext
= die_containing_type (die
, objfile
);
2052 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2053 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2055 /* Get accessibility. */
2056 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2059 switch (DW_UNSND (attr
))
2061 case DW_ACCESS_private
:
2062 fnp
->is_private
= 1;
2064 case DW_ACCESS_protected
:
2065 fnp
->is_protected
= 1;
2070 /* Get index in virtual function table if it is a virtual member function. */
2071 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2073 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
) + 2;
2076 /* Create the vector of member function fields, and attach it to the type. */
2079 dwarf2_attach_fn_fields_to_type (fip
, type
, objfile
)
2080 struct field_info
*fip
;
2082 struct objfile
*objfile
;
2084 struct fnfieldlist
*flp
;
2085 int total_length
= 0;
2088 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2089 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2090 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2092 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2094 struct nextfnfield
*nfp
= flp
->head
;
2095 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2098 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2099 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2100 fn_flp
->fn_fields
= (struct fn_field
*)
2101 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2102 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2103 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2105 total_length
+= flp
->length
;
2108 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2109 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2112 /* Called when we find the DIE that starts a structure or union scope
2113 (definition) to process all dies that define the members of the
2116 NOTE: we need to call struct_type regardless of whether or not the
2117 DIE has an at_name attribute, since it might be an anonymous
2118 structure or union. This gets the type entered into our set of
2121 However, if the structure is incomplete (an opaque struct/union)
2122 then suppress creating a symbol table entry for it since gdb only
2123 wants to find the one with the complete definition. Note that if
2124 it is complete, we just call new_symbol, which does it's own
2125 checking about whether the struct/union is anonymous or not (and
2126 suppresses creating a symbol table entry itself). */
2129 read_structure_scope (die
, objfile
)
2130 struct die_info
*die
;
2131 struct objfile
*objfile
;
2134 struct attribute
*attr
;
2136 type
= alloc_type (objfile
);
2138 INIT_CPLUS_SPECIFIC (type
);
2139 attr
= dwarf_attr (die
, DW_AT_name
);
2140 if (attr
&& DW_STRING (attr
))
2142 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2143 strlen (DW_STRING (attr
)),
2144 &objfile
->type_obstack
);
2147 if (die
->tag
== DW_TAG_structure_type
)
2149 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2151 else if (die
->tag
== DW_TAG_union_type
)
2153 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2157 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2159 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2162 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2165 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2169 TYPE_LENGTH (type
) = 0;
2172 /* We need to add the type field to the die immediately so we don't
2173 infinitely recurse when dealing with pointers to the structure
2174 type within the structure itself. */
2177 if (die
->has_children
&& ! die_is_declaration (die
))
2179 struct field_info fi
;
2180 struct die_info
*child_die
;
2181 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2183 memset (&fi
, 0, sizeof (struct field_info
));
2185 child_die
= die
->next
;
2187 while (child_die
&& child_die
->tag
)
2189 if (child_die
->tag
== DW_TAG_member
)
2191 dwarf2_add_field (&fi
, child_die
, objfile
);
2193 else if (child_die
->tag
== DW_TAG_variable
)
2195 /* C++ static member. */
2196 dwarf2_add_field (&fi
, child_die
, objfile
);
2198 else if (child_die
->tag
== DW_TAG_subprogram
)
2200 /* C++ member function. */
2201 process_die (child_die
, objfile
);
2202 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
);
2204 else if (child_die
->tag
== DW_TAG_inheritance
)
2206 /* C++ base class field. */
2207 dwarf2_add_field (&fi
, child_die
, objfile
);
2211 process_die (child_die
, objfile
);
2213 child_die
= sibling_die (child_die
);
2216 /* Attach fields and member functions to the type. */
2218 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2221 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2223 /* Get the type which refers to the base class (possibly this
2224 class itself) which contains the vtable pointer for the current
2225 class from the DW_AT_containing_type attribute. */
2227 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2229 struct type
*t
= die_containing_type (die
, objfile
);
2231 TYPE_VPTR_BASETYPE (type
) = t
;
2234 static const char vptr_name
[] =
2235 {'_', 'v', 'p', 't', 'r', '\0'};
2238 /* Our own class provides vtbl ptr. */
2239 for (i
= TYPE_NFIELDS (t
) - 1;
2240 i
>= TYPE_N_BASECLASSES (t
);
2243 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2245 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2246 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2248 TYPE_VPTR_FIELDNO (type
) = i
;
2253 /* Complain if virtual function table field not found. */
2254 if (i
< TYPE_N_BASECLASSES (t
))
2255 complain (&dwarf2_vtbl_not_found_complaint
,
2256 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2260 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2265 new_symbol (die
, type
, objfile
);
2267 do_cleanups (back_to
);
2271 /* No children, must be stub. */
2272 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2278 /* Given a pointer to a die which begins an enumeration, process all
2279 the dies that define the members of the enumeration.
2281 This will be much nicer in draft 6 of the DWARF spec when our
2282 members will be dies instead squished into the DW_AT_element_list
2285 NOTE: We reverse the order of the element list. */
2288 read_enumeration (die
, objfile
)
2289 struct die_info
*die
;
2290 struct objfile
*objfile
;
2292 struct die_info
*child_die
;
2294 struct field
*fields
;
2295 struct attribute
*attr
;
2298 int unsigned_enum
= 1;
2300 type
= alloc_type (objfile
);
2302 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2303 attr
= dwarf_attr (die
, DW_AT_name
);
2304 if (attr
&& DW_STRING (attr
))
2306 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2307 strlen (DW_STRING (attr
)),
2308 &objfile
->type_obstack
);
2311 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2314 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2318 TYPE_LENGTH (type
) = 0;
2323 if (die
->has_children
)
2325 child_die
= die
->next
;
2326 while (child_die
&& child_die
->tag
)
2328 if (child_die
->tag
!= DW_TAG_enumerator
)
2330 process_die (child_die
, objfile
);
2334 attr
= dwarf_attr (child_die
, DW_AT_name
);
2337 sym
= new_symbol (child_die
, type
, objfile
);
2338 if (SYMBOL_VALUE (sym
) < 0)
2341 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2343 fields
= (struct field
*)
2345 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2346 * sizeof (struct field
));
2349 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2350 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2351 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2352 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2358 child_die
= sibling_die (child_die
);
2363 TYPE_NFIELDS (type
) = num_fields
;
2364 TYPE_FIELDS (type
) = (struct field
*)
2365 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2366 memcpy (TYPE_FIELDS (type
), fields
,
2367 sizeof (struct field
) * num_fields
);
2371 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2374 new_symbol (die
, type
, objfile
);
2377 /* Extract all information from a DW_TAG_array_type DIE and put it in
2378 the DIE's type field. For now, this only handles one dimensional
2382 read_array_type (die
, objfile
)
2383 struct die_info
*die
;
2384 struct objfile
*objfile
;
2386 struct die_info
*child_die
;
2387 struct type
*type
= NULL
;
2388 struct type
*element_type
, *range_type
, *index_type
;
2389 struct type
**range_types
= NULL
;
2390 struct attribute
*attr
;
2392 struct cleanup
*back_to
;
2394 /* Return if we've already decoded this type. */
2400 element_type
= die_type (die
, objfile
);
2402 /* Irix 6.2 native cc creates array types without children for
2403 arrays with unspecified length. */
2404 if (die
->has_children
== 0)
2406 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2407 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2408 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2412 back_to
= make_cleanup (null_cleanup
, NULL
);
2413 child_die
= die
->next
;
2414 while (child_die
&& child_die
->tag
)
2416 if (child_die
->tag
== DW_TAG_subrange_type
)
2418 unsigned int low
, high
;
2420 /* Default bounds to an array with unspecified length. */
2423 if (cu_language
== language_fortran
)
2425 /* FORTRAN implies a lower bound of 1, if not given. */
2429 index_type
= die_type (child_die
, objfile
);
2430 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2433 if (attr
->form
== DW_FORM_sdata
)
2435 low
= DW_SND (attr
);
2437 else if (attr
->form
== DW_FORM_udata
2438 || attr
->form
== DW_FORM_data1
2439 || attr
->form
== DW_FORM_data2
2440 || attr
->form
== DW_FORM_data4
)
2442 low
= DW_UNSND (attr
);
2446 complain (&dwarf2_non_const_array_bound_ignored
,
2447 dwarf_form_name (attr
->form
));
2449 die
->type
= lookup_pointer_type (element_type
);
2456 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2459 if (attr
->form
== DW_FORM_sdata
)
2461 high
= DW_SND (attr
);
2463 else if (attr
->form
== DW_FORM_udata
2464 || attr
->form
== DW_FORM_data1
2465 || attr
->form
== DW_FORM_data2
2466 || attr
->form
== DW_FORM_data4
)
2468 high
= DW_UNSND (attr
);
2470 else if (attr
->form
== DW_FORM_block1
)
2472 /* GCC encodes arrays with unspecified or dynamic length
2473 with a DW_FORM_block1 attribute.
2474 FIXME: GDB does not yet know how to handle dynamic
2475 arrays properly, treat them as arrays with unspecified
2481 complain (&dwarf2_non_const_array_bound_ignored
,
2482 dwarf_form_name (attr
->form
));
2484 die
->type
= lookup_pointer_type (element_type
);
2492 /* Create a range type and save it for array type creation. */
2493 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2495 range_types
= (struct type
**)
2496 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2497 * sizeof (struct type
*));
2499 make_cleanup (free_current_contents
, &range_types
);
2501 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2503 child_die
= sibling_die (child_die
);
2506 /* Dwarf2 dimensions are output from left to right, create the
2507 necessary array types in backwards order. */
2508 type
= element_type
;
2510 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2512 do_cleanups (back_to
);
2514 /* Install the type in the die. */
2518 /* First cut: install each common block member as a global variable. */
2521 read_common_block (die
, objfile
)
2522 struct die_info
*die
;
2523 struct objfile
*objfile
;
2525 struct die_info
*child_die
;
2526 struct attribute
*attr
;
2528 CORE_ADDR base
= (CORE_ADDR
) 0;
2530 attr
= dwarf_attr (die
, DW_AT_location
);
2533 base
= decode_locdesc (DW_BLOCK (attr
), objfile
);
2535 if (die
->has_children
)
2537 child_die
= die
->next
;
2538 while (child_die
&& child_die
->tag
)
2540 sym
= new_symbol (child_die
, NULL
, objfile
);
2541 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2544 SYMBOL_VALUE_ADDRESS (sym
) =
2545 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
);
2546 add_symbol_to_list (sym
, &global_symbols
);
2548 child_die
= sibling_die (child_die
);
2553 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2554 the user defined type vector. */
2557 read_tag_pointer_type (die
, objfile
)
2558 struct die_info
*die
;
2559 struct objfile
*objfile
;
2562 struct attribute
*attr
;
2569 type
= lookup_pointer_type (die_type (die
, objfile
));
2570 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2573 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2577 TYPE_LENGTH (type
) = address_size
;
2582 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2583 the user defined type vector. */
2586 read_tag_ptr_to_member_type (die
, objfile
)
2587 struct die_info
*die
;
2588 struct objfile
*objfile
;
2591 struct type
*to_type
;
2592 struct type
*domain
;
2599 type
= alloc_type (objfile
);
2600 to_type
= die_type (die
, objfile
);
2601 domain
= die_containing_type (die
, objfile
);
2602 smash_to_member_type (type
, domain
, to_type
);
2607 /* Extract all information from a DW_TAG_reference_type DIE and add to
2608 the user defined type vector. */
2611 read_tag_reference_type (die
, objfile
)
2612 struct die_info
*die
;
2613 struct objfile
*objfile
;
2616 struct attribute
*attr
;
2623 type
= lookup_reference_type (die_type (die
, objfile
));
2624 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2627 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2631 TYPE_LENGTH (type
) = address_size
;
2637 read_tag_const_type (die
, objfile
)
2638 struct die_info
*die
;
2639 struct objfile
*objfile
;
2646 complain (&dwarf2_const_ignored
);
2647 die
->type
= die_type (die
, objfile
);
2651 read_tag_volatile_type (die
, objfile
)
2652 struct die_info
*die
;
2653 struct objfile
*objfile
;
2660 complain (&dwarf2_volatile_ignored
);
2661 die
->type
= die_type (die
, objfile
);
2664 /* Extract all information from a DW_TAG_string_type DIE and add to
2665 the user defined type vector. It isn't really a user defined type,
2666 but it behaves like one, with other DIE's using an AT_user_def_type
2667 attribute to reference it. */
2670 read_tag_string_type (die
, objfile
)
2671 struct die_info
*die
;
2672 struct objfile
*objfile
;
2674 struct type
*type
, *range_type
, *index_type
, *char_type
;
2675 struct attribute
*attr
;
2676 unsigned int length
;
2683 attr
= dwarf_attr (die
, DW_AT_string_length
);
2686 length
= DW_UNSND (attr
);
2692 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2693 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2694 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2695 type
= create_string_type (char_type
, range_type
);
2699 /* Handle DIES due to C code like:
2703 int (*funcp)(int a, long l);
2707 ('funcp' generates a DW_TAG_subroutine_type DIE)
2711 read_subroutine_type (die
, objfile
)
2712 struct die_info
*die
;
2713 struct objfile
*objfile
;
2715 struct type
*type
; /* Type that this function returns */
2716 struct type
*ftype
; /* Function that returns above type */
2717 struct attribute
*attr
;
2719 /* Decode the type that this subroutine returns */
2724 type
= die_type (die
, objfile
);
2725 ftype
= lookup_function_type (type
);
2727 /* All functions in C++ have prototypes. */
2728 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2729 if ((attr
&& (DW_UNSND (attr
) != 0))
2730 || cu_language
== language_cplus
)
2731 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2733 if (die
->has_children
)
2735 struct die_info
*child_die
;
2739 /* Count the number of parameters.
2740 FIXME: GDB currently ignores vararg functions, but knows about
2741 vararg member functions. */
2742 child_die
= die
->next
;
2743 while (child_die
&& child_die
->tag
)
2745 if (child_die
->tag
== DW_TAG_formal_parameter
)
2747 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2748 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2749 child_die
= sibling_die (child_die
);
2752 /* Allocate storage for parameters and fill them in. */
2753 TYPE_NFIELDS (ftype
) = nparams
;
2754 TYPE_FIELDS (ftype
) = (struct field
*)
2755 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2757 child_die
= die
->next
;
2758 while (child_die
&& child_die
->tag
)
2760 if (child_die
->tag
== DW_TAG_formal_parameter
)
2762 /* Dwarf2 has no clean way to discern C++ static and non-static
2763 member functions. G++ helps GDB by marking the first
2764 parameter for non-static member functions (which is the
2765 this pointer) as artificial. We pass this information
2766 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2767 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2769 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2771 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2772 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
);
2775 child_die
= sibling_die (child_die
);
2783 read_typedef (die
, objfile
)
2784 struct die_info
*die
;
2785 struct objfile
*objfile
;
2791 struct attribute
*attr
;
2794 xtype
= die_type (die
, objfile
);
2796 type
= alloc_type (objfile
);
2797 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2798 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2799 TYPE_TARGET_TYPE (type
) = xtype
;
2800 attr
= dwarf_attr (die
, DW_AT_name
);
2801 if (attr
&& DW_STRING (attr
))
2802 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2803 strlen (DW_STRING (attr
)),
2804 &objfile
->type_obstack
);
2810 /* Find a representation of a given base type and install
2811 it in the TYPE field of the die. */
2814 read_base_type (die
, objfile
)
2815 struct die_info
*die
;
2816 struct objfile
*objfile
;
2819 struct attribute
*attr
;
2820 int encoding
= 0, size
= 0;
2822 /* If we've already decoded this die, this is a no-op. */
2828 attr
= dwarf_attr (die
, DW_AT_encoding
);
2831 encoding
= DW_UNSND (attr
);
2833 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2836 size
= DW_UNSND (attr
);
2838 attr
= dwarf_attr (die
, DW_AT_name
);
2839 if (attr
&& DW_STRING (attr
))
2841 enum type_code code
= TYPE_CODE_INT
;
2842 int is_unsigned
= 0;
2846 case DW_ATE_address
:
2847 /* Turn DW_ATE_address into a void * pointer. */
2848 code
= TYPE_CODE_PTR
;
2851 case DW_ATE_boolean
:
2852 code
= TYPE_CODE_BOOL
;
2855 case DW_ATE_complex_float
:
2856 code
= TYPE_CODE_COMPLEX
;
2859 code
= TYPE_CODE_FLT
;
2862 case DW_ATE_signed_char
:
2864 case DW_ATE_unsigned
:
2865 case DW_ATE_unsigned_char
:
2869 complain (&dwarf2_unsupported_at_encoding
,
2870 dwarf_type_encoding_name (encoding
));
2873 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2874 if (encoding
== DW_ATE_address
)
2875 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2879 type
= dwarf_base_type (encoding
, size
, objfile
);
2884 /* Read a whole compilation unit into a linked list of dies. */
2887 read_comp_unit (info_ptr
, abfd
)
2891 struct die_info
*first_die
, *last_die
, *die
;
2895 /* Reset die reference table and cached types table; we are
2896 building new ones now. */
2897 dwarf2_empty_hash_tables ();
2901 first_die
= last_die
= NULL
;
2904 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
);
2905 if (die
->has_children
)
2916 /* Enter die in reference hash table */
2917 store_in_ref_table (die
->offset
, die
);
2921 first_die
= last_die
= die
;
2925 last_die
->next
= die
;
2929 while (nesting_level
> 0);
2933 /* Free a linked list of dies. */
2936 free_die_list (dies
)
2937 struct die_info
*dies
;
2939 struct die_info
*die
, *next
;
2952 do_free_die_list_cleanup (void *dies
)
2954 free_die_list (dies
);
2957 static struct cleanup
*
2958 make_cleanup_free_die_list (struct die_info
*dies
)
2960 return make_cleanup (do_free_die_list_cleanup
, dies
);
2964 /* Read the contents of the section at OFFSET and of size SIZE from the
2965 object file specified by OBJFILE into the psymbol_obstack and return it. */
2968 dwarf2_read_section (objfile
, offset
, size
)
2969 struct objfile
*objfile
;
2973 bfd
*abfd
= objfile
->obfd
;
2979 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
2980 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
2981 (bfd_read (buf
, size
, 1, abfd
) != size
))
2984 error ("Dwarf Error: Can't read DWARF data from '%s'",
2985 bfd_get_filename (abfd
));
2990 /* In DWARF version 2, the description of the debugging information is
2991 stored in a separate .debug_abbrev section. Before we read any
2992 dies from a section we read in all abbreviations and install them
2996 dwarf2_read_abbrevs (abfd
, offset
)
2998 unsigned int offset
;
3001 struct abbrev_info
*cur_abbrev
;
3002 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3003 unsigned int abbrev_form
, hash_number
;
3005 /* empty the table */
3006 dwarf2_empty_abbrev_table (NULL
);
3008 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3009 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3010 abbrev_ptr
+= bytes_read
;
3012 /* loop until we reach an abbrev number of 0 */
3013 while (abbrev_number
)
3015 cur_abbrev
= dwarf_alloc_abbrev ();
3017 /* read in abbrev header */
3018 cur_abbrev
->number
= abbrev_number
;
3019 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3020 abbrev_ptr
+= bytes_read
;
3021 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3024 /* now read in declarations */
3025 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3026 abbrev_ptr
+= bytes_read
;
3027 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3028 abbrev_ptr
+= bytes_read
;
3031 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3033 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3034 xrealloc (cur_abbrev
->attrs
,
3035 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3036 * sizeof (struct attr_abbrev
));
3038 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3039 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3040 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3041 abbrev_ptr
+= bytes_read
;
3042 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3043 abbrev_ptr
+= bytes_read
;
3046 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3047 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3048 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3050 /* Get next abbreviation.
3051 Under Irix6 the abbreviations for a compilation unit are not
3052 always properly terminated with an abbrev number of 0.
3053 Exit loop if we encounter an abbreviation which we have
3054 already read (which means we are about to read the abbreviations
3055 for the next compile unit) or if the end of the abbreviation
3056 table is reached. */
3057 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3058 >= dwarf_abbrev_size
)
3060 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3061 abbrev_ptr
+= bytes_read
;
3062 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3067 /* Empty the abbrev table for a new compilation unit. */
3071 dwarf2_empty_abbrev_table (ignore
)
3075 struct abbrev_info
*abbrev
, *next
;
3077 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3080 abbrev
= dwarf2_abbrevs
[i
];
3083 next
= abbrev
->next
;
3084 free (abbrev
->attrs
);
3088 dwarf2_abbrevs
[i
] = NULL
;
3092 /* Lookup an abbrev_info structure in the abbrev hash table. */
3094 static struct abbrev_info
*
3095 dwarf2_lookup_abbrev (number
)
3096 unsigned int number
;
3098 unsigned int hash_number
;
3099 struct abbrev_info
*abbrev
;
3101 hash_number
= number
% ABBREV_HASH_SIZE
;
3102 abbrev
= dwarf2_abbrevs
[hash_number
];
3106 if (abbrev
->number
== number
)
3109 abbrev
= abbrev
->next
;
3114 /* Read a minimal amount of information into the minimal die structure. */
3117 read_partial_die (part_die
, abfd
, info_ptr
, has_pc_info
)
3118 struct partial_die_info
*part_die
;
3123 unsigned int abbrev_number
, bytes_read
, i
;
3124 struct abbrev_info
*abbrev
;
3125 struct attribute attr
;
3126 struct attribute spec_attr
;
3127 int found_spec_attr
= 0;
3128 int has_low_pc_attr
= 0;
3129 int has_high_pc_attr
= 0;
3131 *part_die
= zeroed_partial_die
;
3133 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3134 info_ptr
+= bytes_read
;
3138 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3141 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3143 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3144 part_die
->tag
= abbrev
->tag
;
3145 part_die
->has_children
= abbrev
->has_children
;
3146 part_die
->abbrev
= abbrev_number
;
3148 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3150 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
);
3152 /* Store the data if it is of an attribute we want to keep in a
3153 partial symbol table. */
3158 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3159 if (part_die
->name
== NULL
)
3160 part_die
->name
= DW_STRING (&attr
);
3162 case DW_AT_MIPS_linkage_name
:
3163 part_die
->name
= DW_STRING (&attr
);
3166 has_low_pc_attr
= 1;
3167 part_die
->lowpc
= DW_ADDR (&attr
);
3170 has_high_pc_attr
= 1;
3171 part_die
->highpc
= DW_ADDR (&attr
);
3173 case DW_AT_location
:
3174 part_die
->locdesc
= DW_BLOCK (&attr
);
3176 case DW_AT_language
:
3177 part_die
->language
= DW_UNSND (&attr
);
3179 case DW_AT_external
:
3180 part_die
->is_external
= DW_UNSND (&attr
);
3182 case DW_AT_declaration
:
3183 part_die
->is_declaration
= DW_UNSND (&attr
);
3186 part_die
->has_type
= 1;
3188 case DW_AT_abstract_origin
:
3189 case DW_AT_specification
:
3190 found_spec_attr
= 1;
3194 /* Ignore absolute siblings, they might point outside of
3195 the current compile unit. */
3196 if (attr
.form
== DW_FORM_ref_addr
)
3197 complain (&dwarf2_absolute_sibling_complaint
);
3200 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3207 /* If we found a reference attribute and the die has no name, try
3208 to find a name in the referred to die. */
3210 if (found_spec_attr
&& part_die
->name
== NULL
)
3212 struct partial_die_info spec_die
;
3216 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3217 read_partial_die (&spec_die
, abfd
, spec_ptr
, &dummy
);
3220 part_die
->name
= spec_die
.name
;
3222 /* Copy DW_AT_external attribute if it is set. */
3223 if (spec_die
.is_external
)
3224 part_die
->is_external
= spec_die
.is_external
;
3228 /* When using the GNU linker, .gnu.linkonce. sections are used to
3229 eliminate duplicate copies of functions and vtables and such.
3230 The linker will arbitrarily choose one and discard the others.
3231 The AT_*_pc values for such functions refer to local labels in
3232 these sections. If the section from that file was discarded, the
3233 labels are not in the output, so the relocs get a value of 0.
3234 If this is a discarded function, mark the pc bounds as invalid,
3235 so that GDB will ignore it. */
3236 if (has_low_pc_attr
&& has_high_pc_attr
3237 && part_die
->lowpc
< part_die
->highpc
3238 && (part_die
->lowpc
!= 0
3239 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3244 /* Read the die from the .debug_info section buffer. And set diep to
3245 point to a newly allocated die with its information. */
3248 read_full_die (diep
, abfd
, info_ptr
)
3249 struct die_info
**diep
;
3253 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3254 struct abbrev_info
*abbrev
;
3255 struct die_info
*die
;
3257 offset
= info_ptr
- dwarf_info_buffer
;
3258 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3259 info_ptr
+= bytes_read
;
3262 die
= dwarf_alloc_die ();
3264 die
->abbrev
= abbrev_number
;
3270 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3273 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3275 die
= dwarf_alloc_die ();
3276 die
->offset
= offset
;
3277 die
->tag
= abbrev
->tag
;
3278 die
->has_children
= abbrev
->has_children
;
3279 die
->abbrev
= abbrev_number
;
3282 die
->num_attrs
= abbrev
->num_attrs
;
3283 die
->attrs
= (struct attribute
*)
3284 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3286 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3288 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3296 /* Read an attribute described by an abbreviated attribute. */
3299 read_attribute (attr
, abbrev
, abfd
, info_ptr
)
3300 struct attribute
*attr
;
3301 struct attr_abbrev
*abbrev
;
3305 unsigned int bytes_read
;
3306 struct dwarf_block
*blk
;
3308 attr
->name
= abbrev
->name
;
3309 attr
->form
= abbrev
->form
;
3310 switch (abbrev
->form
)
3313 case DW_FORM_ref_addr
:
3314 DW_ADDR (attr
) = read_address (abfd
, info_ptr
);
3315 info_ptr
+= address_size
;
3317 case DW_FORM_block2
:
3318 blk
= dwarf_alloc_block ();
3319 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3321 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3322 info_ptr
+= blk
->size
;
3323 DW_BLOCK (attr
) = blk
;
3325 case DW_FORM_block4
:
3326 blk
= dwarf_alloc_block ();
3327 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3329 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3330 info_ptr
+= blk
->size
;
3331 DW_BLOCK (attr
) = blk
;
3334 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3338 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3342 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3345 case DW_FORM_string
:
3346 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3347 info_ptr
+= bytes_read
;
3350 blk
= dwarf_alloc_block ();
3351 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3352 info_ptr
+= bytes_read
;
3353 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3354 info_ptr
+= blk
->size
;
3355 DW_BLOCK (attr
) = blk
;
3357 case DW_FORM_block1
:
3358 blk
= dwarf_alloc_block ();
3359 blk
->size
= read_1_byte (abfd
, info_ptr
);
3361 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3362 info_ptr
+= blk
->size
;
3363 DW_BLOCK (attr
) = blk
;
3366 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3370 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3374 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3375 info_ptr
+= bytes_read
;
3378 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3379 info_ptr
+= bytes_read
;
3382 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3386 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3390 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3393 case DW_FORM_ref_udata
:
3394 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3395 info_ptr
+= bytes_read
;
3398 case DW_FORM_indirect
:
3400 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3401 dwarf_form_name (abbrev
->form
));
3406 /* read dwarf information from a buffer */
3409 read_1_byte (abfd
, buf
)
3413 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3417 read_1_signed_byte (abfd
, buf
)
3421 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3425 read_2_bytes (abfd
, buf
)
3429 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3433 read_2_signed_bytes (abfd
, buf
)
3437 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3441 read_4_bytes (abfd
, buf
)
3445 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3449 read_4_signed_bytes (abfd
, buf
)
3453 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3456 static unsigned long
3457 read_8_bytes (abfd
, buf
)
3461 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3465 read_address (abfd
, buf
)
3469 CORE_ADDR retval
= 0;
3471 switch (address_size
)
3474 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3477 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3480 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3483 /* *THE* alternative is 8, right? */
3491 read_n_bytes (abfd
, buf
, size
)
3496 /* If the size of a host char is 8 bits, we can return a pointer
3497 to the buffer, otherwise we have to copy the data to a buffer
3498 allocated on the temporary obstack. */
3499 #if HOST_CHAR_BIT == 8
3505 ret
= obstack_alloc (&dwarf2_tmp_obstack
, size
);
3506 for (i
= 0; i
< size
; ++i
)
3508 ret
[i
] = bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3516 read_string (abfd
, buf
, bytes_read_ptr
)
3519 unsigned int *bytes_read_ptr
;
3521 /* If the size of a host char is 8 bits, we can return a pointer
3522 to the string, otherwise we have to copy the string to a buffer
3523 allocated on the temporary obstack. */
3524 #if HOST_CHAR_BIT == 8
3527 *bytes_read_ptr
= 1;
3530 *bytes_read_ptr
= strlen (buf
) + 1;
3536 while ((byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
)) != 0)
3538 obstack_1grow (&dwarf2_tmp_obstack
, byte
);
3544 *bytes_read_ptr
= 1;
3547 obstack_1grow (&dwarf2_tmp_obstack
, '\0');
3548 *bytes_read_ptr
= i
+ 1;
3549 return obstack_finish (&dwarf2_tmp_obstack
);
3553 static unsigned long
3554 read_unsigned_leb128 (abfd
, buf
, bytes_read_ptr
)
3557 unsigned int *bytes_read_ptr
;
3559 unsigned long result
;
3560 unsigned int num_read
;
3570 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3573 result
|= ((unsigned long)(byte
& 127) << shift
);
3574 if ((byte
& 128) == 0)
3580 *bytes_read_ptr
= num_read
;
3585 read_signed_leb128 (abfd
, buf
, bytes_read_ptr
)
3588 unsigned int *bytes_read_ptr
;
3591 int i
, shift
, size
, num_read
;
3601 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3604 result
|= ((long)(byte
& 127) << shift
);
3606 if ((byte
& 128) == 0)
3611 if ((shift
< size
) && (byte
& 0x40))
3613 result
|= -(1 << shift
);
3615 *bytes_read_ptr
= num_read
;
3620 set_cu_language (lang
)
3627 cu_language
= language_c
;
3629 case DW_LANG_C_plus_plus
:
3630 cu_language
= language_cplus
;
3632 case DW_LANG_Fortran77
:
3633 case DW_LANG_Fortran90
:
3634 cu_language
= language_fortran
;
3636 case DW_LANG_Mips_Assembler
:
3637 cu_language
= language_asm
;
3640 case DW_LANG_Cobol74
:
3641 case DW_LANG_Cobol85
:
3642 case DW_LANG_Pascal83
:
3643 case DW_LANG_Modula2
:
3645 cu_language
= language_unknown
;
3648 cu_language_defn
= language_def (cu_language
);
3651 /* Return the named attribute or NULL if not there. */
3653 static struct attribute
*
3654 dwarf_attr (die
, name
)
3655 struct die_info
*die
;
3659 struct attribute
*spec
= NULL
;
3661 for (i
= 0; i
< die
->num_attrs
; ++i
)
3663 if (die
->attrs
[i
].name
== name
)
3665 return &die
->attrs
[i
];
3667 if (die
->attrs
[i
].name
== DW_AT_specification
3668 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3669 spec
= &die
->attrs
[i
];
3673 struct die_info
*ref_die
=
3674 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3677 return dwarf_attr (ref_die
, name
);
3684 die_is_declaration (struct die_info
*die
)
3686 return (dwarf_attr (die
, DW_AT_declaration
)
3687 && ! dwarf_attr (die
, DW_AT_specification
));
3690 /* Decode the line number information for the compilation unit whose
3691 line number info is at OFFSET in the .debug_line section.
3692 The compilation directory of the file is passed in COMP_DIR. */
3696 unsigned int num_files
;
3709 unsigned int num_dirs
;
3714 dwarf_decode_lines (offset
, comp_dir
, abfd
)
3715 unsigned int offset
;
3721 struct line_head lh
;
3722 struct cleanup
*back_to
;
3723 unsigned int i
, bytes_read
;
3724 char *cur_file
, *cur_dir
;
3725 unsigned char op_code
, extended_op
, adj_opcode
;
3727 #define FILE_ALLOC_CHUNK 5
3728 #define DIR_ALLOC_CHUNK 5
3730 struct filenames files
;
3731 struct directories dirs
;
3733 if (dwarf_line_buffer
== NULL
)
3735 complain (&dwarf2_missing_line_number_section
);
3739 files
.num_files
= 0;
3745 line_ptr
= dwarf_line_buffer
+ offset
;
3747 /* read in the prologue */
3748 lh
.total_length
= read_4_bytes (abfd
, line_ptr
);
3750 line_end
= line_ptr
+ lh
.total_length
;
3751 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3753 lh
.prologue_length
= read_4_bytes (abfd
, line_ptr
);
3755 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3757 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3759 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3761 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3763 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3765 lh
.standard_opcode_lengths
= (unsigned char *)
3766 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3767 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
3769 lh
.standard_opcode_lengths
[0] = 1;
3770 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3772 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3776 /* Read directory table */
3777 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3779 line_ptr
+= bytes_read
;
3780 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3782 dirs
.dirs
= (char **)
3783 xrealloc (dirs
.dirs
,
3784 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3785 if (dirs
.num_dirs
== 0)
3786 make_cleanup (free_current_contents
, &dirs
.dirs
);
3788 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3790 line_ptr
+= bytes_read
;
3792 /* Read file name table */
3793 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3795 line_ptr
+= bytes_read
;
3796 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3798 files
.files
= (struct fileinfo
*)
3799 xrealloc (files
.files
,
3800 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3801 * sizeof (struct fileinfo
));
3802 if (files
.num_files
== 0)
3803 make_cleanup (free_current_contents
, &files
.files
);
3805 files
.files
[files
.num_files
].name
= cur_file
;
3806 files
.files
[files
.num_files
].dir
=
3807 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3808 line_ptr
+= bytes_read
;
3809 files
.files
[files
.num_files
].time
=
3810 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3811 line_ptr
+= bytes_read
;
3812 files
.files
[files
.num_files
].size
=
3813 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3814 line_ptr
+= bytes_read
;
3817 line_ptr
+= bytes_read
;
3819 /* Read the statement sequences until there's nothing left. */
3820 while (line_ptr
< line_end
)
3822 /* state machine registers */
3823 CORE_ADDR address
= 0;
3824 unsigned int file
= 1;
3825 unsigned int line
= 1;
3826 unsigned int column
= 0;
3827 int is_stmt
= lh
.default_is_stmt
;
3828 int basic_block
= 0;
3829 int end_sequence
= 0;
3831 /* Start a subfile for the current file of the state machine. */
3832 if (files
.num_files
>= file
)
3834 /* The file and directory tables are 0 based, the references
3836 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3837 (files
.files
[file
- 1].dir
3838 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3842 /* Decode the table. */
3843 while (!end_sequence
)
3845 op_code
= read_1_byte (abfd
, line_ptr
);
3849 case DW_LNS_extended_op
:
3850 line_ptr
+= 1; /* ignore length */
3851 extended_op
= read_1_byte (abfd
, line_ptr
);
3853 switch (extended_op
)
3855 case DW_LNE_end_sequence
:
3857 /* Don't call record_line here. The end_sequence
3858 instruction provides the address of the first byte
3859 *after* the last line in the sequence; it's not the
3860 address of any real source line. However, the GDB
3861 linetable structure only records the starts of lines,
3862 not the ends. This is a weakness of GDB. */
3864 case DW_LNE_set_address
:
3865 address
= read_address (abfd
, line_ptr
) + baseaddr
;
3866 line_ptr
+= address_size
;
3868 case DW_LNE_define_file
:
3869 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
3870 line_ptr
+= bytes_read
;
3871 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3873 files
.files
= (struct fileinfo
*)
3874 xrealloc (files
.files
,
3875 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3876 * sizeof (struct fileinfo
));
3877 if (files
.num_files
== 0)
3878 make_cleanup (free_current_contents
, &files
.files
);
3880 files
.files
[files
.num_files
].name
= cur_file
;
3881 files
.files
[files
.num_files
].dir
=
3882 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3883 line_ptr
+= bytes_read
;
3884 files
.files
[files
.num_files
].time
=
3885 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3886 line_ptr
+= bytes_read
;
3887 files
.files
[files
.num_files
].size
=
3888 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3889 line_ptr
+= bytes_read
;
3893 complain (&dwarf2_mangled_line_number_section
);
3898 record_line (current_subfile
, line
, address
);
3901 case DW_LNS_advance_pc
:
3902 address
+= lh
.minimum_instruction_length
3903 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3904 line_ptr
+= bytes_read
;
3906 case DW_LNS_advance_line
:
3907 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
3908 line_ptr
+= bytes_read
;
3910 case DW_LNS_set_file
:
3911 /* The file and directory tables are 0 based, the references
3913 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3914 line_ptr
+= bytes_read
;
3915 dwarf2_start_subfile
3916 (files
.files
[file
- 1].name
,
3917 (files
.files
[file
- 1].dir
3918 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3921 case DW_LNS_set_column
:
3922 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3923 line_ptr
+= bytes_read
;
3925 case DW_LNS_negate_stmt
:
3926 is_stmt
= (!is_stmt
);
3928 case DW_LNS_set_basic_block
:
3931 /* Add to the address register of the state machine the
3932 address increment value corresponding to special opcode
3933 255. Ie, this value is scaled by the minimum instruction
3934 length since special opcode 255 would have scaled the
3936 case DW_LNS_const_add_pc
:
3937 address
+= (lh
.minimum_instruction_length
3938 * ((255 - lh
.opcode_base
) / lh
.line_range
));
3940 case DW_LNS_fixed_advance_pc
:
3941 address
+= read_2_bytes (abfd
, line_ptr
);
3944 default: /* special operand */
3945 adj_opcode
= op_code
- lh
.opcode_base
;
3946 address
+= (adj_opcode
/ lh
.line_range
)
3947 * lh
.minimum_instruction_length
;
3948 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
3949 /* append row to matrix using current values */
3950 record_line (current_subfile
, line
, address
);
3956 do_cleanups (back_to
);
3959 /* Start a subfile for DWARF. FILENAME is the name of the file and
3960 DIRNAME the name of the source directory which contains FILENAME
3961 or NULL if not known.
3962 This routine tries to keep line numbers from identical absolute and
3963 relative file names in a common subfile.
3965 Using the `list' example from the GDB testsuite, which resides in
3966 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
3967 of /srcdir/list0.c yields the following debugging information for list0.c:
3969 DW_AT_name: /srcdir/list0.c
3970 DW_AT_comp_dir: /compdir
3971 files.files[0].name: list0.h
3972 files.files[0].dir: /srcdir
3973 files.files[1].name: list0.c
3974 files.files[1].dir: /srcdir
3976 The line number information for list0.c has to end up in a single
3977 subfile, so that `break /srcdir/list0.c:1' works as expected. */
3980 dwarf2_start_subfile (filename
, dirname
)
3984 /* If the filename isn't absolute, try to match an existing subfile
3985 with the full pathname. */
3987 if (*filename
!= '/' && dirname
!= NULL
)
3989 struct subfile
*subfile
;
3990 char *fullname
= concat (dirname
, "/", filename
, NULL
);
3992 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
3994 if (STREQ (subfile
->name
, fullname
))
3996 current_subfile
= subfile
;
4003 start_subfile (filename
, dirname
);
4006 /* Given a pointer to a DWARF information entry, figure out if we need
4007 to make a symbol table entry for it, and if so, create a new entry
4008 and return a pointer to it.
4009 If TYPE is NULL, determine symbol type from the die, otherwise
4010 used the passed type. */
4012 static struct symbol
*
4013 new_symbol (die
, type
, objfile
)
4014 struct die_info
*die
;
4016 struct objfile
*objfile
;
4018 struct symbol
*sym
= NULL
;
4020 struct attribute
*attr
= NULL
;
4021 struct attribute
*attr2
= NULL
;
4024 name
= dwarf2_linkage_name (die
);
4027 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4028 sizeof (struct symbol
));
4029 OBJSTAT (objfile
, n_syms
++);
4030 memset (sym
, 0, sizeof (struct symbol
));
4031 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4032 &objfile
->symbol_obstack
);
4034 /* Default assumptions.
4035 Use the passed type or decode it from the die. */
4036 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4037 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4039 SYMBOL_TYPE (sym
) = type
;
4041 SYMBOL_TYPE (sym
) = die_type (die
, objfile
);
4042 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4045 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4048 /* If this symbol is from a C++ compilation, then attempt to
4049 cache the demangled form for future reference. This is a
4050 typical time versus space tradeoff, that was decided in favor
4051 of time because it sped up C++ symbol lookups by a factor of
4054 SYMBOL_LANGUAGE (sym
) = cu_language
;
4055 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4059 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4062 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4064 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4066 case DW_TAG_subprogram
:
4067 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4069 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4070 attr2
= dwarf_attr (die
, DW_AT_external
);
4071 if (attr2
&& (DW_UNSND (attr2
) != 0))
4073 add_symbol_to_list (sym
, &global_symbols
);
4077 add_symbol_to_list (sym
, list_in_scope
);
4080 case DW_TAG_variable
:
4081 /* Compilation with minimal debug info may result in variables
4082 with missing type entries. Change the misleading `void' type
4083 to something sensible. */
4084 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4085 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4086 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4087 "<variable, no debug info>",
4089 attr
= dwarf_attr (die
, DW_AT_const_value
);
4092 dwarf2_const_value (attr
, sym
, objfile
);
4093 attr2
= dwarf_attr (die
, DW_AT_external
);
4094 if (attr2
&& (DW_UNSND (attr2
) != 0))
4095 add_symbol_to_list (sym
, &global_symbols
);
4097 add_symbol_to_list (sym
, list_in_scope
);
4100 attr
= dwarf_attr (die
, DW_AT_location
);
4103 attr2
= dwarf_attr (die
, DW_AT_external
);
4104 if (attr2
&& (DW_UNSND (attr2
) != 0))
4106 SYMBOL_VALUE_ADDRESS (sym
) =
4107 decode_locdesc (DW_BLOCK (attr
), objfile
);
4108 add_symbol_to_list (sym
, &global_symbols
);
4110 /* In shared libraries the address of the variable
4111 in the location descriptor might still be relocatable,
4112 so its value could be zero.
4113 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4114 value is zero, the address of the variable will then
4115 be determined from the minimal symbol table whenever
4116 the variable is referenced. */
4117 if (SYMBOL_VALUE_ADDRESS (sym
))
4119 SYMBOL_VALUE_ADDRESS (sym
) += baseaddr
;
4120 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4123 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4127 SYMBOL_VALUE (sym
) = addr
=
4128 decode_locdesc (DW_BLOCK (attr
), objfile
);
4129 add_symbol_to_list (sym
, list_in_scope
);
4132 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4136 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4140 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4141 SYMBOL_BASEREG (sym
) = basereg
;
4145 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4149 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4150 SYMBOL_VALUE_ADDRESS (sym
) = addr
+ baseaddr
;
4156 /* We do not know the address of this symbol.
4157 If it is an external symbol and we have type information
4158 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4159 The address of the variable will then be determined from
4160 the minimal symbol table whenever the variable is
4162 attr2
= dwarf_attr (die
, DW_AT_external
);
4163 if (attr2
&& (DW_UNSND (attr2
) != 0)
4164 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4166 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4167 add_symbol_to_list (sym
, &global_symbols
);
4171 case DW_TAG_formal_parameter
:
4172 attr
= dwarf_attr (die
, DW_AT_location
);
4175 SYMBOL_VALUE (sym
) = decode_locdesc (DW_BLOCK (attr
), objfile
);
4178 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4184 if (basereg
!= frame_base_reg
)
4185 complain (&dwarf2_complex_location_expr
);
4186 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4190 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4191 SYMBOL_BASEREG (sym
) = basereg
;
4196 SYMBOL_CLASS (sym
) = LOC_ARG
;
4199 attr
= dwarf_attr (die
, DW_AT_const_value
);
4202 dwarf2_const_value (attr
, sym
, objfile
);
4204 add_symbol_to_list (sym
, list_in_scope
);
4206 case DW_TAG_unspecified_parameters
:
4207 /* From varargs functions; gdb doesn't seem to have any
4208 interest in this information, so just ignore it for now.
4211 case DW_TAG_class_type
:
4212 case DW_TAG_structure_type
:
4213 case DW_TAG_union_type
:
4214 case DW_TAG_enumeration_type
:
4215 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4216 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4217 add_symbol_to_list (sym
, list_in_scope
);
4219 /* The semantics of C++ state that "struct foo { ... }" also
4220 defines a typedef for "foo". Synthesize a typedef symbol so
4221 that "ptype foo" works as expected. */
4222 if (cu_language
== language_cplus
)
4224 struct symbol
*typedef_sym
= (struct symbol
*)
4225 obstack_alloc (&objfile
->symbol_obstack
,
4226 sizeof (struct symbol
));
4227 *typedef_sym
= *sym
;
4228 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4229 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4230 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4231 obsavestring (SYMBOL_NAME (sym
),
4232 strlen (SYMBOL_NAME (sym
)),
4233 &objfile
->type_obstack
);
4234 add_symbol_to_list (typedef_sym
, list_in_scope
);
4237 case DW_TAG_typedef
:
4238 case DW_TAG_base_type
:
4239 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4240 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4241 add_symbol_to_list (sym
, list_in_scope
);
4243 case DW_TAG_enumerator
:
4244 attr
= dwarf_attr (die
, DW_AT_const_value
);
4247 dwarf2_const_value (attr
, sym
, objfile
);
4249 add_symbol_to_list (sym
, list_in_scope
);
4252 /* Not a tag we recognize. Hopefully we aren't processing
4253 trash data, but since we must specifically ignore things
4254 we don't recognize, there is nothing else we should do at
4256 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4263 /* Copy constant value from an attribute to a symbol. */
4266 dwarf2_const_value (attr
, sym
, objfile
)
4267 struct attribute
*attr
;
4269 struct objfile
*objfile
;
4271 struct dwarf_block
*blk
;
4276 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != (unsigned int) address_size
)
4277 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4278 address_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4279 SYMBOL_VALUE_BYTES (sym
) = (char *)
4280 obstack_alloc (&objfile
->symbol_obstack
, address_size
);
4281 store_address (SYMBOL_VALUE_BYTES (sym
), address_size
, DW_ADDR (attr
));
4282 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4284 case DW_FORM_block1
:
4285 case DW_FORM_block2
:
4286 case DW_FORM_block4
:
4288 blk
= DW_BLOCK (attr
);
4289 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4290 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4291 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4292 SYMBOL_VALUE_BYTES (sym
) = (char *)
4293 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4294 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4295 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4298 /* The DW_AT_const_value attributes are supposed to carry the
4299 symbol's value "represented as it would be on the target
4300 architecture." By the time we get here, it's already been
4301 converted to host endianness, so we just need to sign- or
4302 zero-extend it as appropriate. */
4304 dwarf2_const_value_data (attr
, sym
, 8);
4307 dwarf2_const_value_data (attr
, sym
, 16);
4310 dwarf2_const_value_data (attr
, sym
, 32);
4313 dwarf2_const_value_data (attr
, sym
, 64);
4317 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4318 SYMBOL_CLASS (sym
) = LOC_CONST
;
4322 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4323 SYMBOL_CLASS (sym
) = LOC_CONST
;
4327 complain (&dwarf2_unsupported_const_value_attr
,
4328 dwarf_form_name (attr
->form
));
4329 SYMBOL_VALUE (sym
) = 0;
4330 SYMBOL_CLASS (sym
) = LOC_CONST
;
4336 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4337 or zero-extend it as appropriate for the symbol's type. */
4339 dwarf2_const_value_data (struct attribute
*attr
,
4343 LONGEST l
= DW_UNSND (attr
);
4345 if (bits
< sizeof (l
) * 8)
4347 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4348 l
&= ((LONGEST
) 1 << bits
) - 1;
4350 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4353 SYMBOL_VALUE (sym
) = l
;
4354 SYMBOL_CLASS (sym
) = LOC_CONST
;
4358 /* Return the type of the die in question using its DW_AT_type attribute. */
4360 static struct type
*
4361 die_type (die
, objfile
)
4362 struct die_info
*die
;
4363 struct objfile
*objfile
;
4366 struct attribute
*type_attr
;
4367 struct die_info
*type_die
;
4370 type_attr
= dwarf_attr (die
, DW_AT_type
);
4373 /* A missing DW_AT_type represents a void type. */
4374 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4378 ref
= dwarf2_get_ref_die_offset (type_attr
);
4379 type_die
= follow_die_ref (ref
);
4382 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4386 type
= tag_type_to_type (type_die
, objfile
);
4389 dump_die (type_die
);
4390 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4395 /* Return the containing type of the die in question using its
4396 DW_AT_containing_type attribute. */
4398 static struct type
*
4399 die_containing_type (die
, objfile
)
4400 struct die_info
*die
;
4401 struct objfile
*objfile
;
4403 struct type
*type
= NULL
;
4404 struct attribute
*type_attr
;
4405 struct die_info
*type_die
= NULL
;
4408 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4411 ref
= dwarf2_get_ref_die_offset (type_attr
);
4412 type_die
= follow_die_ref (ref
);
4415 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4418 type
= tag_type_to_type (type_die
, objfile
);
4423 dump_die (type_die
);
4424 error ("Dwarf Error: Problem turning containing type into gdb type.");
4430 static struct type
*
4431 type_at_offset (offset
, objfile
)
4432 unsigned int offset
;
4433 struct objfile
*objfile
;
4435 struct die_info
*die
;
4438 die
= follow_die_ref (offset
);
4441 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4444 type
= tag_type_to_type (die
, objfile
);
4449 static struct type
*
4450 tag_type_to_type (die
, objfile
)
4451 struct die_info
*die
;
4452 struct objfile
*objfile
;
4460 struct attribute
*attr
;
4461 attr
= dwarf_attr (die
, DW_AT_name
);
4462 if (attr
&& DW_STRING (attr
))
4464 char *attrname
=DW_STRING (attr
);
4465 unsigned long hashval
=hash(attrname
, strlen(attrname
)) % TYPE_HASH_SIZE
;
4467 if (dwarf2_cached_types
[hashval
] != NULL
)
4469 const char *nameoftype
;
4470 nameoftype
= TYPE_NAME(dwarf2_cached_types
[hashval
]) == NULL
? TYPE_TAG_NAME(dwarf2_cached_types
[hashval
]) : TYPE_NAME(dwarf2_cached_types
[hashval
]);
4471 if (strcmp(attrname
, nameoftype
) == 0)
4473 die
->type
=dwarf2_cached_types
[hashval
];
4477 read_type_die (die
, objfile
);
4478 dwarf2_cached_types
[hashval
] = die
->type
;
4483 read_type_die (die
, objfile
);
4484 dwarf2_cached_types
[hashval
] = die
->type
;
4489 read_type_die (die
, objfile
);
4495 error ("Dwarf Error: Cannot find type of die.");
4502 read_type_die (die
, objfile
)
4503 struct die_info
*die
;
4504 struct objfile
*objfile
;
4508 case DW_TAG_class_type
:
4509 case DW_TAG_structure_type
:
4510 case DW_TAG_union_type
:
4511 read_structure_scope (die
, objfile
);
4513 case DW_TAG_enumeration_type
:
4514 read_enumeration (die
, objfile
);
4516 case DW_TAG_subprogram
:
4517 case DW_TAG_subroutine_type
:
4518 read_subroutine_type (die
, objfile
);
4520 case DW_TAG_array_type
:
4521 read_array_type (die
, objfile
);
4523 case DW_TAG_pointer_type
:
4524 read_tag_pointer_type (die
, objfile
);
4526 case DW_TAG_ptr_to_member_type
:
4527 read_tag_ptr_to_member_type (die
, objfile
);
4529 case DW_TAG_reference_type
:
4530 read_tag_reference_type (die
, objfile
);
4532 case DW_TAG_const_type
:
4533 read_tag_const_type (die
, objfile
);
4535 case DW_TAG_volatile_type
:
4536 read_tag_volatile_type (die
, objfile
);
4538 case DW_TAG_string_type
:
4539 read_tag_string_type (die
, objfile
);
4541 case DW_TAG_typedef
:
4542 read_typedef (die
, objfile
);
4544 case DW_TAG_base_type
:
4545 read_base_type (die
, objfile
);
4548 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4553 static struct type
*
4554 dwarf_base_type (encoding
, size
, objfile
)
4557 struct objfile
*objfile
;
4559 /* FIXME - this should not produce a new (struct type *)
4560 every time. It should cache base types. */
4564 case DW_ATE_address
:
4565 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4567 case DW_ATE_boolean
:
4568 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4570 case DW_ATE_complex_float
:
4573 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4577 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4583 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4587 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4594 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4597 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4601 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4605 case DW_ATE_signed_char
:
4606 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4608 case DW_ATE_unsigned
:
4612 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4615 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4619 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4623 case DW_ATE_unsigned_char
:
4624 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4627 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4635 struct die_info
*old_die
;
4637 struct die_info
*new_die
;
4640 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4641 memset (new_die
, 0, sizeof (struct die_info
));
4643 new_die
->tag
= old_die
->tag
;
4644 new_die
->has_children
= old_die
->has_children
;
4645 new_die
->abbrev
= old_die
->abbrev
;
4646 new_die
->offset
= old_die
->offset
;
4647 new_die
->type
= NULL
;
4649 num_attrs
= old_die
->num_attrs
;
4650 new_die
->num_attrs
= num_attrs
;
4651 new_die
->attrs
= (struct attribute
*)
4652 xmalloc (num_attrs
* sizeof (struct attribute
));
4654 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4656 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4657 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4658 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4661 new_die
->next
= NULL
;
4666 /* Return sibling of die, NULL if no sibling. */
4670 struct die_info
*die
;
4672 int nesting_level
= 0;
4674 if (!die
->has_children
)
4676 if (die
->next
&& (die
->next
->tag
== 0))
4689 if (die
->has_children
)
4699 while (nesting_level
);
4700 if (die
&& (die
->tag
== 0))
4711 /* Get linkage name of a die, return NULL if not found. */
4714 dwarf2_linkage_name (die
)
4715 struct die_info
*die
;
4717 struct attribute
*attr
;
4719 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4720 if (attr
&& DW_STRING (attr
))
4721 return DW_STRING (attr
);
4722 attr
= dwarf_attr (die
, DW_AT_name
);
4723 if (attr
&& DW_STRING (attr
))
4724 return DW_STRING (attr
);
4728 /* Convert a DIE tag into its string name. */
4731 dwarf_tag_name (tag
)
4732 register unsigned tag
;
4736 case DW_TAG_padding
:
4737 return "DW_TAG_padding";
4738 case DW_TAG_array_type
:
4739 return "DW_TAG_array_type";
4740 case DW_TAG_class_type
:
4741 return "DW_TAG_class_type";
4742 case DW_TAG_entry_point
:
4743 return "DW_TAG_entry_point";
4744 case DW_TAG_enumeration_type
:
4745 return "DW_TAG_enumeration_type";
4746 case DW_TAG_formal_parameter
:
4747 return "DW_TAG_formal_parameter";
4748 case DW_TAG_imported_declaration
:
4749 return "DW_TAG_imported_declaration";
4751 return "DW_TAG_label";
4752 case DW_TAG_lexical_block
:
4753 return "DW_TAG_lexical_block";
4755 return "DW_TAG_member";
4756 case DW_TAG_pointer_type
:
4757 return "DW_TAG_pointer_type";
4758 case DW_TAG_reference_type
:
4759 return "DW_TAG_reference_type";
4760 case DW_TAG_compile_unit
:
4761 return "DW_TAG_compile_unit";
4762 case DW_TAG_string_type
:
4763 return "DW_TAG_string_type";
4764 case DW_TAG_structure_type
:
4765 return "DW_TAG_structure_type";
4766 case DW_TAG_subroutine_type
:
4767 return "DW_TAG_subroutine_type";
4768 case DW_TAG_typedef
:
4769 return "DW_TAG_typedef";
4770 case DW_TAG_union_type
:
4771 return "DW_TAG_union_type";
4772 case DW_TAG_unspecified_parameters
:
4773 return "DW_TAG_unspecified_parameters";
4774 case DW_TAG_variant
:
4775 return "DW_TAG_variant";
4776 case DW_TAG_common_block
:
4777 return "DW_TAG_common_block";
4778 case DW_TAG_common_inclusion
:
4779 return "DW_TAG_common_inclusion";
4780 case DW_TAG_inheritance
:
4781 return "DW_TAG_inheritance";
4782 case DW_TAG_inlined_subroutine
:
4783 return "DW_TAG_inlined_subroutine";
4785 return "DW_TAG_module";
4786 case DW_TAG_ptr_to_member_type
:
4787 return "DW_TAG_ptr_to_member_type";
4788 case DW_TAG_set_type
:
4789 return "DW_TAG_set_type";
4790 case DW_TAG_subrange_type
:
4791 return "DW_TAG_subrange_type";
4792 case DW_TAG_with_stmt
:
4793 return "DW_TAG_with_stmt";
4794 case DW_TAG_access_declaration
:
4795 return "DW_TAG_access_declaration";
4796 case DW_TAG_base_type
:
4797 return "DW_TAG_base_type";
4798 case DW_TAG_catch_block
:
4799 return "DW_TAG_catch_block";
4800 case DW_TAG_const_type
:
4801 return "DW_TAG_const_type";
4802 case DW_TAG_constant
:
4803 return "DW_TAG_constant";
4804 case DW_TAG_enumerator
:
4805 return "DW_TAG_enumerator";
4806 case DW_TAG_file_type
:
4807 return "DW_TAG_file_type";
4809 return "DW_TAG_friend";
4810 case DW_TAG_namelist
:
4811 return "DW_TAG_namelist";
4812 case DW_TAG_namelist_item
:
4813 return "DW_TAG_namelist_item";
4814 case DW_TAG_packed_type
:
4815 return "DW_TAG_packed_type";
4816 case DW_TAG_subprogram
:
4817 return "DW_TAG_subprogram";
4818 case DW_TAG_template_type_param
:
4819 return "DW_TAG_template_type_param";
4820 case DW_TAG_template_value_param
:
4821 return "DW_TAG_template_value_param";
4822 case DW_TAG_thrown_type
:
4823 return "DW_TAG_thrown_type";
4824 case DW_TAG_try_block
:
4825 return "DW_TAG_try_block";
4826 case DW_TAG_variant_part
:
4827 return "DW_TAG_variant_part";
4828 case DW_TAG_variable
:
4829 return "DW_TAG_variable";
4830 case DW_TAG_volatile_type
:
4831 return "DW_TAG_volatile_type";
4832 case DW_TAG_MIPS_loop
:
4833 return "DW_TAG_MIPS_loop";
4834 case DW_TAG_format_label
:
4835 return "DW_TAG_format_label";
4836 case DW_TAG_function_template
:
4837 return "DW_TAG_function_template";
4838 case DW_TAG_class_template
:
4839 return "DW_TAG_class_template";
4841 return "DW_TAG_<unknown>";
4845 /* Convert a DWARF attribute code into its string name. */
4848 dwarf_attr_name (attr
)
4849 register unsigned attr
;
4854 return "DW_AT_sibling";
4855 case DW_AT_location
:
4856 return "DW_AT_location";
4858 return "DW_AT_name";
4859 case DW_AT_ordering
:
4860 return "DW_AT_ordering";
4861 case DW_AT_subscr_data
:
4862 return "DW_AT_subscr_data";
4863 case DW_AT_byte_size
:
4864 return "DW_AT_byte_size";
4865 case DW_AT_bit_offset
:
4866 return "DW_AT_bit_offset";
4867 case DW_AT_bit_size
:
4868 return "DW_AT_bit_size";
4869 case DW_AT_element_list
:
4870 return "DW_AT_element_list";
4871 case DW_AT_stmt_list
:
4872 return "DW_AT_stmt_list";
4874 return "DW_AT_low_pc";
4876 return "DW_AT_high_pc";
4877 case DW_AT_language
:
4878 return "DW_AT_language";
4880 return "DW_AT_member";
4882 return "DW_AT_discr";
4883 case DW_AT_discr_value
:
4884 return "DW_AT_discr_value";
4885 case DW_AT_visibility
:
4886 return "DW_AT_visibility";
4888 return "DW_AT_import";
4889 case DW_AT_string_length
:
4890 return "DW_AT_string_length";
4891 case DW_AT_common_reference
:
4892 return "DW_AT_common_reference";
4893 case DW_AT_comp_dir
:
4894 return "DW_AT_comp_dir";
4895 case DW_AT_const_value
:
4896 return "DW_AT_const_value";
4897 case DW_AT_containing_type
:
4898 return "DW_AT_containing_type";
4899 case DW_AT_default_value
:
4900 return "DW_AT_default_value";
4902 return "DW_AT_inline";
4903 case DW_AT_is_optional
:
4904 return "DW_AT_is_optional";
4905 case DW_AT_lower_bound
:
4906 return "DW_AT_lower_bound";
4907 case DW_AT_producer
:
4908 return "DW_AT_producer";
4909 case DW_AT_prototyped
:
4910 return "DW_AT_prototyped";
4911 case DW_AT_return_addr
:
4912 return "DW_AT_return_addr";
4913 case DW_AT_start_scope
:
4914 return "DW_AT_start_scope";
4915 case DW_AT_stride_size
:
4916 return "DW_AT_stride_size";
4917 case DW_AT_upper_bound
:
4918 return "DW_AT_upper_bound";
4919 case DW_AT_abstract_origin
:
4920 return "DW_AT_abstract_origin";
4921 case DW_AT_accessibility
:
4922 return "DW_AT_accessibility";
4923 case DW_AT_address_class
:
4924 return "DW_AT_address_class";
4925 case DW_AT_artificial
:
4926 return "DW_AT_artificial";
4927 case DW_AT_base_types
:
4928 return "DW_AT_base_types";
4929 case DW_AT_calling_convention
:
4930 return "DW_AT_calling_convention";
4932 return "DW_AT_count";
4933 case DW_AT_data_member_location
:
4934 return "DW_AT_data_member_location";
4935 case DW_AT_decl_column
:
4936 return "DW_AT_decl_column";
4937 case DW_AT_decl_file
:
4938 return "DW_AT_decl_file";
4939 case DW_AT_decl_line
:
4940 return "DW_AT_decl_line";
4941 case DW_AT_declaration
:
4942 return "DW_AT_declaration";
4943 case DW_AT_discr_list
:
4944 return "DW_AT_discr_list";
4945 case DW_AT_encoding
:
4946 return "DW_AT_encoding";
4947 case DW_AT_external
:
4948 return "DW_AT_external";
4949 case DW_AT_frame_base
:
4950 return "DW_AT_frame_base";
4952 return "DW_AT_friend";
4953 case DW_AT_identifier_case
:
4954 return "DW_AT_identifier_case";
4955 case DW_AT_macro_info
:
4956 return "DW_AT_macro_info";
4957 case DW_AT_namelist_items
:
4958 return "DW_AT_namelist_items";
4959 case DW_AT_priority
:
4960 return "DW_AT_priority";
4962 return "DW_AT_segment";
4963 case DW_AT_specification
:
4964 return "DW_AT_specification";
4965 case DW_AT_static_link
:
4966 return "DW_AT_static_link";
4968 return "DW_AT_type";
4969 case DW_AT_use_location
:
4970 return "DW_AT_use_location";
4971 case DW_AT_variable_parameter
:
4972 return "DW_AT_variable_parameter";
4973 case DW_AT_virtuality
:
4974 return "DW_AT_virtuality";
4975 case DW_AT_vtable_elem_location
:
4976 return "DW_AT_vtable_elem_location";
4979 case DW_AT_MIPS_fde
:
4980 return "DW_AT_MIPS_fde";
4981 case DW_AT_MIPS_loop_begin
:
4982 return "DW_AT_MIPS_loop_begin";
4983 case DW_AT_MIPS_tail_loop_begin
:
4984 return "DW_AT_MIPS_tail_loop_begin";
4985 case DW_AT_MIPS_epilog_begin
:
4986 return "DW_AT_MIPS_epilog_begin";
4987 case DW_AT_MIPS_loop_unroll_factor
:
4988 return "DW_AT_MIPS_loop_unroll_factor";
4989 case DW_AT_MIPS_software_pipeline_depth
:
4990 return "DW_AT_MIPS_software_pipeline_depth";
4991 case DW_AT_MIPS_linkage_name
:
4992 return "DW_AT_MIPS_linkage_name";
4995 case DW_AT_sf_names
:
4996 return "DW_AT_sf_names";
4997 case DW_AT_src_info
:
4998 return "DW_AT_src_info";
4999 case DW_AT_mac_info
:
5000 return "DW_AT_mac_info";
5001 case DW_AT_src_coords
:
5002 return "DW_AT_src_coords";
5003 case DW_AT_body_begin
:
5004 return "DW_AT_body_begin";
5005 case DW_AT_body_end
:
5006 return "DW_AT_body_end";
5008 return "DW_AT_<unknown>";
5012 /* Convert a DWARF value form code into its string name. */
5015 dwarf_form_name (form
)
5016 register unsigned form
;
5021 return "DW_FORM_addr";
5022 case DW_FORM_block2
:
5023 return "DW_FORM_block2";
5024 case DW_FORM_block4
:
5025 return "DW_FORM_block4";
5027 return "DW_FORM_data2";
5029 return "DW_FORM_data4";
5031 return "DW_FORM_data8";
5032 case DW_FORM_string
:
5033 return "DW_FORM_string";
5035 return "DW_FORM_block";
5036 case DW_FORM_block1
:
5037 return "DW_FORM_block1";
5039 return "DW_FORM_data1";
5041 return "DW_FORM_flag";
5043 return "DW_FORM_sdata";
5045 return "DW_FORM_strp";
5047 return "DW_FORM_udata";
5048 case DW_FORM_ref_addr
:
5049 return "DW_FORM_ref_addr";
5051 return "DW_FORM_ref1";
5053 return "DW_FORM_ref2";
5055 return "DW_FORM_ref4";
5057 return "DW_FORM_ref8";
5058 case DW_FORM_ref_udata
:
5059 return "DW_FORM_ref_udata";
5060 case DW_FORM_indirect
:
5061 return "DW_FORM_indirect";
5063 return "DW_FORM_<unknown>";
5067 /* Convert a DWARF stack opcode into its string name. */
5070 dwarf_stack_op_name (op
)
5071 register unsigned op
;
5076 return "DW_OP_addr";
5078 return "DW_OP_deref";
5080 return "DW_OP_const1u";
5082 return "DW_OP_const1s";
5084 return "DW_OP_const2u";
5086 return "DW_OP_const2s";
5088 return "DW_OP_const4u";
5090 return "DW_OP_const4s";
5092 return "DW_OP_const8u";
5094 return "DW_OP_const8s";
5096 return "DW_OP_constu";
5098 return "DW_OP_consts";
5102 return "DW_OP_drop";
5104 return "DW_OP_over";
5106 return "DW_OP_pick";
5108 return "DW_OP_swap";
5112 return "DW_OP_xderef";
5120 return "DW_OP_minus";
5132 return "DW_OP_plus";
5133 case DW_OP_plus_uconst
:
5134 return "DW_OP_plus_uconst";
5140 return "DW_OP_shra";
5158 return "DW_OP_skip";
5160 return "DW_OP_lit0";
5162 return "DW_OP_lit1";
5164 return "DW_OP_lit2";
5166 return "DW_OP_lit3";
5168 return "DW_OP_lit4";
5170 return "DW_OP_lit5";
5172 return "DW_OP_lit6";
5174 return "DW_OP_lit7";
5176 return "DW_OP_lit8";
5178 return "DW_OP_lit9";
5180 return "DW_OP_lit10";
5182 return "DW_OP_lit11";
5184 return "DW_OP_lit12";
5186 return "DW_OP_lit13";
5188 return "DW_OP_lit14";
5190 return "DW_OP_lit15";
5192 return "DW_OP_lit16";
5194 return "DW_OP_lit17";
5196 return "DW_OP_lit18";
5198 return "DW_OP_lit19";
5200 return "DW_OP_lit20";
5202 return "DW_OP_lit21";
5204 return "DW_OP_lit22";
5206 return "DW_OP_lit23";
5208 return "DW_OP_lit24";
5210 return "DW_OP_lit25";
5212 return "DW_OP_lit26";
5214 return "DW_OP_lit27";
5216 return "DW_OP_lit28";
5218 return "DW_OP_lit29";
5220 return "DW_OP_lit30";
5222 return "DW_OP_lit31";
5224 return "DW_OP_reg0";
5226 return "DW_OP_reg1";
5228 return "DW_OP_reg2";
5230 return "DW_OP_reg3";
5232 return "DW_OP_reg4";
5234 return "DW_OP_reg5";
5236 return "DW_OP_reg6";
5238 return "DW_OP_reg7";
5240 return "DW_OP_reg8";
5242 return "DW_OP_reg9";
5244 return "DW_OP_reg10";
5246 return "DW_OP_reg11";
5248 return "DW_OP_reg12";
5250 return "DW_OP_reg13";
5252 return "DW_OP_reg14";
5254 return "DW_OP_reg15";
5256 return "DW_OP_reg16";
5258 return "DW_OP_reg17";
5260 return "DW_OP_reg18";
5262 return "DW_OP_reg19";
5264 return "DW_OP_reg20";
5266 return "DW_OP_reg21";
5268 return "DW_OP_reg22";
5270 return "DW_OP_reg23";
5272 return "DW_OP_reg24";
5274 return "DW_OP_reg25";
5276 return "DW_OP_reg26";
5278 return "DW_OP_reg27";
5280 return "DW_OP_reg28";
5282 return "DW_OP_reg29";
5284 return "DW_OP_reg30";
5286 return "DW_OP_reg31";
5288 return "DW_OP_breg0";
5290 return "DW_OP_breg1";
5292 return "DW_OP_breg2";
5294 return "DW_OP_breg3";
5296 return "DW_OP_breg4";
5298 return "DW_OP_breg5";
5300 return "DW_OP_breg6";
5302 return "DW_OP_breg7";
5304 return "DW_OP_breg8";
5306 return "DW_OP_breg9";
5308 return "DW_OP_breg10";
5310 return "DW_OP_breg11";
5312 return "DW_OP_breg12";
5314 return "DW_OP_breg13";
5316 return "DW_OP_breg14";
5318 return "DW_OP_breg15";
5320 return "DW_OP_breg16";
5322 return "DW_OP_breg17";
5324 return "DW_OP_breg18";
5326 return "DW_OP_breg19";
5328 return "DW_OP_breg20";
5330 return "DW_OP_breg21";
5332 return "DW_OP_breg22";
5334 return "DW_OP_breg23";
5336 return "DW_OP_breg24";
5338 return "DW_OP_breg25";
5340 return "DW_OP_breg26";
5342 return "DW_OP_breg27";
5344 return "DW_OP_breg28";
5346 return "DW_OP_breg29";
5348 return "DW_OP_breg30";
5350 return "DW_OP_breg31";
5352 return "DW_OP_regx";
5354 return "DW_OP_fbreg";
5356 return "DW_OP_bregx";
5358 return "DW_OP_piece";
5359 case DW_OP_deref_size
:
5360 return "DW_OP_deref_size";
5361 case DW_OP_xderef_size
:
5362 return "DW_OP_xderef_size";
5366 return "OP_<unknown>";
5371 dwarf_bool_name (mybool
)
5380 /* Convert a DWARF type code into its string name. */
5383 dwarf_type_encoding_name (enc
)
5384 register unsigned enc
;
5388 case DW_ATE_address
:
5389 return "DW_ATE_address";
5390 case DW_ATE_boolean
:
5391 return "DW_ATE_boolean";
5392 case DW_ATE_complex_float
:
5393 return "DW_ATE_complex_float";
5395 return "DW_ATE_float";
5397 return "DW_ATE_signed";
5398 case DW_ATE_signed_char
:
5399 return "DW_ATE_signed_char";
5400 case DW_ATE_unsigned
:
5401 return "DW_ATE_unsigned";
5402 case DW_ATE_unsigned_char
:
5403 return "DW_ATE_unsigned_char";
5405 return "DW_ATE_<unknown>";
5409 /* Convert a DWARF call frame info operation to its string name. */
5413 dwarf_cfi_name (cfi_opc
)
5414 register unsigned cfi_opc
;
5418 case DW_CFA_advance_loc
:
5419 return "DW_CFA_advance_loc";
5421 return "DW_CFA_offset";
5422 case DW_CFA_restore
:
5423 return "DW_CFA_restore";
5425 return "DW_CFA_nop";
5426 case DW_CFA_set_loc
:
5427 return "DW_CFA_set_loc";
5428 case DW_CFA_advance_loc1
:
5429 return "DW_CFA_advance_loc1";
5430 case DW_CFA_advance_loc2
:
5431 return "DW_CFA_advance_loc2";
5432 case DW_CFA_advance_loc4
:
5433 return "DW_CFA_advance_loc4";
5434 case DW_CFA_offset_extended
:
5435 return "DW_CFA_offset_extended";
5436 case DW_CFA_restore_extended
:
5437 return "DW_CFA_restore_extended";
5438 case DW_CFA_undefined
:
5439 return "DW_CFA_undefined";
5440 case DW_CFA_same_value
:
5441 return "DW_CFA_same_value";
5442 case DW_CFA_register
:
5443 return "DW_CFA_register";
5444 case DW_CFA_remember_state
:
5445 return "DW_CFA_remember_state";
5446 case DW_CFA_restore_state
:
5447 return "DW_CFA_restore_state";
5448 case DW_CFA_def_cfa
:
5449 return "DW_CFA_def_cfa";
5450 case DW_CFA_def_cfa_register
:
5451 return "DW_CFA_def_cfa_register";
5452 case DW_CFA_def_cfa_offset
:
5453 return "DW_CFA_def_cfa_offset";
5454 /* SGI/MIPS specific */
5455 case DW_CFA_MIPS_advance_loc8
:
5456 return "DW_CFA_MIPS_advance_loc8";
5458 return "DW_CFA_<unknown>";
5465 struct die_info
*die
;
5469 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5470 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5471 fprintf (stderr
, "\thas children: %s\n",
5472 dwarf_bool_name (die
->has_children
));
5474 fprintf (stderr
, "\tattributes:\n");
5475 for (i
= 0; i
< die
->num_attrs
; ++i
)
5477 fprintf (stderr
, "\t\t%s (%s) ",
5478 dwarf_attr_name (die
->attrs
[i
].name
),
5479 dwarf_form_name (die
->attrs
[i
].form
));
5480 switch (die
->attrs
[i
].form
)
5482 case DW_FORM_ref_addr
:
5484 fprintf (stderr
, "address: ");
5485 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5487 case DW_FORM_block2
:
5488 case DW_FORM_block4
:
5490 case DW_FORM_block1
:
5491 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5502 fprintf (stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
5504 case DW_FORM_string
:
5505 fprintf (stderr
, "string: \"%s\"",
5506 DW_STRING (&die
->attrs
[i
])
5507 ? DW_STRING (&die
->attrs
[i
]) : "");
5510 if (DW_UNSND (&die
->attrs
[i
]))
5511 fprintf (stderr
, "flag: TRUE");
5513 fprintf (stderr
, "flag: FALSE");
5515 case DW_FORM_strp
: /* we do not support separate string
5517 case DW_FORM_indirect
: /* we do not handle indirect yet */
5519 fprintf (stderr
, "unsupported attribute form: %d.",
5520 die
->attrs
[i
].form
);
5522 fprintf (stderr
, "\n");
5528 struct die_info
*die
;
5538 store_in_ref_table (offset
, die
)
5539 unsigned int offset
;
5540 struct die_info
*die
;
5543 struct die_info
*old
;
5545 h
= (offset
% REF_HASH_SIZE
);
5546 old
= die_ref_table
[h
];
5547 die
->next_ref
= old
;
5548 die_ref_table
[h
] = die
;
5553 dwarf2_empty_hash_tables ()
5555 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5556 memset (dwarf2_cached_types
, 0, sizeof(dwarf2_cached_types
));
5560 dwarf2_get_ref_die_offset (attr
)
5561 struct attribute
*attr
;
5563 unsigned int result
= 0;
5567 case DW_FORM_ref_addr
:
5568 result
= DW_ADDR (attr
);
5573 case DW_FORM_ref_udata
:
5574 result
= cu_header_offset
+ DW_UNSND (attr
);
5577 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5583 follow_die_ref (offset
)
5584 unsigned int offset
;
5586 struct die_info
*die
;
5589 h
= (offset
% REF_HASH_SIZE
);
5590 die
= die_ref_table
[h
];
5593 if (die
->offset
== offset
)
5597 die
= die
->next_ref
;
5602 static struct type
*
5603 dwarf2_fundamental_type (objfile
, typeid)
5604 struct objfile
*objfile
;
5607 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5609 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5613 /* Look for this particular type in the fundamental type vector. If
5614 one is not found, create and install one appropriate for the
5615 current language and the current target machine. */
5617 if (ftypes
[typeid] == NULL
)
5619 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5622 return (ftypes
[typeid]);
5625 /* Decode simple location descriptions.
5626 Given a pointer to a dwarf block that defines a location, compute
5627 the location and return the value.
5629 FIXME: This is a kludge until we figure out a better
5630 way to handle the location descriptions.
5631 Gdb's design does not mesh well with the DWARF2 notion of a location
5632 computing interpreter, which is a shame because the flexibility goes unused.
5633 FIXME: Implement more operations as necessary.
5635 A location description containing no operations indicates that the
5636 object is optimized out. The global optimized_out flag is set for
5637 those, the return value is meaningless.
5639 When the result is a register number, the global isreg flag is set,
5640 otherwise it is cleared.
5642 When the result is a base register offset, the global offreg flag is set
5643 and the register number is returned in basereg, otherwise it is cleared.
5645 When the DW_OP_fbreg operation is encountered without a corresponding
5646 DW_AT_frame_base attribute, the global islocal flag is set.
5647 Hopefully the machine dependent code knows how to set up a virtual
5648 frame pointer for the local references.
5650 Note that stack[0] is unused except as a default error return.
5651 Note that stack overflow is not yet handled. */
5654 decode_locdesc (blk
, objfile
)
5655 struct dwarf_block
*blk
;
5656 struct objfile
*objfile
;
5659 int size
= blk
->size
;
5660 char *data
= blk
->data
;
5661 CORE_ADDR stack
[64];
5663 unsigned int bytes_read
, unsnd
;
5714 stack
[++stacki
] = op
- DW_OP_reg0
;
5719 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5721 #if defined(HARRIS_TARGET) && defined(_M88K)
5722 /* The Harris 88110 gdb ports have long kept their special reg
5723 numbers between their gp-regs and their x-regs. This is
5724 not how our dwarf is generated. Punt. */
5727 stack
[++stacki
] = unsnd
;
5763 basereg
= op
- DW_OP_breg0
;
5764 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5770 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5772 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5777 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5779 if (frame_base_reg
>= 0)
5782 basereg
= frame_base_reg
;
5783 stack
[stacki
] += frame_base_offset
;
5787 complain (&dwarf2_missing_at_frame_base
);
5793 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
]);
5798 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5803 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5808 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5813 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5818 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5823 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5828 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5834 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5839 stack
[stacki
- 1] += stack
[stacki
];
5843 case DW_OP_plus_uconst
:
5844 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5849 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5855 /* If we're not the last op, then we definitely can't encode
5856 this using GDB's address_class enum. */
5858 complain (&dwarf2_complex_location_expr
);
5862 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
5863 return (stack
[stacki
]);
5866 return (stack
[stacki
]);
5869 /* memory allocation interface */
5873 dwarf2_free_tmp_obstack (ignore
)
5876 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5879 static struct dwarf_block
*
5880 dwarf_alloc_block ()
5882 struct dwarf_block
*blk
;
5884 blk
= (struct dwarf_block
*)
5885 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5889 static struct abbrev_info
*
5890 dwarf_alloc_abbrev ()
5892 struct abbrev_info
*abbrev
;
5894 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5895 memset (abbrev
, 0, sizeof (struct abbrev_info
));
5899 static struct die_info
*
5902 struct die_info
*die
;
5904 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5905 memset (die
, 0, sizeof (struct die_info
));