1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997 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, Boston, MA 02111-1307, USA. */
33 #include "elf/dwarf2.h"
36 #include "expression.h"
38 #include "complaints.h"
41 #include "gdb_string.h"
42 #include <sys/types.h>
44 /* .debug_info header for a compilation unit
45 Because of alignment constraints, this structure has padding and cannot
46 be mapped directly onto the beginning of the .debug_info section. */
47 typedef struct comp_unit_header
49 unsigned int length
; /* length of the .debug_info
51 unsigned short version
; /* version number -- 2 for DWARF
53 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
54 unsigned char addr_size
; /* byte size of an address -- 4 */
57 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
59 /* .debug_pubnames header
60 Because of alignment constraints, this structure has padding and cannot
61 be mapped directly onto the beginning of the .debug_info section. */
62 typedef struct pubnames_header
64 unsigned int length
; /* length of the .debug_pubnames
66 unsigned char version
; /* version number -- 2 for DWARF
68 unsigned int info_offset
; /* offset into .debug_info section */
69 unsigned int info_size
; /* byte size of .debug_info section
73 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
75 /* .debug_pubnames header
76 Because of alignment constraints, this structure has padding and cannot
77 be mapped directly onto the beginning of the .debug_info section. */
78 typedef struct aranges_header
80 unsigned int length
; /* byte len of the .debug_aranges
82 unsigned short version
; /* version number -- 2 for DWARF
84 unsigned int info_offset
; /* offset into .debug_info section */
85 unsigned char addr_size
; /* byte size of an address */
86 unsigned char seg_size
; /* byte size of segment descriptor */
89 #define _ACTUAL_ARANGES_HEADER_SIZE 12
91 /* .debug_line statement program prologue
92 Because of alignment constraints, this structure has padding and cannot
93 be mapped directly onto the beginning of the .debug_info section. */
94 typedef struct statement_prologue
96 unsigned int total_length
; /* byte length of the statement
98 unsigned short version
; /* version number -- 2 for DWARF
100 unsigned int prologue_length
; /* # bytes between prologue &
102 unsigned char minimum_instruction_length
; /* byte size of
104 unsigned char default_is_stmt
; /* initial value of is_stmt
107 unsigned char line_range
;
108 unsigned char opcode_base
; /* number assigned to first special
110 unsigned char *standard_opcode_lengths
;
114 /* offsets and sizes of debugging sections */
116 static file_ptr dwarf_info_offset
;
117 static file_ptr dwarf_abbrev_offset
;
118 static file_ptr dwarf_line_offset
;
119 static file_ptr dwarf_pubnames_offset
;
120 static file_ptr dwarf_aranges_offset
;
121 static file_ptr dwarf_loc_offset
;
122 static file_ptr dwarf_macinfo_offset
;
123 static file_ptr dwarf_str_offset
;
125 static unsigned int dwarf_info_size
;
126 static unsigned int dwarf_abbrev_size
;
127 static unsigned int dwarf_line_size
;
128 static unsigned int dwarf_pubnames_size
;
129 static unsigned int dwarf_aranges_size
;
130 static unsigned int dwarf_loc_size
;
131 static unsigned int dwarf_macinfo_size
;
132 static unsigned int dwarf_str_size
;
134 /* names of the debugging sections */
136 #define INFO_SECTION ".debug_info"
137 #define ABBREV_SECTION ".debug_abbrev"
138 #define LINE_SECTION ".debug_line"
139 #define PUBNAMES_SECTION ".debug_pubnames"
140 #define ARANGES_SECTION ".debug_aranges"
141 #define LOC_SECTION ".debug_loc"
142 #define MACINFO_SECTION ".debug_macinfo"
143 #define STR_SECTION ".debug_str"
145 /* local data types */
147 /* The data in a compilation unit header looks like this. */
148 struct comp_unit_head
153 unsigned char addr_size
;
156 /* The data in the .debug_line statement prologue looks like this. */
159 unsigned int total_length
;
160 unsigned short version
;
161 unsigned int prologue_length
;
162 unsigned char minimum_instruction_length
;
163 unsigned char default_is_stmt
;
165 unsigned char line_range
;
166 unsigned char opcode_base
;
167 unsigned char *standard_opcode_lengths
;
170 /* When we construct a partial symbol table entry we only
171 need this much information. */
172 struct partial_die_info
175 unsigned char has_children
;
176 unsigned char is_external
;
177 unsigned char is_declaration
;
178 unsigned char has_type
;
184 struct dwarf_block
*locdesc
;
185 unsigned int language
;
189 /* This data structure holds the information of an abbrev. */
192 unsigned int number
; /* number identifying abbrev */
193 enum dwarf_tag tag
; /* dwarf tag */
194 int has_children
; /* boolean */
195 unsigned int num_attrs
; /* number of attributes */
196 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
197 struct abbrev_info
*next
; /* next in chain */
202 enum dwarf_attribute name
;
203 enum dwarf_form form
;
206 /* This data structure holds a complete die structure. */
209 enum dwarf_tag tag
; /* Tag indicating type of die */
210 unsigned short has_children
; /* Does the die have children */
211 unsigned int abbrev
; /* Abbrev number */
212 unsigned int offset
; /* Offset in .debug_info section */
213 unsigned int num_attrs
; /* Number of attributes */
214 struct attribute
*attrs
; /* An array of attributes */
215 struct die_info
*next_ref
; /* Next die in ref hash table */
216 struct die_info
*next
; /* Next die in linked list */
217 struct type
*type
; /* Cached type information */
220 /* Attributes have a name and a value */
223 enum dwarf_attribute name
;
224 enum dwarf_form form
;
228 struct dwarf_block
*blk
;
236 /* Get at parts of an attribute structure */
238 #define DW_STRING(attr) ((attr)->u.str)
239 #define DW_UNSND(attr) ((attr)->u.unsnd)
240 #define DW_BLOCK(attr) ((attr)->u.blk)
241 #define DW_SND(attr) ((attr)->u.snd)
242 #define DW_ADDR(attr) ((attr)->u.addr)
244 /* Blocks are a bunch of untyped bytes. */
251 /* We only hold one compilation unit's abbrevs in
252 memory at any one time. */
253 #ifndef ABBREV_HASH_SIZE
254 #define ABBREV_HASH_SIZE 121
256 #ifndef ATTR_ALLOC_CHUNK
257 #define ATTR_ALLOC_CHUNK 4
260 static struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
262 /* A hash table of die offsets for following references. */
263 #ifndef REF_HASH_SIZE
264 #define REF_HASH_SIZE 1021
267 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
269 /* Obstack for allocating temporary storage used during symbol reading. */
270 static struct obstack dwarf2_tmp_obstack
;
272 /* Offset to the first byte of the current compilation unit header,
273 for resolving relative reference dies. */
274 static unsigned int cu_header_offset
;
276 /* Allocate fields for structs, unions and enums in this size. */
277 #ifndef DW_FIELD_ALLOC_CHUNK
278 #define DW_FIELD_ALLOC_CHUNK 4
281 /* The language we are debugging. */
282 static enum language cu_language
;
283 static const struct language_defn
*cu_language_defn
;
285 /* Actually data from the sections. */
286 static char *dwarf_info_buffer
;
287 static char *dwarf_abbrev_buffer
;
288 static char *dwarf_line_buffer
;
290 /* A zeroed version of a partial die for initialization purposes. */
291 static struct partial_die_info zeroed_partial_die
;
293 /* The generic symbol table building routines have separate lists for
294 file scope symbols and all all other scopes (local scopes). So
295 we need to select the right one to pass to add_symbol_to_list().
296 We do it by keeping a pointer to the correct list in list_in_scope.
298 FIXME: The original dwarf code just treated the file scope as the first
299 local scope, and all other local scopes as nested local scopes, and worked
300 fine. Check to see if we really need to distinguish these
302 static struct pending
**list_in_scope
= &file_symbols
;
304 /* FIXME: The following variables pass additional information from
305 decode_locdesc to the caller. */
306 static int optimized_out
; /* Kludge to identify optimized out variables */
307 static int isreg
; /* Kludge to identify register variables */
308 static int offreg
; /* Kludge to identify basereg references */
309 static int basereg
; /* Which base register is it relative to? */
310 static int islocal
; /* Kludge to identify local variables */
312 /* DW_AT_frame_base values for the current function.
313 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
314 contains the register number for the frame register.
315 frame_base_offset is the offset from the frame register to the
316 virtual stack frame. */
317 static int frame_base_reg
;
318 static CORE_ADDR frame_base_offset
;
320 /* This value is added to each symbol value. FIXME: Generalize to
321 the section_offsets structure used by dbxread (once this is done,
322 pass the appropriate section number to end_symtab). */
323 static CORE_ADDR baseaddr
; /* Add to each symbol value */
325 /* We put a pointer to this structure in the read_symtab_private field
327 The complete dwarf information for an objfile is kept in the
328 psymbol_obstack, so that absolute die references can be handled.
329 Most of the information in this structure is related to an entire
330 object file and could be passed via the sym_private field of the objfile.
331 It is however conceivable that dwarf2 might not be the only type
332 of symbols read from an object file. */
336 /* Pointer to start of dwarf info buffer for the objfile. */
338 char *dwarf_info_buffer
;
340 /* Offset in dwarf_info_buffer for this compilation unit. */
342 unsigned long dwarf_info_offset
;
344 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
346 char *dwarf_abbrev_buffer
;
348 /* Size of dwarf abbreviation section for the objfile. */
350 unsigned int dwarf_abbrev_size
;
352 /* Pointer to start of dwarf line buffer for the objfile. */
354 char *dwarf_line_buffer
;
357 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
358 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
359 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
360 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
361 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
362 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
364 /* Maintain an array of referenced fundamental types for the current
365 compilation unit being read. For DWARF version 1, we have to construct
366 the fundamental types on the fly, since no information about the
367 fundamental types is supplied. Each such fundamental type is created by
368 calling a language dependent routine to create the type, and then a
369 pointer to that type is then placed in the array at the index specified
370 by it's FT_<TYPENAME> value. The array has a fixed size set by the
371 FT_NUM_MEMBERS compile time constant, which is the number of predefined
372 fundamental types gdb knows how to construct. */
373 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
375 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
376 but this would require a corresponding change in unpack_field_as_long
378 static int bits_per_byte
= 8;
380 /* The routines that read and process dies for a C struct or C++ class
381 pass lists of data member fields and lists of member function fields
382 in an instance of a field_info structure, as defined below. */
385 /* List of data member and baseclasses fields. */
388 struct nextfield
*next
;
394 /* Number of fields. */
397 /* Number of baseclasses. */
400 /* Set if the accesibility of one of the fields is not public. */
401 int non_public_fields
;
403 /* Member function fields array, entries are allocated in the order they
404 are encountered in the object file. */
407 struct nextfnfield
*next
;
408 struct fn_field fnfield
;
411 /* Member function fieldlist array, contains name of possibly overloaded
412 member function, number of overloaded member functions and a pointer
413 to the head of the member function field chain. */
418 struct nextfnfield
*head
;
421 /* Number of entries in the fnfieldlists array. */
425 /* FIXME: Kludge to mark a varargs function type for C++ member function
426 argument processing. */
427 #define TYPE_FLAG_VARARGS (1 << 10)
429 /* Dwarf2 has no clean way to discern C++ static and non-static member
430 functions. G++ helps GDB by marking the first parameter for non-static
431 member functions (which is the this pointer) as artificial.
432 We pass this information between dwarf2_add_member_fn and
433 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
434 #define TYPE_FIELD_ARTIFICIAL TYPE_FIELD_BITPOS
436 /* Various complaints about symbol reading that don't abort the process */
438 static struct complaint dwarf2_const_ignored
=
440 "type qualifier 'const' ignored", 0, 0
442 static struct complaint dwarf2_volatile_ignored
=
444 "type qualifier 'volatile' ignored", 0, 0
446 static struct complaint dwarf2_non_const_array_bound_ignored
=
448 "non-constant array bounds form '%s' ignored", 0, 0
450 static struct complaint dwarf2_missing_line_number_section
=
452 "missing .debug_line section", 0, 0
454 static struct complaint dwarf2_mangled_line_number_section
=
456 "mangled .debug_line section", 0, 0
458 static struct complaint dwarf2_unsupported_die_ref_attr
=
460 "unsupported die ref attribute form: '%s'", 0, 0
462 static struct complaint dwarf2_unsupported_stack_op
=
464 "unsupported stack op: '%s'", 0, 0
466 static struct complaint dwarf2_unsupported_tag
=
468 "unsupported tag: '%s'", 0, 0
470 static struct complaint dwarf2_unsupported_at_encoding
=
472 "unsupported DW_AT_encoding: '%s'", 0, 0
474 static struct complaint dwarf2_unsupported_at_frame_base
=
476 "unsupported DW_AT_frame_base for function '%s'", 0, 0
478 static struct complaint dwarf2_unexpected_tag
=
480 "unexepected tag in read_type_die: '%s'", 0, 0
482 static struct complaint dwarf2_missing_at_frame_base
=
484 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
486 static struct complaint dwarf2_bad_static_member_name
=
488 "unrecognized static data member name '%s'", 0, 0
490 static struct complaint dwarf2_unsupported_accessibility
=
492 "unsupported accessibility %d", 0, 0
494 static struct complaint dwarf2_bad_member_name_complaint
=
496 "cannot extract member name from '%s'", 0, 0
498 static struct complaint dwarf2_missing_member_fn_type_complaint
=
500 "member function type missing for '%s'", 0, 0
502 static struct complaint dwarf2_vtbl_not_found_complaint
=
504 "virtual function table pointer not found when defining class '%s'", 0, 0
506 static struct complaint dwarf2_absolute_sibling_complaint
=
508 "ignoring absolute DW_AT_sibling", 0, 0
510 static struct complaint dwarf2_const_value_length_mismatch
=
512 "const value length mismatch for '%s', got %d, expected %d", 0, 0
514 static struct complaint dwarf2_unsupported_const_value_attr
=
516 "unsupported const value attribute form: '%s'", 0, 0
519 /* Remember the addr_size read from the dwarf.
520 If a target expects to link compilation units with differing address
521 sizes, gdb needs to be sure that the appropriate size is here for
522 whatever scope is currently getting read. */
523 static int address_size
;
525 /* Externals references. */
526 extern int info_verbose
; /* From main.c; nonzero => verbose */
528 /* local function prototypes */
530 static void dwarf2_locate_sections
PARAMS ((bfd
*, asection
*, PTR
));
533 static void dwarf2_build_psymtabs_easy
PARAMS ((struct objfile
*,
534 struct section_offsets
*,
538 static void dwarf2_build_psymtabs_hard
PARAMS ((struct objfile
*,
539 struct section_offsets
*,
542 static char *scan_partial_symbols
PARAMS ((char *, struct objfile
*,
543 CORE_ADDR
*, CORE_ADDR
*));
545 static void add_partial_symbol
PARAMS ((struct partial_die_info
*,
548 static void dwarf2_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
550 static void psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*));
552 static char *dwarf2_read_section
PARAMS ((struct objfile
*, file_ptr
,
555 static void dwarf2_read_abbrevs
PARAMS ((bfd
*, unsigned int));
557 static void dwarf2_empty_abbrev_table
PARAMS ((PTR
));
559 static struct abbrev_info
*dwarf2_lookup_abbrev
PARAMS ((unsigned int));
561 static char *read_partial_die
PARAMS ((struct partial_die_info
*,
562 bfd
*, char *, int *));
564 static char *read_full_die
PARAMS ((struct die_info
**, bfd
*, char *));
566 static char *read_attribute
PARAMS ((struct attribute
*, struct attr_abbrev
*,
569 static unsigned int read_1_byte
PARAMS ((bfd
*, char *));
571 static int read_1_signed_byte
PARAMS ((bfd
*, char *));
573 static unsigned int read_2_bytes
PARAMS ((bfd
*, char *));
575 static unsigned int read_4_bytes
PARAMS ((bfd
*, char *));
577 static unsigned int read_8_bytes
PARAMS ((bfd
*, char *));
579 static CORE_ADDR read_address
PARAMS ((bfd
*, char *));
581 static char *read_n_bytes
PARAMS ((bfd
*, char *, unsigned int));
583 static char *read_string
PARAMS ((bfd
*, char *, unsigned int *));
585 static unsigned int read_unsigned_leb128
PARAMS ((bfd
*, char *,
588 static int read_signed_leb128
PARAMS ((bfd
*, char *, unsigned int *));
590 static void set_cu_language
PARAMS ((unsigned int));
592 static struct attribute
*dwarf_attr
PARAMS ((struct die_info
*,
595 static void dwarf_decode_lines
PARAMS ((unsigned int, char *, bfd
*));
597 static void dwarf2_start_subfile
PARAMS ((char *, char *));
599 static struct symbol
*new_symbol
PARAMS ((struct die_info
*, struct type
*,
602 static void dwarf2_const_value
PARAMS ((struct attribute
*, struct symbol
*,
605 static struct type
*die_type
PARAMS ((struct die_info
*, struct objfile
*));
607 static struct type
*die_containing_type
PARAMS ((struct die_info
*,
611 static struct type
*type_at_offset
PARAMS ((unsigned int, struct objfile
*));
614 static struct type
*tag_type_to_type
PARAMS ((struct die_info
*,
617 static void read_type_die
PARAMS ((struct die_info
*, struct objfile
*));
619 static void read_typedef
PARAMS ((struct die_info
*, struct objfile
*));
621 static void read_base_type
PARAMS ((struct die_info
*, struct objfile
*));
623 static void read_file_scope
PARAMS ((struct die_info
*, struct objfile
*));
625 static void read_func_scope
PARAMS ((struct die_info
*, struct objfile
*));
627 static void read_lexical_block_scope
PARAMS ((struct die_info
*,
630 static int dwarf2_get_pc_bounds
PARAMS ((struct die_info
*,
631 CORE_ADDR
*, CORE_ADDR
*,
634 static void dwarf2_add_field
PARAMS ((struct field_info
*, struct die_info
*,
637 static void dwarf2_attach_fields_to_type
PARAMS ((struct field_info
*,
641 static char *skip_member_fn_name
PARAMS ((char *));
643 static void dwarf2_add_member_fn
PARAMS ((struct field_info
*,
644 struct die_info
*, struct type
*,
645 struct objfile
*objfile
));
647 static void dwarf2_attach_fn_fields_to_type
PARAMS ((struct field_info
*,
651 static void read_structure_scope
PARAMS ((struct die_info
*, struct objfile
*));
653 static void read_common_block
PARAMS ((struct die_info
*, struct objfile
*));
655 static void read_enumeration
PARAMS ((struct die_info
*, struct objfile
*));
657 static struct type
*dwarf_base_type
PARAMS ((int, int, struct objfile
*));
659 static CORE_ADDR decode_locdesc
PARAMS ((struct dwarf_block
*,
662 static void read_array_type
PARAMS ((struct die_info
*, struct objfile
*));
664 static void read_tag_pointer_type
PARAMS ((struct die_info
*,
667 static void read_tag_ptr_to_member_type
PARAMS ((struct die_info
*,
670 static void read_tag_reference_type
PARAMS ((struct die_info
*,
673 static void read_tag_const_type
PARAMS ((struct die_info
*, struct objfile
*));
675 static void read_tag_volatile_type
PARAMS ((struct die_info
*,
678 static void read_tag_string_type
PARAMS ((struct die_info
*,
681 static void read_subroutine_type
PARAMS ((struct die_info
*,
684 struct die_info
*read_comp_unit
PARAMS ((char *, bfd
*));
686 static void free_die_list
PARAMS ((struct die_info
*));
688 static void process_die
PARAMS ((struct die_info
*, struct objfile
*));
690 static char *dwarf2_linkage_name
PARAMS ((struct die_info
*));
692 static char *dwarf_tag_name
PARAMS ((unsigned int));
694 static char *dwarf_attr_name
PARAMS ((unsigned int));
696 static char *dwarf_form_name
PARAMS ((unsigned int));
698 static char *dwarf_stack_op_name
PARAMS ((unsigned int));
700 static char *dwarf_bool_name
PARAMS ((unsigned int));
702 static char *dwarf_type_encoding_name
PARAMS ((unsigned int));
705 static char *dwarf_cfi_name
PARAMS ((unsigned int));
707 struct die_info
*copy_die
PARAMS ((struct die_info
*));
710 struct die_info
*sibling_die
PARAMS ((struct die_info
*));
712 void dump_die
PARAMS ((struct die_info
*));
714 void dump_die_list
PARAMS ((struct die_info
*));
716 void store_in_ref_table
PARAMS ((unsigned int, struct die_info
*));
718 static void dwarf2_empty_die_ref_table
PARAMS ((void));
720 static unsigned int dwarf2_get_ref_die_offset
PARAMS ((struct attribute
*));
722 struct die_info
*follow_die_ref
PARAMS ((unsigned int));
724 static struct type
*dwarf2_fundamental_type
PARAMS ((struct objfile
*, int));
726 /* memory allocation interface */
728 static void dwarf2_free_tmp_obstack
PARAMS ((PTR
));
730 static struct dwarf_block
*dwarf_alloc_block
PARAMS ((void));
732 static struct abbrev_info
*dwarf_alloc_abbrev
PARAMS ((void));
734 static struct die_info
*dwarf_alloc_die
PARAMS ((void));
736 /* Try to locate the sections we need for DWARF 2 debugging
737 information and return true if we have enough to do something. */
740 dwarf2_has_info (abfd
)
743 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
744 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
745 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
755 /* This function is mapped across the sections and remembers the
756 offset and size of each of the debugging sections we are interested
760 dwarf2_locate_sections (ignore_abfd
, sectp
, ignore_ptr
)
765 if (STREQ (sectp
->name
, INFO_SECTION
))
767 dwarf_info_offset
= sectp
->filepos
;
768 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
770 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
772 dwarf_abbrev_offset
= sectp
->filepos
;
773 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
775 else if (STREQ (sectp
->name
, LINE_SECTION
))
777 dwarf_line_offset
= sectp
->filepos
;
778 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
780 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
782 dwarf_pubnames_offset
= sectp
->filepos
;
783 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
785 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
787 dwarf_aranges_offset
= sectp
->filepos
;
788 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
790 else if (STREQ (sectp
->name
, LOC_SECTION
))
792 dwarf_loc_offset
= sectp
->filepos
;
793 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
795 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
797 dwarf_macinfo_offset
= sectp
->filepos
;
798 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
800 else if (STREQ (sectp
->name
, STR_SECTION
))
802 dwarf_str_offset
= sectp
->filepos
;
803 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
807 /* Build a partial symbol table. */
810 dwarf2_build_psymtabs (objfile
, section_offsets
, mainline
)
811 struct objfile
*objfile
;
812 struct section_offsets
*section_offsets
;
816 /* We definitely need the .debug_info and .debug_abbrev sections */
818 dwarf_info_buffer
= dwarf2_read_section (objfile
,
821 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
824 dwarf_line_buffer
= dwarf2_read_section (objfile
,
828 if (mainline
|| objfile
->global_psymbols
.size
== 0 ||
829 objfile
->static_psymbols
.size
== 0)
831 init_psymbol_list (objfile
, 1024);
835 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
837 /* Things are significanlty easier if we have .debug_aranges and
838 .debug_pubnames sections */
840 dwarf2_build_psymtabs_easy (objfile
, section_offsets
, mainline
);
844 /* only test this case for now */
846 /* In this case we have to work a bit harder */
847 dwarf2_build_psymtabs_hard (objfile
, section_offsets
, mainline
);
852 /* Build the partial symbol table from the information in the
853 .debug_pubnames and .debug_aranges sections. */
856 dwarf2_build_psymtabs_easy (objfile
, section_offsets
, mainline
)
857 struct objfile
*objfile
;
858 struct section_offsets
*section_offsets
;
861 bfd
*abfd
= objfile
->obfd
;
862 char *aranges_buffer
, *pubnames_buffer
;
863 char *aranges_ptr
, *pubnames_ptr
;
864 unsigned int entry_length
, version
, info_offset
, info_size
;
866 pubnames_buffer
= dwarf2_read_section (objfile
,
867 dwarf_pubnames_offset
,
868 dwarf_pubnames_size
);
869 pubnames_ptr
= pubnames_buffer
;
870 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
872 entry_length
= read_4_bytes (abfd
, pubnames_ptr
);
874 version
= read_1_byte (abfd
, pubnames_ptr
);
876 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
878 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
882 aranges_buffer
= dwarf2_read_section (objfile
,
883 dwarf_aranges_offset
,
889 /* Build the partial symbol table by doing a quick pass through the
890 .debug_info and .debug_abbrev sections. */
893 dwarf2_build_psymtabs_hard (objfile
, section_offsets
, mainline
)
894 struct objfile
*objfile
;
895 struct section_offsets
*section_offsets
;
898 /* Instead of reading this into a big buffer, we should probably use
899 mmap() on architectures that support it. (FIXME) */
900 bfd
*abfd
= objfile
->obfd
;
901 char *info_ptr
, *abbrev_ptr
;
902 char *beg_of_comp_unit
;
903 struct comp_unit_head cu_header
;
904 struct partial_die_info comp_unit_die
;
905 struct partial_symtab
*pst
;
906 struct cleanup
*back_to
;
907 int comp_unit_has_pc_info
;
908 CORE_ADDR lowpc
, highpc
;
910 info_ptr
= dwarf_info_buffer
;
911 abbrev_ptr
= dwarf_abbrev_buffer
;
913 obstack_init (&dwarf2_tmp_obstack
);
914 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
916 while ((unsigned int) (info_ptr
- dwarf_info_buffer
)
917 + ((info_ptr
- dwarf_info_buffer
) % 4) < dwarf_info_size
)
919 beg_of_comp_unit
= info_ptr
;
920 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
922 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
924 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
926 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
928 address_size
= cu_header
.addr_size
;
930 if (cu_header
.version
!= 2)
932 error ("Dwarf Error: wrong version in compilation unit header.");
936 /* Read the abbrevs for this compilation unit into a table */
937 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
938 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
940 /* Read the compilation unit die */
941 info_ptr
= read_partial_die (&comp_unit_die
, abfd
,
942 info_ptr
, &comp_unit_has_pc_info
);
944 /* Set the language we're debugging */
945 set_cu_language (comp_unit_die
.language
);
947 /* Allocate a new partial symbol table structure */
948 pst
= start_psymtab_common (objfile
, section_offsets
,
949 comp_unit_die
.name
? comp_unit_die
.name
: "",
951 objfile
->global_psymbols
.next
,
952 objfile
->static_psymbols
.next
);
954 pst
->read_symtab_private
= (char *)
955 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
956 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
957 DWARF_INFO_BUFFER(pst
) = dwarf_info_buffer
;
958 DWARF_INFO_OFFSET(pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
959 DWARF_ABBREV_BUFFER(pst
) = dwarf_abbrev_buffer
;
960 DWARF_ABBREV_SIZE(pst
) = dwarf_abbrev_size
;
961 DWARF_LINE_BUFFER(pst
) = dwarf_line_buffer
;
962 baseaddr
= ANOFFSET (section_offsets
, 0);
964 /* Store the function that reads in the rest of the symbol table */
965 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
967 /* Read the rest of the partial symbols from this comp unit */
968 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
);
970 /* If the compilation unit didn't have an explicit address range,
971 then use the information extracted from its child dies. */
972 if (!comp_unit_has_pc_info
)
974 comp_unit_die
.lowpc
= lowpc
;
975 comp_unit_die
.highpc
= highpc
;
977 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
978 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
980 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
981 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
982 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
983 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
984 sort_pst_symbols (pst
);
986 /* If there is already a psymtab or symtab for a file of this
987 name, remove it. (If there is a symtab, more drastic things
988 also happen.) This happens in VxWorks. */
989 free_named_symtabs (pst
->filename
);
991 info_ptr
= beg_of_comp_unit
+ cu_header
.length
+ 4;
993 do_cleanups (back_to
);
996 /* Read in all interesting dies to the end of the compilation unit. */
999 scan_partial_symbols (info_ptr
, objfile
, lowpc
, highpc
)
1001 struct objfile
*objfile
;
1005 bfd
*abfd
= objfile
->obfd
;
1006 struct partial_die_info pdi
;
1007 int nesting_level
= 1; /* we've already read in comp_unit_die */
1010 *lowpc
= ((CORE_ADDR
) -1);
1011 *highpc
= ((CORE_ADDR
) 0);
1013 while (nesting_level
)
1015 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, &has_pc_info
);
1021 case DW_TAG_subprogram
:
1024 if (pdi
.lowpc
< *lowpc
)
1028 if (pdi
.highpc
> *highpc
)
1030 *highpc
= pdi
.highpc
;
1032 if ((pdi
.is_external
|| nesting_level
== 1)
1033 && !pdi
.is_declaration
)
1035 add_partial_symbol (&pdi
, objfile
);
1039 case DW_TAG_variable
:
1040 case DW_TAG_typedef
:
1041 case DW_TAG_class_type
:
1042 case DW_TAG_structure_type
:
1043 case DW_TAG_union_type
:
1044 case DW_TAG_enumeration_type
:
1045 if ((pdi
.is_external
|| nesting_level
== 1)
1046 && !pdi
.is_declaration
)
1048 add_partial_symbol (&pdi
, objfile
);
1051 case DW_TAG_enumerator
:
1052 /* File scope enumerators are added to the partial symbol
1054 if (nesting_level
== 2)
1055 add_partial_symbol (&pdi
, objfile
);
1057 case DW_TAG_base_type
:
1058 /* File scope base type definitions are added to the partial
1060 if (nesting_level
== 1)
1061 add_partial_symbol (&pdi
, objfile
);
1068 /* If the die has a sibling, skip to the sibling.
1069 Do not skip enumeration types, we want to record their
1071 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1073 info_ptr
= pdi
.sibling
;
1075 else if (pdi
.has_children
)
1077 /* Die has children, but the optional DW_AT_sibling attribute
1088 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1089 from `maint check'. */
1090 if (*lowpc
== ((CORE_ADDR
) -1))
1096 add_partial_symbol (pdi
, objfile
)
1097 struct partial_die_info
*pdi
;
1098 struct objfile
*objfile
;
1104 case DW_TAG_subprogram
:
1105 if (pdi
->is_external
)
1107 prim_record_minimal_symbol (pdi
->name
, pdi
->lowpc
+ baseaddr
,
1109 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1110 VAR_NAMESPACE
, LOC_BLOCK
,
1111 &objfile
->global_psymbols
,
1112 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1116 prim_record_minimal_symbol (pdi
->name
, pdi
->lowpc
+ baseaddr
,
1117 mst_file_text
, objfile
);
1118 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1119 VAR_NAMESPACE
, LOC_BLOCK
,
1120 &objfile
->static_psymbols
,
1121 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1124 case DW_TAG_variable
:
1125 if (pdi
->is_external
)
1128 Don't enter into the minimal symbol tables as there is
1129 a minimal symbol table entry from the ELF symbols already.
1130 Enter into partial symbol table if it has a location
1131 descriptor or a type.
1132 If the location descriptor is missing, new_symbol will create
1133 a LOC_UNRESOLVED symbol, the address of the variable will then
1134 be determined from the minimal symbol table whenever the variable
1136 The address for the partial symbol table entry is not
1137 used by GDB, but it comes in handy for debugging partial symbol
1141 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1142 if (pdi
->locdesc
|| pdi
->has_type
)
1143 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1144 VAR_NAMESPACE
, LOC_STATIC
,
1145 &objfile
->global_psymbols
,
1146 0, addr
+ baseaddr
, cu_language
, objfile
);
1150 /* Static Variable. Skip symbols without location descriptors. */
1151 if (pdi
->locdesc
== NULL
)
1153 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1154 prim_record_minimal_symbol (pdi
->name
, addr
+ baseaddr
,
1155 mst_file_data
, objfile
);
1156 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1157 VAR_NAMESPACE
, LOC_STATIC
,
1158 &objfile
->static_psymbols
,
1159 0, addr
+ baseaddr
, cu_language
, objfile
);
1162 case DW_TAG_typedef
:
1163 case DW_TAG_base_type
:
1164 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1165 VAR_NAMESPACE
, LOC_TYPEDEF
,
1166 &objfile
->static_psymbols
,
1167 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1169 case DW_TAG_class_type
:
1170 case DW_TAG_structure_type
:
1171 case DW_TAG_union_type
:
1172 case DW_TAG_enumeration_type
:
1173 /* Skip aggregate types without children, these are external
1175 if (pdi
->has_children
== 0)
1177 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1178 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1179 &objfile
->static_psymbols
,
1180 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1182 if (cu_language
== language_cplus
)
1184 /* For C++, these implicitly act as typedefs as well. */
1185 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1186 VAR_NAMESPACE
, LOC_TYPEDEF
,
1187 &objfile
->static_psymbols
,
1188 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1191 case DW_TAG_enumerator
:
1192 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1193 VAR_NAMESPACE
, LOC_CONST
,
1194 &objfile
->static_psymbols
,
1195 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1202 /* Expand this partial symbol table into a full symbol table. */
1205 dwarf2_psymtab_to_symtab (pst
)
1206 struct partial_symtab
*pst
;
1208 /* FIXME: This is barely more than a stub. */
1213 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1219 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1220 gdb_flush (gdb_stdout
);
1223 psymtab_to_symtab_1 (pst
);
1225 /* Finish up the debug error message. */
1227 printf_filtered ("done.\n");
1233 psymtab_to_symtab_1 (pst
)
1234 struct partial_symtab
*pst
;
1236 struct objfile
*objfile
= pst
->objfile
;
1237 bfd
*abfd
= objfile
->obfd
;
1238 struct comp_unit_head cu_header
;
1239 struct die_info
*dies
;
1240 unsigned long offset
;
1241 CORE_ADDR lowpc
, highpc
;
1242 struct die_info
*child_die
;
1244 struct symtab
*symtab
;
1245 struct cleanup
*back_to
;
1247 /* Set local variables from the partial symbol table info. */
1248 offset
= DWARF_INFO_OFFSET(pst
);
1249 dwarf_info_buffer
= DWARF_INFO_BUFFER(pst
);
1250 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER(pst
);
1251 dwarf_abbrev_size
= DWARF_ABBREV_SIZE(pst
);
1252 dwarf_line_buffer
= DWARF_LINE_BUFFER(pst
);
1253 baseaddr
= ANOFFSET (pst
->section_offsets
, 0);
1254 cu_header_offset
= offset
;
1255 info_ptr
= dwarf_info_buffer
+ offset
;
1257 obstack_init (&dwarf2_tmp_obstack
);
1258 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1261 make_cleanup (really_free_pendings
, NULL
);
1263 /* read in the comp_unit header */
1264 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
1266 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
1268 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
1270 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
1273 /* Read the abbrevs for this compilation unit */
1274 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1275 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1277 dies
= read_comp_unit (info_ptr
, abfd
);
1279 make_cleanup (free_die_list
, dies
);
1281 /* Do line number decoding in read_file_scope () */
1282 process_die (dies
, objfile
);
1284 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1286 /* Some compilers don't define a DW_AT_high_pc attribute for
1287 the compilation unit. If the DW_AT_high_pc is missing,
1288 synthesize it, by scanning the DIE's below the compilation unit. */
1290 if (dies
->has_children
)
1292 child_die
= dies
->next
;
1293 while (child_die
&& child_die
->tag
)
1295 if (child_die
->tag
== DW_TAG_subprogram
)
1297 CORE_ADDR low
, high
;
1299 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1301 highpc
= max (highpc
, high
);
1304 child_die
= sibling_die (child_die
);
1308 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, 0);
1310 /* Set symtab language to language from DW_AT_language.
1311 If the compilation is from a C file generated by language preprocessors,
1312 do not set the language if it was already deduced by start_subfile. */
1314 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1316 symtab
->language
= cu_language
;
1318 pst
->symtab
= symtab
;
1320 sort_symtab_syms (pst
->symtab
);
1322 do_cleanups (back_to
);
1325 /* Process a die and its children. */
1328 process_die (die
, objfile
)
1329 struct die_info
*die
;
1330 struct objfile
*objfile
;
1334 case DW_TAG_padding
:
1336 case DW_TAG_compile_unit
:
1337 read_file_scope (die
, objfile
);
1339 case DW_TAG_subprogram
:
1340 read_subroutine_type (die
, objfile
);
1341 read_func_scope (die
, objfile
);
1343 case DW_TAG_inlined_subroutine
:
1344 /* FIXME: These are ignored for now.
1345 They could be used to set breakpoints on all inlined instances
1346 of a function and make GDB `next' properly over inlined functions. */
1348 case DW_TAG_lexical_block
:
1349 read_lexical_block_scope (die
, objfile
);
1351 case DW_TAG_class_type
:
1352 case DW_TAG_structure_type
:
1353 case DW_TAG_union_type
:
1354 read_structure_scope (die
, objfile
);
1356 case DW_TAG_enumeration_type
:
1357 read_enumeration (die
, objfile
);
1359 case DW_TAG_subroutine_type
:
1360 read_subroutine_type (die
, objfile
);
1362 case DW_TAG_array_type
:
1363 read_array_type (die
, objfile
);
1365 case DW_TAG_pointer_type
:
1366 read_tag_pointer_type (die
, objfile
);
1368 case DW_TAG_ptr_to_member_type
:
1369 read_tag_ptr_to_member_type (die
, objfile
);
1371 case DW_TAG_reference_type
:
1372 read_tag_reference_type (die
, objfile
);
1374 case DW_TAG_string_type
:
1375 read_tag_string_type (die
, objfile
);
1377 case DW_TAG_base_type
:
1378 read_base_type (die
, objfile
);
1379 if (dwarf_attr (die
, DW_AT_name
))
1381 /* Add a typedef symbol for the base type definition. */
1382 new_symbol (die
, die
->type
, objfile
);
1385 case DW_TAG_common_block
:
1386 read_common_block (die
, objfile
);
1388 case DW_TAG_common_inclusion
:
1391 new_symbol (die
, NULL
, objfile
);
1397 read_file_scope (die
, objfile
)
1398 struct die_info
*die
;
1399 struct objfile
*objfile
;
1401 unsigned int line_offset
= 0;
1402 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1403 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1404 struct attribute
*attr
;
1405 char *name
= "<unknown>";
1406 char *comp_dir
= NULL
;
1407 struct die_info
*child_die
;
1408 bfd
*abfd
= objfile
->obfd
;
1410 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1412 if (die
->has_children
)
1414 child_die
= die
->next
;
1415 while (child_die
&& child_die
->tag
)
1417 if (child_die
->tag
== DW_TAG_subprogram
)
1419 CORE_ADDR low
, high
;
1421 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1423 lowpc
= min (lowpc
, low
);
1424 highpc
= max (highpc
, high
);
1427 child_die
= sibling_die (child_die
);
1432 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1433 from finish_block. */
1434 if (lowpc
== ((CORE_ADDR
) -1))
1439 attr
= dwarf_attr (die
, DW_AT_name
);
1442 name
= DW_STRING (attr
);
1444 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1447 comp_dir
= DW_STRING (attr
);
1450 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1451 directory, get rid of it. */
1452 char *cp
= strchr (comp_dir
, ':');
1454 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1459 if (objfile
->ei
.entry_point
>= lowpc
&&
1460 objfile
->ei
.entry_point
< highpc
)
1462 objfile
->ei
.entry_file_lowpc
= lowpc
;
1463 objfile
->ei
.entry_file_highpc
= highpc
;
1466 attr
= dwarf_attr (die
, DW_AT_language
);
1469 set_cu_language (DW_UNSND (attr
));
1473 /* FIXME:Do something here. */
1474 if (dip
->at_producer
!= NULL
)
1476 handle_producer (dip
->at_producer
);
1480 /* The compilation unit may be in a different language or objfile,
1481 zero out all remembered fundamental types. */
1482 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1484 start_symtab (name
, comp_dir
, lowpc
);
1485 record_debugformat ("DWARF 2");
1487 /* Decode line number information if present. */
1488 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1491 line_offset
= DW_UNSND (attr
);
1492 dwarf_decode_lines (line_offset
, comp_dir
, abfd
);
1495 /* Process all dies in compilation unit. */
1496 if (die
->has_children
)
1498 child_die
= die
->next
;
1499 while (child_die
&& child_die
->tag
)
1501 process_die (child_die
, objfile
);
1502 child_die
= sibling_die (child_die
);
1508 read_func_scope (die
, objfile
)
1509 struct die_info
*die
;
1510 struct objfile
*objfile
;
1512 register struct context_stack
*new;
1515 struct die_info
*child_die
;
1516 struct attribute
*attr
;
1519 name
= dwarf2_linkage_name (die
);
1521 /* Ignore functions with missing or empty names and functions with
1522 missing or invalid low and high pc attributes. */
1523 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1529 if (objfile
->ei
.entry_point
>= lowpc
&&
1530 objfile
->ei
.entry_point
< highpc
)
1532 objfile
->ei
.entry_func_lowpc
= lowpc
;
1533 objfile
->ei
.entry_func_highpc
= highpc
;
1536 if (STREQ (name
, "main")) /* FIXME: hardwired name */
1538 objfile
->ei
.main_func_lowpc
= lowpc
;
1539 objfile
->ei
.main_func_highpc
= highpc
;
1542 /* Decode DW_AT_frame_base location descriptor if present, keep result
1543 for DW_OP_fbreg operands in decode_locdesc. */
1544 frame_base_reg
= -1;
1545 frame_base_offset
= 0;
1546 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1549 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
);
1551 frame_base_reg
= addr
;
1554 frame_base_reg
= basereg
;
1555 frame_base_offset
= addr
;
1558 complain (&dwarf2_unsupported_at_frame_base
, name
);
1561 new = push_context (0, lowpc
);
1562 new->name
= new_symbol (die
, die
->type
, objfile
);
1563 list_in_scope
= &local_symbols
;
1565 if (die
->has_children
)
1567 child_die
= die
->next
;
1568 while (child_die
&& child_die
->tag
)
1570 process_die (child_die
, objfile
);
1571 child_die
= sibling_die (child_die
);
1575 new = pop_context ();
1576 /* Make a block for the local symbols within. */
1577 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1578 lowpc
, highpc
, objfile
);
1579 list_in_scope
= &file_symbols
;
1582 /* Process all the DIES contained within a lexical block scope. Start
1583 a new scope, process the dies, and then close the scope. */
1586 read_lexical_block_scope (die
, objfile
)
1587 struct die_info
*die
;
1588 struct objfile
*objfile
;
1590 register struct context_stack
*new;
1591 CORE_ADDR lowpc
, highpc
;
1592 struct die_info
*child_die
;
1594 /* Ignore blocks with missing or invalid low and high pc attributes. */
1595 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1600 push_context (0, lowpc
);
1601 if (die
->has_children
)
1603 child_die
= die
->next
;
1604 while (child_die
&& child_die
->tag
)
1606 process_die (child_die
, objfile
);
1607 child_die
= sibling_die (child_die
);
1610 new = pop_context ();
1612 if (local_symbols
!= NULL
)
1614 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1617 local_symbols
= new->locals
;
1620 /* Get low and high pc attributes from a die.
1621 Return 1 if the attributes are present and valid, otherwise, return 0. */
1624 dwarf2_get_pc_bounds (die
, lowpc
, highpc
, objfile
)
1625 struct die_info
*die
;
1628 struct objfile
*objfile
;
1630 struct attribute
*attr
;
1634 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1636 low
= DW_ADDR (attr
);
1639 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1641 high
= DW_ADDR (attr
);
1648 /* When using the GNU linker, .gnu.linkonce. sections are used to
1649 eliminate duplicate copies of functions and vtables and such.
1650 The linker will arbitrarily choose one and discard the others.
1651 The AT_*_pc values for such functions refer to local labels in
1652 these sections. If the section from that file was discarded, the
1653 labels are not in the output, so the relocs get a value of 0.
1654 If this is a discarded function, mark the pc bounds as invalid,
1655 so that GDB will ignore it. */
1656 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1664 /* Add an aggregate field to the field list. */
1667 dwarf2_add_field (fip
, die
, objfile
)
1668 struct field_info
*fip
;
1669 struct die_info
*die
;
1670 struct objfile
*objfile
;
1672 struct nextfield
*new_field
;
1673 struct attribute
*attr
;
1675 char *fieldname
= "";
1677 /* Allocate a new field list entry and link it in. */
1678 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1679 make_cleanup (free
, new_field
);
1680 memset (new_field
, 0, sizeof (struct nextfield
));
1681 new_field
->next
= fip
->fields
;
1682 fip
->fields
= new_field
;
1685 /* Handle accessibility and virtuality of field.
1686 The default accessibility for members is public, the default
1687 accessibility for inheritance is private. */
1688 if (die
->tag
!= DW_TAG_inheritance
)
1689 new_field
->accessibility
= DW_ACCESS_public
;
1691 new_field
->accessibility
= DW_ACCESS_private
;
1692 new_field
->virtuality
= DW_VIRTUALITY_none
;
1694 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1696 new_field
->accessibility
= DW_UNSND (attr
);
1697 if (new_field
->accessibility
!= DW_ACCESS_public
)
1698 fip
->non_public_fields
= 1;
1699 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1701 new_field
->virtuality
= DW_UNSND (attr
);
1703 fp
= &new_field
->field
;
1704 if (die
->tag
== DW_TAG_member
)
1706 /* Get type of field. */
1707 fp
->type
= die_type (die
, objfile
);
1709 /* Get bit size of field (zero if none). */
1710 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1713 fp
->bitsize
= DW_UNSND (attr
);
1720 /* Get bit offset of field. */
1721 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1725 decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1729 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1732 if (BITS_BIG_ENDIAN
)
1734 /* For big endian bits, the DW_AT_bit_offset gives the
1735 additional bit offset from the MSB of the containing
1736 anonymous object to the MSB of the field. We don't
1737 have to do anything special since we don't need to
1738 know the size of the anonymous object. */
1739 fp
->bitpos
+= DW_UNSND (attr
);
1743 /* For little endian bits, compute the bit offset to the
1744 MSB of the anonymous object, subtract off the number of
1745 bits from the MSB of the field to the MSB of the
1746 object, and then subtract off the number of bits of
1747 the field itself. The result is the bit offset of
1748 the LSB of the field. */
1750 int bit_offset
= DW_UNSND (attr
);
1752 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1755 /* The size of the anonymous object containing
1756 the bit field is explicit, so use the
1757 indicated size (in bytes). */
1758 anonymous_size
= DW_UNSND (attr
);
1762 /* The size of the anonymous object containing
1763 the bit field must be inferred from the type
1764 attribute of the data member containing the
1766 anonymous_size
= TYPE_LENGTH (fp
->type
);
1769 anonymous_size
* bits_per_byte
- bit_offset
- fp
->bitsize
;
1773 /* Get name of field. */
1774 attr
= dwarf_attr (die
, DW_AT_name
);
1775 if (attr
&& DW_STRING (attr
))
1776 fieldname
= DW_STRING (attr
);
1777 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1778 &objfile
->type_obstack
);
1780 /* Change accessibility for artificial fields (e.g. virtual table
1781 pointer or virtual base class pointer) to private. */
1782 if (dwarf_attr (die
, DW_AT_artificial
))
1784 new_field
->accessibility
= DW_ACCESS_private
;
1785 fip
->non_public_fields
= 1;
1788 else if (die
->tag
== DW_TAG_variable
)
1793 /* C++ static member.
1794 Get physical name, extract field name from physical name. */
1795 physname
= dwarf2_linkage_name (die
);
1796 if (physname
== NULL
)
1800 while (*cp
&& !is_cplus_marker (*cp
))
1804 if (*fieldname
== '\0')
1806 complain (&dwarf2_bad_static_member_name
, physname
);
1810 fp
->bitsize
= (long) obsavestring (physname
, strlen (physname
),
1811 &objfile
->type_obstack
);
1812 fp
->type
= die_type (die
, objfile
);
1813 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1814 &objfile
->type_obstack
);
1816 else if (die
->tag
== DW_TAG_inheritance
)
1818 /* C++ base class field. */
1819 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1821 fp
->bitpos
= decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1823 fp
->type
= die_type (die
, objfile
);
1824 fp
->name
= type_name_no_tag (fp
->type
);
1825 fip
->nbaseclasses
++;
1829 /* Create the vector of fields, and attach it to the type. */
1832 dwarf2_attach_fields_to_type (fip
, type
, objfile
)
1833 struct field_info
*fip
;
1835 struct objfile
*objfile
;
1837 int nfields
= fip
->nfields
;
1839 /* Record the field count, allocate space for the array of fields,
1840 and create blank accessibility bitfields if necessary. */
1841 TYPE_NFIELDS (type
) = nfields
;
1842 TYPE_FIELDS (type
) = (struct field
*)
1843 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1844 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1846 if (fip
->non_public_fields
)
1848 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1850 TYPE_FIELD_PRIVATE_BITS (type
) =
1851 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1852 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1854 TYPE_FIELD_PROTECTED_BITS (type
) =
1855 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1856 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1858 TYPE_FIELD_IGNORE_BITS (type
) =
1859 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1860 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1863 /* If the type has baseclasses, allocate and clear a bit vector for
1864 TYPE_FIELD_VIRTUAL_BITS. */
1865 if (fip
->nbaseclasses
)
1867 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
1870 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1871 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1872 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1873 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
1874 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
1877 /* Copy the saved-up fields into the field vector. Start from the head
1878 of the list, adding to the tail of the field array, so that they end
1879 up in the same order in the array in which they were added to the list. */
1880 while (nfields
-- > 0)
1882 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
1883 switch (fip
->fields
->accessibility
)
1885 case DW_ACCESS_private
:
1886 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
1889 case DW_ACCESS_protected
:
1890 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
1893 case DW_ACCESS_public
:
1897 /* Unknown accessibility. Complain and treat it as public. */
1899 complain (&dwarf2_unsupported_accessibility
,
1900 fip
->fields
->accessibility
);
1904 if (nfields
< fip
->nbaseclasses
)
1906 switch (fip
->fields
->virtuality
)
1908 case DW_VIRTUALITY_virtual
:
1909 case DW_VIRTUALITY_pure_virtual
:
1910 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
1914 fip
->fields
= fip
->fields
->next
;
1918 /* Skip to the end of a member function name in a mangled name. */
1921 skip_member_fn_name (physname
)
1924 char *endname
= physname
;
1926 /* Skip over leading underscores. */
1927 while (*endname
== '_')
1930 /* Find two succesive underscores. */
1932 endname
= strchr (endname
, '_');
1933 while (endname
!= NULL
&& *++endname
!= '_');
1935 if (endname
== NULL
)
1937 complain (&dwarf2_bad_member_name_complaint
, physname
);
1942 /* Take care of trailing underscores. */
1943 if (endname
[1] != '_')
1949 /* Add a member function to the proper fieldlist. */
1952 dwarf2_add_member_fn (fip
, die
, type
, objfile
)
1953 struct field_info
*fip
;
1954 struct die_info
*die
;
1956 struct objfile
*objfile
;
1958 struct attribute
*attr
;
1959 struct fnfieldlist
*flp
;
1961 struct fn_field
*fnp
;
1964 struct nextfnfield
*new_fnfield
;
1966 /* Extract member function name from mangled name. */
1967 physname
= dwarf2_linkage_name (die
);
1968 if (physname
== NULL
)
1970 if ((physname
[0] == '_' && physname
[1] == '_'
1971 && strchr ("0123456789Qt", physname
[2]))
1972 || DESTRUCTOR_PREFIX_P (physname
))
1974 /* Constructor and destructor field names are set to the name
1975 of the class, but without template parameter lists.
1976 The name might be missing for anonymous aggregates. */
1977 if (TYPE_TAG_NAME (type
))
1979 char *p
= strchr (TYPE_TAG_NAME (type
), '<');
1982 fieldname
= TYPE_TAG_NAME (type
);
1984 fieldname
= obsavestring (TYPE_TAG_NAME (type
),
1985 p
- TYPE_TAG_NAME (type
),
1986 &objfile
->type_obstack
);
1990 char *anon_name
= "";
1991 fieldname
= obsavestring (anon_name
, strlen (anon_name
),
1992 &objfile
->type_obstack
);
1997 char *endname
= skip_member_fn_name (physname
);
1999 /* Ignore member function if we were unable not extract the member
2001 if (endname
== physname
)
2003 fieldname
= obsavestring (physname
, endname
- physname
,
2004 &objfile
->type_obstack
);
2007 /* Look up member function name in fieldlist. */
2008 for (i
= 0; i
< fip
->nfnfields
; i
++)
2010 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2014 /* Create new list element if necessary. */
2015 if (i
< fip
->nfnfields
)
2016 flp
= &fip
->fnfieldlists
[i
];
2019 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2021 fip
->fnfieldlists
= (struct fnfieldlist
*)
2022 xrealloc (fip
->fnfieldlists
,
2023 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2024 * sizeof (struct fnfieldlist
));
2025 if (fip
->nfnfields
== 0)
2026 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2028 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2029 flp
->name
= fieldname
;
2035 /* Create a new member function field and chain it to the field list
2037 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2038 make_cleanup (free
, new_fnfield
);
2039 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2040 new_fnfield
->next
= flp
->head
;
2041 flp
->head
= new_fnfield
;
2044 /* Fill in the member function field info. */
2045 fnp
= &new_fnfield
->fnfield
;
2046 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2047 &objfile
->type_obstack
);
2048 fnp
->type
= alloc_type (objfile
);
2049 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2051 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2052 struct type
**arg_types
;
2053 int nparams
= TYPE_NFIELDS (die
->type
);
2056 /* Copy argument types from the subroutine type. */
2057 arg_types
= (struct type
**)
2058 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2059 for (iparams
= 0; iparams
< nparams
; iparams
++)
2060 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2062 /* Set last entry in argument type vector. */
2063 if (TYPE_FLAGS (die
->type
) & TYPE_FLAG_VARARGS
)
2064 arg_types
[nparams
] = NULL
;
2066 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2068 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2070 /* Handle static member functions.
2071 Dwarf2 has no clean way to discern C++ static and non-static
2072 member functions. G++ helps GDB by marking the first
2073 parameter for non-static member functions (which is the
2074 this pointer) as artificial. We obtain this information
2075 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2076 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2077 fnp
->voffset
= VOFFSET_STATIC
;
2080 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2082 /* Get fcontext from DW_AT_containing_type if present. */
2083 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2084 fnp
->fcontext
= die_containing_type (die
, objfile
);
2086 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2087 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2089 /* Get accessibility. */
2090 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2093 switch (DW_UNSND (attr
))
2095 case DW_ACCESS_private
:
2096 fnp
->is_private
= 1;
2098 case DW_ACCESS_protected
:
2099 fnp
->is_protected
= 1;
2104 /* Get index in virtual function table if it is a virtual member function. */
2105 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2107 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
) + 2;
2110 /* Create the vector of member function fields, and attach it to the type. */
2113 dwarf2_attach_fn_fields_to_type (fip
, type
, objfile
)
2114 struct field_info
*fip
;
2116 struct objfile
*objfile
;
2118 struct fnfieldlist
*flp
;
2119 int total_length
= 0;
2122 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2123 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2124 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2126 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2128 struct nextfnfield
*nfp
= flp
->head
;
2129 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2132 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2133 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2134 fn_flp
->fn_fields
= (struct fn_field
*)
2135 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2136 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2137 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2139 total_length
+= flp
->length
;
2142 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2143 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2146 /* Called when we find the DIE that starts a structure or union scope
2147 (definition) to process all dies that define the members of the
2150 NOTE: we need to call struct_type regardless of whether or not the
2151 DIE has an at_name attribute, since it might be an anonymous
2152 structure or union. This gets the type entered into our set of
2155 However, if the structure is incomplete (an opaque struct/union)
2156 then suppress creating a symbol table entry for it since gdb only
2157 wants to find the one with the complete definition. Note that if
2158 it is complete, we just call new_symbol, which does it's own
2159 checking about whether the struct/union is anonymous or not (and
2160 suppresses creating a symbol table entry itself). */
2163 read_structure_scope (die
, objfile
)
2164 struct die_info
*die
;
2165 struct objfile
*objfile
;
2168 struct attribute
*attr
;
2170 type
= alloc_type (objfile
);
2172 INIT_CPLUS_SPECIFIC (type
);
2173 attr
= dwarf_attr (die
, DW_AT_name
);
2174 if (attr
&& DW_STRING (attr
))
2176 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2177 strlen (DW_STRING (attr
)),
2178 &objfile
->type_obstack
);
2181 if (die
->tag
== DW_TAG_structure_type
)
2183 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2185 else if (die
->tag
== DW_TAG_union_type
)
2187 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2191 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2193 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2196 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2199 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2203 TYPE_LENGTH (type
) = 0;
2206 /* We need to add the type field to the die immediately so we don't
2207 infinitely recurse when dealing with pointers to the structure
2208 type within the structure itself. */
2211 if (die
->has_children
)
2213 struct field_info fi
;
2214 struct die_info
*child_die
;
2215 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2217 memset (&fi
, 0, sizeof (struct field_info
));
2219 child_die
= die
->next
;
2221 while (child_die
&& child_die
->tag
)
2223 if (child_die
->tag
== DW_TAG_member
)
2225 dwarf2_add_field (&fi
, child_die
, objfile
);
2227 else if (child_die
->tag
== DW_TAG_variable
)
2229 /* C++ static member. */
2230 dwarf2_add_field (&fi
, child_die
, objfile
);
2232 else if (child_die
->tag
== DW_TAG_subprogram
)
2234 /* C++ member function. */
2235 process_die (child_die
, objfile
);
2236 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
);
2238 else if (child_die
->tag
== DW_TAG_inheritance
)
2240 /* C++ base class field. */
2241 dwarf2_add_field (&fi
, child_die
, objfile
);
2245 process_die (child_die
, objfile
);
2247 child_die
= sibling_die (child_die
);
2250 /* Attach fields and member functions to the type. */
2252 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2255 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2257 /* Get the type which refers to the base class (possibly this
2258 class itself) which contains the vtable pointer for the current
2259 class from the DW_AT_containing_type attribute. */
2261 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2263 struct type
*t
= die_containing_type (die
, objfile
);
2265 TYPE_VPTR_BASETYPE (type
) = t
;
2268 static const char vptr_name
[] = { '_','v','p','t','r','\0' };
2271 /* Our own class provides vtbl ptr. */
2272 for (i
= TYPE_NFIELDS (t
) - 1;
2273 i
>= TYPE_N_BASECLASSES (t
);
2276 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2278 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2279 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2281 TYPE_VPTR_FIELDNO (type
) = i
;
2286 /* Complain if virtual function table field not found. */
2287 if (i
< TYPE_N_BASECLASSES (t
))
2288 complain (&dwarf2_vtbl_not_found_complaint
,
2289 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2293 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2298 new_symbol (die
, type
, objfile
);
2300 do_cleanups (back_to
);
2304 /* No children, must be stub. */
2305 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2311 /* Given a pointer to a die which begins an enumeration, process all
2312 the dies that define the members of the enumeration.
2314 This will be much nicer in draft 6 of the DWARF spec when our
2315 members will be dies instead squished into the DW_AT_element_list
2318 NOTE: We reverse the order of the element list. */
2321 read_enumeration (die
, objfile
)
2322 struct die_info
*die
;
2323 struct objfile
*objfile
;
2325 struct die_info
*child_die
;
2327 struct field
*fields
;
2328 struct attribute
*attr
;
2331 int unsigned_enum
= 1;
2333 type
= alloc_type (objfile
);
2335 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2336 attr
= dwarf_attr (die
, DW_AT_name
);
2337 if (attr
&& DW_STRING (attr
))
2339 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2340 strlen (DW_STRING (attr
)),
2341 &objfile
->type_obstack
);
2344 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2347 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2351 TYPE_LENGTH (type
) = 0;
2356 if (die
->has_children
)
2358 child_die
= die
->next
;
2359 while (child_die
&& child_die
->tag
)
2361 if (child_die
->tag
!= DW_TAG_enumerator
)
2363 process_die (child_die
, objfile
);
2367 attr
= dwarf_attr (child_die
, DW_AT_name
);
2370 sym
= new_symbol (child_die
, type
, objfile
);
2371 if (SYMBOL_VALUE (sym
) < 0)
2374 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2376 fields
= (struct field
*)
2378 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2379 * sizeof (struct field
));
2382 fields
[num_fields
].name
= SYMBOL_NAME (sym
);
2383 fields
[num_fields
].type
= NULL
;
2384 fields
[num_fields
].bitpos
= SYMBOL_VALUE (sym
);
2385 fields
[num_fields
].bitsize
= 0;
2391 child_die
= sibling_die (child_die
);
2396 TYPE_NFIELDS (type
) = num_fields
;
2397 TYPE_FIELDS (type
) = (struct field
*)
2398 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2399 memcpy (TYPE_FIELDS (type
), fields
,
2400 sizeof (struct field
) * num_fields
);
2404 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2407 new_symbol (die
, type
, objfile
);
2410 /* Extract all information from a DW_TAG_array_type DIE and put it in
2411 the DIE's type field. For now, this only handles one dimensional
2415 read_array_type (die
, objfile
)
2416 struct die_info
*die
;
2417 struct objfile
*objfile
;
2419 struct die_info
*child_die
;
2420 struct type
*type
= NULL
;
2421 struct type
*element_type
, *range_type
, *index_type
;
2422 struct type
**range_types
= NULL
;
2423 struct attribute
*attr
;
2425 struct cleanup
*back_to
;
2427 /* Return if we've already decoded this type. */
2433 element_type
= die_type (die
, objfile
);
2435 /* Irix 6.2 native cc creates array types without children for
2436 arrays with unspecified length. */
2437 if (die
->has_children
== 0)
2439 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2440 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2441 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2445 back_to
= make_cleanup (null_cleanup
, NULL
);
2446 child_die
= die
->next
;
2447 while (child_die
&& child_die
->tag
)
2449 if (child_die
->tag
== DW_TAG_subrange_type
)
2451 unsigned int low
, high
;
2453 /* Default bounds to an array with unspecified length. */
2456 if (cu_language
== DW_LANG_Fortran77
2457 || cu_language
== DW_LANG_Fortran90
)
2459 /* FORTRAN implies a lower bound of 1, if not given. */
2463 index_type
= die_type (child_die
, objfile
);
2464 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2467 if (attr
->form
== DW_FORM_sdata
)
2469 low
= DW_SND (attr
);
2471 else if (attr
->form
== DW_FORM_udata
2472 || attr
->form
== DW_FORM_data1
2473 || attr
->form
== DW_FORM_data2
2474 || attr
->form
== DW_FORM_data4
)
2476 low
= DW_UNSND (attr
);
2480 complain (&dwarf2_non_const_array_bound_ignored
,
2481 dwarf_form_name (attr
->form
));
2483 die
->type
= lookup_pointer_type (element_type
);
2490 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2493 if (attr
->form
== DW_FORM_sdata
)
2495 high
= DW_SND (attr
);
2497 else if (attr
->form
== DW_FORM_udata
2498 || attr
->form
== DW_FORM_data1
2499 || attr
->form
== DW_FORM_data2
2500 || attr
->form
== DW_FORM_data4
)
2502 high
= DW_UNSND (attr
);
2504 else if (attr
->form
== DW_FORM_block1
)
2506 /* GCC encodes arrays with unspecified or dynamic length
2507 with a DW_FORM_block1 attribute.
2508 FIXME: GDB does not yet know how to handle dynamic
2509 arrays properly, treat them as arrays with unspecified
2515 complain (&dwarf2_non_const_array_bound_ignored
,
2516 dwarf_form_name (attr
->form
));
2518 die
->type
= lookup_pointer_type (element_type
);
2526 /* Create a range type and save it for array type creation. */
2527 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2529 range_types
= (struct type
**)
2530 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2531 * sizeof (struct type
*));
2533 make_cleanup (free_current_contents
, &range_types
);
2535 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2537 child_die
= sibling_die (child_die
);
2540 /* Dwarf2 dimensions are output from left to right, create the
2541 necessary array types in backwards order. */
2542 type
= element_type
;
2544 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2546 do_cleanups (back_to
);
2548 /* Install the type in the die. */
2552 /* First cut: install each common block member as a global variable. */
2555 read_common_block (die
, objfile
)
2556 struct die_info
*die
;
2557 struct objfile
*objfile
;
2559 struct die_info
*child_die
;
2560 struct attribute
*attr
;
2562 CORE_ADDR base
= (CORE_ADDR
) 0;
2564 attr
= dwarf_attr (die
, DW_AT_location
);
2567 base
= decode_locdesc (DW_BLOCK (attr
), objfile
);
2569 if (die
->has_children
)
2571 child_die
= die
->next
;
2572 while (child_die
&& child_die
->tag
)
2574 sym
= new_symbol (child_die
, NULL
, objfile
);
2575 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2578 SYMBOL_VALUE_ADDRESS (sym
) =
2579 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
);
2580 add_symbol_to_list (sym
, &global_symbols
);
2582 child_die
= sibling_die (child_die
);
2587 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2588 the user defined type vector. */
2591 read_tag_pointer_type (die
, objfile
)
2592 struct die_info
*die
;
2593 struct objfile
*objfile
;
2596 struct attribute
*attr
;
2603 type
= lookup_pointer_type (die_type (die
, objfile
));
2604 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2607 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2611 TYPE_LENGTH (type
) = address_size
;
2616 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2617 the user defined type vector. */
2620 read_tag_ptr_to_member_type (die
, objfile
)
2621 struct die_info
*die
;
2622 struct objfile
*objfile
;
2625 struct type
*to_type
;
2626 struct type
*domain
;
2633 type
= alloc_type (objfile
);
2634 to_type
= die_type (die
, objfile
);
2635 domain
= die_containing_type (die
, objfile
);
2636 smash_to_member_type (type
, domain
, to_type
);
2641 /* Extract all information from a DW_TAG_reference_type DIE and add to
2642 the user defined type vector. */
2645 read_tag_reference_type (die
, objfile
)
2646 struct die_info
*die
;
2647 struct objfile
*objfile
;
2650 struct attribute
*attr
;
2657 type
= lookup_reference_type (die_type (die
, objfile
));
2658 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2661 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2665 TYPE_LENGTH (type
) = address_size
;
2671 read_tag_const_type (die
, objfile
)
2672 struct die_info
*die
;
2673 struct objfile
*objfile
;
2680 complain (&dwarf2_const_ignored
);
2681 die
->type
= die_type (die
, objfile
);
2685 read_tag_volatile_type (die
, objfile
)
2686 struct die_info
*die
;
2687 struct objfile
*objfile
;
2694 complain (&dwarf2_volatile_ignored
);
2695 die
->type
= die_type (die
, objfile
);
2698 /* Extract all information from a DW_TAG_string_type DIE and add to
2699 the user defined type vector. It isn't really a user defined type,
2700 but it behaves like one, with other DIE's using an AT_user_def_type
2701 attribute to reference it. */
2704 read_tag_string_type (die
, objfile
)
2705 struct die_info
*die
;
2706 struct objfile
*objfile
;
2708 struct type
*type
, *range_type
, *index_type
, *char_type
;
2709 struct attribute
*attr
;
2710 unsigned int length
;
2717 attr
= dwarf_attr (die
, DW_AT_string_length
);
2720 length
= DW_UNSND (attr
);
2726 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2727 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2728 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2729 type
= create_string_type (char_type
, range_type
);
2733 /* Handle DIES due to C code like:
2737 int (*funcp)(int a, long l);
2741 ('funcp' generates a DW_TAG_subroutine_type DIE)
2745 read_subroutine_type (die
, objfile
)
2746 struct die_info
*die
;
2747 struct objfile
*objfile
;
2749 struct type
*type
; /* Type that this function returns */
2750 struct type
*ftype
; /* Function that returns above type */
2751 struct attribute
*attr
;
2753 /* Decode the type that this subroutine returns */
2758 type
= die_type (die
, objfile
);
2759 ftype
= lookup_function_type (type
);
2760 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2761 if (attr
&& (DW_UNSND (attr
) != 0))
2762 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2764 if (die
->has_children
)
2766 struct die_info
*child_die
;
2770 /* Count the number of parameters.
2771 FIXME: GDB currently ignores vararg functions, but knows about
2772 vararg member functions. */
2773 child_die
= die
->next
;
2774 while (child_die
&& child_die
->tag
)
2776 if (child_die
->tag
== DW_TAG_formal_parameter
)
2778 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2779 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2780 child_die
= sibling_die (child_die
);
2783 /* Allocate storage for parameters and fill them in. */
2784 TYPE_NFIELDS (ftype
) = nparams
;
2785 TYPE_FIELDS (ftype
) = (struct field
*)
2786 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2788 child_die
= die
->next
;
2789 while (child_die
&& child_die
->tag
)
2791 if (child_die
->tag
== DW_TAG_formal_parameter
)
2793 /* Dwarf2 has no clean way to discern C++ static and non-static
2794 member functions. G++ helps GDB by marking the first
2795 parameter for non-static member functions (which is the
2796 this pointer) as artificial. We pass this information
2797 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2798 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2800 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2802 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2803 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
);
2806 child_die
= sibling_die (child_die
);
2814 read_typedef (die
, objfile
)
2815 struct die_info
*die
;
2816 struct objfile
*objfile
;
2822 struct attribute
*attr
;
2825 xtype
= die_type (die
, objfile
);
2827 type
= alloc_type (objfile
);
2828 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2829 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2830 TYPE_TARGET_TYPE (type
) = xtype
;
2831 attr
= dwarf_attr (die
, DW_AT_name
);
2832 if (attr
&& DW_STRING (attr
))
2833 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2834 strlen (DW_STRING (attr
)),
2835 &objfile
->type_obstack
);
2841 /* Find a representation of a given base type and install
2842 it in the TYPE field of the die. */
2845 read_base_type (die
, objfile
)
2846 struct die_info
*die
;
2847 struct objfile
*objfile
;
2850 struct attribute
*attr
;
2851 int encoding
= 0, size
= 0;
2853 /* If we've already decoded this die, this is a no-op. */
2859 attr
= dwarf_attr (die
, DW_AT_encoding
);
2862 encoding
= DW_UNSND (attr
);
2864 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2867 size
= DW_UNSND (attr
);
2869 attr
= dwarf_attr (die
, DW_AT_name
);
2870 if (attr
&& DW_STRING (attr
))
2872 enum type_code code
= TYPE_CODE_INT
;
2873 int is_unsigned
= 0;
2877 case DW_ATE_address
:
2878 /* Turn DW_ATE_address into a void * pointer. */
2879 code
= TYPE_CODE_PTR
;
2882 case DW_ATE_boolean
:
2883 code
= TYPE_CODE_BOOL
;
2886 case DW_ATE_complex_float
:
2887 code
= TYPE_CODE_COMPLEX
;
2890 code
= TYPE_CODE_FLT
;
2893 case DW_ATE_signed_char
:
2895 case DW_ATE_unsigned
:
2896 case DW_ATE_unsigned_char
:
2900 complain (&dwarf2_unsupported_at_encoding
,
2901 dwarf_type_encoding_name (encoding
));
2904 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2905 if (encoding
== DW_ATE_address
)
2906 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2910 type
= dwarf_base_type (encoding
, size
, objfile
);
2915 /* Read a whole compilation unit into a linked list of dies. */
2918 read_comp_unit (info_ptr
, abfd
)
2922 struct die_info
*first_die
, *last_die
, *die
;
2926 /* Reset die reference table, we are building a new one now. */
2927 dwarf2_empty_die_ref_table ();
2931 first_die
= last_die
= NULL
;
2934 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
);
2935 if (die
->has_children
)
2946 /* Enter die in reference hash table */
2947 store_in_ref_table (die
->offset
, die
);
2951 first_die
= last_die
= die
;
2955 last_die
->next
= die
;
2959 while (nesting_level
> 0);
2963 /* Free a linked list of dies. */
2966 free_die_list (dies
)
2967 struct die_info
*dies
;
2969 struct die_info
*die
, *next
;
2981 /* Read the contents of the section at OFFSET and of size SIZE from the
2982 object file specified by OBJFILE into the psymbol_obstack and return it. */
2985 dwarf2_read_section (objfile
, offset
, size
)
2986 struct objfile
*objfile
;
2990 bfd
*abfd
= objfile
->obfd
;
2996 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
2997 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
2998 (bfd_read (buf
, size
, 1, abfd
) != size
))
3001 error ("Dwarf Error: Can't read DWARF data from '%s'",
3002 bfd_get_filename (abfd
));
3007 /* In DWARF version 2, the description of the debugging information is
3008 stored in a separate .debug_abbrev section. Before we read any
3009 dies from a section we read in all abbreviations and install them
3013 dwarf2_read_abbrevs (abfd
, offset
)
3015 unsigned int offset
;
3018 struct abbrev_info
*cur_abbrev
;
3019 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3020 unsigned int abbrev_form
, hash_number
;
3022 /* empty the table */
3023 dwarf2_empty_abbrev_table (NULL
);
3025 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3026 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3027 abbrev_ptr
+= bytes_read
;
3029 /* loop until we reach an abbrev number of 0 */
3030 while (abbrev_number
)
3032 cur_abbrev
= dwarf_alloc_abbrev ();
3034 /* read in abbrev header */
3035 cur_abbrev
->number
= abbrev_number
;
3036 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3037 abbrev_ptr
+= bytes_read
;
3038 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3041 /* now read in declarations */
3042 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3043 abbrev_ptr
+= bytes_read
;
3044 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3045 abbrev_ptr
+= bytes_read
;
3048 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3050 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3051 xrealloc (cur_abbrev
->attrs
,
3052 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3053 * sizeof (struct attr_abbrev
));
3055 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3056 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3057 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3058 abbrev_ptr
+= bytes_read
;
3059 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3060 abbrev_ptr
+= bytes_read
;
3063 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3064 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3065 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3067 /* Get next abbreviation.
3068 Under Irix6 the abbreviations for a compilation unit are not
3069 always properly terminated with an abbrev number of 0.
3070 Exit loop if we encounter an abbreviation which we have
3071 already read (which means we are about to read the abbreviations
3072 for the next compile unit) or if the end of the abbreviation
3073 table is reached. */
3074 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3075 >= dwarf_abbrev_size
)
3077 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3078 abbrev_ptr
+= bytes_read
;
3079 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3084 /* Empty the abbrev table for a new compilation unit. */
3088 dwarf2_empty_abbrev_table (ignore
)
3092 struct abbrev_info
*abbrev
, *next
;
3094 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3097 abbrev
= dwarf2_abbrevs
[i
];
3100 next
= abbrev
->next
;
3101 free (abbrev
->attrs
);
3105 dwarf2_abbrevs
[i
] = NULL
;
3109 /* Lookup an abbrev_info structure in the abbrev hash table. */
3111 static struct abbrev_info
*
3112 dwarf2_lookup_abbrev (number
)
3113 unsigned int number
;
3115 unsigned int hash_number
;
3116 struct abbrev_info
*abbrev
;
3118 hash_number
= number
% ABBREV_HASH_SIZE
;
3119 abbrev
= dwarf2_abbrevs
[hash_number
];
3123 if (abbrev
->number
== number
)
3126 abbrev
= abbrev
->next
;
3131 /* Read a minimal amount of information into the minimal die structure. */
3134 read_partial_die (part_die
, abfd
, info_ptr
, has_pc_info
)
3135 struct partial_die_info
*part_die
;
3140 unsigned int abbrev_number
, bytes_read
, i
;
3141 struct abbrev_info
*abbrev
;
3142 struct attribute attr
;
3143 struct attribute spec_attr
;
3144 int found_spec_attr
= 0;
3145 int has_low_pc_attr
= 0;
3146 int has_high_pc_attr
= 0;
3148 *part_die
= zeroed_partial_die
;
3150 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3151 info_ptr
+= bytes_read
;
3155 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3158 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3160 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3161 part_die
->tag
= abbrev
->tag
;
3162 part_die
->has_children
= abbrev
->has_children
;
3163 part_die
->abbrev
= abbrev_number
;
3165 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3167 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
);
3169 /* Store the data if it is of an attribute we want to keep in a
3170 partial symbol table. */
3175 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3176 if (part_die
->name
== NULL
)
3177 part_die
->name
= DW_STRING (&attr
);
3179 case DW_AT_MIPS_linkage_name
:
3180 part_die
->name
= DW_STRING (&attr
);
3183 has_low_pc_attr
= 1;
3184 part_die
->lowpc
= DW_ADDR (&attr
);
3187 has_high_pc_attr
= 1;
3188 part_die
->highpc
= DW_ADDR (&attr
);
3190 case DW_AT_location
:
3191 part_die
->locdesc
= DW_BLOCK (&attr
);
3193 case DW_AT_language
:
3194 part_die
->language
= DW_UNSND (&attr
);
3196 case DW_AT_external
:
3197 part_die
->is_external
= DW_UNSND (&attr
);
3199 case DW_AT_declaration
:
3200 part_die
->is_declaration
= DW_UNSND (&attr
);
3203 part_die
->has_type
= 1;
3205 case DW_AT_abstract_origin
:
3206 case DW_AT_specification
:
3207 found_spec_attr
= 1;
3211 /* Ignore absolute siblings, they might point outside of
3212 the current compile unit. */
3213 if (attr
.form
== DW_FORM_ref_addr
)
3214 complain(&dwarf2_absolute_sibling_complaint
);
3217 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3224 /* If we found a reference attribute and the die has no name, try
3225 to find a name in the referred to die. */
3227 if (found_spec_attr
&& part_die
->name
== NULL
)
3229 struct partial_die_info spec_die
;
3233 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3234 read_partial_die (&spec_die
, abfd
, spec_ptr
, &dummy
);
3237 part_die
->name
= spec_die
.name
;
3239 /* Copy DW_AT_external attribute if it is set. */
3240 if (spec_die
.is_external
)
3241 part_die
->is_external
= spec_die
.is_external
;
3245 /* When using the GNU linker, .gnu.linkonce. sections are used to
3246 eliminate duplicate copies of functions and vtables and such.
3247 The linker will arbitrarily choose one and discard the others.
3248 The AT_*_pc values for such functions refer to local labels in
3249 these sections. If the section from that file was discarded, the
3250 labels are not in the output, so the relocs get a value of 0.
3251 If this is a discarded function, mark the pc bounds as invalid,
3252 so that GDB will ignore it. */
3253 if (has_low_pc_attr
&& has_high_pc_attr
3254 && part_die
->lowpc
< part_die
->highpc
3255 && (part_die
->lowpc
!= 0
3256 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3261 /* Read the die from the .debug_info section buffer. And set diep to
3262 point to a newly allocated die with its information. */
3265 read_full_die (diep
, abfd
, info_ptr
)
3266 struct die_info
**diep
;
3270 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3271 struct abbrev_info
*abbrev
;
3272 struct die_info
*die
;
3274 offset
= info_ptr
- dwarf_info_buffer
;
3275 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3276 info_ptr
+= bytes_read
;
3279 die
= dwarf_alloc_die ();
3281 die
->abbrev
= abbrev_number
;
3287 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3290 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3292 die
= dwarf_alloc_die ();
3293 die
->offset
= offset
;
3294 die
->tag
= abbrev
->tag
;
3295 die
->has_children
= abbrev
->has_children
;
3296 die
->abbrev
= abbrev_number
;
3299 die
->num_attrs
= abbrev
->num_attrs
;
3300 die
->attrs
= (struct attribute
*)
3301 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3303 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3305 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3313 /* Read an attribute described by an abbreviated attribute. */
3316 read_attribute (attr
, abbrev
, abfd
, info_ptr
)
3317 struct attribute
*attr
;
3318 struct attr_abbrev
*abbrev
;
3322 unsigned int bytes_read
;
3323 struct dwarf_block
*blk
;
3325 attr
->name
= abbrev
->name
;
3326 attr
->form
= abbrev
->form
;
3327 switch (abbrev
->form
)
3330 case DW_FORM_ref_addr
:
3331 DW_ADDR (attr
) = read_address (abfd
, info_ptr
);
3332 info_ptr
+= address_size
;
3334 case DW_FORM_block2
:
3335 blk
= dwarf_alloc_block ();
3336 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3338 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3339 info_ptr
+= blk
->size
;
3340 DW_BLOCK (attr
) = blk
;
3342 case DW_FORM_block4
:
3343 blk
= dwarf_alloc_block ();
3344 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3346 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3347 info_ptr
+= blk
->size
;
3348 DW_BLOCK (attr
) = blk
;
3351 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3355 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3359 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3362 case DW_FORM_string
:
3363 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3364 info_ptr
+= bytes_read
;
3367 blk
= dwarf_alloc_block ();
3368 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3369 info_ptr
+= bytes_read
;
3370 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3371 info_ptr
+= blk
->size
;
3372 DW_BLOCK (attr
) = blk
;
3374 case DW_FORM_block1
:
3375 blk
= dwarf_alloc_block ();
3376 blk
->size
= read_1_byte (abfd
, info_ptr
);
3378 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3379 info_ptr
+= blk
->size
;
3380 DW_BLOCK (attr
) = blk
;
3383 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3387 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3391 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3392 info_ptr
+= bytes_read
;
3395 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3396 info_ptr
+= bytes_read
;
3399 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3403 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3407 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3410 case DW_FORM_ref_udata
:
3411 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3412 info_ptr
+= bytes_read
;
3415 case DW_FORM_indirect
:
3417 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3418 dwarf_form_name (abbrev
->form
));
3423 /* read dwarf information from a buffer */
3426 read_1_byte (abfd
, buf
)
3430 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3434 read_1_signed_byte (abfd
, buf
)
3438 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3442 read_2_bytes (abfd
, buf
)
3446 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3450 read_2_signed_bytes (abfd
, buf
)
3454 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3458 read_4_bytes (abfd
, buf
)
3462 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3466 read_4_signed_bytes (abfd
, buf
)
3470 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3474 read_8_bytes (abfd
, buf
)
3478 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3482 read_address (abfd
, buf
)
3486 CORE_ADDR retval
= 0;
3488 if (address_size
== 4)
3490 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3491 } else { /* *THE* alternative is 8, right? */
3492 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3498 read_n_bytes (abfd
, buf
, size
)
3503 /* If the size of a host char is 8 bits, we can return a pointer
3504 to the buffer, otherwise we have to copy the data to a buffer
3505 allocated on the temporary obstack. */
3506 #if HOST_CHAR_BIT == 8
3512 ret
= obstack_alloc (&dwarf2_tmp_obstack
, size
);
3513 for (i
= 0; i
< size
; ++i
)
3515 ret
[i
] = bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3523 read_string (abfd
, buf
, bytes_read_ptr
)
3526 unsigned int *bytes_read_ptr
;
3528 /* If the size of a host char is 8 bits, we can return a pointer
3529 to the string, otherwise we have to copy the string to a buffer
3530 allocated on the temporary obstack. */
3531 #if HOST_CHAR_BIT == 8
3534 *bytes_read_ptr
= 1;
3537 *bytes_read_ptr
= strlen (buf
) + 1;
3543 while ((byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
)) != 0)
3545 obstack_1grow (&dwarf2_tmp_obstack
, byte
);
3551 *bytes_read_ptr
= 1;
3554 obstack_1grow (&dwarf2_tmp_obstack
, '\0');
3555 *bytes_read_ptr
= i
+ 1;
3556 return obstack_finish (&dwarf2_tmp_obstack
);
3561 read_unsigned_leb128 (abfd
, buf
, bytes_read_ptr
)
3564 unsigned int *bytes_read_ptr
;
3566 unsigned int result
, num_read
;
3576 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3579 result
|= ((byte
& 127) << shift
);
3580 if ((byte
& 128) == 0)
3586 *bytes_read_ptr
= num_read
;
3591 read_signed_leb128 (abfd
, buf
, bytes_read_ptr
)
3594 unsigned int *bytes_read_ptr
;
3597 int i
, shift
, size
, num_read
;
3607 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3610 result
|= ((byte
& 127) << shift
);
3612 if ((byte
& 128) == 0)
3617 if ((shift
< size
) && (byte
& 0x40))
3619 result
|= -(1 << shift
);
3621 *bytes_read_ptr
= num_read
;
3626 set_cu_language (lang
)
3633 case DW_LANG_Fortran77
:
3634 cu_language
= language_c
;
3636 case DW_LANG_C_plus_plus
:
3637 cu_language
= language_cplus
;
3639 case DW_LANG_Mips_Assembler
:
3640 cu_language
= language_asm
;
3643 case DW_LANG_Cobol74
:
3644 case DW_LANG_Cobol85
:
3646 case DW_LANG_Fortran77
: /* moved up top for now */
3648 case DW_LANG_Fortran90
:
3649 case DW_LANG_Pascal83
:
3650 case DW_LANG_Modula2
:
3652 cu_language
= language_unknown
;
3655 cu_language_defn
= language_def (cu_language
);
3658 /* Return the named attribute or NULL if not there. */
3660 static struct attribute
*
3661 dwarf_attr (die
, name
)
3662 struct die_info
*die
;
3666 struct attribute
*spec
= NULL
;
3668 for (i
= 0; i
< die
->num_attrs
; ++i
)
3670 if (die
->attrs
[i
].name
== name
)
3672 return &die
->attrs
[i
];
3674 if (die
->attrs
[i
].name
== DW_AT_specification
3675 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3676 spec
= &die
->attrs
[i
];
3680 struct die_info
*ref_die
=
3681 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3684 return dwarf_attr (ref_die
, name
);
3690 /* Decode the line number information for the compilation unit whose
3691 line number info is at OFFSET in the .debug_line section.
3692 The compilation directory of the file is passed in COMP_DIR. */
3696 unsigned int num_files
;
3709 unsigned int num_dirs
;
3714 dwarf_decode_lines (offset
, comp_dir
, abfd
)
3715 unsigned int offset
;
3721 struct line_head lh
;
3722 struct cleanup
*back_to
;
3723 unsigned int i
, bytes_read
;
3724 char *cur_file
, *cur_dir
;
3725 unsigned char op_code
, extended_op
, adj_opcode
;
3727 #define FILE_ALLOC_CHUNK 5
3728 #define DIR_ALLOC_CHUNK 5
3730 struct filenames files
;
3731 struct directories dirs
;
3733 if (dwarf_line_buffer
== NULL
)
3735 complain (&dwarf2_missing_line_number_section
);
3739 files
.num_files
= 0;
3745 line_ptr
= dwarf_line_buffer
+ offset
;
3747 /* read in the prologue */
3748 lh
.total_length
= read_4_bytes (abfd
, line_ptr
);
3750 line_end
= line_ptr
+ lh
.total_length
;
3751 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3753 lh
.prologue_length
= read_4_bytes (abfd
, line_ptr
);
3755 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3757 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3759 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3761 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3763 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3765 lh
.standard_opcode_lengths
= (unsigned char *)
3766 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3767 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
3769 lh
.standard_opcode_lengths
[0] = 1;
3770 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3772 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3776 /* Read directory table */
3777 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3779 line_ptr
+= bytes_read
;
3780 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3782 dirs
.dirs
= (char **)
3783 xrealloc (dirs
.dirs
,
3784 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3785 if (dirs
.num_dirs
== 0)
3786 make_cleanup (free_current_contents
, &dirs
.dirs
);
3788 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3790 line_ptr
+= bytes_read
;
3792 /* Read file name table */
3793 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3795 line_ptr
+= bytes_read
;
3796 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3798 files
.files
= (struct fileinfo
*)
3799 xrealloc (files
.files
,
3800 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3801 * sizeof (struct fileinfo
));
3802 if (files
.num_files
== 0)
3803 make_cleanup (free_current_contents
, &files
.files
);
3805 files
.files
[files
.num_files
].name
= cur_file
;
3806 files
.files
[files
.num_files
].dir
=
3807 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3808 line_ptr
+= bytes_read
;
3809 files
.files
[files
.num_files
].time
=
3810 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3811 line_ptr
+= bytes_read
;
3812 files
.files
[files
.num_files
].size
=
3813 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3814 line_ptr
+= bytes_read
;
3817 line_ptr
+= bytes_read
;
3819 /* Read the statement sequences until there's nothing left. */
3820 while (line_ptr
< line_end
)
3822 /* state machine registers */
3823 unsigned int address
= 0;
3824 unsigned int file
= 1;
3825 unsigned int line
= 1;
3826 unsigned int column
= 0;
3827 int is_stmt
= lh
.default_is_stmt
;
3828 int basic_block
= 0;
3829 int end_sequence
= 0;
3831 /* Start a subfile for the current file of the state machine. */
3832 if (files
.num_files
>= file
)
3834 /* The file and directory tables are 0 based, the references
3836 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3837 (files
.files
[file
- 1].dir
3838 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3842 /* Decode the table. */
3843 while (! end_sequence
)
3845 op_code
= read_1_byte (abfd
, line_ptr
);
3849 case DW_LNS_extended_op
:
3850 line_ptr
+= 1; /* ignore length */
3851 extended_op
= read_1_byte (abfd
, line_ptr
);
3853 switch (extended_op
)
3855 case DW_LNE_end_sequence
:
3857 record_line (current_subfile
, line
, address
);
3859 case DW_LNE_set_address
:
3860 address
= read_address (abfd
, line_ptr
) + baseaddr
;
3861 line_ptr
+= address_size
;
3863 case DW_LNE_define_file
:
3864 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
3865 line_ptr
+= bytes_read
;
3866 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3868 files
.files
= (struct fileinfo
*)
3869 xrealloc (files
.files
,
3870 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3871 * sizeof (struct fileinfo
));
3872 if (files
.num_files
== 0)
3873 make_cleanup (free_current_contents
, &files
.files
);
3875 files
.files
[files
.num_files
].name
= cur_file
;
3876 files
.files
[files
.num_files
].dir
=
3877 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3878 line_ptr
+= bytes_read
;
3879 files
.files
[files
.num_files
].time
=
3880 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3881 line_ptr
+= bytes_read
;
3882 files
.files
[files
.num_files
].size
=
3883 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3884 line_ptr
+= bytes_read
;
3888 complain (&dwarf2_mangled_line_number_section
);
3893 record_line (current_subfile
, line
, address
);
3896 case DW_LNS_advance_pc
:
3897 address
+= lh
.minimum_instruction_length
3898 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3899 line_ptr
+= bytes_read
;
3901 case DW_LNS_advance_line
:
3902 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
3903 line_ptr
+= bytes_read
;
3905 case DW_LNS_set_file
:
3906 /* The file and directory tables are 0 based, the references
3908 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3909 line_ptr
+= bytes_read
;
3910 dwarf2_start_subfile
3911 (files
.files
[file
- 1].name
,
3912 (files
.files
[file
- 1].dir
3913 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3916 case DW_LNS_set_column
:
3917 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3918 line_ptr
+= bytes_read
;
3920 case DW_LNS_negate_stmt
:
3921 is_stmt
= (!is_stmt
);
3923 case DW_LNS_set_basic_block
:
3926 case DW_LNS_const_add_pc
:
3927 address
+= (255 - lh
.opcode_base
) / lh
.line_range
;
3929 case DW_LNS_fixed_advance_pc
:
3930 address
+= read_2_bytes (abfd
, line_ptr
);
3933 default: /* special operand */
3934 adj_opcode
= op_code
- lh
.opcode_base
;
3935 address
+= (adj_opcode
/ lh
.line_range
)
3936 * lh
.minimum_instruction_length
;
3937 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
3938 /* append row to matrix using current values */
3939 record_line (current_subfile
, line
, address
);
3945 do_cleanups (back_to
);
3948 /* Start a subfile for DWARF. FILENAME is the name of the file and
3949 DIRNAME the name of the source directory which contains FILENAME
3950 or NULL if not known.
3951 This routine tries to keep line numbers from identical absolute and
3952 relative file names in a common subfile.
3954 Using the `list' example from the GDB testsuite, which resides in
3955 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
3956 of /srcdir/list0.c yields the following debugging information for list0.c:
3958 DW_AT_name: /srcdir/list0.c
3959 DW_AT_comp_dir: /compdir
3960 files.files[0].name: list0.h
3961 files.files[0].dir: /srcdir
3962 files.files[1].name: list0.c
3963 files.files[1].dir: /srcdir
3965 The line number information for list0.c has to end up in a single
3966 subfile, so that `break /srcdir/list0.c:1' works as expected. */
3969 dwarf2_start_subfile (filename
, dirname
)
3973 /* If the filename isn't absolute, try to match an existing subfile
3974 with the full pathname. */
3976 if (*filename
!= '/' && dirname
!= NULL
)
3978 struct subfile
*subfile
;
3979 char *fullname
= concat (dirname
, "/", filename
, NULL
);
3981 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
3983 if (STREQ (subfile
->name
, fullname
))
3985 current_subfile
= subfile
;
3992 start_subfile (filename
, dirname
);
3995 /* Given a pointer to a DWARF information entry, figure out if we need
3996 to make a symbol table entry for it, and if so, create a new entry
3997 and return a pointer to it.
3998 If TYPE is NULL, determine symbol type from the die, otherwise
3999 used the passed type.
4002 static struct symbol
*
4003 new_symbol (die
, type
, objfile
)
4004 struct die_info
*die
;
4006 struct objfile
*objfile
;
4008 struct symbol
*sym
= NULL
;
4010 struct attribute
*attr
= NULL
;
4011 struct attribute
*attr2
= NULL
;
4014 name
= dwarf2_linkage_name (die
);
4017 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4018 sizeof (struct symbol
));
4019 OBJSTAT (objfile
, n_syms
++);
4020 memset (sym
, 0, sizeof (struct symbol
));
4021 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4022 &objfile
->symbol_obstack
);
4024 /* Default assumptions.
4025 Use the passed type or decode it from the die. */
4026 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4027 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4029 SYMBOL_TYPE (sym
) = type
;
4031 SYMBOL_TYPE (sym
) = die_type (die
, objfile
);
4032 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4035 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4038 /* If this symbol is from a C++ compilation, then attempt to
4039 cache the demangled form for future reference. This is a
4040 typical time versus space tradeoff, that was decided in favor
4041 of time because it sped up C++ symbol lookups by a factor of
4044 SYMBOL_LANGUAGE (sym
) = cu_language
;
4045 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4049 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4052 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4054 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4056 case DW_TAG_subprogram
:
4057 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4059 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4060 attr2
= dwarf_attr (die
, DW_AT_external
);
4061 if (attr2
&& (DW_UNSND (attr2
) != 0))
4063 add_symbol_to_list (sym
, &global_symbols
);
4067 add_symbol_to_list (sym
, list_in_scope
);
4070 case DW_TAG_variable
:
4071 /* Compilation with minimal debug info may result in variables
4072 with missing type entries. Change the misleading `void' type
4073 to something sensible. */
4074 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4075 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4076 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4077 "<variable, no debug info>",
4079 attr
= dwarf_attr (die
, DW_AT_const_value
);
4082 dwarf2_const_value (attr
, sym
, objfile
);
4083 attr2
= dwarf_attr (die
, DW_AT_external
);
4084 if (attr2
&& (DW_UNSND (attr2
) != 0))
4085 add_symbol_to_list (sym
, &global_symbols
);
4087 add_symbol_to_list (sym
, list_in_scope
);
4090 attr
= dwarf_attr (die
, DW_AT_location
);
4093 attr2
= dwarf_attr (die
, DW_AT_external
);
4094 if (attr2
&& (DW_UNSND (attr2
) != 0))
4096 SYMBOL_VALUE_ADDRESS (sym
) =
4097 decode_locdesc (DW_BLOCK (attr
), objfile
);
4098 add_symbol_to_list (sym
, &global_symbols
);
4100 /* In shared libraries the address of the variable
4101 in the location descriptor might still be relocatable,
4102 so its value could be zero.
4103 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4104 value is zero, the address of the variable will then
4105 be determined from the minimal symbol table whenever
4106 the variable is referenced. */
4107 if (SYMBOL_VALUE_ADDRESS (sym
))
4109 SYMBOL_VALUE_ADDRESS (sym
) += baseaddr
;
4110 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4113 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4117 SYMBOL_VALUE (sym
) = addr
=
4118 decode_locdesc (DW_BLOCK (attr
), objfile
);
4119 add_symbol_to_list (sym
, list_in_scope
);
4122 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4126 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4130 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4131 SYMBOL_BASEREG (sym
) = basereg
;
4135 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4139 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4140 SYMBOL_VALUE_ADDRESS (sym
) = addr
+ baseaddr
;
4146 /* We do not know the address of this symbol.
4147 If it is an external symbol and we have type information
4148 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4149 The address of the variable will then be determined from
4150 the minimal symbol table whenever the variable is
4152 attr2
= dwarf_attr (die
, DW_AT_external
);
4153 if (attr2
&& (DW_UNSND (attr2
) != 0)
4154 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4156 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4157 add_symbol_to_list (sym
, &global_symbols
);
4161 case DW_TAG_formal_parameter
:
4162 attr
= dwarf_attr (die
, DW_AT_location
);
4165 SYMBOL_VALUE (sym
) = decode_locdesc (DW_BLOCK (attr
), objfile
);
4168 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4172 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4173 SYMBOL_BASEREG (sym
) = basereg
;
4177 SYMBOL_CLASS (sym
) = LOC_ARG
;
4180 attr
= dwarf_attr (die
, DW_AT_const_value
);
4183 dwarf2_const_value (attr
, sym
, objfile
);
4185 add_symbol_to_list (sym
, list_in_scope
);
4187 case DW_TAG_unspecified_parameters
:
4188 /* From varargs functions; gdb doesn't seem to have any
4189 interest in this information, so just ignore it for now.
4192 case DW_TAG_class_type
:
4193 case DW_TAG_structure_type
:
4194 case DW_TAG_union_type
:
4195 case DW_TAG_enumeration_type
:
4196 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4197 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4198 add_symbol_to_list (sym
, list_in_scope
);
4200 /* The semantics of C++ state that "struct foo { ... }" also
4201 defines a typedef for "foo". Synthesize a typedef symbol so
4202 that "ptype foo" works as expected. */
4203 if (cu_language
== language_cplus
)
4205 struct symbol
*typedef_sym
= (struct symbol
*)
4206 obstack_alloc (&objfile
->symbol_obstack
,
4207 sizeof (struct symbol
));
4208 *typedef_sym
= *sym
;
4209 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4210 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4211 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4212 obsavestring (SYMBOL_NAME (sym
),
4213 strlen (SYMBOL_NAME (sym
)),
4214 &objfile
->type_obstack
);
4215 add_symbol_to_list (typedef_sym
, list_in_scope
);
4218 case DW_TAG_typedef
:
4219 case DW_TAG_base_type
:
4220 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4221 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4222 add_symbol_to_list (sym
, list_in_scope
);
4224 case DW_TAG_enumerator
:
4225 attr
= dwarf_attr (die
, DW_AT_const_value
);
4228 dwarf2_const_value (attr
, sym
, objfile
);
4230 add_symbol_to_list (sym
, list_in_scope
);
4233 /* Not a tag we recognize. Hopefully we aren't processing
4234 trash data, but since we must specifically ignore things
4235 we don't recognize, there is nothing else we should do at
4237 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4244 /* Copy constant value from an attribute to a symbol. */
4247 dwarf2_const_value (attr
, sym
, objfile
)
4248 struct attribute
*attr
;
4250 struct objfile
*objfile
;
4252 struct dwarf_block
*blk
;
4257 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != (unsigned int) address_size
)
4258 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4259 address_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4260 SYMBOL_VALUE_BYTES (sym
) = (char *)
4261 obstack_alloc (&objfile
->symbol_obstack
, address_size
);
4262 store_address (SYMBOL_VALUE_BYTES (sym
), address_size
, DW_ADDR (attr
));
4263 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4265 case DW_FORM_block1
:
4266 case DW_FORM_block2
:
4267 case DW_FORM_block4
:
4269 blk
= DW_BLOCK (attr
);
4270 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4271 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4272 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4273 SYMBOL_VALUE_BYTES (sym
) = (char *)
4274 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4275 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4276 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4284 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4285 SYMBOL_CLASS (sym
) = LOC_CONST
;
4288 complain (&dwarf2_unsupported_const_value_attr
,
4289 dwarf_form_name (attr
->form
));
4290 SYMBOL_VALUE (sym
) = 0;
4291 SYMBOL_CLASS (sym
) = LOC_CONST
;
4296 /* Return the type of the die in question using its DW_AT_type attribute. */
4298 static struct type
*
4299 die_type (die
, objfile
)
4300 struct die_info
*die
;
4301 struct objfile
*objfile
;
4304 struct attribute
*type_attr
;
4305 struct die_info
*type_die
;
4308 type_attr
= dwarf_attr (die
, DW_AT_type
);
4311 /* A missing DW_AT_type represents a void type. */
4312 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4316 ref
= dwarf2_get_ref_die_offset (type_attr
);
4317 type_die
= follow_die_ref (ref
);
4320 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4324 type
= tag_type_to_type (type_die
, objfile
);
4327 dump_die (type_die
);
4328 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4333 /* Return the containing type of the die in question using its
4334 DW_AT_containing_type attribute. */
4336 static struct type
*
4337 die_containing_type (die
, objfile
)
4338 struct die_info
*die
;
4339 struct objfile
*objfile
;
4341 struct type
*type
= NULL
;
4342 struct attribute
*type_attr
;
4343 struct die_info
*type_die
= NULL
;
4346 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4349 ref
= dwarf2_get_ref_die_offset (type_attr
);
4350 type_die
= follow_die_ref (ref
);
4353 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4356 type
= tag_type_to_type (type_die
, objfile
);
4361 dump_die (type_die
);
4362 error ("Dwarf Error: Problem turning containing type into gdb type.");
4368 static struct type
*
4369 type_at_offset (offset
, objfile
)
4370 unsigned int offset
;
4371 struct objfile
*objfile
;
4373 struct die_info
*die
;
4376 die
= follow_die_ref (offset
);
4379 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4382 type
= tag_type_to_type (die
, objfile
);
4387 static struct type
*
4388 tag_type_to_type (die
, objfile
)
4389 struct die_info
*die
;
4390 struct objfile
*objfile
;
4398 read_type_die (die
, objfile
);
4402 error ("Dwarf Error: Cannot find type of die.");
4409 read_type_die (die
, objfile
)
4410 struct die_info
*die
;
4411 struct objfile
*objfile
;
4415 case DW_TAG_class_type
:
4416 case DW_TAG_structure_type
:
4417 case DW_TAG_union_type
:
4418 read_structure_scope (die
, objfile
);
4420 case DW_TAG_enumeration_type
:
4421 read_enumeration (die
, objfile
);
4423 case DW_TAG_subprogram
:
4424 case DW_TAG_subroutine_type
:
4425 read_subroutine_type (die
, objfile
);
4427 case DW_TAG_array_type
:
4428 read_array_type (die
, objfile
);
4430 case DW_TAG_pointer_type
:
4431 read_tag_pointer_type (die
, objfile
);
4433 case DW_TAG_ptr_to_member_type
:
4434 read_tag_ptr_to_member_type (die
, objfile
);
4436 case DW_TAG_reference_type
:
4437 read_tag_reference_type (die
, objfile
);
4439 case DW_TAG_const_type
:
4440 read_tag_const_type (die
, objfile
);
4442 case DW_TAG_volatile_type
:
4443 read_tag_volatile_type (die
, objfile
);
4445 case DW_TAG_string_type
:
4446 read_tag_string_type (die
, objfile
);
4448 case DW_TAG_typedef
:
4449 read_typedef (die
, objfile
);
4451 case DW_TAG_base_type
:
4452 read_base_type (die
, objfile
);
4455 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4460 static struct type
*
4461 dwarf_base_type (encoding
, size
, objfile
)
4464 struct objfile
*objfile
;
4466 /* FIXME - this should not produce a new (struct type *)
4467 every time. It should cache base types. */
4471 case DW_ATE_address
:
4472 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4474 case DW_ATE_boolean
:
4475 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4477 case DW_ATE_complex_float
:
4480 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4484 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4490 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4494 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4501 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4504 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4508 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4512 case DW_ATE_signed_char
:
4513 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4515 case DW_ATE_unsigned
:
4519 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4522 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4526 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4530 case DW_ATE_unsigned_char
:
4531 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4534 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4542 struct die_info
*old_die
;
4544 struct die_info
*new_die
;
4547 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4548 memset (new_die
, 0, sizeof (struct die_info
));
4550 new_die
->tag
= old_die
->tag
;
4551 new_die
->has_children
= old_die
->has_children
;
4552 new_die
->abbrev
= old_die
->abbrev
;
4553 new_die
->offset
= old_die
->offset
;
4554 new_die
->type
= NULL
;
4556 num_attrs
= old_die
->num_attrs
;
4557 new_die
->num_attrs
= num_attrs
;
4558 new_die
->attrs
= (struct attribute
*)
4559 xmalloc (num_attrs
* sizeof (struct attribute
));
4561 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4563 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4564 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4565 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4568 new_die
->next
= NULL
;
4573 /* Return sibling of die, NULL if no sibling. */
4577 struct die_info
*die
;
4579 int nesting_level
= 0;
4581 if (!die
->has_children
)
4583 if (die
->next
&& (die
->next
->tag
== 0))
4596 if (die
->has_children
)
4606 while (nesting_level
);
4607 if (die
&& (die
->tag
== 0))
4618 /* Get linkage name of a die, return NULL if not found. */
4621 dwarf2_linkage_name (die
)
4622 struct die_info
*die
;
4624 struct attribute
*attr
;
4626 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4627 if (attr
&& DW_STRING (attr
))
4628 return DW_STRING (attr
);
4629 attr
= dwarf_attr (die
, DW_AT_name
);
4630 if (attr
&& DW_STRING (attr
))
4631 return DW_STRING (attr
);
4635 /* Convert a DIE tag into its string name. */
4638 dwarf_tag_name (tag
)
4639 register unsigned tag
;
4643 case DW_TAG_padding
:
4644 return "DW_TAG_padding";
4645 case DW_TAG_array_type
:
4646 return "DW_TAG_array_type";
4647 case DW_TAG_class_type
:
4648 return "DW_TAG_class_type";
4649 case DW_TAG_entry_point
:
4650 return "DW_TAG_entry_point";
4651 case DW_TAG_enumeration_type
:
4652 return "DW_TAG_enumeration_type";
4653 case DW_TAG_formal_parameter
:
4654 return "DW_TAG_formal_parameter";
4655 case DW_TAG_imported_declaration
:
4656 return "DW_TAG_imported_declaration";
4658 return "DW_TAG_label";
4659 case DW_TAG_lexical_block
:
4660 return "DW_TAG_lexical_block";
4662 return "DW_TAG_member";
4663 case DW_TAG_pointer_type
:
4664 return "DW_TAG_pointer_type";
4665 case DW_TAG_reference_type
:
4666 return "DW_TAG_reference_type";
4667 case DW_TAG_compile_unit
:
4668 return "DW_TAG_compile_unit";
4669 case DW_TAG_string_type
:
4670 return "DW_TAG_string_type";
4671 case DW_TAG_structure_type
:
4672 return "DW_TAG_structure_type";
4673 case DW_TAG_subroutine_type
:
4674 return "DW_TAG_subroutine_type";
4675 case DW_TAG_typedef
:
4676 return "DW_TAG_typedef";
4677 case DW_TAG_union_type
:
4678 return "DW_TAG_union_type";
4679 case DW_TAG_unspecified_parameters
:
4680 return "DW_TAG_unspecified_parameters";
4681 case DW_TAG_variant
:
4682 return "DW_TAG_variant";
4683 case DW_TAG_common_block
:
4684 return "DW_TAG_common_block";
4685 case DW_TAG_common_inclusion
:
4686 return "DW_TAG_common_inclusion";
4687 case DW_TAG_inheritance
:
4688 return "DW_TAG_inheritance";
4689 case DW_TAG_inlined_subroutine
:
4690 return "DW_TAG_inlined_subroutine";
4692 return "DW_TAG_module";
4693 case DW_TAG_ptr_to_member_type
:
4694 return "DW_TAG_ptr_to_member_type";
4695 case DW_TAG_set_type
:
4696 return "DW_TAG_set_type";
4697 case DW_TAG_subrange_type
:
4698 return "DW_TAG_subrange_type";
4699 case DW_TAG_with_stmt
:
4700 return "DW_TAG_with_stmt";
4701 case DW_TAG_access_declaration
:
4702 return "DW_TAG_access_declaration";
4703 case DW_TAG_base_type
:
4704 return "DW_TAG_base_type";
4705 case DW_TAG_catch_block
:
4706 return "DW_TAG_catch_block";
4707 case DW_TAG_const_type
:
4708 return "DW_TAG_const_type";
4709 case DW_TAG_constant
:
4710 return "DW_TAG_constant";
4711 case DW_TAG_enumerator
:
4712 return "DW_TAG_enumerator";
4713 case DW_TAG_file_type
:
4714 return "DW_TAG_file_type";
4716 return "DW_TAG_friend";
4717 case DW_TAG_namelist
:
4718 return "DW_TAG_namelist";
4719 case DW_TAG_namelist_item
:
4720 return "DW_TAG_namelist_item";
4721 case DW_TAG_packed_type
:
4722 return "DW_TAG_packed_type";
4723 case DW_TAG_subprogram
:
4724 return "DW_TAG_subprogram";
4725 case DW_TAG_template_type_param
:
4726 return "DW_TAG_template_type_param";
4727 case DW_TAG_template_value_param
:
4728 return "DW_TAG_template_value_param";
4729 case DW_TAG_thrown_type
:
4730 return "DW_TAG_thrown_type";
4731 case DW_TAG_try_block
:
4732 return "DW_TAG_try_block";
4733 case DW_TAG_variant_part
:
4734 return "DW_TAG_variant_part";
4735 case DW_TAG_variable
:
4736 return "DW_TAG_variable";
4737 case DW_TAG_volatile_type
:
4738 return "DW_TAG_volatile_type";
4739 case DW_TAG_MIPS_loop
:
4740 return "DW_TAG_MIPS_loop";
4741 case DW_TAG_format_label
:
4742 return "DW_TAG_format_label";
4743 case DW_TAG_function_template
:
4744 return "DW_TAG_function_template";
4745 case DW_TAG_class_template
:
4746 return "DW_TAG_class_template";
4748 return "DW_TAG_<unknown>";
4752 /* Convert a DWARF attribute code into its string name. */
4755 dwarf_attr_name (attr
)
4756 register unsigned attr
;
4761 return "DW_AT_sibling";
4762 case DW_AT_location
:
4763 return "DW_AT_location";
4765 return "DW_AT_name";
4766 case DW_AT_ordering
:
4767 return "DW_AT_ordering";
4768 case DW_AT_subscr_data
:
4769 return "DW_AT_subscr_data";
4770 case DW_AT_byte_size
:
4771 return "DW_AT_byte_size";
4772 case DW_AT_bit_offset
:
4773 return "DW_AT_bit_offset";
4774 case DW_AT_bit_size
:
4775 return "DW_AT_bit_size";
4776 case DW_AT_element_list
:
4777 return "DW_AT_element_list";
4778 case DW_AT_stmt_list
:
4779 return "DW_AT_stmt_list";
4781 return "DW_AT_low_pc";
4783 return "DW_AT_high_pc";
4784 case DW_AT_language
:
4785 return "DW_AT_language";
4787 return "DW_AT_member";
4789 return "DW_AT_discr";
4790 case DW_AT_discr_value
:
4791 return "DW_AT_discr_value";
4792 case DW_AT_visibility
:
4793 return "DW_AT_visibility";
4795 return "DW_AT_import";
4796 case DW_AT_string_length
:
4797 return "DW_AT_string_length";
4798 case DW_AT_common_reference
:
4799 return "DW_AT_common_reference";
4800 case DW_AT_comp_dir
:
4801 return "DW_AT_comp_dir";
4802 case DW_AT_const_value
:
4803 return "DW_AT_const_value";
4804 case DW_AT_containing_type
:
4805 return "DW_AT_containing_type";
4806 case DW_AT_default_value
:
4807 return "DW_AT_default_value";
4809 return "DW_AT_inline";
4810 case DW_AT_is_optional
:
4811 return "DW_AT_is_optional";
4812 case DW_AT_lower_bound
:
4813 return "DW_AT_lower_bound";
4814 case DW_AT_producer
:
4815 return "DW_AT_producer";
4816 case DW_AT_prototyped
:
4817 return "DW_AT_prototyped";
4818 case DW_AT_return_addr
:
4819 return "DW_AT_return_addr";
4820 case DW_AT_start_scope
:
4821 return "DW_AT_start_scope";
4822 case DW_AT_stride_size
:
4823 return "DW_AT_stride_size";
4824 case DW_AT_upper_bound
:
4825 return "DW_AT_upper_bound";
4826 case DW_AT_abstract_origin
:
4827 return "DW_AT_abstract_origin";
4828 case DW_AT_accessibility
:
4829 return "DW_AT_accessibility";
4830 case DW_AT_address_class
:
4831 return "DW_AT_address_class";
4832 case DW_AT_artificial
:
4833 return "DW_AT_artificial";
4834 case DW_AT_base_types
:
4835 return "DW_AT_base_types";
4836 case DW_AT_calling_convention
:
4837 return "DW_AT_calling_convention";
4839 return "DW_AT_count";
4840 case DW_AT_data_member_location
:
4841 return "DW_AT_data_member_location";
4842 case DW_AT_decl_column
:
4843 return "DW_AT_decl_column";
4844 case DW_AT_decl_file
:
4845 return "DW_AT_decl_file";
4846 case DW_AT_decl_line
:
4847 return "DW_AT_decl_line";
4848 case DW_AT_declaration
:
4849 return "DW_AT_declaration";
4850 case DW_AT_discr_list
:
4851 return "DW_AT_discr_list";
4852 case DW_AT_encoding
:
4853 return "DW_AT_encoding";
4854 case DW_AT_external
:
4855 return "DW_AT_external";
4856 case DW_AT_frame_base
:
4857 return "DW_AT_frame_base";
4859 return "DW_AT_friend";
4860 case DW_AT_identifier_case
:
4861 return "DW_AT_identifier_case";
4862 case DW_AT_macro_info
:
4863 return "DW_AT_macro_info";
4864 case DW_AT_namelist_items
:
4865 return "DW_AT_namelist_items";
4866 case DW_AT_priority
:
4867 return "DW_AT_priority";
4869 return "DW_AT_segment";
4870 case DW_AT_specification
:
4871 return "DW_AT_specification";
4872 case DW_AT_static_link
:
4873 return "DW_AT_static_link";
4875 return "DW_AT_type";
4876 case DW_AT_use_location
:
4877 return "DW_AT_use_location";
4878 case DW_AT_variable_parameter
:
4879 return "DW_AT_variable_parameter";
4880 case DW_AT_virtuality
:
4881 return "DW_AT_virtuality";
4882 case DW_AT_vtable_elem_location
:
4883 return "DW_AT_vtable_elem_location";
4886 case DW_AT_MIPS_fde
:
4887 return "DW_AT_MIPS_fde";
4888 case DW_AT_MIPS_loop_begin
:
4889 return "DW_AT_MIPS_loop_begin";
4890 case DW_AT_MIPS_tail_loop_begin
:
4891 return "DW_AT_MIPS_tail_loop_begin";
4892 case DW_AT_MIPS_epilog_begin
:
4893 return "DW_AT_MIPS_epilog_begin";
4894 case DW_AT_MIPS_loop_unroll_factor
:
4895 return "DW_AT_MIPS_loop_unroll_factor";
4896 case DW_AT_MIPS_software_pipeline_depth
:
4897 return "DW_AT_MIPS_software_pipeline_depth";
4898 case DW_AT_MIPS_linkage_name
:
4899 return "DW_AT_MIPS_linkage_name";
4902 case DW_AT_sf_names
:
4903 return "DW_AT_sf_names";
4904 case DW_AT_src_info
:
4905 return "DW_AT_src_info";
4906 case DW_AT_mac_info
:
4907 return "DW_AT_mac_info";
4908 case DW_AT_src_coords
:
4909 return "DW_AT_src_coords";
4910 case DW_AT_body_begin
:
4911 return "DW_AT_body_begin";
4912 case DW_AT_body_end
:
4913 return "DW_AT_body_end";
4915 return "DW_AT_<unknown>";
4919 /* Convert a DWARF value form code into its string name. */
4922 dwarf_form_name (form
)
4923 register unsigned form
;
4928 return "DW_FORM_addr";
4929 case DW_FORM_block2
:
4930 return "DW_FORM_block2";
4931 case DW_FORM_block4
:
4932 return "DW_FORM_block4";
4934 return "DW_FORM_data2";
4936 return "DW_FORM_data4";
4938 return "DW_FORM_data8";
4939 case DW_FORM_string
:
4940 return "DW_FORM_string";
4942 return "DW_FORM_block";
4943 case DW_FORM_block1
:
4944 return "DW_FORM_block1";
4946 return "DW_FORM_data1";
4948 return "DW_FORM_flag";
4950 return "DW_FORM_sdata";
4952 return "DW_FORM_strp";
4954 return "DW_FORM_udata";
4955 case DW_FORM_ref_addr
:
4956 return "DW_FORM_ref_addr";
4958 return "DW_FORM_ref1";
4960 return "DW_FORM_ref2";
4962 return "DW_FORM_ref4";
4964 return "DW_FORM_ref8";
4965 case DW_FORM_ref_udata
:
4966 return "DW_FORM_ref_udata";
4967 case DW_FORM_indirect
:
4968 return "DW_FORM_indirect";
4970 return "DW_FORM_<unknown>";
4974 /* Convert a DWARF stack opcode into its string name. */
4977 dwarf_stack_op_name (op
)
4978 register unsigned op
;
4983 return "DW_OP_addr";
4985 return "DW_OP_deref";
4987 return "DW_OP_const1u";
4989 return "DW_OP_const1s";
4991 return "DW_OP_const2u";
4993 return "DW_OP_const2s";
4995 return "DW_OP_const4u";
4997 return "DW_OP_const4s";
4999 return "DW_OP_const8u";
5001 return "DW_OP_const8s";
5003 return "DW_OP_constu";
5005 return "DW_OP_consts";
5009 return "DW_OP_drop";
5011 return "DW_OP_over";
5013 return "DW_OP_pick";
5015 return "DW_OP_swap";
5019 return "DW_OP_xderef";
5027 return "DW_OP_minus";
5039 return "DW_OP_plus";
5040 case DW_OP_plus_uconst
:
5041 return "DW_OP_plus_uconst";
5047 return "DW_OP_shra";
5065 return "DW_OP_skip";
5067 return "DW_OP_lit0";
5069 return "DW_OP_lit1";
5071 return "DW_OP_lit2";
5073 return "DW_OP_lit3";
5075 return "DW_OP_lit4";
5077 return "DW_OP_lit5";
5079 return "DW_OP_lit6";
5081 return "DW_OP_lit7";
5083 return "DW_OP_lit8";
5085 return "DW_OP_lit9";
5087 return "DW_OP_lit10";
5089 return "DW_OP_lit11";
5091 return "DW_OP_lit12";
5093 return "DW_OP_lit13";
5095 return "DW_OP_lit14";
5097 return "DW_OP_lit15";
5099 return "DW_OP_lit16";
5101 return "DW_OP_lit17";
5103 return "DW_OP_lit18";
5105 return "DW_OP_lit19";
5107 return "DW_OP_lit20";
5109 return "DW_OP_lit21";
5111 return "DW_OP_lit22";
5113 return "DW_OP_lit23";
5115 return "DW_OP_lit24";
5117 return "DW_OP_lit25";
5119 return "DW_OP_lit26";
5121 return "DW_OP_lit27";
5123 return "DW_OP_lit28";
5125 return "DW_OP_lit29";
5127 return "DW_OP_lit30";
5129 return "DW_OP_lit31";
5131 return "DW_OP_reg0";
5133 return "DW_OP_reg1";
5135 return "DW_OP_reg2";
5137 return "DW_OP_reg3";
5139 return "DW_OP_reg4";
5141 return "DW_OP_reg5";
5143 return "DW_OP_reg6";
5145 return "DW_OP_reg7";
5147 return "DW_OP_reg8";
5149 return "DW_OP_reg9";
5151 return "DW_OP_reg10";
5153 return "DW_OP_reg11";
5155 return "DW_OP_reg12";
5157 return "DW_OP_reg13";
5159 return "DW_OP_reg14";
5161 return "DW_OP_reg15";
5163 return "DW_OP_reg16";
5165 return "DW_OP_reg17";
5167 return "DW_OP_reg18";
5169 return "DW_OP_reg19";
5171 return "DW_OP_reg20";
5173 return "DW_OP_reg21";
5175 return "DW_OP_reg22";
5177 return "DW_OP_reg23";
5179 return "DW_OP_reg24";
5181 return "DW_OP_reg25";
5183 return "DW_OP_reg26";
5185 return "DW_OP_reg27";
5187 return "DW_OP_reg28";
5189 return "DW_OP_reg29";
5191 return "DW_OP_reg30";
5193 return "DW_OP_reg31";
5195 return "DW_OP_breg0";
5197 return "DW_OP_breg1";
5199 return "DW_OP_breg2";
5201 return "DW_OP_breg3";
5203 return "DW_OP_breg4";
5205 return "DW_OP_breg5";
5207 return "DW_OP_breg6";
5209 return "DW_OP_breg7";
5211 return "DW_OP_breg8";
5213 return "DW_OP_breg9";
5215 return "DW_OP_breg10";
5217 return "DW_OP_breg11";
5219 return "DW_OP_breg12";
5221 return "DW_OP_breg13";
5223 return "DW_OP_breg14";
5225 return "DW_OP_breg15";
5227 return "DW_OP_breg16";
5229 return "DW_OP_breg17";
5231 return "DW_OP_breg18";
5233 return "DW_OP_breg19";
5235 return "DW_OP_breg20";
5237 return "DW_OP_breg21";
5239 return "DW_OP_breg22";
5241 return "DW_OP_breg23";
5243 return "DW_OP_breg24";
5245 return "DW_OP_breg25";
5247 return "DW_OP_breg26";
5249 return "DW_OP_breg27";
5251 return "DW_OP_breg28";
5253 return "DW_OP_breg29";
5255 return "DW_OP_breg30";
5257 return "DW_OP_breg31";
5259 return "DW_OP_regx";
5261 return "DW_OP_fbreg";
5263 return "DW_OP_bregx";
5265 return "DW_OP_piece";
5266 case DW_OP_deref_size
:
5267 return "DW_OP_deref_size";
5268 case DW_OP_xderef_size
:
5269 return "DW_OP_xderef_size";
5273 return "OP_<unknown>";
5278 dwarf_bool_name (bool)
5287 /* Convert a DWARF type code into its string name. */
5290 dwarf_type_encoding_name (enc
)
5291 register unsigned enc
;
5295 case DW_ATE_address
:
5296 return "DW_ATE_address";
5297 case DW_ATE_boolean
:
5298 return "DW_ATE_boolean";
5299 case DW_ATE_complex_float
:
5300 return "DW_ATE_complex_float";
5302 return "DW_ATE_float";
5304 return "DW_ATE_signed";
5305 case DW_ATE_signed_char
:
5306 return "DW_ATE_signed_char";
5307 case DW_ATE_unsigned
:
5308 return "DW_ATE_unsigned";
5309 case DW_ATE_unsigned_char
:
5310 return "DW_ATE_unsigned_char";
5312 return "DW_ATE_<unknown>";
5316 /* Convert a DWARF call frame info operation to its string name. */
5320 dwarf_cfi_name (cfi_opc
)
5321 register unsigned cfi_opc
;
5325 case DW_CFA_advance_loc
:
5326 return "DW_CFA_advance_loc";
5328 return "DW_CFA_offset";
5329 case DW_CFA_restore
:
5330 return "DW_CFA_restore";
5332 return "DW_CFA_nop";
5333 case DW_CFA_set_loc
:
5334 return "DW_CFA_set_loc";
5335 case DW_CFA_advance_loc1
:
5336 return "DW_CFA_advance_loc1";
5337 case DW_CFA_advance_loc2
:
5338 return "DW_CFA_advance_loc2";
5339 case DW_CFA_advance_loc4
:
5340 return "DW_CFA_advance_loc4";
5341 case DW_CFA_offset_extended
:
5342 return "DW_CFA_offset_extended";
5343 case DW_CFA_restore_extended
:
5344 return "DW_CFA_restore_extended";
5345 case DW_CFA_undefined
:
5346 return "DW_CFA_undefined";
5347 case DW_CFA_same_value
:
5348 return "DW_CFA_same_value";
5349 case DW_CFA_register
:
5350 return "DW_CFA_register";
5351 case DW_CFA_remember_state
:
5352 return "DW_CFA_remember_state";
5353 case DW_CFA_restore_state
:
5354 return "DW_CFA_restore_state";
5355 case DW_CFA_def_cfa
:
5356 return "DW_CFA_def_cfa";
5357 case DW_CFA_def_cfa_register
:
5358 return "DW_CFA_def_cfa_register";
5359 case DW_CFA_def_cfa_offset
:
5360 return "DW_CFA_def_cfa_offset";
5361 /* SGI/MIPS specific */
5362 case DW_CFA_MIPS_advance_loc8
:
5363 return "DW_CFA_MIPS_advance_loc8";
5365 return "DW_CFA_<unknown>";
5372 struct die_info
*die
;
5376 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5377 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5378 fprintf (stderr
, "\thas children: %s\n",
5379 dwarf_bool_name (die
->has_children
));
5381 fprintf (stderr
, "\tattributes:\n");
5382 for (i
= 0; i
< die
->num_attrs
; ++i
)
5384 fprintf (stderr
, "\t\t%s (%s) ",
5385 dwarf_attr_name (die
->attrs
[i
].name
),
5386 dwarf_form_name (die
->attrs
[i
].form
));
5387 switch (die
->attrs
[i
].form
)
5389 case DW_FORM_ref_addr
:
5391 fprintf (stderr
, "address: ");
5392 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, stderr
);
5394 case DW_FORM_block2
:
5395 case DW_FORM_block4
:
5397 case DW_FORM_block1
:
5398 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5408 fprintf (stderr
, "constant: %d", DW_UNSND (&die
->attrs
[i
]));
5410 case DW_FORM_string
:
5411 fprintf (stderr
, "string: \"%s\"",
5412 DW_STRING (&die
->attrs
[i
])
5413 ? DW_STRING (&die
->attrs
[i
]) : "");
5416 if (DW_UNSND (&die
->attrs
[i
]))
5417 fprintf (stderr
, "flag: TRUE");
5419 fprintf (stderr
, "flag: FALSE");
5421 case DW_FORM_strp
: /* we do not support separate string
5423 case DW_FORM_indirect
: /* we do not handle indirect yet */
5424 case DW_FORM_data8
: /* we do not have 64 bit quantities */
5426 fprintf (stderr
, "unsupported attribute form: %d.",
5427 die
->attrs
[i
].form
);
5429 fprintf (stderr
, "\n");
5435 struct die_info
*die
;
5445 store_in_ref_table (offset
, die
)
5446 unsigned int offset
;
5447 struct die_info
*die
;
5450 struct die_info
*old
;
5452 h
= (offset
% REF_HASH_SIZE
);
5453 old
= die_ref_table
[h
];
5454 die
->next_ref
= old
;
5455 die_ref_table
[h
] = die
;
5460 dwarf2_empty_die_ref_table ()
5462 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5466 dwarf2_get_ref_die_offset (attr
)
5467 struct attribute
*attr
;
5469 unsigned int result
= 0;
5473 case DW_FORM_ref_addr
:
5474 result
= DW_ADDR (attr
);
5479 case DW_FORM_ref_udata
:
5480 result
= cu_header_offset
+ DW_UNSND (attr
);
5483 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5489 follow_die_ref (offset
)
5490 unsigned int offset
;
5492 struct die_info
*die
;
5495 h
= (offset
% REF_HASH_SIZE
);
5496 die
= die_ref_table
[h
];
5499 if (die
->offset
== offset
)
5503 die
= die
->next_ref
;
5508 static struct type
*
5509 dwarf2_fundamental_type (objfile
, typeid)
5510 struct objfile
*objfile
;
5513 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5515 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5519 /* Look for this particular type in the fundamental type vector. If
5520 one is not found, create and install one appropriate for the
5521 current language and the current target machine. */
5523 if (ftypes
[typeid] == NULL
)
5525 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5528 return (ftypes
[typeid]);
5531 /* Decode simple location descriptions.
5532 Given a pointer to a dwarf block that defines a location, compute
5533 the location and return the value.
5535 FIXME: This is a kludge until we figure out a better
5536 way to handle the location descriptions.
5537 Gdb's design does not mesh well with the DWARF2 notion of a location
5538 computing interpreter, which is a shame because the flexibility goes unused.
5539 FIXME: Implement more operations as necessary.
5541 A location description containing no operations indicates that the
5542 object is optimized out. The global optimized_out flag is set for
5543 those, the return value is meaningless.
5545 When the result is a register number, the global isreg flag is set,
5546 otherwise it is cleared.
5548 When the result is a base register offset, the global offreg flag is set
5549 and the register number is returned in basereg, otherwise it is cleared.
5551 When the DW_OP_fbreg operation is encountered without a corresponding
5552 DW_AT_frame_base attribute, the global islocal flag is set.
5553 Hopefully the machine dependent code knows how to set up a virtual
5554 frame pointer for the local references.
5556 Note that stack[0] is unused except as a default error return.
5557 Note that stack overflow is not yet handled. */
5560 decode_locdesc (blk
, objfile
)
5561 struct dwarf_block
*blk
;
5562 struct objfile
*objfile
;
5565 int size
= blk
->size
;
5566 char *data
= blk
->data
;
5567 CORE_ADDR stack
[64];
5569 unsigned int bytes_read
, unsnd
;
5619 stack
[++stacki
] = op
- DW_OP_reg0
;
5624 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5626 #if defined(HARRIS_TARGET) && defined(_M88K)
5627 /* The Harris 88110 gdb ports have long kept their special reg
5628 numbers between their gp-regs and their x-regs. This is
5629 not how our dwarf is generated. Punt. */
5632 stack
[++stacki
] = unsnd
;
5668 basereg
= op
- DW_OP_breg0
;
5669 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5674 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5676 if (frame_base_reg
>= 0)
5679 basereg
= frame_base_reg
;
5680 stack
[stacki
] += frame_base_offset
;
5684 complain (&dwarf2_missing_at_frame_base
);
5690 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
]);
5695 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5700 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5705 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5710 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5715 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5720 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5725 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5731 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5736 stack
[stacki
- 1] += stack
[stacki
];
5740 case DW_OP_plus_uconst
:
5741 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5746 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5751 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name(op
));
5752 return (stack
[stacki
]);
5755 return (stack
[stacki
]);
5758 /* memory allocation interface */
5762 dwarf2_free_tmp_obstack (ignore
)
5765 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5768 static struct dwarf_block
*
5769 dwarf_alloc_block ()
5771 struct dwarf_block
*blk
;
5773 blk
= (struct dwarf_block
*)
5774 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5778 static struct abbrev_info
*
5779 dwarf_alloc_abbrev ()
5781 struct abbrev_info
*abbrev
;
5783 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5784 memset (abbrev
, 0, sizeof (struct abbrev_info
));
5788 static struct die_info
*
5791 struct die_info
*die
;
5793 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5794 memset (die
, 0, sizeof (struct die_info
));