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 data in the .debug_line statement prologue looks like this. */
181 unsigned int total_length
;
182 unsigned short version
;
183 unsigned int prologue_length
;
184 unsigned char minimum_instruction_length
;
185 unsigned char default_is_stmt
;
187 unsigned char line_range
;
188 unsigned char opcode_base
;
189 unsigned char *standard_opcode_lengths
;
192 /* When we construct a partial symbol table entry we only
193 need this much information. */
194 struct partial_die_info
197 unsigned char has_children
;
198 unsigned char is_external
;
199 unsigned char is_declaration
;
200 unsigned char has_type
;
207 struct dwarf_block
*locdesc
;
208 unsigned int language
;
212 /* This data structure holds the information of an abbrev. */
215 unsigned int number
; /* number identifying abbrev */
216 enum dwarf_tag tag
; /* dwarf tag */
217 int has_children
; /* boolean */
218 unsigned int num_attrs
; /* number of attributes */
219 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
220 struct abbrev_info
*next
; /* next in chain */
225 enum dwarf_attribute name
;
226 enum dwarf_form form
;
229 /* This data structure holds a complete die structure. */
232 enum dwarf_tag tag
; /* Tag indicating type of die */
233 unsigned short has_children
; /* Does the die have children */
234 unsigned int abbrev
; /* Abbrev number */
235 unsigned int offset
; /* Offset in .debug_info section */
236 unsigned int num_attrs
; /* Number of attributes */
237 struct attribute
*attrs
; /* An array of attributes */
238 struct die_info
*next_ref
; /* Next die in ref hash table */
239 struct die_info
*next
; /* Next die in linked list */
240 struct type
*type
; /* Cached type information */
243 /* Attributes have a name and a value */
246 enum dwarf_attribute name
;
247 enum dwarf_form form
;
251 struct dwarf_block
*blk
;
259 struct function_range
262 CORE_ADDR lowpc
, highpc
;
264 struct function_range
*next
;
267 static struct function_range
*cu_first_fn
, *cu_last_fn
, *cu_cached_fn
;
269 /* Get at parts of an attribute structure */
271 #define DW_STRING(attr) ((attr)->u.str)
272 #define DW_UNSND(attr) ((attr)->u.unsnd)
273 #define DW_BLOCK(attr) ((attr)->u.blk)
274 #define DW_SND(attr) ((attr)->u.snd)
275 #define DW_ADDR(attr) ((attr)->u.addr)
277 /* Blocks are a bunch of untyped bytes. */
284 /* We only hold one compilation unit's abbrevs in
285 memory at any one time. */
286 #ifndef ABBREV_HASH_SIZE
287 #define ABBREV_HASH_SIZE 121
289 #ifndef ATTR_ALLOC_CHUNK
290 #define ATTR_ALLOC_CHUNK 4
293 static struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
295 /* A hash table of die offsets for following references. */
296 #ifndef REF_HASH_SIZE
297 #define REF_HASH_SIZE 1021
300 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
302 /* Obstack for allocating temporary storage used during symbol reading. */
303 static struct obstack dwarf2_tmp_obstack
;
305 /* Offset to the first byte of the current compilation unit header,
306 for resolving relative reference dies. */
307 static unsigned int cu_header_offset
;
309 /* Allocate fields for structs, unions and enums in this size. */
310 #ifndef DW_FIELD_ALLOC_CHUNK
311 #define DW_FIELD_ALLOC_CHUNK 4
314 /* The language we are debugging. */
315 static enum language cu_language
;
316 static const struct language_defn
*cu_language_defn
;
318 /* Actually data from the sections. */
319 static char *dwarf_info_buffer
;
320 static char *dwarf_abbrev_buffer
;
321 static char *dwarf_line_buffer
;
322 static char *dwarf_str_buffer
;
324 /* A zeroed version of a partial die for initialization purposes. */
325 static struct partial_die_info zeroed_partial_die
;
327 /* The generic symbol table building routines have separate lists for
328 file scope symbols and all all other scopes (local scopes). So
329 we need to select the right one to pass to add_symbol_to_list().
330 We do it by keeping a pointer to the correct list in list_in_scope.
332 FIXME: The original dwarf code just treated the file scope as the first
333 local scope, and all other local scopes as nested local scopes, and worked
334 fine. Check to see if we really need to distinguish these
336 static struct pending
**list_in_scope
= &file_symbols
;
338 /* FIXME: decode_locdesc sets these variables to describe the location
339 to the caller. These ought to be a structure or something. If
340 none of the flags are set, the object lives at the address returned
341 by decode_locdesc. */
343 static int optimized_out
; /* No ops in location in expression,
344 so object was optimized out. */
345 static int isreg
; /* Object lives in register.
346 decode_locdesc's return value is
347 the register number. */
348 static int offreg
; /* Object's address is the sum of the
349 register specified by basereg, plus
350 the offset returned. */
351 static int basereg
; /* See `offreg'. */
352 static int isderef
; /* Value described by flags above is
353 the address of a pointer to the object. */
354 static int islocal
; /* Variable is at the returned offset
355 from the frame start, but there's
356 no identified frame pointer for
357 this function, so we can't say
358 which register it's relative to;
361 /* DW_AT_frame_base values for the current function.
362 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
363 contains the register number for the frame register.
364 frame_base_offset is the offset from the frame register to the
365 virtual stack frame. */
366 static int frame_base_reg
;
367 static CORE_ADDR frame_base_offset
;
369 /* This value is added to each symbol value. FIXME: Generalize to
370 the section_offsets structure used by dbxread (once this is done,
371 pass the appropriate section number to end_symtab). */
372 static CORE_ADDR baseaddr
; /* Add to each symbol value */
374 /* We put a pointer to this structure in the read_symtab_private field
376 The complete dwarf information for an objfile is kept in the
377 psymbol_obstack, so that absolute die references can be handled.
378 Most of the information in this structure is related to an entire
379 object file and could be passed via the sym_private field of the objfile.
380 It is however conceivable that dwarf2 might not be the only type
381 of symbols read from an object file. */
385 /* Pointer to start of dwarf info buffer for the objfile. */
387 char *dwarf_info_buffer
;
389 /* Offset in dwarf_info_buffer for this compilation unit. */
391 unsigned long dwarf_info_offset
;
393 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
395 char *dwarf_abbrev_buffer
;
397 /* Size of dwarf abbreviation section for the objfile. */
399 unsigned int dwarf_abbrev_size
;
401 /* Pointer to start of dwarf line buffer for the objfile. */
403 char *dwarf_line_buffer
;
405 /* Pointer to start of dwarf string buffer for the objfile. */
407 char *dwarf_str_buffer
;
409 /* Size of dwarf string section for the objfile. */
411 unsigned int dwarf_str_size
;
414 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
415 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
416 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
417 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
418 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
419 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
420 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
421 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
423 /* Maintain an array of referenced fundamental types for the current
424 compilation unit being read. For DWARF version 1, we have to construct
425 the fundamental types on the fly, since no information about the
426 fundamental types is supplied. Each such fundamental type is created by
427 calling a language dependent routine to create the type, and then a
428 pointer to that type is then placed in the array at the index specified
429 by it's FT_<TYPENAME> value. The array has a fixed size set by the
430 FT_NUM_MEMBERS compile time constant, which is the number of predefined
431 fundamental types gdb knows how to construct. */
432 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
434 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
435 but this would require a corresponding change in unpack_field_as_long
437 static int bits_per_byte
= 8;
439 /* The routines that read and process dies for a C struct or C++ class
440 pass lists of data member fields and lists of member function fields
441 in an instance of a field_info structure, as defined below. */
444 /* List of data member and baseclasses fields. */
447 struct nextfield
*next
;
454 /* Number of fields. */
457 /* Number of baseclasses. */
460 /* Set if the accesibility of one of the fields is not public. */
461 int non_public_fields
;
463 /* Member function fields array, entries are allocated in the order they
464 are encountered in the object file. */
467 struct nextfnfield
*next
;
468 struct fn_field fnfield
;
472 /* Member function fieldlist array, contains name of possibly overloaded
473 member function, number of overloaded member functions and a pointer
474 to the head of the member function field chain. */
479 struct nextfnfield
*head
;
483 /* Number of entries in the fnfieldlists array. */
487 /* Various complaints about symbol reading that don't abort the process */
489 static struct complaint dwarf2_const_ignored
=
491 "type qualifier 'const' ignored", 0, 0
493 static struct complaint dwarf2_volatile_ignored
=
495 "type qualifier 'volatile' ignored", 0, 0
497 static struct complaint dwarf2_non_const_array_bound_ignored
=
499 "non-constant array bounds form '%s' ignored", 0, 0
501 static struct complaint dwarf2_missing_line_number_section
=
503 "missing .debug_line section", 0, 0
505 static struct complaint dwarf2_mangled_line_number_section
=
507 "mangled .debug_line section", 0, 0
509 static struct complaint dwarf2_unsupported_die_ref_attr
=
511 "unsupported die ref attribute form: '%s'", 0, 0
513 static struct complaint dwarf2_unsupported_stack_op
=
515 "unsupported stack op: '%s'", 0, 0
517 static struct complaint dwarf2_complex_location_expr
=
519 "location expression too complex", 0, 0
521 static struct complaint dwarf2_unsupported_tag
=
523 "unsupported tag: '%s'", 0, 0
525 static struct complaint dwarf2_unsupported_at_encoding
=
527 "unsupported DW_AT_encoding: '%s'", 0, 0
529 static struct complaint dwarf2_unsupported_at_frame_base
=
531 "unsupported DW_AT_frame_base for function '%s'", 0, 0
533 static struct complaint dwarf2_unexpected_tag
=
535 "unexepected tag in read_type_die: '%s'", 0, 0
537 static struct complaint dwarf2_missing_at_frame_base
=
539 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
541 static struct complaint dwarf2_bad_static_member_name
=
543 "unrecognized static data member name '%s'", 0, 0
545 static struct complaint dwarf2_unsupported_accessibility
=
547 "unsupported accessibility %d", 0, 0
549 static struct complaint dwarf2_bad_member_name_complaint
=
551 "cannot extract member name from '%s'", 0, 0
553 static struct complaint dwarf2_missing_member_fn_type_complaint
=
555 "member function type missing for '%s'", 0, 0
557 static struct complaint dwarf2_vtbl_not_found_complaint
=
559 "virtual function table pointer not found when defining class '%s'", 0, 0
561 static struct complaint dwarf2_absolute_sibling_complaint
=
563 "ignoring absolute DW_AT_sibling", 0, 0
565 static struct complaint dwarf2_const_value_length_mismatch
=
567 "const value length mismatch for '%s', got %d, expected %d", 0, 0
569 static struct complaint dwarf2_unsupported_const_value_attr
=
571 "unsupported const value attribute form: '%s'", 0, 0
573 static struct complaint dwarf2_misplaced_line_number
=
575 "misplaced first line number at 0x%lx for '%s'", 0, 0
578 /* local function prototypes */
580 static void dwarf2_locate_sections (bfd
*, asection
*, PTR
);
583 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
586 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
588 static char *scan_partial_symbols (char *, struct objfile
*,
589 CORE_ADDR
*, CORE_ADDR
*,
590 const struct comp_unit_head
*);
592 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
593 const struct comp_unit_head
*);
595 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
597 static void psymtab_to_symtab_1 (struct partial_symtab
*);
599 char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int);
601 static void dwarf2_read_abbrevs (bfd
*, unsigned int);
603 static void dwarf2_empty_abbrev_table (PTR
);
605 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int);
607 static char *read_partial_die (struct partial_die_info
*,
609 const struct comp_unit_head
*);
611 static char *read_full_die (struct die_info
**, bfd
*, char *,
612 const struct comp_unit_head
*);
614 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
615 bfd
*, char *, const struct comp_unit_head
*);
617 static char *read_attribute_value (struct attribute
*, unsigned,
618 bfd
*, char *, const struct comp_unit_head
*);
620 static unsigned int read_1_byte (bfd
*, char *);
622 static int read_1_signed_byte (bfd
*, char *);
624 static unsigned int read_2_bytes (bfd
*, char *);
626 static unsigned int read_4_bytes (bfd
*, char *);
628 static unsigned long read_8_bytes (bfd
*, char *);
630 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
633 static LONGEST
read_initial_length (bfd
*, char *,
634 struct comp_unit_head
*, int *bytes_read
);
636 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
639 static char *read_n_bytes (bfd
*, char *, unsigned int);
641 static char *read_string (bfd
*, char *, unsigned int *);
643 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
646 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
648 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
650 static void set_cu_language (unsigned int);
652 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
654 static int die_is_declaration (struct die_info
*);
656 static void dwarf_decode_lines (unsigned int, char *, bfd
*,
657 const struct comp_unit_head
*);
659 static void dwarf2_start_subfile (char *, char *);
661 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
662 struct objfile
*, const struct comp_unit_head
*);
664 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
665 struct objfile
*, const struct comp_unit_head
*);
667 static void dwarf2_const_value_data (struct attribute
*attr
,
671 static struct type
*die_type (struct die_info
*, struct objfile
*,
672 const struct comp_unit_head
*);
674 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
675 const struct comp_unit_head
*);
678 static struct type
*type_at_offset (unsigned int, struct objfile
*);
681 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
682 const struct comp_unit_head
*);
684 static void read_type_die (struct die_info
*, struct objfile
*,
685 const struct comp_unit_head
*);
687 static void read_typedef (struct die_info
*, struct objfile
*,
688 const struct comp_unit_head
*);
690 static void read_base_type (struct die_info
*, struct objfile
*);
692 static void read_file_scope (struct die_info
*, struct objfile
*,
693 const struct comp_unit_head
*);
695 static void read_func_scope (struct die_info
*, struct objfile
*,
696 const struct comp_unit_head
*);
698 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
699 const struct comp_unit_head
*);
701 static int dwarf2_get_pc_bounds (struct die_info
*,
702 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*);
704 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
705 struct objfile
*, const struct comp_unit_head
*);
707 static void dwarf2_attach_fields_to_type (struct field_info
*,
708 struct type
*, struct objfile
*);
710 static void dwarf2_add_member_fn (struct field_info
*,
711 struct die_info
*, struct type
*,
712 struct objfile
*objfile
,
713 const struct comp_unit_head
*);
715 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
716 struct type
*, struct objfile
*);
718 static void read_structure_scope (struct die_info
*, struct objfile
*,
719 const struct comp_unit_head
*);
721 static void read_common_block (struct die_info
*, struct objfile
*,
722 const struct comp_unit_head
*);
724 static void read_enumeration (struct die_info
*, struct objfile
*,
725 const struct comp_unit_head
*);
727 static struct type
*dwarf_base_type (int, int, struct objfile
*);
729 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
730 const struct comp_unit_head
*);
732 static void read_array_type (struct die_info
*, struct objfile
*,
733 const struct comp_unit_head
*);
735 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
736 const struct comp_unit_head
*);
738 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
739 const struct comp_unit_head
*);
741 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
742 const struct comp_unit_head
*);
744 static void read_tag_const_type (struct die_info
*, struct objfile
*,
745 const struct comp_unit_head
*);
747 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
748 const struct comp_unit_head
*);
750 static void read_tag_string_type (struct die_info
*, struct objfile
*);
752 static void read_subroutine_type (struct die_info
*, struct objfile
*,
753 const struct comp_unit_head
*);
755 static struct die_info
*read_comp_unit (char *, bfd
*,
756 const struct comp_unit_head
*);
758 static void free_die_list (struct die_info
*);
760 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
762 static void process_die (struct die_info
*, struct objfile
*,
763 const struct comp_unit_head
*);
765 static char *dwarf2_linkage_name (struct die_info
*);
767 static char *dwarf_tag_name (unsigned int);
769 static char *dwarf_attr_name (unsigned int);
771 static char *dwarf_form_name (unsigned int);
773 static char *dwarf_stack_op_name (unsigned int);
775 static char *dwarf_bool_name (unsigned int);
777 static char *dwarf_type_encoding_name (unsigned int);
780 static char *dwarf_cfi_name (unsigned int);
782 struct die_info
*copy_die (struct die_info
*);
785 static struct die_info
*sibling_die (struct die_info
*);
787 static void dump_die (struct die_info
*);
789 static void dump_die_list (struct die_info
*);
791 static void store_in_ref_table (unsigned int, struct die_info
*);
793 static void dwarf2_empty_hash_tables (void);
795 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
797 static struct die_info
*follow_die_ref (unsigned int);
799 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
801 /* memory allocation interface */
803 static void dwarf2_free_tmp_obstack (PTR
);
805 static struct dwarf_block
*dwarf_alloc_block (void);
807 static struct abbrev_info
*dwarf_alloc_abbrev (void);
809 static struct die_info
*dwarf_alloc_die (void);
811 static void initialize_cu_func_list (void);
813 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
);
815 /* Try to locate the sections we need for DWARF 2 debugging
816 information and return true if we have enough to do something. */
819 dwarf2_has_info (bfd
*abfd
)
821 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
822 dwarf_str_offset
= 0;
823 dwarf_frame_offset
= dwarf_eh_frame_offset
= 0;
824 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
825 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
835 /* This function is mapped across the sections and remembers the
836 offset and size of each of the debugging sections we are interested
840 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, PTR ignore_ptr
)
842 if (STREQ (sectp
->name
, INFO_SECTION
))
844 dwarf_info_offset
= sectp
->filepos
;
845 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
847 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
849 dwarf_abbrev_offset
= sectp
->filepos
;
850 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
852 else if (STREQ (sectp
->name
, LINE_SECTION
))
854 dwarf_line_offset
= sectp
->filepos
;
855 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
857 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
859 dwarf_pubnames_offset
= sectp
->filepos
;
860 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
862 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
864 dwarf_aranges_offset
= sectp
->filepos
;
865 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
867 else if (STREQ (sectp
->name
, LOC_SECTION
))
869 dwarf_loc_offset
= sectp
->filepos
;
870 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
872 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
874 dwarf_macinfo_offset
= sectp
->filepos
;
875 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
877 else if (STREQ (sectp
->name
, STR_SECTION
))
879 dwarf_str_offset
= sectp
->filepos
;
880 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
882 else if (STREQ (sectp
->name
, FRAME_SECTION
))
884 dwarf_frame_offset
= sectp
->filepos
;
885 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
887 else if (STREQ (sectp
->name
, EH_FRAME_SECTION
))
889 dwarf_eh_frame_offset
= sectp
->filepos
;
890 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
894 /* Build a partial symbol table. */
897 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
900 /* We definitely need the .debug_info and .debug_abbrev sections */
902 dwarf_info_buffer
= dwarf2_read_section (objfile
,
905 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
908 dwarf_line_buffer
= dwarf2_read_section (objfile
,
912 if (dwarf_str_offset
)
913 dwarf_str_buffer
= dwarf2_read_section (objfile
,
917 dwarf_str_buffer
= NULL
;
920 || (objfile
->global_psymbols
.size
== 0
921 && objfile
->static_psymbols
.size
== 0))
923 init_psymbol_list (objfile
, 1024);
927 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
929 /* Things are significantly easier if we have .debug_aranges and
930 .debug_pubnames sections */
932 dwarf2_build_psymtabs_easy (objfile
, mainline
);
936 /* only test this case for now */
938 /* In this case we have to work a bit harder */
939 dwarf2_build_psymtabs_hard (objfile
, mainline
);
944 /* Build the partial symbol table from the information in the
945 .debug_pubnames and .debug_aranges sections. */
948 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
950 bfd
*abfd
= objfile
->obfd
;
951 char *aranges_buffer
, *pubnames_buffer
;
952 char *aranges_ptr
, *pubnames_ptr
;
953 unsigned int entry_length
, version
, info_offset
, info_size
;
955 pubnames_buffer
= dwarf2_read_section (objfile
,
956 dwarf_pubnames_offset
,
957 dwarf_pubnames_size
);
958 pubnames_ptr
= pubnames_buffer
;
959 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
961 struct comp_unit_head cu_header
;
964 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
966 pubnames_ptr
+= bytes_read
;
967 version
= read_1_byte (abfd
, pubnames_ptr
);
969 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
971 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
975 aranges_buffer
= dwarf2_read_section (objfile
,
976 dwarf_aranges_offset
,
982 /* Read in the comp unit header information from the debug_info at
986 read_comp_unit_head (struct comp_unit_head
*cu_header
,
987 char *info_ptr
, bfd
*abfd
)
991 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
993 info_ptr
+= bytes_read
;
994 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
996 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
998 info_ptr
+= bytes_read
;
999 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1001 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1002 if (signed_addr
< 0)
1003 internal_error (__FILE__
, __LINE__
,
1004 "read_comp_unit_head: dwarf from non elf file");
1005 cu_header
->signed_addr_p
= signed_addr
;
1009 /* Build the partial symbol table by doing a quick pass through the
1010 .debug_info and .debug_abbrev sections. */
1013 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1015 /* Instead of reading this into a big buffer, we should probably use
1016 mmap() on architectures that support it. (FIXME) */
1017 bfd
*abfd
= objfile
->obfd
;
1018 char *info_ptr
, *abbrev_ptr
;
1019 char *beg_of_comp_unit
;
1020 struct partial_die_info comp_unit_die
;
1021 struct partial_symtab
*pst
;
1022 struct cleanup
*back_to
;
1023 CORE_ADDR lowpc
, highpc
;
1025 info_ptr
= dwarf_info_buffer
;
1026 abbrev_ptr
= dwarf_abbrev_buffer
;
1028 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1029 the partial symbol scan, like attribute values.
1031 We could reduce our peak memory consumption during partial symbol
1032 table construction by freeing stuff from this obstack more often
1033 --- say, after processing each compilation unit, or each die ---
1034 but it turns out that this saves almost nothing. For an
1035 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1036 on dwarf2_tmp_obstack. Some investigation showed:
1038 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1039 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1040 all fixed-length values not requiring dynamic allocation.
1042 2) 30% of the attributes used the form DW_FORM_string. For
1043 DW_FORM_string, read_attribute simply hands back a pointer to
1044 the null-terminated string in dwarf_info_buffer, so no dynamic
1045 allocation is needed there either.
1047 3) The remaining 1% of the attributes all used DW_FORM_block1.
1048 75% of those were DW_AT_frame_base location lists for
1049 functions; the rest were DW_AT_location attributes, probably
1050 for the global variables.
1052 Anyway, what this all means is that the memory the dwarf2
1053 reader uses as temporary space reading partial symbols is about
1054 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1056 obstack_init (&dwarf2_tmp_obstack
);
1057 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1059 /* Since the objects we're extracting from dwarf_info_buffer vary in
1060 length, only the individual functions to extract them (like
1061 read_comp_unit_head and read_partial_die) can really know whether
1062 the buffer is large enough to hold another complete object.
1064 At the moment, they don't actually check that. If
1065 dwarf_info_buffer holds just one extra byte after the last
1066 compilation unit's dies, then read_comp_unit_head will happily
1067 read off the end of the buffer. read_partial_die is similarly
1068 casual. Those functions should be fixed.
1070 For this loop condition, simply checking whether there's any data
1071 left at all should be sufficient. */
1072 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1074 struct comp_unit_head cu_header
;
1075 beg_of_comp_unit
= info_ptr
;
1076 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1078 if (cu_header
.version
!= 2)
1080 error ("Dwarf Error: wrong version in compilation unit header.");
1083 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
1085 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
1086 (long) cu_header
.abbrev_offset
,
1087 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1090 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1091 > dwarf_info_buffer
+ dwarf_info_size
)
1093 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
1094 (long) cu_header
.length
,
1095 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1098 /* Read the abbrevs for this compilation unit into a table */
1099 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1100 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1102 /* Read the compilation unit die */
1103 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1106 /* Set the language we're debugging */
1107 set_cu_language (comp_unit_die
.language
);
1109 /* Allocate a new partial symbol table structure */
1110 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1111 comp_unit_die
.name
? comp_unit_die
.name
: "",
1112 comp_unit_die
.lowpc
,
1113 objfile
->global_psymbols
.next
,
1114 objfile
->static_psymbols
.next
);
1116 pst
->read_symtab_private
= (char *)
1117 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1118 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1119 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1120 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1121 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1122 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1123 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1124 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1125 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1126 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1128 /* Store the function that reads in the rest of the symbol table */
1129 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1131 /* Check if comp unit has_children.
1132 If so, read the rest of the partial symbols from this comp unit.
1133 If not, there's no more debug_info for this comp unit. */
1134 if (comp_unit_die
.has_children
)
1136 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1139 /* If the compilation unit didn't have an explicit address range,
1140 then use the information extracted from its child dies. */
1141 if (! comp_unit_die
.has_pc_info
)
1143 comp_unit_die
.lowpc
= lowpc
;
1144 comp_unit_die
.highpc
= highpc
;
1147 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1148 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1150 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1151 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1152 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1153 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1154 sort_pst_symbols (pst
);
1156 /* If there is already a psymtab or symtab for a file of this
1157 name, remove it. (If there is a symtab, more drastic things
1158 also happen.) This happens in VxWorks. */
1159 free_named_symtabs (pst
->filename
);
1161 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1162 + cu_header
.initial_length_size
;
1164 do_cleanups (back_to
);
1167 /* Read in all interesting dies to the end of the compilation unit. */
1170 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1171 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1172 const struct comp_unit_head
*cu_header
)
1174 bfd
*abfd
= objfile
->obfd
;
1175 struct partial_die_info pdi
;
1177 /* This function is called after we've read in the comp_unit_die in
1178 order to read its children. We start the nesting level at 1 since
1179 we have pushed 1 level down in order to read the comp unit's children.
1180 The comp unit itself is at level 0, so we stop reading when we pop
1181 back to that level. */
1183 int nesting_level
= 1;
1185 *lowpc
= ((CORE_ADDR
) -1);
1186 *highpc
= ((CORE_ADDR
) 0);
1188 while (nesting_level
)
1190 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1196 case DW_TAG_subprogram
:
1197 if (pdi
.has_pc_info
)
1199 if (pdi
.lowpc
< *lowpc
)
1203 if (pdi
.highpc
> *highpc
)
1205 *highpc
= pdi
.highpc
;
1207 if ((pdi
.is_external
|| nesting_level
== 1)
1208 && !pdi
.is_declaration
)
1210 add_partial_symbol (&pdi
, objfile
, cu_header
);
1214 case DW_TAG_variable
:
1215 case DW_TAG_typedef
:
1216 case DW_TAG_class_type
:
1217 case DW_TAG_structure_type
:
1218 case DW_TAG_union_type
:
1219 case DW_TAG_enumeration_type
:
1220 if ((pdi
.is_external
|| nesting_level
== 1)
1221 && !pdi
.is_declaration
)
1223 add_partial_symbol (&pdi
, objfile
, cu_header
);
1226 case DW_TAG_enumerator
:
1227 /* File scope enumerators are added to the partial symbol
1229 if (nesting_level
== 2)
1230 add_partial_symbol (&pdi
, objfile
, cu_header
);
1232 case DW_TAG_base_type
:
1233 /* File scope base type definitions are added to the partial
1235 if (nesting_level
== 1)
1236 add_partial_symbol (&pdi
, objfile
, cu_header
);
1243 /* If the die has a sibling, skip to the sibling.
1244 Do not skip enumeration types, we want to record their
1246 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1248 info_ptr
= pdi
.sibling
;
1250 else if (pdi
.has_children
)
1252 /* Die has children, but the optional DW_AT_sibling attribute
1263 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1264 from `maint check'. */
1265 if (*lowpc
== ((CORE_ADDR
) -1))
1271 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1272 const struct comp_unit_head
*cu_header
)
1278 case DW_TAG_subprogram
:
1279 if (pdi
->is_external
)
1281 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1282 mst_text, objfile); */
1283 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1284 VAR_NAMESPACE
, LOC_BLOCK
,
1285 &objfile
->global_psymbols
,
1286 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1290 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1291 mst_file_text, objfile); */
1292 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1293 VAR_NAMESPACE
, LOC_BLOCK
,
1294 &objfile
->static_psymbols
,
1295 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1298 case DW_TAG_variable
:
1299 if (pdi
->is_external
)
1302 Don't enter into the minimal symbol tables as there is
1303 a minimal symbol table entry from the ELF symbols already.
1304 Enter into partial symbol table if it has a location
1305 descriptor or a type.
1306 If the location descriptor is missing, new_symbol will create
1307 a LOC_UNRESOLVED symbol, the address of the variable will then
1308 be determined from the minimal symbol table whenever the variable
1310 The address for the partial symbol table entry is not
1311 used by GDB, but it comes in handy for debugging partial symbol
1315 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1316 if (pdi
->locdesc
|| pdi
->has_type
)
1317 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1318 VAR_NAMESPACE
, LOC_STATIC
,
1319 &objfile
->global_psymbols
,
1320 0, addr
+ baseaddr
, cu_language
, objfile
);
1324 /* Static Variable. Skip symbols without location descriptors. */
1325 if (pdi
->locdesc
== NULL
)
1327 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1328 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1329 mst_file_data, objfile); */
1330 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1331 VAR_NAMESPACE
, LOC_STATIC
,
1332 &objfile
->static_psymbols
,
1333 0, addr
+ baseaddr
, cu_language
, objfile
);
1336 case DW_TAG_typedef
:
1337 case DW_TAG_base_type
:
1338 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1339 VAR_NAMESPACE
, LOC_TYPEDEF
,
1340 &objfile
->static_psymbols
,
1341 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1343 case DW_TAG_class_type
:
1344 case DW_TAG_structure_type
:
1345 case DW_TAG_union_type
:
1346 case DW_TAG_enumeration_type
:
1347 /* Skip aggregate types without children, these are external
1349 if (pdi
->has_children
== 0)
1351 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1352 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1353 &objfile
->static_psymbols
,
1354 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1356 if (cu_language
== language_cplus
)
1358 /* For C++, these implicitly act as typedefs as well. */
1359 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1360 VAR_NAMESPACE
, LOC_TYPEDEF
,
1361 &objfile
->static_psymbols
,
1362 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1365 case DW_TAG_enumerator
:
1366 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1367 VAR_NAMESPACE
, LOC_CONST
,
1368 &objfile
->static_psymbols
,
1369 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1376 /* Expand this partial symbol table into a full symbol table. */
1379 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1381 /* FIXME: This is barely more than a stub. */
1386 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1392 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1393 gdb_flush (gdb_stdout
);
1396 psymtab_to_symtab_1 (pst
);
1398 /* Finish up the debug error message. */
1400 printf_filtered ("done.\n");
1406 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1408 struct objfile
*objfile
= pst
->objfile
;
1409 bfd
*abfd
= objfile
->obfd
;
1410 struct comp_unit_head cu_header
;
1411 struct die_info
*dies
;
1412 unsigned long offset
;
1413 CORE_ADDR lowpc
, highpc
;
1414 struct die_info
*child_die
;
1416 struct symtab
*symtab
;
1417 struct cleanup
*back_to
;
1419 /* Set local variables from the partial symbol table info. */
1420 offset
= DWARF_INFO_OFFSET (pst
);
1421 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1422 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1423 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1424 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1425 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1426 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1427 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1428 cu_header_offset
= offset
;
1429 info_ptr
= dwarf_info_buffer
+ offset
;
1431 obstack_init (&dwarf2_tmp_obstack
);
1432 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1435 make_cleanup (really_free_pendings
, NULL
);
1437 /* read in the comp_unit header */
1438 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1440 /* Read the abbrevs for this compilation unit */
1441 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1442 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1444 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1446 make_cleanup_free_die_list (dies
);
1448 /* Do line number decoding in read_file_scope () */
1449 process_die (dies
, objfile
, &cu_header
);
1451 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1453 /* Some compilers don't define a DW_AT_high_pc attribute for
1454 the compilation unit. If the DW_AT_high_pc is missing,
1455 synthesize it, by scanning the DIE's below the compilation unit. */
1457 if (dies
->has_children
)
1459 child_die
= dies
->next
;
1460 while (child_die
&& child_die
->tag
)
1462 if (child_die
->tag
== DW_TAG_subprogram
)
1464 CORE_ADDR low
, high
;
1466 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1468 highpc
= max (highpc
, high
);
1471 child_die
= sibling_die (child_die
);
1475 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1477 /* Set symtab language to language from DW_AT_language.
1478 If the compilation is from a C file generated by language preprocessors,
1479 do not set the language if it was already deduced by start_subfile. */
1481 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1483 symtab
->language
= cu_language
;
1485 pst
->symtab
= symtab
;
1487 sort_symtab_syms (pst
->symtab
);
1489 do_cleanups (back_to
);
1492 /* Process a die and its children. */
1495 process_die (struct die_info
*die
, struct objfile
*objfile
,
1496 const struct comp_unit_head
*cu_header
)
1500 case DW_TAG_padding
:
1502 case DW_TAG_compile_unit
:
1503 read_file_scope (die
, objfile
, cu_header
);
1505 case DW_TAG_subprogram
:
1506 read_subroutine_type (die
, objfile
, cu_header
);
1507 read_func_scope (die
, objfile
, cu_header
);
1509 case DW_TAG_inlined_subroutine
:
1510 /* FIXME: These are ignored for now.
1511 They could be used to set breakpoints on all inlined instances
1512 of a function and make GDB `next' properly over inlined functions. */
1514 case DW_TAG_lexical_block
:
1515 read_lexical_block_scope (die
, objfile
, cu_header
);
1517 case DW_TAG_class_type
:
1518 case DW_TAG_structure_type
:
1519 case DW_TAG_union_type
:
1520 read_structure_scope (die
, objfile
, cu_header
);
1522 case DW_TAG_enumeration_type
:
1523 read_enumeration (die
, objfile
, cu_header
);
1525 case DW_TAG_subroutine_type
:
1526 read_subroutine_type (die
, objfile
, cu_header
);
1528 case DW_TAG_array_type
:
1529 read_array_type (die
, objfile
, cu_header
);
1531 case DW_TAG_pointer_type
:
1532 read_tag_pointer_type (die
, objfile
, cu_header
);
1534 case DW_TAG_ptr_to_member_type
:
1535 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1537 case DW_TAG_reference_type
:
1538 read_tag_reference_type (die
, objfile
, cu_header
);
1540 case DW_TAG_string_type
:
1541 read_tag_string_type (die
, objfile
);
1543 case DW_TAG_base_type
:
1544 read_base_type (die
, objfile
);
1545 if (dwarf_attr (die
, DW_AT_name
))
1547 /* Add a typedef symbol for the base type definition. */
1548 new_symbol (die
, die
->type
, objfile
, cu_header
);
1551 case DW_TAG_common_block
:
1552 read_common_block (die
, objfile
, cu_header
);
1554 case DW_TAG_common_inclusion
:
1557 new_symbol (die
, NULL
, objfile
, cu_header
);
1563 initialize_cu_func_list (void)
1565 cu_first_fn
= cu_last_fn
= cu_cached_fn
= NULL
;
1569 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1570 const struct comp_unit_head
*cu_header
)
1572 unsigned int line_offset
= 0;
1573 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1574 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1575 struct attribute
*attr
;
1576 char *name
= "<unknown>";
1577 char *comp_dir
= NULL
;
1578 struct die_info
*child_die
;
1579 bfd
*abfd
= objfile
->obfd
;
1581 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1583 if (die
->has_children
)
1585 child_die
= die
->next
;
1586 while (child_die
&& child_die
->tag
)
1588 if (child_die
->tag
== DW_TAG_subprogram
)
1590 CORE_ADDR low
, high
;
1592 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1594 lowpc
= min (lowpc
, low
);
1595 highpc
= max (highpc
, high
);
1598 child_die
= sibling_die (child_die
);
1603 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1604 from finish_block. */
1605 if (lowpc
== ((CORE_ADDR
) -1))
1610 attr
= dwarf_attr (die
, DW_AT_name
);
1613 name
= DW_STRING (attr
);
1615 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1618 comp_dir
= DW_STRING (attr
);
1621 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1622 directory, get rid of it. */
1623 char *cp
= strchr (comp_dir
, ':');
1625 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1630 if (objfile
->ei
.entry_point
>= lowpc
&&
1631 objfile
->ei
.entry_point
< highpc
)
1633 objfile
->ei
.entry_file_lowpc
= lowpc
;
1634 objfile
->ei
.entry_file_highpc
= highpc
;
1637 attr
= dwarf_attr (die
, DW_AT_language
);
1640 set_cu_language (DW_UNSND (attr
));
1643 /* We assume that we're processing GCC output. */
1644 processing_gcc_compilation
= 2;
1646 /* FIXME:Do something here. */
1647 if (dip
->at_producer
!= NULL
)
1649 handle_producer (dip
->at_producer
);
1653 /* The compilation unit may be in a different language or objfile,
1654 zero out all remembered fundamental types. */
1655 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1657 start_symtab (name
, comp_dir
, lowpc
);
1658 record_debugformat ("DWARF 2");
1660 initialize_cu_func_list ();
1662 /* Process all dies in compilation unit. */
1663 if (die
->has_children
)
1665 child_die
= die
->next
;
1666 while (child_die
&& child_die
->tag
)
1668 process_die (child_die
, objfile
, cu_header
);
1669 child_die
= sibling_die (child_die
);
1673 /* Decode line number information if present. */
1674 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1677 line_offset
= DW_UNSND (attr
);
1678 dwarf_decode_lines (line_offset
, comp_dir
, abfd
, cu_header
);
1683 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
)
1685 struct function_range
*thisfn
;
1687 thisfn
= (struct function_range
*)
1688 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
1689 thisfn
->name
= name
;
1690 thisfn
->lowpc
= lowpc
;
1691 thisfn
->highpc
= highpc
;
1692 thisfn
->seen_line
= 0;
1693 thisfn
->next
= NULL
;
1695 if (cu_last_fn
== NULL
)
1696 cu_first_fn
= thisfn
;
1698 cu_last_fn
->next
= thisfn
;
1700 cu_last_fn
= thisfn
;
1704 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
1705 const struct comp_unit_head
*cu_header
)
1707 register struct context_stack
*new;
1710 struct die_info
*child_die
;
1711 struct attribute
*attr
;
1714 name
= dwarf2_linkage_name (die
);
1716 /* Ignore functions with missing or empty names and functions with
1717 missing or invalid low and high pc attributes. */
1718 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1724 /* Record the function range for dwarf_decode_lines. */
1725 add_to_cu_func_list (name
, lowpc
, highpc
);
1727 if (objfile
->ei
.entry_point
>= lowpc
&&
1728 objfile
->ei
.entry_point
< highpc
)
1730 objfile
->ei
.entry_func_lowpc
= lowpc
;
1731 objfile
->ei
.entry_func_highpc
= highpc
;
1734 /* Decode DW_AT_frame_base location descriptor if present, keep result
1735 for DW_OP_fbreg operands in decode_locdesc. */
1736 frame_base_reg
= -1;
1737 frame_base_offset
= 0;
1738 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1741 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
1743 complain (&dwarf2_unsupported_at_frame_base
, name
);
1745 frame_base_reg
= addr
;
1748 frame_base_reg
= basereg
;
1749 frame_base_offset
= addr
;
1752 complain (&dwarf2_unsupported_at_frame_base
, name
);
1755 new = push_context (0, lowpc
);
1756 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
1757 list_in_scope
= &local_symbols
;
1759 if (die
->has_children
)
1761 child_die
= die
->next
;
1762 while (child_die
&& child_die
->tag
)
1764 process_die (child_die
, objfile
, cu_header
);
1765 child_die
= sibling_die (child_die
);
1769 new = pop_context ();
1770 /* Make a block for the local symbols within. */
1771 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1772 lowpc
, highpc
, objfile
);
1773 list_in_scope
= &file_symbols
;
1776 /* Process all the DIES contained within a lexical block scope. Start
1777 a new scope, process the dies, and then close the scope. */
1780 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
1781 const struct comp_unit_head
*cu_header
)
1783 register struct context_stack
*new;
1784 CORE_ADDR lowpc
, highpc
;
1785 struct die_info
*child_die
;
1787 /* Ignore blocks with missing or invalid low and high pc attributes. */
1788 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1793 push_context (0, lowpc
);
1794 if (die
->has_children
)
1796 child_die
= die
->next
;
1797 while (child_die
&& child_die
->tag
)
1799 process_die (child_die
, objfile
, cu_header
);
1800 child_die
= sibling_die (child_die
);
1803 new = pop_context ();
1805 if (local_symbols
!= NULL
)
1807 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1810 local_symbols
= new->locals
;
1813 /* Get low and high pc attributes from a die.
1814 Return 1 if the attributes are present and valid, otherwise, return 0. */
1817 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1818 struct objfile
*objfile
)
1820 struct attribute
*attr
;
1824 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1826 low
= DW_ADDR (attr
);
1829 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1831 high
= DW_ADDR (attr
);
1838 /* When using the GNU linker, .gnu.linkonce. sections are used to
1839 eliminate duplicate copies of functions and vtables and such.
1840 The linker will arbitrarily choose one and discard the others.
1841 The AT_*_pc values for such functions refer to local labels in
1842 these sections. If the section from that file was discarded, the
1843 labels are not in the output, so the relocs get a value of 0.
1844 If this is a discarded function, mark the pc bounds as invalid,
1845 so that GDB will ignore it. */
1846 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1854 /* Add an aggregate field to the field list. */
1857 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
1858 struct objfile
*objfile
,
1859 const struct comp_unit_head
*cu_header
)
1861 struct nextfield
*new_field
;
1862 struct attribute
*attr
;
1864 char *fieldname
= "";
1866 /* Allocate a new field list entry and link it in. */
1867 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1868 make_cleanup (xfree
, new_field
);
1869 memset (new_field
, 0, sizeof (struct nextfield
));
1870 new_field
->next
= fip
->fields
;
1871 fip
->fields
= new_field
;
1874 /* Handle accessibility and virtuality of field.
1875 The default accessibility for members is public, the default
1876 accessibility for inheritance is private. */
1877 if (die
->tag
!= DW_TAG_inheritance
)
1878 new_field
->accessibility
= DW_ACCESS_public
;
1880 new_field
->accessibility
= DW_ACCESS_private
;
1881 new_field
->virtuality
= DW_VIRTUALITY_none
;
1883 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1885 new_field
->accessibility
= DW_UNSND (attr
);
1886 if (new_field
->accessibility
!= DW_ACCESS_public
)
1887 fip
->non_public_fields
= 1;
1888 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1890 new_field
->virtuality
= DW_UNSND (attr
);
1892 fp
= &new_field
->field
;
1893 if (die
->tag
== DW_TAG_member
)
1895 /* Get type of field. */
1896 fp
->type
= die_type (die
, objfile
, cu_header
);
1898 /* Get bit size of field (zero if none). */
1899 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1902 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1906 FIELD_BITSIZE (*fp
) = 0;
1909 /* Get bit offset of field. */
1910 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1913 FIELD_BITPOS (*fp
) =
1914 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
1917 FIELD_BITPOS (*fp
) = 0;
1918 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1921 if (BITS_BIG_ENDIAN
)
1923 /* For big endian bits, the DW_AT_bit_offset gives the
1924 additional bit offset from the MSB of the containing
1925 anonymous object to the MSB of the field. We don't
1926 have to do anything special since we don't need to
1927 know the size of the anonymous object. */
1928 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1932 /* For little endian bits, compute the bit offset to the
1933 MSB of the anonymous object, subtract off the number of
1934 bits from the MSB of the field to the MSB of the
1935 object, and then subtract off the number of bits of
1936 the field itself. The result is the bit offset of
1937 the LSB of the field. */
1939 int bit_offset
= DW_UNSND (attr
);
1941 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1944 /* The size of the anonymous object containing
1945 the bit field is explicit, so use the
1946 indicated size (in bytes). */
1947 anonymous_size
= DW_UNSND (attr
);
1951 /* The size of the anonymous object containing
1952 the bit field must be inferred from the type
1953 attribute of the data member containing the
1955 anonymous_size
= TYPE_LENGTH (fp
->type
);
1957 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1958 - bit_offset
- FIELD_BITSIZE (*fp
);
1962 /* Get name of field. */
1963 attr
= dwarf_attr (die
, DW_AT_name
);
1964 if (attr
&& DW_STRING (attr
))
1965 fieldname
= DW_STRING (attr
);
1966 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1967 &objfile
->type_obstack
);
1969 /* Change accessibility for artificial fields (e.g. virtual table
1970 pointer or virtual base class pointer) to private. */
1971 if (dwarf_attr (die
, DW_AT_artificial
))
1973 new_field
->accessibility
= DW_ACCESS_private
;
1974 fip
->non_public_fields
= 1;
1977 else if (die
->tag
== DW_TAG_variable
)
1981 /* C++ static member.
1982 Get name of field. */
1983 attr
= dwarf_attr (die
, DW_AT_name
);
1984 if (attr
&& DW_STRING (attr
))
1985 fieldname
= DW_STRING (attr
);
1989 /* Get physical name. */
1990 physname
= dwarf2_linkage_name (die
);
1992 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1993 &objfile
->type_obstack
));
1994 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1995 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1996 &objfile
->type_obstack
);
1998 else if (die
->tag
== DW_TAG_inheritance
)
2000 /* C++ base class field. */
2001 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2003 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
2005 FIELD_BITSIZE (*fp
) = 0;
2006 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2007 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2008 fip
->nbaseclasses
++;
2012 /* Create the vector of fields, and attach it to the type. */
2015 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2016 struct objfile
*objfile
)
2018 int nfields
= fip
->nfields
;
2020 /* Record the field count, allocate space for the array of fields,
2021 and create blank accessibility bitfields if necessary. */
2022 TYPE_NFIELDS (type
) = nfields
;
2023 TYPE_FIELDS (type
) = (struct field
*)
2024 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2025 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2027 if (fip
->non_public_fields
)
2029 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2031 TYPE_FIELD_PRIVATE_BITS (type
) =
2032 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2033 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2035 TYPE_FIELD_PROTECTED_BITS (type
) =
2036 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2037 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2039 TYPE_FIELD_IGNORE_BITS (type
) =
2040 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2041 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2044 /* If the type has baseclasses, allocate and clear a bit vector for
2045 TYPE_FIELD_VIRTUAL_BITS. */
2046 if (fip
->nbaseclasses
)
2048 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2051 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2052 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2053 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2054 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2055 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2058 /* Copy the saved-up fields into the field vector. Start from the head
2059 of the list, adding to the tail of the field array, so that they end
2060 up in the same order in the array in which they were added to the list. */
2061 while (nfields
-- > 0)
2063 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2064 switch (fip
->fields
->accessibility
)
2066 case DW_ACCESS_private
:
2067 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2070 case DW_ACCESS_protected
:
2071 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2074 case DW_ACCESS_public
:
2078 /* Unknown accessibility. Complain and treat it as public. */
2080 complain (&dwarf2_unsupported_accessibility
,
2081 fip
->fields
->accessibility
);
2085 if (nfields
< fip
->nbaseclasses
)
2087 switch (fip
->fields
->virtuality
)
2089 case DW_VIRTUALITY_virtual
:
2090 case DW_VIRTUALITY_pure_virtual
:
2091 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2095 fip
->fields
= fip
->fields
->next
;
2099 /* Add a member function to the proper fieldlist. */
2102 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2103 struct type
*type
, struct objfile
*objfile
,
2104 const struct comp_unit_head
*cu_header
)
2106 struct attribute
*attr
;
2107 struct fnfieldlist
*flp
;
2109 struct fn_field
*fnp
;
2112 struct nextfnfield
*new_fnfield
;
2114 /* Get name of member function. */
2115 attr
= dwarf_attr (die
, DW_AT_name
);
2116 if (attr
&& DW_STRING (attr
))
2117 fieldname
= DW_STRING (attr
);
2121 /* Get the mangled name. */
2122 physname
= dwarf2_linkage_name (die
);
2124 /* Look up member function name in fieldlist. */
2125 for (i
= 0; i
< fip
->nfnfields
; i
++)
2127 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2131 /* Create new list element if necessary. */
2132 if (i
< fip
->nfnfields
)
2133 flp
= &fip
->fnfieldlists
[i
];
2136 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2138 fip
->fnfieldlists
= (struct fnfieldlist
*)
2139 xrealloc (fip
->fnfieldlists
,
2140 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2141 * sizeof (struct fnfieldlist
));
2142 if (fip
->nfnfields
== 0)
2143 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2145 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2146 flp
->name
= fieldname
;
2152 /* Create a new member function field and chain it to the field list
2154 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2155 make_cleanup (xfree
, new_fnfield
);
2156 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2157 new_fnfield
->next
= flp
->head
;
2158 flp
->head
= new_fnfield
;
2161 /* Fill in the member function field info. */
2162 fnp
= &new_fnfield
->fnfield
;
2163 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2164 &objfile
->type_obstack
);
2165 fnp
->type
= alloc_type (objfile
);
2166 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2168 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2169 struct type
**arg_types
;
2170 int nparams
= TYPE_NFIELDS (die
->type
);
2173 /* Copy argument types from the subroutine type. */
2174 arg_types
= (struct type
**)
2175 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2176 for (iparams
= 0; iparams
< nparams
; iparams
++)
2177 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2179 /* Set last entry in argument type vector. */
2180 if (TYPE_VARARGS (die
->type
))
2181 arg_types
[nparams
] = NULL
;
2183 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2185 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2187 /* Handle static member functions.
2188 Dwarf2 has no clean way to discern C++ static and non-static
2189 member functions. G++ helps GDB by marking the first
2190 parameter for non-static member functions (which is the
2191 this pointer) as artificial. We obtain this information
2192 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2193 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2194 fnp
->voffset
= VOFFSET_STATIC
;
2197 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2199 /* Get fcontext from DW_AT_containing_type if present. */
2200 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2201 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2203 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2204 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2206 /* Get accessibility. */
2207 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2210 switch (DW_UNSND (attr
))
2212 case DW_ACCESS_private
:
2213 fnp
->is_private
= 1;
2215 case DW_ACCESS_protected
:
2216 fnp
->is_protected
= 1;
2221 /* Check for artificial methods. */
2222 attr
= dwarf_attr (die
, DW_AT_artificial
);
2223 if (attr
&& DW_UNSND (attr
) != 0)
2224 fnp
->is_artificial
= 1;
2226 /* Get index in virtual function table if it is a virtual member function. */
2227 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2229 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2232 /* Create the vector of member function fields, and attach it to the type. */
2235 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2236 struct objfile
*objfile
)
2238 struct fnfieldlist
*flp
;
2239 int total_length
= 0;
2242 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2243 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2244 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2246 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2248 struct nextfnfield
*nfp
= flp
->head
;
2249 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2252 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2253 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2254 fn_flp
->fn_fields
= (struct fn_field
*)
2255 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2256 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2257 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2259 total_length
+= flp
->length
;
2262 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2263 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2266 /* Called when we find the DIE that starts a structure or union scope
2267 (definition) to process all dies that define the members of the
2270 NOTE: we need to call struct_type regardless of whether or not the
2271 DIE has an at_name attribute, since it might be an anonymous
2272 structure or union. This gets the type entered into our set of
2275 However, if the structure is incomplete (an opaque struct/union)
2276 then suppress creating a symbol table entry for it since gdb only
2277 wants to find the one with the complete definition. Note that if
2278 it is complete, we just call new_symbol, which does it's own
2279 checking about whether the struct/union is anonymous or not (and
2280 suppresses creating a symbol table entry itself). */
2283 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2284 const struct comp_unit_head
*cu_header
)
2287 struct attribute
*attr
;
2289 type
= alloc_type (objfile
);
2291 INIT_CPLUS_SPECIFIC (type
);
2292 attr
= dwarf_attr (die
, DW_AT_name
);
2293 if (attr
&& DW_STRING (attr
))
2295 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2296 strlen (DW_STRING (attr
)),
2297 &objfile
->type_obstack
);
2300 if (die
->tag
== DW_TAG_structure_type
)
2302 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2304 else if (die
->tag
== DW_TAG_union_type
)
2306 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2310 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2312 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2315 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2318 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2322 TYPE_LENGTH (type
) = 0;
2325 /* We need to add the type field to the die immediately so we don't
2326 infinitely recurse when dealing with pointers to the structure
2327 type within the structure itself. */
2330 if (die
->has_children
&& ! die_is_declaration (die
))
2332 struct field_info fi
;
2333 struct die_info
*child_die
;
2334 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2336 memset (&fi
, 0, sizeof (struct field_info
));
2338 child_die
= die
->next
;
2340 while (child_die
&& child_die
->tag
)
2342 if (child_die
->tag
== DW_TAG_member
)
2344 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2346 else if (child_die
->tag
== DW_TAG_variable
)
2348 /* C++ static member. */
2349 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2351 else if (child_die
->tag
== DW_TAG_subprogram
)
2353 /* C++ member function. */
2354 process_die (child_die
, objfile
, cu_header
);
2355 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2357 else if (child_die
->tag
== DW_TAG_inheritance
)
2359 /* C++ base class field. */
2360 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2364 process_die (child_die
, objfile
, cu_header
);
2366 child_die
= sibling_die (child_die
);
2369 /* Attach fields and member functions to the type. */
2371 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2374 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2376 /* Get the type which refers to the base class (possibly this
2377 class itself) which contains the vtable pointer for the current
2378 class from the DW_AT_containing_type attribute. */
2380 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2382 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2384 TYPE_VPTR_BASETYPE (type
) = t
;
2387 static const char vptr_name
[] =
2388 {'_', 'v', 'p', 't', 'r', '\0'};
2391 /* Our own class provides vtbl ptr. */
2392 for (i
= TYPE_NFIELDS (t
) - 1;
2393 i
>= TYPE_N_BASECLASSES (t
);
2396 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2398 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2399 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2401 TYPE_VPTR_FIELDNO (type
) = i
;
2406 /* Complain if virtual function table field not found. */
2407 if (i
< TYPE_N_BASECLASSES (t
))
2408 complain (&dwarf2_vtbl_not_found_complaint
,
2409 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2413 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2418 new_symbol (die
, type
, objfile
, cu_header
);
2420 do_cleanups (back_to
);
2424 /* No children, must be stub. */
2425 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2428 finish_cv_type (die
->type
);
2431 /* Given a pointer to a die which begins an enumeration, process all
2432 the dies that define the members of the enumeration.
2434 This will be much nicer in draft 6 of the DWARF spec when our
2435 members will be dies instead squished into the DW_AT_element_list
2438 NOTE: We reverse the order of the element list. */
2441 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2442 const struct comp_unit_head
*cu_header
)
2444 struct die_info
*child_die
;
2446 struct field
*fields
;
2447 struct attribute
*attr
;
2450 int unsigned_enum
= 1;
2452 type
= alloc_type (objfile
);
2454 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2455 attr
= dwarf_attr (die
, DW_AT_name
);
2456 if (attr
&& DW_STRING (attr
))
2458 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2459 strlen (DW_STRING (attr
)),
2460 &objfile
->type_obstack
);
2463 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2466 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2470 TYPE_LENGTH (type
) = 0;
2475 if (die
->has_children
)
2477 child_die
= die
->next
;
2478 while (child_die
&& child_die
->tag
)
2480 if (child_die
->tag
!= DW_TAG_enumerator
)
2482 process_die (child_die
, objfile
, cu_header
);
2486 attr
= dwarf_attr (child_die
, DW_AT_name
);
2489 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2490 if (SYMBOL_VALUE (sym
) < 0)
2493 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2495 fields
= (struct field
*)
2497 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2498 * sizeof (struct field
));
2501 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2502 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2503 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2504 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2510 child_die
= sibling_die (child_die
);
2515 TYPE_NFIELDS (type
) = num_fields
;
2516 TYPE_FIELDS (type
) = (struct field
*)
2517 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2518 memcpy (TYPE_FIELDS (type
), fields
,
2519 sizeof (struct field
) * num_fields
);
2523 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2526 new_symbol (die
, type
, objfile
, cu_header
);
2529 /* Extract all information from a DW_TAG_array_type DIE and put it in
2530 the DIE's type field. For now, this only handles one dimensional
2534 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
2535 const struct comp_unit_head
*cu_header
)
2537 struct die_info
*child_die
;
2538 struct type
*type
= NULL
;
2539 struct type
*element_type
, *range_type
, *index_type
;
2540 struct type
**range_types
= NULL
;
2541 struct attribute
*attr
;
2543 struct cleanup
*back_to
;
2545 /* Return if we've already decoded this type. */
2551 element_type
= die_type (die
, objfile
, cu_header
);
2553 /* Irix 6.2 native cc creates array types without children for
2554 arrays with unspecified length. */
2555 if (die
->has_children
== 0)
2557 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2558 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2559 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2563 back_to
= make_cleanup (null_cleanup
, NULL
);
2564 child_die
= die
->next
;
2565 while (child_die
&& child_die
->tag
)
2567 if (child_die
->tag
== DW_TAG_subrange_type
)
2569 unsigned int low
, high
;
2571 /* Default bounds to an array with unspecified length. */
2574 if (cu_language
== language_fortran
)
2576 /* FORTRAN implies a lower bound of 1, if not given. */
2580 index_type
= die_type (child_die
, objfile
, cu_header
);
2581 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2584 if (attr
->form
== DW_FORM_sdata
)
2586 low
= DW_SND (attr
);
2588 else if (attr
->form
== DW_FORM_udata
2589 || attr
->form
== DW_FORM_data1
2590 || attr
->form
== DW_FORM_data2
2591 || attr
->form
== DW_FORM_data4
2592 || attr
->form
== DW_FORM_data8
)
2594 low
= DW_UNSND (attr
);
2598 complain (&dwarf2_non_const_array_bound_ignored
,
2599 dwarf_form_name (attr
->form
));
2601 die
->type
= lookup_pointer_type (element_type
);
2608 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2611 if (attr
->form
== DW_FORM_sdata
)
2613 high
= DW_SND (attr
);
2615 else if (attr
->form
== DW_FORM_udata
2616 || attr
->form
== DW_FORM_data1
2617 || attr
->form
== DW_FORM_data2
2618 || attr
->form
== DW_FORM_data4
2619 || attr
->form
== DW_FORM_data8
)
2621 high
= DW_UNSND (attr
);
2623 else if (attr
->form
== DW_FORM_block1
)
2625 /* GCC encodes arrays with unspecified or dynamic length
2626 with a DW_FORM_block1 attribute.
2627 FIXME: GDB does not yet know how to handle dynamic
2628 arrays properly, treat them as arrays with unspecified
2634 complain (&dwarf2_non_const_array_bound_ignored
,
2635 dwarf_form_name (attr
->form
));
2637 die
->type
= lookup_pointer_type (element_type
);
2645 /* Create a range type and save it for array type creation. */
2646 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2648 range_types
= (struct type
**)
2649 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2650 * sizeof (struct type
*));
2652 make_cleanup (free_current_contents
, &range_types
);
2654 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2656 child_die
= sibling_die (child_die
);
2659 /* Dwarf2 dimensions are output from left to right, create the
2660 necessary array types in backwards order. */
2661 type
= element_type
;
2663 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2665 /* Understand Dwarf2 support for vector types (like they occur on
2666 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
2667 array type. This is not part of the Dwarf2/3 standard yet, but a
2668 custom vendor extension. The main difference between a regular
2669 array and the vector variant is that vectors are passed by value
2671 attr
= dwarf_attr (die
, DW_AT_GNU_vector
);
2673 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
2675 do_cleanups (back_to
);
2677 /* Install the type in the die. */
2681 /* First cut: install each common block member as a global variable. */
2684 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
2685 const struct comp_unit_head
*cu_header
)
2687 struct die_info
*child_die
;
2688 struct attribute
*attr
;
2690 CORE_ADDR base
= (CORE_ADDR
) 0;
2692 attr
= dwarf_attr (die
, DW_AT_location
);
2695 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2697 if (die
->has_children
)
2699 child_die
= die
->next
;
2700 while (child_die
&& child_die
->tag
)
2702 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
2703 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2706 SYMBOL_VALUE_ADDRESS (sym
) =
2707 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2708 add_symbol_to_list (sym
, &global_symbols
);
2710 child_die
= sibling_die (child_die
);
2715 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2716 the user defined type vector. */
2719 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
2720 const struct comp_unit_head
*cu_header
)
2723 struct attribute
*attr
;
2730 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
2731 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2734 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2738 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2743 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2744 the user defined type vector. */
2747 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
2748 const struct comp_unit_head
*cu_header
)
2751 struct type
*to_type
;
2752 struct type
*domain
;
2759 type
= alloc_type (objfile
);
2760 to_type
= die_type (die
, objfile
, cu_header
);
2761 domain
= die_containing_type (die
, objfile
, cu_header
);
2762 smash_to_member_type (type
, domain
, to_type
);
2767 /* Extract all information from a DW_TAG_reference_type DIE and add to
2768 the user defined type vector. */
2771 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
2772 const struct comp_unit_head
*cu_header
)
2775 struct attribute
*attr
;
2782 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
2783 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2786 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2790 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2796 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
2797 const struct comp_unit_head
*cu_header
)
2799 struct type
*base_type
;
2806 base_type
= die_type (die
, objfile
, cu_header
);
2807 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
2811 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
2812 const struct comp_unit_head
*cu_header
)
2814 struct type
*base_type
;
2821 base_type
= die_type (die
, objfile
, cu_header
);
2822 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
2825 /* Extract all information from a DW_TAG_string_type DIE and add to
2826 the user defined type vector. It isn't really a user defined type,
2827 but it behaves like one, with other DIE's using an AT_user_def_type
2828 attribute to reference it. */
2831 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
2833 struct type
*type
, *range_type
, *index_type
, *char_type
;
2834 struct attribute
*attr
;
2835 unsigned int length
;
2842 attr
= dwarf_attr (die
, DW_AT_string_length
);
2845 length
= DW_UNSND (attr
);
2849 /* check for the DW_AT_byte_size attribute */
2850 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2853 length
= DW_UNSND (attr
);
2860 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2861 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2862 if (cu_language
== language_fortran
)
2864 /* Need to create a unique string type for bounds
2866 type
= create_string_type (0, range_type
);
2870 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2871 type
= create_string_type (char_type
, range_type
);
2876 /* Handle DIES due to C code like:
2880 int (*funcp)(int a, long l);
2884 ('funcp' generates a DW_TAG_subroutine_type DIE)
2888 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
2889 const struct comp_unit_head
*cu_header
)
2891 struct type
*type
; /* Type that this function returns */
2892 struct type
*ftype
; /* Function that returns above type */
2893 struct attribute
*attr
;
2895 /* Decode the type that this subroutine returns */
2900 type
= die_type (die
, objfile
, cu_header
);
2901 ftype
= lookup_function_type (type
);
2903 /* All functions in C++ have prototypes. */
2904 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2905 if ((attr
&& (DW_UNSND (attr
) != 0))
2906 || cu_language
== language_cplus
)
2907 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2909 if (die
->has_children
)
2911 struct die_info
*child_die
;
2915 /* Count the number of parameters.
2916 FIXME: GDB currently ignores vararg functions, but knows about
2917 vararg member functions. */
2918 child_die
= die
->next
;
2919 while (child_die
&& child_die
->tag
)
2921 if (child_die
->tag
== DW_TAG_formal_parameter
)
2923 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2924 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2925 child_die
= sibling_die (child_die
);
2928 /* Allocate storage for parameters and fill them in. */
2929 TYPE_NFIELDS (ftype
) = nparams
;
2930 TYPE_FIELDS (ftype
) = (struct field
*)
2931 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2933 child_die
= die
->next
;
2934 while (child_die
&& child_die
->tag
)
2936 if (child_die
->tag
== DW_TAG_formal_parameter
)
2938 /* Dwarf2 has no clean way to discern C++ static and non-static
2939 member functions. G++ helps GDB by marking the first
2940 parameter for non-static member functions (which is the
2941 this pointer) as artificial. We pass this information
2942 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2943 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2945 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2947 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2948 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
2952 child_die
= sibling_die (child_die
);
2960 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
2961 const struct comp_unit_head
*cu_header
)
2963 struct attribute
*attr
;
2968 attr
= dwarf_attr (die
, DW_AT_name
);
2969 if (attr
&& DW_STRING (attr
))
2971 name
= DW_STRING (attr
);
2973 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
2974 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, objfile
, cu_header
);
2978 /* Find a representation of a given base type and install
2979 it in the TYPE field of the die. */
2982 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
2985 struct attribute
*attr
;
2986 int encoding
= 0, size
= 0;
2988 /* If we've already decoded this die, this is a no-op. */
2994 attr
= dwarf_attr (die
, DW_AT_encoding
);
2997 encoding
= DW_UNSND (attr
);
2999 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3002 size
= DW_UNSND (attr
);
3004 attr
= dwarf_attr (die
, DW_AT_name
);
3005 if (attr
&& DW_STRING (attr
))
3007 enum type_code code
= TYPE_CODE_INT
;
3012 case DW_ATE_address
:
3013 /* Turn DW_ATE_address into a void * pointer. */
3014 code
= TYPE_CODE_PTR
;
3015 type_flags
|= TYPE_FLAG_UNSIGNED
;
3017 case DW_ATE_boolean
:
3018 code
= TYPE_CODE_BOOL
;
3019 type_flags
|= TYPE_FLAG_UNSIGNED
;
3021 case DW_ATE_complex_float
:
3022 code
= TYPE_CODE_COMPLEX
;
3025 code
= TYPE_CODE_FLT
;
3028 case DW_ATE_signed_char
:
3030 case DW_ATE_unsigned
:
3031 case DW_ATE_unsigned_char
:
3032 type_flags
|= TYPE_FLAG_UNSIGNED
;
3035 complain (&dwarf2_unsupported_at_encoding
,
3036 dwarf_type_encoding_name (encoding
));
3039 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
3040 if (encoding
== DW_ATE_address
)
3041 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
3042 else if (encoding
== DW_ATE_complex_float
)
3045 TYPE_TARGET_TYPE (type
)
3046 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3047 else if (size
== 16)
3048 TYPE_TARGET_TYPE (type
)
3049 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3051 TYPE_TARGET_TYPE (type
)
3052 = dwarf2_fundamental_type (objfile
, FT_FLOAT
);
3057 type
= dwarf_base_type (encoding
, size
, objfile
);
3062 /* Read a whole compilation unit into a linked list of dies. */
3064 static struct die_info
*
3065 read_comp_unit (char *info_ptr
, bfd
*abfd
,
3066 const struct comp_unit_head
*cu_header
)
3068 struct die_info
*first_die
, *last_die
, *die
;
3072 /* Reset die reference table; we are
3073 building new ones now. */
3074 dwarf2_empty_hash_tables ();
3078 first_die
= last_die
= NULL
;
3081 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
3082 if (die
->has_children
)
3093 /* Enter die in reference hash table */
3094 store_in_ref_table (die
->offset
, die
);
3098 first_die
= last_die
= die
;
3102 last_die
->next
= die
;
3106 while (nesting_level
> 0);
3110 /* Free a linked list of dies. */
3113 free_die_list (struct die_info
*dies
)
3115 struct die_info
*die
, *next
;
3128 do_free_die_list_cleanup (void *dies
)
3130 free_die_list (dies
);
3133 static struct cleanup
*
3134 make_cleanup_free_die_list (struct die_info
*dies
)
3136 return make_cleanup (do_free_die_list_cleanup
, dies
);
3140 /* Read the contents of the section at OFFSET and of size SIZE from the
3141 object file specified by OBJFILE into the psymbol_obstack and return it. */
3144 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
3147 bfd
*abfd
= objfile
->obfd
;
3153 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3154 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3155 (bfd_bread (buf
, size
, abfd
) != size
))
3158 error ("Dwarf Error: Can't read DWARF data from '%s'",
3159 bfd_get_filename (abfd
));
3164 /* In DWARF version 2, the description of the debugging information is
3165 stored in a separate .debug_abbrev section. Before we read any
3166 dies from a section we read in all abbreviations and install them
3170 dwarf2_read_abbrevs (bfd
*abfd
, unsigned int offset
)
3173 struct abbrev_info
*cur_abbrev
;
3174 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3175 unsigned int abbrev_form
, hash_number
;
3177 /* empty the table */
3178 dwarf2_empty_abbrev_table (NULL
);
3180 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3181 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3182 abbrev_ptr
+= bytes_read
;
3184 /* loop until we reach an abbrev number of 0 */
3185 while (abbrev_number
)
3187 cur_abbrev
= dwarf_alloc_abbrev ();
3189 /* read in abbrev header */
3190 cur_abbrev
->number
= abbrev_number
;
3191 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3192 abbrev_ptr
+= bytes_read
;
3193 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3196 /* now read in declarations */
3197 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3198 abbrev_ptr
+= bytes_read
;
3199 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3200 abbrev_ptr
+= bytes_read
;
3203 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3205 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3206 xrealloc (cur_abbrev
->attrs
,
3207 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3208 * sizeof (struct attr_abbrev
));
3210 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3211 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3212 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3213 abbrev_ptr
+= bytes_read
;
3214 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3215 abbrev_ptr
+= bytes_read
;
3218 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3219 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3220 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3222 /* Get next abbreviation.
3223 Under Irix6 the abbreviations for a compilation unit are not
3224 always properly terminated with an abbrev number of 0.
3225 Exit loop if we encounter an abbreviation which we have
3226 already read (which means we are about to read the abbreviations
3227 for the next compile unit) or if the end of the abbreviation
3228 table is reached. */
3229 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3230 >= dwarf_abbrev_size
)
3232 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3233 abbrev_ptr
+= bytes_read
;
3234 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3239 /* Empty the abbrev table for a new compilation unit. */
3243 dwarf2_empty_abbrev_table (PTR ignore
)
3246 struct abbrev_info
*abbrev
, *next
;
3248 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3251 abbrev
= dwarf2_abbrevs
[i
];
3254 next
= abbrev
->next
;
3255 xfree (abbrev
->attrs
);
3259 dwarf2_abbrevs
[i
] = NULL
;
3263 /* Lookup an abbrev_info structure in the abbrev hash table. */
3265 static struct abbrev_info
*
3266 dwarf2_lookup_abbrev (unsigned int number
)
3268 unsigned int hash_number
;
3269 struct abbrev_info
*abbrev
;
3271 hash_number
= number
% ABBREV_HASH_SIZE
;
3272 abbrev
= dwarf2_abbrevs
[hash_number
];
3276 if (abbrev
->number
== number
)
3279 abbrev
= abbrev
->next
;
3284 /* Read a minimal amount of information into the minimal die structure. */
3287 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3288 char *info_ptr
, const struct comp_unit_head
*cu_header
)
3290 unsigned int abbrev_number
, bytes_read
, i
;
3291 struct abbrev_info
*abbrev
;
3292 struct attribute attr
;
3293 struct attribute spec_attr
;
3294 int found_spec_attr
= 0;
3295 int has_low_pc_attr
= 0;
3296 int has_high_pc_attr
= 0;
3298 *part_die
= zeroed_partial_die
;
3299 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3300 info_ptr
+= bytes_read
;
3304 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3307 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3309 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3310 part_die
->tag
= abbrev
->tag
;
3311 part_die
->has_children
= abbrev
->has_children
;
3312 part_die
->abbrev
= abbrev_number
;
3314 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3316 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3317 info_ptr
, cu_header
);
3319 /* Store the data if it is of an attribute we want to keep in a
3320 partial symbol table. */
3325 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3326 if (part_die
->name
== NULL
)
3327 part_die
->name
= DW_STRING (&attr
);
3329 case DW_AT_MIPS_linkage_name
:
3330 part_die
->name
= DW_STRING (&attr
);
3333 has_low_pc_attr
= 1;
3334 part_die
->lowpc
= DW_ADDR (&attr
);
3337 has_high_pc_attr
= 1;
3338 part_die
->highpc
= DW_ADDR (&attr
);
3340 case DW_AT_location
:
3341 part_die
->locdesc
= DW_BLOCK (&attr
);
3343 case DW_AT_language
:
3344 part_die
->language
= DW_UNSND (&attr
);
3346 case DW_AT_external
:
3347 part_die
->is_external
= DW_UNSND (&attr
);
3349 case DW_AT_declaration
:
3350 part_die
->is_declaration
= DW_UNSND (&attr
);
3353 part_die
->has_type
= 1;
3355 case DW_AT_abstract_origin
:
3356 case DW_AT_specification
:
3357 found_spec_attr
= 1;
3361 /* Ignore absolute siblings, they might point outside of
3362 the current compile unit. */
3363 if (attr
.form
== DW_FORM_ref_addr
)
3364 complain (&dwarf2_absolute_sibling_complaint
);
3367 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3374 /* If we found a reference attribute and the die has no name, try
3375 to find a name in the referred to die. */
3377 if (found_spec_attr
&& part_die
->name
== NULL
)
3379 struct partial_die_info spec_die
;
3383 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3384 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu_header
);
3387 part_die
->name
= spec_die
.name
;
3389 /* Copy DW_AT_external attribute if it is set. */
3390 if (spec_die
.is_external
)
3391 part_die
->is_external
= spec_die
.is_external
;
3395 /* When using the GNU linker, .gnu.linkonce. sections are used to
3396 eliminate duplicate copies of functions and vtables and such.
3397 The linker will arbitrarily choose one and discard the others.
3398 The AT_*_pc values for such functions refer to local labels in
3399 these sections. If the section from that file was discarded, the
3400 labels are not in the output, so the relocs get a value of 0.
3401 If this is a discarded function, mark the pc bounds as invalid,
3402 so that GDB will ignore it. */
3403 if (has_low_pc_attr
&& has_high_pc_attr
3404 && part_die
->lowpc
< part_die
->highpc
3405 && (part_die
->lowpc
!= 0
3406 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3407 part_die
->has_pc_info
= 1;
3411 /* Read the die from the .debug_info section buffer. And set diep to
3412 point to a newly allocated die with its information. */
3415 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3416 const struct comp_unit_head
*cu_header
)
3418 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3419 struct abbrev_info
*abbrev
;
3420 struct die_info
*die
;
3422 offset
= info_ptr
- dwarf_info_buffer
;
3423 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3424 info_ptr
+= bytes_read
;
3427 die
= dwarf_alloc_die ();
3429 die
->abbrev
= abbrev_number
;
3435 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3438 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3440 die
= dwarf_alloc_die ();
3441 die
->offset
= offset
;
3442 die
->tag
= abbrev
->tag
;
3443 die
->has_children
= abbrev
->has_children
;
3444 die
->abbrev
= abbrev_number
;
3447 die
->num_attrs
= abbrev
->num_attrs
;
3448 die
->attrs
= (struct attribute
*)
3449 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3451 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3453 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3454 abfd
, info_ptr
, cu_header
);
3461 /* Read an attribute value described by an attribute form. */
3464 read_attribute_value (struct attribute
*attr
, unsigned form
,
3465 bfd
*abfd
, char *info_ptr
,
3466 const struct comp_unit_head
*cu_header
)
3468 unsigned int bytes_read
;
3469 struct dwarf_block
*blk
;
3475 case DW_FORM_ref_addr
:
3476 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3477 info_ptr
+= bytes_read
;
3479 case DW_FORM_block2
:
3480 blk
= dwarf_alloc_block ();
3481 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3483 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3484 info_ptr
+= blk
->size
;
3485 DW_BLOCK (attr
) = blk
;
3487 case DW_FORM_block4
:
3488 blk
= dwarf_alloc_block ();
3489 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3491 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3492 info_ptr
+= blk
->size
;
3493 DW_BLOCK (attr
) = blk
;
3496 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3500 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3504 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3507 case DW_FORM_string
:
3508 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3509 info_ptr
+= bytes_read
;
3512 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
3514 info_ptr
+= bytes_read
;
3517 blk
= dwarf_alloc_block ();
3518 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3519 info_ptr
+= bytes_read
;
3520 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3521 info_ptr
+= blk
->size
;
3522 DW_BLOCK (attr
) = blk
;
3524 case DW_FORM_block1
:
3525 blk
= dwarf_alloc_block ();
3526 blk
->size
= read_1_byte (abfd
, info_ptr
);
3528 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3529 info_ptr
+= blk
->size
;
3530 DW_BLOCK (attr
) = blk
;
3533 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3537 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3541 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3542 info_ptr
+= bytes_read
;
3545 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3546 info_ptr
+= bytes_read
;
3549 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3553 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3557 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3561 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3564 case DW_FORM_ref_udata
:
3565 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3566 info_ptr
+= bytes_read
;
3568 case DW_FORM_indirect
:
3569 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3570 info_ptr
+= bytes_read
;
3571 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu_header
);
3574 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3575 dwarf_form_name (form
));
3580 /* Read an attribute described by an abbreviated attribute. */
3583 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
3584 bfd
*abfd
, char *info_ptr
,
3585 const struct comp_unit_head
*cu_header
)
3587 attr
->name
= abbrev
->name
;
3588 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu_header
);
3591 /* read dwarf information from a buffer */
3594 read_1_byte (bfd
*abfd
, char *buf
)
3596 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3600 read_1_signed_byte (bfd
*abfd
, char *buf
)
3602 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3606 read_2_bytes (bfd
*abfd
, char *buf
)
3608 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3612 read_2_signed_bytes (bfd
*abfd
, char *buf
)
3614 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3618 read_4_bytes (bfd
*abfd
, char *buf
)
3620 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3624 read_4_signed_bytes (bfd
*abfd
, char *buf
)
3626 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3629 static unsigned long
3630 read_8_bytes (bfd
*abfd
, char *buf
)
3632 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3636 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3639 CORE_ADDR retval
= 0;
3641 if (cu_header
->signed_addr_p
)
3643 switch (cu_header
->addr_size
)
3646 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3649 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3652 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
3655 internal_error (__FILE__
, __LINE__
,
3656 "read_address: bad switch, signed");
3661 switch (cu_header
->addr_size
)
3664 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3667 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3670 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3673 internal_error (__FILE__
, __LINE__
,
3674 "read_address: bad switch, unsigned");
3678 *bytes_read
= cu_header
->addr_size
;
3682 /* Reads the initial length from a section. The (draft) DWARF 2.1
3683 specification allows the initial length to take up either 4 bytes
3684 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
3685 bytes describe the length and all offsets will be 8 bytes in length
3688 The value returned via bytes_read should be used to increment
3689 the relevant pointer after calling read_initial_length().
3691 As a side effect, this function sets the fields initial_length_size
3692 and offset_size in cu_header to the values appropriate for the
3693 length field. (The format of the initial length field determines
3694 the width of file offsets to be fetched later with fetch_offset().)
3696 [ Note: read_initial_length() and read_offset() are based on the
3697 document entitled "DWARF Debugging Information Format", revision
3698 2.1, draft 4, dated July 20, 2000. This document was obtained
3701 http://reality.sgi.com/dehnert_engr/dwarf/dwarf2p1-draft4-000720.pdf
3703 This document is only a draft and is subject to change. (So beware.)
3705 - Kevin, Aug 4, 2000
3709 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
3714 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3716 if (retval
== 0xffffffff)
3718 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
3720 if (cu_header
!= NULL
)
3722 cu_header
->initial_length_size
= 12;
3723 cu_header
->offset_size
= 8;
3729 if (cu_header
!= NULL
)
3731 cu_header
->initial_length_size
= 4;
3732 cu_header
->offset_size
= 4;
3739 /* Read an offset from the data stream. The size of the offset is
3740 given by cu_header->offset_size. */
3743 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3748 switch (cu_header
->offset_size
)
3751 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3755 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3759 internal_error (__FILE__
, __LINE__
,
3760 "read_offset: bad switch");
3767 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
3769 /* If the size of a host char is 8 bits, we can return a pointer
3770 to the buffer, otherwise we have to copy the data to a buffer
3771 allocated on the temporary obstack. */
3772 gdb_assert (HOST_CHAR_BIT
== 8);
3777 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3779 /* If the size of a host char is 8 bits, we can return a pointer
3780 to the string, otherwise we have to copy the string to a buffer
3781 allocated on the temporary obstack. */
3782 gdb_assert (HOST_CHAR_BIT
== 8);
3785 *bytes_read_ptr
= 1;
3788 *bytes_read_ptr
= strlen (buf
) + 1;
3793 read_indirect_string (bfd
*abfd
, char *buf
,
3794 const struct comp_unit_head
*cu_header
,
3795 unsigned int *bytes_read_ptr
)
3797 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
3798 (int *) bytes_read_ptr
);
3800 if (dwarf_str_buffer
== NULL
)
3802 error ("DW_FORM_strp used without .debug_str section");
3805 if (str_offset
>= dwarf_str_size
)
3807 error ("DW_FORM_strp pointing outside of .debug_str section");
3810 gdb_assert (HOST_CHAR_BIT
== 8);
3811 if (dwarf_str_buffer
[str_offset
] == '\0')
3813 return dwarf_str_buffer
+ str_offset
;
3816 static unsigned long
3817 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3819 unsigned long result
;
3820 unsigned int num_read
;
3830 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3833 result
|= ((unsigned long)(byte
& 127) << shift
);
3834 if ((byte
& 128) == 0)
3840 *bytes_read_ptr
= num_read
;
3845 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3848 int i
, shift
, size
, num_read
;
3858 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3861 result
|= ((long)(byte
& 127) << shift
);
3863 if ((byte
& 128) == 0)
3868 if ((shift
< size
) && (byte
& 0x40))
3870 result
|= -(1 << shift
);
3872 *bytes_read_ptr
= num_read
;
3877 set_cu_language (unsigned int lang
)
3883 cu_language
= language_c
;
3885 case DW_LANG_C_plus_plus
:
3886 cu_language
= language_cplus
;
3888 case DW_LANG_Fortran77
:
3889 case DW_LANG_Fortran90
:
3890 case DW_LANG_Fortran95
:
3891 cu_language
= language_fortran
;
3893 case DW_LANG_Mips_Assembler
:
3894 cu_language
= language_asm
;
3897 cu_language
= language_java
;
3900 case DW_LANG_Cobol74
:
3901 case DW_LANG_Cobol85
:
3902 case DW_LANG_Pascal83
:
3903 case DW_LANG_Modula2
:
3905 cu_language
= language_unknown
;
3908 cu_language_defn
= language_def (cu_language
);
3911 /* Return the named attribute or NULL if not there. */
3913 static struct attribute
*
3914 dwarf_attr (struct die_info
*die
, unsigned int name
)
3917 struct attribute
*spec
= NULL
;
3919 for (i
= 0; i
< die
->num_attrs
; ++i
)
3921 if (die
->attrs
[i
].name
== name
)
3923 return &die
->attrs
[i
];
3925 if (die
->attrs
[i
].name
== DW_AT_specification
3926 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3927 spec
= &die
->attrs
[i
];
3931 struct die_info
*ref_die
=
3932 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3935 return dwarf_attr (ref_die
, name
);
3942 die_is_declaration (struct die_info
*die
)
3944 return (dwarf_attr (die
, DW_AT_declaration
)
3945 && ! dwarf_attr (die
, DW_AT_specification
));
3948 /* Decode the line number information for the compilation unit whose
3949 line number info is at OFFSET in the .debug_line section.
3950 The compilation directory of the file is passed in COMP_DIR. */
3954 unsigned int num_files
;
3967 unsigned int num_dirs
;
3971 /* This function exists to work around a bug in certain compilers
3972 (particularly GCC 2.95), in which the first line number marker of a
3973 function does not show up until after the prologue, right before
3974 the second line number marker. This function shifts ADDRESS down
3975 to the beginning of the function if necessary, and is called on
3976 addresses passed to record_line. */
3979 check_cu_functions (CORE_ADDR address
)
3981 struct function_range
*fn
;
3983 /* Find the function_range containing address. */
3988 cu_cached_fn
= cu_first_fn
;
3992 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
3998 while (fn
&& fn
!= cu_cached_fn
)
3999 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4009 if (address
!= fn
->lowpc
)
4010 complain (&dwarf2_misplaced_line_number
,
4011 (unsigned long) address
, fn
->name
);
4017 dwarf_decode_lines (unsigned int offset
, char *comp_dir
, bfd
*abfd
,
4018 const struct comp_unit_head
*cu_header
)
4022 struct line_head lh
;
4023 struct cleanup
*back_to
;
4024 unsigned int i
, bytes_read
;
4025 char *cur_file
, *cur_dir
;
4026 unsigned char op_code
, extended_op
, adj_opcode
;
4028 #define FILE_ALLOC_CHUNK 5
4029 #define DIR_ALLOC_CHUNK 5
4031 struct filenames files
;
4032 struct directories dirs
;
4034 if (dwarf_line_buffer
== NULL
)
4036 complain (&dwarf2_missing_line_number_section
);
4040 files
.num_files
= 0;
4046 line_ptr
= dwarf_line_buffer
+ offset
;
4048 /* read in the prologue */
4049 lh
.total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
4050 line_ptr
+= bytes_read
;
4051 line_end
= line_ptr
+ lh
.total_length
;
4052 lh
.version
= read_2_bytes (abfd
, line_ptr
);
4054 lh
.prologue_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
4055 line_ptr
+= bytes_read
;
4056 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
4058 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
4060 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
4062 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
4064 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
4066 lh
.standard_opcode_lengths
= (unsigned char *)
4067 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
4068 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
4070 lh
.standard_opcode_lengths
[0] = 1;
4071 for (i
= 1; i
< lh
.opcode_base
; ++i
)
4073 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
4077 /* Read directory table */
4078 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4080 line_ptr
+= bytes_read
;
4081 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
4083 dirs
.dirs
= (char **)
4084 xrealloc (dirs
.dirs
,
4085 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
4086 if (dirs
.num_dirs
== 0)
4087 make_cleanup (free_current_contents
, &dirs
.dirs
);
4089 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
4091 line_ptr
+= bytes_read
;
4093 /* Read file name table */
4094 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4096 line_ptr
+= bytes_read
;
4097 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
4099 files
.files
= (struct fileinfo
*)
4100 xrealloc (files
.files
,
4101 (files
.num_files
+ FILE_ALLOC_CHUNK
)
4102 * sizeof (struct fileinfo
));
4103 if (files
.num_files
== 0)
4104 make_cleanup (free_current_contents
, &files
.files
);
4106 files
.files
[files
.num_files
].name
= cur_file
;
4107 files
.files
[files
.num_files
].dir
=
4108 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4109 line_ptr
+= bytes_read
;
4110 files
.files
[files
.num_files
].time
=
4111 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4112 line_ptr
+= bytes_read
;
4113 files
.files
[files
.num_files
].size
=
4114 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4115 line_ptr
+= bytes_read
;
4118 line_ptr
+= bytes_read
;
4120 /* Read the statement sequences until there's nothing left. */
4121 while (line_ptr
< line_end
)
4123 /* state machine registers */
4124 CORE_ADDR address
= 0;
4125 unsigned int file
= 1;
4126 unsigned int line
= 1;
4127 unsigned int column
= 0;
4128 int is_stmt
= lh
.default_is_stmt
;
4129 int basic_block
= 0;
4130 int end_sequence
= 0;
4132 /* Start a subfile for the current file of the state machine. */
4133 if (files
.num_files
>= file
)
4135 /* The file and directory tables are 0 based, the references
4137 dwarf2_start_subfile (files
.files
[file
- 1].name
,
4138 (files
.files
[file
- 1].dir
4139 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
4143 /* Decode the table. */
4144 while (!end_sequence
)
4146 op_code
= read_1_byte (abfd
, line_ptr
);
4149 if (op_code
>= lh
.opcode_base
)
4150 { /* Special operand. */
4151 adj_opcode
= op_code
- lh
.opcode_base
;
4152 address
+= (adj_opcode
/ lh
.line_range
)
4153 * lh
.minimum_instruction_length
;
4154 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
4155 /* append row to matrix using current values */
4156 address
= check_cu_functions (address
);
4157 record_line (current_subfile
, line
, address
);
4160 else switch (op_code
)
4162 case DW_LNS_extended_op
:
4163 line_ptr
+= 1; /* ignore length */
4164 extended_op
= read_1_byte (abfd
, line_ptr
);
4166 switch (extended_op
)
4168 case DW_LNE_end_sequence
:
4170 record_line (current_subfile
, 0, address
);
4172 case DW_LNE_set_address
:
4173 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
4174 line_ptr
+= bytes_read
;
4175 address
+= baseaddr
;
4177 case DW_LNE_define_file
:
4178 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
4179 line_ptr
+= bytes_read
;
4180 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
4182 files
.files
= (struct fileinfo
*)
4183 xrealloc (files
.files
,
4184 (files
.num_files
+ FILE_ALLOC_CHUNK
)
4185 * sizeof (struct fileinfo
));
4186 if (files
.num_files
== 0)
4187 make_cleanup (free_current_contents
, &files
.files
);
4189 files
.files
[files
.num_files
].name
= cur_file
;
4190 files
.files
[files
.num_files
].dir
=
4191 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4192 line_ptr
+= bytes_read
;
4193 files
.files
[files
.num_files
].time
=
4194 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4195 line_ptr
+= bytes_read
;
4196 files
.files
[files
.num_files
].size
=
4197 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4198 line_ptr
+= bytes_read
;
4202 complain (&dwarf2_mangled_line_number_section
);
4207 address
= check_cu_functions (address
);
4208 record_line (current_subfile
, line
, address
);
4211 case DW_LNS_advance_pc
:
4212 address
+= lh
.minimum_instruction_length
4213 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4214 line_ptr
+= bytes_read
;
4216 case DW_LNS_advance_line
:
4217 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
4218 line_ptr
+= bytes_read
;
4220 case DW_LNS_set_file
:
4221 /* The file and directory tables are 0 based, the references
4223 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4224 line_ptr
+= bytes_read
;
4225 dwarf2_start_subfile
4226 (files
.files
[file
- 1].name
,
4227 (files
.files
[file
- 1].dir
4228 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
4231 case DW_LNS_set_column
:
4232 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4233 line_ptr
+= bytes_read
;
4235 case DW_LNS_negate_stmt
:
4236 is_stmt
= (!is_stmt
);
4238 case DW_LNS_set_basic_block
:
4241 /* Add to the address register of the state machine the
4242 address increment value corresponding to special opcode
4243 255. Ie, this value is scaled by the minimum instruction
4244 length since special opcode 255 would have scaled the
4246 case DW_LNS_const_add_pc
:
4247 address
+= (lh
.minimum_instruction_length
4248 * ((255 - lh
.opcode_base
) / lh
.line_range
));
4250 case DW_LNS_fixed_advance_pc
:
4251 address
+= read_2_bytes (abfd
, line_ptr
);
4255 { /* Unknown standard opcode, ignore it. */
4257 for (i
= 0; i
< lh
.standard_opcode_lengths
[op_code
]; i
++)
4259 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4260 line_ptr
+= bytes_read
;
4267 do_cleanups (back_to
);
4270 /* Start a subfile for DWARF. FILENAME is the name of the file and
4271 DIRNAME the name of the source directory which contains FILENAME
4272 or NULL if not known.
4273 This routine tries to keep line numbers from identical absolute and
4274 relative file names in a common subfile.
4276 Using the `list' example from the GDB testsuite, which resides in
4277 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4278 of /srcdir/list0.c yields the following debugging information for list0.c:
4280 DW_AT_name: /srcdir/list0.c
4281 DW_AT_comp_dir: /compdir
4282 files.files[0].name: list0.h
4283 files.files[0].dir: /srcdir
4284 files.files[1].name: list0.c
4285 files.files[1].dir: /srcdir
4287 The line number information for list0.c has to end up in a single
4288 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4291 dwarf2_start_subfile (char *filename
, char *dirname
)
4293 /* If the filename isn't absolute, try to match an existing subfile
4294 with the full pathname. */
4296 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
4298 struct subfile
*subfile
;
4299 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4301 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4303 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
4305 current_subfile
= subfile
;
4312 start_subfile (filename
, dirname
);
4315 /* Given a pointer to a DWARF information entry, figure out if we need
4316 to make a symbol table entry for it, and if so, create a new entry
4317 and return a pointer to it.
4318 If TYPE is NULL, determine symbol type from the die, otherwise
4319 used the passed type. */
4321 static struct symbol
*
4322 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
4323 const struct comp_unit_head
*cu_header
)
4325 struct symbol
*sym
= NULL
;
4327 struct attribute
*attr
= NULL
;
4328 struct attribute
*attr2
= NULL
;
4331 name
= dwarf2_linkage_name (die
);
4334 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4335 sizeof (struct symbol
));
4336 OBJSTAT (objfile
, n_syms
++);
4337 memset (sym
, 0, sizeof (struct symbol
));
4338 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4339 &objfile
->symbol_obstack
);
4341 /* Default assumptions.
4342 Use the passed type or decode it from the die. */
4343 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4344 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4346 SYMBOL_TYPE (sym
) = type
;
4348 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
4349 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4352 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4355 /* If this symbol is from a C++ compilation, then attempt to
4356 cache the demangled form for future reference. This is a
4357 typical time versus space tradeoff, that was decided in favor
4358 of time because it sped up C++ symbol lookups by a factor of
4361 SYMBOL_LANGUAGE (sym
) = cu_language
;
4362 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4366 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4369 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4371 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4373 case DW_TAG_subprogram
:
4374 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4376 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4377 attr2
= dwarf_attr (die
, DW_AT_external
);
4378 if (attr2
&& (DW_UNSND (attr2
) != 0))
4380 add_symbol_to_list (sym
, &global_symbols
);
4384 add_symbol_to_list (sym
, list_in_scope
);
4387 case DW_TAG_variable
:
4388 /* Compilation with minimal debug info may result in variables
4389 with missing type entries. Change the misleading `void' type
4390 to something sensible. */
4391 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4392 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4393 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4394 "<variable, no debug info>",
4396 attr
= dwarf_attr (die
, DW_AT_const_value
);
4399 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4400 attr2
= dwarf_attr (die
, DW_AT_external
);
4401 if (attr2
&& (DW_UNSND (attr2
) != 0))
4402 add_symbol_to_list (sym
, &global_symbols
);
4404 add_symbol_to_list (sym
, list_in_scope
);
4407 attr
= dwarf_attr (die
, DW_AT_location
);
4410 attr2
= dwarf_attr (die
, DW_AT_external
);
4411 if (attr2
&& (DW_UNSND (attr2
) != 0))
4413 SYMBOL_VALUE_ADDRESS (sym
) =
4414 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4415 add_symbol_to_list (sym
, &global_symbols
);
4417 /* In shared libraries the address of the variable
4418 in the location descriptor might still be relocatable,
4419 so its value could be zero.
4420 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4421 value is zero, the address of the variable will then
4422 be determined from the minimal symbol table whenever
4423 the variable is referenced. */
4424 if (SYMBOL_VALUE_ADDRESS (sym
))
4426 fixup_symbol_section (sym
, objfile
);
4427 SYMBOL_VALUE_ADDRESS (sym
) +=
4428 ANOFFSET (objfile
->section_offsets
,
4429 SYMBOL_SECTION (sym
));
4430 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4433 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4437 SYMBOL_VALUE (sym
) = addr
=
4438 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4439 add_symbol_to_list (sym
, list_in_scope
);
4442 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4446 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4447 SYMBOL_VALUE (sym
) =
4448 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4452 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4453 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4457 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4461 fixup_symbol_section (sym
, objfile
);
4462 SYMBOL_VALUE_ADDRESS (sym
) =
4463 addr
+ ANOFFSET (objfile
->section_offsets
,
4464 SYMBOL_SECTION (sym
));
4465 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4471 /* We do not know the address of this symbol.
4472 If it is an external symbol and we have type information
4473 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4474 The address of the variable will then be determined from
4475 the minimal symbol table whenever the variable is
4477 attr2
= dwarf_attr (die
, DW_AT_external
);
4478 if (attr2
&& (DW_UNSND (attr2
) != 0)
4479 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4481 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4482 add_symbol_to_list (sym
, &global_symbols
);
4486 case DW_TAG_formal_parameter
:
4487 attr
= dwarf_attr (die
, DW_AT_location
);
4490 SYMBOL_VALUE (sym
) =
4491 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4494 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4495 SYMBOL_VALUE (sym
) =
4496 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4502 if (basereg
!= frame_base_reg
)
4503 complain (&dwarf2_complex_location_expr
);
4504 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4508 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4509 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4514 SYMBOL_CLASS (sym
) = LOC_ARG
;
4517 attr
= dwarf_attr (die
, DW_AT_const_value
);
4520 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4522 add_symbol_to_list (sym
, list_in_scope
);
4524 case DW_TAG_unspecified_parameters
:
4525 /* From varargs functions; gdb doesn't seem to have any
4526 interest in this information, so just ignore it for now.
4529 case DW_TAG_class_type
:
4530 case DW_TAG_structure_type
:
4531 case DW_TAG_union_type
:
4532 case DW_TAG_enumeration_type
:
4533 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4534 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4535 add_symbol_to_list (sym
, list_in_scope
);
4537 /* The semantics of C++ state that "struct foo { ... }" also
4538 defines a typedef for "foo". Synthesize a typedef symbol so
4539 that "ptype foo" works as expected. */
4540 if (cu_language
== language_cplus
)
4542 struct symbol
*typedef_sym
= (struct symbol
*)
4543 obstack_alloc (&objfile
->symbol_obstack
,
4544 sizeof (struct symbol
));
4545 *typedef_sym
= *sym
;
4546 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4547 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4548 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4549 obsavestring (SYMBOL_NAME (sym
),
4550 strlen (SYMBOL_NAME (sym
)),
4551 &objfile
->type_obstack
);
4552 add_symbol_to_list (typedef_sym
, list_in_scope
);
4555 case DW_TAG_typedef
:
4556 case DW_TAG_base_type
:
4557 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4558 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4559 add_symbol_to_list (sym
, list_in_scope
);
4561 case DW_TAG_enumerator
:
4562 attr
= dwarf_attr (die
, DW_AT_const_value
);
4565 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4567 add_symbol_to_list (sym
, list_in_scope
);
4570 /* Not a tag we recognize. Hopefully we aren't processing
4571 trash data, but since we must specifically ignore things
4572 we don't recognize, there is nothing else we should do at
4574 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4581 /* Copy constant value from an attribute to a symbol. */
4584 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
4585 struct objfile
*objfile
,
4586 const struct comp_unit_head
*cu_header
)
4588 struct dwarf_block
*blk
;
4593 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
4594 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4595 cu_header
->addr_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4596 SYMBOL_VALUE_BYTES (sym
) = (char *)
4597 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
4598 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
4600 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4602 case DW_FORM_block1
:
4603 case DW_FORM_block2
:
4604 case DW_FORM_block4
:
4606 blk
= DW_BLOCK (attr
);
4607 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4608 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4609 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4610 SYMBOL_VALUE_BYTES (sym
) = (char *)
4611 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4612 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4613 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4616 /* The DW_AT_const_value attributes are supposed to carry the
4617 symbol's value "represented as it would be on the target
4618 architecture." By the time we get here, it's already been
4619 converted to host endianness, so we just need to sign- or
4620 zero-extend it as appropriate. */
4622 dwarf2_const_value_data (attr
, sym
, 8);
4625 dwarf2_const_value_data (attr
, sym
, 16);
4628 dwarf2_const_value_data (attr
, sym
, 32);
4631 dwarf2_const_value_data (attr
, sym
, 64);
4635 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4636 SYMBOL_CLASS (sym
) = LOC_CONST
;
4640 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4641 SYMBOL_CLASS (sym
) = LOC_CONST
;
4645 complain (&dwarf2_unsupported_const_value_attr
,
4646 dwarf_form_name (attr
->form
));
4647 SYMBOL_VALUE (sym
) = 0;
4648 SYMBOL_CLASS (sym
) = LOC_CONST
;
4654 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4655 or zero-extend it as appropriate for the symbol's type. */
4657 dwarf2_const_value_data (struct attribute
*attr
,
4661 LONGEST l
= DW_UNSND (attr
);
4663 if (bits
< sizeof (l
) * 8)
4665 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4666 l
&= ((LONGEST
) 1 << bits
) - 1;
4668 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4671 SYMBOL_VALUE (sym
) = l
;
4672 SYMBOL_CLASS (sym
) = LOC_CONST
;
4676 /* Return the type of the die in question using its DW_AT_type attribute. */
4678 static struct type
*
4679 die_type (struct die_info
*die
, struct objfile
*objfile
,
4680 const struct comp_unit_head
*cu_header
)
4683 struct attribute
*type_attr
;
4684 struct die_info
*type_die
;
4687 type_attr
= dwarf_attr (die
, DW_AT_type
);
4690 /* A missing DW_AT_type represents a void type. */
4691 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4695 ref
= dwarf2_get_ref_die_offset (type_attr
);
4696 type_die
= follow_die_ref (ref
);
4699 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4703 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4706 dump_die (type_die
);
4707 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4712 /* Return the containing type of the die in question using its
4713 DW_AT_containing_type attribute. */
4715 static struct type
*
4716 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
4717 const struct comp_unit_head
*cu_header
)
4719 struct type
*type
= NULL
;
4720 struct attribute
*type_attr
;
4721 struct die_info
*type_die
= NULL
;
4724 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4727 ref
= dwarf2_get_ref_die_offset (type_attr
);
4728 type_die
= follow_die_ref (ref
);
4731 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4734 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4739 dump_die (type_die
);
4740 error ("Dwarf Error: Problem turning containing type into gdb type.");
4746 static struct type
*
4747 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
4749 struct die_info
*die
;
4752 die
= follow_die_ref (offset
);
4755 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4758 type
= tag_type_to_type (die
, objfile
);
4763 static struct type
*
4764 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
4765 const struct comp_unit_head
*cu_header
)
4773 read_type_die (die
, objfile
, cu_header
);
4777 error ("Dwarf Error: Cannot find type of die.");
4784 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
4785 const struct comp_unit_head
*cu_header
)
4789 case DW_TAG_class_type
:
4790 case DW_TAG_structure_type
:
4791 case DW_TAG_union_type
:
4792 read_structure_scope (die
, objfile
, cu_header
);
4794 case DW_TAG_enumeration_type
:
4795 read_enumeration (die
, objfile
, cu_header
);
4797 case DW_TAG_subprogram
:
4798 case DW_TAG_subroutine_type
:
4799 read_subroutine_type (die
, objfile
, cu_header
);
4801 case DW_TAG_array_type
:
4802 read_array_type (die
, objfile
, cu_header
);
4804 case DW_TAG_pointer_type
:
4805 read_tag_pointer_type (die
, objfile
, cu_header
);
4807 case DW_TAG_ptr_to_member_type
:
4808 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
4810 case DW_TAG_reference_type
:
4811 read_tag_reference_type (die
, objfile
, cu_header
);
4813 case DW_TAG_const_type
:
4814 read_tag_const_type (die
, objfile
, cu_header
);
4816 case DW_TAG_volatile_type
:
4817 read_tag_volatile_type (die
, objfile
, cu_header
);
4819 case DW_TAG_string_type
:
4820 read_tag_string_type (die
, objfile
);
4822 case DW_TAG_typedef
:
4823 read_typedef (die
, objfile
, cu_header
);
4825 case DW_TAG_base_type
:
4826 read_base_type (die
, objfile
);
4829 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4834 static struct type
*
4835 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
4837 /* FIXME - this should not produce a new (struct type *)
4838 every time. It should cache base types. */
4842 case DW_ATE_address
:
4843 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4845 case DW_ATE_boolean
:
4846 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4848 case DW_ATE_complex_float
:
4851 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4855 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4861 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4865 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4872 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4875 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4879 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4883 case DW_ATE_signed_char
:
4884 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4886 case DW_ATE_unsigned
:
4890 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4893 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4897 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4901 case DW_ATE_unsigned_char
:
4902 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4905 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4912 copy_die (struct die_info
*old_die
)
4914 struct die_info
*new_die
;
4917 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4918 memset (new_die
, 0, sizeof (struct die_info
));
4920 new_die
->tag
= old_die
->tag
;
4921 new_die
->has_children
= old_die
->has_children
;
4922 new_die
->abbrev
= old_die
->abbrev
;
4923 new_die
->offset
= old_die
->offset
;
4924 new_die
->type
= NULL
;
4926 num_attrs
= old_die
->num_attrs
;
4927 new_die
->num_attrs
= num_attrs
;
4928 new_die
->attrs
= (struct attribute
*)
4929 xmalloc (num_attrs
* sizeof (struct attribute
));
4931 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4933 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4934 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4935 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4938 new_die
->next
= NULL
;
4943 /* Return sibling of die, NULL if no sibling. */
4945 static struct die_info
*
4946 sibling_die (struct die_info
*die
)
4948 int nesting_level
= 0;
4950 if (!die
->has_children
)
4952 if (die
->next
&& (die
->next
->tag
== 0))
4965 if (die
->has_children
)
4975 while (nesting_level
);
4976 if (die
&& (die
->tag
== 0))
4987 /* Get linkage name of a die, return NULL if not found. */
4990 dwarf2_linkage_name (struct die_info
*die
)
4992 struct attribute
*attr
;
4994 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4995 if (attr
&& DW_STRING (attr
))
4996 return DW_STRING (attr
);
4997 attr
= dwarf_attr (die
, DW_AT_name
);
4998 if (attr
&& DW_STRING (attr
))
4999 return DW_STRING (attr
);
5003 /* Convert a DIE tag into its string name. */
5006 dwarf_tag_name (register unsigned tag
)
5010 case DW_TAG_padding
:
5011 return "DW_TAG_padding";
5012 case DW_TAG_array_type
:
5013 return "DW_TAG_array_type";
5014 case DW_TAG_class_type
:
5015 return "DW_TAG_class_type";
5016 case DW_TAG_entry_point
:
5017 return "DW_TAG_entry_point";
5018 case DW_TAG_enumeration_type
:
5019 return "DW_TAG_enumeration_type";
5020 case DW_TAG_formal_parameter
:
5021 return "DW_TAG_formal_parameter";
5022 case DW_TAG_imported_declaration
:
5023 return "DW_TAG_imported_declaration";
5025 return "DW_TAG_label";
5026 case DW_TAG_lexical_block
:
5027 return "DW_TAG_lexical_block";
5029 return "DW_TAG_member";
5030 case DW_TAG_pointer_type
:
5031 return "DW_TAG_pointer_type";
5032 case DW_TAG_reference_type
:
5033 return "DW_TAG_reference_type";
5034 case DW_TAG_compile_unit
:
5035 return "DW_TAG_compile_unit";
5036 case DW_TAG_string_type
:
5037 return "DW_TAG_string_type";
5038 case DW_TAG_structure_type
:
5039 return "DW_TAG_structure_type";
5040 case DW_TAG_subroutine_type
:
5041 return "DW_TAG_subroutine_type";
5042 case DW_TAG_typedef
:
5043 return "DW_TAG_typedef";
5044 case DW_TAG_union_type
:
5045 return "DW_TAG_union_type";
5046 case DW_TAG_unspecified_parameters
:
5047 return "DW_TAG_unspecified_parameters";
5048 case DW_TAG_variant
:
5049 return "DW_TAG_variant";
5050 case DW_TAG_common_block
:
5051 return "DW_TAG_common_block";
5052 case DW_TAG_common_inclusion
:
5053 return "DW_TAG_common_inclusion";
5054 case DW_TAG_inheritance
:
5055 return "DW_TAG_inheritance";
5056 case DW_TAG_inlined_subroutine
:
5057 return "DW_TAG_inlined_subroutine";
5059 return "DW_TAG_module";
5060 case DW_TAG_ptr_to_member_type
:
5061 return "DW_TAG_ptr_to_member_type";
5062 case DW_TAG_set_type
:
5063 return "DW_TAG_set_type";
5064 case DW_TAG_subrange_type
:
5065 return "DW_TAG_subrange_type";
5066 case DW_TAG_with_stmt
:
5067 return "DW_TAG_with_stmt";
5068 case DW_TAG_access_declaration
:
5069 return "DW_TAG_access_declaration";
5070 case DW_TAG_base_type
:
5071 return "DW_TAG_base_type";
5072 case DW_TAG_catch_block
:
5073 return "DW_TAG_catch_block";
5074 case DW_TAG_const_type
:
5075 return "DW_TAG_const_type";
5076 case DW_TAG_constant
:
5077 return "DW_TAG_constant";
5078 case DW_TAG_enumerator
:
5079 return "DW_TAG_enumerator";
5080 case DW_TAG_file_type
:
5081 return "DW_TAG_file_type";
5083 return "DW_TAG_friend";
5084 case DW_TAG_namelist
:
5085 return "DW_TAG_namelist";
5086 case DW_TAG_namelist_item
:
5087 return "DW_TAG_namelist_item";
5088 case DW_TAG_packed_type
:
5089 return "DW_TAG_packed_type";
5090 case DW_TAG_subprogram
:
5091 return "DW_TAG_subprogram";
5092 case DW_TAG_template_type_param
:
5093 return "DW_TAG_template_type_param";
5094 case DW_TAG_template_value_param
:
5095 return "DW_TAG_template_value_param";
5096 case DW_TAG_thrown_type
:
5097 return "DW_TAG_thrown_type";
5098 case DW_TAG_try_block
:
5099 return "DW_TAG_try_block";
5100 case DW_TAG_variant_part
:
5101 return "DW_TAG_variant_part";
5102 case DW_TAG_variable
:
5103 return "DW_TAG_variable";
5104 case DW_TAG_volatile_type
:
5105 return "DW_TAG_volatile_type";
5106 case DW_TAG_MIPS_loop
:
5107 return "DW_TAG_MIPS_loop";
5108 case DW_TAG_format_label
:
5109 return "DW_TAG_format_label";
5110 case DW_TAG_function_template
:
5111 return "DW_TAG_function_template";
5112 case DW_TAG_class_template
:
5113 return "DW_TAG_class_template";
5115 return "DW_TAG_<unknown>";
5119 /* Convert a DWARF attribute code into its string name. */
5122 dwarf_attr_name (register unsigned attr
)
5127 return "DW_AT_sibling";
5128 case DW_AT_location
:
5129 return "DW_AT_location";
5131 return "DW_AT_name";
5132 case DW_AT_ordering
:
5133 return "DW_AT_ordering";
5134 case DW_AT_subscr_data
:
5135 return "DW_AT_subscr_data";
5136 case DW_AT_byte_size
:
5137 return "DW_AT_byte_size";
5138 case DW_AT_bit_offset
:
5139 return "DW_AT_bit_offset";
5140 case DW_AT_bit_size
:
5141 return "DW_AT_bit_size";
5142 case DW_AT_element_list
:
5143 return "DW_AT_element_list";
5144 case DW_AT_stmt_list
:
5145 return "DW_AT_stmt_list";
5147 return "DW_AT_low_pc";
5149 return "DW_AT_high_pc";
5150 case DW_AT_language
:
5151 return "DW_AT_language";
5153 return "DW_AT_member";
5155 return "DW_AT_discr";
5156 case DW_AT_discr_value
:
5157 return "DW_AT_discr_value";
5158 case DW_AT_visibility
:
5159 return "DW_AT_visibility";
5161 return "DW_AT_import";
5162 case DW_AT_string_length
:
5163 return "DW_AT_string_length";
5164 case DW_AT_common_reference
:
5165 return "DW_AT_common_reference";
5166 case DW_AT_comp_dir
:
5167 return "DW_AT_comp_dir";
5168 case DW_AT_const_value
:
5169 return "DW_AT_const_value";
5170 case DW_AT_containing_type
:
5171 return "DW_AT_containing_type";
5172 case DW_AT_default_value
:
5173 return "DW_AT_default_value";
5175 return "DW_AT_inline";
5176 case DW_AT_is_optional
:
5177 return "DW_AT_is_optional";
5178 case DW_AT_lower_bound
:
5179 return "DW_AT_lower_bound";
5180 case DW_AT_producer
:
5181 return "DW_AT_producer";
5182 case DW_AT_prototyped
:
5183 return "DW_AT_prototyped";
5184 case DW_AT_return_addr
:
5185 return "DW_AT_return_addr";
5186 case DW_AT_start_scope
:
5187 return "DW_AT_start_scope";
5188 case DW_AT_stride_size
:
5189 return "DW_AT_stride_size";
5190 case DW_AT_upper_bound
:
5191 return "DW_AT_upper_bound";
5192 case DW_AT_abstract_origin
:
5193 return "DW_AT_abstract_origin";
5194 case DW_AT_accessibility
:
5195 return "DW_AT_accessibility";
5196 case DW_AT_address_class
:
5197 return "DW_AT_address_class";
5198 case DW_AT_artificial
:
5199 return "DW_AT_artificial";
5200 case DW_AT_base_types
:
5201 return "DW_AT_base_types";
5202 case DW_AT_calling_convention
:
5203 return "DW_AT_calling_convention";
5205 return "DW_AT_count";
5206 case DW_AT_data_member_location
:
5207 return "DW_AT_data_member_location";
5208 case DW_AT_decl_column
:
5209 return "DW_AT_decl_column";
5210 case DW_AT_decl_file
:
5211 return "DW_AT_decl_file";
5212 case DW_AT_decl_line
:
5213 return "DW_AT_decl_line";
5214 case DW_AT_declaration
:
5215 return "DW_AT_declaration";
5216 case DW_AT_discr_list
:
5217 return "DW_AT_discr_list";
5218 case DW_AT_encoding
:
5219 return "DW_AT_encoding";
5220 case DW_AT_external
:
5221 return "DW_AT_external";
5222 case DW_AT_frame_base
:
5223 return "DW_AT_frame_base";
5225 return "DW_AT_friend";
5226 case DW_AT_identifier_case
:
5227 return "DW_AT_identifier_case";
5228 case DW_AT_macro_info
:
5229 return "DW_AT_macro_info";
5230 case DW_AT_namelist_items
:
5231 return "DW_AT_namelist_items";
5232 case DW_AT_priority
:
5233 return "DW_AT_priority";
5235 return "DW_AT_segment";
5236 case DW_AT_specification
:
5237 return "DW_AT_specification";
5238 case DW_AT_static_link
:
5239 return "DW_AT_static_link";
5241 return "DW_AT_type";
5242 case DW_AT_use_location
:
5243 return "DW_AT_use_location";
5244 case DW_AT_variable_parameter
:
5245 return "DW_AT_variable_parameter";
5246 case DW_AT_virtuality
:
5247 return "DW_AT_virtuality";
5248 case DW_AT_vtable_elem_location
:
5249 return "DW_AT_vtable_elem_location";
5252 case DW_AT_MIPS_fde
:
5253 return "DW_AT_MIPS_fde";
5254 case DW_AT_MIPS_loop_begin
:
5255 return "DW_AT_MIPS_loop_begin";
5256 case DW_AT_MIPS_tail_loop_begin
:
5257 return "DW_AT_MIPS_tail_loop_begin";
5258 case DW_AT_MIPS_epilog_begin
:
5259 return "DW_AT_MIPS_epilog_begin";
5260 case DW_AT_MIPS_loop_unroll_factor
:
5261 return "DW_AT_MIPS_loop_unroll_factor";
5262 case DW_AT_MIPS_software_pipeline_depth
:
5263 return "DW_AT_MIPS_software_pipeline_depth";
5264 case DW_AT_MIPS_linkage_name
:
5265 return "DW_AT_MIPS_linkage_name";
5268 case DW_AT_sf_names
:
5269 return "DW_AT_sf_names";
5270 case DW_AT_src_info
:
5271 return "DW_AT_src_info";
5272 case DW_AT_mac_info
:
5273 return "DW_AT_mac_info";
5274 case DW_AT_src_coords
:
5275 return "DW_AT_src_coords";
5276 case DW_AT_body_begin
:
5277 return "DW_AT_body_begin";
5278 case DW_AT_body_end
:
5279 return "DW_AT_body_end";
5280 case DW_AT_GNU_vector
:
5281 return "DW_AT_GNU_vector";
5283 return "DW_AT_<unknown>";
5287 /* Convert a DWARF value form code into its string name. */
5290 dwarf_form_name (register unsigned form
)
5295 return "DW_FORM_addr";
5296 case DW_FORM_block2
:
5297 return "DW_FORM_block2";
5298 case DW_FORM_block4
:
5299 return "DW_FORM_block4";
5301 return "DW_FORM_data2";
5303 return "DW_FORM_data4";
5305 return "DW_FORM_data8";
5306 case DW_FORM_string
:
5307 return "DW_FORM_string";
5309 return "DW_FORM_block";
5310 case DW_FORM_block1
:
5311 return "DW_FORM_block1";
5313 return "DW_FORM_data1";
5315 return "DW_FORM_flag";
5317 return "DW_FORM_sdata";
5319 return "DW_FORM_strp";
5321 return "DW_FORM_udata";
5322 case DW_FORM_ref_addr
:
5323 return "DW_FORM_ref_addr";
5325 return "DW_FORM_ref1";
5327 return "DW_FORM_ref2";
5329 return "DW_FORM_ref4";
5331 return "DW_FORM_ref8";
5332 case DW_FORM_ref_udata
:
5333 return "DW_FORM_ref_udata";
5334 case DW_FORM_indirect
:
5335 return "DW_FORM_indirect";
5337 return "DW_FORM_<unknown>";
5341 /* Convert a DWARF stack opcode into its string name. */
5344 dwarf_stack_op_name (register unsigned op
)
5349 return "DW_OP_addr";
5351 return "DW_OP_deref";
5353 return "DW_OP_const1u";
5355 return "DW_OP_const1s";
5357 return "DW_OP_const2u";
5359 return "DW_OP_const2s";
5361 return "DW_OP_const4u";
5363 return "DW_OP_const4s";
5365 return "DW_OP_const8u";
5367 return "DW_OP_const8s";
5369 return "DW_OP_constu";
5371 return "DW_OP_consts";
5375 return "DW_OP_drop";
5377 return "DW_OP_over";
5379 return "DW_OP_pick";
5381 return "DW_OP_swap";
5385 return "DW_OP_xderef";
5393 return "DW_OP_minus";
5405 return "DW_OP_plus";
5406 case DW_OP_plus_uconst
:
5407 return "DW_OP_plus_uconst";
5413 return "DW_OP_shra";
5431 return "DW_OP_skip";
5433 return "DW_OP_lit0";
5435 return "DW_OP_lit1";
5437 return "DW_OP_lit2";
5439 return "DW_OP_lit3";
5441 return "DW_OP_lit4";
5443 return "DW_OP_lit5";
5445 return "DW_OP_lit6";
5447 return "DW_OP_lit7";
5449 return "DW_OP_lit8";
5451 return "DW_OP_lit9";
5453 return "DW_OP_lit10";
5455 return "DW_OP_lit11";
5457 return "DW_OP_lit12";
5459 return "DW_OP_lit13";
5461 return "DW_OP_lit14";
5463 return "DW_OP_lit15";
5465 return "DW_OP_lit16";
5467 return "DW_OP_lit17";
5469 return "DW_OP_lit18";
5471 return "DW_OP_lit19";
5473 return "DW_OP_lit20";
5475 return "DW_OP_lit21";
5477 return "DW_OP_lit22";
5479 return "DW_OP_lit23";
5481 return "DW_OP_lit24";
5483 return "DW_OP_lit25";
5485 return "DW_OP_lit26";
5487 return "DW_OP_lit27";
5489 return "DW_OP_lit28";
5491 return "DW_OP_lit29";
5493 return "DW_OP_lit30";
5495 return "DW_OP_lit31";
5497 return "DW_OP_reg0";
5499 return "DW_OP_reg1";
5501 return "DW_OP_reg2";
5503 return "DW_OP_reg3";
5505 return "DW_OP_reg4";
5507 return "DW_OP_reg5";
5509 return "DW_OP_reg6";
5511 return "DW_OP_reg7";
5513 return "DW_OP_reg8";
5515 return "DW_OP_reg9";
5517 return "DW_OP_reg10";
5519 return "DW_OP_reg11";
5521 return "DW_OP_reg12";
5523 return "DW_OP_reg13";
5525 return "DW_OP_reg14";
5527 return "DW_OP_reg15";
5529 return "DW_OP_reg16";
5531 return "DW_OP_reg17";
5533 return "DW_OP_reg18";
5535 return "DW_OP_reg19";
5537 return "DW_OP_reg20";
5539 return "DW_OP_reg21";
5541 return "DW_OP_reg22";
5543 return "DW_OP_reg23";
5545 return "DW_OP_reg24";
5547 return "DW_OP_reg25";
5549 return "DW_OP_reg26";
5551 return "DW_OP_reg27";
5553 return "DW_OP_reg28";
5555 return "DW_OP_reg29";
5557 return "DW_OP_reg30";
5559 return "DW_OP_reg31";
5561 return "DW_OP_breg0";
5563 return "DW_OP_breg1";
5565 return "DW_OP_breg2";
5567 return "DW_OP_breg3";
5569 return "DW_OP_breg4";
5571 return "DW_OP_breg5";
5573 return "DW_OP_breg6";
5575 return "DW_OP_breg7";
5577 return "DW_OP_breg8";
5579 return "DW_OP_breg9";
5581 return "DW_OP_breg10";
5583 return "DW_OP_breg11";
5585 return "DW_OP_breg12";
5587 return "DW_OP_breg13";
5589 return "DW_OP_breg14";
5591 return "DW_OP_breg15";
5593 return "DW_OP_breg16";
5595 return "DW_OP_breg17";
5597 return "DW_OP_breg18";
5599 return "DW_OP_breg19";
5601 return "DW_OP_breg20";
5603 return "DW_OP_breg21";
5605 return "DW_OP_breg22";
5607 return "DW_OP_breg23";
5609 return "DW_OP_breg24";
5611 return "DW_OP_breg25";
5613 return "DW_OP_breg26";
5615 return "DW_OP_breg27";
5617 return "DW_OP_breg28";
5619 return "DW_OP_breg29";
5621 return "DW_OP_breg30";
5623 return "DW_OP_breg31";
5625 return "DW_OP_regx";
5627 return "DW_OP_fbreg";
5629 return "DW_OP_bregx";
5631 return "DW_OP_piece";
5632 case DW_OP_deref_size
:
5633 return "DW_OP_deref_size";
5634 case DW_OP_xderef_size
:
5635 return "DW_OP_xderef_size";
5639 return "OP_<unknown>";
5644 dwarf_bool_name (unsigned mybool
)
5652 /* Convert a DWARF type code into its string name. */
5655 dwarf_type_encoding_name (register unsigned enc
)
5659 case DW_ATE_address
:
5660 return "DW_ATE_address";
5661 case DW_ATE_boolean
:
5662 return "DW_ATE_boolean";
5663 case DW_ATE_complex_float
:
5664 return "DW_ATE_complex_float";
5666 return "DW_ATE_float";
5668 return "DW_ATE_signed";
5669 case DW_ATE_signed_char
:
5670 return "DW_ATE_signed_char";
5671 case DW_ATE_unsigned
:
5672 return "DW_ATE_unsigned";
5673 case DW_ATE_unsigned_char
:
5674 return "DW_ATE_unsigned_char";
5676 return "DW_ATE_<unknown>";
5680 /* Convert a DWARF call frame info operation to its string name. */
5684 dwarf_cfi_name (register unsigned cfi_opc
)
5688 case DW_CFA_advance_loc
:
5689 return "DW_CFA_advance_loc";
5691 return "DW_CFA_offset";
5692 case DW_CFA_restore
:
5693 return "DW_CFA_restore";
5695 return "DW_CFA_nop";
5696 case DW_CFA_set_loc
:
5697 return "DW_CFA_set_loc";
5698 case DW_CFA_advance_loc1
:
5699 return "DW_CFA_advance_loc1";
5700 case DW_CFA_advance_loc2
:
5701 return "DW_CFA_advance_loc2";
5702 case DW_CFA_advance_loc4
:
5703 return "DW_CFA_advance_loc4";
5704 case DW_CFA_offset_extended
:
5705 return "DW_CFA_offset_extended";
5706 case DW_CFA_restore_extended
:
5707 return "DW_CFA_restore_extended";
5708 case DW_CFA_undefined
:
5709 return "DW_CFA_undefined";
5710 case DW_CFA_same_value
:
5711 return "DW_CFA_same_value";
5712 case DW_CFA_register
:
5713 return "DW_CFA_register";
5714 case DW_CFA_remember_state
:
5715 return "DW_CFA_remember_state";
5716 case DW_CFA_restore_state
:
5717 return "DW_CFA_restore_state";
5718 case DW_CFA_def_cfa
:
5719 return "DW_CFA_def_cfa";
5720 case DW_CFA_def_cfa_register
:
5721 return "DW_CFA_def_cfa_register";
5722 case DW_CFA_def_cfa_offset
:
5723 return "DW_CFA_def_cfa_offset";
5726 case DW_CFA_def_cfa_expression
:
5727 return "DW_CFA_def_cfa_expression";
5728 case DW_CFA_expression
:
5729 return "DW_CFA_expression";
5730 case DW_CFA_offset_extended_sf
:
5731 return "DW_CFA_offset_extended_sf";
5732 case DW_CFA_def_cfa_sf
:
5733 return "DW_CFA_def_cfa_sf";
5734 case DW_CFA_def_cfa_offset_sf
:
5735 return "DW_CFA_def_cfa_offset_sf";
5737 /* SGI/MIPS specific */
5738 case DW_CFA_MIPS_advance_loc8
:
5739 return "DW_CFA_MIPS_advance_loc8";
5741 /* GNU extensions */
5742 case DW_CFA_GNU_window_save
:
5743 return "DW_CFA_GNU_window_save";
5744 case DW_CFA_GNU_args_size
:
5745 return "DW_CFA_GNU_args_size";
5746 case DW_CFA_GNU_negative_offset_extended
:
5747 return "DW_CFA_GNU_negative_offset_extended";
5750 return "DW_CFA_<unknown>";
5756 dump_die (struct die_info
*die
)
5760 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5761 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5762 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
5763 dwarf_bool_name (die
->has_children
));
5765 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
5766 for (i
= 0; i
< die
->num_attrs
; ++i
)
5768 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
5769 dwarf_attr_name (die
->attrs
[i
].name
),
5770 dwarf_form_name (die
->attrs
[i
].form
));
5771 switch (die
->attrs
[i
].form
)
5773 case DW_FORM_ref_addr
:
5775 fprintf_unfiltered (gdb_stderr
, "address: ");
5776 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5778 case DW_FORM_block2
:
5779 case DW_FORM_block4
:
5781 case DW_FORM_block1
:
5782 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5793 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
5795 case DW_FORM_string
:
5797 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
5798 DW_STRING (&die
->attrs
[i
])
5799 ? DW_STRING (&die
->attrs
[i
]) : "");
5802 if (DW_UNSND (&die
->attrs
[i
]))
5803 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
5805 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
5807 case DW_FORM_indirect
:
5808 /* the reader will have reduced the indirect form to
5809 the "base form" so this form should not occur */
5810 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
5813 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
5814 die
->attrs
[i
].form
);
5816 fprintf_unfiltered (gdb_stderr
, "\n");
5821 dump_die_list (struct die_info
*die
)
5831 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
5834 struct die_info
*old
;
5836 h
= (offset
% REF_HASH_SIZE
);
5837 old
= die_ref_table
[h
];
5838 die
->next_ref
= old
;
5839 die_ref_table
[h
] = die
;
5844 dwarf2_empty_hash_tables (void)
5846 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5850 dwarf2_get_ref_die_offset (struct attribute
*attr
)
5852 unsigned int result
= 0;
5856 case DW_FORM_ref_addr
:
5857 result
= DW_ADDR (attr
);
5863 case DW_FORM_ref_udata
:
5864 result
= cu_header_offset
+ DW_UNSND (attr
);
5867 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5872 static struct die_info
*
5873 follow_die_ref (unsigned int offset
)
5875 struct die_info
*die
;
5878 h
= (offset
% REF_HASH_SIZE
);
5879 die
= die_ref_table
[h
];
5882 if (die
->offset
== offset
)
5886 die
= die
->next_ref
;
5891 static struct type
*
5892 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
5894 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5896 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5900 /* Look for this particular type in the fundamental type vector. If
5901 one is not found, create and install one appropriate for the
5902 current language and the current target machine. */
5904 if (ftypes
[typeid] == NULL
)
5906 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5909 return (ftypes
[typeid]);
5912 /* Decode simple location descriptions.
5913 Given a pointer to a dwarf block that defines a location, compute
5914 the location and return the value.
5916 FIXME: This is a kludge until we figure out a better
5917 way to handle the location descriptions.
5918 Gdb's design does not mesh well with the DWARF2 notion of a location
5919 computing interpreter, which is a shame because the flexibility goes unused.
5920 FIXME: Implement more operations as necessary.
5922 A location description containing no operations indicates that the
5923 object is optimized out. The global optimized_out flag is set for
5924 those, the return value is meaningless.
5926 When the result is a register number, the global isreg flag is set,
5927 otherwise it is cleared.
5929 When the result is a base register offset, the global offreg flag is set
5930 and the register number is returned in basereg, otherwise it is cleared.
5932 When the DW_OP_fbreg operation is encountered without a corresponding
5933 DW_AT_frame_base attribute, the global islocal flag is set.
5934 Hopefully the machine dependent code knows how to set up a virtual
5935 frame pointer for the local references.
5937 Note that stack[0] is unused except as a default error return.
5938 Note that stack overflow is not yet handled. */
5941 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
5942 const struct comp_unit_head
*cu_header
)
5945 int size
= blk
->size
;
5946 char *data
= blk
->data
;
5947 CORE_ADDR stack
[64];
5949 unsigned int bytes_read
, unsnd
;
5999 stack
[++stacki
] = op
- DW_OP_lit0
;
6035 stack
[++stacki
] = op
- DW_OP_reg0
;
6040 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6042 #if defined(HARRIS_TARGET) && defined(_M88K)
6043 /* The Harris 88110 gdb ports have long kept their special reg
6044 numbers between their gp-regs and their x-regs. This is
6045 not how our dwarf is generated. Punt. */
6048 stack
[++stacki
] = unsnd
;
6084 basereg
= op
- DW_OP_breg0
;
6085 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6091 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6093 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6098 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6100 if (frame_base_reg
>= 0)
6103 basereg
= frame_base_reg
;
6104 stack
[stacki
] += frame_base_offset
;
6108 complain (&dwarf2_missing_at_frame_base
);
6114 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
6115 cu_header
, &bytes_read
);
6120 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
6125 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
6130 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
6135 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
6140 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
6145 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
6150 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
6156 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6161 stack
[stacki
+ 1] = stack
[stacki
];
6166 stack
[stacki
- 1] += stack
[stacki
];
6170 case DW_OP_plus_uconst
:
6171 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6176 stack
[stacki
- 1] -= stack
[stacki
];
6182 /* If we're not the last op, then we definitely can't encode
6183 this using GDB's address_class enum. */
6185 complain (&dwarf2_complex_location_expr
);
6189 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
6190 return (stack
[stacki
]);
6193 return (stack
[stacki
]);
6196 /* memory allocation interface */
6200 dwarf2_free_tmp_obstack (PTR ignore
)
6202 obstack_free (&dwarf2_tmp_obstack
, NULL
);
6205 static struct dwarf_block
*
6206 dwarf_alloc_block (void)
6208 struct dwarf_block
*blk
;
6210 blk
= (struct dwarf_block
*)
6211 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
6215 static struct abbrev_info
*
6216 dwarf_alloc_abbrev (void)
6218 struct abbrev_info
*abbrev
;
6220 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
6221 memset (abbrev
, 0, sizeof (struct abbrev_info
));
6225 static struct die_info
*
6226 dwarf_alloc_die (void)
6228 struct die_info
*die
;
6230 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6231 memset (die
, 0, sizeof (struct die_info
));