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. */
35 #include "elf/dwarf2.h"
38 #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 /* Obstack for allocating temporary storage used during symbol reading. */
272 static struct obstack dwarf2_tmp_obstack
;
274 /* Offset to the first byte of the current compilation unit header,
275 for resolving relative reference dies. */
276 static unsigned int cu_header_offset
;
278 /* Allocate fields for structs, unions and enums in this size. */
279 #ifndef DW_FIELD_ALLOC_CHUNK
280 #define DW_FIELD_ALLOC_CHUNK 4
283 /* The language we are debugging. */
284 static enum language cu_language
;
285 static const struct language_defn
*cu_language_defn
;
287 /* Actually data from the sections. */
288 static char *dwarf_info_buffer
;
289 static char *dwarf_abbrev_buffer
;
290 static char *dwarf_line_buffer
;
292 /* A zeroed version of a partial die for initialization purposes. */
293 static struct partial_die_info zeroed_partial_die
;
295 /* The generic symbol table building routines have separate lists for
296 file scope symbols and all all other scopes (local scopes). So
297 we need to select the right one to pass to add_symbol_to_list().
298 We do it by keeping a pointer to the correct list in list_in_scope.
300 FIXME: The original dwarf code just treated the file scope as the first
301 local scope, and all other local scopes as nested local scopes, and worked
302 fine. Check to see if we really need to distinguish these
304 static struct pending
**list_in_scope
= &file_symbols
;
306 /* FIXME: decode_locdesc sets these variables to describe the location
307 to the caller. These ought to be a structure or something. If
308 none of the flags are set, the object lives at the address returned
309 by decode_locdesc. */
311 static int optimized_out
; /* No ops in location in expression,
312 so object was optimized out. */
313 static int isreg
; /* Object lives in register.
314 decode_locdesc's return value is
315 the register number. */
316 static int offreg
; /* Object's address is the sum of the
317 register specified by basereg, plus
318 the offset returned. */
319 static int basereg
; /* See `offreg'. */
320 static int isderef
; /* Value described by flags above is
321 the address of a pointer to the object. */
322 static int islocal
; /* Variable is at the returned offset
323 from the frame start, but there's
324 no identified frame pointer for
325 this function, so we can't say
326 which register it's relative to;
329 /* DW_AT_frame_base values for the current function.
330 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
331 contains the register number for the frame register.
332 frame_base_offset is the offset from the frame register to the
333 virtual stack frame. */
334 static int frame_base_reg
;
335 static CORE_ADDR frame_base_offset
;
337 /* This value is added to each symbol value. FIXME: Generalize to
338 the section_offsets structure used by dbxread (once this is done,
339 pass the appropriate section number to end_symtab). */
340 static CORE_ADDR baseaddr
; /* Add to each symbol value */
342 /* We put a pointer to this structure in the read_symtab_private field
344 The complete dwarf information for an objfile is kept in the
345 psymbol_obstack, so that absolute die references can be handled.
346 Most of the information in this structure is related to an entire
347 object file and could be passed via the sym_private field of the objfile.
348 It is however conceivable that dwarf2 might not be the only type
349 of symbols read from an object file. */
353 /* Pointer to start of dwarf info buffer for the objfile. */
355 char *dwarf_info_buffer
;
357 /* Offset in dwarf_info_buffer for this compilation unit. */
359 unsigned long dwarf_info_offset
;
361 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
363 char *dwarf_abbrev_buffer
;
365 /* Size of dwarf abbreviation section for the objfile. */
367 unsigned int dwarf_abbrev_size
;
369 /* Pointer to start of dwarf line buffer for the objfile. */
371 char *dwarf_line_buffer
;
374 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
375 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
376 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
377 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
378 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
379 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
381 /* Maintain an array of referenced fundamental types for the current
382 compilation unit being read. For DWARF version 1, we have to construct
383 the fundamental types on the fly, since no information about the
384 fundamental types is supplied. Each such fundamental type is created by
385 calling a language dependent routine to create the type, and then a
386 pointer to that type is then placed in the array at the index specified
387 by it's FT_<TYPENAME> value. The array has a fixed size set by the
388 FT_NUM_MEMBERS compile time constant, which is the number of predefined
389 fundamental types gdb knows how to construct. */
390 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
392 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
393 but this would require a corresponding change in unpack_field_as_long
395 static int bits_per_byte
= 8;
397 /* The routines that read and process dies for a C struct or C++ class
398 pass lists of data member fields and lists of member function fields
399 in an instance of a field_info structure, as defined below. */
402 /* List of data member and baseclasses fields. */
405 struct nextfield
*next
;
412 /* Number of fields. */
415 /* Number of baseclasses. */
418 /* Set if the accesibility of one of the fields is not public. */
419 int non_public_fields
;
421 /* Member function fields array, entries are allocated in the order they
422 are encountered in the object file. */
425 struct nextfnfield
*next
;
426 struct fn_field fnfield
;
430 /* Member function fieldlist array, contains name of possibly overloaded
431 member function, number of overloaded member functions and a pointer
432 to the head of the member function field chain. */
437 struct nextfnfield
*head
;
441 /* Number of entries in the fnfieldlists array. */
445 /* FIXME: Kludge to mark a varargs function type for C++ member function
446 argument processing. */
447 #define TYPE_FLAG_VARARGS (1 << 10)
449 /* Dwarf2 has no clean way to discern C++ static and non-static member
450 functions. G++ helps GDB by marking the first parameter for non-static
451 member functions (which is the this pointer) as artificial.
452 We pass this information between dwarf2_add_member_fn and
453 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
454 #define TYPE_FIELD_ARTIFICIAL TYPE_FIELD_BITPOS
456 /* Various complaints about symbol reading that don't abort the process */
458 static struct complaint dwarf2_const_ignored
=
460 "type qualifier 'const' ignored", 0, 0
462 static struct complaint dwarf2_volatile_ignored
=
464 "type qualifier 'volatile' ignored", 0, 0
466 static struct complaint dwarf2_non_const_array_bound_ignored
=
468 "non-constant array bounds form '%s' ignored", 0, 0
470 static struct complaint dwarf2_missing_line_number_section
=
472 "missing .debug_line section", 0, 0
474 static struct complaint dwarf2_mangled_line_number_section
=
476 "mangled .debug_line section", 0, 0
478 static struct complaint dwarf2_unsupported_die_ref_attr
=
480 "unsupported die ref attribute form: '%s'", 0, 0
482 static struct complaint dwarf2_unsupported_stack_op
=
484 "unsupported stack op: '%s'", 0, 0
486 static struct complaint dwarf2_complex_location_expr
=
488 "location expression too complex", 0, 0
490 static struct complaint dwarf2_unsupported_tag
=
492 "unsupported tag: '%s'", 0, 0
494 static struct complaint dwarf2_unsupported_at_encoding
=
496 "unsupported DW_AT_encoding: '%s'", 0, 0
498 static struct complaint dwarf2_unsupported_at_frame_base
=
500 "unsupported DW_AT_frame_base for function '%s'", 0, 0
502 static struct complaint dwarf2_unexpected_tag
=
504 "unexepected tag in read_type_die: '%s'", 0, 0
506 static struct complaint dwarf2_missing_at_frame_base
=
508 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
510 static struct complaint dwarf2_bad_static_member_name
=
512 "unrecognized static data member name '%s'", 0, 0
514 static struct complaint dwarf2_unsupported_accessibility
=
516 "unsupported accessibility %d", 0, 0
518 static struct complaint dwarf2_bad_member_name_complaint
=
520 "cannot extract member name from '%s'", 0, 0
522 static struct complaint dwarf2_missing_member_fn_type_complaint
=
524 "member function type missing for '%s'", 0, 0
526 static struct complaint dwarf2_vtbl_not_found_complaint
=
528 "virtual function table pointer not found when defining class '%s'", 0, 0
530 static struct complaint dwarf2_absolute_sibling_complaint
=
532 "ignoring absolute DW_AT_sibling", 0, 0
534 static struct complaint dwarf2_const_value_length_mismatch
=
536 "const value length mismatch for '%s', got %d, expected %d", 0, 0
538 static struct complaint dwarf2_unsupported_const_value_attr
=
540 "unsupported const value attribute form: '%s'", 0, 0
543 /* Remember the addr_size read from the dwarf.
544 If a target expects to link compilation units with differing address
545 sizes, gdb needs to be sure that the appropriate size is here for
546 whatever scope is currently getting read. */
547 static int address_size
;
549 /* Some elf32 object file formats while linked for a 32 bit address
550 space contain debug information that has assumed 64 bit
551 addresses. Eg 64 bit MIPS target produced by GCC/GAS/LD where the
552 symbol table contains 32bit address values while its .debug_info
553 section contains 64 bit address values.
554 ADDRESS_SIGNIFICANT_SIZE specifies the number significant bits in
555 the ADDRESS_SIZE bytes read from the file */
556 static int address_significant_size
;
558 /* Externals references. */
559 extern int info_verbose
; /* From main.c; nonzero => verbose */
561 /* local function prototypes */
563 static void dwarf2_locate_sections
PARAMS ((bfd
*, asection
*, PTR
));
566 static void dwarf2_build_psymtabs_easy
PARAMS ((struct objfile
*, int));
569 static void dwarf2_build_psymtabs_hard
PARAMS ((struct objfile
*, int));
571 static char *scan_partial_symbols
PARAMS ((char *, struct objfile
*,
572 CORE_ADDR
*, CORE_ADDR
*));
574 static void add_partial_symbol
PARAMS ((struct partial_die_info
*,
577 static void dwarf2_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
579 static void psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*));
581 static char *dwarf2_read_section
PARAMS ((struct objfile
*, file_ptr
,
584 static void dwarf2_read_abbrevs
PARAMS ((bfd
*, unsigned int));
586 static void dwarf2_empty_abbrev_table
PARAMS ((PTR
));
588 static struct abbrev_info
*dwarf2_lookup_abbrev
PARAMS ((unsigned int));
590 static char *read_partial_die
PARAMS ((struct partial_die_info
*,
591 bfd
*, char *, int *));
593 static char *read_full_die
PARAMS ((struct die_info
**, bfd
*, char *));
595 static char *read_attribute
PARAMS ((struct attribute
*, struct attr_abbrev
*,
598 static unsigned int read_1_byte
PARAMS ((bfd
*, char *));
600 static int read_1_signed_byte
PARAMS ((bfd
*, char *));
602 static unsigned int read_2_bytes
PARAMS ((bfd
*, char *));
604 static unsigned int read_4_bytes
PARAMS ((bfd
*, char *));
606 static unsigned int read_8_bytes
PARAMS ((bfd
*, char *));
608 static CORE_ADDR read_address
PARAMS ((bfd
*, char *));
610 static char *read_n_bytes
PARAMS ((bfd
*, char *, unsigned int));
612 static char *read_string
PARAMS ((bfd
*, char *, unsigned int *));
614 static unsigned int read_unsigned_leb128
PARAMS ((bfd
*, char *,
617 static int read_signed_leb128
PARAMS ((bfd
*, char *, unsigned int *));
619 static void set_cu_language
PARAMS ((unsigned int));
621 static struct attribute
*dwarf_attr
PARAMS ((struct die_info
*,
624 static void dwarf_decode_lines
PARAMS ((unsigned int, char *, bfd
*));
626 static void dwarf2_start_subfile
PARAMS ((char *, char *));
628 static struct symbol
*new_symbol
PARAMS ((struct die_info
*, struct type
*,
631 static void dwarf2_const_value
PARAMS ((struct attribute
*, struct symbol
*,
634 static void dwarf2_const_value_data (struct attribute
*attr
,
638 static struct type
*die_type
PARAMS ((struct die_info
*, struct objfile
*));
640 static struct type
*die_containing_type
PARAMS ((struct die_info
*,
644 static struct type
*type_at_offset
PARAMS ((unsigned int, struct objfile
*));
647 static struct type
*tag_type_to_type
PARAMS ((struct die_info
*,
650 static void read_type_die
PARAMS ((struct die_info
*, struct objfile
*));
652 static void read_typedef
PARAMS ((struct die_info
*, struct objfile
*));
654 static void read_base_type
PARAMS ((struct die_info
*, struct objfile
*));
656 static void read_file_scope
PARAMS ((struct die_info
*, struct objfile
*));
658 static void read_func_scope
PARAMS ((struct die_info
*, struct objfile
*));
660 static void read_lexical_block_scope
PARAMS ((struct die_info
*,
663 static int dwarf2_get_pc_bounds
PARAMS ((struct die_info
*,
664 CORE_ADDR
*, CORE_ADDR
*,
667 static void dwarf2_add_field
PARAMS ((struct field_info
*, struct die_info
*,
670 static void dwarf2_attach_fields_to_type
PARAMS ((struct field_info
*,
674 static void dwarf2_add_member_fn
PARAMS ((struct field_info
*,
675 struct die_info
*, struct type
*,
676 struct objfile
* objfile
));
678 static void dwarf2_attach_fn_fields_to_type
PARAMS ((struct field_info
*,
682 static void read_structure_scope
PARAMS ((struct die_info
*, struct objfile
*));
684 static void read_common_block
PARAMS ((struct die_info
*, struct objfile
*));
686 static void read_enumeration
PARAMS ((struct die_info
*, struct objfile
*));
688 static struct type
*dwarf_base_type
PARAMS ((int, int, struct objfile
*));
690 static CORE_ADDR decode_locdesc
PARAMS ((struct dwarf_block
*,
693 static void read_array_type
PARAMS ((struct die_info
*, struct objfile
*));
695 static void read_tag_pointer_type
PARAMS ((struct die_info
*,
698 static void read_tag_ptr_to_member_type
PARAMS ((struct die_info
*,
701 static void read_tag_reference_type
PARAMS ((struct die_info
*,
704 static void read_tag_const_type
PARAMS ((struct die_info
*, struct objfile
*));
706 static void read_tag_volatile_type
PARAMS ((struct die_info
*,
709 static void read_tag_string_type
PARAMS ((struct die_info
*,
712 static void read_subroutine_type
PARAMS ((struct die_info
*,
715 struct die_info
*read_comp_unit
PARAMS ((char *, bfd
*));
717 static void free_die_list
PARAMS ((struct die_info
*));
719 static void process_die
PARAMS ((struct die_info
*, struct objfile
*));
721 static char *dwarf2_linkage_name
PARAMS ((struct die_info
*));
723 static char *dwarf_tag_name
PARAMS ((unsigned int));
725 static char *dwarf_attr_name
PARAMS ((unsigned int));
727 static char *dwarf_form_name
PARAMS ((unsigned int));
729 static char *dwarf_stack_op_name
PARAMS ((unsigned int));
731 static char *dwarf_bool_name
PARAMS ((unsigned int));
733 static char *dwarf_type_encoding_name
PARAMS ((unsigned int));
736 static char *dwarf_cfi_name
PARAMS ((unsigned int));
738 struct die_info
*copy_die
PARAMS ((struct die_info
*));
741 struct die_info
*sibling_die
PARAMS ((struct die_info
*));
743 void dump_die
PARAMS ((struct die_info
*));
745 void dump_die_list
PARAMS ((struct die_info
*));
747 void store_in_ref_table
PARAMS ((unsigned int, struct die_info
*));
749 static void dwarf2_empty_die_ref_table
PARAMS ((void));
751 static unsigned int dwarf2_get_ref_die_offset
PARAMS ((struct attribute
*));
753 struct die_info
*follow_die_ref
PARAMS ((unsigned int));
755 static struct type
*dwarf2_fundamental_type
PARAMS ((struct objfile
*, int));
757 /* memory allocation interface */
759 static void dwarf2_free_tmp_obstack
PARAMS ((PTR
));
761 static struct dwarf_block
*dwarf_alloc_block
PARAMS ((void));
763 static struct abbrev_info
*dwarf_alloc_abbrev
PARAMS ((void));
765 static struct die_info
*dwarf_alloc_die
PARAMS ((void));
767 /* Try to locate the sections we need for DWARF 2 debugging
768 information and return true if we have enough to do something. */
771 dwarf2_has_info (abfd
)
774 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
775 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
776 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
786 /* This function is mapped across the sections and remembers the
787 offset and size of each of the debugging sections we are interested
791 dwarf2_locate_sections (ignore_abfd
, sectp
, ignore_ptr
)
796 if (STREQ (sectp
->name
, INFO_SECTION
))
798 dwarf_info_offset
= sectp
->filepos
;
799 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
801 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
803 dwarf_abbrev_offset
= sectp
->filepos
;
804 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
806 else if (STREQ (sectp
->name
, LINE_SECTION
))
808 dwarf_line_offset
= sectp
->filepos
;
809 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
811 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
813 dwarf_pubnames_offset
= sectp
->filepos
;
814 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
816 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
818 dwarf_aranges_offset
= sectp
->filepos
;
819 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
821 else if (STREQ (sectp
->name
, LOC_SECTION
))
823 dwarf_loc_offset
= sectp
->filepos
;
824 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
826 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
828 dwarf_macinfo_offset
= sectp
->filepos
;
829 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
831 else if (STREQ (sectp
->name
, STR_SECTION
))
833 dwarf_str_offset
= sectp
->filepos
;
834 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
838 /* Build a partial symbol table. */
841 dwarf2_build_psymtabs (objfile
, mainline
)
842 struct objfile
*objfile
;
846 /* We definitely need the .debug_info and .debug_abbrev sections */
848 dwarf_info_buffer
= dwarf2_read_section (objfile
,
851 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
854 dwarf_line_buffer
= dwarf2_read_section (objfile
,
858 if (mainline
|| objfile
->global_psymbols
.size
== 0 ||
859 objfile
->static_psymbols
.size
== 0)
861 init_psymbol_list (objfile
, 1024);
865 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
867 /* Things are significantly easier if we have .debug_aranges and
868 .debug_pubnames sections */
870 dwarf2_build_psymtabs_easy (objfile
, mainline
);
874 /* only test this case for now */
876 /* In this case we have to work a bit harder */
877 dwarf2_build_psymtabs_hard (objfile
, mainline
);
882 /* Build the partial symbol table from the information in the
883 .debug_pubnames and .debug_aranges sections. */
886 dwarf2_build_psymtabs_easy (objfile
, mainline
)
887 struct objfile
*objfile
;
890 bfd
*abfd
= objfile
->obfd
;
891 char *aranges_buffer
, *pubnames_buffer
;
892 char *aranges_ptr
, *pubnames_ptr
;
893 unsigned int entry_length
, version
, info_offset
, info_size
;
895 pubnames_buffer
= dwarf2_read_section (objfile
,
896 dwarf_pubnames_offset
,
897 dwarf_pubnames_size
);
898 pubnames_ptr
= pubnames_buffer
;
899 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
901 entry_length
= read_4_bytes (abfd
, pubnames_ptr
);
903 version
= read_1_byte (abfd
, pubnames_ptr
);
905 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
907 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
911 aranges_buffer
= dwarf2_read_section (objfile
,
912 dwarf_aranges_offset
,
918 /* Build the partial symbol table by doing a quick pass through the
919 .debug_info and .debug_abbrev sections. */
922 dwarf2_build_psymtabs_hard (objfile
, mainline
)
923 struct objfile
*objfile
;
926 /* Instead of reading this into a big buffer, we should probably use
927 mmap() on architectures that support it. (FIXME) */
928 bfd
*abfd
= objfile
->obfd
;
929 char *info_ptr
, *abbrev_ptr
;
930 char *beg_of_comp_unit
;
931 struct comp_unit_head cu_header
;
932 struct partial_die_info comp_unit_die
;
933 struct partial_symtab
*pst
;
934 struct cleanup
*back_to
;
935 int comp_unit_has_pc_info
;
936 CORE_ADDR lowpc
, highpc
;
938 /* Number of bytes of any addresses that are signficant */
939 address_significant_size
= get_elf_backend_data (abfd
)->s
->arch_size
/ 8;
941 info_ptr
= dwarf_info_buffer
;
942 abbrev_ptr
= dwarf_abbrev_buffer
;
944 obstack_init (&dwarf2_tmp_obstack
);
945 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
947 while ((unsigned int) (info_ptr
- dwarf_info_buffer
)
948 + ((info_ptr
- dwarf_info_buffer
) % 4) < dwarf_info_size
)
950 beg_of_comp_unit
= info_ptr
;
951 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
953 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
955 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
957 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
959 address_size
= cu_header
.addr_size
;
961 if (cu_header
.version
!= 2)
963 error ("Dwarf Error: wrong version in compilation unit header.");
966 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
968 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
969 (long) cu_header
.abbrev_offset
,
970 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
973 if (beg_of_comp_unit
+ cu_header
.length
+ 4
974 > dwarf_info_buffer
+ dwarf_info_size
)
976 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
977 (long) cu_header
.length
,
978 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
981 if (address_size
< address_significant_size
)
983 error ("Dwarf Error: bad address size (%ld) in compilation unit header (offset 0x%lx + 11).",
984 (long) cu_header
.addr_size
,
985 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
988 /* Read the abbrevs for this compilation unit into a table */
989 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
990 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
992 /* Read the compilation unit die */
993 info_ptr
= read_partial_die (&comp_unit_die
, abfd
,
994 info_ptr
, &comp_unit_has_pc_info
);
996 /* Set the language we're debugging */
997 set_cu_language (comp_unit_die
.language
);
999 /* Allocate a new partial symbol table structure */
1000 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1001 comp_unit_die
.name
? comp_unit_die
.name
: "",
1002 comp_unit_die
.lowpc
,
1003 objfile
->global_psymbols
.next
,
1004 objfile
->static_psymbols
.next
);
1006 pst
->read_symtab_private
= (char *)
1007 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1008 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1009 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1010 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1011 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1012 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1013 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1014 baseaddr
= ANOFFSET (objfile
->section_offsets
, 0);
1016 /* Store the function that reads in the rest of the symbol table */
1017 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1019 /* Check if comp unit has_children.
1020 If so, read the rest of the partial symbols from this comp unit.
1021 If not, there's no more debug_info for this comp unit. */
1022 if (comp_unit_die
.has_children
)
1024 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
);
1026 /* If the compilation unit didn't have an explicit address range,
1027 then use the information extracted from its child dies. */
1028 if (!comp_unit_has_pc_info
)
1030 comp_unit_die
.lowpc
= lowpc
;
1031 comp_unit_die
.highpc
= highpc
;
1034 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1035 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1037 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1038 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1039 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1040 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1041 sort_pst_symbols (pst
);
1043 /* If there is already a psymtab or symtab for a file of this
1044 name, remove it. (If there is a symtab, more drastic things
1045 also happen.) This happens in VxWorks. */
1046 free_named_symtabs (pst
->filename
);
1048 info_ptr
= beg_of_comp_unit
+ cu_header
.length
+ 4;
1050 do_cleanups (back_to
);
1053 /* Read in all interesting dies to the end of the compilation unit. */
1056 scan_partial_symbols (info_ptr
, objfile
, lowpc
, highpc
)
1058 struct objfile
*objfile
;
1062 bfd
*abfd
= objfile
->obfd
;
1063 struct partial_die_info pdi
;
1065 /* This function is called after we've read in the comp_unit_die in
1066 order to read its children. We start the nesting level at 1 since
1067 we have pushed 1 level down in order to read the comp unit's children.
1068 The comp unit itself is at level 0, so we stop reading when we pop
1069 back to that level. */
1071 int nesting_level
= 1;
1074 *lowpc
= ((CORE_ADDR
) -1);
1075 *highpc
= ((CORE_ADDR
) 0);
1077 while (nesting_level
)
1079 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, &has_pc_info
);
1085 case DW_TAG_subprogram
:
1088 if (pdi
.lowpc
< *lowpc
)
1092 if (pdi
.highpc
> *highpc
)
1094 *highpc
= pdi
.highpc
;
1096 if ((pdi
.is_external
|| nesting_level
== 1)
1097 && !pdi
.is_declaration
)
1099 add_partial_symbol (&pdi
, objfile
);
1103 case DW_TAG_variable
:
1104 case DW_TAG_typedef
:
1105 case DW_TAG_class_type
:
1106 case DW_TAG_structure_type
:
1107 case DW_TAG_union_type
:
1108 case DW_TAG_enumeration_type
:
1109 if ((pdi
.is_external
|| nesting_level
== 1)
1110 && !pdi
.is_declaration
)
1112 add_partial_symbol (&pdi
, objfile
);
1115 case DW_TAG_enumerator
:
1116 /* File scope enumerators are added to the partial symbol
1118 if (nesting_level
== 2)
1119 add_partial_symbol (&pdi
, objfile
);
1121 case DW_TAG_base_type
:
1122 /* File scope base type definitions are added to the partial
1124 if (nesting_level
== 1)
1125 add_partial_symbol (&pdi
, objfile
);
1132 /* If the die has a sibling, skip to the sibling.
1133 Do not skip enumeration types, we want to record their
1135 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1137 info_ptr
= pdi
.sibling
;
1139 else if (pdi
.has_children
)
1141 /* Die has children, but the optional DW_AT_sibling attribute
1152 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1153 from `maint check'. */
1154 if (*lowpc
== ((CORE_ADDR
) -1))
1160 add_partial_symbol (pdi
, objfile
)
1161 struct partial_die_info
*pdi
;
1162 struct objfile
*objfile
;
1168 case DW_TAG_subprogram
:
1169 if (pdi
->is_external
)
1171 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1172 mst_text, objfile); */
1173 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1174 VAR_NAMESPACE
, LOC_BLOCK
,
1175 &objfile
->global_psymbols
,
1176 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1180 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1181 mst_file_text, objfile); */
1182 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1183 VAR_NAMESPACE
, LOC_BLOCK
,
1184 &objfile
->static_psymbols
,
1185 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1188 case DW_TAG_variable
:
1189 if (pdi
->is_external
)
1192 Don't enter into the minimal symbol tables as there is
1193 a minimal symbol table entry from the ELF symbols already.
1194 Enter into partial symbol table if it has a location
1195 descriptor or a type.
1196 If the location descriptor is missing, new_symbol will create
1197 a LOC_UNRESOLVED symbol, the address of the variable will then
1198 be determined from the minimal symbol table whenever the variable
1200 The address for the partial symbol table entry is not
1201 used by GDB, but it comes in handy for debugging partial symbol
1205 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1206 if (pdi
->locdesc
|| pdi
->has_type
)
1207 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1208 VAR_NAMESPACE
, LOC_STATIC
,
1209 &objfile
->global_psymbols
,
1210 0, addr
+ baseaddr
, cu_language
, objfile
);
1214 /* Static Variable. Skip symbols without location descriptors. */
1215 if (pdi
->locdesc
== NULL
)
1217 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1218 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1219 mst_file_data, objfile); */
1220 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1221 VAR_NAMESPACE
, LOC_STATIC
,
1222 &objfile
->static_psymbols
,
1223 0, addr
+ baseaddr
, cu_language
, objfile
);
1226 case DW_TAG_typedef
:
1227 case DW_TAG_base_type
:
1228 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1229 VAR_NAMESPACE
, LOC_TYPEDEF
,
1230 &objfile
->static_psymbols
,
1231 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1233 case DW_TAG_class_type
:
1234 case DW_TAG_structure_type
:
1235 case DW_TAG_union_type
:
1236 case DW_TAG_enumeration_type
:
1237 /* Skip aggregate types without children, these are external
1239 if (pdi
->has_children
== 0)
1241 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1242 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1243 &objfile
->static_psymbols
,
1244 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1246 if (cu_language
== language_cplus
)
1248 /* For C++, these implicitly act as typedefs as well. */
1249 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1250 VAR_NAMESPACE
, LOC_TYPEDEF
,
1251 &objfile
->static_psymbols
,
1252 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1255 case DW_TAG_enumerator
:
1256 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1257 VAR_NAMESPACE
, LOC_CONST
,
1258 &objfile
->static_psymbols
,
1259 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1266 /* Expand this partial symbol table into a full symbol table. */
1269 dwarf2_psymtab_to_symtab (pst
)
1270 struct partial_symtab
*pst
;
1272 /* FIXME: This is barely more than a stub. */
1277 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1283 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1284 gdb_flush (gdb_stdout
);
1287 psymtab_to_symtab_1 (pst
);
1289 /* Finish up the debug error message. */
1291 printf_filtered ("done.\n");
1297 psymtab_to_symtab_1 (pst
)
1298 struct partial_symtab
*pst
;
1300 struct objfile
*objfile
= pst
->objfile
;
1301 bfd
*abfd
= objfile
->obfd
;
1302 struct comp_unit_head cu_header
;
1303 struct die_info
*dies
;
1304 unsigned long offset
;
1305 CORE_ADDR lowpc
, highpc
;
1306 struct die_info
*child_die
;
1308 struct symtab
*symtab
;
1309 struct cleanup
*back_to
;
1311 /* Set local variables from the partial symbol table info. */
1312 offset
= DWARF_INFO_OFFSET (pst
);
1313 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1314 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1315 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1316 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1317 baseaddr
= ANOFFSET (pst
->section_offsets
, 0);
1318 cu_header_offset
= offset
;
1319 info_ptr
= dwarf_info_buffer
+ offset
;
1321 obstack_init (&dwarf2_tmp_obstack
);
1322 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1325 make_cleanup (really_free_pendings
, NULL
);
1327 /* read in the comp_unit header */
1328 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
1330 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
1332 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
1334 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
1337 /* Read the abbrevs for this compilation unit */
1338 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1339 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1341 dies
= read_comp_unit (info_ptr
, abfd
);
1343 make_cleanup ((make_cleanup_func
) free_die_list
, dies
);
1345 /* Do line number decoding in read_file_scope () */
1346 process_die (dies
, objfile
);
1348 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1350 /* Some compilers don't define a DW_AT_high_pc attribute for
1351 the compilation unit. If the DW_AT_high_pc is missing,
1352 synthesize it, by scanning the DIE's below the compilation unit. */
1354 if (dies
->has_children
)
1356 child_die
= dies
->next
;
1357 while (child_die
&& child_die
->tag
)
1359 if (child_die
->tag
== DW_TAG_subprogram
)
1361 CORE_ADDR low
, high
;
1363 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1365 highpc
= max (highpc
, high
);
1368 child_die
= sibling_die (child_die
);
1372 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, 0);
1374 /* Set symtab language to language from DW_AT_language.
1375 If the compilation is from a C file generated by language preprocessors,
1376 do not set the language if it was already deduced by start_subfile. */
1378 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1380 symtab
->language
= cu_language
;
1382 pst
->symtab
= symtab
;
1384 sort_symtab_syms (pst
->symtab
);
1386 do_cleanups (back_to
);
1389 /* Process a die and its children. */
1392 process_die (die
, objfile
)
1393 struct die_info
*die
;
1394 struct objfile
*objfile
;
1398 case DW_TAG_padding
:
1400 case DW_TAG_compile_unit
:
1401 read_file_scope (die
, objfile
);
1403 case DW_TAG_subprogram
:
1404 read_subroutine_type (die
, objfile
);
1405 read_func_scope (die
, objfile
);
1407 case DW_TAG_inlined_subroutine
:
1408 /* FIXME: These are ignored for now.
1409 They could be used to set breakpoints on all inlined instances
1410 of a function and make GDB `next' properly over inlined functions. */
1412 case DW_TAG_lexical_block
:
1413 read_lexical_block_scope (die
, objfile
);
1415 case DW_TAG_class_type
:
1416 case DW_TAG_structure_type
:
1417 case DW_TAG_union_type
:
1418 read_structure_scope (die
, objfile
);
1420 case DW_TAG_enumeration_type
:
1421 read_enumeration (die
, objfile
);
1423 case DW_TAG_subroutine_type
:
1424 read_subroutine_type (die
, objfile
);
1426 case DW_TAG_array_type
:
1427 read_array_type (die
, objfile
);
1429 case DW_TAG_pointer_type
:
1430 read_tag_pointer_type (die
, objfile
);
1432 case DW_TAG_ptr_to_member_type
:
1433 read_tag_ptr_to_member_type (die
, objfile
);
1435 case DW_TAG_reference_type
:
1436 read_tag_reference_type (die
, objfile
);
1438 case DW_TAG_string_type
:
1439 read_tag_string_type (die
, objfile
);
1441 case DW_TAG_base_type
:
1442 read_base_type (die
, objfile
);
1443 if (dwarf_attr (die
, DW_AT_name
))
1445 /* Add a typedef symbol for the base type definition. */
1446 new_symbol (die
, die
->type
, objfile
);
1449 case DW_TAG_common_block
:
1450 read_common_block (die
, objfile
);
1452 case DW_TAG_common_inclusion
:
1455 new_symbol (die
, NULL
, objfile
);
1461 read_file_scope (die
, objfile
)
1462 struct die_info
*die
;
1463 struct objfile
*objfile
;
1465 unsigned int line_offset
= 0;
1466 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1467 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1468 struct attribute
*attr
;
1469 char *name
= "<unknown>";
1470 char *comp_dir
= NULL
;
1471 struct die_info
*child_die
;
1472 bfd
*abfd
= objfile
->obfd
;
1474 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1476 if (die
->has_children
)
1478 child_die
= die
->next
;
1479 while (child_die
&& child_die
->tag
)
1481 if (child_die
->tag
== DW_TAG_subprogram
)
1483 CORE_ADDR low
, high
;
1485 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1487 lowpc
= min (lowpc
, low
);
1488 highpc
= max (highpc
, high
);
1491 child_die
= sibling_die (child_die
);
1496 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1497 from finish_block. */
1498 if (lowpc
== ((CORE_ADDR
) -1))
1503 attr
= dwarf_attr (die
, DW_AT_name
);
1506 name
= DW_STRING (attr
);
1508 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1511 comp_dir
= DW_STRING (attr
);
1514 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1515 directory, get rid of it. */
1516 char *cp
= strchr (comp_dir
, ':');
1518 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1523 if (objfile
->ei
.entry_point
>= lowpc
&&
1524 objfile
->ei
.entry_point
< highpc
)
1526 objfile
->ei
.entry_file_lowpc
= lowpc
;
1527 objfile
->ei
.entry_file_highpc
= highpc
;
1530 attr
= dwarf_attr (die
, DW_AT_language
);
1533 set_cu_language (DW_UNSND (attr
));
1536 /* We assume that we're processing GCC output. */
1537 processing_gcc_compilation
= 2;
1539 /* FIXME:Do something here. */
1540 if (dip
->at_producer
!= NULL
)
1542 handle_producer (dip
->at_producer
);
1546 /* The compilation unit may be in a different language or objfile,
1547 zero out all remembered fundamental types. */
1548 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1550 start_symtab (name
, comp_dir
, lowpc
);
1551 record_debugformat ("DWARF 2");
1553 /* Decode line number information if present. */
1554 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1557 line_offset
= DW_UNSND (attr
);
1558 dwarf_decode_lines (line_offset
, comp_dir
, abfd
);
1561 /* Process all dies in compilation unit. */
1562 if (die
->has_children
)
1564 child_die
= die
->next
;
1565 while (child_die
&& child_die
->tag
)
1567 process_die (child_die
, objfile
);
1568 child_die
= sibling_die (child_die
);
1574 read_func_scope (die
, objfile
)
1575 struct die_info
*die
;
1576 struct objfile
*objfile
;
1578 register struct context_stack
*new;
1581 struct die_info
*child_die
;
1582 struct attribute
*attr
;
1585 name
= dwarf2_linkage_name (die
);
1587 /* Ignore functions with missing or empty names and functions with
1588 missing or invalid low and high pc attributes. */
1589 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1595 if (objfile
->ei
.entry_point
>= lowpc
&&
1596 objfile
->ei
.entry_point
< highpc
)
1598 objfile
->ei
.entry_func_lowpc
= lowpc
;
1599 objfile
->ei
.entry_func_highpc
= highpc
;
1602 /* Decode DW_AT_frame_base location descriptor if present, keep result
1603 for DW_OP_fbreg operands in decode_locdesc. */
1604 frame_base_reg
= -1;
1605 frame_base_offset
= 0;
1606 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1609 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
);
1611 complain (&dwarf2_unsupported_at_frame_base
, name
);
1613 frame_base_reg
= addr
;
1616 frame_base_reg
= basereg
;
1617 frame_base_offset
= addr
;
1620 complain (&dwarf2_unsupported_at_frame_base
, name
);
1623 new = push_context (0, lowpc
);
1624 new->name
= new_symbol (die
, die
->type
, objfile
);
1625 list_in_scope
= &local_symbols
;
1627 if (die
->has_children
)
1629 child_die
= die
->next
;
1630 while (child_die
&& child_die
->tag
)
1632 process_die (child_die
, objfile
);
1633 child_die
= sibling_die (child_die
);
1637 new = pop_context ();
1638 /* Make a block for the local symbols within. */
1639 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1640 lowpc
, highpc
, objfile
);
1641 list_in_scope
= &file_symbols
;
1644 /* Process all the DIES contained within a lexical block scope. Start
1645 a new scope, process the dies, and then close the scope. */
1648 read_lexical_block_scope (die
, objfile
)
1649 struct die_info
*die
;
1650 struct objfile
*objfile
;
1652 register struct context_stack
*new;
1653 CORE_ADDR lowpc
, highpc
;
1654 struct die_info
*child_die
;
1656 /* Ignore blocks with missing or invalid low and high pc attributes. */
1657 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1662 push_context (0, lowpc
);
1663 if (die
->has_children
)
1665 child_die
= die
->next
;
1666 while (child_die
&& child_die
->tag
)
1668 process_die (child_die
, objfile
);
1669 child_die
= sibling_die (child_die
);
1672 new = pop_context ();
1674 if (local_symbols
!= NULL
)
1676 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1679 local_symbols
= new->locals
;
1682 /* Get low and high pc attributes from a die.
1683 Return 1 if the attributes are present and valid, otherwise, return 0. */
1686 dwarf2_get_pc_bounds (die
, lowpc
, highpc
, objfile
)
1687 struct die_info
*die
;
1690 struct objfile
*objfile
;
1692 struct attribute
*attr
;
1696 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1698 low
= DW_ADDR (attr
);
1701 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1703 high
= DW_ADDR (attr
);
1710 /* When using the GNU linker, .gnu.linkonce. sections are used to
1711 eliminate duplicate copies of functions and vtables and such.
1712 The linker will arbitrarily choose one and discard the others.
1713 The AT_*_pc values for such functions refer to local labels in
1714 these sections. If the section from that file was discarded, the
1715 labels are not in the output, so the relocs get a value of 0.
1716 If this is a discarded function, mark the pc bounds as invalid,
1717 so that GDB will ignore it. */
1718 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1726 /* Add an aggregate field to the field list. */
1729 dwarf2_add_field (fip
, die
, objfile
)
1730 struct field_info
*fip
;
1731 struct die_info
*die
;
1732 struct objfile
*objfile
;
1734 struct nextfield
*new_field
;
1735 struct attribute
*attr
;
1737 char *fieldname
= "";
1739 /* Allocate a new field list entry and link it in. */
1740 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1741 make_cleanup (free
, new_field
);
1742 memset (new_field
, 0, sizeof (struct nextfield
));
1743 new_field
->next
= fip
->fields
;
1744 fip
->fields
= new_field
;
1747 /* Handle accessibility and virtuality of field.
1748 The default accessibility for members is public, the default
1749 accessibility for inheritance is private. */
1750 if (die
->tag
!= DW_TAG_inheritance
)
1751 new_field
->accessibility
= DW_ACCESS_public
;
1753 new_field
->accessibility
= DW_ACCESS_private
;
1754 new_field
->virtuality
= DW_VIRTUALITY_none
;
1756 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1758 new_field
->accessibility
= DW_UNSND (attr
);
1759 if (new_field
->accessibility
!= DW_ACCESS_public
)
1760 fip
->non_public_fields
= 1;
1761 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1763 new_field
->virtuality
= DW_UNSND (attr
);
1765 fp
= &new_field
->field
;
1766 if (die
->tag
== DW_TAG_member
)
1768 /* Get type of field. */
1769 fp
->type
= die_type (die
, objfile
);
1771 /* Get bit size of field (zero if none). */
1772 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1775 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1779 FIELD_BITSIZE (*fp
) = 0;
1782 /* Get bit offset of field. */
1783 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1786 FIELD_BITPOS (*fp
) =
1787 decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1790 FIELD_BITPOS (*fp
) = 0;
1791 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1794 if (BITS_BIG_ENDIAN
)
1796 /* For big endian bits, the DW_AT_bit_offset gives the
1797 additional bit offset from the MSB of the containing
1798 anonymous object to the MSB of the field. We don't
1799 have to do anything special since we don't need to
1800 know the size of the anonymous object. */
1801 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1805 /* For little endian bits, compute the bit offset to the
1806 MSB of the anonymous object, subtract off the number of
1807 bits from the MSB of the field to the MSB of the
1808 object, and then subtract off the number of bits of
1809 the field itself. The result is the bit offset of
1810 the LSB of the field. */
1812 int bit_offset
= DW_UNSND (attr
);
1814 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1817 /* The size of the anonymous object containing
1818 the bit field is explicit, so use the
1819 indicated size (in bytes). */
1820 anonymous_size
= DW_UNSND (attr
);
1824 /* The size of the anonymous object containing
1825 the bit field must be inferred from the type
1826 attribute of the data member containing the
1828 anonymous_size
= TYPE_LENGTH (fp
->type
);
1830 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1831 - bit_offset
- FIELD_BITSIZE (*fp
);
1835 /* Get name of field. */
1836 attr
= dwarf_attr (die
, DW_AT_name
);
1837 if (attr
&& DW_STRING (attr
))
1838 fieldname
= DW_STRING (attr
);
1839 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1840 &objfile
->type_obstack
);
1842 /* Change accessibility for artificial fields (e.g. virtual table
1843 pointer or virtual base class pointer) to private. */
1844 if (dwarf_attr (die
, DW_AT_artificial
))
1846 new_field
->accessibility
= DW_ACCESS_private
;
1847 fip
->non_public_fields
= 1;
1850 else if (die
->tag
== DW_TAG_variable
)
1854 /* C++ static member.
1855 Get name of field. */
1856 attr
= dwarf_attr (die
, DW_AT_name
);
1857 if (attr
&& DW_STRING (attr
))
1858 fieldname
= DW_STRING (attr
);
1862 /* Get physical name. */
1863 physname
= dwarf2_linkage_name (die
);
1865 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1866 &objfile
->type_obstack
));
1867 FIELD_TYPE (*fp
) = die_type (die
, objfile
);
1868 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1869 &objfile
->type_obstack
);
1871 else if (die
->tag
== DW_TAG_inheritance
)
1873 /* C++ base class field. */
1874 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1876 FIELD_BITPOS (*fp
) = decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1877 FIELD_BITSIZE (*fp
) = 0;
1878 FIELD_TYPE (*fp
) = die_type (die
, objfile
);
1879 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1880 fip
->nbaseclasses
++;
1884 /* Create the vector of fields, and attach it to the type. */
1887 dwarf2_attach_fields_to_type (fip
, type
, objfile
)
1888 struct field_info
*fip
;
1890 struct objfile
*objfile
;
1892 int nfields
= fip
->nfields
;
1894 /* Record the field count, allocate space for the array of fields,
1895 and create blank accessibility bitfields if necessary. */
1896 TYPE_NFIELDS (type
) = nfields
;
1897 TYPE_FIELDS (type
) = (struct field
*)
1898 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1899 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1901 if (fip
->non_public_fields
)
1903 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1905 TYPE_FIELD_PRIVATE_BITS (type
) =
1906 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1907 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1909 TYPE_FIELD_PROTECTED_BITS (type
) =
1910 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1911 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1913 TYPE_FIELD_IGNORE_BITS (type
) =
1914 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1915 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1918 /* If the type has baseclasses, allocate and clear a bit vector for
1919 TYPE_FIELD_VIRTUAL_BITS. */
1920 if (fip
->nbaseclasses
)
1922 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
1925 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1926 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1927 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1928 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
1929 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
1932 /* Copy the saved-up fields into the field vector. Start from the head
1933 of the list, adding to the tail of the field array, so that they end
1934 up in the same order in the array in which they were added to the list. */
1935 while (nfields
-- > 0)
1937 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
1938 switch (fip
->fields
->accessibility
)
1940 case DW_ACCESS_private
:
1941 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
1944 case DW_ACCESS_protected
:
1945 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
1948 case DW_ACCESS_public
:
1952 /* Unknown accessibility. Complain and treat it as public. */
1954 complain (&dwarf2_unsupported_accessibility
,
1955 fip
->fields
->accessibility
);
1959 if (nfields
< fip
->nbaseclasses
)
1961 switch (fip
->fields
->virtuality
)
1963 case DW_VIRTUALITY_virtual
:
1964 case DW_VIRTUALITY_pure_virtual
:
1965 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
1969 fip
->fields
= fip
->fields
->next
;
1973 /* Add a member function to the proper fieldlist. */
1976 dwarf2_add_member_fn (fip
, die
, type
, objfile
)
1977 struct field_info
*fip
;
1978 struct die_info
*die
;
1980 struct objfile
*objfile
;
1982 struct attribute
*attr
;
1983 struct fnfieldlist
*flp
;
1985 struct fn_field
*fnp
;
1988 struct nextfnfield
*new_fnfield
;
1990 /* Get name of member function. */
1991 attr
= dwarf_attr (die
, DW_AT_name
);
1992 if (attr
&& DW_STRING (attr
))
1993 fieldname
= DW_STRING (attr
);
1997 /* Get the mangled name. */
1998 physname
= dwarf2_linkage_name (die
);
2000 /* Look up member function name in fieldlist. */
2001 for (i
= 0; i
< fip
->nfnfields
; i
++)
2003 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2007 /* Create new list element if necessary. */
2008 if (i
< fip
->nfnfields
)
2009 flp
= &fip
->fnfieldlists
[i
];
2012 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2014 fip
->fnfieldlists
= (struct fnfieldlist
*)
2015 xrealloc (fip
->fnfieldlists
,
2016 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2017 * sizeof (struct fnfieldlist
));
2018 if (fip
->nfnfields
== 0)
2019 make_cleanup ((make_cleanup_func
) free_current_contents
,
2020 &fip
->fnfieldlists
);
2022 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2023 flp
->name
= fieldname
;
2029 /* Create a new member function field and chain it to the field list
2031 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2032 make_cleanup (free
, new_fnfield
);
2033 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2034 new_fnfield
->next
= flp
->head
;
2035 flp
->head
= new_fnfield
;
2038 /* Fill in the member function field info. */
2039 fnp
= &new_fnfield
->fnfield
;
2040 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2041 &objfile
->type_obstack
);
2042 fnp
->type
= alloc_type (objfile
);
2043 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2045 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2046 struct type
**arg_types
;
2047 int nparams
= TYPE_NFIELDS (die
->type
);
2050 /* Copy argument types from the subroutine type. */
2051 arg_types
= (struct type
**)
2052 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2053 for (iparams
= 0; iparams
< nparams
; iparams
++)
2054 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2056 /* Set last entry in argument type vector. */
2057 if (TYPE_FLAGS (die
->type
) & TYPE_FLAG_VARARGS
)
2058 arg_types
[nparams
] = NULL
;
2060 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2062 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2064 /* Handle static member functions.
2065 Dwarf2 has no clean way to discern C++ static and non-static
2066 member functions. G++ helps GDB by marking the first
2067 parameter for non-static member functions (which is the
2068 this pointer) as artificial. We obtain this information
2069 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2070 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2071 fnp
->voffset
= VOFFSET_STATIC
;
2074 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2076 /* Get fcontext from DW_AT_containing_type if present. */
2077 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2078 fnp
->fcontext
= die_containing_type (die
, objfile
);
2080 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2081 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2083 /* Get accessibility. */
2084 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2087 switch (DW_UNSND (attr
))
2089 case DW_ACCESS_private
:
2090 fnp
->is_private
= 1;
2092 case DW_ACCESS_protected
:
2093 fnp
->is_protected
= 1;
2098 /* Get index in virtual function table if it is a virtual member function. */
2099 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2101 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
) + 2;
2104 /* Create the vector of member function fields, and attach it to the type. */
2107 dwarf2_attach_fn_fields_to_type (fip
, type
, objfile
)
2108 struct field_info
*fip
;
2110 struct objfile
*objfile
;
2112 struct fnfieldlist
*flp
;
2113 int total_length
= 0;
2116 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2117 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2118 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2120 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2122 struct nextfnfield
*nfp
= flp
->head
;
2123 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2126 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2127 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2128 fn_flp
->fn_fields
= (struct fn_field
*)
2129 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2130 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2131 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2133 total_length
+= flp
->length
;
2136 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2137 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2140 /* Called when we find the DIE that starts a structure or union scope
2141 (definition) to process all dies that define the members of the
2144 NOTE: we need to call struct_type regardless of whether or not the
2145 DIE has an at_name attribute, since it might be an anonymous
2146 structure or union. This gets the type entered into our set of
2149 However, if the structure is incomplete (an opaque struct/union)
2150 then suppress creating a symbol table entry for it since gdb only
2151 wants to find the one with the complete definition. Note that if
2152 it is complete, we just call new_symbol, which does it's own
2153 checking about whether the struct/union is anonymous or not (and
2154 suppresses creating a symbol table entry itself). */
2157 read_structure_scope (die
, objfile
)
2158 struct die_info
*die
;
2159 struct objfile
*objfile
;
2162 struct attribute
*attr
;
2164 type
= alloc_type (objfile
);
2166 INIT_CPLUS_SPECIFIC (type
);
2167 attr
= dwarf_attr (die
, DW_AT_name
);
2168 if (attr
&& DW_STRING (attr
))
2170 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2171 strlen (DW_STRING (attr
)),
2172 &objfile
->type_obstack
);
2175 if (die
->tag
== DW_TAG_structure_type
)
2177 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2179 else if (die
->tag
== DW_TAG_union_type
)
2181 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2185 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2187 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2190 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2193 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2197 TYPE_LENGTH (type
) = 0;
2200 /* We need to add the type field to the die immediately so we don't
2201 infinitely recurse when dealing with pointers to the structure
2202 type within the structure itself. */
2205 if (die
->has_children
)
2207 struct field_info fi
;
2208 struct die_info
*child_die
;
2209 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2211 memset (&fi
, 0, sizeof (struct field_info
));
2213 child_die
= die
->next
;
2215 while (child_die
&& child_die
->tag
)
2217 if (child_die
->tag
== DW_TAG_member
)
2219 dwarf2_add_field (&fi
, child_die
, objfile
);
2221 else if (child_die
->tag
== DW_TAG_variable
)
2223 /* C++ static member. */
2224 dwarf2_add_field (&fi
, child_die
, objfile
);
2226 else if (child_die
->tag
== DW_TAG_subprogram
)
2228 /* C++ member function. */
2229 process_die (child_die
, objfile
);
2230 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
);
2232 else if (child_die
->tag
== DW_TAG_inheritance
)
2234 /* C++ base class field. */
2235 dwarf2_add_field (&fi
, child_die
, objfile
);
2239 process_die (child_die
, objfile
);
2241 child_die
= sibling_die (child_die
);
2244 /* Attach fields and member functions to the type. */
2246 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2249 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2251 /* Get the type which refers to the base class (possibly this
2252 class itself) which contains the vtable pointer for the current
2253 class from the DW_AT_containing_type attribute. */
2255 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2257 struct type
*t
= die_containing_type (die
, objfile
);
2259 TYPE_VPTR_BASETYPE (type
) = t
;
2262 static const char vptr_name
[] =
2263 {'_', 'v', 'p', 't', 'r', '\0'};
2266 /* Our own class provides vtbl ptr. */
2267 for (i
= TYPE_NFIELDS (t
) - 1;
2268 i
>= TYPE_N_BASECLASSES (t
);
2271 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2273 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2274 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2276 TYPE_VPTR_FIELDNO (type
) = i
;
2281 /* Complain if virtual function table field not found. */
2282 if (i
< TYPE_N_BASECLASSES (t
))
2283 complain (&dwarf2_vtbl_not_found_complaint
,
2284 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2288 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2293 new_symbol (die
, type
, objfile
);
2295 do_cleanups (back_to
);
2299 /* No children, must be stub. */
2300 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2306 /* Given a pointer to a die which begins an enumeration, process all
2307 the dies that define the members of the enumeration.
2309 This will be much nicer in draft 6 of the DWARF spec when our
2310 members will be dies instead squished into the DW_AT_element_list
2313 NOTE: We reverse the order of the element list. */
2316 read_enumeration (die
, objfile
)
2317 struct die_info
*die
;
2318 struct objfile
*objfile
;
2320 struct die_info
*child_die
;
2322 struct field
*fields
;
2323 struct attribute
*attr
;
2326 int unsigned_enum
= 1;
2328 type
= alloc_type (objfile
);
2330 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2331 attr
= dwarf_attr (die
, DW_AT_name
);
2332 if (attr
&& DW_STRING (attr
))
2334 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2335 strlen (DW_STRING (attr
)),
2336 &objfile
->type_obstack
);
2339 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2342 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2346 TYPE_LENGTH (type
) = 0;
2351 if (die
->has_children
)
2353 child_die
= die
->next
;
2354 while (child_die
&& child_die
->tag
)
2356 if (child_die
->tag
!= DW_TAG_enumerator
)
2358 process_die (child_die
, objfile
);
2362 attr
= dwarf_attr (child_die
, DW_AT_name
);
2365 sym
= new_symbol (child_die
, type
, objfile
);
2366 if (SYMBOL_VALUE (sym
) < 0)
2369 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2371 fields
= (struct field
*)
2373 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2374 * sizeof (struct field
));
2377 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2378 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2379 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2380 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2386 child_die
= sibling_die (child_die
);
2391 TYPE_NFIELDS (type
) = num_fields
;
2392 TYPE_FIELDS (type
) = (struct field
*)
2393 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2394 memcpy (TYPE_FIELDS (type
), fields
,
2395 sizeof (struct field
) * num_fields
);
2399 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2402 new_symbol (die
, type
, objfile
);
2405 /* Extract all information from a DW_TAG_array_type DIE and put it in
2406 the DIE's type field. For now, this only handles one dimensional
2410 read_array_type (die
, objfile
)
2411 struct die_info
*die
;
2412 struct objfile
*objfile
;
2414 struct die_info
*child_die
;
2415 struct type
*type
= NULL
;
2416 struct type
*element_type
, *range_type
, *index_type
;
2417 struct type
**range_types
= NULL
;
2418 struct attribute
*attr
;
2420 struct cleanup
*back_to
;
2422 /* Return if we've already decoded this type. */
2428 element_type
= die_type (die
, objfile
);
2430 /* Irix 6.2 native cc creates array types without children for
2431 arrays with unspecified length. */
2432 if (die
->has_children
== 0)
2434 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2435 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2436 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2440 back_to
= make_cleanup (null_cleanup
, NULL
);
2441 child_die
= die
->next
;
2442 while (child_die
&& child_die
->tag
)
2444 if (child_die
->tag
== DW_TAG_subrange_type
)
2446 unsigned int low
, high
;
2448 /* Default bounds to an array with unspecified length. */
2451 if (cu_language
== language_fortran
)
2453 /* FORTRAN implies a lower bound of 1, if not given. */
2457 index_type
= die_type (child_die
, objfile
);
2458 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2461 if (attr
->form
== DW_FORM_sdata
)
2463 low
= DW_SND (attr
);
2465 else if (attr
->form
== DW_FORM_udata
2466 || attr
->form
== DW_FORM_data1
2467 || attr
->form
== DW_FORM_data2
2468 || attr
->form
== DW_FORM_data4
)
2470 low
= DW_UNSND (attr
);
2474 complain (&dwarf2_non_const_array_bound_ignored
,
2475 dwarf_form_name (attr
->form
));
2477 die
->type
= lookup_pointer_type (element_type
);
2484 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2487 if (attr
->form
== DW_FORM_sdata
)
2489 high
= DW_SND (attr
);
2491 else if (attr
->form
== DW_FORM_udata
2492 || attr
->form
== DW_FORM_data1
2493 || attr
->form
== DW_FORM_data2
2494 || attr
->form
== DW_FORM_data4
)
2496 high
= DW_UNSND (attr
);
2498 else if (attr
->form
== DW_FORM_block1
)
2500 /* GCC encodes arrays with unspecified or dynamic length
2501 with a DW_FORM_block1 attribute.
2502 FIXME: GDB does not yet know how to handle dynamic
2503 arrays properly, treat them as arrays with unspecified
2509 complain (&dwarf2_non_const_array_bound_ignored
,
2510 dwarf_form_name (attr
->form
));
2512 die
->type
= lookup_pointer_type (element_type
);
2520 /* Create a range type and save it for array type creation. */
2521 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2523 range_types
= (struct type
**)
2524 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2525 * sizeof (struct type
*));
2527 make_cleanup ((make_cleanup_func
) free_current_contents
,
2530 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2532 child_die
= sibling_die (child_die
);
2535 /* Dwarf2 dimensions are output from left to right, create the
2536 necessary array types in backwards order. */
2537 type
= element_type
;
2539 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2541 do_cleanups (back_to
);
2543 /* Install the type in the die. */
2547 /* First cut: install each common block member as a global variable. */
2550 read_common_block (die
, objfile
)
2551 struct die_info
*die
;
2552 struct objfile
*objfile
;
2554 struct die_info
*child_die
;
2555 struct attribute
*attr
;
2557 CORE_ADDR base
= (CORE_ADDR
) 0;
2559 attr
= dwarf_attr (die
, DW_AT_location
);
2562 base
= decode_locdesc (DW_BLOCK (attr
), objfile
);
2564 if (die
->has_children
)
2566 child_die
= die
->next
;
2567 while (child_die
&& child_die
->tag
)
2569 sym
= new_symbol (child_die
, NULL
, objfile
);
2570 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2573 SYMBOL_VALUE_ADDRESS (sym
) =
2574 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
);
2575 add_symbol_to_list (sym
, &global_symbols
);
2577 child_die
= sibling_die (child_die
);
2582 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2583 the user defined type vector. */
2586 read_tag_pointer_type (die
, objfile
)
2587 struct die_info
*die
;
2588 struct objfile
*objfile
;
2591 struct attribute
*attr
;
2598 type
= lookup_pointer_type (die_type (die
, objfile
));
2599 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2602 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2606 TYPE_LENGTH (type
) = address_size
;
2611 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2612 the user defined type vector. */
2615 read_tag_ptr_to_member_type (die
, objfile
)
2616 struct die_info
*die
;
2617 struct objfile
*objfile
;
2620 struct type
*to_type
;
2621 struct type
*domain
;
2628 type
= alloc_type (objfile
);
2629 to_type
= die_type (die
, objfile
);
2630 domain
= die_containing_type (die
, objfile
);
2631 smash_to_member_type (type
, domain
, to_type
);
2636 /* Extract all information from a DW_TAG_reference_type DIE and add to
2637 the user defined type vector. */
2640 read_tag_reference_type (die
, objfile
)
2641 struct die_info
*die
;
2642 struct objfile
*objfile
;
2645 struct attribute
*attr
;
2652 type
= lookup_reference_type (die_type (die
, objfile
));
2653 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2656 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2660 TYPE_LENGTH (type
) = address_size
;
2666 read_tag_const_type (die
, objfile
)
2667 struct die_info
*die
;
2668 struct objfile
*objfile
;
2675 complain (&dwarf2_const_ignored
);
2676 die
->type
= die_type (die
, objfile
);
2680 read_tag_volatile_type (die
, objfile
)
2681 struct die_info
*die
;
2682 struct objfile
*objfile
;
2689 complain (&dwarf2_volatile_ignored
);
2690 die
->type
= die_type (die
, objfile
);
2693 /* Extract all information from a DW_TAG_string_type DIE and add to
2694 the user defined type vector. It isn't really a user defined type,
2695 but it behaves like one, with other DIE's using an AT_user_def_type
2696 attribute to reference it. */
2699 read_tag_string_type (die
, objfile
)
2700 struct die_info
*die
;
2701 struct objfile
*objfile
;
2703 struct type
*type
, *range_type
, *index_type
, *char_type
;
2704 struct attribute
*attr
;
2705 unsigned int length
;
2712 attr
= dwarf_attr (die
, DW_AT_string_length
);
2715 length
= DW_UNSND (attr
);
2721 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2722 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2723 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2724 type
= create_string_type (char_type
, range_type
);
2728 /* Handle DIES due to C code like:
2732 int (*funcp)(int a, long l);
2736 ('funcp' generates a DW_TAG_subroutine_type DIE)
2740 read_subroutine_type (die
, objfile
)
2741 struct die_info
*die
;
2742 struct objfile
*objfile
;
2744 struct type
*type
; /* Type that this function returns */
2745 struct type
*ftype
; /* Function that returns above type */
2746 struct attribute
*attr
;
2748 /* Decode the type that this subroutine returns */
2753 type
= die_type (die
, objfile
);
2754 ftype
= lookup_function_type (type
);
2756 /* All functions in C++ have prototypes. */
2757 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2758 if ((attr
&& (DW_UNSND (attr
) != 0))
2759 || cu_language
== language_cplus
)
2760 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2762 if (die
->has_children
)
2764 struct die_info
*child_die
;
2768 /* Count the number of parameters.
2769 FIXME: GDB currently ignores vararg functions, but knows about
2770 vararg member functions. */
2771 child_die
= die
->next
;
2772 while (child_die
&& child_die
->tag
)
2774 if (child_die
->tag
== DW_TAG_formal_parameter
)
2776 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2777 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2778 child_die
= sibling_die (child_die
);
2781 /* Allocate storage for parameters and fill them in. */
2782 TYPE_NFIELDS (ftype
) = nparams
;
2783 TYPE_FIELDS (ftype
) = (struct field
*)
2784 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2786 child_die
= die
->next
;
2787 while (child_die
&& child_die
->tag
)
2789 if (child_die
->tag
== DW_TAG_formal_parameter
)
2791 /* Dwarf2 has no clean way to discern C++ static and non-static
2792 member functions. G++ helps GDB by marking the first
2793 parameter for non-static member functions (which is the
2794 this pointer) as artificial. We pass this information
2795 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2796 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2798 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2800 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2801 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
);
2804 child_die
= sibling_die (child_die
);
2812 read_typedef (die
, objfile
)
2813 struct die_info
*die
;
2814 struct objfile
*objfile
;
2820 struct attribute
*attr
;
2823 xtype
= die_type (die
, objfile
);
2825 type
= alloc_type (objfile
);
2826 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2827 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2828 TYPE_TARGET_TYPE (type
) = xtype
;
2829 attr
= dwarf_attr (die
, DW_AT_name
);
2830 if (attr
&& DW_STRING (attr
))
2831 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2832 strlen (DW_STRING (attr
)),
2833 &objfile
->type_obstack
);
2839 /* Find a representation of a given base type and install
2840 it in the TYPE field of the die. */
2843 read_base_type (die
, objfile
)
2844 struct die_info
*die
;
2845 struct objfile
*objfile
;
2848 struct attribute
*attr
;
2849 int encoding
= 0, size
= 0;
2851 /* If we've already decoded this die, this is a no-op. */
2857 attr
= dwarf_attr (die
, DW_AT_encoding
);
2860 encoding
= DW_UNSND (attr
);
2862 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2865 size
= DW_UNSND (attr
);
2867 attr
= dwarf_attr (die
, DW_AT_name
);
2868 if (attr
&& DW_STRING (attr
))
2870 enum type_code code
= TYPE_CODE_INT
;
2871 int is_unsigned
= 0;
2875 case DW_ATE_address
:
2876 /* Turn DW_ATE_address into a void * pointer. */
2877 code
= TYPE_CODE_PTR
;
2880 case DW_ATE_boolean
:
2881 code
= TYPE_CODE_BOOL
;
2884 case DW_ATE_complex_float
:
2885 code
= TYPE_CODE_COMPLEX
;
2888 code
= TYPE_CODE_FLT
;
2891 case DW_ATE_signed_char
:
2893 case DW_ATE_unsigned
:
2894 case DW_ATE_unsigned_char
:
2898 complain (&dwarf2_unsupported_at_encoding
,
2899 dwarf_type_encoding_name (encoding
));
2902 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2903 if (encoding
== DW_ATE_address
)
2904 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2908 type
= dwarf_base_type (encoding
, size
, objfile
);
2913 /* Read a whole compilation unit into a linked list of dies. */
2916 read_comp_unit (info_ptr
, abfd
)
2920 struct die_info
*first_die
, *last_die
, *die
;
2924 /* Reset die reference table, we are building a new one now. */
2925 dwarf2_empty_die_ref_table ();
2929 first_die
= last_die
= NULL
;
2932 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
);
2933 if (die
->has_children
)
2944 /* Enter die in reference hash table */
2945 store_in_ref_table (die
->offset
, die
);
2949 first_die
= last_die
= die
;
2953 last_die
->next
= die
;
2957 while (nesting_level
> 0);
2961 /* Free a linked list of dies. */
2964 free_die_list (dies
)
2965 struct die_info
*dies
;
2967 struct die_info
*die
, *next
;
2979 /* Read the contents of the section at OFFSET and of size SIZE from the
2980 object file specified by OBJFILE into the psymbol_obstack and return it. */
2983 dwarf2_read_section (objfile
, offset
, size
)
2984 struct objfile
*objfile
;
2988 bfd
*abfd
= objfile
->obfd
;
2994 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
2995 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
2996 (bfd_read (buf
, size
, 1, abfd
) != size
))
2999 error ("Dwarf Error: Can't read DWARF data from '%s'",
3000 bfd_get_filename (abfd
));
3005 /* In DWARF version 2, the description of the debugging information is
3006 stored in a separate .debug_abbrev section. Before we read any
3007 dies from a section we read in all abbreviations and install them
3011 dwarf2_read_abbrevs (abfd
, offset
)
3013 unsigned int offset
;
3016 struct abbrev_info
*cur_abbrev
;
3017 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3018 unsigned int abbrev_form
, hash_number
;
3020 /* empty the table */
3021 dwarf2_empty_abbrev_table (NULL
);
3023 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3024 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3025 abbrev_ptr
+= bytes_read
;
3027 /* loop until we reach an abbrev number of 0 */
3028 while (abbrev_number
)
3030 cur_abbrev
= dwarf_alloc_abbrev ();
3032 /* read in abbrev header */
3033 cur_abbrev
->number
= abbrev_number
;
3034 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3035 abbrev_ptr
+= bytes_read
;
3036 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3039 /* now read in declarations */
3040 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3041 abbrev_ptr
+= bytes_read
;
3042 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3043 abbrev_ptr
+= bytes_read
;
3046 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3048 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3049 xrealloc (cur_abbrev
->attrs
,
3050 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3051 * sizeof (struct attr_abbrev
));
3053 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3054 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3055 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3056 abbrev_ptr
+= bytes_read
;
3057 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3058 abbrev_ptr
+= bytes_read
;
3061 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3062 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3063 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3065 /* Get next abbreviation.
3066 Under Irix6 the abbreviations for a compilation unit are not
3067 always properly terminated with an abbrev number of 0.
3068 Exit loop if we encounter an abbreviation which we have
3069 already read (which means we are about to read the abbreviations
3070 for the next compile unit) or if the end of the abbreviation
3071 table is reached. */
3072 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3073 >= dwarf_abbrev_size
)
3075 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3076 abbrev_ptr
+= bytes_read
;
3077 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3082 /* Empty the abbrev table for a new compilation unit. */
3086 dwarf2_empty_abbrev_table (ignore
)
3090 struct abbrev_info
*abbrev
, *next
;
3092 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3095 abbrev
= dwarf2_abbrevs
[i
];
3098 next
= abbrev
->next
;
3099 free (abbrev
->attrs
);
3103 dwarf2_abbrevs
[i
] = NULL
;
3107 /* Lookup an abbrev_info structure in the abbrev hash table. */
3109 static struct abbrev_info
*
3110 dwarf2_lookup_abbrev (number
)
3111 unsigned int number
;
3113 unsigned int hash_number
;
3114 struct abbrev_info
*abbrev
;
3116 hash_number
= number
% ABBREV_HASH_SIZE
;
3117 abbrev
= dwarf2_abbrevs
[hash_number
];
3121 if (abbrev
->number
== number
)
3124 abbrev
= abbrev
->next
;
3129 /* Read a minimal amount of information into the minimal die structure. */
3132 read_partial_die (part_die
, abfd
, info_ptr
, has_pc_info
)
3133 struct partial_die_info
*part_die
;
3138 unsigned int abbrev_number
, bytes_read
, i
;
3139 struct abbrev_info
*abbrev
;
3140 struct attribute attr
;
3141 struct attribute spec_attr
;
3142 int found_spec_attr
= 0;
3143 int has_low_pc_attr
= 0;
3144 int has_high_pc_attr
= 0;
3146 *part_die
= zeroed_partial_die
;
3148 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3149 info_ptr
+= bytes_read
;
3153 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3156 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3158 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3159 part_die
->tag
= abbrev
->tag
;
3160 part_die
->has_children
= abbrev
->has_children
;
3161 part_die
->abbrev
= abbrev_number
;
3163 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3165 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
);
3167 /* Store the data if it is of an attribute we want to keep in a
3168 partial symbol table. */
3173 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3174 if (part_die
->name
== NULL
)
3175 part_die
->name
= DW_STRING (&attr
);
3177 case DW_AT_MIPS_linkage_name
:
3178 part_die
->name
= DW_STRING (&attr
);
3181 has_low_pc_attr
= 1;
3182 part_die
->lowpc
= DW_ADDR (&attr
);
3185 has_high_pc_attr
= 1;
3186 part_die
->highpc
= DW_ADDR (&attr
);
3188 case DW_AT_location
:
3189 part_die
->locdesc
= DW_BLOCK (&attr
);
3191 case DW_AT_language
:
3192 part_die
->language
= DW_UNSND (&attr
);
3194 case DW_AT_external
:
3195 part_die
->is_external
= DW_UNSND (&attr
);
3197 case DW_AT_declaration
:
3198 part_die
->is_declaration
= DW_UNSND (&attr
);
3201 part_die
->has_type
= 1;
3203 case DW_AT_abstract_origin
:
3204 case DW_AT_specification
:
3205 found_spec_attr
= 1;
3209 /* Ignore absolute siblings, they might point outside of
3210 the current compile unit. */
3211 if (attr
.form
== DW_FORM_ref_addr
)
3212 complain (&dwarf2_absolute_sibling_complaint
);
3215 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3222 /* If we found a reference attribute and the die has no name, try
3223 to find a name in the referred to die. */
3225 if (found_spec_attr
&& part_die
->name
== NULL
)
3227 struct partial_die_info spec_die
;
3231 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3232 read_partial_die (&spec_die
, abfd
, spec_ptr
, &dummy
);
3235 part_die
->name
= spec_die
.name
;
3237 /* Copy DW_AT_external attribute if it is set. */
3238 if (spec_die
.is_external
)
3239 part_die
->is_external
= spec_die
.is_external
;
3243 /* When using the GNU linker, .gnu.linkonce. sections are used to
3244 eliminate duplicate copies of functions and vtables and such.
3245 The linker will arbitrarily choose one and discard the others.
3246 The AT_*_pc values for such functions refer to local labels in
3247 these sections. If the section from that file was discarded, the
3248 labels are not in the output, so the relocs get a value of 0.
3249 If this is a discarded function, mark the pc bounds as invalid,
3250 so that GDB will ignore it. */
3251 if (has_low_pc_attr
&& has_high_pc_attr
3252 && part_die
->lowpc
< part_die
->highpc
3253 && (part_die
->lowpc
!= 0
3254 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3259 /* Read the die from the .debug_info section buffer. And set diep to
3260 point to a newly allocated die with its information. */
3263 read_full_die (diep
, abfd
, info_ptr
)
3264 struct die_info
**diep
;
3268 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3269 struct abbrev_info
*abbrev
;
3270 struct die_info
*die
;
3272 offset
= info_ptr
- dwarf_info_buffer
;
3273 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3274 info_ptr
+= bytes_read
;
3277 die
= dwarf_alloc_die ();
3279 die
->abbrev
= abbrev_number
;
3285 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3288 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3290 die
= dwarf_alloc_die ();
3291 die
->offset
= offset
;
3292 die
->tag
= abbrev
->tag
;
3293 die
->has_children
= abbrev
->has_children
;
3294 die
->abbrev
= abbrev_number
;
3297 die
->num_attrs
= abbrev
->num_attrs
;
3298 die
->attrs
= (struct attribute
*)
3299 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3301 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3303 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3311 /* Read an attribute described by an abbreviated attribute. */
3314 read_attribute (attr
, abbrev
, abfd
, info_ptr
)
3315 struct attribute
*attr
;
3316 struct attr_abbrev
*abbrev
;
3320 unsigned int bytes_read
;
3321 struct dwarf_block
*blk
;
3323 attr
->name
= abbrev
->name
;
3324 attr
->form
= abbrev
->form
;
3325 switch (abbrev
->form
)
3328 case DW_FORM_ref_addr
:
3329 DW_ADDR (attr
) = read_address (abfd
, info_ptr
);
3330 info_ptr
+= address_size
;
3332 case DW_FORM_block2
:
3333 blk
= dwarf_alloc_block ();
3334 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3336 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3337 info_ptr
+= blk
->size
;
3338 DW_BLOCK (attr
) = blk
;
3340 case DW_FORM_block4
:
3341 blk
= dwarf_alloc_block ();
3342 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3344 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3345 info_ptr
+= blk
->size
;
3346 DW_BLOCK (attr
) = blk
;
3349 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3353 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3357 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3360 case DW_FORM_string
:
3361 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3362 info_ptr
+= bytes_read
;
3365 blk
= dwarf_alloc_block ();
3366 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3367 info_ptr
+= bytes_read
;
3368 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3369 info_ptr
+= blk
->size
;
3370 DW_BLOCK (attr
) = blk
;
3372 case DW_FORM_block1
:
3373 blk
= dwarf_alloc_block ();
3374 blk
->size
= read_1_byte (abfd
, info_ptr
);
3376 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3377 info_ptr
+= blk
->size
;
3378 DW_BLOCK (attr
) = blk
;
3381 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3385 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3389 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3390 info_ptr
+= bytes_read
;
3393 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3394 info_ptr
+= bytes_read
;
3397 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3401 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3405 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3408 case DW_FORM_ref_udata
:
3409 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3410 info_ptr
+= bytes_read
;
3413 case DW_FORM_indirect
:
3415 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3416 dwarf_form_name (abbrev
->form
));
3421 /* read dwarf information from a buffer */
3424 read_1_byte (abfd
, buf
)
3428 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3432 read_1_signed_byte (abfd
, buf
)
3436 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3440 read_2_bytes (abfd
, buf
)
3444 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3448 read_2_signed_bytes (abfd
, buf
)
3452 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3456 read_4_bytes (abfd
, buf
)
3460 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3464 read_4_signed_bytes (abfd
, buf
)
3468 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3472 read_8_bytes (abfd
, buf
)
3476 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3480 read_address (abfd
, buf
)
3484 CORE_ADDR retval
= 0;
3486 switch (address_size
)
3489 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3492 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3495 /* *THE* alternative is 8, right? */
3498 /* If the address being read is larger than the address that is
3499 applicable for the object file format then mask it down to the
3500 correct size. Take care to avoid unnecessary shift or shift
3502 if (address_size
> address_significant_size
3503 && address_significant_size
< sizeof (CORE_ADDR
))
3505 CORE_ADDR mask
= ((CORE_ADDR
) 0) - 1;
3506 retval
&= ~(mask
<< (address_significant_size
* 8));
3512 read_n_bytes (abfd
, buf
, size
)
3517 /* If the size of a host char is 8 bits, we can return a pointer
3518 to the buffer, otherwise we have to copy the data to a buffer
3519 allocated on the temporary obstack. */
3520 #if HOST_CHAR_BIT == 8
3526 ret
= obstack_alloc (&dwarf2_tmp_obstack
, size
);
3527 for (i
= 0; i
< size
; ++i
)
3529 ret
[i
] = bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3537 read_string (abfd
, buf
, bytes_read_ptr
)
3540 unsigned int *bytes_read_ptr
;
3542 /* If the size of a host char is 8 bits, we can return a pointer
3543 to the string, otherwise we have to copy the string to a buffer
3544 allocated on the temporary obstack. */
3545 #if HOST_CHAR_BIT == 8
3548 *bytes_read_ptr
= 1;
3551 *bytes_read_ptr
= strlen (buf
) + 1;
3557 while ((byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
)) != 0)
3559 obstack_1grow (&dwarf2_tmp_obstack
, byte
);
3565 *bytes_read_ptr
= 1;
3568 obstack_1grow (&dwarf2_tmp_obstack
, '\0');
3569 *bytes_read_ptr
= i
+ 1;
3570 return obstack_finish (&dwarf2_tmp_obstack
);
3575 read_unsigned_leb128 (abfd
, buf
, bytes_read_ptr
)
3578 unsigned int *bytes_read_ptr
;
3580 unsigned int result
, num_read
;
3590 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3593 result
|= ((byte
& 127) << shift
);
3594 if ((byte
& 128) == 0)
3600 *bytes_read_ptr
= num_read
;
3605 read_signed_leb128 (abfd
, buf
, bytes_read_ptr
)
3608 unsigned int *bytes_read_ptr
;
3611 int i
, shift
, size
, num_read
;
3621 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3624 result
|= ((byte
& 127) << shift
);
3626 if ((byte
& 128) == 0)
3631 if ((shift
< size
) && (byte
& 0x40))
3633 result
|= -(1 << shift
);
3635 *bytes_read_ptr
= num_read
;
3640 set_cu_language (lang
)
3647 cu_language
= language_c
;
3649 case DW_LANG_C_plus_plus
:
3650 cu_language
= language_cplus
;
3652 case DW_LANG_Fortran77
:
3653 case DW_LANG_Fortran90
:
3654 cu_language
= language_fortran
;
3656 case DW_LANG_Mips_Assembler
:
3657 cu_language
= language_asm
;
3660 case DW_LANG_Cobol74
:
3661 case DW_LANG_Cobol85
:
3662 case DW_LANG_Pascal83
:
3663 case DW_LANG_Modula2
:
3665 cu_language
= language_unknown
;
3668 cu_language_defn
= language_def (cu_language
);
3671 /* Return the named attribute or NULL if not there. */
3673 static struct attribute
*
3674 dwarf_attr (die
, name
)
3675 struct die_info
*die
;
3679 struct attribute
*spec
= NULL
;
3681 for (i
= 0; i
< die
->num_attrs
; ++i
)
3683 if (die
->attrs
[i
].name
== name
)
3685 return &die
->attrs
[i
];
3687 if (die
->attrs
[i
].name
== DW_AT_specification
3688 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3689 spec
= &die
->attrs
[i
];
3693 struct die_info
*ref_die
=
3694 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3697 return dwarf_attr (ref_die
, name
);
3703 /* Decode the line number information for the compilation unit whose
3704 line number info is at OFFSET in the .debug_line section.
3705 The compilation directory of the file is passed in COMP_DIR. */
3709 unsigned int num_files
;
3722 unsigned int num_dirs
;
3727 dwarf_decode_lines (offset
, comp_dir
, abfd
)
3728 unsigned int offset
;
3734 struct line_head lh
;
3735 struct cleanup
*back_to
;
3736 unsigned int i
, bytes_read
;
3737 char *cur_file
, *cur_dir
;
3738 unsigned char op_code
, extended_op
, adj_opcode
;
3740 #define FILE_ALLOC_CHUNK 5
3741 #define DIR_ALLOC_CHUNK 5
3743 struct filenames files
;
3744 struct directories dirs
;
3746 if (dwarf_line_buffer
== NULL
)
3748 complain (&dwarf2_missing_line_number_section
);
3752 files
.num_files
= 0;
3758 line_ptr
= dwarf_line_buffer
+ offset
;
3760 /* read in the prologue */
3761 lh
.total_length
= read_4_bytes (abfd
, line_ptr
);
3763 line_end
= line_ptr
+ lh
.total_length
;
3764 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3766 lh
.prologue_length
= read_4_bytes (abfd
, line_ptr
);
3768 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3770 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3772 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3774 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3776 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3778 lh
.standard_opcode_lengths
= (unsigned char *)
3779 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3780 back_to
= make_cleanup ((make_cleanup_func
) free_current_contents
,
3781 &lh
.standard_opcode_lengths
);
3783 lh
.standard_opcode_lengths
[0] = 1;
3784 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3786 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3790 /* Read directory table */
3791 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3793 line_ptr
+= bytes_read
;
3794 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3796 dirs
.dirs
= (char **)
3797 xrealloc (dirs
.dirs
,
3798 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3799 if (dirs
.num_dirs
== 0)
3800 make_cleanup ((make_cleanup_func
) free_current_contents
, &dirs
.dirs
);
3802 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3804 line_ptr
+= bytes_read
;
3806 /* Read file name table */
3807 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3809 line_ptr
+= bytes_read
;
3810 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3812 files
.files
= (struct fileinfo
*)
3813 xrealloc (files
.files
,
3814 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3815 * sizeof (struct fileinfo
));
3816 if (files
.num_files
== 0)
3817 make_cleanup ((make_cleanup_func
) free_current_contents
,
3820 files
.files
[files
.num_files
].name
= cur_file
;
3821 files
.files
[files
.num_files
].dir
=
3822 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3823 line_ptr
+= bytes_read
;
3824 files
.files
[files
.num_files
].time
=
3825 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3826 line_ptr
+= bytes_read
;
3827 files
.files
[files
.num_files
].size
=
3828 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3829 line_ptr
+= bytes_read
;
3832 line_ptr
+= bytes_read
;
3834 /* Read the statement sequences until there's nothing left. */
3835 while (line_ptr
< line_end
)
3837 /* state machine registers */
3838 CORE_ADDR address
= 0;
3839 unsigned int file
= 1;
3840 unsigned int line
= 1;
3841 unsigned int column
= 0;
3842 int is_stmt
= lh
.default_is_stmt
;
3843 int basic_block
= 0;
3844 int end_sequence
= 0;
3846 /* Start a subfile for the current file of the state machine. */
3847 if (files
.num_files
>= file
)
3849 /* The file and directory tables are 0 based, the references
3851 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3852 (files
.files
[file
- 1].dir
3853 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3857 /* Decode the table. */
3858 while (!end_sequence
)
3860 op_code
= read_1_byte (abfd
, line_ptr
);
3864 case DW_LNS_extended_op
:
3865 line_ptr
+= 1; /* ignore length */
3866 extended_op
= read_1_byte (abfd
, line_ptr
);
3868 switch (extended_op
)
3870 case DW_LNE_end_sequence
:
3872 /* Don't call record_line here. The end_sequence
3873 instruction provides the address of the first byte
3874 *after* the last line in the sequence; it's not the
3875 address of any real source line. However, the GDB
3876 linetable structure only records the starts of lines,
3877 not the ends. This is a weakness of GDB. */
3879 case DW_LNE_set_address
:
3880 address
= read_address (abfd
, line_ptr
) + baseaddr
;
3881 line_ptr
+= address_size
;
3883 case DW_LNE_define_file
:
3884 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
3885 line_ptr
+= bytes_read
;
3886 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3888 files
.files
= (struct fileinfo
*)
3889 xrealloc (files
.files
,
3890 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3891 * sizeof (struct fileinfo
));
3892 if (files
.num_files
== 0)
3893 make_cleanup ((make_cleanup_func
) free_current_contents
,
3896 files
.files
[files
.num_files
].name
= cur_file
;
3897 files
.files
[files
.num_files
].dir
=
3898 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3899 line_ptr
+= bytes_read
;
3900 files
.files
[files
.num_files
].time
=
3901 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3902 line_ptr
+= bytes_read
;
3903 files
.files
[files
.num_files
].size
=
3904 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3905 line_ptr
+= bytes_read
;
3909 complain (&dwarf2_mangled_line_number_section
);
3914 record_line (current_subfile
, line
, address
);
3917 case DW_LNS_advance_pc
:
3918 address
+= lh
.minimum_instruction_length
3919 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3920 line_ptr
+= bytes_read
;
3922 case DW_LNS_advance_line
:
3923 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
3924 line_ptr
+= bytes_read
;
3926 case DW_LNS_set_file
:
3927 /* The file and directory tables are 0 based, the references
3929 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3930 line_ptr
+= bytes_read
;
3931 dwarf2_start_subfile
3932 (files
.files
[file
- 1].name
,
3933 (files
.files
[file
- 1].dir
3934 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3937 case DW_LNS_set_column
:
3938 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3939 line_ptr
+= bytes_read
;
3941 case DW_LNS_negate_stmt
:
3942 is_stmt
= (!is_stmt
);
3944 case DW_LNS_set_basic_block
:
3947 /* Add to the address register of the state machine the
3948 address increment value corresponding to special opcode
3949 255. Ie, this value is scaled by the minimum instruction
3950 length since special opcode 255 would have scaled the
3952 case DW_LNS_const_add_pc
:
3953 address
+= (lh
.minimum_instruction_length
3954 * ((255 - lh
.opcode_base
) / lh
.line_range
));
3956 case DW_LNS_fixed_advance_pc
:
3957 address
+= read_2_bytes (abfd
, line_ptr
);
3960 default: /* special operand */
3961 adj_opcode
= op_code
- lh
.opcode_base
;
3962 address
+= (adj_opcode
/ lh
.line_range
)
3963 * lh
.minimum_instruction_length
;
3964 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
3965 /* append row to matrix using current values */
3966 record_line (current_subfile
, line
, address
);
3972 do_cleanups (back_to
);
3975 /* Start a subfile for DWARF. FILENAME is the name of the file and
3976 DIRNAME the name of the source directory which contains FILENAME
3977 or NULL if not known.
3978 This routine tries to keep line numbers from identical absolute and
3979 relative file names in a common subfile.
3981 Using the `list' example from the GDB testsuite, which resides in
3982 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
3983 of /srcdir/list0.c yields the following debugging information for list0.c:
3985 DW_AT_name: /srcdir/list0.c
3986 DW_AT_comp_dir: /compdir
3987 files.files[0].name: list0.h
3988 files.files[0].dir: /srcdir
3989 files.files[1].name: list0.c
3990 files.files[1].dir: /srcdir
3992 The line number information for list0.c has to end up in a single
3993 subfile, so that `break /srcdir/list0.c:1' works as expected. */
3996 dwarf2_start_subfile (filename
, dirname
)
4000 /* If the filename isn't absolute, try to match an existing subfile
4001 with the full pathname. */
4003 if (*filename
!= '/' && dirname
!= NULL
)
4005 struct subfile
*subfile
;
4006 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4008 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4010 if (STREQ (subfile
->name
, fullname
))
4012 current_subfile
= subfile
;
4019 start_subfile (filename
, dirname
);
4022 /* Given a pointer to a DWARF information entry, figure out if we need
4023 to make a symbol table entry for it, and if so, create a new entry
4024 and return a pointer to it.
4025 If TYPE is NULL, determine symbol type from the die, otherwise
4026 used the passed type. */
4028 static struct symbol
*
4029 new_symbol (die
, type
, objfile
)
4030 struct die_info
*die
;
4032 struct objfile
*objfile
;
4034 struct symbol
*sym
= NULL
;
4036 struct attribute
*attr
= NULL
;
4037 struct attribute
*attr2
= NULL
;
4040 name
= dwarf2_linkage_name (die
);
4043 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4044 sizeof (struct symbol
));
4045 OBJSTAT (objfile
, n_syms
++);
4046 memset (sym
, 0, sizeof (struct symbol
));
4047 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4048 &objfile
->symbol_obstack
);
4050 /* Default assumptions.
4051 Use the passed type or decode it from the die. */
4052 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4053 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4055 SYMBOL_TYPE (sym
) = type
;
4057 SYMBOL_TYPE (sym
) = die_type (die
, objfile
);
4058 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4061 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4064 /* If this symbol is from a C++ compilation, then attempt to
4065 cache the demangled form for future reference. This is a
4066 typical time versus space tradeoff, that was decided in favor
4067 of time because it sped up C++ symbol lookups by a factor of
4070 SYMBOL_LANGUAGE (sym
) = cu_language
;
4071 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4075 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4078 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4080 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4082 case DW_TAG_subprogram
:
4083 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4085 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4086 attr2
= dwarf_attr (die
, DW_AT_external
);
4087 if (attr2
&& (DW_UNSND (attr2
) != 0))
4089 add_symbol_to_list (sym
, &global_symbols
);
4093 add_symbol_to_list (sym
, list_in_scope
);
4096 case DW_TAG_variable
:
4097 /* Compilation with minimal debug info may result in variables
4098 with missing type entries. Change the misleading `void' type
4099 to something sensible. */
4100 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4101 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4102 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4103 "<variable, no debug info>",
4105 attr
= dwarf_attr (die
, DW_AT_const_value
);
4108 dwarf2_const_value (attr
, sym
, objfile
);
4109 attr2
= dwarf_attr (die
, DW_AT_external
);
4110 if (attr2
&& (DW_UNSND (attr2
) != 0))
4111 add_symbol_to_list (sym
, &global_symbols
);
4113 add_symbol_to_list (sym
, list_in_scope
);
4116 attr
= dwarf_attr (die
, DW_AT_location
);
4119 attr2
= dwarf_attr (die
, DW_AT_external
);
4120 if (attr2
&& (DW_UNSND (attr2
) != 0))
4122 SYMBOL_VALUE_ADDRESS (sym
) =
4123 decode_locdesc (DW_BLOCK (attr
), objfile
);
4124 add_symbol_to_list (sym
, &global_symbols
);
4126 /* In shared libraries the address of the variable
4127 in the location descriptor might still be relocatable,
4128 so its value could be zero.
4129 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4130 value is zero, the address of the variable will then
4131 be determined from the minimal symbol table whenever
4132 the variable is referenced. */
4133 if (SYMBOL_VALUE_ADDRESS (sym
))
4135 SYMBOL_VALUE_ADDRESS (sym
) += baseaddr
;
4136 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4139 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4143 SYMBOL_VALUE (sym
) = addr
=
4144 decode_locdesc (DW_BLOCK (attr
), objfile
);
4145 add_symbol_to_list (sym
, list_in_scope
);
4148 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4152 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4156 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4157 SYMBOL_BASEREG (sym
) = basereg
;
4161 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4165 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4166 SYMBOL_VALUE_ADDRESS (sym
) = addr
+ baseaddr
;
4172 /* We do not know the address of this symbol.
4173 If it is an external symbol and we have type information
4174 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4175 The address of the variable will then be determined from
4176 the minimal symbol table whenever the variable is
4178 attr2
= dwarf_attr (die
, DW_AT_external
);
4179 if (attr2
&& (DW_UNSND (attr2
) != 0)
4180 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4182 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4183 add_symbol_to_list (sym
, &global_symbols
);
4187 case DW_TAG_formal_parameter
:
4188 attr
= dwarf_attr (die
, DW_AT_location
);
4191 SYMBOL_VALUE (sym
) = decode_locdesc (DW_BLOCK (attr
), objfile
);
4194 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4200 if (basereg
!= frame_base_reg
)
4201 complain (&dwarf2_complex_location_expr
);
4202 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4206 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4207 SYMBOL_BASEREG (sym
) = basereg
;
4212 SYMBOL_CLASS (sym
) = LOC_ARG
;
4215 attr
= dwarf_attr (die
, DW_AT_const_value
);
4218 dwarf2_const_value (attr
, sym
, objfile
);
4220 add_symbol_to_list (sym
, list_in_scope
);
4222 case DW_TAG_unspecified_parameters
:
4223 /* From varargs functions; gdb doesn't seem to have any
4224 interest in this information, so just ignore it for now.
4227 case DW_TAG_class_type
:
4228 case DW_TAG_structure_type
:
4229 case DW_TAG_union_type
:
4230 case DW_TAG_enumeration_type
:
4231 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4232 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4233 add_symbol_to_list (sym
, list_in_scope
);
4235 /* The semantics of C++ state that "struct foo { ... }" also
4236 defines a typedef for "foo". Synthesize a typedef symbol so
4237 that "ptype foo" works as expected. */
4238 if (cu_language
== language_cplus
)
4240 struct symbol
*typedef_sym
= (struct symbol
*)
4241 obstack_alloc (&objfile
->symbol_obstack
,
4242 sizeof (struct symbol
));
4243 *typedef_sym
= *sym
;
4244 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4245 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4246 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4247 obsavestring (SYMBOL_NAME (sym
),
4248 strlen (SYMBOL_NAME (sym
)),
4249 &objfile
->type_obstack
);
4250 add_symbol_to_list (typedef_sym
, list_in_scope
);
4253 case DW_TAG_typedef
:
4254 case DW_TAG_base_type
:
4255 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4256 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4257 add_symbol_to_list (sym
, list_in_scope
);
4259 case DW_TAG_enumerator
:
4260 attr
= dwarf_attr (die
, DW_AT_const_value
);
4263 dwarf2_const_value (attr
, sym
, objfile
);
4265 add_symbol_to_list (sym
, list_in_scope
);
4268 /* Not a tag we recognize. Hopefully we aren't processing
4269 trash data, but since we must specifically ignore things
4270 we don't recognize, there is nothing else we should do at
4272 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4279 /* Copy constant value from an attribute to a symbol. */
4282 dwarf2_const_value (attr
, sym
, objfile
)
4283 struct attribute
*attr
;
4285 struct objfile
*objfile
;
4287 struct dwarf_block
*blk
;
4292 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != (unsigned int) address_size
)
4293 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4294 address_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4295 SYMBOL_VALUE_BYTES (sym
) = (char *)
4296 obstack_alloc (&objfile
->symbol_obstack
, address_size
);
4297 store_address (SYMBOL_VALUE_BYTES (sym
), address_size
, DW_ADDR (attr
));
4298 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4300 case DW_FORM_block1
:
4301 case DW_FORM_block2
:
4302 case DW_FORM_block4
:
4304 blk
= DW_BLOCK (attr
);
4305 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4306 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4307 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4308 SYMBOL_VALUE_BYTES (sym
) = (char *)
4309 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4310 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4311 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4314 /* The DW_AT_const_value attributes are supposed to carry the
4315 symbol's value "represented as it would be on the target
4316 architecture." By the time we get here, it's already been
4317 converted to host endianness, so we just need to sign- or
4318 zero-extend it as appropriate. */
4320 dwarf2_const_value_data (attr
, sym
, 8);
4323 dwarf2_const_value_data (attr
, sym
, 16);
4326 dwarf2_const_value_data (attr
, sym
, 32);
4329 dwarf2_const_value_data (attr
, sym
, 64);
4333 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4334 SYMBOL_CLASS (sym
) = LOC_CONST
;
4338 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4339 SYMBOL_CLASS (sym
) = LOC_CONST
;
4343 complain (&dwarf2_unsupported_const_value_attr
,
4344 dwarf_form_name (attr
->form
));
4345 SYMBOL_VALUE (sym
) = 0;
4346 SYMBOL_CLASS (sym
) = LOC_CONST
;
4352 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4353 or zero-extend it as appropriate for the symbol's type. */
4355 dwarf2_const_value_data (struct attribute
*attr
,
4359 LONGEST l
= DW_UNSND (attr
);
4361 if (bits
< sizeof (l
) * 8)
4363 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4364 l
&= ((LONGEST
) 1 << bits
) - 1;
4366 l
= (l
<< (sizeof (l
) - bits
)) >> (sizeof (l
) - bits
);
4369 SYMBOL_VALUE (sym
) = l
;
4370 SYMBOL_CLASS (sym
) = LOC_CONST
;
4374 /* Return the type of the die in question using its DW_AT_type attribute. */
4376 static struct type
*
4377 die_type (die
, objfile
)
4378 struct die_info
*die
;
4379 struct objfile
*objfile
;
4382 struct attribute
*type_attr
;
4383 struct die_info
*type_die
;
4386 type_attr
= dwarf_attr (die
, DW_AT_type
);
4389 /* A missing DW_AT_type represents a void type. */
4390 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4394 ref
= dwarf2_get_ref_die_offset (type_attr
);
4395 type_die
= follow_die_ref (ref
);
4398 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4402 type
= tag_type_to_type (type_die
, objfile
);
4405 dump_die (type_die
);
4406 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4411 /* Return the containing type of the die in question using its
4412 DW_AT_containing_type attribute. */
4414 static struct type
*
4415 die_containing_type (die
, objfile
)
4416 struct die_info
*die
;
4417 struct objfile
*objfile
;
4419 struct type
*type
= NULL
;
4420 struct attribute
*type_attr
;
4421 struct die_info
*type_die
= NULL
;
4424 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4427 ref
= dwarf2_get_ref_die_offset (type_attr
);
4428 type_die
= follow_die_ref (ref
);
4431 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4434 type
= tag_type_to_type (type_die
, objfile
);
4439 dump_die (type_die
);
4440 error ("Dwarf Error: Problem turning containing type into gdb type.");
4446 static struct type
*
4447 type_at_offset (offset
, objfile
)
4448 unsigned int offset
;
4449 struct objfile
*objfile
;
4451 struct die_info
*die
;
4454 die
= follow_die_ref (offset
);
4457 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4460 type
= tag_type_to_type (die
, objfile
);
4465 static struct type
*
4466 tag_type_to_type (die
, objfile
)
4467 struct die_info
*die
;
4468 struct objfile
*objfile
;
4476 read_type_die (die
, objfile
);
4480 error ("Dwarf Error: Cannot find type of die.");
4487 read_type_die (die
, objfile
)
4488 struct die_info
*die
;
4489 struct objfile
*objfile
;
4493 case DW_TAG_class_type
:
4494 case DW_TAG_structure_type
:
4495 case DW_TAG_union_type
:
4496 read_structure_scope (die
, objfile
);
4498 case DW_TAG_enumeration_type
:
4499 read_enumeration (die
, objfile
);
4501 case DW_TAG_subprogram
:
4502 case DW_TAG_subroutine_type
:
4503 read_subroutine_type (die
, objfile
);
4505 case DW_TAG_array_type
:
4506 read_array_type (die
, objfile
);
4508 case DW_TAG_pointer_type
:
4509 read_tag_pointer_type (die
, objfile
);
4511 case DW_TAG_ptr_to_member_type
:
4512 read_tag_ptr_to_member_type (die
, objfile
);
4514 case DW_TAG_reference_type
:
4515 read_tag_reference_type (die
, objfile
);
4517 case DW_TAG_const_type
:
4518 read_tag_const_type (die
, objfile
);
4520 case DW_TAG_volatile_type
:
4521 read_tag_volatile_type (die
, objfile
);
4523 case DW_TAG_string_type
:
4524 read_tag_string_type (die
, objfile
);
4526 case DW_TAG_typedef
:
4527 read_typedef (die
, objfile
);
4529 case DW_TAG_base_type
:
4530 read_base_type (die
, objfile
);
4533 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4538 static struct type
*
4539 dwarf_base_type (encoding
, size
, objfile
)
4542 struct objfile
*objfile
;
4544 /* FIXME - this should not produce a new (struct type *)
4545 every time. It should cache base types. */
4549 case DW_ATE_address
:
4550 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4552 case DW_ATE_boolean
:
4553 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4555 case DW_ATE_complex_float
:
4558 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4562 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4568 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4572 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4579 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4582 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4586 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4590 case DW_ATE_signed_char
:
4591 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4593 case DW_ATE_unsigned
:
4597 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4600 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4604 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4608 case DW_ATE_unsigned_char
:
4609 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4612 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4620 struct die_info
*old_die
;
4622 struct die_info
*new_die
;
4625 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4626 memset (new_die
, 0, sizeof (struct die_info
));
4628 new_die
->tag
= old_die
->tag
;
4629 new_die
->has_children
= old_die
->has_children
;
4630 new_die
->abbrev
= old_die
->abbrev
;
4631 new_die
->offset
= old_die
->offset
;
4632 new_die
->type
= NULL
;
4634 num_attrs
= old_die
->num_attrs
;
4635 new_die
->num_attrs
= num_attrs
;
4636 new_die
->attrs
= (struct attribute
*)
4637 xmalloc (num_attrs
* sizeof (struct attribute
));
4639 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4641 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4642 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4643 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4646 new_die
->next
= NULL
;
4651 /* Return sibling of die, NULL if no sibling. */
4655 struct die_info
*die
;
4657 int nesting_level
= 0;
4659 if (!die
->has_children
)
4661 if (die
->next
&& (die
->next
->tag
== 0))
4674 if (die
->has_children
)
4684 while (nesting_level
);
4685 if (die
&& (die
->tag
== 0))
4696 /* Get linkage name of a die, return NULL if not found. */
4699 dwarf2_linkage_name (die
)
4700 struct die_info
*die
;
4702 struct attribute
*attr
;
4704 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4705 if (attr
&& DW_STRING (attr
))
4706 return DW_STRING (attr
);
4707 attr
= dwarf_attr (die
, DW_AT_name
);
4708 if (attr
&& DW_STRING (attr
))
4709 return DW_STRING (attr
);
4713 /* Convert a DIE tag into its string name. */
4716 dwarf_tag_name (tag
)
4717 register unsigned tag
;
4721 case DW_TAG_padding
:
4722 return "DW_TAG_padding";
4723 case DW_TAG_array_type
:
4724 return "DW_TAG_array_type";
4725 case DW_TAG_class_type
:
4726 return "DW_TAG_class_type";
4727 case DW_TAG_entry_point
:
4728 return "DW_TAG_entry_point";
4729 case DW_TAG_enumeration_type
:
4730 return "DW_TAG_enumeration_type";
4731 case DW_TAG_formal_parameter
:
4732 return "DW_TAG_formal_parameter";
4733 case DW_TAG_imported_declaration
:
4734 return "DW_TAG_imported_declaration";
4736 return "DW_TAG_label";
4737 case DW_TAG_lexical_block
:
4738 return "DW_TAG_lexical_block";
4740 return "DW_TAG_member";
4741 case DW_TAG_pointer_type
:
4742 return "DW_TAG_pointer_type";
4743 case DW_TAG_reference_type
:
4744 return "DW_TAG_reference_type";
4745 case DW_TAG_compile_unit
:
4746 return "DW_TAG_compile_unit";
4747 case DW_TAG_string_type
:
4748 return "DW_TAG_string_type";
4749 case DW_TAG_structure_type
:
4750 return "DW_TAG_structure_type";
4751 case DW_TAG_subroutine_type
:
4752 return "DW_TAG_subroutine_type";
4753 case DW_TAG_typedef
:
4754 return "DW_TAG_typedef";
4755 case DW_TAG_union_type
:
4756 return "DW_TAG_union_type";
4757 case DW_TAG_unspecified_parameters
:
4758 return "DW_TAG_unspecified_parameters";
4759 case DW_TAG_variant
:
4760 return "DW_TAG_variant";
4761 case DW_TAG_common_block
:
4762 return "DW_TAG_common_block";
4763 case DW_TAG_common_inclusion
:
4764 return "DW_TAG_common_inclusion";
4765 case DW_TAG_inheritance
:
4766 return "DW_TAG_inheritance";
4767 case DW_TAG_inlined_subroutine
:
4768 return "DW_TAG_inlined_subroutine";
4770 return "DW_TAG_module";
4771 case DW_TAG_ptr_to_member_type
:
4772 return "DW_TAG_ptr_to_member_type";
4773 case DW_TAG_set_type
:
4774 return "DW_TAG_set_type";
4775 case DW_TAG_subrange_type
:
4776 return "DW_TAG_subrange_type";
4777 case DW_TAG_with_stmt
:
4778 return "DW_TAG_with_stmt";
4779 case DW_TAG_access_declaration
:
4780 return "DW_TAG_access_declaration";
4781 case DW_TAG_base_type
:
4782 return "DW_TAG_base_type";
4783 case DW_TAG_catch_block
:
4784 return "DW_TAG_catch_block";
4785 case DW_TAG_const_type
:
4786 return "DW_TAG_const_type";
4787 case DW_TAG_constant
:
4788 return "DW_TAG_constant";
4789 case DW_TAG_enumerator
:
4790 return "DW_TAG_enumerator";
4791 case DW_TAG_file_type
:
4792 return "DW_TAG_file_type";
4794 return "DW_TAG_friend";
4795 case DW_TAG_namelist
:
4796 return "DW_TAG_namelist";
4797 case DW_TAG_namelist_item
:
4798 return "DW_TAG_namelist_item";
4799 case DW_TAG_packed_type
:
4800 return "DW_TAG_packed_type";
4801 case DW_TAG_subprogram
:
4802 return "DW_TAG_subprogram";
4803 case DW_TAG_template_type_param
:
4804 return "DW_TAG_template_type_param";
4805 case DW_TAG_template_value_param
:
4806 return "DW_TAG_template_value_param";
4807 case DW_TAG_thrown_type
:
4808 return "DW_TAG_thrown_type";
4809 case DW_TAG_try_block
:
4810 return "DW_TAG_try_block";
4811 case DW_TAG_variant_part
:
4812 return "DW_TAG_variant_part";
4813 case DW_TAG_variable
:
4814 return "DW_TAG_variable";
4815 case DW_TAG_volatile_type
:
4816 return "DW_TAG_volatile_type";
4817 case DW_TAG_MIPS_loop
:
4818 return "DW_TAG_MIPS_loop";
4819 case DW_TAG_format_label
:
4820 return "DW_TAG_format_label";
4821 case DW_TAG_function_template
:
4822 return "DW_TAG_function_template";
4823 case DW_TAG_class_template
:
4824 return "DW_TAG_class_template";
4826 return "DW_TAG_<unknown>";
4830 /* Convert a DWARF attribute code into its string name. */
4833 dwarf_attr_name (attr
)
4834 register unsigned attr
;
4839 return "DW_AT_sibling";
4840 case DW_AT_location
:
4841 return "DW_AT_location";
4843 return "DW_AT_name";
4844 case DW_AT_ordering
:
4845 return "DW_AT_ordering";
4846 case DW_AT_subscr_data
:
4847 return "DW_AT_subscr_data";
4848 case DW_AT_byte_size
:
4849 return "DW_AT_byte_size";
4850 case DW_AT_bit_offset
:
4851 return "DW_AT_bit_offset";
4852 case DW_AT_bit_size
:
4853 return "DW_AT_bit_size";
4854 case DW_AT_element_list
:
4855 return "DW_AT_element_list";
4856 case DW_AT_stmt_list
:
4857 return "DW_AT_stmt_list";
4859 return "DW_AT_low_pc";
4861 return "DW_AT_high_pc";
4862 case DW_AT_language
:
4863 return "DW_AT_language";
4865 return "DW_AT_member";
4867 return "DW_AT_discr";
4868 case DW_AT_discr_value
:
4869 return "DW_AT_discr_value";
4870 case DW_AT_visibility
:
4871 return "DW_AT_visibility";
4873 return "DW_AT_import";
4874 case DW_AT_string_length
:
4875 return "DW_AT_string_length";
4876 case DW_AT_common_reference
:
4877 return "DW_AT_common_reference";
4878 case DW_AT_comp_dir
:
4879 return "DW_AT_comp_dir";
4880 case DW_AT_const_value
:
4881 return "DW_AT_const_value";
4882 case DW_AT_containing_type
:
4883 return "DW_AT_containing_type";
4884 case DW_AT_default_value
:
4885 return "DW_AT_default_value";
4887 return "DW_AT_inline";
4888 case DW_AT_is_optional
:
4889 return "DW_AT_is_optional";
4890 case DW_AT_lower_bound
:
4891 return "DW_AT_lower_bound";
4892 case DW_AT_producer
:
4893 return "DW_AT_producer";
4894 case DW_AT_prototyped
:
4895 return "DW_AT_prototyped";
4896 case DW_AT_return_addr
:
4897 return "DW_AT_return_addr";
4898 case DW_AT_start_scope
:
4899 return "DW_AT_start_scope";
4900 case DW_AT_stride_size
:
4901 return "DW_AT_stride_size";
4902 case DW_AT_upper_bound
:
4903 return "DW_AT_upper_bound";
4904 case DW_AT_abstract_origin
:
4905 return "DW_AT_abstract_origin";
4906 case DW_AT_accessibility
:
4907 return "DW_AT_accessibility";
4908 case DW_AT_address_class
:
4909 return "DW_AT_address_class";
4910 case DW_AT_artificial
:
4911 return "DW_AT_artificial";
4912 case DW_AT_base_types
:
4913 return "DW_AT_base_types";
4914 case DW_AT_calling_convention
:
4915 return "DW_AT_calling_convention";
4917 return "DW_AT_count";
4918 case DW_AT_data_member_location
:
4919 return "DW_AT_data_member_location";
4920 case DW_AT_decl_column
:
4921 return "DW_AT_decl_column";
4922 case DW_AT_decl_file
:
4923 return "DW_AT_decl_file";
4924 case DW_AT_decl_line
:
4925 return "DW_AT_decl_line";
4926 case DW_AT_declaration
:
4927 return "DW_AT_declaration";
4928 case DW_AT_discr_list
:
4929 return "DW_AT_discr_list";
4930 case DW_AT_encoding
:
4931 return "DW_AT_encoding";
4932 case DW_AT_external
:
4933 return "DW_AT_external";
4934 case DW_AT_frame_base
:
4935 return "DW_AT_frame_base";
4937 return "DW_AT_friend";
4938 case DW_AT_identifier_case
:
4939 return "DW_AT_identifier_case";
4940 case DW_AT_macro_info
:
4941 return "DW_AT_macro_info";
4942 case DW_AT_namelist_items
:
4943 return "DW_AT_namelist_items";
4944 case DW_AT_priority
:
4945 return "DW_AT_priority";
4947 return "DW_AT_segment";
4948 case DW_AT_specification
:
4949 return "DW_AT_specification";
4950 case DW_AT_static_link
:
4951 return "DW_AT_static_link";
4953 return "DW_AT_type";
4954 case DW_AT_use_location
:
4955 return "DW_AT_use_location";
4956 case DW_AT_variable_parameter
:
4957 return "DW_AT_variable_parameter";
4958 case DW_AT_virtuality
:
4959 return "DW_AT_virtuality";
4960 case DW_AT_vtable_elem_location
:
4961 return "DW_AT_vtable_elem_location";
4964 case DW_AT_MIPS_fde
:
4965 return "DW_AT_MIPS_fde";
4966 case DW_AT_MIPS_loop_begin
:
4967 return "DW_AT_MIPS_loop_begin";
4968 case DW_AT_MIPS_tail_loop_begin
:
4969 return "DW_AT_MIPS_tail_loop_begin";
4970 case DW_AT_MIPS_epilog_begin
:
4971 return "DW_AT_MIPS_epilog_begin";
4972 case DW_AT_MIPS_loop_unroll_factor
:
4973 return "DW_AT_MIPS_loop_unroll_factor";
4974 case DW_AT_MIPS_software_pipeline_depth
:
4975 return "DW_AT_MIPS_software_pipeline_depth";
4976 case DW_AT_MIPS_linkage_name
:
4977 return "DW_AT_MIPS_linkage_name";
4980 case DW_AT_sf_names
:
4981 return "DW_AT_sf_names";
4982 case DW_AT_src_info
:
4983 return "DW_AT_src_info";
4984 case DW_AT_mac_info
:
4985 return "DW_AT_mac_info";
4986 case DW_AT_src_coords
:
4987 return "DW_AT_src_coords";
4988 case DW_AT_body_begin
:
4989 return "DW_AT_body_begin";
4990 case DW_AT_body_end
:
4991 return "DW_AT_body_end";
4993 return "DW_AT_<unknown>";
4997 /* Convert a DWARF value form code into its string name. */
5000 dwarf_form_name (form
)
5001 register unsigned form
;
5006 return "DW_FORM_addr";
5007 case DW_FORM_block2
:
5008 return "DW_FORM_block2";
5009 case DW_FORM_block4
:
5010 return "DW_FORM_block4";
5012 return "DW_FORM_data2";
5014 return "DW_FORM_data4";
5016 return "DW_FORM_data8";
5017 case DW_FORM_string
:
5018 return "DW_FORM_string";
5020 return "DW_FORM_block";
5021 case DW_FORM_block1
:
5022 return "DW_FORM_block1";
5024 return "DW_FORM_data1";
5026 return "DW_FORM_flag";
5028 return "DW_FORM_sdata";
5030 return "DW_FORM_strp";
5032 return "DW_FORM_udata";
5033 case DW_FORM_ref_addr
:
5034 return "DW_FORM_ref_addr";
5036 return "DW_FORM_ref1";
5038 return "DW_FORM_ref2";
5040 return "DW_FORM_ref4";
5042 return "DW_FORM_ref8";
5043 case DW_FORM_ref_udata
:
5044 return "DW_FORM_ref_udata";
5045 case DW_FORM_indirect
:
5046 return "DW_FORM_indirect";
5048 return "DW_FORM_<unknown>";
5052 /* Convert a DWARF stack opcode into its string name. */
5055 dwarf_stack_op_name (op
)
5056 register unsigned op
;
5061 return "DW_OP_addr";
5063 return "DW_OP_deref";
5065 return "DW_OP_const1u";
5067 return "DW_OP_const1s";
5069 return "DW_OP_const2u";
5071 return "DW_OP_const2s";
5073 return "DW_OP_const4u";
5075 return "DW_OP_const4s";
5077 return "DW_OP_const8u";
5079 return "DW_OP_const8s";
5081 return "DW_OP_constu";
5083 return "DW_OP_consts";
5087 return "DW_OP_drop";
5089 return "DW_OP_over";
5091 return "DW_OP_pick";
5093 return "DW_OP_swap";
5097 return "DW_OP_xderef";
5105 return "DW_OP_minus";
5117 return "DW_OP_plus";
5118 case DW_OP_plus_uconst
:
5119 return "DW_OP_plus_uconst";
5125 return "DW_OP_shra";
5143 return "DW_OP_skip";
5145 return "DW_OP_lit0";
5147 return "DW_OP_lit1";
5149 return "DW_OP_lit2";
5151 return "DW_OP_lit3";
5153 return "DW_OP_lit4";
5155 return "DW_OP_lit5";
5157 return "DW_OP_lit6";
5159 return "DW_OP_lit7";
5161 return "DW_OP_lit8";
5163 return "DW_OP_lit9";
5165 return "DW_OP_lit10";
5167 return "DW_OP_lit11";
5169 return "DW_OP_lit12";
5171 return "DW_OP_lit13";
5173 return "DW_OP_lit14";
5175 return "DW_OP_lit15";
5177 return "DW_OP_lit16";
5179 return "DW_OP_lit17";
5181 return "DW_OP_lit18";
5183 return "DW_OP_lit19";
5185 return "DW_OP_lit20";
5187 return "DW_OP_lit21";
5189 return "DW_OP_lit22";
5191 return "DW_OP_lit23";
5193 return "DW_OP_lit24";
5195 return "DW_OP_lit25";
5197 return "DW_OP_lit26";
5199 return "DW_OP_lit27";
5201 return "DW_OP_lit28";
5203 return "DW_OP_lit29";
5205 return "DW_OP_lit30";
5207 return "DW_OP_lit31";
5209 return "DW_OP_reg0";
5211 return "DW_OP_reg1";
5213 return "DW_OP_reg2";
5215 return "DW_OP_reg3";
5217 return "DW_OP_reg4";
5219 return "DW_OP_reg5";
5221 return "DW_OP_reg6";
5223 return "DW_OP_reg7";
5225 return "DW_OP_reg8";
5227 return "DW_OP_reg9";
5229 return "DW_OP_reg10";
5231 return "DW_OP_reg11";
5233 return "DW_OP_reg12";
5235 return "DW_OP_reg13";
5237 return "DW_OP_reg14";
5239 return "DW_OP_reg15";
5241 return "DW_OP_reg16";
5243 return "DW_OP_reg17";
5245 return "DW_OP_reg18";
5247 return "DW_OP_reg19";
5249 return "DW_OP_reg20";
5251 return "DW_OP_reg21";
5253 return "DW_OP_reg22";
5255 return "DW_OP_reg23";
5257 return "DW_OP_reg24";
5259 return "DW_OP_reg25";
5261 return "DW_OP_reg26";
5263 return "DW_OP_reg27";
5265 return "DW_OP_reg28";
5267 return "DW_OP_reg29";
5269 return "DW_OP_reg30";
5271 return "DW_OP_reg31";
5273 return "DW_OP_breg0";
5275 return "DW_OP_breg1";
5277 return "DW_OP_breg2";
5279 return "DW_OP_breg3";
5281 return "DW_OP_breg4";
5283 return "DW_OP_breg5";
5285 return "DW_OP_breg6";
5287 return "DW_OP_breg7";
5289 return "DW_OP_breg8";
5291 return "DW_OP_breg9";
5293 return "DW_OP_breg10";
5295 return "DW_OP_breg11";
5297 return "DW_OP_breg12";
5299 return "DW_OP_breg13";
5301 return "DW_OP_breg14";
5303 return "DW_OP_breg15";
5305 return "DW_OP_breg16";
5307 return "DW_OP_breg17";
5309 return "DW_OP_breg18";
5311 return "DW_OP_breg19";
5313 return "DW_OP_breg20";
5315 return "DW_OP_breg21";
5317 return "DW_OP_breg22";
5319 return "DW_OP_breg23";
5321 return "DW_OP_breg24";
5323 return "DW_OP_breg25";
5325 return "DW_OP_breg26";
5327 return "DW_OP_breg27";
5329 return "DW_OP_breg28";
5331 return "DW_OP_breg29";
5333 return "DW_OP_breg30";
5335 return "DW_OP_breg31";
5337 return "DW_OP_regx";
5339 return "DW_OP_fbreg";
5341 return "DW_OP_bregx";
5343 return "DW_OP_piece";
5344 case DW_OP_deref_size
:
5345 return "DW_OP_deref_size";
5346 case DW_OP_xderef_size
:
5347 return "DW_OP_xderef_size";
5351 return "OP_<unknown>";
5356 dwarf_bool_name (mybool
)
5365 /* Convert a DWARF type code into its string name. */
5368 dwarf_type_encoding_name (enc
)
5369 register unsigned enc
;
5373 case DW_ATE_address
:
5374 return "DW_ATE_address";
5375 case DW_ATE_boolean
:
5376 return "DW_ATE_boolean";
5377 case DW_ATE_complex_float
:
5378 return "DW_ATE_complex_float";
5380 return "DW_ATE_float";
5382 return "DW_ATE_signed";
5383 case DW_ATE_signed_char
:
5384 return "DW_ATE_signed_char";
5385 case DW_ATE_unsigned
:
5386 return "DW_ATE_unsigned";
5387 case DW_ATE_unsigned_char
:
5388 return "DW_ATE_unsigned_char";
5390 return "DW_ATE_<unknown>";
5394 /* Convert a DWARF call frame info operation to its string name. */
5398 dwarf_cfi_name (cfi_opc
)
5399 register unsigned cfi_opc
;
5403 case DW_CFA_advance_loc
:
5404 return "DW_CFA_advance_loc";
5406 return "DW_CFA_offset";
5407 case DW_CFA_restore
:
5408 return "DW_CFA_restore";
5410 return "DW_CFA_nop";
5411 case DW_CFA_set_loc
:
5412 return "DW_CFA_set_loc";
5413 case DW_CFA_advance_loc1
:
5414 return "DW_CFA_advance_loc1";
5415 case DW_CFA_advance_loc2
:
5416 return "DW_CFA_advance_loc2";
5417 case DW_CFA_advance_loc4
:
5418 return "DW_CFA_advance_loc4";
5419 case DW_CFA_offset_extended
:
5420 return "DW_CFA_offset_extended";
5421 case DW_CFA_restore_extended
:
5422 return "DW_CFA_restore_extended";
5423 case DW_CFA_undefined
:
5424 return "DW_CFA_undefined";
5425 case DW_CFA_same_value
:
5426 return "DW_CFA_same_value";
5427 case DW_CFA_register
:
5428 return "DW_CFA_register";
5429 case DW_CFA_remember_state
:
5430 return "DW_CFA_remember_state";
5431 case DW_CFA_restore_state
:
5432 return "DW_CFA_restore_state";
5433 case DW_CFA_def_cfa
:
5434 return "DW_CFA_def_cfa";
5435 case DW_CFA_def_cfa_register
:
5436 return "DW_CFA_def_cfa_register";
5437 case DW_CFA_def_cfa_offset
:
5438 return "DW_CFA_def_cfa_offset";
5439 /* SGI/MIPS specific */
5440 case DW_CFA_MIPS_advance_loc8
:
5441 return "DW_CFA_MIPS_advance_loc8";
5443 return "DW_CFA_<unknown>";
5450 struct die_info
*die
;
5454 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5455 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5456 fprintf (stderr
, "\thas children: %s\n",
5457 dwarf_bool_name (die
->has_children
));
5459 fprintf (stderr
, "\tattributes:\n");
5460 for (i
= 0; i
< die
->num_attrs
; ++i
)
5462 fprintf (stderr
, "\t\t%s (%s) ",
5463 dwarf_attr_name (die
->attrs
[i
].name
),
5464 dwarf_form_name (die
->attrs
[i
].form
));
5465 switch (die
->attrs
[i
].form
)
5467 case DW_FORM_ref_addr
:
5469 fprintf (stderr
, "address: ");
5470 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5472 case DW_FORM_block2
:
5473 case DW_FORM_block4
:
5475 case DW_FORM_block1
:
5476 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5486 fprintf (stderr
, "constant: %d", DW_UNSND (&die
->attrs
[i
]));
5488 case DW_FORM_string
:
5489 fprintf (stderr
, "string: \"%s\"",
5490 DW_STRING (&die
->attrs
[i
])
5491 ? DW_STRING (&die
->attrs
[i
]) : "");
5494 if (DW_UNSND (&die
->attrs
[i
]))
5495 fprintf (stderr
, "flag: TRUE");
5497 fprintf (stderr
, "flag: FALSE");
5499 case DW_FORM_strp
: /* we do not support separate string
5501 case DW_FORM_indirect
: /* we do not handle indirect yet */
5502 case DW_FORM_data8
: /* we do not have 64 bit quantities */
5504 fprintf (stderr
, "unsupported attribute form: %d.",
5505 die
->attrs
[i
].form
);
5507 fprintf (stderr
, "\n");
5513 struct die_info
*die
;
5523 store_in_ref_table (offset
, die
)
5524 unsigned int offset
;
5525 struct die_info
*die
;
5528 struct die_info
*old
;
5530 h
= (offset
% REF_HASH_SIZE
);
5531 old
= die_ref_table
[h
];
5532 die
->next_ref
= old
;
5533 die_ref_table
[h
] = die
;
5538 dwarf2_empty_die_ref_table ()
5540 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5544 dwarf2_get_ref_die_offset (attr
)
5545 struct attribute
*attr
;
5547 unsigned int result
= 0;
5551 case DW_FORM_ref_addr
:
5552 result
= DW_ADDR (attr
);
5557 case DW_FORM_ref_udata
:
5558 result
= cu_header_offset
+ DW_UNSND (attr
);
5561 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5567 follow_die_ref (offset
)
5568 unsigned int offset
;
5570 struct die_info
*die
;
5573 h
= (offset
% REF_HASH_SIZE
);
5574 die
= die_ref_table
[h
];
5577 if (die
->offset
== offset
)
5581 die
= die
->next_ref
;
5586 static struct type
*
5587 dwarf2_fundamental_type (objfile
, typeid)
5588 struct objfile
*objfile
;
5591 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5593 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5597 /* Look for this particular type in the fundamental type vector. If
5598 one is not found, create and install one appropriate for the
5599 current language and the current target machine. */
5601 if (ftypes
[typeid] == NULL
)
5603 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5606 return (ftypes
[typeid]);
5609 /* Decode simple location descriptions.
5610 Given a pointer to a dwarf block that defines a location, compute
5611 the location and return the value.
5613 FIXME: This is a kludge until we figure out a better
5614 way to handle the location descriptions.
5615 Gdb's design does not mesh well with the DWARF2 notion of a location
5616 computing interpreter, which is a shame because the flexibility goes unused.
5617 FIXME: Implement more operations as necessary.
5619 A location description containing no operations indicates that the
5620 object is optimized out. The global optimized_out flag is set for
5621 those, the return value is meaningless.
5623 When the result is a register number, the global isreg flag is set,
5624 otherwise it is cleared.
5626 When the result is a base register offset, the global offreg flag is set
5627 and the register number is returned in basereg, otherwise it is cleared.
5629 When the DW_OP_fbreg operation is encountered without a corresponding
5630 DW_AT_frame_base attribute, the global islocal flag is set.
5631 Hopefully the machine dependent code knows how to set up a virtual
5632 frame pointer for the local references.
5634 Note that stack[0] is unused except as a default error return.
5635 Note that stack overflow is not yet handled. */
5638 decode_locdesc (blk
, objfile
)
5639 struct dwarf_block
*blk
;
5640 struct objfile
*objfile
;
5643 int size
= blk
->size
;
5644 char *data
= blk
->data
;
5645 CORE_ADDR stack
[64];
5647 unsigned int bytes_read
, unsnd
;
5698 stack
[++stacki
] = op
- DW_OP_reg0
;
5703 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5705 #if defined(HARRIS_TARGET) && defined(_M88K)
5706 /* The Harris 88110 gdb ports have long kept their special reg
5707 numbers between their gp-regs and their x-regs. This is
5708 not how our dwarf is generated. Punt. */
5711 stack
[++stacki
] = unsnd
;
5747 basereg
= op
- DW_OP_breg0
;
5748 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5754 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5756 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5761 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5763 if (frame_base_reg
>= 0)
5766 basereg
= frame_base_reg
;
5767 stack
[stacki
] += frame_base_offset
;
5771 complain (&dwarf2_missing_at_frame_base
);
5777 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
]);
5782 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5787 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5792 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5797 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5802 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5807 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5812 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5818 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5823 stack
[stacki
- 1] += stack
[stacki
];
5827 case DW_OP_plus_uconst
:
5828 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5833 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5839 /* If we're not the last op, then we definitely can't encode
5840 this using GDB's address_class enum. */
5842 complain (&dwarf2_complex_location_expr
);
5846 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
5847 return (stack
[stacki
]);
5850 return (stack
[stacki
]);
5853 /* memory allocation interface */
5857 dwarf2_free_tmp_obstack (ignore
)
5860 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5863 static struct dwarf_block
*
5864 dwarf_alloc_block ()
5866 struct dwarf_block
*blk
;
5868 blk
= (struct dwarf_block
*)
5869 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5873 static struct abbrev_info
*
5874 dwarf_alloc_abbrev ()
5876 struct abbrev_info
*abbrev
;
5878 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5879 memset (abbrev
, 0, sizeof (struct abbrev_info
));
5883 static struct die_info
*
5886 struct die_info
*die
;
5888 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5889 memset (die
, 0, sizeof (struct die_info
));