1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
10 support in dwarfread.c
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or (at
17 your option) any later version.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. */
35 #include "elf/dwarf2.h"
38 #include "expression.h"
39 #include "filenames.h" /* for DOSish file names */
42 #include "complaints.h"
45 #include "gdb_string.h"
46 #include "gdb_assert.h"
47 #include <sys/types.h>
49 #ifndef DWARF2_REG_TO_REGNUM
50 #define DWARF2_REG_TO_REGNUM(REG) (REG)
54 /* .debug_info header for a compilation unit
55 Because of alignment constraints, this structure has padding and cannot
56 be mapped directly onto the beginning of the .debug_info section. */
57 typedef struct comp_unit_header
59 unsigned int length
; /* length of the .debug_info
61 unsigned short version
; /* version number -- 2 for DWARF
63 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
64 unsigned char addr_size
; /* byte size of an address -- 4 */
67 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
70 /* .debug_pubnames header
71 Because of alignment constraints, this structure has padding and cannot
72 be mapped directly onto the beginning of the .debug_info section. */
73 typedef struct pubnames_header
75 unsigned int length
; /* length of the .debug_pubnames
77 unsigned char version
; /* version number -- 2 for DWARF
79 unsigned int info_offset
; /* offset into .debug_info section */
80 unsigned int info_size
; /* byte size of .debug_info section
84 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
86 /* .debug_pubnames header
87 Because of alignment constraints, this structure has padding and cannot
88 be mapped directly onto the beginning of the .debug_info section. */
89 typedef struct aranges_header
91 unsigned int length
; /* byte len of the .debug_aranges
93 unsigned short version
; /* version number -- 2 for DWARF
95 unsigned int info_offset
; /* offset into .debug_info section */
96 unsigned char addr_size
; /* byte size of an address */
97 unsigned char seg_size
; /* byte size of segment descriptor */
100 #define _ACTUAL_ARANGES_HEADER_SIZE 12
102 /* .debug_line statement program prologue
103 Because of alignment constraints, this structure has padding and cannot
104 be mapped directly onto the beginning of the .debug_info section. */
105 typedef struct statement_prologue
107 unsigned int total_length
; /* byte length of the statement
109 unsigned short version
; /* version number -- 2 for DWARF
111 unsigned int prologue_length
; /* # bytes between prologue &
113 unsigned char minimum_instruction_length
; /* byte size of
115 unsigned char default_is_stmt
; /* initial value of is_stmt
118 unsigned char line_range
;
119 unsigned char opcode_base
; /* number assigned to first special
121 unsigned char *standard_opcode_lengths
;
125 /* offsets and sizes of debugging sections */
127 static file_ptr dwarf_info_offset
;
128 static file_ptr dwarf_abbrev_offset
;
129 static file_ptr dwarf_line_offset
;
130 static file_ptr dwarf_pubnames_offset
;
131 static file_ptr dwarf_aranges_offset
;
132 static file_ptr dwarf_loc_offset
;
133 static file_ptr dwarf_macinfo_offset
;
134 static file_ptr dwarf_str_offset
;
135 file_ptr dwarf_frame_offset
;
136 file_ptr dwarf_eh_frame_offset
;
138 static unsigned int dwarf_info_size
;
139 static unsigned int dwarf_abbrev_size
;
140 static unsigned int dwarf_line_size
;
141 static unsigned int dwarf_pubnames_size
;
142 static unsigned int dwarf_aranges_size
;
143 static unsigned int dwarf_loc_size
;
144 static unsigned int dwarf_macinfo_size
;
145 static unsigned int dwarf_str_size
;
146 unsigned int dwarf_frame_size
;
147 unsigned int dwarf_eh_frame_size
;
149 /* names of the debugging sections */
151 #define INFO_SECTION ".debug_info"
152 #define ABBREV_SECTION ".debug_abbrev"
153 #define LINE_SECTION ".debug_line"
154 #define PUBNAMES_SECTION ".debug_pubnames"
155 #define ARANGES_SECTION ".debug_aranges"
156 #define LOC_SECTION ".debug_loc"
157 #define MACINFO_SECTION ".debug_macinfo"
158 #define STR_SECTION ".debug_str"
159 #define FRAME_SECTION ".debug_frame"
160 #define EH_FRAME_SECTION ".eh_frame"
162 /* local data types */
164 /* The data in a compilation unit header, after target2host
165 translation, looks like this. */
166 struct comp_unit_head
168 unsigned long length
;
170 unsigned int abbrev_offset
;
171 unsigned char addr_size
;
172 unsigned char signed_addr_p
;
173 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
174 unsigned int initial_length_size
; /* size of the length field; either
178 /* The line number information for a compilation unit (found in the
179 .debug_line section) begins with a "statement program header",
180 which contains the following information. */
183 unsigned int total_length
;
184 unsigned short version
;
185 unsigned int header_length
;
186 unsigned char minimum_instruction_length
;
187 unsigned char default_is_stmt
;
189 unsigned char line_range
;
190 unsigned char opcode_base
;
192 /* standard_opcode_lengths[i] is the number of operands for the
193 standard opcode whose value is i. This means that
194 standard_opcode_lengths[0] is unused, and the last meaningful
195 element is standard_opcode_lengths[opcode_base - 1]. */
196 unsigned char *standard_opcode_lengths
;
198 /* The include_directories table. NOTE! These strings are not
199 allocated with xmalloc; instead, they are pointers into
200 debug_line_buffer. If you try to free them, `free' will get
202 unsigned int num_include_dirs
, include_dirs_size
;
205 /* The file_names table. NOTE! These strings are not allocated
206 with xmalloc; instead, they are pointers into debug_line_buffer.
207 Don't try to free them directly. */
208 unsigned int num_file_names
, file_names_size
;
212 unsigned int dir_index
;
213 unsigned int mod_time
;
217 /* The start and end of the statement program following this
218 header. These point into dwarf_line_buffer. */
219 char *statement_program_start
, *statement_program_end
;
222 /* When we construct a partial symbol table entry we only
223 need this much information. */
224 struct partial_die_info
227 unsigned char has_children
;
228 unsigned char is_external
;
229 unsigned char is_declaration
;
230 unsigned char has_type
;
237 struct dwarf_block
*locdesc
;
238 unsigned int language
;
242 /* This data structure holds the information of an abbrev. */
245 unsigned int number
; /* number identifying abbrev */
246 enum dwarf_tag tag
; /* dwarf tag */
247 int has_children
; /* boolean */
248 unsigned int num_attrs
; /* number of attributes */
249 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
250 struct abbrev_info
*next
; /* next in chain */
255 enum dwarf_attribute name
;
256 enum dwarf_form form
;
259 /* This data structure holds a complete die structure. */
262 enum dwarf_tag tag
; /* Tag indicating type of die */
263 unsigned short has_children
; /* Does the die have children */
264 unsigned int abbrev
; /* Abbrev number */
265 unsigned int offset
; /* Offset in .debug_info section */
266 unsigned int num_attrs
; /* Number of attributes */
267 struct attribute
*attrs
; /* An array of attributes */
268 struct die_info
*next_ref
; /* Next die in ref hash table */
269 struct die_info
*next
; /* Next die in linked list */
270 struct type
*type
; /* Cached type information */
273 /* Attributes have a name and a value */
276 enum dwarf_attribute name
;
277 enum dwarf_form form
;
281 struct dwarf_block
*blk
;
289 struct function_range
292 CORE_ADDR lowpc
, highpc
;
294 struct function_range
*next
;
297 static struct function_range
*cu_first_fn
, *cu_last_fn
, *cu_cached_fn
;
299 /* Get at parts of an attribute structure */
301 #define DW_STRING(attr) ((attr)->u.str)
302 #define DW_UNSND(attr) ((attr)->u.unsnd)
303 #define DW_BLOCK(attr) ((attr)->u.blk)
304 #define DW_SND(attr) ((attr)->u.snd)
305 #define DW_ADDR(attr) ((attr)->u.addr)
307 /* Blocks are a bunch of untyped bytes. */
314 /* We only hold one compilation unit's abbrevs in
315 memory at any one time. */
316 #ifndef ABBREV_HASH_SIZE
317 #define ABBREV_HASH_SIZE 121
319 #ifndef ATTR_ALLOC_CHUNK
320 #define ATTR_ALLOC_CHUNK 4
323 static struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
325 /* A hash table of die offsets for following references. */
326 #ifndef REF_HASH_SIZE
327 #define REF_HASH_SIZE 1021
330 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
332 /* Obstack for allocating temporary storage used during symbol reading. */
333 static struct obstack dwarf2_tmp_obstack
;
335 /* Offset to the first byte of the current compilation unit header,
336 for resolving relative reference dies. */
337 static unsigned int cu_header_offset
;
339 /* Allocate fields for structs, unions and enums in this size. */
340 #ifndef DW_FIELD_ALLOC_CHUNK
341 #define DW_FIELD_ALLOC_CHUNK 4
344 /* The language we are debugging. */
345 static enum language cu_language
;
346 static const struct language_defn
*cu_language_defn
;
348 /* Actually data from the sections. */
349 static char *dwarf_info_buffer
;
350 static char *dwarf_abbrev_buffer
;
351 static char *dwarf_line_buffer
;
352 static char *dwarf_str_buffer
;
354 /* A zeroed version of a partial die for initialization purposes. */
355 static struct partial_die_info zeroed_partial_die
;
357 /* The generic symbol table building routines have separate lists for
358 file scope symbols and all all other scopes (local scopes). So
359 we need to select the right one to pass to add_symbol_to_list().
360 We do it by keeping a pointer to the correct list in list_in_scope.
362 FIXME: The original dwarf code just treated the file scope as the first
363 local scope, and all other local scopes as nested local scopes, and worked
364 fine. Check to see if we really need to distinguish these
366 static struct pending
**list_in_scope
= &file_symbols
;
368 /* FIXME: decode_locdesc sets these variables to describe the location
369 to the caller. These ought to be a structure or something. If
370 none of the flags are set, the object lives at the address returned
371 by decode_locdesc. */
373 static int optimized_out
; /* No ops in location in expression,
374 so object was optimized out. */
375 static int isreg
; /* Object lives in register.
376 decode_locdesc's return value is
377 the register number. */
378 static int offreg
; /* Object's address is the sum of the
379 register specified by basereg, plus
380 the offset returned. */
381 static int basereg
; /* See `offreg'. */
382 static int isderef
; /* Value described by flags above is
383 the address of a pointer to the object. */
384 static int islocal
; /* Variable is at the returned offset
385 from the frame start, but there's
386 no identified frame pointer for
387 this function, so we can't say
388 which register it's relative to;
391 /* DW_AT_frame_base values for the current function.
392 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
393 contains the register number for the frame register.
394 frame_base_offset is the offset from the frame register to the
395 virtual stack frame. */
396 static int frame_base_reg
;
397 static CORE_ADDR frame_base_offset
;
399 /* This value is added to each symbol value. FIXME: Generalize to
400 the section_offsets structure used by dbxread (once this is done,
401 pass the appropriate section number to end_symtab). */
402 static CORE_ADDR baseaddr
; /* Add to each symbol value */
404 /* We put a pointer to this structure in the read_symtab_private field
406 The complete dwarf information for an objfile is kept in the
407 psymbol_obstack, so that absolute die references can be handled.
408 Most of the information in this structure is related to an entire
409 object file and could be passed via the sym_private field of the objfile.
410 It is however conceivable that dwarf2 might not be the only type
411 of symbols read from an object file. */
415 /* Pointer to start of dwarf info buffer for the objfile. */
417 char *dwarf_info_buffer
;
419 /* Offset in dwarf_info_buffer for this compilation unit. */
421 unsigned long dwarf_info_offset
;
423 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
425 char *dwarf_abbrev_buffer
;
427 /* Size of dwarf abbreviation section for the objfile. */
429 unsigned int dwarf_abbrev_size
;
431 /* Pointer to start of dwarf line buffer for the objfile. */
433 char *dwarf_line_buffer
;
435 /* Size of dwarf_line_buffer, in bytes. */
437 unsigned int dwarf_line_size
;
439 /* Pointer to start of dwarf string buffer for the objfile. */
441 char *dwarf_str_buffer
;
443 /* Size of dwarf string section for the objfile. */
445 unsigned int dwarf_str_size
;
448 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
449 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
450 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
451 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
452 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
453 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
454 #define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size)
455 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
456 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
458 /* Maintain an array of referenced fundamental types for the current
459 compilation unit being read. For DWARF version 1, we have to construct
460 the fundamental types on the fly, since no information about the
461 fundamental types is supplied. Each such fundamental type is created by
462 calling a language dependent routine to create the type, and then a
463 pointer to that type is then placed in the array at the index specified
464 by it's FT_<TYPENAME> value. The array has a fixed size set by the
465 FT_NUM_MEMBERS compile time constant, which is the number of predefined
466 fundamental types gdb knows how to construct. */
467 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
469 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
470 but this would require a corresponding change in unpack_field_as_long
472 static int bits_per_byte
= 8;
474 /* The routines that read and process dies for a C struct or C++ class
475 pass lists of data member fields and lists of member function fields
476 in an instance of a field_info structure, as defined below. */
479 /* List of data member and baseclasses fields. */
482 struct nextfield
*next
;
489 /* Number of fields. */
492 /* Number of baseclasses. */
495 /* Set if the accesibility of one of the fields is not public. */
496 int non_public_fields
;
498 /* Member function fields array, entries are allocated in the order they
499 are encountered in the object file. */
502 struct nextfnfield
*next
;
503 struct fn_field fnfield
;
507 /* Member function fieldlist array, contains name of possibly overloaded
508 member function, number of overloaded member functions and a pointer
509 to the head of the member function field chain. */
514 struct nextfnfield
*head
;
518 /* Number of entries in the fnfieldlists array. */
522 /* Various complaints about symbol reading that don't abort the process */
524 static struct complaint dwarf2_const_ignored
=
526 "type qualifier 'const' ignored", 0, 0
528 static struct complaint dwarf2_volatile_ignored
=
530 "type qualifier 'volatile' ignored", 0, 0
532 static struct complaint dwarf2_non_const_array_bound_ignored
=
534 "non-constant array bounds form '%s' ignored", 0, 0
536 static struct complaint dwarf2_missing_line_number_section
=
538 "missing .debug_line section", 0, 0
540 static struct complaint dwarf2_statement_list_fits_in_line_number_section
=
542 "statement list doesn't fit in .debug_line section", 0, 0
544 static struct complaint dwarf2_mangled_line_number_section
=
546 "mangled .debug_line section", 0, 0
548 static struct complaint dwarf2_unsupported_die_ref_attr
=
550 "unsupported die ref attribute form: '%s'", 0, 0
552 static struct complaint dwarf2_unsupported_stack_op
=
554 "unsupported stack op: '%s'", 0, 0
556 static struct complaint dwarf2_complex_location_expr
=
558 "location expression too complex", 0, 0
560 static struct complaint dwarf2_unsupported_tag
=
562 "unsupported tag: '%s'", 0, 0
564 static struct complaint dwarf2_unsupported_at_encoding
=
566 "unsupported DW_AT_encoding: '%s'", 0, 0
568 static struct complaint dwarf2_unsupported_at_frame_base
=
570 "unsupported DW_AT_frame_base for function '%s'", 0, 0
572 static struct complaint dwarf2_unexpected_tag
=
574 "unexepected tag in read_type_die: '%s'", 0, 0
576 static struct complaint dwarf2_missing_at_frame_base
=
578 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
580 static struct complaint dwarf2_bad_static_member_name
=
582 "unrecognized static data member name '%s'", 0, 0
584 static struct complaint dwarf2_unsupported_accessibility
=
586 "unsupported accessibility %d", 0, 0
588 static struct complaint dwarf2_bad_member_name_complaint
=
590 "cannot extract member name from '%s'", 0, 0
592 static struct complaint dwarf2_missing_member_fn_type_complaint
=
594 "member function type missing for '%s'", 0, 0
596 static struct complaint dwarf2_vtbl_not_found_complaint
=
598 "virtual function table pointer not found when defining class '%s'", 0, 0
600 static struct complaint dwarf2_absolute_sibling_complaint
=
602 "ignoring absolute DW_AT_sibling", 0, 0
604 static struct complaint dwarf2_const_value_length_mismatch
=
606 "const value length mismatch for '%s', got %d, expected %d", 0, 0
608 static struct complaint dwarf2_unsupported_const_value_attr
=
610 "unsupported const value attribute form: '%s'", 0, 0
612 static struct complaint dwarf2_misplaced_line_number
=
614 "misplaced first line number at 0x%lx for '%s'", 0, 0
616 static struct complaint dwarf2_line_header_too_long
=
618 "line number info header doesn't fit in `.debug_line' section", 0, 0
621 /* local function prototypes */
623 static void dwarf2_locate_sections (bfd
*, asection
*, PTR
);
626 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
629 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
631 static char *scan_partial_symbols (char *, struct objfile
*,
632 CORE_ADDR
*, CORE_ADDR
*,
633 const struct comp_unit_head
*);
635 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
636 const struct comp_unit_head
*);
638 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
640 static void psymtab_to_symtab_1 (struct partial_symtab
*);
642 char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int);
644 static void dwarf2_read_abbrevs (bfd
*, unsigned int);
646 static void dwarf2_empty_abbrev_table (PTR
);
648 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int);
650 static char *read_partial_die (struct partial_die_info
*,
652 const struct comp_unit_head
*);
654 static char *read_full_die (struct die_info
**, bfd
*, char *,
655 const struct comp_unit_head
*);
657 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
658 bfd
*, char *, const struct comp_unit_head
*);
660 static char *read_attribute_value (struct attribute
*, unsigned,
661 bfd
*, char *, const struct comp_unit_head
*);
663 static unsigned int read_1_byte (bfd
*, char *);
665 static int read_1_signed_byte (bfd
*, char *);
667 static unsigned int read_2_bytes (bfd
*, char *);
669 static unsigned int read_4_bytes (bfd
*, char *);
671 static unsigned long read_8_bytes (bfd
*, char *);
673 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
676 static LONGEST
read_initial_length (bfd
*, char *,
677 struct comp_unit_head
*, int *bytes_read
);
679 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
682 static char *read_n_bytes (bfd
*, char *, unsigned int);
684 static char *read_string (bfd
*, char *, unsigned int *);
686 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
689 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
691 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
693 static void set_cu_language (unsigned int);
695 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
697 static int die_is_declaration (struct die_info
*);
699 static void free_line_header (struct line_header
*lh
);
701 static struct line_header
*(dwarf_decode_line_header
702 (unsigned int offset
,
704 const struct comp_unit_head
*cu_header
));
706 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
707 const struct comp_unit_head
*);
709 static void dwarf2_start_subfile (char *, char *);
711 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
712 struct objfile
*, const struct comp_unit_head
*);
714 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
715 struct objfile
*, const struct comp_unit_head
*);
717 static void dwarf2_const_value_data (struct attribute
*attr
,
721 static struct type
*die_type (struct die_info
*, struct objfile
*,
722 const struct comp_unit_head
*);
724 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
725 const struct comp_unit_head
*);
728 static struct type
*type_at_offset (unsigned int, struct objfile
*);
731 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
732 const struct comp_unit_head
*);
734 static void read_type_die (struct die_info
*, struct objfile
*,
735 const struct comp_unit_head
*);
737 static void read_typedef (struct die_info
*, struct objfile
*,
738 const struct comp_unit_head
*);
740 static void read_base_type (struct die_info
*, struct objfile
*);
742 static void read_file_scope (struct die_info
*, struct objfile
*,
743 const struct comp_unit_head
*);
745 static void read_func_scope (struct die_info
*, struct objfile
*,
746 const struct comp_unit_head
*);
748 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
749 const struct comp_unit_head
*);
751 static int dwarf2_get_pc_bounds (struct die_info
*,
752 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*);
754 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
755 struct objfile
*, const struct comp_unit_head
*);
757 static void dwarf2_attach_fields_to_type (struct field_info
*,
758 struct type
*, struct objfile
*);
760 static void dwarf2_add_member_fn (struct field_info
*,
761 struct die_info
*, struct type
*,
762 struct objfile
*objfile
,
763 const struct comp_unit_head
*);
765 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
766 struct type
*, struct objfile
*);
768 static void read_structure_scope (struct die_info
*, struct objfile
*,
769 const struct comp_unit_head
*);
771 static void read_common_block (struct die_info
*, struct objfile
*,
772 const struct comp_unit_head
*);
774 static void read_enumeration (struct die_info
*, struct objfile
*,
775 const struct comp_unit_head
*);
777 static struct type
*dwarf_base_type (int, int, struct objfile
*);
779 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
780 const struct comp_unit_head
*);
782 static void read_array_type (struct die_info
*, struct objfile
*,
783 const struct comp_unit_head
*);
785 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
786 const struct comp_unit_head
*);
788 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
789 const struct comp_unit_head
*);
791 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
792 const struct comp_unit_head
*);
794 static void read_tag_const_type (struct die_info
*, struct objfile
*,
795 const struct comp_unit_head
*);
797 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
798 const struct comp_unit_head
*);
800 static void read_tag_string_type (struct die_info
*, struct objfile
*);
802 static void read_subroutine_type (struct die_info
*, struct objfile
*,
803 const struct comp_unit_head
*);
805 static struct die_info
*read_comp_unit (char *, bfd
*,
806 const struct comp_unit_head
*);
808 static void free_die_list (struct die_info
*);
810 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
812 static void process_die (struct die_info
*, struct objfile
*,
813 const struct comp_unit_head
*);
815 static char *dwarf2_linkage_name (struct die_info
*);
817 static char *dwarf_tag_name (unsigned int);
819 static char *dwarf_attr_name (unsigned int);
821 static char *dwarf_form_name (unsigned int);
823 static char *dwarf_stack_op_name (unsigned int);
825 static char *dwarf_bool_name (unsigned int);
827 static char *dwarf_type_encoding_name (unsigned int);
830 static char *dwarf_cfi_name (unsigned int);
832 struct die_info
*copy_die (struct die_info
*);
835 static struct die_info
*sibling_die (struct die_info
*);
837 static void dump_die (struct die_info
*);
839 static void dump_die_list (struct die_info
*);
841 static void store_in_ref_table (unsigned int, struct die_info
*);
843 static void dwarf2_empty_hash_tables (void);
845 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
847 static struct die_info
*follow_die_ref (unsigned int);
849 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
851 /* memory allocation interface */
853 static void dwarf2_free_tmp_obstack (PTR
);
855 static struct dwarf_block
*dwarf_alloc_block (void);
857 static struct abbrev_info
*dwarf_alloc_abbrev (void);
859 static struct die_info
*dwarf_alloc_die (void);
861 static void initialize_cu_func_list (void);
863 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
);
865 /* Try to locate the sections we need for DWARF 2 debugging
866 information and return true if we have enough to do something. */
869 dwarf2_has_info (bfd
*abfd
)
871 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
872 dwarf_str_offset
= 0;
873 dwarf_frame_offset
= dwarf_eh_frame_offset
= 0;
874 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
875 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
885 /* This function is mapped across the sections and remembers the
886 offset and size of each of the debugging sections we are interested
890 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, PTR ignore_ptr
)
892 if (STREQ (sectp
->name
, INFO_SECTION
))
894 dwarf_info_offset
= sectp
->filepos
;
895 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
897 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
899 dwarf_abbrev_offset
= sectp
->filepos
;
900 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
902 else if (STREQ (sectp
->name
, LINE_SECTION
))
904 dwarf_line_offset
= sectp
->filepos
;
905 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
907 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
909 dwarf_pubnames_offset
= sectp
->filepos
;
910 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
912 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
914 dwarf_aranges_offset
= sectp
->filepos
;
915 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
917 else if (STREQ (sectp
->name
, LOC_SECTION
))
919 dwarf_loc_offset
= sectp
->filepos
;
920 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
922 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
924 dwarf_macinfo_offset
= sectp
->filepos
;
925 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
927 else if (STREQ (sectp
->name
, STR_SECTION
))
929 dwarf_str_offset
= sectp
->filepos
;
930 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
932 else if (STREQ (sectp
->name
, FRAME_SECTION
))
934 dwarf_frame_offset
= sectp
->filepos
;
935 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
937 else if (STREQ (sectp
->name
, EH_FRAME_SECTION
))
939 dwarf_eh_frame_offset
= sectp
->filepos
;
940 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
944 /* Build a partial symbol table. */
947 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
950 /* We definitely need the .debug_info and .debug_abbrev sections */
952 dwarf_info_buffer
= dwarf2_read_section (objfile
,
955 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
958 dwarf_line_buffer
= dwarf2_read_section (objfile
,
962 if (dwarf_str_offset
)
963 dwarf_str_buffer
= dwarf2_read_section (objfile
,
967 dwarf_str_buffer
= NULL
;
970 || (objfile
->global_psymbols
.size
== 0
971 && objfile
->static_psymbols
.size
== 0))
973 init_psymbol_list (objfile
, 1024);
977 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
979 /* Things are significantly easier if we have .debug_aranges and
980 .debug_pubnames sections */
982 dwarf2_build_psymtabs_easy (objfile
, mainline
);
986 /* only test this case for now */
988 /* In this case we have to work a bit harder */
989 dwarf2_build_psymtabs_hard (objfile
, mainline
);
994 /* Build the partial symbol table from the information in the
995 .debug_pubnames and .debug_aranges sections. */
998 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1000 bfd
*abfd
= objfile
->obfd
;
1001 char *aranges_buffer
, *pubnames_buffer
;
1002 char *aranges_ptr
, *pubnames_ptr
;
1003 unsigned int entry_length
, version
, info_offset
, info_size
;
1005 pubnames_buffer
= dwarf2_read_section (objfile
,
1006 dwarf_pubnames_offset
,
1007 dwarf_pubnames_size
);
1008 pubnames_ptr
= pubnames_buffer
;
1009 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1011 struct comp_unit_head cu_header
;
1014 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1016 pubnames_ptr
+= bytes_read
;
1017 version
= read_1_byte (abfd
, pubnames_ptr
);
1019 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1021 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1025 aranges_buffer
= dwarf2_read_section (objfile
,
1026 dwarf_aranges_offset
,
1027 dwarf_aranges_size
);
1032 /* Read in the comp unit header information from the debug_info at
1036 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1037 char *info_ptr
, bfd
*abfd
)
1041 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1043 info_ptr
+= bytes_read
;
1044 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1046 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1048 info_ptr
+= bytes_read
;
1049 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1051 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1052 if (signed_addr
< 0)
1053 internal_error (__FILE__
, __LINE__
,
1054 "read_comp_unit_head: dwarf from non elf file");
1055 cu_header
->signed_addr_p
= signed_addr
;
1059 /* Build the partial symbol table by doing a quick pass through the
1060 .debug_info and .debug_abbrev sections. */
1063 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1065 /* Instead of reading this into a big buffer, we should probably use
1066 mmap() on architectures that support it. (FIXME) */
1067 bfd
*abfd
= objfile
->obfd
;
1068 char *info_ptr
, *abbrev_ptr
;
1069 char *beg_of_comp_unit
;
1070 struct partial_die_info comp_unit_die
;
1071 struct partial_symtab
*pst
;
1072 struct cleanup
*back_to
;
1073 CORE_ADDR lowpc
, highpc
;
1075 info_ptr
= dwarf_info_buffer
;
1076 abbrev_ptr
= dwarf_abbrev_buffer
;
1078 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1079 the partial symbol scan, like attribute values.
1081 We could reduce our peak memory consumption during partial symbol
1082 table construction by freeing stuff from this obstack more often
1083 --- say, after processing each compilation unit, or each die ---
1084 but it turns out that this saves almost nothing. For an
1085 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1086 on dwarf2_tmp_obstack. Some investigation showed:
1088 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1089 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1090 all fixed-length values not requiring dynamic allocation.
1092 2) 30% of the attributes used the form DW_FORM_string. For
1093 DW_FORM_string, read_attribute simply hands back a pointer to
1094 the null-terminated string in dwarf_info_buffer, so no dynamic
1095 allocation is needed there either.
1097 3) The remaining 1% of the attributes all used DW_FORM_block1.
1098 75% of those were DW_AT_frame_base location lists for
1099 functions; the rest were DW_AT_location attributes, probably
1100 for the global variables.
1102 Anyway, what this all means is that the memory the dwarf2
1103 reader uses as temporary space reading partial symbols is about
1104 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1106 obstack_init (&dwarf2_tmp_obstack
);
1107 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1109 /* Since the objects we're extracting from dwarf_info_buffer vary in
1110 length, only the individual functions to extract them (like
1111 read_comp_unit_head and read_partial_die) can really know whether
1112 the buffer is large enough to hold another complete object.
1114 At the moment, they don't actually check that. If
1115 dwarf_info_buffer holds just one extra byte after the last
1116 compilation unit's dies, then read_comp_unit_head will happily
1117 read off the end of the buffer. read_partial_die is similarly
1118 casual. Those functions should be fixed.
1120 For this loop condition, simply checking whether there's any data
1121 left at all should be sufficient. */
1122 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1124 struct comp_unit_head cu_header
;
1125 beg_of_comp_unit
= info_ptr
;
1126 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1128 if (cu_header
.version
!= 2)
1130 error ("Dwarf Error: wrong version in compilation unit header.");
1133 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
1135 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
1136 (long) cu_header
.abbrev_offset
,
1137 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1140 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1141 > dwarf_info_buffer
+ dwarf_info_size
)
1143 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
1144 (long) cu_header
.length
,
1145 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1148 /* Read the abbrevs for this compilation unit into a table */
1149 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1150 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1152 /* Read the compilation unit die */
1153 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1156 /* Set the language we're debugging */
1157 set_cu_language (comp_unit_die
.language
);
1159 /* Allocate a new partial symbol table structure */
1160 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1161 comp_unit_die
.name
? comp_unit_die
.name
: "",
1162 comp_unit_die
.lowpc
,
1163 objfile
->global_psymbols
.next
,
1164 objfile
->static_psymbols
.next
);
1166 pst
->read_symtab_private
= (char *)
1167 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1168 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1169 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1170 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1171 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1172 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1173 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1174 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1175 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1176 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1177 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1179 /* Store the function that reads in the rest of the symbol table */
1180 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1182 /* Check if comp unit has_children.
1183 If so, read the rest of the partial symbols from this comp unit.
1184 If not, there's no more debug_info for this comp unit. */
1185 if (comp_unit_die
.has_children
)
1187 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1190 /* If the compilation unit didn't have an explicit address range,
1191 then use the information extracted from its child dies. */
1192 if (! comp_unit_die
.has_pc_info
)
1194 comp_unit_die
.lowpc
= lowpc
;
1195 comp_unit_die
.highpc
= highpc
;
1198 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1199 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1201 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1202 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1203 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1204 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1205 sort_pst_symbols (pst
);
1207 /* If there is already a psymtab or symtab for a file of this
1208 name, remove it. (If there is a symtab, more drastic things
1209 also happen.) This happens in VxWorks. */
1210 free_named_symtabs (pst
->filename
);
1212 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1213 + cu_header
.initial_length_size
;
1215 do_cleanups (back_to
);
1218 /* Read in all interesting dies to the end of the compilation unit. */
1221 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1222 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1223 const struct comp_unit_head
*cu_header
)
1225 bfd
*abfd
= objfile
->obfd
;
1226 struct partial_die_info pdi
;
1228 /* This function is called after we've read in the comp_unit_die in
1229 order to read its children. We start the nesting level at 1 since
1230 we have pushed 1 level down in order to read the comp unit's children.
1231 The comp unit itself is at level 0, so we stop reading when we pop
1232 back to that level. */
1234 int nesting_level
= 1;
1236 *lowpc
= ((CORE_ADDR
) -1);
1237 *highpc
= ((CORE_ADDR
) 0);
1239 while (nesting_level
)
1241 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1247 case DW_TAG_subprogram
:
1248 if (pdi
.has_pc_info
)
1250 if (pdi
.lowpc
< *lowpc
)
1254 if (pdi
.highpc
> *highpc
)
1256 *highpc
= pdi
.highpc
;
1258 if ((pdi
.is_external
|| nesting_level
== 1)
1259 && !pdi
.is_declaration
)
1261 add_partial_symbol (&pdi
, objfile
, cu_header
);
1265 case DW_TAG_variable
:
1266 case DW_TAG_typedef
:
1267 case DW_TAG_class_type
:
1268 case DW_TAG_structure_type
:
1269 case DW_TAG_union_type
:
1270 case DW_TAG_enumeration_type
:
1271 if ((pdi
.is_external
|| nesting_level
== 1)
1272 && !pdi
.is_declaration
)
1274 add_partial_symbol (&pdi
, objfile
, cu_header
);
1277 case DW_TAG_enumerator
:
1278 /* File scope enumerators are added to the partial symbol
1280 if (nesting_level
== 2)
1281 add_partial_symbol (&pdi
, objfile
, cu_header
);
1283 case DW_TAG_base_type
:
1284 /* File scope base type definitions are added to the partial
1286 if (nesting_level
== 1)
1287 add_partial_symbol (&pdi
, objfile
, cu_header
);
1294 /* If the die has a sibling, skip to the sibling.
1295 Do not skip enumeration types, we want to record their
1297 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1299 info_ptr
= pdi
.sibling
;
1301 else if (pdi
.has_children
)
1303 /* Die has children, but the optional DW_AT_sibling attribute
1314 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1315 from `maint check'. */
1316 if (*lowpc
== ((CORE_ADDR
) -1))
1322 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1323 const struct comp_unit_head
*cu_header
)
1329 case DW_TAG_subprogram
:
1330 if (pdi
->is_external
)
1332 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1333 mst_text, objfile); */
1334 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1335 VAR_NAMESPACE
, LOC_BLOCK
,
1336 &objfile
->global_psymbols
,
1337 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1341 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1342 mst_file_text, objfile); */
1343 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1344 VAR_NAMESPACE
, LOC_BLOCK
,
1345 &objfile
->static_psymbols
,
1346 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1349 case DW_TAG_variable
:
1350 if (pdi
->is_external
)
1353 Don't enter into the minimal symbol tables as there is
1354 a minimal symbol table entry from the ELF symbols already.
1355 Enter into partial symbol table if it has a location
1356 descriptor or a type.
1357 If the location descriptor is missing, new_symbol will create
1358 a LOC_UNRESOLVED symbol, the address of the variable will then
1359 be determined from the minimal symbol table whenever the variable
1361 The address for the partial symbol table entry is not
1362 used by GDB, but it comes in handy for debugging partial symbol
1366 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1367 if (pdi
->locdesc
|| pdi
->has_type
)
1368 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1369 VAR_NAMESPACE
, LOC_STATIC
,
1370 &objfile
->global_psymbols
,
1371 0, addr
+ baseaddr
, cu_language
, objfile
);
1375 /* Static Variable. Skip symbols without location descriptors. */
1376 if (pdi
->locdesc
== NULL
)
1378 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1379 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1380 mst_file_data, objfile); */
1381 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1382 VAR_NAMESPACE
, LOC_STATIC
,
1383 &objfile
->static_psymbols
,
1384 0, addr
+ baseaddr
, cu_language
, objfile
);
1387 case DW_TAG_typedef
:
1388 case DW_TAG_base_type
:
1389 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1390 VAR_NAMESPACE
, LOC_TYPEDEF
,
1391 &objfile
->static_psymbols
,
1392 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1394 case DW_TAG_class_type
:
1395 case DW_TAG_structure_type
:
1396 case DW_TAG_union_type
:
1397 case DW_TAG_enumeration_type
:
1398 /* Skip aggregate types without children, these are external
1400 if (pdi
->has_children
== 0)
1402 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1403 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1404 &objfile
->static_psymbols
,
1405 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1407 if (cu_language
== language_cplus
)
1409 /* For C++, these implicitly act as typedefs as well. */
1410 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1411 VAR_NAMESPACE
, LOC_TYPEDEF
,
1412 &objfile
->static_psymbols
,
1413 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1416 case DW_TAG_enumerator
:
1417 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1418 VAR_NAMESPACE
, LOC_CONST
,
1419 &objfile
->static_psymbols
,
1420 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1427 /* Expand this partial symbol table into a full symbol table. */
1430 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1432 /* FIXME: This is barely more than a stub. */
1437 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1443 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1444 gdb_flush (gdb_stdout
);
1447 psymtab_to_symtab_1 (pst
);
1449 /* Finish up the debug error message. */
1451 printf_filtered ("done.\n");
1457 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1459 struct objfile
*objfile
= pst
->objfile
;
1460 bfd
*abfd
= objfile
->obfd
;
1461 struct comp_unit_head cu_header
;
1462 struct die_info
*dies
;
1463 unsigned long offset
;
1464 CORE_ADDR lowpc
, highpc
;
1465 struct die_info
*child_die
;
1467 struct symtab
*symtab
;
1468 struct cleanup
*back_to
;
1470 /* Set local variables from the partial symbol table info. */
1471 offset
= DWARF_INFO_OFFSET (pst
);
1472 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1473 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1474 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1475 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1476 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1477 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1478 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1479 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1480 cu_header_offset
= offset
;
1481 info_ptr
= dwarf_info_buffer
+ offset
;
1483 obstack_init (&dwarf2_tmp_obstack
);
1484 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1487 make_cleanup (really_free_pendings
, NULL
);
1489 /* read in the comp_unit header */
1490 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1492 /* Read the abbrevs for this compilation unit */
1493 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1494 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1496 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1498 make_cleanup_free_die_list (dies
);
1500 /* Do line number decoding in read_file_scope () */
1501 process_die (dies
, objfile
, &cu_header
);
1503 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1505 /* Some compilers don't define a DW_AT_high_pc attribute for
1506 the compilation unit. If the DW_AT_high_pc is missing,
1507 synthesize it, by scanning the DIE's below the compilation unit. */
1509 if (dies
->has_children
)
1511 child_die
= dies
->next
;
1512 while (child_die
&& child_die
->tag
)
1514 if (child_die
->tag
== DW_TAG_subprogram
)
1516 CORE_ADDR low
, high
;
1518 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1520 highpc
= max (highpc
, high
);
1523 child_die
= sibling_die (child_die
);
1527 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1529 /* Set symtab language to language from DW_AT_language.
1530 If the compilation is from a C file generated by language preprocessors,
1531 do not set the language if it was already deduced by start_subfile. */
1533 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1535 symtab
->language
= cu_language
;
1537 pst
->symtab
= symtab
;
1539 sort_symtab_syms (pst
->symtab
);
1541 do_cleanups (back_to
);
1544 /* Process a die and its children. */
1547 process_die (struct die_info
*die
, struct objfile
*objfile
,
1548 const struct comp_unit_head
*cu_header
)
1552 case DW_TAG_padding
:
1554 case DW_TAG_compile_unit
:
1555 read_file_scope (die
, objfile
, cu_header
);
1557 case DW_TAG_subprogram
:
1558 read_subroutine_type (die
, objfile
, cu_header
);
1559 read_func_scope (die
, objfile
, cu_header
);
1561 case DW_TAG_inlined_subroutine
:
1562 /* FIXME: These are ignored for now.
1563 They could be used to set breakpoints on all inlined instances
1564 of a function and make GDB `next' properly over inlined functions. */
1566 case DW_TAG_lexical_block
:
1567 read_lexical_block_scope (die
, objfile
, cu_header
);
1569 case DW_TAG_class_type
:
1570 case DW_TAG_structure_type
:
1571 case DW_TAG_union_type
:
1572 read_structure_scope (die
, objfile
, cu_header
);
1574 case DW_TAG_enumeration_type
:
1575 read_enumeration (die
, objfile
, cu_header
);
1577 case DW_TAG_subroutine_type
:
1578 read_subroutine_type (die
, objfile
, cu_header
);
1580 case DW_TAG_array_type
:
1581 read_array_type (die
, objfile
, cu_header
);
1583 case DW_TAG_pointer_type
:
1584 read_tag_pointer_type (die
, objfile
, cu_header
);
1586 case DW_TAG_ptr_to_member_type
:
1587 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1589 case DW_TAG_reference_type
:
1590 read_tag_reference_type (die
, objfile
, cu_header
);
1592 case DW_TAG_string_type
:
1593 read_tag_string_type (die
, objfile
);
1595 case DW_TAG_base_type
:
1596 read_base_type (die
, objfile
);
1597 if (dwarf_attr (die
, DW_AT_name
))
1599 /* Add a typedef symbol for the base type definition. */
1600 new_symbol (die
, die
->type
, objfile
, cu_header
);
1603 case DW_TAG_common_block
:
1604 read_common_block (die
, objfile
, cu_header
);
1606 case DW_TAG_common_inclusion
:
1609 new_symbol (die
, NULL
, objfile
, cu_header
);
1615 initialize_cu_func_list (void)
1617 cu_first_fn
= cu_last_fn
= cu_cached_fn
= NULL
;
1621 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1622 const struct comp_unit_head
*cu_header
)
1624 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
1625 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1626 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1627 struct attribute
*attr
;
1628 char *name
= "<unknown>";
1629 char *comp_dir
= NULL
;
1630 struct die_info
*child_die
;
1631 bfd
*abfd
= objfile
->obfd
;
1632 struct line_header
*line_header
= 0;
1634 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1636 if (die
->has_children
)
1638 child_die
= die
->next
;
1639 while (child_die
&& child_die
->tag
)
1641 if (child_die
->tag
== DW_TAG_subprogram
)
1643 CORE_ADDR low
, high
;
1645 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1647 lowpc
= min (lowpc
, low
);
1648 highpc
= max (highpc
, high
);
1651 child_die
= sibling_die (child_die
);
1656 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1657 from finish_block. */
1658 if (lowpc
== ((CORE_ADDR
) -1))
1663 attr
= dwarf_attr (die
, DW_AT_name
);
1666 name
= DW_STRING (attr
);
1668 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1671 comp_dir
= DW_STRING (attr
);
1674 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1675 directory, get rid of it. */
1676 char *cp
= strchr (comp_dir
, ':');
1678 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1683 if (objfile
->ei
.entry_point
>= lowpc
&&
1684 objfile
->ei
.entry_point
< highpc
)
1686 objfile
->ei
.entry_file_lowpc
= lowpc
;
1687 objfile
->ei
.entry_file_highpc
= highpc
;
1690 attr
= dwarf_attr (die
, DW_AT_language
);
1693 set_cu_language (DW_UNSND (attr
));
1696 /* We assume that we're processing GCC output. */
1697 processing_gcc_compilation
= 2;
1699 /* FIXME:Do something here. */
1700 if (dip
->at_producer
!= NULL
)
1702 handle_producer (dip
->at_producer
);
1706 /* The compilation unit may be in a different language or objfile,
1707 zero out all remembered fundamental types. */
1708 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1710 start_symtab (name
, comp_dir
, lowpc
);
1711 record_debugformat ("DWARF 2");
1713 initialize_cu_func_list ();
1715 /* Process all dies in compilation unit. */
1716 if (die
->has_children
)
1718 child_die
= die
->next
;
1719 while (child_die
&& child_die
->tag
)
1721 process_die (child_die
, objfile
, cu_header
);
1722 child_die
= sibling_die (child_die
);
1726 /* Decode line number information if present. */
1727 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1730 unsigned int line_offset
= DW_UNSND (attr
);
1731 line_header
= dwarf_decode_line_header (line_offset
,
1735 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
1736 (void *) line_header
);
1737 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu_header
);
1741 do_cleanups (back_to
);
1745 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
)
1747 struct function_range
*thisfn
;
1749 thisfn
= (struct function_range
*)
1750 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
1751 thisfn
->name
= name
;
1752 thisfn
->lowpc
= lowpc
;
1753 thisfn
->highpc
= highpc
;
1754 thisfn
->seen_line
= 0;
1755 thisfn
->next
= NULL
;
1757 if (cu_last_fn
== NULL
)
1758 cu_first_fn
= thisfn
;
1760 cu_last_fn
->next
= thisfn
;
1762 cu_last_fn
= thisfn
;
1766 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
1767 const struct comp_unit_head
*cu_header
)
1769 register struct context_stack
*new;
1772 struct die_info
*child_die
;
1773 struct attribute
*attr
;
1776 name
= dwarf2_linkage_name (die
);
1778 /* Ignore functions with missing or empty names and functions with
1779 missing or invalid low and high pc attributes. */
1780 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1786 /* Record the function range for dwarf_decode_lines. */
1787 add_to_cu_func_list (name
, lowpc
, highpc
);
1789 if (objfile
->ei
.entry_point
>= lowpc
&&
1790 objfile
->ei
.entry_point
< highpc
)
1792 objfile
->ei
.entry_func_lowpc
= lowpc
;
1793 objfile
->ei
.entry_func_highpc
= highpc
;
1796 /* Decode DW_AT_frame_base location descriptor if present, keep result
1797 for DW_OP_fbreg operands in decode_locdesc. */
1798 frame_base_reg
= -1;
1799 frame_base_offset
= 0;
1800 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1803 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
1805 complain (&dwarf2_unsupported_at_frame_base
, name
);
1807 frame_base_reg
= addr
;
1810 frame_base_reg
= basereg
;
1811 frame_base_offset
= addr
;
1814 complain (&dwarf2_unsupported_at_frame_base
, name
);
1817 new = push_context (0, lowpc
);
1818 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
1819 list_in_scope
= &local_symbols
;
1821 if (die
->has_children
)
1823 child_die
= die
->next
;
1824 while (child_die
&& child_die
->tag
)
1826 process_die (child_die
, objfile
, cu_header
);
1827 child_die
= sibling_die (child_die
);
1831 new = pop_context ();
1832 /* Make a block for the local symbols within. */
1833 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1834 lowpc
, highpc
, objfile
);
1835 list_in_scope
= &file_symbols
;
1838 /* Process all the DIES contained within a lexical block scope. Start
1839 a new scope, process the dies, and then close the scope. */
1842 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
1843 const struct comp_unit_head
*cu_header
)
1845 register struct context_stack
*new;
1846 CORE_ADDR lowpc
, highpc
;
1847 struct die_info
*child_die
;
1849 /* Ignore blocks with missing or invalid low and high pc attributes. */
1850 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1855 push_context (0, lowpc
);
1856 if (die
->has_children
)
1858 child_die
= die
->next
;
1859 while (child_die
&& child_die
->tag
)
1861 process_die (child_die
, objfile
, cu_header
);
1862 child_die
= sibling_die (child_die
);
1865 new = pop_context ();
1867 if (local_symbols
!= NULL
)
1869 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1872 local_symbols
= new->locals
;
1875 /* Get low and high pc attributes from a die.
1876 Return 1 if the attributes are present and valid, otherwise, return 0. */
1879 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1880 struct objfile
*objfile
)
1882 struct attribute
*attr
;
1886 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1888 low
= DW_ADDR (attr
);
1891 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1893 high
= DW_ADDR (attr
);
1900 /* When using the GNU linker, .gnu.linkonce. sections are used to
1901 eliminate duplicate copies of functions and vtables and such.
1902 The linker will arbitrarily choose one and discard the others.
1903 The AT_*_pc values for such functions refer to local labels in
1904 these sections. If the section from that file was discarded, the
1905 labels are not in the output, so the relocs get a value of 0.
1906 If this is a discarded function, mark the pc bounds as invalid,
1907 so that GDB will ignore it. */
1908 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1916 /* Add an aggregate field to the field list. */
1919 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
1920 struct objfile
*objfile
,
1921 const struct comp_unit_head
*cu_header
)
1923 struct nextfield
*new_field
;
1924 struct attribute
*attr
;
1926 char *fieldname
= "";
1928 /* Allocate a new field list entry and link it in. */
1929 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1930 make_cleanup (xfree
, new_field
);
1931 memset (new_field
, 0, sizeof (struct nextfield
));
1932 new_field
->next
= fip
->fields
;
1933 fip
->fields
= new_field
;
1936 /* Handle accessibility and virtuality of field.
1937 The default accessibility for members is public, the default
1938 accessibility for inheritance is private. */
1939 if (die
->tag
!= DW_TAG_inheritance
)
1940 new_field
->accessibility
= DW_ACCESS_public
;
1942 new_field
->accessibility
= DW_ACCESS_private
;
1943 new_field
->virtuality
= DW_VIRTUALITY_none
;
1945 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1947 new_field
->accessibility
= DW_UNSND (attr
);
1948 if (new_field
->accessibility
!= DW_ACCESS_public
)
1949 fip
->non_public_fields
= 1;
1950 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1952 new_field
->virtuality
= DW_UNSND (attr
);
1954 fp
= &new_field
->field
;
1955 if (die
->tag
== DW_TAG_member
)
1957 /* Get type of field. */
1958 fp
->type
= die_type (die
, objfile
, cu_header
);
1960 /* Get bit size of field (zero if none). */
1961 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1964 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1968 FIELD_BITSIZE (*fp
) = 0;
1971 /* Get bit offset of field. */
1972 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1975 FIELD_BITPOS (*fp
) =
1976 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
1979 FIELD_BITPOS (*fp
) = 0;
1980 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1983 if (BITS_BIG_ENDIAN
)
1985 /* For big endian bits, the DW_AT_bit_offset gives the
1986 additional bit offset from the MSB of the containing
1987 anonymous object to the MSB of the field. We don't
1988 have to do anything special since we don't need to
1989 know the size of the anonymous object. */
1990 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1994 /* For little endian bits, compute the bit offset to the
1995 MSB of the anonymous object, subtract off the number of
1996 bits from the MSB of the field to the MSB of the
1997 object, and then subtract off the number of bits of
1998 the field itself. The result is the bit offset of
1999 the LSB of the field. */
2001 int bit_offset
= DW_UNSND (attr
);
2003 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2006 /* The size of the anonymous object containing
2007 the bit field is explicit, so use the
2008 indicated size (in bytes). */
2009 anonymous_size
= DW_UNSND (attr
);
2013 /* The size of the anonymous object containing
2014 the bit field must be inferred from the type
2015 attribute of the data member containing the
2017 anonymous_size
= TYPE_LENGTH (fp
->type
);
2019 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2020 - bit_offset
- FIELD_BITSIZE (*fp
);
2024 /* Get name of field. */
2025 attr
= dwarf_attr (die
, DW_AT_name
);
2026 if (attr
&& DW_STRING (attr
))
2027 fieldname
= DW_STRING (attr
);
2028 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
2029 &objfile
->type_obstack
);
2031 /* Change accessibility for artificial fields (e.g. virtual table
2032 pointer or virtual base class pointer) to private. */
2033 if (dwarf_attr (die
, DW_AT_artificial
))
2035 new_field
->accessibility
= DW_ACCESS_private
;
2036 fip
->non_public_fields
= 1;
2039 else if (die
->tag
== DW_TAG_variable
)
2043 /* C++ static member.
2044 Get name of field. */
2045 attr
= dwarf_attr (die
, DW_AT_name
);
2046 if (attr
&& DW_STRING (attr
))
2047 fieldname
= DW_STRING (attr
);
2051 /* Get physical name. */
2052 physname
= dwarf2_linkage_name (die
);
2054 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
2055 &objfile
->type_obstack
));
2056 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2057 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
2058 &objfile
->type_obstack
);
2060 else if (die
->tag
== DW_TAG_inheritance
)
2062 /* C++ base class field. */
2063 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2065 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
2067 FIELD_BITSIZE (*fp
) = 0;
2068 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2069 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2070 fip
->nbaseclasses
++;
2074 /* Create the vector of fields, and attach it to the type. */
2077 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2078 struct objfile
*objfile
)
2080 int nfields
= fip
->nfields
;
2082 /* Record the field count, allocate space for the array of fields,
2083 and create blank accessibility bitfields if necessary. */
2084 TYPE_NFIELDS (type
) = nfields
;
2085 TYPE_FIELDS (type
) = (struct field
*)
2086 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2087 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2089 if (fip
->non_public_fields
)
2091 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2093 TYPE_FIELD_PRIVATE_BITS (type
) =
2094 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2095 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2097 TYPE_FIELD_PROTECTED_BITS (type
) =
2098 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2099 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2101 TYPE_FIELD_IGNORE_BITS (type
) =
2102 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2103 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2106 /* If the type has baseclasses, allocate and clear a bit vector for
2107 TYPE_FIELD_VIRTUAL_BITS. */
2108 if (fip
->nbaseclasses
)
2110 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2113 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2114 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2115 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2116 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2117 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2120 /* Copy the saved-up fields into the field vector. Start from the head
2121 of the list, adding to the tail of the field array, so that they end
2122 up in the same order in the array in which they were added to the list. */
2123 while (nfields
-- > 0)
2125 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2126 switch (fip
->fields
->accessibility
)
2128 case DW_ACCESS_private
:
2129 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2132 case DW_ACCESS_protected
:
2133 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2136 case DW_ACCESS_public
:
2140 /* Unknown accessibility. Complain and treat it as public. */
2142 complain (&dwarf2_unsupported_accessibility
,
2143 fip
->fields
->accessibility
);
2147 if (nfields
< fip
->nbaseclasses
)
2149 switch (fip
->fields
->virtuality
)
2151 case DW_VIRTUALITY_virtual
:
2152 case DW_VIRTUALITY_pure_virtual
:
2153 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2157 fip
->fields
= fip
->fields
->next
;
2161 /* Add a member function to the proper fieldlist. */
2164 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2165 struct type
*type
, struct objfile
*objfile
,
2166 const struct comp_unit_head
*cu_header
)
2168 struct attribute
*attr
;
2169 struct fnfieldlist
*flp
;
2171 struct fn_field
*fnp
;
2174 struct nextfnfield
*new_fnfield
;
2176 /* Get name of member function. */
2177 attr
= dwarf_attr (die
, DW_AT_name
);
2178 if (attr
&& DW_STRING (attr
))
2179 fieldname
= DW_STRING (attr
);
2183 /* Get the mangled name. */
2184 physname
= dwarf2_linkage_name (die
);
2186 /* Look up member function name in fieldlist. */
2187 for (i
= 0; i
< fip
->nfnfields
; i
++)
2189 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2193 /* Create new list element if necessary. */
2194 if (i
< fip
->nfnfields
)
2195 flp
= &fip
->fnfieldlists
[i
];
2198 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2200 fip
->fnfieldlists
= (struct fnfieldlist
*)
2201 xrealloc (fip
->fnfieldlists
,
2202 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2203 * sizeof (struct fnfieldlist
));
2204 if (fip
->nfnfields
== 0)
2205 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2207 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2208 flp
->name
= fieldname
;
2214 /* Create a new member function field and chain it to the field list
2216 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2217 make_cleanup (xfree
, new_fnfield
);
2218 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2219 new_fnfield
->next
= flp
->head
;
2220 flp
->head
= new_fnfield
;
2223 /* Fill in the member function field info. */
2224 fnp
= &new_fnfield
->fnfield
;
2225 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2226 &objfile
->type_obstack
);
2227 fnp
->type
= alloc_type (objfile
);
2228 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2230 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2231 struct type
**arg_types
;
2232 int nparams
= TYPE_NFIELDS (die
->type
);
2235 /* Copy argument types from the subroutine type. */
2236 arg_types
= (struct type
**)
2237 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2238 for (iparams
= 0; iparams
< nparams
; iparams
++)
2239 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2241 /* Set last entry in argument type vector. */
2242 if (TYPE_VARARGS (die
->type
))
2243 arg_types
[nparams
] = NULL
;
2245 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2247 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2249 /* Handle static member functions.
2250 Dwarf2 has no clean way to discern C++ static and non-static
2251 member functions. G++ helps GDB by marking the first
2252 parameter for non-static member functions (which is the
2253 this pointer) as artificial. We obtain this information
2254 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2255 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2256 fnp
->voffset
= VOFFSET_STATIC
;
2259 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2261 /* Get fcontext from DW_AT_containing_type if present. */
2262 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2263 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2265 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2266 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2268 /* Get accessibility. */
2269 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2272 switch (DW_UNSND (attr
))
2274 case DW_ACCESS_private
:
2275 fnp
->is_private
= 1;
2277 case DW_ACCESS_protected
:
2278 fnp
->is_protected
= 1;
2283 /* Check for artificial methods. */
2284 attr
= dwarf_attr (die
, DW_AT_artificial
);
2285 if (attr
&& DW_UNSND (attr
) != 0)
2286 fnp
->is_artificial
= 1;
2288 /* Get index in virtual function table if it is a virtual member function. */
2289 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2291 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2294 /* Create the vector of member function fields, and attach it to the type. */
2297 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2298 struct objfile
*objfile
)
2300 struct fnfieldlist
*flp
;
2301 int total_length
= 0;
2304 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2305 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2306 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2308 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2310 struct nextfnfield
*nfp
= flp
->head
;
2311 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2314 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2315 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2316 fn_flp
->fn_fields
= (struct fn_field
*)
2317 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2318 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2319 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2321 total_length
+= flp
->length
;
2324 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2325 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2328 /* Called when we find the DIE that starts a structure or union scope
2329 (definition) to process all dies that define the members of the
2332 NOTE: we need to call struct_type regardless of whether or not the
2333 DIE has an at_name attribute, since it might be an anonymous
2334 structure or union. This gets the type entered into our set of
2337 However, if the structure is incomplete (an opaque struct/union)
2338 then suppress creating a symbol table entry for it since gdb only
2339 wants to find the one with the complete definition. Note that if
2340 it is complete, we just call new_symbol, which does it's own
2341 checking about whether the struct/union is anonymous or not (and
2342 suppresses creating a symbol table entry itself). */
2345 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2346 const struct comp_unit_head
*cu_header
)
2349 struct attribute
*attr
;
2351 type
= alloc_type (objfile
);
2353 INIT_CPLUS_SPECIFIC (type
);
2354 attr
= dwarf_attr (die
, DW_AT_name
);
2355 if (attr
&& DW_STRING (attr
))
2357 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2358 strlen (DW_STRING (attr
)),
2359 &objfile
->type_obstack
);
2362 if (die
->tag
== DW_TAG_structure_type
)
2364 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2366 else if (die
->tag
== DW_TAG_union_type
)
2368 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2372 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2374 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2377 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2380 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2384 TYPE_LENGTH (type
) = 0;
2387 /* We need to add the type field to the die immediately so we don't
2388 infinitely recurse when dealing with pointers to the structure
2389 type within the structure itself. */
2392 if (die
->has_children
&& ! die_is_declaration (die
))
2394 struct field_info fi
;
2395 struct die_info
*child_die
;
2396 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2398 memset (&fi
, 0, sizeof (struct field_info
));
2400 child_die
= die
->next
;
2402 while (child_die
&& child_die
->tag
)
2404 if (child_die
->tag
== DW_TAG_member
)
2406 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2408 else if (child_die
->tag
== DW_TAG_variable
)
2410 /* C++ static member. */
2411 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2413 else if (child_die
->tag
== DW_TAG_subprogram
)
2415 /* C++ member function. */
2416 process_die (child_die
, objfile
, cu_header
);
2417 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2419 else if (child_die
->tag
== DW_TAG_inheritance
)
2421 /* C++ base class field. */
2422 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2426 process_die (child_die
, objfile
, cu_header
);
2428 child_die
= sibling_die (child_die
);
2431 /* Attach fields and member functions to the type. */
2433 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2436 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2438 /* Get the type which refers to the base class (possibly this
2439 class itself) which contains the vtable pointer for the current
2440 class from the DW_AT_containing_type attribute. */
2442 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2444 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2446 TYPE_VPTR_BASETYPE (type
) = t
;
2449 static const char vptr_name
[] =
2450 {'_', 'v', 'p', 't', 'r', '\0'};
2453 /* Our own class provides vtbl ptr. */
2454 for (i
= TYPE_NFIELDS (t
) - 1;
2455 i
>= TYPE_N_BASECLASSES (t
);
2458 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2460 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2461 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2463 TYPE_VPTR_FIELDNO (type
) = i
;
2468 /* Complain if virtual function table field not found. */
2469 if (i
< TYPE_N_BASECLASSES (t
))
2470 complain (&dwarf2_vtbl_not_found_complaint
,
2471 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2475 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2480 new_symbol (die
, type
, objfile
, cu_header
);
2482 do_cleanups (back_to
);
2486 /* No children, must be stub. */
2487 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2491 /* Given a pointer to a die which begins an enumeration, process all
2492 the dies that define the members of the enumeration.
2494 This will be much nicer in draft 6 of the DWARF spec when our
2495 members will be dies instead squished into the DW_AT_element_list
2498 NOTE: We reverse the order of the element list. */
2501 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2502 const struct comp_unit_head
*cu_header
)
2504 struct die_info
*child_die
;
2506 struct field
*fields
;
2507 struct attribute
*attr
;
2510 int unsigned_enum
= 1;
2512 type
= alloc_type (objfile
);
2514 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2515 attr
= dwarf_attr (die
, DW_AT_name
);
2516 if (attr
&& DW_STRING (attr
))
2518 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2519 strlen (DW_STRING (attr
)),
2520 &objfile
->type_obstack
);
2523 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2526 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2530 TYPE_LENGTH (type
) = 0;
2535 if (die
->has_children
)
2537 child_die
= die
->next
;
2538 while (child_die
&& child_die
->tag
)
2540 if (child_die
->tag
!= DW_TAG_enumerator
)
2542 process_die (child_die
, objfile
, cu_header
);
2546 attr
= dwarf_attr (child_die
, DW_AT_name
);
2549 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2550 if (SYMBOL_VALUE (sym
) < 0)
2553 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2555 fields
= (struct field
*)
2557 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2558 * sizeof (struct field
));
2561 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2562 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2563 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2564 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2570 child_die
= sibling_die (child_die
);
2575 TYPE_NFIELDS (type
) = num_fields
;
2576 TYPE_FIELDS (type
) = (struct field
*)
2577 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2578 memcpy (TYPE_FIELDS (type
), fields
,
2579 sizeof (struct field
) * num_fields
);
2583 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2586 new_symbol (die
, type
, objfile
, cu_header
);
2589 /* Extract all information from a DW_TAG_array_type DIE and put it in
2590 the DIE's type field. For now, this only handles one dimensional
2594 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
2595 const struct comp_unit_head
*cu_header
)
2597 struct die_info
*child_die
;
2598 struct type
*type
= NULL
;
2599 struct type
*element_type
, *range_type
, *index_type
;
2600 struct type
**range_types
= NULL
;
2601 struct attribute
*attr
;
2603 struct cleanup
*back_to
;
2605 /* Return if we've already decoded this type. */
2611 element_type
= die_type (die
, objfile
, cu_header
);
2613 /* Irix 6.2 native cc creates array types without children for
2614 arrays with unspecified length. */
2615 if (die
->has_children
== 0)
2617 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2618 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2619 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2623 back_to
= make_cleanup (null_cleanup
, NULL
);
2624 child_die
= die
->next
;
2625 while (child_die
&& child_die
->tag
)
2627 if (child_die
->tag
== DW_TAG_subrange_type
)
2629 unsigned int low
, high
;
2631 /* Default bounds to an array with unspecified length. */
2634 if (cu_language
== language_fortran
)
2636 /* FORTRAN implies a lower bound of 1, if not given. */
2640 index_type
= die_type (child_die
, objfile
, cu_header
);
2641 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2644 if (attr
->form
== DW_FORM_sdata
)
2646 low
= DW_SND (attr
);
2648 else if (attr
->form
== DW_FORM_udata
2649 || attr
->form
== DW_FORM_data1
2650 || attr
->form
== DW_FORM_data2
2651 || attr
->form
== DW_FORM_data4
2652 || attr
->form
== DW_FORM_data8
)
2654 low
= DW_UNSND (attr
);
2658 complain (&dwarf2_non_const_array_bound_ignored
,
2659 dwarf_form_name (attr
->form
));
2661 die
->type
= lookup_pointer_type (element_type
);
2668 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2671 if (attr
->form
== DW_FORM_sdata
)
2673 high
= DW_SND (attr
);
2675 else if (attr
->form
== DW_FORM_udata
2676 || attr
->form
== DW_FORM_data1
2677 || attr
->form
== DW_FORM_data2
2678 || attr
->form
== DW_FORM_data4
2679 || attr
->form
== DW_FORM_data8
)
2681 high
= DW_UNSND (attr
);
2683 else if (attr
->form
== DW_FORM_block1
)
2685 /* GCC encodes arrays with unspecified or dynamic length
2686 with a DW_FORM_block1 attribute.
2687 FIXME: GDB does not yet know how to handle dynamic
2688 arrays properly, treat them as arrays with unspecified
2694 complain (&dwarf2_non_const_array_bound_ignored
,
2695 dwarf_form_name (attr
->form
));
2697 die
->type
= lookup_pointer_type (element_type
);
2705 /* Create a range type and save it for array type creation. */
2706 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2708 range_types
= (struct type
**)
2709 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2710 * sizeof (struct type
*));
2712 make_cleanup (free_current_contents
, &range_types
);
2714 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2716 child_die
= sibling_die (child_die
);
2719 /* Dwarf2 dimensions are output from left to right, create the
2720 necessary array types in backwards order. */
2721 type
= element_type
;
2723 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2725 /* Understand Dwarf2 support for vector types (like they occur on
2726 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
2727 array type. This is not part of the Dwarf2/3 standard yet, but a
2728 custom vendor extension. The main difference between a regular
2729 array and the vector variant is that vectors are passed by value
2731 attr
= dwarf_attr (die
, DW_AT_GNU_vector
);
2733 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
2735 do_cleanups (back_to
);
2737 /* Install the type in the die. */
2741 /* First cut: install each common block member as a global variable. */
2744 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
2745 const struct comp_unit_head
*cu_header
)
2747 struct die_info
*child_die
;
2748 struct attribute
*attr
;
2750 CORE_ADDR base
= (CORE_ADDR
) 0;
2752 attr
= dwarf_attr (die
, DW_AT_location
);
2755 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2757 if (die
->has_children
)
2759 child_die
= die
->next
;
2760 while (child_die
&& child_die
->tag
)
2762 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
2763 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2766 SYMBOL_VALUE_ADDRESS (sym
) =
2767 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2768 add_symbol_to_list (sym
, &global_symbols
);
2770 child_die
= sibling_die (child_die
);
2775 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2776 the user defined type vector. */
2779 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
2780 const struct comp_unit_head
*cu_header
)
2783 struct attribute
*attr
;
2790 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
2791 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2794 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2798 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2803 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2804 the user defined type vector. */
2807 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
2808 const struct comp_unit_head
*cu_header
)
2811 struct type
*to_type
;
2812 struct type
*domain
;
2819 type
= alloc_type (objfile
);
2820 to_type
= die_type (die
, objfile
, cu_header
);
2821 domain
= die_containing_type (die
, objfile
, cu_header
);
2822 smash_to_member_type (type
, domain
, to_type
);
2827 /* Extract all information from a DW_TAG_reference_type DIE and add to
2828 the user defined type vector. */
2831 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
2832 const struct comp_unit_head
*cu_header
)
2835 struct attribute
*attr
;
2842 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
2843 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2846 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2850 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2856 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
2857 const struct comp_unit_head
*cu_header
)
2859 struct type
*base_type
;
2866 base_type
= die_type (die
, objfile
, cu_header
);
2867 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
2871 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
2872 const struct comp_unit_head
*cu_header
)
2874 struct type
*base_type
;
2881 base_type
= die_type (die
, objfile
, cu_header
);
2882 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
2885 /* Extract all information from a DW_TAG_string_type DIE and add to
2886 the user defined type vector. It isn't really a user defined type,
2887 but it behaves like one, with other DIE's using an AT_user_def_type
2888 attribute to reference it. */
2891 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
2893 struct type
*type
, *range_type
, *index_type
, *char_type
;
2894 struct attribute
*attr
;
2895 unsigned int length
;
2902 attr
= dwarf_attr (die
, DW_AT_string_length
);
2905 length
= DW_UNSND (attr
);
2909 /* check for the DW_AT_byte_size attribute */
2910 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2913 length
= DW_UNSND (attr
);
2920 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2921 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2922 if (cu_language
== language_fortran
)
2924 /* Need to create a unique string type for bounds
2926 type
= create_string_type (0, range_type
);
2930 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2931 type
= create_string_type (char_type
, range_type
);
2936 /* Handle DIES due to C code like:
2940 int (*funcp)(int a, long l);
2944 ('funcp' generates a DW_TAG_subroutine_type DIE)
2948 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
2949 const struct comp_unit_head
*cu_header
)
2951 struct type
*type
; /* Type that this function returns */
2952 struct type
*ftype
; /* Function that returns above type */
2953 struct attribute
*attr
;
2955 /* Decode the type that this subroutine returns */
2960 type
= die_type (die
, objfile
, cu_header
);
2961 ftype
= lookup_function_type (type
);
2963 /* All functions in C++ have prototypes. */
2964 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2965 if ((attr
&& (DW_UNSND (attr
) != 0))
2966 || cu_language
== language_cplus
)
2967 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2969 if (die
->has_children
)
2971 struct die_info
*child_die
;
2975 /* Count the number of parameters.
2976 FIXME: GDB currently ignores vararg functions, but knows about
2977 vararg member functions. */
2978 child_die
= die
->next
;
2979 while (child_die
&& child_die
->tag
)
2981 if (child_die
->tag
== DW_TAG_formal_parameter
)
2983 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2984 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2985 child_die
= sibling_die (child_die
);
2988 /* Allocate storage for parameters and fill them in. */
2989 TYPE_NFIELDS (ftype
) = nparams
;
2990 TYPE_FIELDS (ftype
) = (struct field
*)
2991 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2993 child_die
= die
->next
;
2994 while (child_die
&& child_die
->tag
)
2996 if (child_die
->tag
== DW_TAG_formal_parameter
)
2998 /* Dwarf2 has no clean way to discern C++ static and non-static
2999 member functions. G++ helps GDB by marking the first
3000 parameter for non-static member functions (which is the
3001 this pointer) as artificial. We pass this information
3002 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3003 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
3005 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
3007 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
3008 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
3012 child_die
= sibling_die (child_die
);
3020 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
3021 const struct comp_unit_head
*cu_header
)
3023 struct attribute
*attr
;
3028 attr
= dwarf_attr (die
, DW_AT_name
);
3029 if (attr
&& DW_STRING (attr
))
3031 name
= DW_STRING (attr
);
3033 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
3034 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, objfile
, cu_header
);
3038 /* Find a representation of a given base type and install
3039 it in the TYPE field of the die. */
3042 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
3045 struct attribute
*attr
;
3046 int encoding
= 0, size
= 0;
3048 /* If we've already decoded this die, this is a no-op. */
3054 attr
= dwarf_attr (die
, DW_AT_encoding
);
3057 encoding
= DW_UNSND (attr
);
3059 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3062 size
= DW_UNSND (attr
);
3064 attr
= dwarf_attr (die
, DW_AT_name
);
3065 if (attr
&& DW_STRING (attr
))
3067 enum type_code code
= TYPE_CODE_INT
;
3072 case DW_ATE_address
:
3073 /* Turn DW_ATE_address into a void * pointer. */
3074 code
= TYPE_CODE_PTR
;
3075 type_flags
|= TYPE_FLAG_UNSIGNED
;
3077 case DW_ATE_boolean
:
3078 code
= TYPE_CODE_BOOL
;
3079 type_flags
|= TYPE_FLAG_UNSIGNED
;
3081 case DW_ATE_complex_float
:
3082 code
= TYPE_CODE_COMPLEX
;
3085 code
= TYPE_CODE_FLT
;
3088 case DW_ATE_signed_char
:
3090 case DW_ATE_unsigned
:
3091 case DW_ATE_unsigned_char
:
3092 type_flags
|= TYPE_FLAG_UNSIGNED
;
3095 complain (&dwarf2_unsupported_at_encoding
,
3096 dwarf_type_encoding_name (encoding
));
3099 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
3100 if (encoding
== DW_ATE_address
)
3101 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
3102 else if (encoding
== DW_ATE_complex_float
)
3105 TYPE_TARGET_TYPE (type
)
3106 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3107 else if (size
== 16)
3108 TYPE_TARGET_TYPE (type
)
3109 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3111 TYPE_TARGET_TYPE (type
)
3112 = dwarf2_fundamental_type (objfile
, FT_FLOAT
);
3117 type
= dwarf_base_type (encoding
, size
, objfile
);
3122 /* Read a whole compilation unit into a linked list of dies. */
3124 static struct die_info
*
3125 read_comp_unit (char *info_ptr
, bfd
*abfd
,
3126 const struct comp_unit_head
*cu_header
)
3128 struct die_info
*first_die
, *last_die
, *die
;
3132 /* Reset die reference table; we are
3133 building new ones now. */
3134 dwarf2_empty_hash_tables ();
3138 first_die
= last_die
= NULL
;
3141 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
3142 if (die
->has_children
)
3153 /* Enter die in reference hash table */
3154 store_in_ref_table (die
->offset
, die
);
3158 first_die
= last_die
= die
;
3162 last_die
->next
= die
;
3166 while (nesting_level
> 0);
3170 /* Free a linked list of dies. */
3173 free_die_list (struct die_info
*dies
)
3175 struct die_info
*die
, *next
;
3188 do_free_die_list_cleanup (void *dies
)
3190 free_die_list (dies
);
3193 static struct cleanup
*
3194 make_cleanup_free_die_list (struct die_info
*dies
)
3196 return make_cleanup (do_free_die_list_cleanup
, dies
);
3200 /* Read the contents of the section at OFFSET and of size SIZE from the
3201 object file specified by OBJFILE into the psymbol_obstack and return it. */
3204 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
3207 bfd
*abfd
= objfile
->obfd
;
3213 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3214 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3215 (bfd_bread (buf
, size
, abfd
) != size
))
3218 error ("Dwarf Error: Can't read DWARF data from '%s'",
3219 bfd_get_filename (abfd
));
3224 /* In DWARF version 2, the description of the debugging information is
3225 stored in a separate .debug_abbrev section. Before we read any
3226 dies from a section we read in all abbreviations and install them
3230 dwarf2_read_abbrevs (bfd
*abfd
, unsigned int offset
)
3233 struct abbrev_info
*cur_abbrev
;
3234 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3235 unsigned int abbrev_form
, hash_number
;
3237 /* empty the table */
3238 dwarf2_empty_abbrev_table (NULL
);
3240 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3241 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3242 abbrev_ptr
+= bytes_read
;
3244 /* loop until we reach an abbrev number of 0 */
3245 while (abbrev_number
)
3247 cur_abbrev
= dwarf_alloc_abbrev ();
3249 /* read in abbrev header */
3250 cur_abbrev
->number
= abbrev_number
;
3251 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3252 abbrev_ptr
+= bytes_read
;
3253 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3256 /* now read in declarations */
3257 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3258 abbrev_ptr
+= bytes_read
;
3259 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3260 abbrev_ptr
+= bytes_read
;
3263 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3265 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3266 xrealloc (cur_abbrev
->attrs
,
3267 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3268 * sizeof (struct attr_abbrev
));
3270 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3271 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3272 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3273 abbrev_ptr
+= bytes_read
;
3274 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3275 abbrev_ptr
+= bytes_read
;
3278 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3279 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3280 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3282 /* Get next abbreviation.
3283 Under Irix6 the abbreviations for a compilation unit are not
3284 always properly terminated with an abbrev number of 0.
3285 Exit loop if we encounter an abbreviation which we have
3286 already read (which means we are about to read the abbreviations
3287 for the next compile unit) or if the end of the abbreviation
3288 table is reached. */
3289 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3290 >= dwarf_abbrev_size
)
3292 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3293 abbrev_ptr
+= bytes_read
;
3294 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3299 /* Empty the abbrev table for a new compilation unit. */
3303 dwarf2_empty_abbrev_table (PTR ignore
)
3306 struct abbrev_info
*abbrev
, *next
;
3308 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3311 abbrev
= dwarf2_abbrevs
[i
];
3314 next
= abbrev
->next
;
3315 xfree (abbrev
->attrs
);
3319 dwarf2_abbrevs
[i
] = NULL
;
3323 /* Lookup an abbrev_info structure in the abbrev hash table. */
3325 static struct abbrev_info
*
3326 dwarf2_lookup_abbrev (unsigned int number
)
3328 unsigned int hash_number
;
3329 struct abbrev_info
*abbrev
;
3331 hash_number
= number
% ABBREV_HASH_SIZE
;
3332 abbrev
= dwarf2_abbrevs
[hash_number
];
3336 if (abbrev
->number
== number
)
3339 abbrev
= abbrev
->next
;
3344 /* Read a minimal amount of information into the minimal die structure. */
3347 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3348 char *info_ptr
, const struct comp_unit_head
*cu_header
)
3350 unsigned int abbrev_number
, bytes_read
, i
;
3351 struct abbrev_info
*abbrev
;
3352 struct attribute attr
;
3353 struct attribute spec_attr
;
3354 int found_spec_attr
= 0;
3355 int has_low_pc_attr
= 0;
3356 int has_high_pc_attr
= 0;
3358 *part_die
= zeroed_partial_die
;
3359 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3360 info_ptr
+= bytes_read
;
3364 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3367 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3369 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3370 part_die
->tag
= abbrev
->tag
;
3371 part_die
->has_children
= abbrev
->has_children
;
3372 part_die
->abbrev
= abbrev_number
;
3374 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3376 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3377 info_ptr
, cu_header
);
3379 /* Store the data if it is of an attribute we want to keep in a
3380 partial symbol table. */
3385 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3386 if (part_die
->name
== NULL
)
3387 part_die
->name
= DW_STRING (&attr
);
3389 case DW_AT_MIPS_linkage_name
:
3390 part_die
->name
= DW_STRING (&attr
);
3393 has_low_pc_attr
= 1;
3394 part_die
->lowpc
= DW_ADDR (&attr
);
3397 has_high_pc_attr
= 1;
3398 part_die
->highpc
= DW_ADDR (&attr
);
3400 case DW_AT_location
:
3401 part_die
->locdesc
= DW_BLOCK (&attr
);
3403 case DW_AT_language
:
3404 part_die
->language
= DW_UNSND (&attr
);
3406 case DW_AT_external
:
3407 part_die
->is_external
= DW_UNSND (&attr
);
3409 case DW_AT_declaration
:
3410 part_die
->is_declaration
= DW_UNSND (&attr
);
3413 part_die
->has_type
= 1;
3415 case DW_AT_abstract_origin
:
3416 case DW_AT_specification
:
3417 found_spec_attr
= 1;
3421 /* Ignore absolute siblings, they might point outside of
3422 the current compile unit. */
3423 if (attr
.form
== DW_FORM_ref_addr
)
3424 complain (&dwarf2_absolute_sibling_complaint
);
3427 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3434 /* If we found a reference attribute and the die has no name, try
3435 to find a name in the referred to die. */
3437 if (found_spec_attr
&& part_die
->name
== NULL
)
3439 struct partial_die_info spec_die
;
3443 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3444 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu_header
);
3447 part_die
->name
= spec_die
.name
;
3449 /* Copy DW_AT_external attribute if it is set. */
3450 if (spec_die
.is_external
)
3451 part_die
->is_external
= spec_die
.is_external
;
3455 /* When using the GNU linker, .gnu.linkonce. sections are used to
3456 eliminate duplicate copies of functions and vtables and such.
3457 The linker will arbitrarily choose one and discard the others.
3458 The AT_*_pc values for such functions refer to local labels in
3459 these sections. If the section from that file was discarded, the
3460 labels are not in the output, so the relocs get a value of 0.
3461 If this is a discarded function, mark the pc bounds as invalid,
3462 so that GDB will ignore it. */
3463 if (has_low_pc_attr
&& has_high_pc_attr
3464 && part_die
->lowpc
< part_die
->highpc
3465 && (part_die
->lowpc
!= 0
3466 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3467 part_die
->has_pc_info
= 1;
3471 /* Read the die from the .debug_info section buffer. And set diep to
3472 point to a newly allocated die with its information. */
3475 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3476 const struct comp_unit_head
*cu_header
)
3478 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3479 struct abbrev_info
*abbrev
;
3480 struct die_info
*die
;
3482 offset
= info_ptr
- dwarf_info_buffer
;
3483 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3484 info_ptr
+= bytes_read
;
3487 die
= dwarf_alloc_die ();
3489 die
->abbrev
= abbrev_number
;
3495 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3498 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3500 die
= dwarf_alloc_die ();
3501 die
->offset
= offset
;
3502 die
->tag
= abbrev
->tag
;
3503 die
->has_children
= abbrev
->has_children
;
3504 die
->abbrev
= abbrev_number
;
3507 die
->num_attrs
= abbrev
->num_attrs
;
3508 die
->attrs
= (struct attribute
*)
3509 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3511 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3513 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3514 abfd
, info_ptr
, cu_header
);
3521 /* Read an attribute value described by an attribute form. */
3524 read_attribute_value (struct attribute
*attr
, unsigned form
,
3525 bfd
*abfd
, char *info_ptr
,
3526 const struct comp_unit_head
*cu_header
)
3528 unsigned int bytes_read
;
3529 struct dwarf_block
*blk
;
3535 case DW_FORM_ref_addr
:
3536 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3537 info_ptr
+= bytes_read
;
3539 case DW_FORM_block2
:
3540 blk
= dwarf_alloc_block ();
3541 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3543 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3544 info_ptr
+= blk
->size
;
3545 DW_BLOCK (attr
) = blk
;
3547 case DW_FORM_block4
:
3548 blk
= dwarf_alloc_block ();
3549 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3551 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3552 info_ptr
+= blk
->size
;
3553 DW_BLOCK (attr
) = blk
;
3556 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3560 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3564 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3567 case DW_FORM_string
:
3568 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3569 info_ptr
+= bytes_read
;
3572 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
3574 info_ptr
+= bytes_read
;
3577 blk
= dwarf_alloc_block ();
3578 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3579 info_ptr
+= bytes_read
;
3580 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3581 info_ptr
+= blk
->size
;
3582 DW_BLOCK (attr
) = blk
;
3584 case DW_FORM_block1
:
3585 blk
= dwarf_alloc_block ();
3586 blk
->size
= read_1_byte (abfd
, info_ptr
);
3588 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3589 info_ptr
+= blk
->size
;
3590 DW_BLOCK (attr
) = blk
;
3593 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3597 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3601 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3602 info_ptr
+= bytes_read
;
3605 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3606 info_ptr
+= bytes_read
;
3609 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3613 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3617 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3621 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3624 case DW_FORM_ref_udata
:
3625 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3626 info_ptr
+= bytes_read
;
3628 case DW_FORM_indirect
:
3629 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3630 info_ptr
+= bytes_read
;
3631 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu_header
);
3634 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3635 dwarf_form_name (form
));
3640 /* Read an attribute described by an abbreviated attribute. */
3643 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
3644 bfd
*abfd
, char *info_ptr
,
3645 const struct comp_unit_head
*cu_header
)
3647 attr
->name
= abbrev
->name
;
3648 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu_header
);
3651 /* read dwarf information from a buffer */
3654 read_1_byte (bfd
*abfd
, char *buf
)
3656 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3660 read_1_signed_byte (bfd
*abfd
, char *buf
)
3662 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3666 read_2_bytes (bfd
*abfd
, char *buf
)
3668 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3672 read_2_signed_bytes (bfd
*abfd
, char *buf
)
3674 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3678 read_4_bytes (bfd
*abfd
, char *buf
)
3680 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3684 read_4_signed_bytes (bfd
*abfd
, char *buf
)
3686 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3689 static unsigned long
3690 read_8_bytes (bfd
*abfd
, char *buf
)
3692 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3696 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3699 CORE_ADDR retval
= 0;
3701 if (cu_header
->signed_addr_p
)
3703 switch (cu_header
->addr_size
)
3706 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3709 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3712 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
3715 internal_error (__FILE__
, __LINE__
,
3716 "read_address: bad switch, signed");
3721 switch (cu_header
->addr_size
)
3724 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3727 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3730 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3733 internal_error (__FILE__
, __LINE__
,
3734 "read_address: bad switch, unsigned");
3738 *bytes_read
= cu_header
->addr_size
;
3742 /* Reads the initial length from a section. The (draft) DWARF 2.1
3743 specification allows the initial length to take up either 4 bytes
3744 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
3745 bytes describe the length and all offsets will be 8 bytes in length
3748 The value returned via bytes_read should be used to increment
3749 the relevant pointer after calling read_initial_length().
3751 As a side effect, this function sets the fields initial_length_size
3752 and offset_size in cu_header to the values appropriate for the
3753 length field. (The format of the initial length field determines
3754 the width of file offsets to be fetched later with fetch_offset().)
3756 [ Note: read_initial_length() and read_offset() are based on the
3757 document entitled "DWARF Debugging Information Format", revision
3758 2.1, draft 4, dated July 20, 2000. This document was obtained
3761 http://reality.sgi.com/dehnert_engr/dwarf/dwarf2p1-draft4-000720.pdf
3763 This document is only a draft and is subject to change. (So beware.)
3765 - Kevin, Aug 4, 2000
3769 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
3774 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3776 if (retval
== 0xffffffff)
3778 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
3780 if (cu_header
!= NULL
)
3782 cu_header
->initial_length_size
= 12;
3783 cu_header
->offset_size
= 8;
3789 if (cu_header
!= NULL
)
3791 cu_header
->initial_length_size
= 4;
3792 cu_header
->offset_size
= 4;
3799 /* Read an offset from the data stream. The size of the offset is
3800 given by cu_header->offset_size. */
3803 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3808 switch (cu_header
->offset_size
)
3811 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3815 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3819 internal_error (__FILE__
, __LINE__
,
3820 "read_offset: bad switch");
3827 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
3829 /* If the size of a host char is 8 bits, we can return a pointer
3830 to the buffer, otherwise we have to copy the data to a buffer
3831 allocated on the temporary obstack. */
3832 gdb_assert (HOST_CHAR_BIT
== 8);
3837 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3839 /* If the size of a host char is 8 bits, we can return a pointer
3840 to the string, otherwise we have to copy the string to a buffer
3841 allocated on the temporary obstack. */
3842 gdb_assert (HOST_CHAR_BIT
== 8);
3845 *bytes_read_ptr
= 1;
3848 *bytes_read_ptr
= strlen (buf
) + 1;
3853 read_indirect_string (bfd
*abfd
, char *buf
,
3854 const struct comp_unit_head
*cu_header
,
3855 unsigned int *bytes_read_ptr
)
3857 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
3858 (int *) bytes_read_ptr
);
3860 if (dwarf_str_buffer
== NULL
)
3862 error ("DW_FORM_strp used without .debug_str section");
3865 if (str_offset
>= dwarf_str_size
)
3867 error ("DW_FORM_strp pointing outside of .debug_str section");
3870 gdb_assert (HOST_CHAR_BIT
== 8);
3871 if (dwarf_str_buffer
[str_offset
] == '\0')
3873 return dwarf_str_buffer
+ str_offset
;
3876 static unsigned long
3877 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3879 unsigned long result
;
3880 unsigned int num_read
;
3890 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3893 result
|= ((unsigned long)(byte
& 127) << shift
);
3894 if ((byte
& 128) == 0)
3900 *bytes_read_ptr
= num_read
;
3905 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3908 int i
, shift
, size
, num_read
;
3918 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3921 result
|= ((long)(byte
& 127) << shift
);
3923 if ((byte
& 128) == 0)
3928 if ((shift
< size
) && (byte
& 0x40))
3930 result
|= -(1 << shift
);
3932 *bytes_read_ptr
= num_read
;
3937 set_cu_language (unsigned int lang
)
3943 cu_language
= language_c
;
3945 case DW_LANG_C_plus_plus
:
3946 cu_language
= language_cplus
;
3948 case DW_LANG_Fortran77
:
3949 case DW_LANG_Fortran90
:
3950 case DW_LANG_Fortran95
:
3951 cu_language
= language_fortran
;
3953 case DW_LANG_Mips_Assembler
:
3954 cu_language
= language_asm
;
3957 cu_language
= language_java
;
3960 case DW_LANG_Cobol74
:
3961 case DW_LANG_Cobol85
:
3962 case DW_LANG_Pascal83
:
3963 case DW_LANG_Modula2
:
3965 cu_language
= language_unknown
;
3968 cu_language_defn
= language_def (cu_language
);
3971 /* Return the named attribute or NULL if not there. */
3973 static struct attribute
*
3974 dwarf_attr (struct die_info
*die
, unsigned int name
)
3977 struct attribute
*spec
= NULL
;
3979 for (i
= 0; i
< die
->num_attrs
; ++i
)
3981 if (die
->attrs
[i
].name
== name
)
3983 return &die
->attrs
[i
];
3985 if (die
->attrs
[i
].name
== DW_AT_specification
3986 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3987 spec
= &die
->attrs
[i
];
3991 struct die_info
*ref_die
=
3992 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3995 return dwarf_attr (ref_die
, name
);
4002 die_is_declaration (struct die_info
*die
)
4004 return (dwarf_attr (die
, DW_AT_declaration
)
4005 && ! dwarf_attr (die
, DW_AT_specification
));
4009 /* Free the line_header structure *LH, and any arrays and strings it
4012 free_line_header (struct line_header
*lh
)
4014 if (lh
->standard_opcode_lengths
)
4015 free (lh
->standard_opcode_lengths
);
4017 /* Remember that all the lh->file_names[i].name pointers are
4018 pointers into debug_line_buffer, and don't need to be freed. */
4020 free (lh
->file_names
);
4022 /* Similarly for the include directory names. */
4023 if (lh
->include_dirs
)
4024 free (lh
->include_dirs
);
4030 /* Add an entry to LH's include directory table. */
4032 add_include_dir (struct line_header
*lh
, char *include_dir
)
4034 /* Grow the array if necessary. */
4035 if (lh
->include_dirs_size
== 0)
4037 lh
->include_dirs_size
= 1; /* for testing */
4038 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
4039 * sizeof (*lh
->include_dirs
));
4041 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
4043 lh
->include_dirs_size
*= 2;
4044 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
4045 (lh
->include_dirs_size
4046 * sizeof (*lh
->include_dirs
)));
4049 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
4053 /* Add an entry to LH's file name table. */
4055 add_file_name (struct line_header
*lh
,
4057 unsigned int dir_index
,
4058 unsigned int mod_time
,
4059 unsigned int length
)
4061 struct file_entry
*fe
;
4063 /* Grow the array if necessary. */
4064 if (lh
->file_names_size
== 0)
4066 lh
->file_names_size
= 1; /* for testing */
4067 lh
->file_names
= xmalloc (lh
->file_names_size
4068 * sizeof (*lh
->file_names
));
4070 else if (lh
->num_file_names
>= lh
->file_names_size
)
4072 lh
->file_names_size
*= 2;
4073 lh
->file_names
= xrealloc (lh
->file_names
,
4074 (lh
->file_names_size
4075 * sizeof (*lh
->file_names
)));
4078 fe
= &lh
->file_names
[lh
->num_file_names
++];
4080 fe
->dir_index
= dir_index
;
4081 fe
->mod_time
= mod_time
;
4082 fe
->length
= length
;
4086 /* Read the statement program header starting at OFFSET in
4087 dwarf_line_buffer, according to the endianness of ABFD. Return a
4088 pointer to a struct line_header, allocated using xmalloc.
4090 NOTE: the strings in the include directory and file name tables of
4091 the returned object point into debug_line_buffer, and must not be
4093 static struct line_header
*
4094 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
4095 const struct comp_unit_head
*cu_header
)
4097 struct cleanup
*back_to
;
4098 struct line_header
*lh
;
4102 char *cur_dir
, *cur_file
;
4104 if (dwarf_line_buffer
== NULL
)
4106 complain (&dwarf2_missing_line_number_section
);
4110 /* Make sure that at least there's room for the total_length field. That
4111 could be 12 bytes long, but we're just going to fudge that. */
4112 if (offset
+ 4 >= dwarf_line_size
)
4114 complain (&dwarf2_statement_list_fits_in_line_number_section
);
4118 lh
= xmalloc (sizeof (*lh
));
4119 memset (lh
, 0, sizeof (*lh
));
4120 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
4123 line_ptr
= dwarf_line_buffer
+ offset
;
4125 /* read in the header */
4126 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
4127 line_ptr
+= bytes_read
;
4128 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
4130 complain (&dwarf2_statement_list_fits_in_line_number_section
);
4133 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
4134 lh
->version
= read_2_bytes (abfd
, line_ptr
);
4136 lh
->header_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
4137 line_ptr
+= bytes_read
;
4138 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
4140 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
4142 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
4144 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
4146 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
4148 lh
->standard_opcode_lengths
4149 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
4151 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
4152 for (i
= 1; i
< lh
->opcode_base
; ++i
)
4154 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
4158 /* Read directory table */
4159 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4161 line_ptr
+= bytes_read
;
4162 add_include_dir (lh
, cur_dir
);
4164 line_ptr
+= bytes_read
;
4166 /* Read file name table */
4167 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4169 unsigned int dir_index
, mod_time
, length
;
4171 line_ptr
+= bytes_read
;
4172 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4173 line_ptr
+= bytes_read
;
4174 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4175 line_ptr
+= bytes_read
;
4176 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4177 line_ptr
+= bytes_read
;
4179 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4181 line_ptr
+= bytes_read
;
4182 lh
->statement_program_start
= line_ptr
;
4184 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
4185 complain (&dwarf2_line_header_too_long
);
4187 discard_cleanups (back_to
);
4191 /* This function exists to work around a bug in certain compilers
4192 (particularly GCC 2.95), in which the first line number marker of a
4193 function does not show up until after the prologue, right before
4194 the second line number marker. This function shifts ADDRESS down
4195 to the beginning of the function if necessary, and is called on
4196 addresses passed to record_line. */
4199 check_cu_functions (CORE_ADDR address
)
4201 struct function_range
*fn
;
4203 /* Find the function_range containing address. */
4208 cu_cached_fn
= cu_first_fn
;
4212 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4218 while (fn
&& fn
!= cu_cached_fn
)
4219 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4229 if (address
!= fn
->lowpc
)
4230 complain (&dwarf2_misplaced_line_number
,
4231 (unsigned long) address
, fn
->name
);
4236 /* Decode the line number information for the compilation unit whose
4237 line number info is at OFFSET in the .debug_line section.
4238 The compilation directory of the file is passed in COMP_DIR. */
4241 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
4242 const struct comp_unit_head
*cu_header
)
4246 unsigned int i
, bytes_read
;
4248 unsigned char op_code
, extended_op
, adj_opcode
;
4250 line_ptr
= lh
->statement_program_start
;
4251 line_end
= lh
->statement_program_end
;
4253 /* Read the statement sequences until there's nothing left. */
4254 while (line_ptr
< line_end
)
4256 /* state machine registers */
4257 CORE_ADDR address
= 0;
4258 unsigned int file
= 1;
4259 unsigned int line
= 1;
4260 unsigned int column
= 0;
4261 int is_stmt
= lh
->default_is_stmt
;
4262 int basic_block
= 0;
4263 int end_sequence
= 0;
4265 /* Start a subfile for the current file of the state machine. */
4266 if (lh
->num_file_names
>= file
)
4268 /* lh->include_dirs and lh->file_names are 0-based, but the
4269 directory and file name numbers in the statement program
4271 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
4274 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4277 dwarf2_start_subfile (fe
->name
, dir
);
4280 /* Decode the table. */
4281 while (!end_sequence
)
4283 op_code
= read_1_byte (abfd
, line_ptr
);
4286 if (op_code
>= lh
->opcode_base
)
4287 { /* Special operand. */
4288 adj_opcode
= op_code
- lh
->opcode_base
;
4289 address
+= (adj_opcode
/ lh
->line_range
)
4290 * lh
->minimum_instruction_length
;
4291 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
4292 /* append row to matrix using current values */
4293 address
= check_cu_functions (address
);
4294 record_line (current_subfile
, line
, address
);
4297 else switch (op_code
)
4299 case DW_LNS_extended_op
:
4300 line_ptr
+= 1; /* ignore length */
4301 extended_op
= read_1_byte (abfd
, line_ptr
);
4303 switch (extended_op
)
4305 case DW_LNE_end_sequence
:
4307 record_line (current_subfile
, 0, address
);
4309 case DW_LNE_set_address
:
4310 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
4311 line_ptr
+= bytes_read
;
4312 address
+= baseaddr
;
4314 case DW_LNE_define_file
:
4317 unsigned int dir_index
, mod_time
, length
;
4319 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
4320 line_ptr
+= bytes_read
;
4322 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4323 line_ptr
+= bytes_read
;
4325 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4326 line_ptr
+= bytes_read
;
4328 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4329 line_ptr
+= bytes_read
;
4330 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4334 complain (&dwarf2_mangled_line_number_section
);
4339 address
= check_cu_functions (address
);
4340 record_line (current_subfile
, line
, address
);
4343 case DW_LNS_advance_pc
:
4344 address
+= lh
->minimum_instruction_length
4345 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4346 line_ptr
+= bytes_read
;
4348 case DW_LNS_advance_line
:
4349 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
4350 line_ptr
+= bytes_read
;
4352 case DW_LNS_set_file
:
4354 /* lh->include_dirs and lh->file_names are 0-based,
4355 but the directory and file name numbers in the
4356 statement program are 1-based. */
4357 struct file_entry
*fe
;
4359 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4360 line_ptr
+= bytes_read
;
4361 fe
= &lh
->file_names
[file
- 1];
4363 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4366 dwarf2_start_subfile (fe
->name
, dir
);
4369 case DW_LNS_set_column
:
4370 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4371 line_ptr
+= bytes_read
;
4373 case DW_LNS_negate_stmt
:
4374 is_stmt
= (!is_stmt
);
4376 case DW_LNS_set_basic_block
:
4379 /* Add to the address register of the state machine the
4380 address increment value corresponding to special opcode
4381 255. Ie, this value is scaled by the minimum instruction
4382 length since special opcode 255 would have scaled the
4384 case DW_LNS_const_add_pc
:
4385 address
+= (lh
->minimum_instruction_length
4386 * ((255 - lh
->opcode_base
) / lh
->line_range
));
4388 case DW_LNS_fixed_advance_pc
:
4389 address
+= read_2_bytes (abfd
, line_ptr
);
4393 { /* Unknown standard opcode, ignore it. */
4395 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
4397 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4398 line_ptr
+= bytes_read
;
4406 /* Start a subfile for DWARF. FILENAME is the name of the file and
4407 DIRNAME the name of the source directory which contains FILENAME
4408 or NULL if not known.
4409 This routine tries to keep line numbers from identical absolute and
4410 relative file names in a common subfile.
4412 Using the `list' example from the GDB testsuite, which resides in
4413 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4414 of /srcdir/list0.c yields the following debugging information for list0.c:
4416 DW_AT_name: /srcdir/list0.c
4417 DW_AT_comp_dir: /compdir
4418 files.files[0].name: list0.h
4419 files.files[0].dir: /srcdir
4420 files.files[1].name: list0.c
4421 files.files[1].dir: /srcdir
4423 The line number information for list0.c has to end up in a single
4424 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4427 dwarf2_start_subfile (char *filename
, char *dirname
)
4429 /* If the filename isn't absolute, try to match an existing subfile
4430 with the full pathname. */
4432 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
4434 struct subfile
*subfile
;
4435 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4437 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4439 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
4441 current_subfile
= subfile
;
4448 start_subfile (filename
, dirname
);
4451 /* Given a pointer to a DWARF information entry, figure out if we need
4452 to make a symbol table entry for it, and if so, create a new entry
4453 and return a pointer to it.
4454 If TYPE is NULL, determine symbol type from the die, otherwise
4455 used the passed type. */
4457 static struct symbol
*
4458 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
4459 const struct comp_unit_head
*cu_header
)
4461 struct symbol
*sym
= NULL
;
4463 struct attribute
*attr
= NULL
;
4464 struct attribute
*attr2
= NULL
;
4467 name
= dwarf2_linkage_name (die
);
4470 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4471 sizeof (struct symbol
));
4472 OBJSTAT (objfile
, n_syms
++);
4473 memset (sym
, 0, sizeof (struct symbol
));
4474 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4475 &objfile
->symbol_obstack
);
4477 /* Default assumptions.
4478 Use the passed type or decode it from the die. */
4479 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4480 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4482 SYMBOL_TYPE (sym
) = type
;
4484 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
4485 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4488 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4491 /* If this symbol is from a C++ compilation, then attempt to
4492 cache the demangled form for future reference. This is a
4493 typical time versus space tradeoff, that was decided in favor
4494 of time because it sped up C++ symbol lookups by a factor of
4497 SYMBOL_LANGUAGE (sym
) = cu_language
;
4498 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4502 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4505 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4507 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4509 case DW_TAG_subprogram
:
4510 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4512 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4513 attr2
= dwarf_attr (die
, DW_AT_external
);
4514 if (attr2
&& (DW_UNSND (attr2
) != 0))
4516 add_symbol_to_list (sym
, &global_symbols
);
4520 add_symbol_to_list (sym
, list_in_scope
);
4523 case DW_TAG_variable
:
4524 /* Compilation with minimal debug info may result in variables
4525 with missing type entries. Change the misleading `void' type
4526 to something sensible. */
4527 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4528 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4529 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4530 "<variable, no debug info>",
4532 attr
= dwarf_attr (die
, DW_AT_const_value
);
4535 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4536 attr2
= dwarf_attr (die
, DW_AT_external
);
4537 if (attr2
&& (DW_UNSND (attr2
) != 0))
4538 add_symbol_to_list (sym
, &global_symbols
);
4540 add_symbol_to_list (sym
, list_in_scope
);
4543 attr
= dwarf_attr (die
, DW_AT_location
);
4546 attr2
= dwarf_attr (die
, DW_AT_external
);
4547 if (attr2
&& (DW_UNSND (attr2
) != 0))
4549 SYMBOL_VALUE_ADDRESS (sym
) =
4550 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4551 add_symbol_to_list (sym
, &global_symbols
);
4553 /* In shared libraries the address of the variable
4554 in the location descriptor might still be relocatable,
4555 so its value could be zero.
4556 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4557 value is zero, the address of the variable will then
4558 be determined from the minimal symbol table whenever
4559 the variable is referenced. */
4560 if (SYMBOL_VALUE_ADDRESS (sym
))
4562 fixup_symbol_section (sym
, objfile
);
4563 SYMBOL_VALUE_ADDRESS (sym
) +=
4564 ANOFFSET (objfile
->section_offsets
,
4565 SYMBOL_SECTION (sym
));
4566 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4569 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4573 SYMBOL_VALUE (sym
) = addr
=
4574 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4575 add_symbol_to_list (sym
, list_in_scope
);
4578 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4582 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4583 SYMBOL_VALUE (sym
) =
4584 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4588 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4589 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4593 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4597 fixup_symbol_section (sym
, objfile
);
4598 SYMBOL_VALUE_ADDRESS (sym
) =
4599 addr
+ ANOFFSET (objfile
->section_offsets
,
4600 SYMBOL_SECTION (sym
));
4601 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4607 /* We do not know the address of this symbol.
4608 If it is an external symbol and we have type information
4609 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4610 The address of the variable will then be determined from
4611 the minimal symbol table whenever the variable is
4613 attr2
= dwarf_attr (die
, DW_AT_external
);
4614 if (attr2
&& (DW_UNSND (attr2
) != 0)
4615 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4617 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4618 add_symbol_to_list (sym
, &global_symbols
);
4622 case DW_TAG_formal_parameter
:
4623 attr
= dwarf_attr (die
, DW_AT_location
);
4626 SYMBOL_VALUE (sym
) =
4627 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4630 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4631 SYMBOL_VALUE (sym
) =
4632 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4638 if (basereg
!= frame_base_reg
)
4639 complain (&dwarf2_complex_location_expr
);
4640 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4644 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4645 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4650 SYMBOL_CLASS (sym
) = LOC_ARG
;
4653 attr
= dwarf_attr (die
, DW_AT_const_value
);
4656 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4658 add_symbol_to_list (sym
, list_in_scope
);
4660 case DW_TAG_unspecified_parameters
:
4661 /* From varargs functions; gdb doesn't seem to have any
4662 interest in this information, so just ignore it for now.
4665 case DW_TAG_class_type
:
4666 case DW_TAG_structure_type
:
4667 case DW_TAG_union_type
:
4668 case DW_TAG_enumeration_type
:
4669 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4670 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4671 add_symbol_to_list (sym
, list_in_scope
);
4673 /* The semantics of C++ state that "struct foo { ... }" also
4674 defines a typedef for "foo". Synthesize a typedef symbol so
4675 that "ptype foo" works as expected. */
4676 if (cu_language
== language_cplus
)
4678 struct symbol
*typedef_sym
= (struct symbol
*)
4679 obstack_alloc (&objfile
->symbol_obstack
,
4680 sizeof (struct symbol
));
4681 *typedef_sym
= *sym
;
4682 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4683 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4684 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4685 obsavestring (SYMBOL_NAME (sym
),
4686 strlen (SYMBOL_NAME (sym
)),
4687 &objfile
->type_obstack
);
4688 add_symbol_to_list (typedef_sym
, list_in_scope
);
4691 case DW_TAG_typedef
:
4692 case DW_TAG_base_type
:
4693 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4694 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4695 add_symbol_to_list (sym
, list_in_scope
);
4697 case DW_TAG_enumerator
:
4698 attr
= dwarf_attr (die
, DW_AT_const_value
);
4701 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4703 add_symbol_to_list (sym
, list_in_scope
);
4706 /* Not a tag we recognize. Hopefully we aren't processing
4707 trash data, but since we must specifically ignore things
4708 we don't recognize, there is nothing else we should do at
4710 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4717 /* Copy constant value from an attribute to a symbol. */
4720 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
4721 struct objfile
*objfile
,
4722 const struct comp_unit_head
*cu_header
)
4724 struct dwarf_block
*blk
;
4729 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
4730 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4731 cu_header
->addr_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4732 SYMBOL_VALUE_BYTES (sym
) = (char *)
4733 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
4734 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
4736 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4738 case DW_FORM_block1
:
4739 case DW_FORM_block2
:
4740 case DW_FORM_block4
:
4742 blk
= DW_BLOCK (attr
);
4743 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4744 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4745 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4746 SYMBOL_VALUE_BYTES (sym
) = (char *)
4747 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4748 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4749 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4752 /* The DW_AT_const_value attributes are supposed to carry the
4753 symbol's value "represented as it would be on the target
4754 architecture." By the time we get here, it's already been
4755 converted to host endianness, so we just need to sign- or
4756 zero-extend it as appropriate. */
4758 dwarf2_const_value_data (attr
, sym
, 8);
4761 dwarf2_const_value_data (attr
, sym
, 16);
4764 dwarf2_const_value_data (attr
, sym
, 32);
4767 dwarf2_const_value_data (attr
, sym
, 64);
4771 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4772 SYMBOL_CLASS (sym
) = LOC_CONST
;
4776 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4777 SYMBOL_CLASS (sym
) = LOC_CONST
;
4781 complain (&dwarf2_unsupported_const_value_attr
,
4782 dwarf_form_name (attr
->form
));
4783 SYMBOL_VALUE (sym
) = 0;
4784 SYMBOL_CLASS (sym
) = LOC_CONST
;
4790 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4791 or zero-extend it as appropriate for the symbol's type. */
4793 dwarf2_const_value_data (struct attribute
*attr
,
4797 LONGEST l
= DW_UNSND (attr
);
4799 if (bits
< sizeof (l
) * 8)
4801 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4802 l
&= ((LONGEST
) 1 << bits
) - 1;
4804 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4807 SYMBOL_VALUE (sym
) = l
;
4808 SYMBOL_CLASS (sym
) = LOC_CONST
;
4812 /* Return the type of the die in question using its DW_AT_type attribute. */
4814 static struct type
*
4815 die_type (struct die_info
*die
, struct objfile
*objfile
,
4816 const struct comp_unit_head
*cu_header
)
4819 struct attribute
*type_attr
;
4820 struct die_info
*type_die
;
4823 type_attr
= dwarf_attr (die
, DW_AT_type
);
4826 /* A missing DW_AT_type represents a void type. */
4827 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4831 ref
= dwarf2_get_ref_die_offset (type_attr
);
4832 type_die
= follow_die_ref (ref
);
4835 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4839 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4842 dump_die (type_die
);
4843 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4848 /* Return the containing type of the die in question using its
4849 DW_AT_containing_type attribute. */
4851 static struct type
*
4852 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
4853 const struct comp_unit_head
*cu_header
)
4855 struct type
*type
= NULL
;
4856 struct attribute
*type_attr
;
4857 struct die_info
*type_die
= NULL
;
4860 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4863 ref
= dwarf2_get_ref_die_offset (type_attr
);
4864 type_die
= follow_die_ref (ref
);
4867 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4870 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4875 dump_die (type_die
);
4876 error ("Dwarf Error: Problem turning containing type into gdb type.");
4882 static struct type
*
4883 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
4885 struct die_info
*die
;
4888 die
= follow_die_ref (offset
);
4891 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4894 type
= tag_type_to_type (die
, objfile
);
4899 static struct type
*
4900 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
4901 const struct comp_unit_head
*cu_header
)
4909 read_type_die (die
, objfile
, cu_header
);
4913 error ("Dwarf Error: Cannot find type of die.");
4920 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
4921 const struct comp_unit_head
*cu_header
)
4925 case DW_TAG_class_type
:
4926 case DW_TAG_structure_type
:
4927 case DW_TAG_union_type
:
4928 read_structure_scope (die
, objfile
, cu_header
);
4930 case DW_TAG_enumeration_type
:
4931 read_enumeration (die
, objfile
, cu_header
);
4933 case DW_TAG_subprogram
:
4934 case DW_TAG_subroutine_type
:
4935 read_subroutine_type (die
, objfile
, cu_header
);
4937 case DW_TAG_array_type
:
4938 read_array_type (die
, objfile
, cu_header
);
4940 case DW_TAG_pointer_type
:
4941 read_tag_pointer_type (die
, objfile
, cu_header
);
4943 case DW_TAG_ptr_to_member_type
:
4944 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
4946 case DW_TAG_reference_type
:
4947 read_tag_reference_type (die
, objfile
, cu_header
);
4949 case DW_TAG_const_type
:
4950 read_tag_const_type (die
, objfile
, cu_header
);
4952 case DW_TAG_volatile_type
:
4953 read_tag_volatile_type (die
, objfile
, cu_header
);
4955 case DW_TAG_string_type
:
4956 read_tag_string_type (die
, objfile
);
4958 case DW_TAG_typedef
:
4959 read_typedef (die
, objfile
, cu_header
);
4961 case DW_TAG_base_type
:
4962 read_base_type (die
, objfile
);
4965 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4970 static struct type
*
4971 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
4973 /* FIXME - this should not produce a new (struct type *)
4974 every time. It should cache base types. */
4978 case DW_ATE_address
:
4979 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4981 case DW_ATE_boolean
:
4982 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4984 case DW_ATE_complex_float
:
4987 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4991 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4997 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
5001 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
5008 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5011 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
5015 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5019 case DW_ATE_signed_char
:
5020 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5022 case DW_ATE_unsigned
:
5026 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5029 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
5033 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
5037 case DW_ATE_unsigned_char
:
5038 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5041 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5048 copy_die (struct die_info
*old_die
)
5050 struct die_info
*new_die
;
5053 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5054 memset (new_die
, 0, sizeof (struct die_info
));
5056 new_die
->tag
= old_die
->tag
;
5057 new_die
->has_children
= old_die
->has_children
;
5058 new_die
->abbrev
= old_die
->abbrev
;
5059 new_die
->offset
= old_die
->offset
;
5060 new_die
->type
= NULL
;
5062 num_attrs
= old_die
->num_attrs
;
5063 new_die
->num_attrs
= num_attrs
;
5064 new_die
->attrs
= (struct attribute
*)
5065 xmalloc (num_attrs
* sizeof (struct attribute
));
5067 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
5069 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
5070 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
5071 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
5074 new_die
->next
= NULL
;
5079 /* Return sibling of die, NULL if no sibling. */
5081 static struct die_info
*
5082 sibling_die (struct die_info
*die
)
5084 int nesting_level
= 0;
5086 if (!die
->has_children
)
5088 if (die
->next
&& (die
->next
->tag
== 0))
5101 if (die
->has_children
)
5111 while (nesting_level
);
5112 if (die
&& (die
->tag
== 0))
5123 /* Get linkage name of a die, return NULL if not found. */
5126 dwarf2_linkage_name (struct die_info
*die
)
5128 struct attribute
*attr
;
5130 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
5131 if (attr
&& DW_STRING (attr
))
5132 return DW_STRING (attr
);
5133 attr
= dwarf_attr (die
, DW_AT_name
);
5134 if (attr
&& DW_STRING (attr
))
5135 return DW_STRING (attr
);
5139 /* Convert a DIE tag into its string name. */
5142 dwarf_tag_name (register unsigned tag
)
5146 case DW_TAG_padding
:
5147 return "DW_TAG_padding";
5148 case DW_TAG_array_type
:
5149 return "DW_TAG_array_type";
5150 case DW_TAG_class_type
:
5151 return "DW_TAG_class_type";
5152 case DW_TAG_entry_point
:
5153 return "DW_TAG_entry_point";
5154 case DW_TAG_enumeration_type
:
5155 return "DW_TAG_enumeration_type";
5156 case DW_TAG_formal_parameter
:
5157 return "DW_TAG_formal_parameter";
5158 case DW_TAG_imported_declaration
:
5159 return "DW_TAG_imported_declaration";
5161 return "DW_TAG_label";
5162 case DW_TAG_lexical_block
:
5163 return "DW_TAG_lexical_block";
5165 return "DW_TAG_member";
5166 case DW_TAG_pointer_type
:
5167 return "DW_TAG_pointer_type";
5168 case DW_TAG_reference_type
:
5169 return "DW_TAG_reference_type";
5170 case DW_TAG_compile_unit
:
5171 return "DW_TAG_compile_unit";
5172 case DW_TAG_string_type
:
5173 return "DW_TAG_string_type";
5174 case DW_TAG_structure_type
:
5175 return "DW_TAG_structure_type";
5176 case DW_TAG_subroutine_type
:
5177 return "DW_TAG_subroutine_type";
5178 case DW_TAG_typedef
:
5179 return "DW_TAG_typedef";
5180 case DW_TAG_union_type
:
5181 return "DW_TAG_union_type";
5182 case DW_TAG_unspecified_parameters
:
5183 return "DW_TAG_unspecified_parameters";
5184 case DW_TAG_variant
:
5185 return "DW_TAG_variant";
5186 case DW_TAG_common_block
:
5187 return "DW_TAG_common_block";
5188 case DW_TAG_common_inclusion
:
5189 return "DW_TAG_common_inclusion";
5190 case DW_TAG_inheritance
:
5191 return "DW_TAG_inheritance";
5192 case DW_TAG_inlined_subroutine
:
5193 return "DW_TAG_inlined_subroutine";
5195 return "DW_TAG_module";
5196 case DW_TAG_ptr_to_member_type
:
5197 return "DW_TAG_ptr_to_member_type";
5198 case DW_TAG_set_type
:
5199 return "DW_TAG_set_type";
5200 case DW_TAG_subrange_type
:
5201 return "DW_TAG_subrange_type";
5202 case DW_TAG_with_stmt
:
5203 return "DW_TAG_with_stmt";
5204 case DW_TAG_access_declaration
:
5205 return "DW_TAG_access_declaration";
5206 case DW_TAG_base_type
:
5207 return "DW_TAG_base_type";
5208 case DW_TAG_catch_block
:
5209 return "DW_TAG_catch_block";
5210 case DW_TAG_const_type
:
5211 return "DW_TAG_const_type";
5212 case DW_TAG_constant
:
5213 return "DW_TAG_constant";
5214 case DW_TAG_enumerator
:
5215 return "DW_TAG_enumerator";
5216 case DW_TAG_file_type
:
5217 return "DW_TAG_file_type";
5219 return "DW_TAG_friend";
5220 case DW_TAG_namelist
:
5221 return "DW_TAG_namelist";
5222 case DW_TAG_namelist_item
:
5223 return "DW_TAG_namelist_item";
5224 case DW_TAG_packed_type
:
5225 return "DW_TAG_packed_type";
5226 case DW_TAG_subprogram
:
5227 return "DW_TAG_subprogram";
5228 case DW_TAG_template_type_param
:
5229 return "DW_TAG_template_type_param";
5230 case DW_TAG_template_value_param
:
5231 return "DW_TAG_template_value_param";
5232 case DW_TAG_thrown_type
:
5233 return "DW_TAG_thrown_type";
5234 case DW_TAG_try_block
:
5235 return "DW_TAG_try_block";
5236 case DW_TAG_variant_part
:
5237 return "DW_TAG_variant_part";
5238 case DW_TAG_variable
:
5239 return "DW_TAG_variable";
5240 case DW_TAG_volatile_type
:
5241 return "DW_TAG_volatile_type";
5242 case DW_TAG_MIPS_loop
:
5243 return "DW_TAG_MIPS_loop";
5244 case DW_TAG_format_label
:
5245 return "DW_TAG_format_label";
5246 case DW_TAG_function_template
:
5247 return "DW_TAG_function_template";
5248 case DW_TAG_class_template
:
5249 return "DW_TAG_class_template";
5251 return "DW_TAG_<unknown>";
5255 /* Convert a DWARF attribute code into its string name. */
5258 dwarf_attr_name (register unsigned attr
)
5263 return "DW_AT_sibling";
5264 case DW_AT_location
:
5265 return "DW_AT_location";
5267 return "DW_AT_name";
5268 case DW_AT_ordering
:
5269 return "DW_AT_ordering";
5270 case DW_AT_subscr_data
:
5271 return "DW_AT_subscr_data";
5272 case DW_AT_byte_size
:
5273 return "DW_AT_byte_size";
5274 case DW_AT_bit_offset
:
5275 return "DW_AT_bit_offset";
5276 case DW_AT_bit_size
:
5277 return "DW_AT_bit_size";
5278 case DW_AT_element_list
:
5279 return "DW_AT_element_list";
5280 case DW_AT_stmt_list
:
5281 return "DW_AT_stmt_list";
5283 return "DW_AT_low_pc";
5285 return "DW_AT_high_pc";
5286 case DW_AT_language
:
5287 return "DW_AT_language";
5289 return "DW_AT_member";
5291 return "DW_AT_discr";
5292 case DW_AT_discr_value
:
5293 return "DW_AT_discr_value";
5294 case DW_AT_visibility
:
5295 return "DW_AT_visibility";
5297 return "DW_AT_import";
5298 case DW_AT_string_length
:
5299 return "DW_AT_string_length";
5300 case DW_AT_common_reference
:
5301 return "DW_AT_common_reference";
5302 case DW_AT_comp_dir
:
5303 return "DW_AT_comp_dir";
5304 case DW_AT_const_value
:
5305 return "DW_AT_const_value";
5306 case DW_AT_containing_type
:
5307 return "DW_AT_containing_type";
5308 case DW_AT_default_value
:
5309 return "DW_AT_default_value";
5311 return "DW_AT_inline";
5312 case DW_AT_is_optional
:
5313 return "DW_AT_is_optional";
5314 case DW_AT_lower_bound
:
5315 return "DW_AT_lower_bound";
5316 case DW_AT_producer
:
5317 return "DW_AT_producer";
5318 case DW_AT_prototyped
:
5319 return "DW_AT_prototyped";
5320 case DW_AT_return_addr
:
5321 return "DW_AT_return_addr";
5322 case DW_AT_start_scope
:
5323 return "DW_AT_start_scope";
5324 case DW_AT_stride_size
:
5325 return "DW_AT_stride_size";
5326 case DW_AT_upper_bound
:
5327 return "DW_AT_upper_bound";
5328 case DW_AT_abstract_origin
:
5329 return "DW_AT_abstract_origin";
5330 case DW_AT_accessibility
:
5331 return "DW_AT_accessibility";
5332 case DW_AT_address_class
:
5333 return "DW_AT_address_class";
5334 case DW_AT_artificial
:
5335 return "DW_AT_artificial";
5336 case DW_AT_base_types
:
5337 return "DW_AT_base_types";
5338 case DW_AT_calling_convention
:
5339 return "DW_AT_calling_convention";
5341 return "DW_AT_count";
5342 case DW_AT_data_member_location
:
5343 return "DW_AT_data_member_location";
5344 case DW_AT_decl_column
:
5345 return "DW_AT_decl_column";
5346 case DW_AT_decl_file
:
5347 return "DW_AT_decl_file";
5348 case DW_AT_decl_line
:
5349 return "DW_AT_decl_line";
5350 case DW_AT_declaration
:
5351 return "DW_AT_declaration";
5352 case DW_AT_discr_list
:
5353 return "DW_AT_discr_list";
5354 case DW_AT_encoding
:
5355 return "DW_AT_encoding";
5356 case DW_AT_external
:
5357 return "DW_AT_external";
5358 case DW_AT_frame_base
:
5359 return "DW_AT_frame_base";
5361 return "DW_AT_friend";
5362 case DW_AT_identifier_case
:
5363 return "DW_AT_identifier_case";
5364 case DW_AT_macro_info
:
5365 return "DW_AT_macro_info";
5366 case DW_AT_namelist_items
:
5367 return "DW_AT_namelist_items";
5368 case DW_AT_priority
:
5369 return "DW_AT_priority";
5371 return "DW_AT_segment";
5372 case DW_AT_specification
:
5373 return "DW_AT_specification";
5374 case DW_AT_static_link
:
5375 return "DW_AT_static_link";
5377 return "DW_AT_type";
5378 case DW_AT_use_location
:
5379 return "DW_AT_use_location";
5380 case DW_AT_variable_parameter
:
5381 return "DW_AT_variable_parameter";
5382 case DW_AT_virtuality
:
5383 return "DW_AT_virtuality";
5384 case DW_AT_vtable_elem_location
:
5385 return "DW_AT_vtable_elem_location";
5388 case DW_AT_MIPS_fde
:
5389 return "DW_AT_MIPS_fde";
5390 case DW_AT_MIPS_loop_begin
:
5391 return "DW_AT_MIPS_loop_begin";
5392 case DW_AT_MIPS_tail_loop_begin
:
5393 return "DW_AT_MIPS_tail_loop_begin";
5394 case DW_AT_MIPS_epilog_begin
:
5395 return "DW_AT_MIPS_epilog_begin";
5396 case DW_AT_MIPS_loop_unroll_factor
:
5397 return "DW_AT_MIPS_loop_unroll_factor";
5398 case DW_AT_MIPS_software_pipeline_depth
:
5399 return "DW_AT_MIPS_software_pipeline_depth";
5400 case DW_AT_MIPS_linkage_name
:
5401 return "DW_AT_MIPS_linkage_name";
5404 case DW_AT_sf_names
:
5405 return "DW_AT_sf_names";
5406 case DW_AT_src_info
:
5407 return "DW_AT_src_info";
5408 case DW_AT_mac_info
:
5409 return "DW_AT_mac_info";
5410 case DW_AT_src_coords
:
5411 return "DW_AT_src_coords";
5412 case DW_AT_body_begin
:
5413 return "DW_AT_body_begin";
5414 case DW_AT_body_end
:
5415 return "DW_AT_body_end";
5416 case DW_AT_GNU_vector
:
5417 return "DW_AT_GNU_vector";
5419 return "DW_AT_<unknown>";
5423 /* Convert a DWARF value form code into its string name. */
5426 dwarf_form_name (register unsigned form
)
5431 return "DW_FORM_addr";
5432 case DW_FORM_block2
:
5433 return "DW_FORM_block2";
5434 case DW_FORM_block4
:
5435 return "DW_FORM_block4";
5437 return "DW_FORM_data2";
5439 return "DW_FORM_data4";
5441 return "DW_FORM_data8";
5442 case DW_FORM_string
:
5443 return "DW_FORM_string";
5445 return "DW_FORM_block";
5446 case DW_FORM_block1
:
5447 return "DW_FORM_block1";
5449 return "DW_FORM_data1";
5451 return "DW_FORM_flag";
5453 return "DW_FORM_sdata";
5455 return "DW_FORM_strp";
5457 return "DW_FORM_udata";
5458 case DW_FORM_ref_addr
:
5459 return "DW_FORM_ref_addr";
5461 return "DW_FORM_ref1";
5463 return "DW_FORM_ref2";
5465 return "DW_FORM_ref4";
5467 return "DW_FORM_ref8";
5468 case DW_FORM_ref_udata
:
5469 return "DW_FORM_ref_udata";
5470 case DW_FORM_indirect
:
5471 return "DW_FORM_indirect";
5473 return "DW_FORM_<unknown>";
5477 /* Convert a DWARF stack opcode into its string name. */
5480 dwarf_stack_op_name (register unsigned op
)
5485 return "DW_OP_addr";
5487 return "DW_OP_deref";
5489 return "DW_OP_const1u";
5491 return "DW_OP_const1s";
5493 return "DW_OP_const2u";
5495 return "DW_OP_const2s";
5497 return "DW_OP_const4u";
5499 return "DW_OP_const4s";
5501 return "DW_OP_const8u";
5503 return "DW_OP_const8s";
5505 return "DW_OP_constu";
5507 return "DW_OP_consts";
5511 return "DW_OP_drop";
5513 return "DW_OP_over";
5515 return "DW_OP_pick";
5517 return "DW_OP_swap";
5521 return "DW_OP_xderef";
5529 return "DW_OP_minus";
5541 return "DW_OP_plus";
5542 case DW_OP_plus_uconst
:
5543 return "DW_OP_plus_uconst";
5549 return "DW_OP_shra";
5567 return "DW_OP_skip";
5569 return "DW_OP_lit0";
5571 return "DW_OP_lit1";
5573 return "DW_OP_lit2";
5575 return "DW_OP_lit3";
5577 return "DW_OP_lit4";
5579 return "DW_OP_lit5";
5581 return "DW_OP_lit6";
5583 return "DW_OP_lit7";
5585 return "DW_OP_lit8";
5587 return "DW_OP_lit9";
5589 return "DW_OP_lit10";
5591 return "DW_OP_lit11";
5593 return "DW_OP_lit12";
5595 return "DW_OP_lit13";
5597 return "DW_OP_lit14";
5599 return "DW_OP_lit15";
5601 return "DW_OP_lit16";
5603 return "DW_OP_lit17";
5605 return "DW_OP_lit18";
5607 return "DW_OP_lit19";
5609 return "DW_OP_lit20";
5611 return "DW_OP_lit21";
5613 return "DW_OP_lit22";
5615 return "DW_OP_lit23";
5617 return "DW_OP_lit24";
5619 return "DW_OP_lit25";
5621 return "DW_OP_lit26";
5623 return "DW_OP_lit27";
5625 return "DW_OP_lit28";
5627 return "DW_OP_lit29";
5629 return "DW_OP_lit30";
5631 return "DW_OP_lit31";
5633 return "DW_OP_reg0";
5635 return "DW_OP_reg1";
5637 return "DW_OP_reg2";
5639 return "DW_OP_reg3";
5641 return "DW_OP_reg4";
5643 return "DW_OP_reg5";
5645 return "DW_OP_reg6";
5647 return "DW_OP_reg7";
5649 return "DW_OP_reg8";
5651 return "DW_OP_reg9";
5653 return "DW_OP_reg10";
5655 return "DW_OP_reg11";
5657 return "DW_OP_reg12";
5659 return "DW_OP_reg13";
5661 return "DW_OP_reg14";
5663 return "DW_OP_reg15";
5665 return "DW_OP_reg16";
5667 return "DW_OP_reg17";
5669 return "DW_OP_reg18";
5671 return "DW_OP_reg19";
5673 return "DW_OP_reg20";
5675 return "DW_OP_reg21";
5677 return "DW_OP_reg22";
5679 return "DW_OP_reg23";
5681 return "DW_OP_reg24";
5683 return "DW_OP_reg25";
5685 return "DW_OP_reg26";
5687 return "DW_OP_reg27";
5689 return "DW_OP_reg28";
5691 return "DW_OP_reg29";
5693 return "DW_OP_reg30";
5695 return "DW_OP_reg31";
5697 return "DW_OP_breg0";
5699 return "DW_OP_breg1";
5701 return "DW_OP_breg2";
5703 return "DW_OP_breg3";
5705 return "DW_OP_breg4";
5707 return "DW_OP_breg5";
5709 return "DW_OP_breg6";
5711 return "DW_OP_breg7";
5713 return "DW_OP_breg8";
5715 return "DW_OP_breg9";
5717 return "DW_OP_breg10";
5719 return "DW_OP_breg11";
5721 return "DW_OP_breg12";
5723 return "DW_OP_breg13";
5725 return "DW_OP_breg14";
5727 return "DW_OP_breg15";
5729 return "DW_OP_breg16";
5731 return "DW_OP_breg17";
5733 return "DW_OP_breg18";
5735 return "DW_OP_breg19";
5737 return "DW_OP_breg20";
5739 return "DW_OP_breg21";
5741 return "DW_OP_breg22";
5743 return "DW_OP_breg23";
5745 return "DW_OP_breg24";
5747 return "DW_OP_breg25";
5749 return "DW_OP_breg26";
5751 return "DW_OP_breg27";
5753 return "DW_OP_breg28";
5755 return "DW_OP_breg29";
5757 return "DW_OP_breg30";
5759 return "DW_OP_breg31";
5761 return "DW_OP_regx";
5763 return "DW_OP_fbreg";
5765 return "DW_OP_bregx";
5767 return "DW_OP_piece";
5768 case DW_OP_deref_size
:
5769 return "DW_OP_deref_size";
5770 case DW_OP_xderef_size
:
5771 return "DW_OP_xderef_size";
5775 return "OP_<unknown>";
5780 dwarf_bool_name (unsigned mybool
)
5788 /* Convert a DWARF type code into its string name. */
5791 dwarf_type_encoding_name (register unsigned enc
)
5795 case DW_ATE_address
:
5796 return "DW_ATE_address";
5797 case DW_ATE_boolean
:
5798 return "DW_ATE_boolean";
5799 case DW_ATE_complex_float
:
5800 return "DW_ATE_complex_float";
5802 return "DW_ATE_float";
5804 return "DW_ATE_signed";
5805 case DW_ATE_signed_char
:
5806 return "DW_ATE_signed_char";
5807 case DW_ATE_unsigned
:
5808 return "DW_ATE_unsigned";
5809 case DW_ATE_unsigned_char
:
5810 return "DW_ATE_unsigned_char";
5812 return "DW_ATE_<unknown>";
5816 /* Convert a DWARF call frame info operation to its string name. */
5820 dwarf_cfi_name (register unsigned cfi_opc
)
5824 case DW_CFA_advance_loc
:
5825 return "DW_CFA_advance_loc";
5827 return "DW_CFA_offset";
5828 case DW_CFA_restore
:
5829 return "DW_CFA_restore";
5831 return "DW_CFA_nop";
5832 case DW_CFA_set_loc
:
5833 return "DW_CFA_set_loc";
5834 case DW_CFA_advance_loc1
:
5835 return "DW_CFA_advance_loc1";
5836 case DW_CFA_advance_loc2
:
5837 return "DW_CFA_advance_loc2";
5838 case DW_CFA_advance_loc4
:
5839 return "DW_CFA_advance_loc4";
5840 case DW_CFA_offset_extended
:
5841 return "DW_CFA_offset_extended";
5842 case DW_CFA_restore_extended
:
5843 return "DW_CFA_restore_extended";
5844 case DW_CFA_undefined
:
5845 return "DW_CFA_undefined";
5846 case DW_CFA_same_value
:
5847 return "DW_CFA_same_value";
5848 case DW_CFA_register
:
5849 return "DW_CFA_register";
5850 case DW_CFA_remember_state
:
5851 return "DW_CFA_remember_state";
5852 case DW_CFA_restore_state
:
5853 return "DW_CFA_restore_state";
5854 case DW_CFA_def_cfa
:
5855 return "DW_CFA_def_cfa";
5856 case DW_CFA_def_cfa_register
:
5857 return "DW_CFA_def_cfa_register";
5858 case DW_CFA_def_cfa_offset
:
5859 return "DW_CFA_def_cfa_offset";
5862 case DW_CFA_def_cfa_expression
:
5863 return "DW_CFA_def_cfa_expression";
5864 case DW_CFA_expression
:
5865 return "DW_CFA_expression";
5866 case DW_CFA_offset_extended_sf
:
5867 return "DW_CFA_offset_extended_sf";
5868 case DW_CFA_def_cfa_sf
:
5869 return "DW_CFA_def_cfa_sf";
5870 case DW_CFA_def_cfa_offset_sf
:
5871 return "DW_CFA_def_cfa_offset_sf";
5873 /* SGI/MIPS specific */
5874 case DW_CFA_MIPS_advance_loc8
:
5875 return "DW_CFA_MIPS_advance_loc8";
5877 /* GNU extensions */
5878 case DW_CFA_GNU_window_save
:
5879 return "DW_CFA_GNU_window_save";
5880 case DW_CFA_GNU_args_size
:
5881 return "DW_CFA_GNU_args_size";
5882 case DW_CFA_GNU_negative_offset_extended
:
5883 return "DW_CFA_GNU_negative_offset_extended";
5886 return "DW_CFA_<unknown>";
5892 dump_die (struct die_info
*die
)
5896 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5897 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5898 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
5899 dwarf_bool_name (die
->has_children
));
5901 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
5902 for (i
= 0; i
< die
->num_attrs
; ++i
)
5904 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
5905 dwarf_attr_name (die
->attrs
[i
].name
),
5906 dwarf_form_name (die
->attrs
[i
].form
));
5907 switch (die
->attrs
[i
].form
)
5909 case DW_FORM_ref_addr
:
5911 fprintf_unfiltered (gdb_stderr
, "address: ");
5912 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5914 case DW_FORM_block2
:
5915 case DW_FORM_block4
:
5917 case DW_FORM_block1
:
5918 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5929 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
5931 case DW_FORM_string
:
5933 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
5934 DW_STRING (&die
->attrs
[i
])
5935 ? DW_STRING (&die
->attrs
[i
]) : "");
5938 if (DW_UNSND (&die
->attrs
[i
]))
5939 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
5941 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
5943 case DW_FORM_indirect
:
5944 /* the reader will have reduced the indirect form to
5945 the "base form" so this form should not occur */
5946 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
5949 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
5950 die
->attrs
[i
].form
);
5952 fprintf_unfiltered (gdb_stderr
, "\n");
5957 dump_die_list (struct die_info
*die
)
5967 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
5970 struct die_info
*old
;
5972 h
= (offset
% REF_HASH_SIZE
);
5973 old
= die_ref_table
[h
];
5974 die
->next_ref
= old
;
5975 die_ref_table
[h
] = die
;
5980 dwarf2_empty_hash_tables (void)
5982 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5986 dwarf2_get_ref_die_offset (struct attribute
*attr
)
5988 unsigned int result
= 0;
5992 case DW_FORM_ref_addr
:
5993 result
= DW_ADDR (attr
);
5999 case DW_FORM_ref_udata
:
6000 result
= cu_header_offset
+ DW_UNSND (attr
);
6003 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
6008 static struct die_info
*
6009 follow_die_ref (unsigned int offset
)
6011 struct die_info
*die
;
6014 h
= (offset
% REF_HASH_SIZE
);
6015 die
= die_ref_table
[h
];
6018 if (die
->offset
== offset
)
6022 die
= die
->next_ref
;
6027 static struct type
*
6028 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
6030 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
6032 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
6036 /* Look for this particular type in the fundamental type vector. If
6037 one is not found, create and install one appropriate for the
6038 current language and the current target machine. */
6040 if (ftypes
[typeid] == NULL
)
6042 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
6045 return (ftypes
[typeid]);
6048 /* Decode simple location descriptions.
6049 Given a pointer to a dwarf block that defines a location, compute
6050 the location and return the value.
6052 FIXME: This is a kludge until we figure out a better
6053 way to handle the location descriptions.
6054 Gdb's design does not mesh well with the DWARF2 notion of a location
6055 computing interpreter, which is a shame because the flexibility goes unused.
6056 FIXME: Implement more operations as necessary.
6058 A location description containing no operations indicates that the
6059 object is optimized out. The global optimized_out flag is set for
6060 those, the return value is meaningless.
6062 When the result is a register number, the global isreg flag is set,
6063 otherwise it is cleared.
6065 When the result is a base register offset, the global offreg flag is set
6066 and the register number is returned in basereg, otherwise it is cleared.
6068 When the DW_OP_fbreg operation is encountered without a corresponding
6069 DW_AT_frame_base attribute, the global islocal flag is set.
6070 Hopefully the machine dependent code knows how to set up a virtual
6071 frame pointer for the local references.
6073 Note that stack[0] is unused except as a default error return.
6074 Note that stack overflow is not yet handled. */
6077 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
6078 const struct comp_unit_head
*cu_header
)
6081 int size
= blk
->size
;
6082 char *data
= blk
->data
;
6083 CORE_ADDR stack
[64];
6085 unsigned int bytes_read
, unsnd
;
6135 stack
[++stacki
] = op
- DW_OP_lit0
;
6171 stack
[++stacki
] = op
- DW_OP_reg0
;
6176 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6178 #if defined(HARRIS_TARGET) && defined(_M88K)
6179 /* The Harris 88110 gdb ports have long kept their special reg
6180 numbers between their gp-regs and their x-regs. This is
6181 not how our dwarf is generated. Punt. */
6184 stack
[++stacki
] = unsnd
;
6220 basereg
= op
- DW_OP_breg0
;
6221 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6227 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6229 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6234 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6236 if (frame_base_reg
>= 0)
6239 basereg
= frame_base_reg
;
6240 stack
[stacki
] += frame_base_offset
;
6244 complain (&dwarf2_missing_at_frame_base
);
6250 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
6251 cu_header
, &bytes_read
);
6256 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
6261 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
6266 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
6271 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
6276 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
6281 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
6286 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
6292 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6297 stack
[stacki
+ 1] = stack
[stacki
];
6302 stack
[stacki
- 1] += stack
[stacki
];
6306 case DW_OP_plus_uconst
:
6307 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6312 stack
[stacki
- 1] -= stack
[stacki
];
6318 /* If we're not the last op, then we definitely can't encode
6319 this using GDB's address_class enum. */
6321 complain (&dwarf2_complex_location_expr
);
6325 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
6326 return (stack
[stacki
]);
6329 return (stack
[stacki
]);
6332 /* memory allocation interface */
6336 dwarf2_free_tmp_obstack (PTR ignore
)
6338 obstack_free (&dwarf2_tmp_obstack
, NULL
);
6341 static struct dwarf_block
*
6342 dwarf_alloc_block (void)
6344 struct dwarf_block
*blk
;
6346 blk
= (struct dwarf_block
*)
6347 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
6351 static struct abbrev_info
*
6352 dwarf_alloc_abbrev (void)
6354 struct abbrev_info
*abbrev
;
6356 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
6357 memset (abbrev
, 0, sizeof (struct abbrev_info
));
6361 static struct die_info
*
6362 dwarf_alloc_die (void)
6364 struct die_info
*die
;
6366 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6367 memset (die
, 0, sizeof (struct die_info
));