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
152 unsigned int abbrev_offset
;
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.");
935 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
937 error ("Dwarf Error: bad offset in compilation unit header.");
940 if (cu_header
.length
> dwarf_abbrev_size
- cu_header
.abbrev_offset
)
942 error ("Dwarf Error: bad length in compilation unit header.");
946 /* Read the abbrevs for this compilation unit into a table */
947 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
948 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
950 /* Read the compilation unit die */
951 info_ptr
= read_partial_die (&comp_unit_die
, abfd
,
952 info_ptr
, &comp_unit_has_pc_info
);
954 /* Set the language we're debugging */
955 set_cu_language (comp_unit_die
.language
);
957 /* Allocate a new partial symbol table structure */
958 pst
= start_psymtab_common (objfile
, section_offsets
,
959 comp_unit_die
.name
? comp_unit_die
.name
: "",
961 objfile
->global_psymbols
.next
,
962 objfile
->static_psymbols
.next
);
964 pst
->read_symtab_private
= (char *)
965 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
966 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
967 DWARF_INFO_BUFFER(pst
) = dwarf_info_buffer
;
968 DWARF_INFO_OFFSET(pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
969 DWARF_ABBREV_BUFFER(pst
) = dwarf_abbrev_buffer
;
970 DWARF_ABBREV_SIZE(pst
) = dwarf_abbrev_size
;
971 DWARF_LINE_BUFFER(pst
) = dwarf_line_buffer
;
972 baseaddr
= ANOFFSET (section_offsets
, 0);
974 /* Store the function that reads in the rest of the symbol table */
975 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
977 /* Check if comp unit has_children.
978 If so, read the rest of the partial symbols from this comp unit.
979 If not, there's no more debug_info for this comp unit. */
980 if (comp_unit_die
.has_children
)
981 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
);
983 /* If the compilation unit didn't have an explicit address range,
984 then use the information extracted from its child dies. */
985 if (!comp_unit_has_pc_info
)
987 comp_unit_die
.lowpc
= lowpc
;
988 comp_unit_die
.highpc
= highpc
;
990 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
991 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
993 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
994 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
995 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
996 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
997 sort_pst_symbols (pst
);
999 /* If there is already a psymtab or symtab for a file of this
1000 name, remove it. (If there is a symtab, more drastic things
1001 also happen.) This happens in VxWorks. */
1002 free_named_symtabs (pst
->filename
);
1004 info_ptr
= beg_of_comp_unit
+ cu_header
.length
+ 4;
1006 do_cleanups (back_to
);
1009 /* Read in all interesting dies to the end of the compilation unit. */
1012 scan_partial_symbols (info_ptr
, objfile
, lowpc
, highpc
)
1014 struct objfile
*objfile
;
1018 bfd
*abfd
= objfile
->obfd
;
1019 struct partial_die_info pdi
;
1021 /* This function is called after we've read in the comp_unit_die in
1022 order to read its children. We start the nesting level at 1 since
1023 we have pushed 1 level down in order to read the comp unit's children.
1024 The comp unit itself is at level 0, so we stop reading when we pop
1025 back to that level. */
1027 int nesting_level
= 1;
1030 *lowpc
= ((CORE_ADDR
) -1);
1031 *highpc
= ((CORE_ADDR
) 0);
1033 while (nesting_level
)
1035 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, &has_pc_info
);
1041 case DW_TAG_subprogram
:
1044 if (pdi
.lowpc
< *lowpc
)
1048 if (pdi
.highpc
> *highpc
)
1050 *highpc
= pdi
.highpc
;
1052 if ((pdi
.is_external
|| nesting_level
== 1)
1053 && !pdi
.is_declaration
)
1055 add_partial_symbol (&pdi
, objfile
);
1059 case DW_TAG_variable
:
1060 case DW_TAG_typedef
:
1061 case DW_TAG_class_type
:
1062 case DW_TAG_structure_type
:
1063 case DW_TAG_union_type
:
1064 case DW_TAG_enumeration_type
:
1065 if ((pdi
.is_external
|| nesting_level
== 1)
1066 && !pdi
.is_declaration
)
1068 add_partial_symbol (&pdi
, objfile
);
1071 case DW_TAG_enumerator
:
1072 /* File scope enumerators are added to the partial symbol
1074 if (nesting_level
== 2)
1075 add_partial_symbol (&pdi
, objfile
);
1077 case DW_TAG_base_type
:
1078 /* File scope base type definitions are added to the partial
1080 if (nesting_level
== 1)
1081 add_partial_symbol (&pdi
, objfile
);
1088 /* If the die has a sibling, skip to the sibling.
1089 Do not skip enumeration types, we want to record their
1091 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1093 info_ptr
= pdi
.sibling
;
1095 else if (pdi
.has_children
)
1097 /* Die has children, but the optional DW_AT_sibling attribute
1108 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1109 from `maint check'. */
1110 if (*lowpc
== ((CORE_ADDR
) -1))
1116 add_partial_symbol (pdi
, objfile
)
1117 struct partial_die_info
*pdi
;
1118 struct objfile
*objfile
;
1124 case DW_TAG_subprogram
:
1125 if (pdi
->is_external
)
1127 prim_record_minimal_symbol (pdi
->name
, pdi
->lowpc
+ baseaddr
,
1129 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1130 VAR_NAMESPACE
, LOC_BLOCK
,
1131 &objfile
->global_psymbols
,
1132 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1136 prim_record_minimal_symbol (pdi
->name
, pdi
->lowpc
+ baseaddr
,
1137 mst_file_text
, objfile
);
1138 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1139 VAR_NAMESPACE
, LOC_BLOCK
,
1140 &objfile
->static_psymbols
,
1141 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1144 case DW_TAG_variable
:
1145 if (pdi
->is_external
)
1148 Don't enter into the minimal symbol tables as there is
1149 a minimal symbol table entry from the ELF symbols already.
1150 Enter into partial symbol table if it has a location
1151 descriptor or a type.
1152 If the location descriptor is missing, new_symbol will create
1153 a LOC_UNRESOLVED symbol, the address of the variable will then
1154 be determined from the minimal symbol table whenever the variable
1156 The address for the partial symbol table entry is not
1157 used by GDB, but it comes in handy for debugging partial symbol
1161 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1162 if (pdi
->locdesc
|| pdi
->has_type
)
1163 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1164 VAR_NAMESPACE
, LOC_STATIC
,
1165 &objfile
->global_psymbols
,
1166 0, addr
+ baseaddr
, cu_language
, objfile
);
1170 /* Static Variable. Skip symbols without location descriptors. */
1171 if (pdi
->locdesc
== NULL
)
1173 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1174 prim_record_minimal_symbol (pdi
->name
, addr
+ baseaddr
,
1175 mst_file_data
, objfile
);
1176 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1177 VAR_NAMESPACE
, LOC_STATIC
,
1178 &objfile
->static_psymbols
,
1179 0, addr
+ baseaddr
, cu_language
, objfile
);
1182 case DW_TAG_typedef
:
1183 case DW_TAG_base_type
:
1184 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1185 VAR_NAMESPACE
, LOC_TYPEDEF
,
1186 &objfile
->static_psymbols
,
1187 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1189 case DW_TAG_class_type
:
1190 case DW_TAG_structure_type
:
1191 case DW_TAG_union_type
:
1192 case DW_TAG_enumeration_type
:
1193 /* Skip aggregate types without children, these are external
1195 if (pdi
->has_children
== 0)
1197 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1198 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1199 &objfile
->static_psymbols
,
1200 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1202 if (cu_language
== language_cplus
)
1204 /* For C++, these implicitly act as typedefs as well. */
1205 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1206 VAR_NAMESPACE
, LOC_TYPEDEF
,
1207 &objfile
->static_psymbols
,
1208 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1211 case DW_TAG_enumerator
:
1212 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1213 VAR_NAMESPACE
, LOC_CONST
,
1214 &objfile
->static_psymbols
,
1215 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1222 /* Expand this partial symbol table into a full symbol table. */
1225 dwarf2_psymtab_to_symtab (pst
)
1226 struct partial_symtab
*pst
;
1228 /* FIXME: This is barely more than a stub. */
1233 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1239 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1240 gdb_flush (gdb_stdout
);
1243 psymtab_to_symtab_1 (pst
);
1245 /* Finish up the debug error message. */
1247 printf_filtered ("done.\n");
1253 psymtab_to_symtab_1 (pst
)
1254 struct partial_symtab
*pst
;
1256 struct objfile
*objfile
= pst
->objfile
;
1257 bfd
*abfd
= objfile
->obfd
;
1258 struct comp_unit_head cu_header
;
1259 struct die_info
*dies
;
1260 unsigned long offset
;
1261 CORE_ADDR lowpc
, highpc
;
1262 struct die_info
*child_die
;
1264 struct symtab
*symtab
;
1265 struct cleanup
*back_to
;
1267 /* Set local variables from the partial symbol table info. */
1268 offset
= DWARF_INFO_OFFSET(pst
);
1269 dwarf_info_buffer
= DWARF_INFO_BUFFER(pst
);
1270 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER(pst
);
1271 dwarf_abbrev_size
= DWARF_ABBREV_SIZE(pst
);
1272 dwarf_line_buffer
= DWARF_LINE_BUFFER(pst
);
1273 baseaddr
= ANOFFSET (pst
->section_offsets
, 0);
1274 cu_header_offset
= offset
;
1275 info_ptr
= dwarf_info_buffer
+ offset
;
1277 obstack_init (&dwarf2_tmp_obstack
);
1278 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1281 make_cleanup (really_free_pendings
, NULL
);
1283 /* read in the comp_unit header */
1284 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
1286 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
1288 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
1290 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
1293 /* Read the abbrevs for this compilation unit */
1294 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1295 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1297 dies
= read_comp_unit (info_ptr
, abfd
);
1299 make_cleanup (free_die_list
, dies
);
1301 /* Do line number decoding in read_file_scope () */
1302 process_die (dies
, objfile
);
1304 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1306 /* Some compilers don't define a DW_AT_high_pc attribute for
1307 the compilation unit. If the DW_AT_high_pc is missing,
1308 synthesize it, by scanning the DIE's below the compilation unit. */
1310 if (dies
->has_children
)
1312 child_die
= dies
->next
;
1313 while (child_die
&& child_die
->tag
)
1315 if (child_die
->tag
== DW_TAG_subprogram
)
1317 CORE_ADDR low
, high
;
1319 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1321 highpc
= max (highpc
, high
);
1324 child_die
= sibling_die (child_die
);
1328 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, 0);
1330 /* Set symtab language to language from DW_AT_language.
1331 If the compilation is from a C file generated by language preprocessors,
1332 do not set the language if it was already deduced by start_subfile. */
1334 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1336 symtab
->language
= cu_language
;
1338 pst
->symtab
= symtab
;
1340 sort_symtab_syms (pst
->symtab
);
1342 do_cleanups (back_to
);
1345 /* Process a die and its children. */
1348 process_die (die
, objfile
)
1349 struct die_info
*die
;
1350 struct objfile
*objfile
;
1354 case DW_TAG_padding
:
1356 case DW_TAG_compile_unit
:
1357 read_file_scope (die
, objfile
);
1359 case DW_TAG_subprogram
:
1360 read_subroutine_type (die
, objfile
);
1361 read_func_scope (die
, objfile
);
1363 case DW_TAG_inlined_subroutine
:
1364 /* FIXME: These are ignored for now.
1365 They could be used to set breakpoints on all inlined instances
1366 of a function and make GDB `next' properly over inlined functions. */
1368 case DW_TAG_lexical_block
:
1369 read_lexical_block_scope (die
, objfile
);
1371 case DW_TAG_class_type
:
1372 case DW_TAG_structure_type
:
1373 case DW_TAG_union_type
:
1374 read_structure_scope (die
, objfile
);
1376 case DW_TAG_enumeration_type
:
1377 read_enumeration (die
, objfile
);
1379 case DW_TAG_subroutine_type
:
1380 read_subroutine_type (die
, objfile
);
1382 case DW_TAG_array_type
:
1383 read_array_type (die
, objfile
);
1385 case DW_TAG_pointer_type
:
1386 read_tag_pointer_type (die
, objfile
);
1388 case DW_TAG_ptr_to_member_type
:
1389 read_tag_ptr_to_member_type (die
, objfile
);
1391 case DW_TAG_reference_type
:
1392 read_tag_reference_type (die
, objfile
);
1394 case DW_TAG_string_type
:
1395 read_tag_string_type (die
, objfile
);
1397 case DW_TAG_base_type
:
1398 read_base_type (die
, objfile
);
1399 if (dwarf_attr (die
, DW_AT_name
))
1401 /* Add a typedef symbol for the base type definition. */
1402 new_symbol (die
, die
->type
, objfile
);
1405 case DW_TAG_common_block
:
1406 read_common_block (die
, objfile
);
1408 case DW_TAG_common_inclusion
:
1411 new_symbol (die
, NULL
, objfile
);
1417 read_file_scope (die
, objfile
)
1418 struct die_info
*die
;
1419 struct objfile
*objfile
;
1421 unsigned int line_offset
= 0;
1422 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1423 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1424 struct attribute
*attr
;
1425 char *name
= "<unknown>";
1426 char *comp_dir
= NULL
;
1427 struct die_info
*child_die
;
1428 bfd
*abfd
= objfile
->obfd
;
1430 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1432 if (die
->has_children
)
1434 child_die
= die
->next
;
1435 while (child_die
&& child_die
->tag
)
1437 if (child_die
->tag
== DW_TAG_subprogram
)
1439 CORE_ADDR low
, high
;
1441 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1443 lowpc
= min (lowpc
, low
);
1444 highpc
= max (highpc
, high
);
1447 child_die
= sibling_die (child_die
);
1452 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1453 from finish_block. */
1454 if (lowpc
== ((CORE_ADDR
) -1))
1459 attr
= dwarf_attr (die
, DW_AT_name
);
1462 name
= DW_STRING (attr
);
1464 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1467 comp_dir
= DW_STRING (attr
);
1470 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1471 directory, get rid of it. */
1472 char *cp
= strchr (comp_dir
, ':');
1474 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1479 if (objfile
->ei
.entry_point
>= lowpc
&&
1480 objfile
->ei
.entry_point
< highpc
)
1482 objfile
->ei
.entry_file_lowpc
= lowpc
;
1483 objfile
->ei
.entry_file_highpc
= highpc
;
1486 attr
= dwarf_attr (die
, DW_AT_language
);
1489 set_cu_language (DW_UNSND (attr
));
1493 /* FIXME:Do something here. */
1494 if (dip
->at_producer
!= NULL
)
1496 handle_producer (dip
->at_producer
);
1500 /* The compilation unit may be in a different language or objfile,
1501 zero out all remembered fundamental types. */
1502 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1504 start_symtab (name
, comp_dir
, lowpc
);
1505 record_debugformat ("DWARF 2");
1507 /* Decode line number information if present. */
1508 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1511 line_offset
= DW_UNSND (attr
);
1512 dwarf_decode_lines (line_offset
, comp_dir
, abfd
);
1515 /* Process all dies in compilation unit. */
1516 if (die
->has_children
)
1518 child_die
= die
->next
;
1519 while (child_die
&& child_die
->tag
)
1521 process_die (child_die
, objfile
);
1522 child_die
= sibling_die (child_die
);
1528 read_func_scope (die
, objfile
)
1529 struct die_info
*die
;
1530 struct objfile
*objfile
;
1532 register struct context_stack
*new;
1535 struct die_info
*child_die
;
1536 struct attribute
*attr
;
1539 name
= dwarf2_linkage_name (die
);
1541 /* Ignore functions with missing or empty names and functions with
1542 missing or invalid low and high pc attributes. */
1543 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1549 if (objfile
->ei
.entry_point
>= lowpc
&&
1550 objfile
->ei
.entry_point
< highpc
)
1552 objfile
->ei
.entry_func_lowpc
= lowpc
;
1553 objfile
->ei
.entry_func_highpc
= highpc
;
1556 if (STREQ (name
, "main")) /* FIXME: hardwired name */
1558 objfile
->ei
.main_func_lowpc
= lowpc
;
1559 objfile
->ei
.main_func_highpc
= highpc
;
1562 /* Decode DW_AT_frame_base location descriptor if present, keep result
1563 for DW_OP_fbreg operands in decode_locdesc. */
1564 frame_base_reg
= -1;
1565 frame_base_offset
= 0;
1566 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1569 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
);
1571 frame_base_reg
= addr
;
1574 frame_base_reg
= basereg
;
1575 frame_base_offset
= addr
;
1578 complain (&dwarf2_unsupported_at_frame_base
, name
);
1581 new = push_context (0, lowpc
);
1582 new->name
= new_symbol (die
, die
->type
, objfile
);
1583 list_in_scope
= &local_symbols
;
1585 if (die
->has_children
)
1587 child_die
= die
->next
;
1588 while (child_die
&& child_die
->tag
)
1590 process_die (child_die
, objfile
);
1591 child_die
= sibling_die (child_die
);
1595 new = pop_context ();
1596 /* Make a block for the local symbols within. */
1597 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1598 lowpc
, highpc
, objfile
);
1599 list_in_scope
= &file_symbols
;
1602 /* Process all the DIES contained within a lexical block scope. Start
1603 a new scope, process the dies, and then close the scope. */
1606 read_lexical_block_scope (die
, objfile
)
1607 struct die_info
*die
;
1608 struct objfile
*objfile
;
1610 register struct context_stack
*new;
1611 CORE_ADDR lowpc
, highpc
;
1612 struct die_info
*child_die
;
1614 /* Ignore blocks with missing or invalid low and high pc attributes. */
1615 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1620 push_context (0, lowpc
);
1621 if (die
->has_children
)
1623 child_die
= die
->next
;
1624 while (child_die
&& child_die
->tag
)
1626 process_die (child_die
, objfile
);
1627 child_die
= sibling_die (child_die
);
1630 new = pop_context ();
1632 if (local_symbols
!= NULL
)
1634 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1637 local_symbols
= new->locals
;
1640 /* Get low and high pc attributes from a die.
1641 Return 1 if the attributes are present and valid, otherwise, return 0. */
1644 dwarf2_get_pc_bounds (die
, lowpc
, highpc
, objfile
)
1645 struct die_info
*die
;
1648 struct objfile
*objfile
;
1650 struct attribute
*attr
;
1654 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1656 low
= DW_ADDR (attr
);
1659 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1661 high
= DW_ADDR (attr
);
1668 /* When using the GNU linker, .gnu.linkonce. sections are used to
1669 eliminate duplicate copies of functions and vtables and such.
1670 The linker will arbitrarily choose one and discard the others.
1671 The AT_*_pc values for such functions refer to local labels in
1672 these sections. If the section from that file was discarded, the
1673 labels are not in the output, so the relocs get a value of 0.
1674 If this is a discarded function, mark the pc bounds as invalid,
1675 so that GDB will ignore it. */
1676 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1684 /* Add an aggregate field to the field list. */
1687 dwarf2_add_field (fip
, die
, objfile
)
1688 struct field_info
*fip
;
1689 struct die_info
*die
;
1690 struct objfile
*objfile
;
1692 struct nextfield
*new_field
;
1693 struct attribute
*attr
;
1695 char *fieldname
= "";
1697 /* Allocate a new field list entry and link it in. */
1698 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1699 make_cleanup (free
, new_field
);
1700 memset (new_field
, 0, sizeof (struct nextfield
));
1701 new_field
->next
= fip
->fields
;
1702 fip
->fields
= new_field
;
1705 /* Handle accessibility and virtuality of field.
1706 The default accessibility for members is public, the default
1707 accessibility for inheritance is private. */
1708 if (die
->tag
!= DW_TAG_inheritance
)
1709 new_field
->accessibility
= DW_ACCESS_public
;
1711 new_field
->accessibility
= DW_ACCESS_private
;
1712 new_field
->virtuality
= DW_VIRTUALITY_none
;
1714 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1716 new_field
->accessibility
= DW_UNSND (attr
);
1717 if (new_field
->accessibility
!= DW_ACCESS_public
)
1718 fip
->non_public_fields
= 1;
1719 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1721 new_field
->virtuality
= DW_UNSND (attr
);
1723 fp
= &new_field
->field
;
1724 if (die
->tag
== DW_TAG_member
)
1726 /* Get type of field. */
1727 fp
->type
= die_type (die
, objfile
);
1729 /* Get bit size of field (zero if none). */
1730 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1733 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1737 FIELD_BITSIZE (*fp
) = 0;
1740 /* Get bit offset of field. */
1741 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1744 FIELD_BITPOS (*fp
) =
1745 decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1748 FIELD_BITPOS (*fp
) = 0;
1749 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1752 if (BITS_BIG_ENDIAN
)
1754 /* For big endian bits, the DW_AT_bit_offset gives the
1755 additional bit offset from the MSB of the containing
1756 anonymous object to the MSB of the field. We don't
1757 have to do anything special since we don't need to
1758 know the size of the anonymous object. */
1759 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1763 /* For little endian bits, compute the bit offset to the
1764 MSB of the anonymous object, subtract off the number of
1765 bits from the MSB of the field to the MSB of the
1766 object, and then subtract off the number of bits of
1767 the field itself. The result is the bit offset of
1768 the LSB of the field. */
1770 int bit_offset
= DW_UNSND (attr
);
1772 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1775 /* The size of the anonymous object containing
1776 the bit field is explicit, so use the
1777 indicated size (in bytes). */
1778 anonymous_size
= DW_UNSND (attr
);
1782 /* The size of the anonymous object containing
1783 the bit field must be inferred from the type
1784 attribute of the data member containing the
1786 anonymous_size
= TYPE_LENGTH (fp
->type
);
1788 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1789 - bit_offset
- FIELD_BITSIZE (*fp
);
1793 /* Get name of field. */
1794 attr
= dwarf_attr (die
, DW_AT_name
);
1795 if (attr
&& DW_STRING (attr
))
1796 fieldname
= DW_STRING (attr
);
1797 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1798 &objfile
->type_obstack
);
1800 /* Change accessibility for artificial fields (e.g. virtual table
1801 pointer or virtual base class pointer) to private. */
1802 if (dwarf_attr (die
, DW_AT_artificial
))
1804 new_field
->accessibility
= DW_ACCESS_private
;
1805 fip
->non_public_fields
= 1;
1808 else if (die
->tag
== DW_TAG_variable
)
1813 /* C++ static member.
1814 Get physical name, extract field name from physical name. */
1815 physname
= dwarf2_linkage_name (die
);
1816 if (physname
== NULL
)
1820 while (*cp
&& !is_cplus_marker (*cp
))
1824 if (*fieldname
== '\0')
1826 complain (&dwarf2_bad_static_member_name
, physname
);
1829 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1830 &objfile
->type_obstack
));
1831 FIELD_TYPE (*fp
) = die_type (die
, objfile
);
1832 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1833 &objfile
->type_obstack
);
1835 else if (die
->tag
== DW_TAG_inheritance
)
1837 /* C++ base class field. */
1838 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1840 FIELD_BITPOS (*fp
) = decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1841 FIELD_BITSIZE (*fp
) = 0;
1842 FIELD_TYPE (*fp
) = die_type (die
, objfile
);
1843 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1844 fip
->nbaseclasses
++;
1848 /* Create the vector of fields, and attach it to the type. */
1851 dwarf2_attach_fields_to_type (fip
, type
, objfile
)
1852 struct field_info
*fip
;
1854 struct objfile
*objfile
;
1856 int nfields
= fip
->nfields
;
1858 /* Record the field count, allocate space for the array of fields,
1859 and create blank accessibility bitfields if necessary. */
1860 TYPE_NFIELDS (type
) = nfields
;
1861 TYPE_FIELDS (type
) = (struct field
*)
1862 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1863 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1865 if (fip
->non_public_fields
)
1867 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1869 TYPE_FIELD_PRIVATE_BITS (type
) =
1870 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1871 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1873 TYPE_FIELD_PROTECTED_BITS (type
) =
1874 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1875 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1877 TYPE_FIELD_IGNORE_BITS (type
) =
1878 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1879 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1882 /* If the type has baseclasses, allocate and clear a bit vector for
1883 TYPE_FIELD_VIRTUAL_BITS. */
1884 if (fip
->nbaseclasses
)
1886 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
1889 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1890 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1891 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1892 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
1893 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
1896 /* Copy the saved-up fields into the field vector. Start from the head
1897 of the list, adding to the tail of the field array, so that they end
1898 up in the same order in the array in which they were added to the list. */
1899 while (nfields
-- > 0)
1901 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
1902 switch (fip
->fields
->accessibility
)
1904 case DW_ACCESS_private
:
1905 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
1908 case DW_ACCESS_protected
:
1909 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
1912 case DW_ACCESS_public
:
1916 /* Unknown accessibility. Complain and treat it as public. */
1918 complain (&dwarf2_unsupported_accessibility
,
1919 fip
->fields
->accessibility
);
1923 if (nfields
< fip
->nbaseclasses
)
1925 switch (fip
->fields
->virtuality
)
1927 case DW_VIRTUALITY_virtual
:
1928 case DW_VIRTUALITY_pure_virtual
:
1929 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
1933 fip
->fields
= fip
->fields
->next
;
1937 /* Skip to the end of a member function name in a mangled name. */
1940 skip_member_fn_name (physname
)
1943 char *endname
= physname
;
1945 /* Skip over leading underscores. */
1946 while (*endname
== '_')
1949 /* Find two succesive underscores. */
1951 endname
= strchr (endname
, '_');
1952 while (endname
!= NULL
&& *++endname
!= '_');
1954 if (endname
== NULL
)
1956 complain (&dwarf2_bad_member_name_complaint
, physname
);
1961 /* Take care of trailing underscores. */
1962 if (endname
[1] != '_')
1968 /* Add a member function to the proper fieldlist. */
1971 dwarf2_add_member_fn (fip
, die
, type
, objfile
)
1972 struct field_info
*fip
;
1973 struct die_info
*die
;
1975 struct objfile
*objfile
;
1977 struct attribute
*attr
;
1978 struct fnfieldlist
*flp
;
1980 struct fn_field
*fnp
;
1983 struct nextfnfield
*new_fnfield
;
1985 /* Extract member function name from mangled name. */
1986 physname
= dwarf2_linkage_name (die
);
1987 if (physname
== NULL
)
1989 if ((physname
[0] == '_' && physname
[1] == '_'
1990 && strchr ("0123456789Qt", physname
[2]))
1991 || DESTRUCTOR_PREFIX_P (physname
))
1993 /* Constructor and destructor field names are set to the name
1994 of the class, but without template parameter lists.
1995 The name might be missing for anonymous aggregates. */
1996 if (TYPE_TAG_NAME (type
))
1998 char *p
= strchr (TYPE_TAG_NAME (type
), '<');
2001 fieldname
= TYPE_TAG_NAME (type
);
2003 fieldname
= obsavestring (TYPE_TAG_NAME (type
),
2004 p
- TYPE_TAG_NAME (type
),
2005 &objfile
->type_obstack
);
2009 char *anon_name
= "";
2010 fieldname
= obsavestring (anon_name
, strlen (anon_name
),
2011 &objfile
->type_obstack
);
2016 char *endname
= skip_member_fn_name (physname
);
2018 /* Ignore member function if we were unable not extract the member
2020 if (endname
== physname
)
2022 fieldname
= obsavestring (physname
, endname
- physname
,
2023 &objfile
->type_obstack
);
2026 /* Look up member function name in fieldlist. */
2027 for (i
= 0; i
< fip
->nfnfields
; i
++)
2029 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2033 /* Create new list element if necessary. */
2034 if (i
< fip
->nfnfields
)
2035 flp
= &fip
->fnfieldlists
[i
];
2038 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2040 fip
->fnfieldlists
= (struct fnfieldlist
*)
2041 xrealloc (fip
->fnfieldlists
,
2042 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2043 * sizeof (struct fnfieldlist
));
2044 if (fip
->nfnfields
== 0)
2045 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2047 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2048 flp
->name
= fieldname
;
2054 /* Create a new member function field and chain it to the field list
2056 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2057 make_cleanup (free
, new_fnfield
);
2058 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2059 new_fnfield
->next
= flp
->head
;
2060 flp
->head
= new_fnfield
;
2063 /* Fill in the member function field info. */
2064 fnp
= &new_fnfield
->fnfield
;
2065 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2066 &objfile
->type_obstack
);
2067 fnp
->type
= alloc_type (objfile
);
2068 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2070 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2071 struct type
**arg_types
;
2072 int nparams
= TYPE_NFIELDS (die
->type
);
2075 /* Copy argument types from the subroutine type. */
2076 arg_types
= (struct type
**)
2077 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2078 for (iparams
= 0; iparams
< nparams
; iparams
++)
2079 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2081 /* Set last entry in argument type vector. */
2082 if (TYPE_FLAGS (die
->type
) & TYPE_FLAG_VARARGS
)
2083 arg_types
[nparams
] = NULL
;
2085 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2087 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2089 /* Handle static member functions.
2090 Dwarf2 has no clean way to discern C++ static and non-static
2091 member functions. G++ helps GDB by marking the first
2092 parameter for non-static member functions (which is the
2093 this pointer) as artificial. We obtain this information
2094 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2095 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2096 fnp
->voffset
= VOFFSET_STATIC
;
2099 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2101 /* Get fcontext from DW_AT_containing_type if present. */
2102 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2103 fnp
->fcontext
= die_containing_type (die
, objfile
);
2105 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2106 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2108 /* Get accessibility. */
2109 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2112 switch (DW_UNSND (attr
))
2114 case DW_ACCESS_private
:
2115 fnp
->is_private
= 1;
2117 case DW_ACCESS_protected
:
2118 fnp
->is_protected
= 1;
2123 /* Get index in virtual function table if it is a virtual member function. */
2124 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2126 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
) + 2;
2129 /* Create the vector of member function fields, and attach it to the type. */
2132 dwarf2_attach_fn_fields_to_type (fip
, type
, objfile
)
2133 struct field_info
*fip
;
2135 struct objfile
*objfile
;
2137 struct fnfieldlist
*flp
;
2138 int total_length
= 0;
2141 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2142 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2143 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2145 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2147 struct nextfnfield
*nfp
= flp
->head
;
2148 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2151 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2152 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2153 fn_flp
->fn_fields
= (struct fn_field
*)
2154 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2155 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2156 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2158 total_length
+= flp
->length
;
2161 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2162 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2165 /* Called when we find the DIE that starts a structure or union scope
2166 (definition) to process all dies that define the members of the
2169 NOTE: we need to call struct_type regardless of whether or not the
2170 DIE has an at_name attribute, since it might be an anonymous
2171 structure or union. This gets the type entered into our set of
2174 However, if the structure is incomplete (an opaque struct/union)
2175 then suppress creating a symbol table entry for it since gdb only
2176 wants to find the one with the complete definition. Note that if
2177 it is complete, we just call new_symbol, which does it's own
2178 checking about whether the struct/union is anonymous or not (and
2179 suppresses creating a symbol table entry itself). */
2182 read_structure_scope (die
, objfile
)
2183 struct die_info
*die
;
2184 struct objfile
*objfile
;
2187 struct attribute
*attr
;
2189 type
= alloc_type (objfile
);
2191 INIT_CPLUS_SPECIFIC (type
);
2192 attr
= dwarf_attr (die
, DW_AT_name
);
2193 if (attr
&& DW_STRING (attr
))
2195 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2196 strlen (DW_STRING (attr
)),
2197 &objfile
->type_obstack
);
2200 if (die
->tag
== DW_TAG_structure_type
)
2202 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2204 else if (die
->tag
== DW_TAG_union_type
)
2206 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2210 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2212 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2215 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2218 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2222 TYPE_LENGTH (type
) = 0;
2225 /* We need to add the type field to the die immediately so we don't
2226 infinitely recurse when dealing with pointers to the structure
2227 type within the structure itself. */
2230 if (die
->has_children
)
2232 struct field_info fi
;
2233 struct die_info
*child_die
;
2234 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2236 memset (&fi
, 0, sizeof (struct field_info
));
2238 child_die
= die
->next
;
2240 while (child_die
&& child_die
->tag
)
2242 if (child_die
->tag
== DW_TAG_member
)
2244 dwarf2_add_field (&fi
, child_die
, objfile
);
2246 else if (child_die
->tag
== DW_TAG_variable
)
2248 /* C++ static member. */
2249 dwarf2_add_field (&fi
, child_die
, objfile
);
2251 else if (child_die
->tag
== DW_TAG_subprogram
)
2253 /* C++ member function. */
2254 process_die (child_die
, objfile
);
2255 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
);
2257 else if (child_die
->tag
== DW_TAG_inheritance
)
2259 /* C++ base class field. */
2260 dwarf2_add_field (&fi
, child_die
, objfile
);
2264 process_die (child_die
, objfile
);
2266 child_die
= sibling_die (child_die
);
2269 /* Attach fields and member functions to the type. */
2271 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2274 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2276 /* Get the type which refers to the base class (possibly this
2277 class itself) which contains the vtable pointer for the current
2278 class from the DW_AT_containing_type attribute. */
2280 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2282 struct type
*t
= die_containing_type (die
, objfile
);
2284 TYPE_VPTR_BASETYPE (type
) = t
;
2287 static const char vptr_name
[] = { '_','v','p','t','r','\0' };
2290 /* Our own class provides vtbl ptr. */
2291 for (i
= TYPE_NFIELDS (t
) - 1;
2292 i
>= TYPE_N_BASECLASSES (t
);
2295 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2297 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2298 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2300 TYPE_VPTR_FIELDNO (type
) = i
;
2305 /* Complain if virtual function table field not found. */
2306 if (i
< TYPE_N_BASECLASSES (t
))
2307 complain (&dwarf2_vtbl_not_found_complaint
,
2308 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2312 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2317 new_symbol (die
, type
, objfile
);
2319 do_cleanups (back_to
);
2323 /* No children, must be stub. */
2324 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2330 /* Given a pointer to a die which begins an enumeration, process all
2331 the dies that define the members of the enumeration.
2333 This will be much nicer in draft 6 of the DWARF spec when our
2334 members will be dies instead squished into the DW_AT_element_list
2337 NOTE: We reverse the order of the element list. */
2340 read_enumeration (die
, objfile
)
2341 struct die_info
*die
;
2342 struct objfile
*objfile
;
2344 struct die_info
*child_die
;
2346 struct field
*fields
;
2347 struct attribute
*attr
;
2350 int unsigned_enum
= 1;
2352 type
= alloc_type (objfile
);
2354 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2355 attr
= dwarf_attr (die
, DW_AT_name
);
2356 if (attr
&& DW_STRING (attr
))
2358 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2359 strlen (DW_STRING (attr
)),
2360 &objfile
->type_obstack
);
2363 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2366 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2370 TYPE_LENGTH (type
) = 0;
2375 if (die
->has_children
)
2377 child_die
= die
->next
;
2378 while (child_die
&& child_die
->tag
)
2380 if (child_die
->tag
!= DW_TAG_enumerator
)
2382 process_die (child_die
, objfile
);
2386 attr
= dwarf_attr (child_die
, DW_AT_name
);
2389 sym
= new_symbol (child_die
, type
, objfile
);
2390 if (SYMBOL_VALUE (sym
) < 0)
2393 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2395 fields
= (struct field
*)
2397 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2398 * sizeof (struct field
));
2401 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2402 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2403 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2404 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2410 child_die
= sibling_die (child_die
);
2415 TYPE_NFIELDS (type
) = num_fields
;
2416 TYPE_FIELDS (type
) = (struct field
*)
2417 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2418 memcpy (TYPE_FIELDS (type
), fields
,
2419 sizeof (struct field
) * num_fields
);
2423 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2426 new_symbol (die
, type
, objfile
);
2429 /* Extract all information from a DW_TAG_array_type DIE and put it in
2430 the DIE's type field. For now, this only handles one dimensional
2434 read_array_type (die
, objfile
)
2435 struct die_info
*die
;
2436 struct objfile
*objfile
;
2438 struct die_info
*child_die
;
2439 struct type
*type
= NULL
;
2440 struct type
*element_type
, *range_type
, *index_type
;
2441 struct type
**range_types
= NULL
;
2442 struct attribute
*attr
;
2444 struct cleanup
*back_to
;
2446 /* Return if we've already decoded this type. */
2452 element_type
= die_type (die
, objfile
);
2454 /* Irix 6.2 native cc creates array types without children for
2455 arrays with unspecified length. */
2456 if (die
->has_children
== 0)
2458 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2459 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2460 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2464 back_to
= make_cleanup (null_cleanup
, NULL
);
2465 child_die
= die
->next
;
2466 while (child_die
&& child_die
->tag
)
2468 if (child_die
->tag
== DW_TAG_subrange_type
)
2470 unsigned int low
, high
;
2472 /* Default bounds to an array with unspecified length. */
2475 if (cu_language
== DW_LANG_Fortran77
2476 || cu_language
== DW_LANG_Fortran90
)
2478 /* FORTRAN implies a lower bound of 1, if not given. */
2482 index_type
= die_type (child_die
, objfile
);
2483 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2486 if (attr
->form
== DW_FORM_sdata
)
2488 low
= DW_SND (attr
);
2490 else if (attr
->form
== DW_FORM_udata
2491 || attr
->form
== DW_FORM_data1
2492 || attr
->form
== DW_FORM_data2
2493 || attr
->form
== DW_FORM_data4
)
2495 low
= DW_UNSND (attr
);
2499 complain (&dwarf2_non_const_array_bound_ignored
,
2500 dwarf_form_name (attr
->form
));
2502 die
->type
= lookup_pointer_type (element_type
);
2509 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2512 if (attr
->form
== DW_FORM_sdata
)
2514 high
= DW_SND (attr
);
2516 else if (attr
->form
== DW_FORM_udata
2517 || attr
->form
== DW_FORM_data1
2518 || attr
->form
== DW_FORM_data2
2519 || attr
->form
== DW_FORM_data4
)
2521 high
= DW_UNSND (attr
);
2523 else if (attr
->form
== DW_FORM_block1
)
2525 /* GCC encodes arrays with unspecified or dynamic length
2526 with a DW_FORM_block1 attribute.
2527 FIXME: GDB does not yet know how to handle dynamic
2528 arrays properly, treat them as arrays with unspecified
2534 complain (&dwarf2_non_const_array_bound_ignored
,
2535 dwarf_form_name (attr
->form
));
2537 die
->type
= lookup_pointer_type (element_type
);
2545 /* Create a range type and save it for array type creation. */
2546 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2548 range_types
= (struct type
**)
2549 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2550 * sizeof (struct type
*));
2552 make_cleanup (free_current_contents
, &range_types
);
2554 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2556 child_die
= sibling_die (child_die
);
2559 /* Dwarf2 dimensions are output from left to right, create the
2560 necessary array types in backwards order. */
2561 type
= element_type
;
2563 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2565 do_cleanups (back_to
);
2567 /* Install the type in the die. */
2571 /* First cut: install each common block member as a global variable. */
2574 read_common_block (die
, objfile
)
2575 struct die_info
*die
;
2576 struct objfile
*objfile
;
2578 struct die_info
*child_die
;
2579 struct attribute
*attr
;
2581 CORE_ADDR base
= (CORE_ADDR
) 0;
2583 attr
= dwarf_attr (die
, DW_AT_location
);
2586 base
= decode_locdesc (DW_BLOCK (attr
), objfile
);
2588 if (die
->has_children
)
2590 child_die
= die
->next
;
2591 while (child_die
&& child_die
->tag
)
2593 sym
= new_symbol (child_die
, NULL
, objfile
);
2594 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2597 SYMBOL_VALUE_ADDRESS (sym
) =
2598 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
);
2599 add_symbol_to_list (sym
, &global_symbols
);
2601 child_die
= sibling_die (child_die
);
2606 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2607 the user defined type vector. */
2610 read_tag_pointer_type (die
, objfile
)
2611 struct die_info
*die
;
2612 struct objfile
*objfile
;
2615 struct attribute
*attr
;
2622 type
= lookup_pointer_type (die_type (die
, objfile
));
2623 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2626 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2630 TYPE_LENGTH (type
) = address_size
;
2635 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2636 the user defined type vector. */
2639 read_tag_ptr_to_member_type (die
, objfile
)
2640 struct die_info
*die
;
2641 struct objfile
*objfile
;
2644 struct type
*to_type
;
2645 struct type
*domain
;
2652 type
= alloc_type (objfile
);
2653 to_type
= die_type (die
, objfile
);
2654 domain
= die_containing_type (die
, objfile
);
2655 smash_to_member_type (type
, domain
, to_type
);
2660 /* Extract all information from a DW_TAG_reference_type DIE and add to
2661 the user defined type vector. */
2664 read_tag_reference_type (die
, objfile
)
2665 struct die_info
*die
;
2666 struct objfile
*objfile
;
2669 struct attribute
*attr
;
2676 type
= lookup_reference_type (die_type (die
, objfile
));
2677 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2680 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2684 TYPE_LENGTH (type
) = address_size
;
2690 read_tag_const_type (die
, objfile
)
2691 struct die_info
*die
;
2692 struct objfile
*objfile
;
2699 complain (&dwarf2_const_ignored
);
2700 die
->type
= die_type (die
, objfile
);
2704 read_tag_volatile_type (die
, objfile
)
2705 struct die_info
*die
;
2706 struct objfile
*objfile
;
2713 complain (&dwarf2_volatile_ignored
);
2714 die
->type
= die_type (die
, objfile
);
2717 /* Extract all information from a DW_TAG_string_type DIE and add to
2718 the user defined type vector. It isn't really a user defined type,
2719 but it behaves like one, with other DIE's using an AT_user_def_type
2720 attribute to reference it. */
2723 read_tag_string_type (die
, objfile
)
2724 struct die_info
*die
;
2725 struct objfile
*objfile
;
2727 struct type
*type
, *range_type
, *index_type
, *char_type
;
2728 struct attribute
*attr
;
2729 unsigned int length
;
2736 attr
= dwarf_attr (die
, DW_AT_string_length
);
2739 length
= DW_UNSND (attr
);
2745 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2746 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2747 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2748 type
= create_string_type (char_type
, range_type
);
2752 /* Handle DIES due to C code like:
2756 int (*funcp)(int a, long l);
2760 ('funcp' generates a DW_TAG_subroutine_type DIE)
2764 read_subroutine_type (die
, objfile
)
2765 struct die_info
*die
;
2766 struct objfile
*objfile
;
2768 struct type
*type
; /* Type that this function returns */
2769 struct type
*ftype
; /* Function that returns above type */
2770 struct attribute
*attr
;
2772 /* Decode the type that this subroutine returns */
2777 type
= die_type (die
, objfile
);
2778 ftype
= lookup_function_type (type
);
2779 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2780 if (attr
&& (DW_UNSND (attr
) != 0))
2781 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2783 if (die
->has_children
)
2785 struct die_info
*child_die
;
2789 /* Count the number of parameters.
2790 FIXME: GDB currently ignores vararg functions, but knows about
2791 vararg member functions. */
2792 child_die
= die
->next
;
2793 while (child_die
&& child_die
->tag
)
2795 if (child_die
->tag
== DW_TAG_formal_parameter
)
2797 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2798 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2799 child_die
= sibling_die (child_die
);
2802 /* Allocate storage for parameters and fill them in. */
2803 TYPE_NFIELDS (ftype
) = nparams
;
2804 TYPE_FIELDS (ftype
) = (struct field
*)
2805 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2807 child_die
= die
->next
;
2808 while (child_die
&& child_die
->tag
)
2810 if (child_die
->tag
== DW_TAG_formal_parameter
)
2812 /* Dwarf2 has no clean way to discern C++ static and non-static
2813 member functions. G++ helps GDB by marking the first
2814 parameter for non-static member functions (which is the
2815 this pointer) as artificial. We pass this information
2816 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2817 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2819 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2821 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2822 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
);
2825 child_die
= sibling_die (child_die
);
2833 read_typedef (die
, objfile
)
2834 struct die_info
*die
;
2835 struct objfile
*objfile
;
2841 struct attribute
*attr
;
2844 xtype
= die_type (die
, objfile
);
2846 type
= alloc_type (objfile
);
2847 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2848 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2849 TYPE_TARGET_TYPE (type
) = xtype
;
2850 attr
= dwarf_attr (die
, DW_AT_name
);
2851 if (attr
&& DW_STRING (attr
))
2852 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2853 strlen (DW_STRING (attr
)),
2854 &objfile
->type_obstack
);
2860 /* Find a representation of a given base type and install
2861 it in the TYPE field of the die. */
2864 read_base_type (die
, objfile
)
2865 struct die_info
*die
;
2866 struct objfile
*objfile
;
2869 struct attribute
*attr
;
2870 int encoding
= 0, size
= 0;
2872 /* If we've already decoded this die, this is a no-op. */
2878 attr
= dwarf_attr (die
, DW_AT_encoding
);
2881 encoding
= DW_UNSND (attr
);
2883 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2886 size
= DW_UNSND (attr
);
2888 attr
= dwarf_attr (die
, DW_AT_name
);
2889 if (attr
&& DW_STRING (attr
))
2891 enum type_code code
= TYPE_CODE_INT
;
2892 int is_unsigned
= 0;
2896 case DW_ATE_address
:
2897 /* Turn DW_ATE_address into a void * pointer. */
2898 code
= TYPE_CODE_PTR
;
2901 case DW_ATE_boolean
:
2902 code
= TYPE_CODE_BOOL
;
2905 case DW_ATE_complex_float
:
2906 code
= TYPE_CODE_COMPLEX
;
2909 code
= TYPE_CODE_FLT
;
2912 case DW_ATE_signed_char
:
2914 case DW_ATE_unsigned
:
2915 case DW_ATE_unsigned_char
:
2919 complain (&dwarf2_unsupported_at_encoding
,
2920 dwarf_type_encoding_name (encoding
));
2923 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2924 if (encoding
== DW_ATE_address
)
2925 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2929 type
= dwarf_base_type (encoding
, size
, objfile
);
2934 /* Read a whole compilation unit into a linked list of dies. */
2937 read_comp_unit (info_ptr
, abfd
)
2941 struct die_info
*first_die
, *last_die
, *die
;
2945 /* Reset die reference table, we are building a new one now. */
2946 dwarf2_empty_die_ref_table ();
2950 first_die
= last_die
= NULL
;
2953 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
);
2954 if (die
->has_children
)
2965 /* Enter die in reference hash table */
2966 store_in_ref_table (die
->offset
, die
);
2970 first_die
= last_die
= die
;
2974 last_die
->next
= die
;
2978 while (nesting_level
> 0);
2982 /* Free a linked list of dies. */
2985 free_die_list (dies
)
2986 struct die_info
*dies
;
2988 struct die_info
*die
, *next
;
3000 /* Read the contents of the section at OFFSET and of size SIZE from the
3001 object file specified by OBJFILE into the psymbol_obstack and return it. */
3004 dwarf2_read_section (objfile
, offset
, size
)
3005 struct objfile
*objfile
;
3009 bfd
*abfd
= objfile
->obfd
;
3015 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3016 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3017 (bfd_read (buf
, size
, 1, abfd
) != size
))
3020 error ("Dwarf Error: Can't read DWARF data from '%s'",
3021 bfd_get_filename (abfd
));
3026 /* In DWARF version 2, the description of the debugging information is
3027 stored in a separate .debug_abbrev section. Before we read any
3028 dies from a section we read in all abbreviations and install them
3032 dwarf2_read_abbrevs (abfd
, offset
)
3034 unsigned int offset
;
3037 struct abbrev_info
*cur_abbrev
;
3038 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3039 unsigned int abbrev_form
, hash_number
;
3041 /* empty the table */
3042 dwarf2_empty_abbrev_table (NULL
);
3044 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3045 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3046 abbrev_ptr
+= bytes_read
;
3048 /* loop until we reach an abbrev number of 0 */
3049 while (abbrev_number
)
3051 cur_abbrev
= dwarf_alloc_abbrev ();
3053 /* read in abbrev header */
3054 cur_abbrev
->number
= abbrev_number
;
3055 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3056 abbrev_ptr
+= bytes_read
;
3057 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3060 /* now read in declarations */
3061 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3062 abbrev_ptr
+= bytes_read
;
3063 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3064 abbrev_ptr
+= bytes_read
;
3067 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3069 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3070 xrealloc (cur_abbrev
->attrs
,
3071 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3072 * sizeof (struct attr_abbrev
));
3074 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3075 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3076 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3077 abbrev_ptr
+= bytes_read
;
3078 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3079 abbrev_ptr
+= bytes_read
;
3082 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3083 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3084 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3086 /* Get next abbreviation.
3087 Under Irix6 the abbreviations for a compilation unit are not
3088 always properly terminated with an abbrev number of 0.
3089 Exit loop if we encounter an abbreviation which we have
3090 already read (which means we are about to read the abbreviations
3091 for the next compile unit) or if the end of the abbreviation
3092 table is reached. */
3093 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3094 >= dwarf_abbrev_size
)
3096 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3097 abbrev_ptr
+= bytes_read
;
3098 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3103 /* Empty the abbrev table for a new compilation unit. */
3107 dwarf2_empty_abbrev_table (ignore
)
3111 struct abbrev_info
*abbrev
, *next
;
3113 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3116 abbrev
= dwarf2_abbrevs
[i
];
3119 next
= abbrev
->next
;
3120 free (abbrev
->attrs
);
3124 dwarf2_abbrevs
[i
] = NULL
;
3128 /* Lookup an abbrev_info structure in the abbrev hash table. */
3130 static struct abbrev_info
*
3131 dwarf2_lookup_abbrev (number
)
3132 unsigned int number
;
3134 unsigned int hash_number
;
3135 struct abbrev_info
*abbrev
;
3137 hash_number
= number
% ABBREV_HASH_SIZE
;
3138 abbrev
= dwarf2_abbrevs
[hash_number
];
3142 if (abbrev
->number
== number
)
3145 abbrev
= abbrev
->next
;
3150 /* Read a minimal amount of information into the minimal die structure. */
3153 read_partial_die (part_die
, abfd
, info_ptr
, has_pc_info
)
3154 struct partial_die_info
*part_die
;
3159 unsigned int abbrev_number
, bytes_read
, i
;
3160 struct abbrev_info
*abbrev
;
3161 struct attribute attr
;
3162 struct attribute spec_attr
;
3163 int found_spec_attr
= 0;
3164 int has_low_pc_attr
= 0;
3165 int has_high_pc_attr
= 0;
3167 *part_die
= zeroed_partial_die
;
3169 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3170 info_ptr
+= bytes_read
;
3174 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3177 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3179 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3180 part_die
->tag
= abbrev
->tag
;
3181 part_die
->has_children
= abbrev
->has_children
;
3182 part_die
->abbrev
= abbrev_number
;
3184 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3186 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
);
3188 /* Store the data if it is of an attribute we want to keep in a
3189 partial symbol table. */
3194 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3195 if (part_die
->name
== NULL
)
3196 part_die
->name
= DW_STRING (&attr
);
3198 case DW_AT_MIPS_linkage_name
:
3199 part_die
->name
= DW_STRING (&attr
);
3202 has_low_pc_attr
= 1;
3203 part_die
->lowpc
= DW_ADDR (&attr
);
3206 has_high_pc_attr
= 1;
3207 part_die
->highpc
= DW_ADDR (&attr
);
3209 case DW_AT_location
:
3210 part_die
->locdesc
= DW_BLOCK (&attr
);
3212 case DW_AT_language
:
3213 part_die
->language
= DW_UNSND (&attr
);
3215 case DW_AT_external
:
3216 part_die
->is_external
= DW_UNSND (&attr
);
3218 case DW_AT_declaration
:
3219 part_die
->is_declaration
= DW_UNSND (&attr
);
3222 part_die
->has_type
= 1;
3224 case DW_AT_abstract_origin
:
3225 case DW_AT_specification
:
3226 found_spec_attr
= 1;
3230 /* Ignore absolute siblings, they might point outside of
3231 the current compile unit. */
3232 if (attr
.form
== DW_FORM_ref_addr
)
3233 complain(&dwarf2_absolute_sibling_complaint
);
3236 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3243 /* If we found a reference attribute and the die has no name, try
3244 to find a name in the referred to die. */
3246 if (found_spec_attr
&& part_die
->name
== NULL
)
3248 struct partial_die_info spec_die
;
3252 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3253 read_partial_die (&spec_die
, abfd
, spec_ptr
, &dummy
);
3256 part_die
->name
= spec_die
.name
;
3258 /* Copy DW_AT_external attribute if it is set. */
3259 if (spec_die
.is_external
)
3260 part_die
->is_external
= spec_die
.is_external
;
3264 /* When using the GNU linker, .gnu.linkonce. sections are used to
3265 eliminate duplicate copies of functions and vtables and such.
3266 The linker will arbitrarily choose one and discard the others.
3267 The AT_*_pc values for such functions refer to local labels in
3268 these sections. If the section from that file was discarded, the
3269 labels are not in the output, so the relocs get a value of 0.
3270 If this is a discarded function, mark the pc bounds as invalid,
3271 so that GDB will ignore it. */
3272 if (has_low_pc_attr
&& has_high_pc_attr
3273 && part_die
->lowpc
< part_die
->highpc
3274 && (part_die
->lowpc
!= 0
3275 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3280 /* Read the die from the .debug_info section buffer. And set diep to
3281 point to a newly allocated die with its information. */
3284 read_full_die (diep
, abfd
, info_ptr
)
3285 struct die_info
**diep
;
3289 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3290 struct abbrev_info
*abbrev
;
3291 struct die_info
*die
;
3293 offset
= info_ptr
- dwarf_info_buffer
;
3294 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3295 info_ptr
+= bytes_read
;
3298 die
= dwarf_alloc_die ();
3300 die
->abbrev
= abbrev_number
;
3306 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3309 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3311 die
= dwarf_alloc_die ();
3312 die
->offset
= offset
;
3313 die
->tag
= abbrev
->tag
;
3314 die
->has_children
= abbrev
->has_children
;
3315 die
->abbrev
= abbrev_number
;
3318 die
->num_attrs
= abbrev
->num_attrs
;
3319 die
->attrs
= (struct attribute
*)
3320 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3322 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3324 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3332 /* Read an attribute described by an abbreviated attribute. */
3335 read_attribute (attr
, abbrev
, abfd
, info_ptr
)
3336 struct attribute
*attr
;
3337 struct attr_abbrev
*abbrev
;
3341 unsigned int bytes_read
;
3342 struct dwarf_block
*blk
;
3344 attr
->name
= abbrev
->name
;
3345 attr
->form
= abbrev
->form
;
3346 switch (abbrev
->form
)
3349 case DW_FORM_ref_addr
:
3350 DW_ADDR (attr
) = read_address (abfd
, info_ptr
);
3351 info_ptr
+= address_size
;
3353 case DW_FORM_block2
:
3354 blk
= dwarf_alloc_block ();
3355 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3357 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3358 info_ptr
+= blk
->size
;
3359 DW_BLOCK (attr
) = blk
;
3361 case DW_FORM_block4
:
3362 blk
= dwarf_alloc_block ();
3363 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3365 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3366 info_ptr
+= blk
->size
;
3367 DW_BLOCK (attr
) = blk
;
3370 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3374 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3378 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3381 case DW_FORM_string
:
3382 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3383 info_ptr
+= bytes_read
;
3386 blk
= dwarf_alloc_block ();
3387 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3388 info_ptr
+= bytes_read
;
3389 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3390 info_ptr
+= blk
->size
;
3391 DW_BLOCK (attr
) = blk
;
3393 case DW_FORM_block1
:
3394 blk
= dwarf_alloc_block ();
3395 blk
->size
= read_1_byte (abfd
, info_ptr
);
3397 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3398 info_ptr
+= blk
->size
;
3399 DW_BLOCK (attr
) = blk
;
3402 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3406 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3410 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3411 info_ptr
+= bytes_read
;
3414 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3415 info_ptr
+= bytes_read
;
3418 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3422 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3426 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3429 case DW_FORM_ref_udata
:
3430 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3431 info_ptr
+= bytes_read
;
3434 case DW_FORM_indirect
:
3436 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3437 dwarf_form_name (abbrev
->form
));
3442 /* read dwarf information from a buffer */
3445 read_1_byte (abfd
, buf
)
3449 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3453 read_1_signed_byte (abfd
, buf
)
3457 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3461 read_2_bytes (abfd
, buf
)
3465 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3469 read_2_signed_bytes (abfd
, buf
)
3473 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3477 read_4_bytes (abfd
, buf
)
3481 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3485 read_4_signed_bytes (abfd
, buf
)
3489 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3493 read_8_bytes (abfd
, buf
)
3497 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3501 read_address (abfd
, buf
)
3505 CORE_ADDR retval
= 0;
3507 if (address_size
== 4)
3509 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3510 } else { /* *THE* alternative is 8, right? */
3511 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3517 read_n_bytes (abfd
, buf
, size
)
3522 /* If the size of a host char is 8 bits, we can return a pointer
3523 to the buffer, otherwise we have to copy the data to a buffer
3524 allocated on the temporary obstack. */
3525 #if HOST_CHAR_BIT == 8
3531 ret
= obstack_alloc (&dwarf2_tmp_obstack
, size
);
3532 for (i
= 0; i
< size
; ++i
)
3534 ret
[i
] = bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3542 read_string (abfd
, buf
, bytes_read_ptr
)
3545 unsigned int *bytes_read_ptr
;
3547 /* If the size of a host char is 8 bits, we can return a pointer
3548 to the string, otherwise we have to copy the string to a buffer
3549 allocated on the temporary obstack. */
3550 #if HOST_CHAR_BIT == 8
3553 *bytes_read_ptr
= 1;
3556 *bytes_read_ptr
= strlen (buf
) + 1;
3562 while ((byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
)) != 0)
3564 obstack_1grow (&dwarf2_tmp_obstack
, byte
);
3570 *bytes_read_ptr
= 1;
3573 obstack_1grow (&dwarf2_tmp_obstack
, '\0');
3574 *bytes_read_ptr
= i
+ 1;
3575 return obstack_finish (&dwarf2_tmp_obstack
);
3580 read_unsigned_leb128 (abfd
, buf
, bytes_read_ptr
)
3583 unsigned int *bytes_read_ptr
;
3585 unsigned int result
, num_read
;
3595 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3598 result
|= ((byte
& 127) << shift
);
3599 if ((byte
& 128) == 0)
3605 *bytes_read_ptr
= num_read
;
3610 read_signed_leb128 (abfd
, buf
, bytes_read_ptr
)
3613 unsigned int *bytes_read_ptr
;
3616 int i
, shift
, size
, num_read
;
3626 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3629 result
|= ((byte
& 127) << shift
);
3631 if ((byte
& 128) == 0)
3636 if ((shift
< size
) && (byte
& 0x40))
3638 result
|= -(1 << shift
);
3640 *bytes_read_ptr
= num_read
;
3645 set_cu_language (lang
)
3652 case DW_LANG_Fortran77
:
3653 cu_language
= language_c
;
3655 case DW_LANG_C_plus_plus
:
3656 cu_language
= language_cplus
;
3658 case DW_LANG_Mips_Assembler
:
3659 cu_language
= language_asm
;
3662 case DW_LANG_Cobol74
:
3663 case DW_LANG_Cobol85
:
3665 case DW_LANG_Fortran77
: /* moved up top for now */
3667 case DW_LANG_Fortran90
:
3668 case DW_LANG_Pascal83
:
3669 case DW_LANG_Modula2
:
3671 cu_language
= language_unknown
;
3674 cu_language_defn
= language_def (cu_language
);
3677 /* Return the named attribute or NULL if not there. */
3679 static struct attribute
*
3680 dwarf_attr (die
, name
)
3681 struct die_info
*die
;
3685 struct attribute
*spec
= NULL
;
3687 for (i
= 0; i
< die
->num_attrs
; ++i
)
3689 if (die
->attrs
[i
].name
== name
)
3691 return &die
->attrs
[i
];
3693 if (die
->attrs
[i
].name
== DW_AT_specification
3694 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3695 spec
= &die
->attrs
[i
];
3699 struct die_info
*ref_die
=
3700 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3703 return dwarf_attr (ref_die
, name
);
3709 /* Decode the line number information for the compilation unit whose
3710 line number info is at OFFSET in the .debug_line section.
3711 The compilation directory of the file is passed in COMP_DIR. */
3715 unsigned int num_files
;
3728 unsigned int num_dirs
;
3733 dwarf_decode_lines (offset
, comp_dir
, abfd
)
3734 unsigned int offset
;
3740 struct line_head lh
;
3741 struct cleanup
*back_to
;
3742 unsigned int i
, bytes_read
;
3743 char *cur_file
, *cur_dir
;
3744 unsigned char op_code
, extended_op
, adj_opcode
;
3746 #define FILE_ALLOC_CHUNK 5
3747 #define DIR_ALLOC_CHUNK 5
3749 struct filenames files
;
3750 struct directories dirs
;
3752 if (dwarf_line_buffer
== NULL
)
3754 complain (&dwarf2_missing_line_number_section
);
3758 files
.num_files
= 0;
3764 line_ptr
= dwarf_line_buffer
+ offset
;
3766 /* read in the prologue */
3767 lh
.total_length
= read_4_bytes (abfd
, line_ptr
);
3769 line_end
= line_ptr
+ lh
.total_length
;
3770 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3772 lh
.prologue_length
= read_4_bytes (abfd
, line_ptr
);
3774 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3776 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3778 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3780 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3782 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3784 lh
.standard_opcode_lengths
= (unsigned char *)
3785 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3786 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
3788 lh
.standard_opcode_lengths
[0] = 1;
3789 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3791 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3795 /* Read directory table */
3796 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3798 line_ptr
+= bytes_read
;
3799 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3801 dirs
.dirs
= (char **)
3802 xrealloc (dirs
.dirs
,
3803 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3804 if (dirs
.num_dirs
== 0)
3805 make_cleanup (free_current_contents
, &dirs
.dirs
);
3807 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3809 line_ptr
+= bytes_read
;
3811 /* Read file name table */
3812 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3814 line_ptr
+= bytes_read
;
3815 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3817 files
.files
= (struct fileinfo
*)
3818 xrealloc (files
.files
,
3819 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3820 * sizeof (struct fileinfo
));
3821 if (files
.num_files
== 0)
3822 make_cleanup (free_current_contents
, &files
.files
);
3824 files
.files
[files
.num_files
].name
= cur_file
;
3825 files
.files
[files
.num_files
].dir
=
3826 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3827 line_ptr
+= bytes_read
;
3828 files
.files
[files
.num_files
].time
=
3829 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3830 line_ptr
+= bytes_read
;
3831 files
.files
[files
.num_files
].size
=
3832 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3833 line_ptr
+= bytes_read
;
3836 line_ptr
+= bytes_read
;
3838 /* Read the statement sequences until there's nothing left. */
3839 while (line_ptr
< line_end
)
3841 /* state machine registers */
3842 unsigned int address
= 0;
3843 unsigned int file
= 1;
3844 unsigned int line
= 1;
3845 unsigned int column
= 0;
3846 int is_stmt
= lh
.default_is_stmt
;
3847 int basic_block
= 0;
3848 int end_sequence
= 0;
3850 /* Start a subfile for the current file of the state machine. */
3851 if (files
.num_files
>= file
)
3853 /* The file and directory tables are 0 based, the references
3855 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3856 (files
.files
[file
- 1].dir
3857 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3861 /* Decode the table. */
3862 while (! end_sequence
)
3864 op_code
= read_1_byte (abfd
, line_ptr
);
3868 case DW_LNS_extended_op
:
3869 line_ptr
+= 1; /* ignore length */
3870 extended_op
= read_1_byte (abfd
, line_ptr
);
3872 switch (extended_op
)
3874 case DW_LNE_end_sequence
:
3876 record_line (current_subfile
, line
, address
);
3878 case DW_LNE_set_address
:
3879 address
= read_address (abfd
, line_ptr
) + baseaddr
;
3880 line_ptr
+= address_size
;
3882 case DW_LNE_define_file
:
3883 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
3884 line_ptr
+= bytes_read
;
3885 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3887 files
.files
= (struct fileinfo
*)
3888 xrealloc (files
.files
,
3889 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3890 * sizeof (struct fileinfo
));
3891 if (files
.num_files
== 0)
3892 make_cleanup (free_current_contents
, &files
.files
);
3894 files
.files
[files
.num_files
].name
= cur_file
;
3895 files
.files
[files
.num_files
].dir
=
3896 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3897 line_ptr
+= bytes_read
;
3898 files
.files
[files
.num_files
].time
=
3899 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3900 line_ptr
+= bytes_read
;
3901 files
.files
[files
.num_files
].size
=
3902 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3903 line_ptr
+= bytes_read
;
3907 complain (&dwarf2_mangled_line_number_section
);
3912 record_line (current_subfile
, line
, address
);
3915 case DW_LNS_advance_pc
:
3916 address
+= lh
.minimum_instruction_length
3917 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3918 line_ptr
+= bytes_read
;
3920 case DW_LNS_advance_line
:
3921 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
3922 line_ptr
+= bytes_read
;
3924 case DW_LNS_set_file
:
3925 /* The file and directory tables are 0 based, the references
3927 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3928 line_ptr
+= bytes_read
;
3929 dwarf2_start_subfile
3930 (files
.files
[file
- 1].name
,
3931 (files
.files
[file
- 1].dir
3932 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3935 case DW_LNS_set_column
:
3936 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3937 line_ptr
+= bytes_read
;
3939 case DW_LNS_negate_stmt
:
3940 is_stmt
= (!is_stmt
);
3942 case DW_LNS_set_basic_block
:
3945 case DW_LNS_const_add_pc
:
3946 address
+= (255 - lh
.opcode_base
) / lh
.line_range
;
3948 case DW_LNS_fixed_advance_pc
:
3949 address
+= read_2_bytes (abfd
, line_ptr
);
3952 default: /* special operand */
3953 adj_opcode
= op_code
- lh
.opcode_base
;
3954 address
+= (adj_opcode
/ lh
.line_range
)
3955 * lh
.minimum_instruction_length
;
3956 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
3957 /* append row to matrix using current values */
3958 record_line (current_subfile
, line
, address
);
3964 do_cleanups (back_to
);
3967 /* Start a subfile for DWARF. FILENAME is the name of the file and
3968 DIRNAME the name of the source directory which contains FILENAME
3969 or NULL if not known.
3970 This routine tries to keep line numbers from identical absolute and
3971 relative file names in a common subfile.
3973 Using the `list' example from the GDB testsuite, which resides in
3974 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
3975 of /srcdir/list0.c yields the following debugging information for list0.c:
3977 DW_AT_name: /srcdir/list0.c
3978 DW_AT_comp_dir: /compdir
3979 files.files[0].name: list0.h
3980 files.files[0].dir: /srcdir
3981 files.files[1].name: list0.c
3982 files.files[1].dir: /srcdir
3984 The line number information for list0.c has to end up in a single
3985 subfile, so that `break /srcdir/list0.c:1' works as expected. */
3988 dwarf2_start_subfile (filename
, dirname
)
3992 /* If the filename isn't absolute, try to match an existing subfile
3993 with the full pathname. */
3995 if (*filename
!= '/' && dirname
!= NULL
)
3997 struct subfile
*subfile
;
3998 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4000 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4002 if (STREQ (subfile
->name
, fullname
))
4004 current_subfile
= subfile
;
4011 start_subfile (filename
, dirname
);
4014 /* Given a pointer to a DWARF information entry, figure out if we need
4015 to make a symbol table entry for it, and if so, create a new entry
4016 and return a pointer to it.
4017 If TYPE is NULL, determine symbol type from the die, otherwise
4018 used the passed type.
4021 static struct symbol
*
4022 new_symbol (die
, type
, objfile
)
4023 struct die_info
*die
;
4025 struct objfile
*objfile
;
4027 struct symbol
*sym
= NULL
;
4029 struct attribute
*attr
= NULL
;
4030 struct attribute
*attr2
= NULL
;
4033 name
= dwarf2_linkage_name (die
);
4036 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4037 sizeof (struct symbol
));
4038 OBJSTAT (objfile
, n_syms
++);
4039 memset (sym
, 0, sizeof (struct symbol
));
4040 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4041 &objfile
->symbol_obstack
);
4043 /* Default assumptions.
4044 Use the passed type or decode it from the die. */
4045 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4046 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4048 SYMBOL_TYPE (sym
) = type
;
4050 SYMBOL_TYPE (sym
) = die_type (die
, objfile
);
4051 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4054 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4057 /* If this symbol is from a C++ compilation, then attempt to
4058 cache the demangled form for future reference. This is a
4059 typical time versus space tradeoff, that was decided in favor
4060 of time because it sped up C++ symbol lookups by a factor of
4063 SYMBOL_LANGUAGE (sym
) = cu_language
;
4064 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4068 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4071 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4073 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4075 case DW_TAG_subprogram
:
4076 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4078 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4079 attr2
= dwarf_attr (die
, DW_AT_external
);
4080 if (attr2
&& (DW_UNSND (attr2
) != 0))
4082 add_symbol_to_list (sym
, &global_symbols
);
4086 add_symbol_to_list (sym
, list_in_scope
);
4089 case DW_TAG_variable
:
4090 /* Compilation with minimal debug info may result in variables
4091 with missing type entries. Change the misleading `void' type
4092 to something sensible. */
4093 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4094 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4095 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4096 "<variable, no debug info>",
4098 attr
= dwarf_attr (die
, DW_AT_const_value
);
4101 dwarf2_const_value (attr
, sym
, objfile
);
4102 attr2
= dwarf_attr (die
, DW_AT_external
);
4103 if (attr2
&& (DW_UNSND (attr2
) != 0))
4104 add_symbol_to_list (sym
, &global_symbols
);
4106 add_symbol_to_list (sym
, list_in_scope
);
4109 attr
= dwarf_attr (die
, DW_AT_location
);
4112 attr2
= dwarf_attr (die
, DW_AT_external
);
4113 if (attr2
&& (DW_UNSND (attr2
) != 0))
4115 SYMBOL_VALUE_ADDRESS (sym
) =
4116 decode_locdesc (DW_BLOCK (attr
), objfile
);
4117 add_symbol_to_list (sym
, &global_symbols
);
4119 /* In shared libraries the address of the variable
4120 in the location descriptor might still be relocatable,
4121 so its value could be zero.
4122 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4123 value is zero, the address of the variable will then
4124 be determined from the minimal symbol table whenever
4125 the variable is referenced. */
4126 if (SYMBOL_VALUE_ADDRESS (sym
))
4128 SYMBOL_VALUE_ADDRESS (sym
) += baseaddr
;
4129 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4132 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4136 SYMBOL_VALUE (sym
) = addr
=
4137 decode_locdesc (DW_BLOCK (attr
), objfile
);
4138 add_symbol_to_list (sym
, list_in_scope
);
4141 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4145 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4149 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4150 SYMBOL_BASEREG (sym
) = basereg
;
4154 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4158 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4159 SYMBOL_VALUE_ADDRESS (sym
) = addr
+ baseaddr
;
4165 /* We do not know the address of this symbol.
4166 If it is an external symbol and we have type information
4167 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4168 The address of the variable will then be determined from
4169 the minimal symbol table whenever the variable is
4171 attr2
= dwarf_attr (die
, DW_AT_external
);
4172 if (attr2
&& (DW_UNSND (attr2
) != 0)
4173 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4175 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4176 add_symbol_to_list (sym
, &global_symbols
);
4180 case DW_TAG_formal_parameter
:
4181 attr
= dwarf_attr (die
, DW_AT_location
);
4184 SYMBOL_VALUE (sym
) = decode_locdesc (DW_BLOCK (attr
), objfile
);
4187 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4191 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4192 SYMBOL_BASEREG (sym
) = basereg
;
4196 SYMBOL_CLASS (sym
) = LOC_ARG
;
4199 attr
= dwarf_attr (die
, DW_AT_const_value
);
4202 dwarf2_const_value (attr
, sym
, objfile
);
4204 add_symbol_to_list (sym
, list_in_scope
);
4206 case DW_TAG_unspecified_parameters
:
4207 /* From varargs functions; gdb doesn't seem to have any
4208 interest in this information, so just ignore it for now.
4211 case DW_TAG_class_type
:
4212 case DW_TAG_structure_type
:
4213 case DW_TAG_union_type
:
4214 case DW_TAG_enumeration_type
:
4215 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4216 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4217 add_symbol_to_list (sym
, list_in_scope
);
4219 /* The semantics of C++ state that "struct foo { ... }" also
4220 defines a typedef for "foo". Synthesize a typedef symbol so
4221 that "ptype foo" works as expected. */
4222 if (cu_language
== language_cplus
)
4224 struct symbol
*typedef_sym
= (struct symbol
*)
4225 obstack_alloc (&objfile
->symbol_obstack
,
4226 sizeof (struct symbol
));
4227 *typedef_sym
= *sym
;
4228 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4229 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4230 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4231 obsavestring (SYMBOL_NAME (sym
),
4232 strlen (SYMBOL_NAME (sym
)),
4233 &objfile
->type_obstack
);
4234 add_symbol_to_list (typedef_sym
, list_in_scope
);
4237 case DW_TAG_typedef
:
4238 case DW_TAG_base_type
:
4239 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4240 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4241 add_symbol_to_list (sym
, list_in_scope
);
4243 case DW_TAG_enumerator
:
4244 attr
= dwarf_attr (die
, DW_AT_const_value
);
4247 dwarf2_const_value (attr
, sym
, objfile
);
4249 add_symbol_to_list (sym
, list_in_scope
);
4252 /* Not a tag we recognize. Hopefully we aren't processing
4253 trash data, but since we must specifically ignore things
4254 we don't recognize, there is nothing else we should do at
4256 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4263 /* Copy constant value from an attribute to a symbol. */
4266 dwarf2_const_value (attr
, sym
, objfile
)
4267 struct attribute
*attr
;
4269 struct objfile
*objfile
;
4271 struct dwarf_block
*blk
;
4276 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != (unsigned int) address_size
)
4277 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4278 address_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4279 SYMBOL_VALUE_BYTES (sym
) = (char *)
4280 obstack_alloc (&objfile
->symbol_obstack
, address_size
);
4281 store_address (SYMBOL_VALUE_BYTES (sym
), address_size
, DW_ADDR (attr
));
4282 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4284 case DW_FORM_block1
:
4285 case DW_FORM_block2
:
4286 case DW_FORM_block4
:
4288 blk
= DW_BLOCK (attr
);
4289 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4290 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4291 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4292 SYMBOL_VALUE_BYTES (sym
) = (char *)
4293 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4294 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4295 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4303 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4304 SYMBOL_CLASS (sym
) = LOC_CONST
;
4307 complain (&dwarf2_unsupported_const_value_attr
,
4308 dwarf_form_name (attr
->form
));
4309 SYMBOL_VALUE (sym
) = 0;
4310 SYMBOL_CLASS (sym
) = LOC_CONST
;
4315 /* Return the type of the die in question using its DW_AT_type attribute. */
4317 static struct type
*
4318 die_type (die
, objfile
)
4319 struct die_info
*die
;
4320 struct objfile
*objfile
;
4323 struct attribute
*type_attr
;
4324 struct die_info
*type_die
;
4327 type_attr
= dwarf_attr (die
, DW_AT_type
);
4330 /* A missing DW_AT_type represents a void type. */
4331 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4335 ref
= dwarf2_get_ref_die_offset (type_attr
);
4336 type_die
= follow_die_ref (ref
);
4339 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4343 type
= tag_type_to_type (type_die
, objfile
);
4346 dump_die (type_die
);
4347 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4352 /* Return the containing type of the die in question using its
4353 DW_AT_containing_type attribute. */
4355 static struct type
*
4356 die_containing_type (die
, objfile
)
4357 struct die_info
*die
;
4358 struct objfile
*objfile
;
4360 struct type
*type
= NULL
;
4361 struct attribute
*type_attr
;
4362 struct die_info
*type_die
= NULL
;
4365 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4368 ref
= dwarf2_get_ref_die_offset (type_attr
);
4369 type_die
= follow_die_ref (ref
);
4372 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4375 type
= tag_type_to_type (type_die
, objfile
);
4380 dump_die (type_die
);
4381 error ("Dwarf Error: Problem turning containing type into gdb type.");
4387 static struct type
*
4388 type_at_offset (offset
, objfile
)
4389 unsigned int offset
;
4390 struct objfile
*objfile
;
4392 struct die_info
*die
;
4395 die
= follow_die_ref (offset
);
4398 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4401 type
= tag_type_to_type (die
, objfile
);
4406 static struct type
*
4407 tag_type_to_type (die
, objfile
)
4408 struct die_info
*die
;
4409 struct objfile
*objfile
;
4417 read_type_die (die
, objfile
);
4421 error ("Dwarf Error: Cannot find type of die.");
4428 read_type_die (die
, objfile
)
4429 struct die_info
*die
;
4430 struct objfile
*objfile
;
4434 case DW_TAG_class_type
:
4435 case DW_TAG_structure_type
:
4436 case DW_TAG_union_type
:
4437 read_structure_scope (die
, objfile
);
4439 case DW_TAG_enumeration_type
:
4440 read_enumeration (die
, objfile
);
4442 case DW_TAG_subprogram
:
4443 case DW_TAG_subroutine_type
:
4444 read_subroutine_type (die
, objfile
);
4446 case DW_TAG_array_type
:
4447 read_array_type (die
, objfile
);
4449 case DW_TAG_pointer_type
:
4450 read_tag_pointer_type (die
, objfile
);
4452 case DW_TAG_ptr_to_member_type
:
4453 read_tag_ptr_to_member_type (die
, objfile
);
4455 case DW_TAG_reference_type
:
4456 read_tag_reference_type (die
, objfile
);
4458 case DW_TAG_const_type
:
4459 read_tag_const_type (die
, objfile
);
4461 case DW_TAG_volatile_type
:
4462 read_tag_volatile_type (die
, objfile
);
4464 case DW_TAG_string_type
:
4465 read_tag_string_type (die
, objfile
);
4467 case DW_TAG_typedef
:
4468 read_typedef (die
, objfile
);
4470 case DW_TAG_base_type
:
4471 read_base_type (die
, objfile
);
4474 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4479 static struct type
*
4480 dwarf_base_type (encoding
, size
, objfile
)
4483 struct objfile
*objfile
;
4485 /* FIXME - this should not produce a new (struct type *)
4486 every time. It should cache base types. */
4490 case DW_ATE_address
:
4491 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4493 case DW_ATE_boolean
:
4494 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4496 case DW_ATE_complex_float
:
4499 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4503 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4509 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4513 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4520 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4523 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4527 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4531 case DW_ATE_signed_char
:
4532 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4534 case DW_ATE_unsigned
:
4538 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4541 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4545 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4549 case DW_ATE_unsigned_char
:
4550 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4553 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4561 struct die_info
*old_die
;
4563 struct die_info
*new_die
;
4566 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4567 memset (new_die
, 0, sizeof (struct die_info
));
4569 new_die
->tag
= old_die
->tag
;
4570 new_die
->has_children
= old_die
->has_children
;
4571 new_die
->abbrev
= old_die
->abbrev
;
4572 new_die
->offset
= old_die
->offset
;
4573 new_die
->type
= NULL
;
4575 num_attrs
= old_die
->num_attrs
;
4576 new_die
->num_attrs
= num_attrs
;
4577 new_die
->attrs
= (struct attribute
*)
4578 xmalloc (num_attrs
* sizeof (struct attribute
));
4580 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4582 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4583 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4584 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4587 new_die
->next
= NULL
;
4592 /* Return sibling of die, NULL if no sibling. */
4596 struct die_info
*die
;
4598 int nesting_level
= 0;
4600 if (!die
->has_children
)
4602 if (die
->next
&& (die
->next
->tag
== 0))
4615 if (die
->has_children
)
4625 while (nesting_level
);
4626 if (die
&& (die
->tag
== 0))
4637 /* Get linkage name of a die, return NULL if not found. */
4640 dwarf2_linkage_name (die
)
4641 struct die_info
*die
;
4643 struct attribute
*attr
;
4645 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4646 if (attr
&& DW_STRING (attr
))
4647 return DW_STRING (attr
);
4648 attr
= dwarf_attr (die
, DW_AT_name
);
4649 if (attr
&& DW_STRING (attr
))
4650 return DW_STRING (attr
);
4654 /* Convert a DIE tag into its string name. */
4657 dwarf_tag_name (tag
)
4658 register unsigned tag
;
4662 case DW_TAG_padding
:
4663 return "DW_TAG_padding";
4664 case DW_TAG_array_type
:
4665 return "DW_TAG_array_type";
4666 case DW_TAG_class_type
:
4667 return "DW_TAG_class_type";
4668 case DW_TAG_entry_point
:
4669 return "DW_TAG_entry_point";
4670 case DW_TAG_enumeration_type
:
4671 return "DW_TAG_enumeration_type";
4672 case DW_TAG_formal_parameter
:
4673 return "DW_TAG_formal_parameter";
4674 case DW_TAG_imported_declaration
:
4675 return "DW_TAG_imported_declaration";
4677 return "DW_TAG_label";
4678 case DW_TAG_lexical_block
:
4679 return "DW_TAG_lexical_block";
4681 return "DW_TAG_member";
4682 case DW_TAG_pointer_type
:
4683 return "DW_TAG_pointer_type";
4684 case DW_TAG_reference_type
:
4685 return "DW_TAG_reference_type";
4686 case DW_TAG_compile_unit
:
4687 return "DW_TAG_compile_unit";
4688 case DW_TAG_string_type
:
4689 return "DW_TAG_string_type";
4690 case DW_TAG_structure_type
:
4691 return "DW_TAG_structure_type";
4692 case DW_TAG_subroutine_type
:
4693 return "DW_TAG_subroutine_type";
4694 case DW_TAG_typedef
:
4695 return "DW_TAG_typedef";
4696 case DW_TAG_union_type
:
4697 return "DW_TAG_union_type";
4698 case DW_TAG_unspecified_parameters
:
4699 return "DW_TAG_unspecified_parameters";
4700 case DW_TAG_variant
:
4701 return "DW_TAG_variant";
4702 case DW_TAG_common_block
:
4703 return "DW_TAG_common_block";
4704 case DW_TAG_common_inclusion
:
4705 return "DW_TAG_common_inclusion";
4706 case DW_TAG_inheritance
:
4707 return "DW_TAG_inheritance";
4708 case DW_TAG_inlined_subroutine
:
4709 return "DW_TAG_inlined_subroutine";
4711 return "DW_TAG_module";
4712 case DW_TAG_ptr_to_member_type
:
4713 return "DW_TAG_ptr_to_member_type";
4714 case DW_TAG_set_type
:
4715 return "DW_TAG_set_type";
4716 case DW_TAG_subrange_type
:
4717 return "DW_TAG_subrange_type";
4718 case DW_TAG_with_stmt
:
4719 return "DW_TAG_with_stmt";
4720 case DW_TAG_access_declaration
:
4721 return "DW_TAG_access_declaration";
4722 case DW_TAG_base_type
:
4723 return "DW_TAG_base_type";
4724 case DW_TAG_catch_block
:
4725 return "DW_TAG_catch_block";
4726 case DW_TAG_const_type
:
4727 return "DW_TAG_const_type";
4728 case DW_TAG_constant
:
4729 return "DW_TAG_constant";
4730 case DW_TAG_enumerator
:
4731 return "DW_TAG_enumerator";
4732 case DW_TAG_file_type
:
4733 return "DW_TAG_file_type";
4735 return "DW_TAG_friend";
4736 case DW_TAG_namelist
:
4737 return "DW_TAG_namelist";
4738 case DW_TAG_namelist_item
:
4739 return "DW_TAG_namelist_item";
4740 case DW_TAG_packed_type
:
4741 return "DW_TAG_packed_type";
4742 case DW_TAG_subprogram
:
4743 return "DW_TAG_subprogram";
4744 case DW_TAG_template_type_param
:
4745 return "DW_TAG_template_type_param";
4746 case DW_TAG_template_value_param
:
4747 return "DW_TAG_template_value_param";
4748 case DW_TAG_thrown_type
:
4749 return "DW_TAG_thrown_type";
4750 case DW_TAG_try_block
:
4751 return "DW_TAG_try_block";
4752 case DW_TAG_variant_part
:
4753 return "DW_TAG_variant_part";
4754 case DW_TAG_variable
:
4755 return "DW_TAG_variable";
4756 case DW_TAG_volatile_type
:
4757 return "DW_TAG_volatile_type";
4758 case DW_TAG_MIPS_loop
:
4759 return "DW_TAG_MIPS_loop";
4760 case DW_TAG_format_label
:
4761 return "DW_TAG_format_label";
4762 case DW_TAG_function_template
:
4763 return "DW_TAG_function_template";
4764 case DW_TAG_class_template
:
4765 return "DW_TAG_class_template";
4767 return "DW_TAG_<unknown>";
4771 /* Convert a DWARF attribute code into its string name. */
4774 dwarf_attr_name (attr
)
4775 register unsigned attr
;
4780 return "DW_AT_sibling";
4781 case DW_AT_location
:
4782 return "DW_AT_location";
4784 return "DW_AT_name";
4785 case DW_AT_ordering
:
4786 return "DW_AT_ordering";
4787 case DW_AT_subscr_data
:
4788 return "DW_AT_subscr_data";
4789 case DW_AT_byte_size
:
4790 return "DW_AT_byte_size";
4791 case DW_AT_bit_offset
:
4792 return "DW_AT_bit_offset";
4793 case DW_AT_bit_size
:
4794 return "DW_AT_bit_size";
4795 case DW_AT_element_list
:
4796 return "DW_AT_element_list";
4797 case DW_AT_stmt_list
:
4798 return "DW_AT_stmt_list";
4800 return "DW_AT_low_pc";
4802 return "DW_AT_high_pc";
4803 case DW_AT_language
:
4804 return "DW_AT_language";
4806 return "DW_AT_member";
4808 return "DW_AT_discr";
4809 case DW_AT_discr_value
:
4810 return "DW_AT_discr_value";
4811 case DW_AT_visibility
:
4812 return "DW_AT_visibility";
4814 return "DW_AT_import";
4815 case DW_AT_string_length
:
4816 return "DW_AT_string_length";
4817 case DW_AT_common_reference
:
4818 return "DW_AT_common_reference";
4819 case DW_AT_comp_dir
:
4820 return "DW_AT_comp_dir";
4821 case DW_AT_const_value
:
4822 return "DW_AT_const_value";
4823 case DW_AT_containing_type
:
4824 return "DW_AT_containing_type";
4825 case DW_AT_default_value
:
4826 return "DW_AT_default_value";
4828 return "DW_AT_inline";
4829 case DW_AT_is_optional
:
4830 return "DW_AT_is_optional";
4831 case DW_AT_lower_bound
:
4832 return "DW_AT_lower_bound";
4833 case DW_AT_producer
:
4834 return "DW_AT_producer";
4835 case DW_AT_prototyped
:
4836 return "DW_AT_prototyped";
4837 case DW_AT_return_addr
:
4838 return "DW_AT_return_addr";
4839 case DW_AT_start_scope
:
4840 return "DW_AT_start_scope";
4841 case DW_AT_stride_size
:
4842 return "DW_AT_stride_size";
4843 case DW_AT_upper_bound
:
4844 return "DW_AT_upper_bound";
4845 case DW_AT_abstract_origin
:
4846 return "DW_AT_abstract_origin";
4847 case DW_AT_accessibility
:
4848 return "DW_AT_accessibility";
4849 case DW_AT_address_class
:
4850 return "DW_AT_address_class";
4851 case DW_AT_artificial
:
4852 return "DW_AT_artificial";
4853 case DW_AT_base_types
:
4854 return "DW_AT_base_types";
4855 case DW_AT_calling_convention
:
4856 return "DW_AT_calling_convention";
4858 return "DW_AT_count";
4859 case DW_AT_data_member_location
:
4860 return "DW_AT_data_member_location";
4861 case DW_AT_decl_column
:
4862 return "DW_AT_decl_column";
4863 case DW_AT_decl_file
:
4864 return "DW_AT_decl_file";
4865 case DW_AT_decl_line
:
4866 return "DW_AT_decl_line";
4867 case DW_AT_declaration
:
4868 return "DW_AT_declaration";
4869 case DW_AT_discr_list
:
4870 return "DW_AT_discr_list";
4871 case DW_AT_encoding
:
4872 return "DW_AT_encoding";
4873 case DW_AT_external
:
4874 return "DW_AT_external";
4875 case DW_AT_frame_base
:
4876 return "DW_AT_frame_base";
4878 return "DW_AT_friend";
4879 case DW_AT_identifier_case
:
4880 return "DW_AT_identifier_case";
4881 case DW_AT_macro_info
:
4882 return "DW_AT_macro_info";
4883 case DW_AT_namelist_items
:
4884 return "DW_AT_namelist_items";
4885 case DW_AT_priority
:
4886 return "DW_AT_priority";
4888 return "DW_AT_segment";
4889 case DW_AT_specification
:
4890 return "DW_AT_specification";
4891 case DW_AT_static_link
:
4892 return "DW_AT_static_link";
4894 return "DW_AT_type";
4895 case DW_AT_use_location
:
4896 return "DW_AT_use_location";
4897 case DW_AT_variable_parameter
:
4898 return "DW_AT_variable_parameter";
4899 case DW_AT_virtuality
:
4900 return "DW_AT_virtuality";
4901 case DW_AT_vtable_elem_location
:
4902 return "DW_AT_vtable_elem_location";
4905 case DW_AT_MIPS_fde
:
4906 return "DW_AT_MIPS_fde";
4907 case DW_AT_MIPS_loop_begin
:
4908 return "DW_AT_MIPS_loop_begin";
4909 case DW_AT_MIPS_tail_loop_begin
:
4910 return "DW_AT_MIPS_tail_loop_begin";
4911 case DW_AT_MIPS_epilog_begin
:
4912 return "DW_AT_MIPS_epilog_begin";
4913 case DW_AT_MIPS_loop_unroll_factor
:
4914 return "DW_AT_MIPS_loop_unroll_factor";
4915 case DW_AT_MIPS_software_pipeline_depth
:
4916 return "DW_AT_MIPS_software_pipeline_depth";
4917 case DW_AT_MIPS_linkage_name
:
4918 return "DW_AT_MIPS_linkage_name";
4921 case DW_AT_sf_names
:
4922 return "DW_AT_sf_names";
4923 case DW_AT_src_info
:
4924 return "DW_AT_src_info";
4925 case DW_AT_mac_info
:
4926 return "DW_AT_mac_info";
4927 case DW_AT_src_coords
:
4928 return "DW_AT_src_coords";
4929 case DW_AT_body_begin
:
4930 return "DW_AT_body_begin";
4931 case DW_AT_body_end
:
4932 return "DW_AT_body_end";
4934 return "DW_AT_<unknown>";
4938 /* Convert a DWARF value form code into its string name. */
4941 dwarf_form_name (form
)
4942 register unsigned form
;
4947 return "DW_FORM_addr";
4948 case DW_FORM_block2
:
4949 return "DW_FORM_block2";
4950 case DW_FORM_block4
:
4951 return "DW_FORM_block4";
4953 return "DW_FORM_data2";
4955 return "DW_FORM_data4";
4957 return "DW_FORM_data8";
4958 case DW_FORM_string
:
4959 return "DW_FORM_string";
4961 return "DW_FORM_block";
4962 case DW_FORM_block1
:
4963 return "DW_FORM_block1";
4965 return "DW_FORM_data1";
4967 return "DW_FORM_flag";
4969 return "DW_FORM_sdata";
4971 return "DW_FORM_strp";
4973 return "DW_FORM_udata";
4974 case DW_FORM_ref_addr
:
4975 return "DW_FORM_ref_addr";
4977 return "DW_FORM_ref1";
4979 return "DW_FORM_ref2";
4981 return "DW_FORM_ref4";
4983 return "DW_FORM_ref8";
4984 case DW_FORM_ref_udata
:
4985 return "DW_FORM_ref_udata";
4986 case DW_FORM_indirect
:
4987 return "DW_FORM_indirect";
4989 return "DW_FORM_<unknown>";
4993 /* Convert a DWARF stack opcode into its string name. */
4996 dwarf_stack_op_name (op
)
4997 register unsigned op
;
5002 return "DW_OP_addr";
5004 return "DW_OP_deref";
5006 return "DW_OP_const1u";
5008 return "DW_OP_const1s";
5010 return "DW_OP_const2u";
5012 return "DW_OP_const2s";
5014 return "DW_OP_const4u";
5016 return "DW_OP_const4s";
5018 return "DW_OP_const8u";
5020 return "DW_OP_const8s";
5022 return "DW_OP_constu";
5024 return "DW_OP_consts";
5028 return "DW_OP_drop";
5030 return "DW_OP_over";
5032 return "DW_OP_pick";
5034 return "DW_OP_swap";
5038 return "DW_OP_xderef";
5046 return "DW_OP_minus";
5058 return "DW_OP_plus";
5059 case DW_OP_plus_uconst
:
5060 return "DW_OP_plus_uconst";
5066 return "DW_OP_shra";
5084 return "DW_OP_skip";
5086 return "DW_OP_lit0";
5088 return "DW_OP_lit1";
5090 return "DW_OP_lit2";
5092 return "DW_OP_lit3";
5094 return "DW_OP_lit4";
5096 return "DW_OP_lit5";
5098 return "DW_OP_lit6";
5100 return "DW_OP_lit7";
5102 return "DW_OP_lit8";
5104 return "DW_OP_lit9";
5106 return "DW_OP_lit10";
5108 return "DW_OP_lit11";
5110 return "DW_OP_lit12";
5112 return "DW_OP_lit13";
5114 return "DW_OP_lit14";
5116 return "DW_OP_lit15";
5118 return "DW_OP_lit16";
5120 return "DW_OP_lit17";
5122 return "DW_OP_lit18";
5124 return "DW_OP_lit19";
5126 return "DW_OP_lit20";
5128 return "DW_OP_lit21";
5130 return "DW_OP_lit22";
5132 return "DW_OP_lit23";
5134 return "DW_OP_lit24";
5136 return "DW_OP_lit25";
5138 return "DW_OP_lit26";
5140 return "DW_OP_lit27";
5142 return "DW_OP_lit28";
5144 return "DW_OP_lit29";
5146 return "DW_OP_lit30";
5148 return "DW_OP_lit31";
5150 return "DW_OP_reg0";
5152 return "DW_OP_reg1";
5154 return "DW_OP_reg2";
5156 return "DW_OP_reg3";
5158 return "DW_OP_reg4";
5160 return "DW_OP_reg5";
5162 return "DW_OP_reg6";
5164 return "DW_OP_reg7";
5166 return "DW_OP_reg8";
5168 return "DW_OP_reg9";
5170 return "DW_OP_reg10";
5172 return "DW_OP_reg11";
5174 return "DW_OP_reg12";
5176 return "DW_OP_reg13";
5178 return "DW_OP_reg14";
5180 return "DW_OP_reg15";
5182 return "DW_OP_reg16";
5184 return "DW_OP_reg17";
5186 return "DW_OP_reg18";
5188 return "DW_OP_reg19";
5190 return "DW_OP_reg20";
5192 return "DW_OP_reg21";
5194 return "DW_OP_reg22";
5196 return "DW_OP_reg23";
5198 return "DW_OP_reg24";
5200 return "DW_OP_reg25";
5202 return "DW_OP_reg26";
5204 return "DW_OP_reg27";
5206 return "DW_OP_reg28";
5208 return "DW_OP_reg29";
5210 return "DW_OP_reg30";
5212 return "DW_OP_reg31";
5214 return "DW_OP_breg0";
5216 return "DW_OP_breg1";
5218 return "DW_OP_breg2";
5220 return "DW_OP_breg3";
5222 return "DW_OP_breg4";
5224 return "DW_OP_breg5";
5226 return "DW_OP_breg6";
5228 return "DW_OP_breg7";
5230 return "DW_OP_breg8";
5232 return "DW_OP_breg9";
5234 return "DW_OP_breg10";
5236 return "DW_OP_breg11";
5238 return "DW_OP_breg12";
5240 return "DW_OP_breg13";
5242 return "DW_OP_breg14";
5244 return "DW_OP_breg15";
5246 return "DW_OP_breg16";
5248 return "DW_OP_breg17";
5250 return "DW_OP_breg18";
5252 return "DW_OP_breg19";
5254 return "DW_OP_breg20";
5256 return "DW_OP_breg21";
5258 return "DW_OP_breg22";
5260 return "DW_OP_breg23";
5262 return "DW_OP_breg24";
5264 return "DW_OP_breg25";
5266 return "DW_OP_breg26";
5268 return "DW_OP_breg27";
5270 return "DW_OP_breg28";
5272 return "DW_OP_breg29";
5274 return "DW_OP_breg30";
5276 return "DW_OP_breg31";
5278 return "DW_OP_regx";
5280 return "DW_OP_fbreg";
5282 return "DW_OP_bregx";
5284 return "DW_OP_piece";
5285 case DW_OP_deref_size
:
5286 return "DW_OP_deref_size";
5287 case DW_OP_xderef_size
:
5288 return "DW_OP_xderef_size";
5292 return "OP_<unknown>";
5297 dwarf_bool_name (bool)
5306 /* Convert a DWARF type code into its string name. */
5309 dwarf_type_encoding_name (enc
)
5310 register unsigned enc
;
5314 case DW_ATE_address
:
5315 return "DW_ATE_address";
5316 case DW_ATE_boolean
:
5317 return "DW_ATE_boolean";
5318 case DW_ATE_complex_float
:
5319 return "DW_ATE_complex_float";
5321 return "DW_ATE_float";
5323 return "DW_ATE_signed";
5324 case DW_ATE_signed_char
:
5325 return "DW_ATE_signed_char";
5326 case DW_ATE_unsigned
:
5327 return "DW_ATE_unsigned";
5328 case DW_ATE_unsigned_char
:
5329 return "DW_ATE_unsigned_char";
5331 return "DW_ATE_<unknown>";
5335 /* Convert a DWARF call frame info operation to its string name. */
5339 dwarf_cfi_name (cfi_opc
)
5340 register unsigned cfi_opc
;
5344 case DW_CFA_advance_loc
:
5345 return "DW_CFA_advance_loc";
5347 return "DW_CFA_offset";
5348 case DW_CFA_restore
:
5349 return "DW_CFA_restore";
5351 return "DW_CFA_nop";
5352 case DW_CFA_set_loc
:
5353 return "DW_CFA_set_loc";
5354 case DW_CFA_advance_loc1
:
5355 return "DW_CFA_advance_loc1";
5356 case DW_CFA_advance_loc2
:
5357 return "DW_CFA_advance_loc2";
5358 case DW_CFA_advance_loc4
:
5359 return "DW_CFA_advance_loc4";
5360 case DW_CFA_offset_extended
:
5361 return "DW_CFA_offset_extended";
5362 case DW_CFA_restore_extended
:
5363 return "DW_CFA_restore_extended";
5364 case DW_CFA_undefined
:
5365 return "DW_CFA_undefined";
5366 case DW_CFA_same_value
:
5367 return "DW_CFA_same_value";
5368 case DW_CFA_register
:
5369 return "DW_CFA_register";
5370 case DW_CFA_remember_state
:
5371 return "DW_CFA_remember_state";
5372 case DW_CFA_restore_state
:
5373 return "DW_CFA_restore_state";
5374 case DW_CFA_def_cfa
:
5375 return "DW_CFA_def_cfa";
5376 case DW_CFA_def_cfa_register
:
5377 return "DW_CFA_def_cfa_register";
5378 case DW_CFA_def_cfa_offset
:
5379 return "DW_CFA_def_cfa_offset";
5380 /* SGI/MIPS specific */
5381 case DW_CFA_MIPS_advance_loc8
:
5382 return "DW_CFA_MIPS_advance_loc8";
5384 return "DW_CFA_<unknown>";
5391 struct die_info
*die
;
5395 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5396 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5397 fprintf (stderr
, "\thas children: %s\n",
5398 dwarf_bool_name (die
->has_children
));
5400 fprintf (stderr
, "\tattributes:\n");
5401 for (i
= 0; i
< die
->num_attrs
; ++i
)
5403 fprintf (stderr
, "\t\t%s (%s) ",
5404 dwarf_attr_name (die
->attrs
[i
].name
),
5405 dwarf_form_name (die
->attrs
[i
].form
));
5406 switch (die
->attrs
[i
].form
)
5408 case DW_FORM_ref_addr
:
5410 fprintf (stderr
, "address: ");
5411 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, stderr
);
5413 case DW_FORM_block2
:
5414 case DW_FORM_block4
:
5416 case DW_FORM_block1
:
5417 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5427 fprintf (stderr
, "constant: %d", DW_UNSND (&die
->attrs
[i
]));
5429 case DW_FORM_string
:
5430 fprintf (stderr
, "string: \"%s\"",
5431 DW_STRING (&die
->attrs
[i
])
5432 ? DW_STRING (&die
->attrs
[i
]) : "");
5435 if (DW_UNSND (&die
->attrs
[i
]))
5436 fprintf (stderr
, "flag: TRUE");
5438 fprintf (stderr
, "flag: FALSE");
5440 case DW_FORM_strp
: /* we do not support separate string
5442 case DW_FORM_indirect
: /* we do not handle indirect yet */
5443 case DW_FORM_data8
: /* we do not have 64 bit quantities */
5445 fprintf (stderr
, "unsupported attribute form: %d.",
5446 die
->attrs
[i
].form
);
5448 fprintf (stderr
, "\n");
5454 struct die_info
*die
;
5464 store_in_ref_table (offset
, die
)
5465 unsigned int offset
;
5466 struct die_info
*die
;
5469 struct die_info
*old
;
5471 h
= (offset
% REF_HASH_SIZE
);
5472 old
= die_ref_table
[h
];
5473 die
->next_ref
= old
;
5474 die_ref_table
[h
] = die
;
5479 dwarf2_empty_die_ref_table ()
5481 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5485 dwarf2_get_ref_die_offset (attr
)
5486 struct attribute
*attr
;
5488 unsigned int result
= 0;
5492 case DW_FORM_ref_addr
:
5493 result
= DW_ADDR (attr
);
5498 case DW_FORM_ref_udata
:
5499 result
= cu_header_offset
+ DW_UNSND (attr
);
5502 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5508 follow_die_ref (offset
)
5509 unsigned int offset
;
5511 struct die_info
*die
;
5514 h
= (offset
% REF_HASH_SIZE
);
5515 die
= die_ref_table
[h
];
5518 if (die
->offset
== offset
)
5522 die
= die
->next_ref
;
5527 static struct type
*
5528 dwarf2_fundamental_type (objfile
, typeid)
5529 struct objfile
*objfile
;
5532 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5534 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5538 /* Look for this particular type in the fundamental type vector. If
5539 one is not found, create and install one appropriate for the
5540 current language and the current target machine. */
5542 if (ftypes
[typeid] == NULL
)
5544 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5547 return (ftypes
[typeid]);
5550 /* Decode simple location descriptions.
5551 Given a pointer to a dwarf block that defines a location, compute
5552 the location and return the value.
5554 FIXME: This is a kludge until we figure out a better
5555 way to handle the location descriptions.
5556 Gdb's design does not mesh well with the DWARF2 notion of a location
5557 computing interpreter, which is a shame because the flexibility goes unused.
5558 FIXME: Implement more operations as necessary.
5560 A location description containing no operations indicates that the
5561 object is optimized out. The global optimized_out flag is set for
5562 those, the return value is meaningless.
5564 When the result is a register number, the global isreg flag is set,
5565 otherwise it is cleared.
5567 When the result is a base register offset, the global offreg flag is set
5568 and the register number is returned in basereg, otherwise it is cleared.
5570 When the DW_OP_fbreg operation is encountered without a corresponding
5571 DW_AT_frame_base attribute, the global islocal flag is set.
5572 Hopefully the machine dependent code knows how to set up a virtual
5573 frame pointer for the local references.
5575 Note that stack[0] is unused except as a default error return.
5576 Note that stack overflow is not yet handled. */
5579 decode_locdesc (blk
, objfile
)
5580 struct dwarf_block
*blk
;
5581 struct objfile
*objfile
;
5584 int size
= blk
->size
;
5585 char *data
= blk
->data
;
5586 CORE_ADDR stack
[64];
5588 unsigned int bytes_read
, unsnd
;
5638 stack
[++stacki
] = op
- DW_OP_reg0
;
5643 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5645 #if defined(HARRIS_TARGET) && defined(_M88K)
5646 /* The Harris 88110 gdb ports have long kept their special reg
5647 numbers between their gp-regs and their x-regs. This is
5648 not how our dwarf is generated. Punt. */
5651 stack
[++stacki
] = unsnd
;
5687 basereg
= op
- DW_OP_breg0
;
5688 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5693 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5695 if (frame_base_reg
>= 0)
5698 basereg
= frame_base_reg
;
5699 stack
[stacki
] += frame_base_offset
;
5703 complain (&dwarf2_missing_at_frame_base
);
5709 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
]);
5714 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5719 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5724 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5729 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5734 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5739 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5744 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5750 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5755 stack
[stacki
- 1] += stack
[stacki
];
5759 case DW_OP_plus_uconst
:
5760 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5765 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5770 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name(op
));
5771 return (stack
[stacki
]);
5774 return (stack
[stacki
]);
5777 /* memory allocation interface */
5781 dwarf2_free_tmp_obstack (ignore
)
5784 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5787 static struct dwarf_block
*
5788 dwarf_alloc_block ()
5790 struct dwarf_block
*blk
;
5792 blk
= (struct dwarf_block
*)
5793 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5797 static struct abbrev_info
*
5798 dwarf_alloc_abbrev ()
5800 struct abbrev_info
*abbrev
;
5802 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5803 memset (abbrev
, 0, sizeof (struct abbrev_info
));
5807 static struct die_info
*
5810 struct die_info
*die
;
5812 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5813 memset (die
, 0, sizeof (struct die_info
));