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_die_ref_table (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, we are building a new one now. */
2896 dwarf2_empty_die_ref_table ();
2900 first_die
= last_die
= NULL
;
2903 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
);
2904 if (die
->has_children
)
2915 /* Enter die in reference hash table */
2916 store_in_ref_table (die
->offset
, die
);
2920 first_die
= last_die
= die
;
2924 last_die
->next
= die
;
2928 while (nesting_level
> 0);
2932 /* Free a linked list of dies. */
2935 free_die_list (dies
)
2936 struct die_info
*dies
;
2938 struct die_info
*die
, *next
;
2951 do_free_die_list_cleanup (void *dies
)
2953 free_die_list (dies
);
2956 static struct cleanup
*
2957 make_cleanup_free_die_list (struct die_info
*dies
)
2959 return make_cleanup (do_free_die_list_cleanup
, dies
);
2963 /* Read the contents of the section at OFFSET and of size SIZE from the
2964 object file specified by OBJFILE into the psymbol_obstack and return it. */
2967 dwarf2_read_section (objfile
, offset
, size
)
2968 struct objfile
*objfile
;
2972 bfd
*abfd
= objfile
->obfd
;
2978 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
2979 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
2980 (bfd_read (buf
, size
, 1, abfd
) != size
))
2983 error ("Dwarf Error: Can't read DWARF data from '%s'",
2984 bfd_get_filename (abfd
));
2989 /* In DWARF version 2, the description of the debugging information is
2990 stored in a separate .debug_abbrev section. Before we read any
2991 dies from a section we read in all abbreviations and install them
2995 dwarf2_read_abbrevs (abfd
, offset
)
2997 unsigned int offset
;
3000 struct abbrev_info
*cur_abbrev
;
3001 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3002 unsigned int abbrev_form
, hash_number
;
3004 /* empty the table */
3005 dwarf2_empty_abbrev_table (NULL
);
3007 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3008 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3009 abbrev_ptr
+= bytes_read
;
3011 /* loop until we reach an abbrev number of 0 */
3012 while (abbrev_number
)
3014 cur_abbrev
= dwarf_alloc_abbrev ();
3016 /* read in abbrev header */
3017 cur_abbrev
->number
= abbrev_number
;
3018 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3019 abbrev_ptr
+= bytes_read
;
3020 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3023 /* now read in declarations */
3024 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3025 abbrev_ptr
+= bytes_read
;
3026 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3027 abbrev_ptr
+= bytes_read
;
3030 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3032 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3033 xrealloc (cur_abbrev
->attrs
,
3034 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3035 * sizeof (struct attr_abbrev
));
3037 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3038 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3039 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3040 abbrev_ptr
+= bytes_read
;
3041 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3042 abbrev_ptr
+= bytes_read
;
3045 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3046 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3047 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3049 /* Get next abbreviation.
3050 Under Irix6 the abbreviations for a compilation unit are not
3051 always properly terminated with an abbrev number of 0.
3052 Exit loop if we encounter an abbreviation which we have
3053 already read (which means we are about to read the abbreviations
3054 for the next compile unit) or if the end of the abbreviation
3055 table is reached. */
3056 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3057 >= dwarf_abbrev_size
)
3059 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3060 abbrev_ptr
+= bytes_read
;
3061 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3066 /* Empty the abbrev table for a new compilation unit. */
3070 dwarf2_empty_abbrev_table (ignore
)
3074 struct abbrev_info
*abbrev
, *next
;
3076 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3079 abbrev
= dwarf2_abbrevs
[i
];
3082 next
= abbrev
->next
;
3083 free (abbrev
->attrs
);
3087 dwarf2_abbrevs
[i
] = NULL
;
3091 /* Lookup an abbrev_info structure in the abbrev hash table. */
3093 static struct abbrev_info
*
3094 dwarf2_lookup_abbrev (number
)
3095 unsigned int number
;
3097 unsigned int hash_number
;
3098 struct abbrev_info
*abbrev
;
3100 hash_number
= number
% ABBREV_HASH_SIZE
;
3101 abbrev
= dwarf2_abbrevs
[hash_number
];
3105 if (abbrev
->number
== number
)
3108 abbrev
= abbrev
->next
;
3113 /* Read a minimal amount of information into the minimal die structure. */
3116 read_partial_die (part_die
, abfd
, info_ptr
, has_pc_info
)
3117 struct partial_die_info
*part_die
;
3122 unsigned int abbrev_number
, bytes_read
, i
;
3123 struct abbrev_info
*abbrev
;
3124 struct attribute attr
;
3125 struct attribute spec_attr
;
3126 int found_spec_attr
= 0;
3127 int has_low_pc_attr
= 0;
3128 int has_high_pc_attr
= 0;
3130 *part_die
= zeroed_partial_die
;
3132 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3133 info_ptr
+= bytes_read
;
3137 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3140 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3142 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3143 part_die
->tag
= abbrev
->tag
;
3144 part_die
->has_children
= abbrev
->has_children
;
3145 part_die
->abbrev
= abbrev_number
;
3147 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3149 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
);
3151 /* Store the data if it is of an attribute we want to keep in a
3152 partial symbol table. */
3157 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3158 if (part_die
->name
== NULL
)
3159 part_die
->name
= DW_STRING (&attr
);
3161 case DW_AT_MIPS_linkage_name
:
3162 part_die
->name
= DW_STRING (&attr
);
3165 has_low_pc_attr
= 1;
3166 part_die
->lowpc
= DW_ADDR (&attr
);
3169 has_high_pc_attr
= 1;
3170 part_die
->highpc
= DW_ADDR (&attr
);
3172 case DW_AT_location
:
3173 part_die
->locdesc
= DW_BLOCK (&attr
);
3175 case DW_AT_language
:
3176 part_die
->language
= DW_UNSND (&attr
);
3178 case DW_AT_external
:
3179 part_die
->is_external
= DW_UNSND (&attr
);
3181 case DW_AT_declaration
:
3182 part_die
->is_declaration
= DW_UNSND (&attr
);
3185 part_die
->has_type
= 1;
3187 case DW_AT_abstract_origin
:
3188 case DW_AT_specification
:
3189 found_spec_attr
= 1;
3193 /* Ignore absolute siblings, they might point outside of
3194 the current compile unit. */
3195 if (attr
.form
== DW_FORM_ref_addr
)
3196 complain (&dwarf2_absolute_sibling_complaint
);
3199 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3206 /* If we found a reference attribute and the die has no name, try
3207 to find a name in the referred to die. */
3209 if (found_spec_attr
&& part_die
->name
== NULL
)
3211 struct partial_die_info spec_die
;
3215 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3216 read_partial_die (&spec_die
, abfd
, spec_ptr
, &dummy
);
3219 part_die
->name
= spec_die
.name
;
3221 /* Copy DW_AT_external attribute if it is set. */
3222 if (spec_die
.is_external
)
3223 part_die
->is_external
= spec_die
.is_external
;
3227 /* When using the GNU linker, .gnu.linkonce. sections are used to
3228 eliminate duplicate copies of functions and vtables and such.
3229 The linker will arbitrarily choose one and discard the others.
3230 The AT_*_pc values for such functions refer to local labels in
3231 these sections. If the section from that file was discarded, the
3232 labels are not in the output, so the relocs get a value of 0.
3233 If this is a discarded function, mark the pc bounds as invalid,
3234 so that GDB will ignore it. */
3235 if (has_low_pc_attr
&& has_high_pc_attr
3236 && part_die
->lowpc
< part_die
->highpc
3237 && (part_die
->lowpc
!= 0
3238 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3243 /* Read the die from the .debug_info section buffer. And set diep to
3244 point to a newly allocated die with its information. */
3247 read_full_die (diep
, abfd
, info_ptr
)
3248 struct die_info
**diep
;
3252 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3253 struct abbrev_info
*abbrev
;
3254 struct die_info
*die
;
3256 offset
= info_ptr
- dwarf_info_buffer
;
3257 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3258 info_ptr
+= bytes_read
;
3261 die
= dwarf_alloc_die ();
3263 die
->abbrev
= abbrev_number
;
3269 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3272 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3274 die
= dwarf_alloc_die ();
3275 die
->offset
= offset
;
3276 die
->tag
= abbrev
->tag
;
3277 die
->has_children
= abbrev
->has_children
;
3278 die
->abbrev
= abbrev_number
;
3281 die
->num_attrs
= abbrev
->num_attrs
;
3282 die
->attrs
= (struct attribute
*)
3283 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3285 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3287 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3295 /* Read an attribute described by an abbreviated attribute. */
3298 read_attribute (attr
, abbrev
, abfd
, info_ptr
)
3299 struct attribute
*attr
;
3300 struct attr_abbrev
*abbrev
;
3304 unsigned int bytes_read
;
3305 struct dwarf_block
*blk
;
3307 attr
->name
= abbrev
->name
;
3308 attr
->form
= abbrev
->form
;
3309 switch (abbrev
->form
)
3312 case DW_FORM_ref_addr
:
3313 DW_ADDR (attr
) = read_address (abfd
, info_ptr
);
3314 info_ptr
+= address_size
;
3316 case DW_FORM_block2
:
3317 blk
= dwarf_alloc_block ();
3318 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3320 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3321 info_ptr
+= blk
->size
;
3322 DW_BLOCK (attr
) = blk
;
3324 case DW_FORM_block4
:
3325 blk
= dwarf_alloc_block ();
3326 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3328 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3329 info_ptr
+= blk
->size
;
3330 DW_BLOCK (attr
) = blk
;
3333 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3337 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3341 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3344 case DW_FORM_string
:
3345 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3346 info_ptr
+= bytes_read
;
3349 blk
= dwarf_alloc_block ();
3350 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3351 info_ptr
+= bytes_read
;
3352 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3353 info_ptr
+= blk
->size
;
3354 DW_BLOCK (attr
) = blk
;
3356 case DW_FORM_block1
:
3357 blk
= dwarf_alloc_block ();
3358 blk
->size
= read_1_byte (abfd
, info_ptr
);
3360 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3361 info_ptr
+= blk
->size
;
3362 DW_BLOCK (attr
) = blk
;
3365 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3369 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3373 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3374 info_ptr
+= bytes_read
;
3377 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3378 info_ptr
+= bytes_read
;
3381 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3385 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3389 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3392 case DW_FORM_ref_udata
:
3393 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3394 info_ptr
+= bytes_read
;
3397 case DW_FORM_indirect
:
3399 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3400 dwarf_form_name (abbrev
->form
));
3405 /* read dwarf information from a buffer */
3408 read_1_byte (abfd
, buf
)
3412 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3416 read_1_signed_byte (abfd
, buf
)
3420 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3424 read_2_bytes (abfd
, buf
)
3428 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3432 read_2_signed_bytes (abfd
, buf
)
3436 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3440 read_4_bytes (abfd
, buf
)
3444 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3448 read_4_signed_bytes (abfd
, buf
)
3452 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3455 static unsigned long
3456 read_8_bytes (abfd
, buf
)
3460 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3464 read_address (abfd
, buf
)
3468 CORE_ADDR retval
= 0;
3470 switch (address_size
)
3473 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3476 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3479 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3482 /* *THE* alternative is 8, right? */
3490 read_n_bytes (abfd
, buf
, size
)
3495 /* If the size of a host char is 8 bits, we can return a pointer
3496 to the buffer, otherwise we have to copy the data to a buffer
3497 allocated on the temporary obstack. */
3498 #if HOST_CHAR_BIT == 8
3504 ret
= obstack_alloc (&dwarf2_tmp_obstack
, size
);
3505 for (i
= 0; i
< size
; ++i
)
3507 ret
[i
] = bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3515 read_string (abfd
, buf
, bytes_read_ptr
)
3518 unsigned int *bytes_read_ptr
;
3520 /* If the size of a host char is 8 bits, we can return a pointer
3521 to the string, otherwise we have to copy the string to a buffer
3522 allocated on the temporary obstack. */
3523 #if HOST_CHAR_BIT == 8
3526 *bytes_read_ptr
= 1;
3529 *bytes_read_ptr
= strlen (buf
) + 1;
3535 while ((byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
)) != 0)
3537 obstack_1grow (&dwarf2_tmp_obstack
, byte
);
3543 *bytes_read_ptr
= 1;
3546 obstack_1grow (&dwarf2_tmp_obstack
, '\0');
3547 *bytes_read_ptr
= i
+ 1;
3548 return obstack_finish (&dwarf2_tmp_obstack
);
3552 static unsigned long
3553 read_unsigned_leb128 (abfd
, buf
, bytes_read_ptr
)
3556 unsigned int *bytes_read_ptr
;
3558 unsigned long result
;
3559 unsigned int num_read
;
3569 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3572 result
|= ((unsigned long)(byte
& 127) << shift
);
3573 if ((byte
& 128) == 0)
3579 *bytes_read_ptr
= num_read
;
3584 read_signed_leb128 (abfd
, buf
, bytes_read_ptr
)
3587 unsigned int *bytes_read_ptr
;
3590 int i
, shift
, size
, num_read
;
3600 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3603 result
|= ((long)(byte
& 127) << shift
);
3605 if ((byte
& 128) == 0)
3610 if ((shift
< size
) && (byte
& 0x40))
3612 result
|= -(1 << shift
);
3614 *bytes_read_ptr
= num_read
;
3619 set_cu_language (lang
)
3626 cu_language
= language_c
;
3628 case DW_LANG_C_plus_plus
:
3629 cu_language
= language_cplus
;
3631 case DW_LANG_Fortran77
:
3632 case DW_LANG_Fortran90
:
3633 cu_language
= language_fortran
;
3635 case DW_LANG_Mips_Assembler
:
3636 cu_language
= language_asm
;
3639 case DW_LANG_Cobol74
:
3640 case DW_LANG_Cobol85
:
3641 case DW_LANG_Pascal83
:
3642 case DW_LANG_Modula2
:
3644 cu_language
= language_unknown
;
3647 cu_language_defn
= language_def (cu_language
);
3650 /* Return the named attribute or NULL if not there. */
3652 static struct attribute
*
3653 dwarf_attr (die
, name
)
3654 struct die_info
*die
;
3658 struct attribute
*spec
= NULL
;
3660 for (i
= 0; i
< die
->num_attrs
; ++i
)
3662 if (die
->attrs
[i
].name
== name
)
3664 return &die
->attrs
[i
];
3666 if (die
->attrs
[i
].name
== DW_AT_specification
3667 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3668 spec
= &die
->attrs
[i
];
3672 struct die_info
*ref_die
=
3673 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3676 return dwarf_attr (ref_die
, name
);
3683 die_is_declaration (struct die_info
*die
)
3685 return (dwarf_attr (die
, DW_AT_declaration
)
3686 && ! dwarf_attr (die
, DW_AT_specification
));
3689 /* Decode the line number information for the compilation unit whose
3690 line number info is at OFFSET in the .debug_line section.
3691 The compilation directory of the file is passed in COMP_DIR. */
3695 unsigned int num_files
;
3708 unsigned int num_dirs
;
3713 dwarf_decode_lines (offset
, comp_dir
, abfd
)
3714 unsigned int offset
;
3720 struct line_head lh
;
3721 struct cleanup
*back_to
;
3722 unsigned int i
, bytes_read
;
3723 char *cur_file
, *cur_dir
;
3724 unsigned char op_code
, extended_op
, adj_opcode
;
3726 #define FILE_ALLOC_CHUNK 5
3727 #define DIR_ALLOC_CHUNK 5
3729 struct filenames files
;
3730 struct directories dirs
;
3732 if (dwarf_line_buffer
== NULL
)
3734 complain (&dwarf2_missing_line_number_section
);
3738 files
.num_files
= 0;
3744 line_ptr
= dwarf_line_buffer
+ offset
;
3746 /* read in the prologue */
3747 lh
.total_length
= read_4_bytes (abfd
, line_ptr
);
3749 line_end
= line_ptr
+ lh
.total_length
;
3750 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3752 lh
.prologue_length
= read_4_bytes (abfd
, line_ptr
);
3754 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3756 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3758 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3760 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3762 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3764 lh
.standard_opcode_lengths
= (unsigned char *)
3765 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3766 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
3768 lh
.standard_opcode_lengths
[0] = 1;
3769 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3771 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3775 /* Read directory table */
3776 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3778 line_ptr
+= bytes_read
;
3779 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3781 dirs
.dirs
= (char **)
3782 xrealloc (dirs
.dirs
,
3783 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3784 if (dirs
.num_dirs
== 0)
3785 make_cleanup (free_current_contents
, &dirs
.dirs
);
3787 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3789 line_ptr
+= bytes_read
;
3791 /* Read file name table */
3792 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3794 line_ptr
+= bytes_read
;
3795 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3797 files
.files
= (struct fileinfo
*)
3798 xrealloc (files
.files
,
3799 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3800 * sizeof (struct fileinfo
));
3801 if (files
.num_files
== 0)
3802 make_cleanup (free_current_contents
, &files
.files
);
3804 files
.files
[files
.num_files
].name
= cur_file
;
3805 files
.files
[files
.num_files
].dir
=
3806 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3807 line_ptr
+= bytes_read
;
3808 files
.files
[files
.num_files
].time
=
3809 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3810 line_ptr
+= bytes_read
;
3811 files
.files
[files
.num_files
].size
=
3812 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3813 line_ptr
+= bytes_read
;
3816 line_ptr
+= bytes_read
;
3818 /* Read the statement sequences until there's nothing left. */
3819 while (line_ptr
< line_end
)
3821 /* state machine registers */
3822 CORE_ADDR address
= 0;
3823 unsigned int file
= 1;
3824 unsigned int line
= 1;
3825 unsigned int column
= 0;
3826 int is_stmt
= lh
.default_is_stmt
;
3827 int basic_block
= 0;
3828 int end_sequence
= 0;
3830 /* Start a subfile for the current file of the state machine. */
3831 if (files
.num_files
>= file
)
3833 /* The file and directory tables are 0 based, the references
3835 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3836 (files
.files
[file
- 1].dir
3837 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3841 /* Decode the table. */
3842 while (!end_sequence
)
3844 op_code
= read_1_byte (abfd
, line_ptr
);
3848 case DW_LNS_extended_op
:
3849 line_ptr
+= 1; /* ignore length */
3850 extended_op
= read_1_byte (abfd
, line_ptr
);
3852 switch (extended_op
)
3854 case DW_LNE_end_sequence
:
3856 /* Don't call record_line here. The end_sequence
3857 instruction provides the address of the first byte
3858 *after* the last line in the sequence; it's not the
3859 address of any real source line. However, the GDB
3860 linetable structure only records the starts of lines,
3861 not the ends. This is a weakness of GDB. */
3863 case DW_LNE_set_address
:
3864 address
= read_address (abfd
, line_ptr
) + baseaddr
;
3865 line_ptr
+= address_size
;
3867 case DW_LNE_define_file
:
3868 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
3869 line_ptr
+= bytes_read
;
3870 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3872 files
.files
= (struct fileinfo
*)
3873 xrealloc (files
.files
,
3874 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3875 * sizeof (struct fileinfo
));
3876 if (files
.num_files
== 0)
3877 make_cleanup (free_current_contents
, &files
.files
);
3879 files
.files
[files
.num_files
].name
= cur_file
;
3880 files
.files
[files
.num_files
].dir
=
3881 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3882 line_ptr
+= bytes_read
;
3883 files
.files
[files
.num_files
].time
=
3884 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3885 line_ptr
+= bytes_read
;
3886 files
.files
[files
.num_files
].size
=
3887 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3888 line_ptr
+= bytes_read
;
3892 complain (&dwarf2_mangled_line_number_section
);
3897 record_line (current_subfile
, line
, address
);
3900 case DW_LNS_advance_pc
:
3901 address
+= lh
.minimum_instruction_length
3902 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3903 line_ptr
+= bytes_read
;
3905 case DW_LNS_advance_line
:
3906 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
3907 line_ptr
+= bytes_read
;
3909 case DW_LNS_set_file
:
3910 /* The file and directory tables are 0 based, the references
3912 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3913 line_ptr
+= bytes_read
;
3914 dwarf2_start_subfile
3915 (files
.files
[file
- 1].name
,
3916 (files
.files
[file
- 1].dir
3917 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3920 case DW_LNS_set_column
:
3921 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3922 line_ptr
+= bytes_read
;
3924 case DW_LNS_negate_stmt
:
3925 is_stmt
= (!is_stmt
);
3927 case DW_LNS_set_basic_block
:
3930 /* Add to the address register of the state machine the
3931 address increment value corresponding to special opcode
3932 255. Ie, this value is scaled by the minimum instruction
3933 length since special opcode 255 would have scaled the
3935 case DW_LNS_const_add_pc
:
3936 address
+= (lh
.minimum_instruction_length
3937 * ((255 - lh
.opcode_base
) / lh
.line_range
));
3939 case DW_LNS_fixed_advance_pc
:
3940 address
+= read_2_bytes (abfd
, line_ptr
);
3943 default: /* special operand */
3944 adj_opcode
= op_code
- lh
.opcode_base
;
3945 address
+= (adj_opcode
/ lh
.line_range
)
3946 * lh
.minimum_instruction_length
;
3947 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
3948 /* append row to matrix using current values */
3949 record_line (current_subfile
, line
, address
);
3955 do_cleanups (back_to
);
3958 /* Start a subfile for DWARF. FILENAME is the name of the file and
3959 DIRNAME the name of the source directory which contains FILENAME
3960 or NULL if not known.
3961 This routine tries to keep line numbers from identical absolute and
3962 relative file names in a common subfile.
3964 Using the `list' example from the GDB testsuite, which resides in
3965 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
3966 of /srcdir/list0.c yields the following debugging information for list0.c:
3968 DW_AT_name: /srcdir/list0.c
3969 DW_AT_comp_dir: /compdir
3970 files.files[0].name: list0.h
3971 files.files[0].dir: /srcdir
3972 files.files[1].name: list0.c
3973 files.files[1].dir: /srcdir
3975 The line number information for list0.c has to end up in a single
3976 subfile, so that `break /srcdir/list0.c:1' works as expected. */
3979 dwarf2_start_subfile (filename
, dirname
)
3983 /* If the filename isn't absolute, try to match an existing subfile
3984 with the full pathname. */
3986 if (*filename
!= '/' && dirname
!= NULL
)
3988 struct subfile
*subfile
;
3989 char *fullname
= concat (dirname
, "/", filename
, NULL
);
3991 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
3993 if (STREQ (subfile
->name
, fullname
))
3995 current_subfile
= subfile
;
4002 start_subfile (filename
, dirname
);
4005 /* Given a pointer to a DWARF information entry, figure out if we need
4006 to make a symbol table entry for it, and if so, create a new entry
4007 and return a pointer to it.
4008 If TYPE is NULL, determine symbol type from the die, otherwise
4009 used the passed type. */
4011 static struct symbol
*
4012 new_symbol (die
, type
, objfile
)
4013 struct die_info
*die
;
4015 struct objfile
*objfile
;
4017 struct symbol
*sym
= NULL
;
4019 struct attribute
*attr
= NULL
;
4020 struct attribute
*attr2
= NULL
;
4023 name
= dwarf2_linkage_name (die
);
4026 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4027 sizeof (struct symbol
));
4028 OBJSTAT (objfile
, n_syms
++);
4029 memset (sym
, 0, sizeof (struct symbol
));
4030 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4031 &objfile
->symbol_obstack
);
4033 /* Default assumptions.
4034 Use the passed type or decode it from the die. */
4035 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4036 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4038 SYMBOL_TYPE (sym
) = type
;
4040 SYMBOL_TYPE (sym
) = die_type (die
, objfile
);
4041 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4044 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4047 /* If this symbol is from a C++ compilation, then attempt to
4048 cache the demangled form for future reference. This is a
4049 typical time versus space tradeoff, that was decided in favor
4050 of time because it sped up C++ symbol lookups by a factor of
4053 SYMBOL_LANGUAGE (sym
) = cu_language
;
4054 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4058 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4061 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4063 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4065 case DW_TAG_subprogram
:
4066 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4068 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4069 attr2
= dwarf_attr (die
, DW_AT_external
);
4070 if (attr2
&& (DW_UNSND (attr2
) != 0))
4072 add_symbol_to_list (sym
, &global_symbols
);
4076 add_symbol_to_list (sym
, list_in_scope
);
4079 case DW_TAG_variable
:
4080 /* Compilation with minimal debug info may result in variables
4081 with missing type entries. Change the misleading `void' type
4082 to something sensible. */
4083 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4084 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4085 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4086 "<variable, no debug info>",
4088 attr
= dwarf_attr (die
, DW_AT_const_value
);
4091 dwarf2_const_value (attr
, sym
, objfile
);
4092 attr2
= dwarf_attr (die
, DW_AT_external
);
4093 if (attr2
&& (DW_UNSND (attr2
) != 0))
4094 add_symbol_to_list (sym
, &global_symbols
);
4096 add_symbol_to_list (sym
, list_in_scope
);
4099 attr
= dwarf_attr (die
, DW_AT_location
);
4102 attr2
= dwarf_attr (die
, DW_AT_external
);
4103 if (attr2
&& (DW_UNSND (attr2
) != 0))
4105 SYMBOL_VALUE_ADDRESS (sym
) =
4106 decode_locdesc (DW_BLOCK (attr
), objfile
);
4107 add_symbol_to_list (sym
, &global_symbols
);
4109 /* In shared libraries the address of the variable
4110 in the location descriptor might still be relocatable,
4111 so its value could be zero.
4112 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4113 value is zero, the address of the variable will then
4114 be determined from the minimal symbol table whenever
4115 the variable is referenced. */
4116 if (SYMBOL_VALUE_ADDRESS (sym
))
4118 SYMBOL_VALUE_ADDRESS (sym
) += baseaddr
;
4119 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4122 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4126 SYMBOL_VALUE (sym
) = addr
=
4127 decode_locdesc (DW_BLOCK (attr
), objfile
);
4128 add_symbol_to_list (sym
, list_in_scope
);
4131 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4135 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4139 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4140 SYMBOL_BASEREG (sym
) = basereg
;
4144 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4148 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4149 SYMBOL_VALUE_ADDRESS (sym
) = addr
+ baseaddr
;
4155 /* We do not know the address of this symbol.
4156 If it is an external symbol and we have type information
4157 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4158 The address of the variable will then be determined from
4159 the minimal symbol table whenever the variable is
4161 attr2
= dwarf_attr (die
, DW_AT_external
);
4162 if (attr2
&& (DW_UNSND (attr2
) != 0)
4163 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4165 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4166 add_symbol_to_list (sym
, &global_symbols
);
4170 case DW_TAG_formal_parameter
:
4171 attr
= dwarf_attr (die
, DW_AT_location
);
4174 SYMBOL_VALUE (sym
) = decode_locdesc (DW_BLOCK (attr
), objfile
);
4177 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4183 if (basereg
!= frame_base_reg
)
4184 complain (&dwarf2_complex_location_expr
);
4185 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4189 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4190 SYMBOL_BASEREG (sym
) = basereg
;
4195 SYMBOL_CLASS (sym
) = LOC_ARG
;
4198 attr
= dwarf_attr (die
, DW_AT_const_value
);
4201 dwarf2_const_value (attr
, sym
, objfile
);
4203 add_symbol_to_list (sym
, list_in_scope
);
4205 case DW_TAG_unspecified_parameters
:
4206 /* From varargs functions; gdb doesn't seem to have any
4207 interest in this information, so just ignore it for now.
4210 case DW_TAG_class_type
:
4211 case DW_TAG_structure_type
:
4212 case DW_TAG_union_type
:
4213 case DW_TAG_enumeration_type
:
4214 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4215 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4216 add_symbol_to_list (sym
, list_in_scope
);
4218 /* The semantics of C++ state that "struct foo { ... }" also
4219 defines a typedef for "foo". Synthesize a typedef symbol so
4220 that "ptype foo" works as expected. */
4221 if (cu_language
== language_cplus
)
4223 struct symbol
*typedef_sym
= (struct symbol
*)
4224 obstack_alloc (&objfile
->symbol_obstack
,
4225 sizeof (struct symbol
));
4226 *typedef_sym
= *sym
;
4227 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4228 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4229 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4230 obsavestring (SYMBOL_NAME (sym
),
4231 strlen (SYMBOL_NAME (sym
)),
4232 &objfile
->type_obstack
);
4233 add_symbol_to_list (typedef_sym
, list_in_scope
);
4236 case DW_TAG_typedef
:
4237 case DW_TAG_base_type
:
4238 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4239 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4240 add_symbol_to_list (sym
, list_in_scope
);
4242 case DW_TAG_enumerator
:
4243 attr
= dwarf_attr (die
, DW_AT_const_value
);
4246 dwarf2_const_value (attr
, sym
, objfile
);
4248 add_symbol_to_list (sym
, list_in_scope
);
4251 /* Not a tag we recognize. Hopefully we aren't processing
4252 trash data, but since we must specifically ignore things
4253 we don't recognize, there is nothing else we should do at
4255 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4262 /* Copy constant value from an attribute to a symbol. */
4265 dwarf2_const_value (attr
, sym
, objfile
)
4266 struct attribute
*attr
;
4268 struct objfile
*objfile
;
4270 struct dwarf_block
*blk
;
4275 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != (unsigned int) address_size
)
4276 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4277 address_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4278 SYMBOL_VALUE_BYTES (sym
) = (char *)
4279 obstack_alloc (&objfile
->symbol_obstack
, address_size
);
4280 store_address (SYMBOL_VALUE_BYTES (sym
), address_size
, DW_ADDR (attr
));
4281 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4283 case DW_FORM_block1
:
4284 case DW_FORM_block2
:
4285 case DW_FORM_block4
:
4287 blk
= DW_BLOCK (attr
);
4288 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4289 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4290 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4291 SYMBOL_VALUE_BYTES (sym
) = (char *)
4292 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4293 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4294 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4297 /* The DW_AT_const_value attributes are supposed to carry the
4298 symbol's value "represented as it would be on the target
4299 architecture." By the time we get here, it's already been
4300 converted to host endianness, so we just need to sign- or
4301 zero-extend it as appropriate. */
4303 dwarf2_const_value_data (attr
, sym
, 8);
4306 dwarf2_const_value_data (attr
, sym
, 16);
4309 dwarf2_const_value_data (attr
, sym
, 32);
4312 dwarf2_const_value_data (attr
, sym
, 64);
4316 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4317 SYMBOL_CLASS (sym
) = LOC_CONST
;
4321 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4322 SYMBOL_CLASS (sym
) = LOC_CONST
;
4326 complain (&dwarf2_unsupported_const_value_attr
,
4327 dwarf_form_name (attr
->form
));
4328 SYMBOL_VALUE (sym
) = 0;
4329 SYMBOL_CLASS (sym
) = LOC_CONST
;
4335 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4336 or zero-extend it as appropriate for the symbol's type. */
4338 dwarf2_const_value_data (struct attribute
*attr
,
4342 LONGEST l
= DW_UNSND (attr
);
4344 if (bits
< sizeof (l
) * 8)
4346 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4347 l
&= ((LONGEST
) 1 << bits
) - 1;
4349 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4352 SYMBOL_VALUE (sym
) = l
;
4353 SYMBOL_CLASS (sym
) = LOC_CONST
;
4357 /* Return the type of the die in question using its DW_AT_type attribute. */
4359 static struct type
*
4360 die_type (die
, objfile
)
4361 struct die_info
*die
;
4362 struct objfile
*objfile
;
4365 struct attribute
*type_attr
;
4366 struct die_info
*type_die
;
4369 type_attr
= dwarf_attr (die
, DW_AT_type
);
4372 /* A missing DW_AT_type represents a void type. */
4373 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4377 ref
= dwarf2_get_ref_die_offset (type_attr
);
4378 type_die
= follow_die_ref (ref
);
4381 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4385 type
= tag_type_to_type (type_die
, objfile
);
4388 dump_die (type_die
);
4389 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4394 /* Return the containing type of the die in question using its
4395 DW_AT_containing_type attribute. */
4397 static struct type
*
4398 die_containing_type (die
, objfile
)
4399 struct die_info
*die
;
4400 struct objfile
*objfile
;
4402 struct type
*type
= NULL
;
4403 struct attribute
*type_attr
;
4404 struct die_info
*type_die
= NULL
;
4407 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4410 ref
= dwarf2_get_ref_die_offset (type_attr
);
4411 type_die
= follow_die_ref (ref
);
4414 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4417 type
= tag_type_to_type (type_die
, objfile
);
4422 dump_die (type_die
);
4423 error ("Dwarf Error: Problem turning containing type into gdb type.");
4429 static struct type
*
4430 type_at_offset (offset
, objfile
)
4431 unsigned int offset
;
4432 struct objfile
*objfile
;
4434 struct die_info
*die
;
4437 die
= follow_die_ref (offset
);
4440 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4443 type
= tag_type_to_type (die
, objfile
);
4448 static struct type
*
4449 tag_type_to_type (die
, objfile
)
4450 struct die_info
*die
;
4451 struct objfile
*objfile
;
4459 struct attribute
*attr
;
4460 attr
= dwarf_attr (die
, DW_AT_name
);
4461 if (attr
&& DW_STRING (attr
))
4463 char *attrname
=DW_STRING (attr
);
4464 unsigned long hashval
=hash(attrname
, strlen(attrname
)) % TYPE_HASH_SIZE
;
4466 if (dwarf2_cached_types
[hashval
] != NULL
)
4468 const char *nameoftype
;
4469 nameoftype
= TYPE_NAME(dwarf2_cached_types
[hashval
]) == NULL
? TYPE_TAG_NAME(dwarf2_cached_types
[hashval
]) : TYPE_NAME(dwarf2_cached_types
[hashval
]);
4470 if (strcmp(attrname
, nameoftype
) == 0)
4472 die
->type
=dwarf2_cached_types
[hashval
];
4476 read_type_die (die
, objfile
);
4477 dwarf2_cached_types
[hashval
] = die
->type
;
4482 read_type_die (die
, objfile
);
4483 dwarf2_cached_types
[hashval
] = die
->type
;
4488 read_type_die (die
, objfile
);
4494 error ("Dwarf Error: Cannot find type of die.");
4501 read_type_die (die
, objfile
)
4502 struct die_info
*die
;
4503 struct objfile
*objfile
;
4507 case DW_TAG_class_type
:
4508 case DW_TAG_structure_type
:
4509 case DW_TAG_union_type
:
4510 read_structure_scope (die
, objfile
);
4512 case DW_TAG_enumeration_type
:
4513 read_enumeration (die
, objfile
);
4515 case DW_TAG_subprogram
:
4516 case DW_TAG_subroutine_type
:
4517 read_subroutine_type (die
, objfile
);
4519 case DW_TAG_array_type
:
4520 read_array_type (die
, objfile
);
4522 case DW_TAG_pointer_type
:
4523 read_tag_pointer_type (die
, objfile
);
4525 case DW_TAG_ptr_to_member_type
:
4526 read_tag_ptr_to_member_type (die
, objfile
);
4528 case DW_TAG_reference_type
:
4529 read_tag_reference_type (die
, objfile
);
4531 case DW_TAG_const_type
:
4532 read_tag_const_type (die
, objfile
);
4534 case DW_TAG_volatile_type
:
4535 read_tag_volatile_type (die
, objfile
);
4537 case DW_TAG_string_type
:
4538 read_tag_string_type (die
, objfile
);
4540 case DW_TAG_typedef
:
4541 read_typedef (die
, objfile
);
4543 case DW_TAG_base_type
:
4544 read_base_type (die
, objfile
);
4547 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4552 static struct type
*
4553 dwarf_base_type (encoding
, size
, objfile
)
4556 struct objfile
*objfile
;
4558 /* FIXME - this should not produce a new (struct type *)
4559 every time. It should cache base types. */
4563 case DW_ATE_address
:
4564 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4566 case DW_ATE_boolean
:
4567 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4569 case DW_ATE_complex_float
:
4572 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4576 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4582 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4586 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4593 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4596 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4600 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4604 case DW_ATE_signed_char
:
4605 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4607 case DW_ATE_unsigned
:
4611 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4614 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4618 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4622 case DW_ATE_unsigned_char
:
4623 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4626 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4634 struct die_info
*old_die
;
4636 struct die_info
*new_die
;
4639 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4640 memset (new_die
, 0, sizeof (struct die_info
));
4642 new_die
->tag
= old_die
->tag
;
4643 new_die
->has_children
= old_die
->has_children
;
4644 new_die
->abbrev
= old_die
->abbrev
;
4645 new_die
->offset
= old_die
->offset
;
4646 new_die
->type
= NULL
;
4648 num_attrs
= old_die
->num_attrs
;
4649 new_die
->num_attrs
= num_attrs
;
4650 new_die
->attrs
= (struct attribute
*)
4651 xmalloc (num_attrs
* sizeof (struct attribute
));
4653 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4655 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4656 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4657 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4660 new_die
->next
= NULL
;
4665 /* Return sibling of die, NULL if no sibling. */
4669 struct die_info
*die
;
4671 int nesting_level
= 0;
4673 if (!die
->has_children
)
4675 if (die
->next
&& (die
->next
->tag
== 0))
4688 if (die
->has_children
)
4698 while (nesting_level
);
4699 if (die
&& (die
->tag
== 0))
4710 /* Get linkage name of a die, return NULL if not found. */
4713 dwarf2_linkage_name (die
)
4714 struct die_info
*die
;
4716 struct attribute
*attr
;
4718 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4719 if (attr
&& DW_STRING (attr
))
4720 return DW_STRING (attr
);
4721 attr
= dwarf_attr (die
, DW_AT_name
);
4722 if (attr
&& DW_STRING (attr
))
4723 return DW_STRING (attr
);
4727 /* Convert a DIE tag into its string name. */
4730 dwarf_tag_name (tag
)
4731 register unsigned tag
;
4735 case DW_TAG_padding
:
4736 return "DW_TAG_padding";
4737 case DW_TAG_array_type
:
4738 return "DW_TAG_array_type";
4739 case DW_TAG_class_type
:
4740 return "DW_TAG_class_type";
4741 case DW_TAG_entry_point
:
4742 return "DW_TAG_entry_point";
4743 case DW_TAG_enumeration_type
:
4744 return "DW_TAG_enumeration_type";
4745 case DW_TAG_formal_parameter
:
4746 return "DW_TAG_formal_parameter";
4747 case DW_TAG_imported_declaration
:
4748 return "DW_TAG_imported_declaration";
4750 return "DW_TAG_label";
4751 case DW_TAG_lexical_block
:
4752 return "DW_TAG_lexical_block";
4754 return "DW_TAG_member";
4755 case DW_TAG_pointer_type
:
4756 return "DW_TAG_pointer_type";
4757 case DW_TAG_reference_type
:
4758 return "DW_TAG_reference_type";
4759 case DW_TAG_compile_unit
:
4760 return "DW_TAG_compile_unit";
4761 case DW_TAG_string_type
:
4762 return "DW_TAG_string_type";
4763 case DW_TAG_structure_type
:
4764 return "DW_TAG_structure_type";
4765 case DW_TAG_subroutine_type
:
4766 return "DW_TAG_subroutine_type";
4767 case DW_TAG_typedef
:
4768 return "DW_TAG_typedef";
4769 case DW_TAG_union_type
:
4770 return "DW_TAG_union_type";
4771 case DW_TAG_unspecified_parameters
:
4772 return "DW_TAG_unspecified_parameters";
4773 case DW_TAG_variant
:
4774 return "DW_TAG_variant";
4775 case DW_TAG_common_block
:
4776 return "DW_TAG_common_block";
4777 case DW_TAG_common_inclusion
:
4778 return "DW_TAG_common_inclusion";
4779 case DW_TAG_inheritance
:
4780 return "DW_TAG_inheritance";
4781 case DW_TAG_inlined_subroutine
:
4782 return "DW_TAG_inlined_subroutine";
4784 return "DW_TAG_module";
4785 case DW_TAG_ptr_to_member_type
:
4786 return "DW_TAG_ptr_to_member_type";
4787 case DW_TAG_set_type
:
4788 return "DW_TAG_set_type";
4789 case DW_TAG_subrange_type
:
4790 return "DW_TAG_subrange_type";
4791 case DW_TAG_with_stmt
:
4792 return "DW_TAG_with_stmt";
4793 case DW_TAG_access_declaration
:
4794 return "DW_TAG_access_declaration";
4795 case DW_TAG_base_type
:
4796 return "DW_TAG_base_type";
4797 case DW_TAG_catch_block
:
4798 return "DW_TAG_catch_block";
4799 case DW_TAG_const_type
:
4800 return "DW_TAG_const_type";
4801 case DW_TAG_constant
:
4802 return "DW_TAG_constant";
4803 case DW_TAG_enumerator
:
4804 return "DW_TAG_enumerator";
4805 case DW_TAG_file_type
:
4806 return "DW_TAG_file_type";
4808 return "DW_TAG_friend";
4809 case DW_TAG_namelist
:
4810 return "DW_TAG_namelist";
4811 case DW_TAG_namelist_item
:
4812 return "DW_TAG_namelist_item";
4813 case DW_TAG_packed_type
:
4814 return "DW_TAG_packed_type";
4815 case DW_TAG_subprogram
:
4816 return "DW_TAG_subprogram";
4817 case DW_TAG_template_type_param
:
4818 return "DW_TAG_template_type_param";
4819 case DW_TAG_template_value_param
:
4820 return "DW_TAG_template_value_param";
4821 case DW_TAG_thrown_type
:
4822 return "DW_TAG_thrown_type";
4823 case DW_TAG_try_block
:
4824 return "DW_TAG_try_block";
4825 case DW_TAG_variant_part
:
4826 return "DW_TAG_variant_part";
4827 case DW_TAG_variable
:
4828 return "DW_TAG_variable";
4829 case DW_TAG_volatile_type
:
4830 return "DW_TAG_volatile_type";
4831 case DW_TAG_MIPS_loop
:
4832 return "DW_TAG_MIPS_loop";
4833 case DW_TAG_format_label
:
4834 return "DW_TAG_format_label";
4835 case DW_TAG_function_template
:
4836 return "DW_TAG_function_template";
4837 case DW_TAG_class_template
:
4838 return "DW_TAG_class_template";
4840 return "DW_TAG_<unknown>";
4844 /* Convert a DWARF attribute code into its string name. */
4847 dwarf_attr_name (attr
)
4848 register unsigned attr
;
4853 return "DW_AT_sibling";
4854 case DW_AT_location
:
4855 return "DW_AT_location";
4857 return "DW_AT_name";
4858 case DW_AT_ordering
:
4859 return "DW_AT_ordering";
4860 case DW_AT_subscr_data
:
4861 return "DW_AT_subscr_data";
4862 case DW_AT_byte_size
:
4863 return "DW_AT_byte_size";
4864 case DW_AT_bit_offset
:
4865 return "DW_AT_bit_offset";
4866 case DW_AT_bit_size
:
4867 return "DW_AT_bit_size";
4868 case DW_AT_element_list
:
4869 return "DW_AT_element_list";
4870 case DW_AT_stmt_list
:
4871 return "DW_AT_stmt_list";
4873 return "DW_AT_low_pc";
4875 return "DW_AT_high_pc";
4876 case DW_AT_language
:
4877 return "DW_AT_language";
4879 return "DW_AT_member";
4881 return "DW_AT_discr";
4882 case DW_AT_discr_value
:
4883 return "DW_AT_discr_value";
4884 case DW_AT_visibility
:
4885 return "DW_AT_visibility";
4887 return "DW_AT_import";
4888 case DW_AT_string_length
:
4889 return "DW_AT_string_length";
4890 case DW_AT_common_reference
:
4891 return "DW_AT_common_reference";
4892 case DW_AT_comp_dir
:
4893 return "DW_AT_comp_dir";
4894 case DW_AT_const_value
:
4895 return "DW_AT_const_value";
4896 case DW_AT_containing_type
:
4897 return "DW_AT_containing_type";
4898 case DW_AT_default_value
:
4899 return "DW_AT_default_value";
4901 return "DW_AT_inline";
4902 case DW_AT_is_optional
:
4903 return "DW_AT_is_optional";
4904 case DW_AT_lower_bound
:
4905 return "DW_AT_lower_bound";
4906 case DW_AT_producer
:
4907 return "DW_AT_producer";
4908 case DW_AT_prototyped
:
4909 return "DW_AT_prototyped";
4910 case DW_AT_return_addr
:
4911 return "DW_AT_return_addr";
4912 case DW_AT_start_scope
:
4913 return "DW_AT_start_scope";
4914 case DW_AT_stride_size
:
4915 return "DW_AT_stride_size";
4916 case DW_AT_upper_bound
:
4917 return "DW_AT_upper_bound";
4918 case DW_AT_abstract_origin
:
4919 return "DW_AT_abstract_origin";
4920 case DW_AT_accessibility
:
4921 return "DW_AT_accessibility";
4922 case DW_AT_address_class
:
4923 return "DW_AT_address_class";
4924 case DW_AT_artificial
:
4925 return "DW_AT_artificial";
4926 case DW_AT_base_types
:
4927 return "DW_AT_base_types";
4928 case DW_AT_calling_convention
:
4929 return "DW_AT_calling_convention";
4931 return "DW_AT_count";
4932 case DW_AT_data_member_location
:
4933 return "DW_AT_data_member_location";
4934 case DW_AT_decl_column
:
4935 return "DW_AT_decl_column";
4936 case DW_AT_decl_file
:
4937 return "DW_AT_decl_file";
4938 case DW_AT_decl_line
:
4939 return "DW_AT_decl_line";
4940 case DW_AT_declaration
:
4941 return "DW_AT_declaration";
4942 case DW_AT_discr_list
:
4943 return "DW_AT_discr_list";
4944 case DW_AT_encoding
:
4945 return "DW_AT_encoding";
4946 case DW_AT_external
:
4947 return "DW_AT_external";
4948 case DW_AT_frame_base
:
4949 return "DW_AT_frame_base";
4951 return "DW_AT_friend";
4952 case DW_AT_identifier_case
:
4953 return "DW_AT_identifier_case";
4954 case DW_AT_macro_info
:
4955 return "DW_AT_macro_info";
4956 case DW_AT_namelist_items
:
4957 return "DW_AT_namelist_items";
4958 case DW_AT_priority
:
4959 return "DW_AT_priority";
4961 return "DW_AT_segment";
4962 case DW_AT_specification
:
4963 return "DW_AT_specification";
4964 case DW_AT_static_link
:
4965 return "DW_AT_static_link";
4967 return "DW_AT_type";
4968 case DW_AT_use_location
:
4969 return "DW_AT_use_location";
4970 case DW_AT_variable_parameter
:
4971 return "DW_AT_variable_parameter";
4972 case DW_AT_virtuality
:
4973 return "DW_AT_virtuality";
4974 case DW_AT_vtable_elem_location
:
4975 return "DW_AT_vtable_elem_location";
4978 case DW_AT_MIPS_fde
:
4979 return "DW_AT_MIPS_fde";
4980 case DW_AT_MIPS_loop_begin
:
4981 return "DW_AT_MIPS_loop_begin";
4982 case DW_AT_MIPS_tail_loop_begin
:
4983 return "DW_AT_MIPS_tail_loop_begin";
4984 case DW_AT_MIPS_epilog_begin
:
4985 return "DW_AT_MIPS_epilog_begin";
4986 case DW_AT_MIPS_loop_unroll_factor
:
4987 return "DW_AT_MIPS_loop_unroll_factor";
4988 case DW_AT_MIPS_software_pipeline_depth
:
4989 return "DW_AT_MIPS_software_pipeline_depth";
4990 case DW_AT_MIPS_linkage_name
:
4991 return "DW_AT_MIPS_linkage_name";
4994 case DW_AT_sf_names
:
4995 return "DW_AT_sf_names";
4996 case DW_AT_src_info
:
4997 return "DW_AT_src_info";
4998 case DW_AT_mac_info
:
4999 return "DW_AT_mac_info";
5000 case DW_AT_src_coords
:
5001 return "DW_AT_src_coords";
5002 case DW_AT_body_begin
:
5003 return "DW_AT_body_begin";
5004 case DW_AT_body_end
:
5005 return "DW_AT_body_end";
5007 return "DW_AT_<unknown>";
5011 /* Convert a DWARF value form code into its string name. */
5014 dwarf_form_name (form
)
5015 register unsigned form
;
5020 return "DW_FORM_addr";
5021 case DW_FORM_block2
:
5022 return "DW_FORM_block2";
5023 case DW_FORM_block4
:
5024 return "DW_FORM_block4";
5026 return "DW_FORM_data2";
5028 return "DW_FORM_data4";
5030 return "DW_FORM_data8";
5031 case DW_FORM_string
:
5032 return "DW_FORM_string";
5034 return "DW_FORM_block";
5035 case DW_FORM_block1
:
5036 return "DW_FORM_block1";
5038 return "DW_FORM_data1";
5040 return "DW_FORM_flag";
5042 return "DW_FORM_sdata";
5044 return "DW_FORM_strp";
5046 return "DW_FORM_udata";
5047 case DW_FORM_ref_addr
:
5048 return "DW_FORM_ref_addr";
5050 return "DW_FORM_ref1";
5052 return "DW_FORM_ref2";
5054 return "DW_FORM_ref4";
5056 return "DW_FORM_ref8";
5057 case DW_FORM_ref_udata
:
5058 return "DW_FORM_ref_udata";
5059 case DW_FORM_indirect
:
5060 return "DW_FORM_indirect";
5062 return "DW_FORM_<unknown>";
5066 /* Convert a DWARF stack opcode into its string name. */
5069 dwarf_stack_op_name (op
)
5070 register unsigned op
;
5075 return "DW_OP_addr";
5077 return "DW_OP_deref";
5079 return "DW_OP_const1u";
5081 return "DW_OP_const1s";
5083 return "DW_OP_const2u";
5085 return "DW_OP_const2s";
5087 return "DW_OP_const4u";
5089 return "DW_OP_const4s";
5091 return "DW_OP_const8u";
5093 return "DW_OP_const8s";
5095 return "DW_OP_constu";
5097 return "DW_OP_consts";
5101 return "DW_OP_drop";
5103 return "DW_OP_over";
5105 return "DW_OP_pick";
5107 return "DW_OP_swap";
5111 return "DW_OP_xderef";
5119 return "DW_OP_minus";
5131 return "DW_OP_plus";
5132 case DW_OP_plus_uconst
:
5133 return "DW_OP_plus_uconst";
5139 return "DW_OP_shra";
5157 return "DW_OP_skip";
5159 return "DW_OP_lit0";
5161 return "DW_OP_lit1";
5163 return "DW_OP_lit2";
5165 return "DW_OP_lit3";
5167 return "DW_OP_lit4";
5169 return "DW_OP_lit5";
5171 return "DW_OP_lit6";
5173 return "DW_OP_lit7";
5175 return "DW_OP_lit8";
5177 return "DW_OP_lit9";
5179 return "DW_OP_lit10";
5181 return "DW_OP_lit11";
5183 return "DW_OP_lit12";
5185 return "DW_OP_lit13";
5187 return "DW_OP_lit14";
5189 return "DW_OP_lit15";
5191 return "DW_OP_lit16";
5193 return "DW_OP_lit17";
5195 return "DW_OP_lit18";
5197 return "DW_OP_lit19";
5199 return "DW_OP_lit20";
5201 return "DW_OP_lit21";
5203 return "DW_OP_lit22";
5205 return "DW_OP_lit23";
5207 return "DW_OP_lit24";
5209 return "DW_OP_lit25";
5211 return "DW_OP_lit26";
5213 return "DW_OP_lit27";
5215 return "DW_OP_lit28";
5217 return "DW_OP_lit29";
5219 return "DW_OP_lit30";
5221 return "DW_OP_lit31";
5223 return "DW_OP_reg0";
5225 return "DW_OP_reg1";
5227 return "DW_OP_reg2";
5229 return "DW_OP_reg3";
5231 return "DW_OP_reg4";
5233 return "DW_OP_reg5";
5235 return "DW_OP_reg6";
5237 return "DW_OP_reg7";
5239 return "DW_OP_reg8";
5241 return "DW_OP_reg9";
5243 return "DW_OP_reg10";
5245 return "DW_OP_reg11";
5247 return "DW_OP_reg12";
5249 return "DW_OP_reg13";
5251 return "DW_OP_reg14";
5253 return "DW_OP_reg15";
5255 return "DW_OP_reg16";
5257 return "DW_OP_reg17";
5259 return "DW_OP_reg18";
5261 return "DW_OP_reg19";
5263 return "DW_OP_reg20";
5265 return "DW_OP_reg21";
5267 return "DW_OP_reg22";
5269 return "DW_OP_reg23";
5271 return "DW_OP_reg24";
5273 return "DW_OP_reg25";
5275 return "DW_OP_reg26";
5277 return "DW_OP_reg27";
5279 return "DW_OP_reg28";
5281 return "DW_OP_reg29";
5283 return "DW_OP_reg30";
5285 return "DW_OP_reg31";
5287 return "DW_OP_breg0";
5289 return "DW_OP_breg1";
5291 return "DW_OP_breg2";
5293 return "DW_OP_breg3";
5295 return "DW_OP_breg4";
5297 return "DW_OP_breg5";
5299 return "DW_OP_breg6";
5301 return "DW_OP_breg7";
5303 return "DW_OP_breg8";
5305 return "DW_OP_breg9";
5307 return "DW_OP_breg10";
5309 return "DW_OP_breg11";
5311 return "DW_OP_breg12";
5313 return "DW_OP_breg13";
5315 return "DW_OP_breg14";
5317 return "DW_OP_breg15";
5319 return "DW_OP_breg16";
5321 return "DW_OP_breg17";
5323 return "DW_OP_breg18";
5325 return "DW_OP_breg19";
5327 return "DW_OP_breg20";
5329 return "DW_OP_breg21";
5331 return "DW_OP_breg22";
5333 return "DW_OP_breg23";
5335 return "DW_OP_breg24";
5337 return "DW_OP_breg25";
5339 return "DW_OP_breg26";
5341 return "DW_OP_breg27";
5343 return "DW_OP_breg28";
5345 return "DW_OP_breg29";
5347 return "DW_OP_breg30";
5349 return "DW_OP_breg31";
5351 return "DW_OP_regx";
5353 return "DW_OP_fbreg";
5355 return "DW_OP_bregx";
5357 return "DW_OP_piece";
5358 case DW_OP_deref_size
:
5359 return "DW_OP_deref_size";
5360 case DW_OP_xderef_size
:
5361 return "DW_OP_xderef_size";
5365 return "OP_<unknown>";
5370 dwarf_bool_name (mybool
)
5379 /* Convert a DWARF type code into its string name. */
5382 dwarf_type_encoding_name (enc
)
5383 register unsigned enc
;
5387 case DW_ATE_address
:
5388 return "DW_ATE_address";
5389 case DW_ATE_boolean
:
5390 return "DW_ATE_boolean";
5391 case DW_ATE_complex_float
:
5392 return "DW_ATE_complex_float";
5394 return "DW_ATE_float";
5396 return "DW_ATE_signed";
5397 case DW_ATE_signed_char
:
5398 return "DW_ATE_signed_char";
5399 case DW_ATE_unsigned
:
5400 return "DW_ATE_unsigned";
5401 case DW_ATE_unsigned_char
:
5402 return "DW_ATE_unsigned_char";
5404 return "DW_ATE_<unknown>";
5408 /* Convert a DWARF call frame info operation to its string name. */
5412 dwarf_cfi_name (cfi_opc
)
5413 register unsigned cfi_opc
;
5417 case DW_CFA_advance_loc
:
5418 return "DW_CFA_advance_loc";
5420 return "DW_CFA_offset";
5421 case DW_CFA_restore
:
5422 return "DW_CFA_restore";
5424 return "DW_CFA_nop";
5425 case DW_CFA_set_loc
:
5426 return "DW_CFA_set_loc";
5427 case DW_CFA_advance_loc1
:
5428 return "DW_CFA_advance_loc1";
5429 case DW_CFA_advance_loc2
:
5430 return "DW_CFA_advance_loc2";
5431 case DW_CFA_advance_loc4
:
5432 return "DW_CFA_advance_loc4";
5433 case DW_CFA_offset_extended
:
5434 return "DW_CFA_offset_extended";
5435 case DW_CFA_restore_extended
:
5436 return "DW_CFA_restore_extended";
5437 case DW_CFA_undefined
:
5438 return "DW_CFA_undefined";
5439 case DW_CFA_same_value
:
5440 return "DW_CFA_same_value";
5441 case DW_CFA_register
:
5442 return "DW_CFA_register";
5443 case DW_CFA_remember_state
:
5444 return "DW_CFA_remember_state";
5445 case DW_CFA_restore_state
:
5446 return "DW_CFA_restore_state";
5447 case DW_CFA_def_cfa
:
5448 return "DW_CFA_def_cfa";
5449 case DW_CFA_def_cfa_register
:
5450 return "DW_CFA_def_cfa_register";
5451 case DW_CFA_def_cfa_offset
:
5452 return "DW_CFA_def_cfa_offset";
5453 /* SGI/MIPS specific */
5454 case DW_CFA_MIPS_advance_loc8
:
5455 return "DW_CFA_MIPS_advance_loc8";
5457 return "DW_CFA_<unknown>";
5464 struct die_info
*die
;
5468 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5469 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5470 fprintf (stderr
, "\thas children: %s\n",
5471 dwarf_bool_name (die
->has_children
));
5473 fprintf (stderr
, "\tattributes:\n");
5474 for (i
= 0; i
< die
->num_attrs
; ++i
)
5476 fprintf (stderr
, "\t\t%s (%s) ",
5477 dwarf_attr_name (die
->attrs
[i
].name
),
5478 dwarf_form_name (die
->attrs
[i
].form
));
5479 switch (die
->attrs
[i
].form
)
5481 case DW_FORM_ref_addr
:
5483 fprintf (stderr
, "address: ");
5484 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5486 case DW_FORM_block2
:
5487 case DW_FORM_block4
:
5489 case DW_FORM_block1
:
5490 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5501 fprintf (stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
5503 case DW_FORM_string
:
5504 fprintf (stderr
, "string: \"%s\"",
5505 DW_STRING (&die
->attrs
[i
])
5506 ? DW_STRING (&die
->attrs
[i
]) : "");
5509 if (DW_UNSND (&die
->attrs
[i
]))
5510 fprintf (stderr
, "flag: TRUE");
5512 fprintf (stderr
, "flag: FALSE");
5514 case DW_FORM_strp
: /* we do not support separate string
5516 case DW_FORM_indirect
: /* we do not handle indirect yet */
5518 fprintf (stderr
, "unsupported attribute form: %d.",
5519 die
->attrs
[i
].form
);
5521 fprintf (stderr
, "\n");
5527 struct die_info
*die
;
5537 store_in_ref_table (offset
, die
)
5538 unsigned int offset
;
5539 struct die_info
*die
;
5542 struct die_info
*old
;
5544 h
= (offset
% REF_HASH_SIZE
);
5545 old
= die_ref_table
[h
];
5546 die
->next_ref
= old
;
5547 die_ref_table
[h
] = die
;
5552 dwarf2_empty_die_ref_table ()
5554 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5558 dwarf2_get_ref_die_offset (attr
)
5559 struct attribute
*attr
;
5561 unsigned int result
= 0;
5565 case DW_FORM_ref_addr
:
5566 result
= DW_ADDR (attr
);
5571 case DW_FORM_ref_udata
:
5572 result
= cu_header_offset
+ DW_UNSND (attr
);
5575 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5581 follow_die_ref (offset
)
5582 unsigned int offset
;
5584 struct die_info
*die
;
5587 h
= (offset
% REF_HASH_SIZE
);
5588 die
= die_ref_table
[h
];
5591 if (die
->offset
== offset
)
5595 die
= die
->next_ref
;
5600 static struct type
*
5601 dwarf2_fundamental_type (objfile
, typeid)
5602 struct objfile
*objfile
;
5605 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5607 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5611 /* Look for this particular type in the fundamental type vector. If
5612 one is not found, create and install one appropriate for the
5613 current language and the current target machine. */
5615 if (ftypes
[typeid] == NULL
)
5617 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5620 return (ftypes
[typeid]);
5623 /* Decode simple location descriptions.
5624 Given a pointer to a dwarf block that defines a location, compute
5625 the location and return the value.
5627 FIXME: This is a kludge until we figure out a better
5628 way to handle the location descriptions.
5629 Gdb's design does not mesh well with the DWARF2 notion of a location
5630 computing interpreter, which is a shame because the flexibility goes unused.
5631 FIXME: Implement more operations as necessary.
5633 A location description containing no operations indicates that the
5634 object is optimized out. The global optimized_out flag is set for
5635 those, the return value is meaningless.
5637 When the result is a register number, the global isreg flag is set,
5638 otherwise it is cleared.
5640 When the result is a base register offset, the global offreg flag is set
5641 and the register number is returned in basereg, otherwise it is cleared.
5643 When the DW_OP_fbreg operation is encountered without a corresponding
5644 DW_AT_frame_base attribute, the global islocal flag is set.
5645 Hopefully the machine dependent code knows how to set up a virtual
5646 frame pointer for the local references.
5648 Note that stack[0] is unused except as a default error return.
5649 Note that stack overflow is not yet handled. */
5652 decode_locdesc (blk
, objfile
)
5653 struct dwarf_block
*blk
;
5654 struct objfile
*objfile
;
5657 int size
= blk
->size
;
5658 char *data
= blk
->data
;
5659 CORE_ADDR stack
[64];
5661 unsigned int bytes_read
, unsnd
;
5712 stack
[++stacki
] = op
- DW_OP_reg0
;
5717 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5719 #if defined(HARRIS_TARGET) && defined(_M88K)
5720 /* The Harris 88110 gdb ports have long kept their special reg
5721 numbers between their gp-regs and their x-regs. This is
5722 not how our dwarf is generated. Punt. */
5725 stack
[++stacki
] = unsnd
;
5761 basereg
= op
- DW_OP_breg0
;
5762 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5768 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5770 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5775 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5777 if (frame_base_reg
>= 0)
5780 basereg
= frame_base_reg
;
5781 stack
[stacki
] += frame_base_offset
;
5785 complain (&dwarf2_missing_at_frame_base
);
5791 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
]);
5796 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5801 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5806 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5811 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5816 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5821 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5826 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5832 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5837 stack
[stacki
- 1] += stack
[stacki
];
5841 case DW_OP_plus_uconst
:
5842 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5847 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5853 /* If we're not the last op, then we definitely can't encode
5854 this using GDB's address_class enum. */
5856 complain (&dwarf2_complex_location_expr
);
5860 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
5861 return (stack
[stacki
]);
5864 return (stack
[stacki
]);
5867 /* memory allocation interface */
5871 dwarf2_free_tmp_obstack (ignore
)
5874 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5877 static struct dwarf_block
*
5878 dwarf_alloc_block ()
5880 struct dwarf_block
*blk
;
5882 blk
= (struct dwarf_block
*)
5883 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5887 static struct abbrev_info
*
5888 dwarf_alloc_abbrev ()
5890 struct abbrev_info
*abbrev
;
5892 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5893 memset (abbrev
, 0, sizeof (struct abbrev_info
));
5897 static struct die_info
*
5900 struct die_info
*die
;
5902 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5903 memset (die
, 0, sizeof (struct die_info
));