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 do_cleanups (back_to
);
2667 /* Install the type in the die. */
2671 /* First cut: install each common block member as a global variable. */
2674 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
2675 const struct comp_unit_head
*cu_header
)
2677 struct die_info
*child_die
;
2678 struct attribute
*attr
;
2680 CORE_ADDR base
= (CORE_ADDR
) 0;
2682 attr
= dwarf_attr (die
, DW_AT_location
);
2685 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2687 if (die
->has_children
)
2689 child_die
= die
->next
;
2690 while (child_die
&& child_die
->tag
)
2692 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
2693 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2696 SYMBOL_VALUE_ADDRESS (sym
) =
2697 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2698 add_symbol_to_list (sym
, &global_symbols
);
2700 child_die
= sibling_die (child_die
);
2705 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2706 the user defined type vector. */
2709 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
2710 const struct comp_unit_head
*cu_header
)
2713 struct attribute
*attr
;
2720 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
2721 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2724 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2728 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2733 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2734 the user defined type vector. */
2737 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
2738 const struct comp_unit_head
*cu_header
)
2741 struct type
*to_type
;
2742 struct type
*domain
;
2749 type
= alloc_type (objfile
);
2750 to_type
= die_type (die
, objfile
, cu_header
);
2751 domain
= die_containing_type (die
, objfile
, cu_header
);
2752 smash_to_member_type (type
, domain
, to_type
);
2757 /* Extract all information from a DW_TAG_reference_type DIE and add to
2758 the user defined type vector. */
2761 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
2762 const struct comp_unit_head
*cu_header
)
2765 struct attribute
*attr
;
2772 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
2773 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2776 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2780 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2786 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
2787 const struct comp_unit_head
*cu_header
)
2789 struct type
*base_type
;
2796 base_type
= die_type (die
, objfile
, cu_header
);
2797 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
2801 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
2802 const struct comp_unit_head
*cu_header
)
2804 struct type
*base_type
;
2811 base_type
= die_type (die
, objfile
, cu_header
);
2812 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
2815 /* Extract all information from a DW_TAG_string_type DIE and add to
2816 the user defined type vector. It isn't really a user defined type,
2817 but it behaves like one, with other DIE's using an AT_user_def_type
2818 attribute to reference it. */
2821 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
2823 struct type
*type
, *range_type
, *index_type
, *char_type
;
2824 struct attribute
*attr
;
2825 unsigned int length
;
2832 attr
= dwarf_attr (die
, DW_AT_string_length
);
2835 length
= DW_UNSND (attr
);
2839 /* check for the DW_AT_byte_size attribute */
2840 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2843 length
= DW_UNSND (attr
);
2850 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2851 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2852 if (cu_language
== language_fortran
)
2854 /* Need to create a unique string type for bounds
2856 type
= create_string_type (0, range_type
);
2860 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2861 type
= create_string_type (char_type
, range_type
);
2866 /* Handle DIES due to C code like:
2870 int (*funcp)(int a, long l);
2874 ('funcp' generates a DW_TAG_subroutine_type DIE)
2878 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
2879 const struct comp_unit_head
*cu_header
)
2881 struct type
*type
; /* Type that this function returns */
2882 struct type
*ftype
; /* Function that returns above type */
2883 struct attribute
*attr
;
2885 /* Decode the type that this subroutine returns */
2890 type
= die_type (die
, objfile
, cu_header
);
2891 ftype
= lookup_function_type (type
);
2893 /* All functions in C++ have prototypes. */
2894 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2895 if ((attr
&& (DW_UNSND (attr
) != 0))
2896 || cu_language
== language_cplus
)
2897 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2899 if (die
->has_children
)
2901 struct die_info
*child_die
;
2905 /* Count the number of parameters.
2906 FIXME: GDB currently ignores vararg functions, but knows about
2907 vararg member functions. */
2908 child_die
= die
->next
;
2909 while (child_die
&& child_die
->tag
)
2911 if (child_die
->tag
== DW_TAG_formal_parameter
)
2913 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2914 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2915 child_die
= sibling_die (child_die
);
2918 /* Allocate storage for parameters and fill them in. */
2919 TYPE_NFIELDS (ftype
) = nparams
;
2920 TYPE_FIELDS (ftype
) = (struct field
*)
2921 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2923 child_die
= die
->next
;
2924 while (child_die
&& child_die
->tag
)
2926 if (child_die
->tag
== DW_TAG_formal_parameter
)
2928 /* Dwarf2 has no clean way to discern C++ static and non-static
2929 member functions. G++ helps GDB by marking the first
2930 parameter for non-static member functions (which is the
2931 this pointer) as artificial. We pass this information
2932 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2933 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2935 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2937 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2938 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
2942 child_die
= sibling_die (child_die
);
2950 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
2951 const struct comp_unit_head
*cu_header
)
2953 struct attribute
*attr
;
2958 attr
= dwarf_attr (die
, DW_AT_name
);
2959 if (attr
&& DW_STRING (attr
))
2961 name
= DW_STRING (attr
);
2963 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
2964 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, objfile
, cu_header
);
2968 /* Find a representation of a given base type and install
2969 it in the TYPE field of the die. */
2972 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
2975 struct attribute
*attr
;
2976 int encoding
= 0, size
= 0;
2978 /* If we've already decoded this die, this is a no-op. */
2984 attr
= dwarf_attr (die
, DW_AT_encoding
);
2987 encoding
= DW_UNSND (attr
);
2989 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2992 size
= DW_UNSND (attr
);
2994 attr
= dwarf_attr (die
, DW_AT_name
);
2995 if (attr
&& DW_STRING (attr
))
2997 enum type_code code
= TYPE_CODE_INT
;
3002 case DW_ATE_address
:
3003 /* Turn DW_ATE_address into a void * pointer. */
3004 code
= TYPE_CODE_PTR
;
3005 type_flags
|= TYPE_FLAG_UNSIGNED
;
3007 case DW_ATE_boolean
:
3008 code
= TYPE_CODE_BOOL
;
3009 type_flags
|= TYPE_FLAG_UNSIGNED
;
3011 case DW_ATE_complex_float
:
3012 code
= TYPE_CODE_COMPLEX
;
3015 code
= TYPE_CODE_FLT
;
3018 case DW_ATE_signed_char
:
3020 case DW_ATE_unsigned
:
3021 case DW_ATE_unsigned_char
:
3022 type_flags
|= TYPE_FLAG_UNSIGNED
;
3025 complain (&dwarf2_unsupported_at_encoding
,
3026 dwarf_type_encoding_name (encoding
));
3029 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
3030 if (encoding
== DW_ATE_address
)
3031 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
3032 else if (encoding
== DW_ATE_complex_float
)
3035 TYPE_TARGET_TYPE (type
)
3036 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3037 else if (size
== 16)
3038 TYPE_TARGET_TYPE (type
)
3039 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3041 TYPE_TARGET_TYPE (type
)
3042 = dwarf2_fundamental_type (objfile
, FT_FLOAT
);
3047 type
= dwarf_base_type (encoding
, size
, objfile
);
3052 /* Read a whole compilation unit into a linked list of dies. */
3054 static struct die_info
*
3055 read_comp_unit (char *info_ptr
, bfd
*abfd
,
3056 const struct comp_unit_head
*cu_header
)
3058 struct die_info
*first_die
, *last_die
, *die
;
3062 /* Reset die reference table; we are
3063 building new ones now. */
3064 dwarf2_empty_hash_tables ();
3068 first_die
= last_die
= NULL
;
3071 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
3072 if (die
->has_children
)
3083 /* Enter die in reference hash table */
3084 store_in_ref_table (die
->offset
, die
);
3088 first_die
= last_die
= die
;
3092 last_die
->next
= die
;
3096 while (nesting_level
> 0);
3100 /* Free a linked list of dies. */
3103 free_die_list (struct die_info
*dies
)
3105 struct die_info
*die
, *next
;
3118 do_free_die_list_cleanup (void *dies
)
3120 free_die_list (dies
);
3123 static struct cleanup
*
3124 make_cleanup_free_die_list (struct die_info
*dies
)
3126 return make_cleanup (do_free_die_list_cleanup
, dies
);
3130 /* Read the contents of the section at OFFSET and of size SIZE from the
3131 object file specified by OBJFILE into the psymbol_obstack and return it. */
3134 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
3137 bfd
*abfd
= objfile
->obfd
;
3143 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3144 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3145 (bfd_bread (buf
, size
, abfd
) != size
))
3148 error ("Dwarf Error: Can't read DWARF data from '%s'",
3149 bfd_get_filename (abfd
));
3154 /* In DWARF version 2, the description of the debugging information is
3155 stored in a separate .debug_abbrev section. Before we read any
3156 dies from a section we read in all abbreviations and install them
3160 dwarf2_read_abbrevs (bfd
*abfd
, unsigned int offset
)
3163 struct abbrev_info
*cur_abbrev
;
3164 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3165 unsigned int abbrev_form
, hash_number
;
3167 /* empty the table */
3168 dwarf2_empty_abbrev_table (NULL
);
3170 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3171 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3172 abbrev_ptr
+= bytes_read
;
3174 /* loop until we reach an abbrev number of 0 */
3175 while (abbrev_number
)
3177 cur_abbrev
= dwarf_alloc_abbrev ();
3179 /* read in abbrev header */
3180 cur_abbrev
->number
= abbrev_number
;
3181 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3182 abbrev_ptr
+= bytes_read
;
3183 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3186 /* now read in declarations */
3187 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3188 abbrev_ptr
+= bytes_read
;
3189 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3190 abbrev_ptr
+= bytes_read
;
3193 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3195 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3196 xrealloc (cur_abbrev
->attrs
,
3197 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3198 * sizeof (struct attr_abbrev
));
3200 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3201 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3202 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3203 abbrev_ptr
+= bytes_read
;
3204 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3205 abbrev_ptr
+= bytes_read
;
3208 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3209 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3210 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3212 /* Get next abbreviation.
3213 Under Irix6 the abbreviations for a compilation unit are not
3214 always properly terminated with an abbrev number of 0.
3215 Exit loop if we encounter an abbreviation which we have
3216 already read (which means we are about to read the abbreviations
3217 for the next compile unit) or if the end of the abbreviation
3218 table is reached. */
3219 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3220 >= dwarf_abbrev_size
)
3222 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3223 abbrev_ptr
+= bytes_read
;
3224 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3229 /* Empty the abbrev table for a new compilation unit. */
3233 dwarf2_empty_abbrev_table (PTR ignore
)
3236 struct abbrev_info
*abbrev
, *next
;
3238 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3241 abbrev
= dwarf2_abbrevs
[i
];
3244 next
= abbrev
->next
;
3245 xfree (abbrev
->attrs
);
3249 dwarf2_abbrevs
[i
] = NULL
;
3253 /* Lookup an abbrev_info structure in the abbrev hash table. */
3255 static struct abbrev_info
*
3256 dwarf2_lookup_abbrev (unsigned int number
)
3258 unsigned int hash_number
;
3259 struct abbrev_info
*abbrev
;
3261 hash_number
= number
% ABBREV_HASH_SIZE
;
3262 abbrev
= dwarf2_abbrevs
[hash_number
];
3266 if (abbrev
->number
== number
)
3269 abbrev
= abbrev
->next
;
3274 /* Read a minimal amount of information into the minimal die structure. */
3277 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3278 char *info_ptr
, const struct comp_unit_head
*cu_header
)
3280 unsigned int abbrev_number
, bytes_read
, i
;
3281 struct abbrev_info
*abbrev
;
3282 struct attribute attr
;
3283 struct attribute spec_attr
;
3284 int found_spec_attr
= 0;
3285 int has_low_pc_attr
= 0;
3286 int has_high_pc_attr
= 0;
3288 *part_die
= zeroed_partial_die
;
3289 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3290 info_ptr
+= bytes_read
;
3294 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3297 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3299 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3300 part_die
->tag
= abbrev
->tag
;
3301 part_die
->has_children
= abbrev
->has_children
;
3302 part_die
->abbrev
= abbrev_number
;
3304 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3306 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3307 info_ptr
, cu_header
);
3309 /* Store the data if it is of an attribute we want to keep in a
3310 partial symbol table. */
3315 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3316 if (part_die
->name
== NULL
)
3317 part_die
->name
= DW_STRING (&attr
);
3319 case DW_AT_MIPS_linkage_name
:
3320 part_die
->name
= DW_STRING (&attr
);
3323 has_low_pc_attr
= 1;
3324 part_die
->lowpc
= DW_ADDR (&attr
);
3327 has_high_pc_attr
= 1;
3328 part_die
->highpc
= DW_ADDR (&attr
);
3330 case DW_AT_location
:
3331 part_die
->locdesc
= DW_BLOCK (&attr
);
3333 case DW_AT_language
:
3334 part_die
->language
= DW_UNSND (&attr
);
3336 case DW_AT_external
:
3337 part_die
->is_external
= DW_UNSND (&attr
);
3339 case DW_AT_declaration
:
3340 part_die
->is_declaration
= DW_UNSND (&attr
);
3343 part_die
->has_type
= 1;
3345 case DW_AT_abstract_origin
:
3346 case DW_AT_specification
:
3347 found_spec_attr
= 1;
3351 /* Ignore absolute siblings, they might point outside of
3352 the current compile unit. */
3353 if (attr
.form
== DW_FORM_ref_addr
)
3354 complain (&dwarf2_absolute_sibling_complaint
);
3357 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3364 /* If we found a reference attribute and the die has no name, try
3365 to find a name in the referred to die. */
3367 if (found_spec_attr
&& part_die
->name
== NULL
)
3369 struct partial_die_info spec_die
;
3373 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3374 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu_header
);
3377 part_die
->name
= spec_die
.name
;
3379 /* Copy DW_AT_external attribute if it is set. */
3380 if (spec_die
.is_external
)
3381 part_die
->is_external
= spec_die
.is_external
;
3385 /* When using the GNU linker, .gnu.linkonce. sections are used to
3386 eliminate duplicate copies of functions and vtables and such.
3387 The linker will arbitrarily choose one and discard the others.
3388 The AT_*_pc values for such functions refer to local labels in
3389 these sections. If the section from that file was discarded, the
3390 labels are not in the output, so the relocs get a value of 0.
3391 If this is a discarded function, mark the pc bounds as invalid,
3392 so that GDB will ignore it. */
3393 if (has_low_pc_attr
&& has_high_pc_attr
3394 && part_die
->lowpc
< part_die
->highpc
3395 && (part_die
->lowpc
!= 0
3396 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3397 part_die
->has_pc_info
= 1;
3401 /* Read the die from the .debug_info section buffer. And set diep to
3402 point to a newly allocated die with its information. */
3405 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3406 const struct comp_unit_head
*cu_header
)
3408 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3409 struct abbrev_info
*abbrev
;
3410 struct die_info
*die
;
3412 offset
= info_ptr
- dwarf_info_buffer
;
3413 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3414 info_ptr
+= bytes_read
;
3417 die
= dwarf_alloc_die ();
3419 die
->abbrev
= abbrev_number
;
3425 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3428 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3430 die
= dwarf_alloc_die ();
3431 die
->offset
= offset
;
3432 die
->tag
= abbrev
->tag
;
3433 die
->has_children
= abbrev
->has_children
;
3434 die
->abbrev
= abbrev_number
;
3437 die
->num_attrs
= abbrev
->num_attrs
;
3438 die
->attrs
= (struct attribute
*)
3439 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3441 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3443 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3444 abfd
, info_ptr
, cu_header
);
3451 /* Read an attribute value described by an attribute form. */
3454 read_attribute_value (struct attribute
*attr
, unsigned form
,
3455 bfd
*abfd
, char *info_ptr
,
3456 const struct comp_unit_head
*cu_header
)
3458 unsigned int bytes_read
;
3459 struct dwarf_block
*blk
;
3465 case DW_FORM_ref_addr
:
3466 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3467 info_ptr
+= bytes_read
;
3469 case DW_FORM_block2
:
3470 blk
= dwarf_alloc_block ();
3471 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3473 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3474 info_ptr
+= blk
->size
;
3475 DW_BLOCK (attr
) = blk
;
3477 case DW_FORM_block4
:
3478 blk
= dwarf_alloc_block ();
3479 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3481 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3482 info_ptr
+= blk
->size
;
3483 DW_BLOCK (attr
) = blk
;
3486 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3490 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3494 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3497 case DW_FORM_string
:
3498 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3499 info_ptr
+= bytes_read
;
3502 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
3504 info_ptr
+= bytes_read
;
3507 blk
= dwarf_alloc_block ();
3508 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3509 info_ptr
+= bytes_read
;
3510 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3511 info_ptr
+= blk
->size
;
3512 DW_BLOCK (attr
) = blk
;
3514 case DW_FORM_block1
:
3515 blk
= dwarf_alloc_block ();
3516 blk
->size
= read_1_byte (abfd
, info_ptr
);
3518 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3519 info_ptr
+= blk
->size
;
3520 DW_BLOCK (attr
) = blk
;
3523 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3527 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3531 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3532 info_ptr
+= bytes_read
;
3535 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3536 info_ptr
+= bytes_read
;
3539 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3543 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3547 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3551 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3554 case DW_FORM_ref_udata
:
3555 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3556 info_ptr
+= bytes_read
;
3558 case DW_FORM_indirect
:
3559 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3560 info_ptr
+= bytes_read
;
3561 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu_header
);
3564 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3565 dwarf_form_name (form
));
3570 /* Read an attribute described by an abbreviated attribute. */
3573 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
3574 bfd
*abfd
, char *info_ptr
,
3575 const struct comp_unit_head
*cu_header
)
3577 attr
->name
= abbrev
->name
;
3578 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu_header
);
3581 /* read dwarf information from a buffer */
3584 read_1_byte (bfd
*abfd
, char *buf
)
3586 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3590 read_1_signed_byte (bfd
*abfd
, char *buf
)
3592 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3596 read_2_bytes (bfd
*abfd
, char *buf
)
3598 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3602 read_2_signed_bytes (bfd
*abfd
, char *buf
)
3604 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3608 read_4_bytes (bfd
*abfd
, char *buf
)
3610 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3614 read_4_signed_bytes (bfd
*abfd
, char *buf
)
3616 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3619 static unsigned long
3620 read_8_bytes (bfd
*abfd
, char *buf
)
3622 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3626 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3629 CORE_ADDR retval
= 0;
3631 if (cu_header
->signed_addr_p
)
3633 switch (cu_header
->addr_size
)
3636 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3639 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3642 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
3645 internal_error (__FILE__
, __LINE__
,
3646 "read_address: bad switch, signed");
3651 switch (cu_header
->addr_size
)
3654 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3657 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3660 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3663 internal_error (__FILE__
, __LINE__
,
3664 "read_address: bad switch, unsigned");
3668 *bytes_read
= cu_header
->addr_size
;
3672 /* Reads the initial length from a section. The (draft) DWARF 2.1
3673 specification allows the initial length to take up either 4 bytes
3674 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
3675 bytes describe the length and all offsets will be 8 bytes in length
3678 The value returned via bytes_read should be used to increment
3679 the relevant pointer after calling read_initial_length().
3681 As a side effect, this function sets the fields initial_length_size
3682 and offset_size in cu_header to the values appropriate for the
3683 length field. (The format of the initial length field determines
3684 the width of file offsets to be fetched later with fetch_offset().)
3686 [ Note: read_initial_length() and read_offset() are based on the
3687 document entitled "DWARF Debugging Information Format", revision
3688 2.1, draft 4, dated July 20, 2000. This document was obtained
3691 http://reality.sgi.com/dehnert_engr/dwarf/dwarf2p1-draft4-000720.pdf
3693 This document is only a draft and is subject to change. (So beware.)
3695 - Kevin, Aug 4, 2000
3699 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
3704 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3706 if (retval
== 0xffffffff)
3708 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
3710 if (cu_header
!= NULL
)
3712 cu_header
->initial_length_size
= 12;
3713 cu_header
->offset_size
= 8;
3719 if (cu_header
!= NULL
)
3721 cu_header
->initial_length_size
= 4;
3722 cu_header
->offset_size
= 4;
3729 /* Read an offset from the data stream. The size of the offset is
3730 given by cu_header->offset_size. */
3733 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3738 switch (cu_header
->offset_size
)
3741 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3745 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3749 internal_error (__FILE__
, __LINE__
,
3750 "read_offset: bad switch");
3757 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
3759 /* If the size of a host char is 8 bits, we can return a pointer
3760 to the buffer, otherwise we have to copy the data to a buffer
3761 allocated on the temporary obstack. */
3762 gdb_assert (HOST_CHAR_BIT
== 8);
3767 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3769 /* If the size of a host char is 8 bits, we can return a pointer
3770 to the string, otherwise we have to copy the string to a buffer
3771 allocated on the temporary obstack. */
3772 gdb_assert (HOST_CHAR_BIT
== 8);
3775 *bytes_read_ptr
= 1;
3778 *bytes_read_ptr
= strlen (buf
) + 1;
3783 read_indirect_string (bfd
*abfd
, char *buf
,
3784 const struct comp_unit_head
*cu_header
,
3785 unsigned int *bytes_read_ptr
)
3787 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
3788 (int *) bytes_read_ptr
);
3790 if (dwarf_str_buffer
== NULL
)
3792 error ("DW_FORM_strp used without .debug_str section");
3795 if (str_offset
>= dwarf_str_size
)
3797 error ("DW_FORM_strp pointing outside of .debug_str section");
3800 gdb_assert (HOST_CHAR_BIT
== 8);
3801 if (dwarf_str_buffer
[str_offset
] == '\0')
3803 return dwarf_str_buffer
+ str_offset
;
3806 static unsigned long
3807 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3809 unsigned long result
;
3810 unsigned int num_read
;
3820 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3823 result
|= ((unsigned long)(byte
& 127) << shift
);
3824 if ((byte
& 128) == 0)
3830 *bytes_read_ptr
= num_read
;
3835 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3838 int i
, shift
, size
, num_read
;
3848 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3851 result
|= ((long)(byte
& 127) << shift
);
3853 if ((byte
& 128) == 0)
3858 if ((shift
< size
) && (byte
& 0x40))
3860 result
|= -(1 << shift
);
3862 *bytes_read_ptr
= num_read
;
3867 set_cu_language (unsigned int lang
)
3873 cu_language
= language_c
;
3875 case DW_LANG_C_plus_plus
:
3876 cu_language
= language_cplus
;
3878 case DW_LANG_Fortran77
:
3879 case DW_LANG_Fortran90
:
3880 case DW_LANG_Fortran95
:
3881 cu_language
= language_fortran
;
3883 case DW_LANG_Mips_Assembler
:
3884 cu_language
= language_asm
;
3887 cu_language
= language_java
;
3890 case DW_LANG_Cobol74
:
3891 case DW_LANG_Cobol85
:
3892 case DW_LANG_Pascal83
:
3893 case DW_LANG_Modula2
:
3895 cu_language
= language_unknown
;
3898 cu_language_defn
= language_def (cu_language
);
3901 /* Return the named attribute or NULL if not there. */
3903 static struct attribute
*
3904 dwarf_attr (struct die_info
*die
, unsigned int name
)
3907 struct attribute
*spec
= NULL
;
3909 for (i
= 0; i
< die
->num_attrs
; ++i
)
3911 if (die
->attrs
[i
].name
== name
)
3913 return &die
->attrs
[i
];
3915 if (die
->attrs
[i
].name
== DW_AT_specification
3916 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3917 spec
= &die
->attrs
[i
];
3921 struct die_info
*ref_die
=
3922 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3925 return dwarf_attr (ref_die
, name
);
3932 die_is_declaration (struct die_info
*die
)
3934 return (dwarf_attr (die
, DW_AT_declaration
)
3935 && ! dwarf_attr (die
, DW_AT_specification
));
3938 /* Decode the line number information for the compilation unit whose
3939 line number info is at OFFSET in the .debug_line section.
3940 The compilation directory of the file is passed in COMP_DIR. */
3944 unsigned int num_files
;
3957 unsigned int num_dirs
;
3961 /* This function exists to work around a bug in certain compilers
3962 (particularly GCC 2.95), in which the first line number marker of a
3963 function does not show up until after the prologue, right before
3964 the second line number marker. This function shifts ADDRESS down
3965 to the beginning of the function if necessary, and is called on
3966 addresses passed to record_line. */
3969 check_cu_functions (CORE_ADDR address
)
3971 struct function_range
*fn
;
3973 /* Find the function_range containing address. */
3978 cu_cached_fn
= cu_first_fn
;
3982 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
3988 while (fn
&& fn
!= cu_cached_fn
)
3989 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
3999 if (address
!= fn
->lowpc
)
4000 complain (&dwarf2_misplaced_line_number
,
4001 (unsigned long) address
, fn
->name
);
4007 dwarf_decode_lines (unsigned int offset
, char *comp_dir
, bfd
*abfd
,
4008 const struct comp_unit_head
*cu_header
)
4012 struct line_head lh
;
4013 struct cleanup
*back_to
;
4014 unsigned int i
, bytes_read
;
4015 char *cur_file
, *cur_dir
;
4016 unsigned char op_code
, extended_op
, adj_opcode
;
4018 #define FILE_ALLOC_CHUNK 5
4019 #define DIR_ALLOC_CHUNK 5
4021 struct filenames files
;
4022 struct directories dirs
;
4024 if (dwarf_line_buffer
== NULL
)
4026 complain (&dwarf2_missing_line_number_section
);
4030 files
.num_files
= 0;
4036 line_ptr
= dwarf_line_buffer
+ offset
;
4038 /* read in the prologue */
4039 lh
.total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
4040 line_ptr
+= bytes_read
;
4041 line_end
= line_ptr
+ lh
.total_length
;
4042 lh
.version
= read_2_bytes (abfd
, line_ptr
);
4044 lh
.prologue_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
4045 line_ptr
+= bytes_read
;
4046 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
4048 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
4050 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
4052 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
4054 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
4056 lh
.standard_opcode_lengths
= (unsigned char *)
4057 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
4058 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
4060 lh
.standard_opcode_lengths
[0] = 1;
4061 for (i
= 1; i
< lh
.opcode_base
; ++i
)
4063 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
4067 /* Read directory table */
4068 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4070 line_ptr
+= bytes_read
;
4071 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
4073 dirs
.dirs
= (char **)
4074 xrealloc (dirs
.dirs
,
4075 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
4076 if (dirs
.num_dirs
== 0)
4077 make_cleanup (free_current_contents
, &dirs
.dirs
);
4079 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
4081 line_ptr
+= bytes_read
;
4083 /* Read file name table */
4084 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4086 line_ptr
+= bytes_read
;
4087 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
4089 files
.files
= (struct fileinfo
*)
4090 xrealloc (files
.files
,
4091 (files
.num_files
+ FILE_ALLOC_CHUNK
)
4092 * sizeof (struct fileinfo
));
4093 if (files
.num_files
== 0)
4094 make_cleanup (free_current_contents
, &files
.files
);
4096 files
.files
[files
.num_files
].name
= cur_file
;
4097 files
.files
[files
.num_files
].dir
=
4098 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4099 line_ptr
+= bytes_read
;
4100 files
.files
[files
.num_files
].time
=
4101 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4102 line_ptr
+= bytes_read
;
4103 files
.files
[files
.num_files
].size
=
4104 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4105 line_ptr
+= bytes_read
;
4108 line_ptr
+= bytes_read
;
4110 /* Read the statement sequences until there's nothing left. */
4111 while (line_ptr
< line_end
)
4113 /* state machine registers */
4114 CORE_ADDR address
= 0;
4115 unsigned int file
= 1;
4116 unsigned int line
= 1;
4117 unsigned int column
= 0;
4118 int is_stmt
= lh
.default_is_stmt
;
4119 int basic_block
= 0;
4120 int end_sequence
= 0;
4122 /* Start a subfile for the current file of the state machine. */
4123 if (files
.num_files
>= file
)
4125 /* The file and directory tables are 0 based, the references
4127 dwarf2_start_subfile (files
.files
[file
- 1].name
,
4128 (files
.files
[file
- 1].dir
4129 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
4133 /* Decode the table. */
4134 while (!end_sequence
)
4136 op_code
= read_1_byte (abfd
, line_ptr
);
4139 if (op_code
>= lh
.opcode_base
)
4140 { /* Special operand. */
4141 adj_opcode
= op_code
- lh
.opcode_base
;
4142 address
+= (adj_opcode
/ lh
.line_range
)
4143 * lh
.minimum_instruction_length
;
4144 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
4145 /* append row to matrix using current values */
4146 address
= check_cu_functions (address
);
4147 record_line (current_subfile
, line
, address
);
4150 else switch (op_code
)
4152 case DW_LNS_extended_op
:
4153 line_ptr
+= 1; /* ignore length */
4154 extended_op
= read_1_byte (abfd
, line_ptr
);
4156 switch (extended_op
)
4158 case DW_LNE_end_sequence
:
4160 record_line (current_subfile
, 0, address
);
4162 case DW_LNE_set_address
:
4163 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
4164 line_ptr
+= bytes_read
;
4165 address
+= baseaddr
;
4167 case DW_LNE_define_file
:
4168 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
4169 line_ptr
+= bytes_read
;
4170 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
4172 files
.files
= (struct fileinfo
*)
4173 xrealloc (files
.files
,
4174 (files
.num_files
+ FILE_ALLOC_CHUNK
)
4175 * sizeof (struct fileinfo
));
4176 if (files
.num_files
== 0)
4177 make_cleanup (free_current_contents
, &files
.files
);
4179 files
.files
[files
.num_files
].name
= cur_file
;
4180 files
.files
[files
.num_files
].dir
=
4181 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4182 line_ptr
+= bytes_read
;
4183 files
.files
[files
.num_files
].time
=
4184 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4185 line_ptr
+= bytes_read
;
4186 files
.files
[files
.num_files
].size
=
4187 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4188 line_ptr
+= bytes_read
;
4192 complain (&dwarf2_mangled_line_number_section
);
4197 address
= check_cu_functions (address
);
4198 record_line (current_subfile
, line
, address
);
4201 case DW_LNS_advance_pc
:
4202 address
+= lh
.minimum_instruction_length
4203 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4204 line_ptr
+= bytes_read
;
4206 case DW_LNS_advance_line
:
4207 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
4208 line_ptr
+= bytes_read
;
4210 case DW_LNS_set_file
:
4211 /* The file and directory tables are 0 based, the references
4213 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4214 line_ptr
+= bytes_read
;
4215 dwarf2_start_subfile
4216 (files
.files
[file
- 1].name
,
4217 (files
.files
[file
- 1].dir
4218 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
4221 case DW_LNS_set_column
:
4222 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4223 line_ptr
+= bytes_read
;
4225 case DW_LNS_negate_stmt
:
4226 is_stmt
= (!is_stmt
);
4228 case DW_LNS_set_basic_block
:
4231 /* Add to the address register of the state machine the
4232 address increment value corresponding to special opcode
4233 255. Ie, this value is scaled by the minimum instruction
4234 length since special opcode 255 would have scaled the
4236 case DW_LNS_const_add_pc
:
4237 address
+= (lh
.minimum_instruction_length
4238 * ((255 - lh
.opcode_base
) / lh
.line_range
));
4240 case DW_LNS_fixed_advance_pc
:
4241 address
+= read_2_bytes (abfd
, line_ptr
);
4245 { /* Unknown standard opcode, ignore it. */
4247 for (i
= 0; i
< lh
.standard_opcode_lengths
[op_code
]; i
++)
4249 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4250 line_ptr
+= bytes_read
;
4257 do_cleanups (back_to
);
4260 /* Start a subfile for DWARF. FILENAME is the name of the file and
4261 DIRNAME the name of the source directory which contains FILENAME
4262 or NULL if not known.
4263 This routine tries to keep line numbers from identical absolute and
4264 relative file names in a common subfile.
4266 Using the `list' example from the GDB testsuite, which resides in
4267 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4268 of /srcdir/list0.c yields the following debugging information for list0.c:
4270 DW_AT_name: /srcdir/list0.c
4271 DW_AT_comp_dir: /compdir
4272 files.files[0].name: list0.h
4273 files.files[0].dir: /srcdir
4274 files.files[1].name: list0.c
4275 files.files[1].dir: /srcdir
4277 The line number information for list0.c has to end up in a single
4278 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4281 dwarf2_start_subfile (char *filename
, char *dirname
)
4283 /* If the filename isn't absolute, try to match an existing subfile
4284 with the full pathname. */
4286 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
4288 struct subfile
*subfile
;
4289 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4291 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4293 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
4295 current_subfile
= subfile
;
4302 start_subfile (filename
, dirname
);
4305 /* Given a pointer to a DWARF information entry, figure out if we need
4306 to make a symbol table entry for it, and if so, create a new entry
4307 and return a pointer to it.
4308 If TYPE is NULL, determine symbol type from the die, otherwise
4309 used the passed type. */
4311 static struct symbol
*
4312 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
4313 const struct comp_unit_head
*cu_header
)
4315 struct symbol
*sym
= NULL
;
4317 struct attribute
*attr
= NULL
;
4318 struct attribute
*attr2
= NULL
;
4321 name
= dwarf2_linkage_name (die
);
4324 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4325 sizeof (struct symbol
));
4326 OBJSTAT (objfile
, n_syms
++);
4327 memset (sym
, 0, sizeof (struct symbol
));
4328 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4329 &objfile
->symbol_obstack
);
4331 /* Default assumptions.
4332 Use the passed type or decode it from the die. */
4333 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4334 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4336 SYMBOL_TYPE (sym
) = type
;
4338 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
4339 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4342 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4345 /* If this symbol is from a C++ compilation, then attempt to
4346 cache the demangled form for future reference. This is a
4347 typical time versus space tradeoff, that was decided in favor
4348 of time because it sped up C++ symbol lookups by a factor of
4351 SYMBOL_LANGUAGE (sym
) = cu_language
;
4352 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4356 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4359 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4361 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4363 case DW_TAG_subprogram
:
4364 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4366 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4367 attr2
= dwarf_attr (die
, DW_AT_external
);
4368 if (attr2
&& (DW_UNSND (attr2
) != 0))
4370 add_symbol_to_list (sym
, &global_symbols
);
4374 add_symbol_to_list (sym
, list_in_scope
);
4377 case DW_TAG_variable
:
4378 /* Compilation with minimal debug info may result in variables
4379 with missing type entries. Change the misleading `void' type
4380 to something sensible. */
4381 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4382 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4383 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4384 "<variable, no debug info>",
4386 attr
= dwarf_attr (die
, DW_AT_const_value
);
4389 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4390 attr2
= dwarf_attr (die
, DW_AT_external
);
4391 if (attr2
&& (DW_UNSND (attr2
) != 0))
4392 add_symbol_to_list (sym
, &global_symbols
);
4394 add_symbol_to_list (sym
, list_in_scope
);
4397 attr
= dwarf_attr (die
, DW_AT_location
);
4400 attr2
= dwarf_attr (die
, DW_AT_external
);
4401 if (attr2
&& (DW_UNSND (attr2
) != 0))
4403 SYMBOL_VALUE_ADDRESS (sym
) =
4404 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4405 add_symbol_to_list (sym
, &global_symbols
);
4407 /* In shared libraries the address of the variable
4408 in the location descriptor might still be relocatable,
4409 so its value could be zero.
4410 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4411 value is zero, the address of the variable will then
4412 be determined from the minimal symbol table whenever
4413 the variable is referenced. */
4414 if (SYMBOL_VALUE_ADDRESS (sym
))
4416 fixup_symbol_section (sym
, objfile
);
4417 SYMBOL_VALUE_ADDRESS (sym
) +=
4418 ANOFFSET (objfile
->section_offsets
,
4419 SYMBOL_SECTION (sym
));
4420 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4423 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4427 SYMBOL_VALUE (sym
) = addr
=
4428 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4429 add_symbol_to_list (sym
, list_in_scope
);
4432 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4436 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4437 SYMBOL_VALUE (sym
) =
4438 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4442 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4443 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4447 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4451 fixup_symbol_section (sym
, objfile
);
4452 SYMBOL_VALUE_ADDRESS (sym
) =
4453 addr
+ ANOFFSET (objfile
->section_offsets
,
4454 SYMBOL_SECTION (sym
));
4455 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4461 /* We do not know the address of this symbol.
4462 If it is an external symbol and we have type information
4463 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4464 The address of the variable will then be determined from
4465 the minimal symbol table whenever the variable is
4467 attr2
= dwarf_attr (die
, DW_AT_external
);
4468 if (attr2
&& (DW_UNSND (attr2
) != 0)
4469 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4471 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4472 add_symbol_to_list (sym
, &global_symbols
);
4476 case DW_TAG_formal_parameter
:
4477 attr
= dwarf_attr (die
, DW_AT_location
);
4480 SYMBOL_VALUE (sym
) =
4481 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4484 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4485 SYMBOL_VALUE (sym
) =
4486 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4492 if (basereg
!= frame_base_reg
)
4493 complain (&dwarf2_complex_location_expr
);
4494 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4498 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4499 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4504 SYMBOL_CLASS (sym
) = LOC_ARG
;
4507 attr
= dwarf_attr (die
, DW_AT_const_value
);
4510 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4512 add_symbol_to_list (sym
, list_in_scope
);
4514 case DW_TAG_unspecified_parameters
:
4515 /* From varargs functions; gdb doesn't seem to have any
4516 interest in this information, so just ignore it for now.
4519 case DW_TAG_class_type
:
4520 case DW_TAG_structure_type
:
4521 case DW_TAG_union_type
:
4522 case DW_TAG_enumeration_type
:
4523 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4524 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4525 add_symbol_to_list (sym
, list_in_scope
);
4527 /* The semantics of C++ state that "struct foo { ... }" also
4528 defines a typedef for "foo". Synthesize a typedef symbol so
4529 that "ptype foo" works as expected. */
4530 if (cu_language
== language_cplus
)
4532 struct symbol
*typedef_sym
= (struct symbol
*)
4533 obstack_alloc (&objfile
->symbol_obstack
,
4534 sizeof (struct symbol
));
4535 *typedef_sym
= *sym
;
4536 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4537 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4538 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4539 obsavestring (SYMBOL_NAME (sym
),
4540 strlen (SYMBOL_NAME (sym
)),
4541 &objfile
->type_obstack
);
4542 add_symbol_to_list (typedef_sym
, list_in_scope
);
4545 case DW_TAG_typedef
:
4546 case DW_TAG_base_type
:
4547 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4548 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4549 add_symbol_to_list (sym
, list_in_scope
);
4551 case DW_TAG_enumerator
:
4552 attr
= dwarf_attr (die
, DW_AT_const_value
);
4555 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4557 add_symbol_to_list (sym
, list_in_scope
);
4560 /* Not a tag we recognize. Hopefully we aren't processing
4561 trash data, but since we must specifically ignore things
4562 we don't recognize, there is nothing else we should do at
4564 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4571 /* Copy constant value from an attribute to a symbol. */
4574 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
4575 struct objfile
*objfile
,
4576 const struct comp_unit_head
*cu_header
)
4578 struct dwarf_block
*blk
;
4583 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
4584 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4585 cu_header
->addr_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4586 SYMBOL_VALUE_BYTES (sym
) = (char *)
4587 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
4588 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
4590 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4592 case DW_FORM_block1
:
4593 case DW_FORM_block2
:
4594 case DW_FORM_block4
:
4596 blk
= DW_BLOCK (attr
);
4597 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4598 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4599 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4600 SYMBOL_VALUE_BYTES (sym
) = (char *)
4601 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4602 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4603 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4606 /* The DW_AT_const_value attributes are supposed to carry the
4607 symbol's value "represented as it would be on the target
4608 architecture." By the time we get here, it's already been
4609 converted to host endianness, so we just need to sign- or
4610 zero-extend it as appropriate. */
4612 dwarf2_const_value_data (attr
, sym
, 8);
4615 dwarf2_const_value_data (attr
, sym
, 16);
4618 dwarf2_const_value_data (attr
, sym
, 32);
4621 dwarf2_const_value_data (attr
, sym
, 64);
4625 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4626 SYMBOL_CLASS (sym
) = LOC_CONST
;
4630 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4631 SYMBOL_CLASS (sym
) = LOC_CONST
;
4635 complain (&dwarf2_unsupported_const_value_attr
,
4636 dwarf_form_name (attr
->form
));
4637 SYMBOL_VALUE (sym
) = 0;
4638 SYMBOL_CLASS (sym
) = LOC_CONST
;
4644 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4645 or zero-extend it as appropriate for the symbol's type. */
4647 dwarf2_const_value_data (struct attribute
*attr
,
4651 LONGEST l
= DW_UNSND (attr
);
4653 if (bits
< sizeof (l
) * 8)
4655 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4656 l
&= ((LONGEST
) 1 << bits
) - 1;
4658 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4661 SYMBOL_VALUE (sym
) = l
;
4662 SYMBOL_CLASS (sym
) = LOC_CONST
;
4666 /* Return the type of the die in question using its DW_AT_type attribute. */
4668 static struct type
*
4669 die_type (struct die_info
*die
, struct objfile
*objfile
,
4670 const struct comp_unit_head
*cu_header
)
4673 struct attribute
*type_attr
;
4674 struct die_info
*type_die
;
4677 type_attr
= dwarf_attr (die
, DW_AT_type
);
4680 /* A missing DW_AT_type represents a void type. */
4681 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4685 ref
= dwarf2_get_ref_die_offset (type_attr
);
4686 type_die
= follow_die_ref (ref
);
4689 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4693 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4696 dump_die (type_die
);
4697 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4702 /* Return the containing type of the die in question using its
4703 DW_AT_containing_type attribute. */
4705 static struct type
*
4706 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
4707 const struct comp_unit_head
*cu_header
)
4709 struct type
*type
= NULL
;
4710 struct attribute
*type_attr
;
4711 struct die_info
*type_die
= NULL
;
4714 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4717 ref
= dwarf2_get_ref_die_offset (type_attr
);
4718 type_die
= follow_die_ref (ref
);
4721 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4724 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4729 dump_die (type_die
);
4730 error ("Dwarf Error: Problem turning containing type into gdb type.");
4736 static struct type
*
4737 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
4739 struct die_info
*die
;
4742 die
= follow_die_ref (offset
);
4745 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4748 type
= tag_type_to_type (die
, objfile
);
4753 static struct type
*
4754 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
4755 const struct comp_unit_head
*cu_header
)
4763 read_type_die (die
, objfile
, cu_header
);
4767 error ("Dwarf Error: Cannot find type of die.");
4774 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
4775 const struct comp_unit_head
*cu_header
)
4779 case DW_TAG_class_type
:
4780 case DW_TAG_structure_type
:
4781 case DW_TAG_union_type
:
4782 read_structure_scope (die
, objfile
, cu_header
);
4784 case DW_TAG_enumeration_type
:
4785 read_enumeration (die
, objfile
, cu_header
);
4787 case DW_TAG_subprogram
:
4788 case DW_TAG_subroutine_type
:
4789 read_subroutine_type (die
, objfile
, cu_header
);
4791 case DW_TAG_array_type
:
4792 read_array_type (die
, objfile
, cu_header
);
4794 case DW_TAG_pointer_type
:
4795 read_tag_pointer_type (die
, objfile
, cu_header
);
4797 case DW_TAG_ptr_to_member_type
:
4798 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
4800 case DW_TAG_reference_type
:
4801 read_tag_reference_type (die
, objfile
, cu_header
);
4803 case DW_TAG_const_type
:
4804 read_tag_const_type (die
, objfile
, cu_header
);
4806 case DW_TAG_volatile_type
:
4807 read_tag_volatile_type (die
, objfile
, cu_header
);
4809 case DW_TAG_string_type
:
4810 read_tag_string_type (die
, objfile
);
4812 case DW_TAG_typedef
:
4813 read_typedef (die
, objfile
, cu_header
);
4815 case DW_TAG_base_type
:
4816 read_base_type (die
, objfile
);
4819 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4824 static struct type
*
4825 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
4827 /* FIXME - this should not produce a new (struct type *)
4828 every time. It should cache base types. */
4832 case DW_ATE_address
:
4833 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4835 case DW_ATE_boolean
:
4836 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4838 case DW_ATE_complex_float
:
4841 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4845 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4851 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4855 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4862 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4865 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4869 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4873 case DW_ATE_signed_char
:
4874 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4876 case DW_ATE_unsigned
:
4880 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4883 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4887 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4891 case DW_ATE_unsigned_char
:
4892 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4895 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4902 copy_die (struct die_info
*old_die
)
4904 struct die_info
*new_die
;
4907 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4908 memset (new_die
, 0, sizeof (struct die_info
));
4910 new_die
->tag
= old_die
->tag
;
4911 new_die
->has_children
= old_die
->has_children
;
4912 new_die
->abbrev
= old_die
->abbrev
;
4913 new_die
->offset
= old_die
->offset
;
4914 new_die
->type
= NULL
;
4916 num_attrs
= old_die
->num_attrs
;
4917 new_die
->num_attrs
= num_attrs
;
4918 new_die
->attrs
= (struct attribute
*)
4919 xmalloc (num_attrs
* sizeof (struct attribute
));
4921 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4923 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4924 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4925 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4928 new_die
->next
= NULL
;
4933 /* Return sibling of die, NULL if no sibling. */
4935 static struct die_info
*
4936 sibling_die (struct die_info
*die
)
4938 int nesting_level
= 0;
4940 if (!die
->has_children
)
4942 if (die
->next
&& (die
->next
->tag
== 0))
4955 if (die
->has_children
)
4965 while (nesting_level
);
4966 if (die
&& (die
->tag
== 0))
4977 /* Get linkage name of a die, return NULL if not found. */
4980 dwarf2_linkage_name (struct die_info
*die
)
4982 struct attribute
*attr
;
4984 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4985 if (attr
&& DW_STRING (attr
))
4986 return DW_STRING (attr
);
4987 attr
= dwarf_attr (die
, DW_AT_name
);
4988 if (attr
&& DW_STRING (attr
))
4989 return DW_STRING (attr
);
4993 /* Convert a DIE tag into its string name. */
4996 dwarf_tag_name (register unsigned tag
)
5000 case DW_TAG_padding
:
5001 return "DW_TAG_padding";
5002 case DW_TAG_array_type
:
5003 return "DW_TAG_array_type";
5004 case DW_TAG_class_type
:
5005 return "DW_TAG_class_type";
5006 case DW_TAG_entry_point
:
5007 return "DW_TAG_entry_point";
5008 case DW_TAG_enumeration_type
:
5009 return "DW_TAG_enumeration_type";
5010 case DW_TAG_formal_parameter
:
5011 return "DW_TAG_formal_parameter";
5012 case DW_TAG_imported_declaration
:
5013 return "DW_TAG_imported_declaration";
5015 return "DW_TAG_label";
5016 case DW_TAG_lexical_block
:
5017 return "DW_TAG_lexical_block";
5019 return "DW_TAG_member";
5020 case DW_TAG_pointer_type
:
5021 return "DW_TAG_pointer_type";
5022 case DW_TAG_reference_type
:
5023 return "DW_TAG_reference_type";
5024 case DW_TAG_compile_unit
:
5025 return "DW_TAG_compile_unit";
5026 case DW_TAG_string_type
:
5027 return "DW_TAG_string_type";
5028 case DW_TAG_structure_type
:
5029 return "DW_TAG_structure_type";
5030 case DW_TAG_subroutine_type
:
5031 return "DW_TAG_subroutine_type";
5032 case DW_TAG_typedef
:
5033 return "DW_TAG_typedef";
5034 case DW_TAG_union_type
:
5035 return "DW_TAG_union_type";
5036 case DW_TAG_unspecified_parameters
:
5037 return "DW_TAG_unspecified_parameters";
5038 case DW_TAG_variant
:
5039 return "DW_TAG_variant";
5040 case DW_TAG_common_block
:
5041 return "DW_TAG_common_block";
5042 case DW_TAG_common_inclusion
:
5043 return "DW_TAG_common_inclusion";
5044 case DW_TAG_inheritance
:
5045 return "DW_TAG_inheritance";
5046 case DW_TAG_inlined_subroutine
:
5047 return "DW_TAG_inlined_subroutine";
5049 return "DW_TAG_module";
5050 case DW_TAG_ptr_to_member_type
:
5051 return "DW_TAG_ptr_to_member_type";
5052 case DW_TAG_set_type
:
5053 return "DW_TAG_set_type";
5054 case DW_TAG_subrange_type
:
5055 return "DW_TAG_subrange_type";
5056 case DW_TAG_with_stmt
:
5057 return "DW_TAG_with_stmt";
5058 case DW_TAG_access_declaration
:
5059 return "DW_TAG_access_declaration";
5060 case DW_TAG_base_type
:
5061 return "DW_TAG_base_type";
5062 case DW_TAG_catch_block
:
5063 return "DW_TAG_catch_block";
5064 case DW_TAG_const_type
:
5065 return "DW_TAG_const_type";
5066 case DW_TAG_constant
:
5067 return "DW_TAG_constant";
5068 case DW_TAG_enumerator
:
5069 return "DW_TAG_enumerator";
5070 case DW_TAG_file_type
:
5071 return "DW_TAG_file_type";
5073 return "DW_TAG_friend";
5074 case DW_TAG_namelist
:
5075 return "DW_TAG_namelist";
5076 case DW_TAG_namelist_item
:
5077 return "DW_TAG_namelist_item";
5078 case DW_TAG_packed_type
:
5079 return "DW_TAG_packed_type";
5080 case DW_TAG_subprogram
:
5081 return "DW_TAG_subprogram";
5082 case DW_TAG_template_type_param
:
5083 return "DW_TAG_template_type_param";
5084 case DW_TAG_template_value_param
:
5085 return "DW_TAG_template_value_param";
5086 case DW_TAG_thrown_type
:
5087 return "DW_TAG_thrown_type";
5088 case DW_TAG_try_block
:
5089 return "DW_TAG_try_block";
5090 case DW_TAG_variant_part
:
5091 return "DW_TAG_variant_part";
5092 case DW_TAG_variable
:
5093 return "DW_TAG_variable";
5094 case DW_TAG_volatile_type
:
5095 return "DW_TAG_volatile_type";
5096 case DW_TAG_MIPS_loop
:
5097 return "DW_TAG_MIPS_loop";
5098 case DW_TAG_format_label
:
5099 return "DW_TAG_format_label";
5100 case DW_TAG_function_template
:
5101 return "DW_TAG_function_template";
5102 case DW_TAG_class_template
:
5103 return "DW_TAG_class_template";
5105 return "DW_TAG_<unknown>";
5109 /* Convert a DWARF attribute code into its string name. */
5112 dwarf_attr_name (register unsigned attr
)
5117 return "DW_AT_sibling";
5118 case DW_AT_location
:
5119 return "DW_AT_location";
5121 return "DW_AT_name";
5122 case DW_AT_ordering
:
5123 return "DW_AT_ordering";
5124 case DW_AT_subscr_data
:
5125 return "DW_AT_subscr_data";
5126 case DW_AT_byte_size
:
5127 return "DW_AT_byte_size";
5128 case DW_AT_bit_offset
:
5129 return "DW_AT_bit_offset";
5130 case DW_AT_bit_size
:
5131 return "DW_AT_bit_size";
5132 case DW_AT_element_list
:
5133 return "DW_AT_element_list";
5134 case DW_AT_stmt_list
:
5135 return "DW_AT_stmt_list";
5137 return "DW_AT_low_pc";
5139 return "DW_AT_high_pc";
5140 case DW_AT_language
:
5141 return "DW_AT_language";
5143 return "DW_AT_member";
5145 return "DW_AT_discr";
5146 case DW_AT_discr_value
:
5147 return "DW_AT_discr_value";
5148 case DW_AT_visibility
:
5149 return "DW_AT_visibility";
5151 return "DW_AT_import";
5152 case DW_AT_string_length
:
5153 return "DW_AT_string_length";
5154 case DW_AT_common_reference
:
5155 return "DW_AT_common_reference";
5156 case DW_AT_comp_dir
:
5157 return "DW_AT_comp_dir";
5158 case DW_AT_const_value
:
5159 return "DW_AT_const_value";
5160 case DW_AT_containing_type
:
5161 return "DW_AT_containing_type";
5162 case DW_AT_default_value
:
5163 return "DW_AT_default_value";
5165 return "DW_AT_inline";
5166 case DW_AT_is_optional
:
5167 return "DW_AT_is_optional";
5168 case DW_AT_lower_bound
:
5169 return "DW_AT_lower_bound";
5170 case DW_AT_producer
:
5171 return "DW_AT_producer";
5172 case DW_AT_prototyped
:
5173 return "DW_AT_prototyped";
5174 case DW_AT_return_addr
:
5175 return "DW_AT_return_addr";
5176 case DW_AT_start_scope
:
5177 return "DW_AT_start_scope";
5178 case DW_AT_stride_size
:
5179 return "DW_AT_stride_size";
5180 case DW_AT_upper_bound
:
5181 return "DW_AT_upper_bound";
5182 case DW_AT_abstract_origin
:
5183 return "DW_AT_abstract_origin";
5184 case DW_AT_accessibility
:
5185 return "DW_AT_accessibility";
5186 case DW_AT_address_class
:
5187 return "DW_AT_address_class";
5188 case DW_AT_artificial
:
5189 return "DW_AT_artificial";
5190 case DW_AT_base_types
:
5191 return "DW_AT_base_types";
5192 case DW_AT_calling_convention
:
5193 return "DW_AT_calling_convention";
5195 return "DW_AT_count";
5196 case DW_AT_data_member_location
:
5197 return "DW_AT_data_member_location";
5198 case DW_AT_decl_column
:
5199 return "DW_AT_decl_column";
5200 case DW_AT_decl_file
:
5201 return "DW_AT_decl_file";
5202 case DW_AT_decl_line
:
5203 return "DW_AT_decl_line";
5204 case DW_AT_declaration
:
5205 return "DW_AT_declaration";
5206 case DW_AT_discr_list
:
5207 return "DW_AT_discr_list";
5208 case DW_AT_encoding
:
5209 return "DW_AT_encoding";
5210 case DW_AT_external
:
5211 return "DW_AT_external";
5212 case DW_AT_frame_base
:
5213 return "DW_AT_frame_base";
5215 return "DW_AT_friend";
5216 case DW_AT_identifier_case
:
5217 return "DW_AT_identifier_case";
5218 case DW_AT_macro_info
:
5219 return "DW_AT_macro_info";
5220 case DW_AT_namelist_items
:
5221 return "DW_AT_namelist_items";
5222 case DW_AT_priority
:
5223 return "DW_AT_priority";
5225 return "DW_AT_segment";
5226 case DW_AT_specification
:
5227 return "DW_AT_specification";
5228 case DW_AT_static_link
:
5229 return "DW_AT_static_link";
5231 return "DW_AT_type";
5232 case DW_AT_use_location
:
5233 return "DW_AT_use_location";
5234 case DW_AT_variable_parameter
:
5235 return "DW_AT_variable_parameter";
5236 case DW_AT_virtuality
:
5237 return "DW_AT_virtuality";
5238 case DW_AT_vtable_elem_location
:
5239 return "DW_AT_vtable_elem_location";
5242 case DW_AT_MIPS_fde
:
5243 return "DW_AT_MIPS_fde";
5244 case DW_AT_MIPS_loop_begin
:
5245 return "DW_AT_MIPS_loop_begin";
5246 case DW_AT_MIPS_tail_loop_begin
:
5247 return "DW_AT_MIPS_tail_loop_begin";
5248 case DW_AT_MIPS_epilog_begin
:
5249 return "DW_AT_MIPS_epilog_begin";
5250 case DW_AT_MIPS_loop_unroll_factor
:
5251 return "DW_AT_MIPS_loop_unroll_factor";
5252 case DW_AT_MIPS_software_pipeline_depth
:
5253 return "DW_AT_MIPS_software_pipeline_depth";
5254 case DW_AT_MIPS_linkage_name
:
5255 return "DW_AT_MIPS_linkage_name";
5258 case DW_AT_sf_names
:
5259 return "DW_AT_sf_names";
5260 case DW_AT_src_info
:
5261 return "DW_AT_src_info";
5262 case DW_AT_mac_info
:
5263 return "DW_AT_mac_info";
5264 case DW_AT_src_coords
:
5265 return "DW_AT_src_coords";
5266 case DW_AT_body_begin
:
5267 return "DW_AT_body_begin";
5268 case DW_AT_body_end
:
5269 return "DW_AT_body_end";
5271 return "DW_AT_<unknown>";
5275 /* Convert a DWARF value form code into its string name. */
5278 dwarf_form_name (register unsigned form
)
5283 return "DW_FORM_addr";
5284 case DW_FORM_block2
:
5285 return "DW_FORM_block2";
5286 case DW_FORM_block4
:
5287 return "DW_FORM_block4";
5289 return "DW_FORM_data2";
5291 return "DW_FORM_data4";
5293 return "DW_FORM_data8";
5294 case DW_FORM_string
:
5295 return "DW_FORM_string";
5297 return "DW_FORM_block";
5298 case DW_FORM_block1
:
5299 return "DW_FORM_block1";
5301 return "DW_FORM_data1";
5303 return "DW_FORM_flag";
5305 return "DW_FORM_sdata";
5307 return "DW_FORM_strp";
5309 return "DW_FORM_udata";
5310 case DW_FORM_ref_addr
:
5311 return "DW_FORM_ref_addr";
5313 return "DW_FORM_ref1";
5315 return "DW_FORM_ref2";
5317 return "DW_FORM_ref4";
5319 return "DW_FORM_ref8";
5320 case DW_FORM_ref_udata
:
5321 return "DW_FORM_ref_udata";
5322 case DW_FORM_indirect
:
5323 return "DW_FORM_indirect";
5325 return "DW_FORM_<unknown>";
5329 /* Convert a DWARF stack opcode into its string name. */
5332 dwarf_stack_op_name (register unsigned op
)
5337 return "DW_OP_addr";
5339 return "DW_OP_deref";
5341 return "DW_OP_const1u";
5343 return "DW_OP_const1s";
5345 return "DW_OP_const2u";
5347 return "DW_OP_const2s";
5349 return "DW_OP_const4u";
5351 return "DW_OP_const4s";
5353 return "DW_OP_const8u";
5355 return "DW_OP_const8s";
5357 return "DW_OP_constu";
5359 return "DW_OP_consts";
5363 return "DW_OP_drop";
5365 return "DW_OP_over";
5367 return "DW_OP_pick";
5369 return "DW_OP_swap";
5373 return "DW_OP_xderef";
5381 return "DW_OP_minus";
5393 return "DW_OP_plus";
5394 case DW_OP_plus_uconst
:
5395 return "DW_OP_plus_uconst";
5401 return "DW_OP_shra";
5419 return "DW_OP_skip";
5421 return "DW_OP_lit0";
5423 return "DW_OP_lit1";
5425 return "DW_OP_lit2";
5427 return "DW_OP_lit3";
5429 return "DW_OP_lit4";
5431 return "DW_OP_lit5";
5433 return "DW_OP_lit6";
5435 return "DW_OP_lit7";
5437 return "DW_OP_lit8";
5439 return "DW_OP_lit9";
5441 return "DW_OP_lit10";
5443 return "DW_OP_lit11";
5445 return "DW_OP_lit12";
5447 return "DW_OP_lit13";
5449 return "DW_OP_lit14";
5451 return "DW_OP_lit15";
5453 return "DW_OP_lit16";
5455 return "DW_OP_lit17";
5457 return "DW_OP_lit18";
5459 return "DW_OP_lit19";
5461 return "DW_OP_lit20";
5463 return "DW_OP_lit21";
5465 return "DW_OP_lit22";
5467 return "DW_OP_lit23";
5469 return "DW_OP_lit24";
5471 return "DW_OP_lit25";
5473 return "DW_OP_lit26";
5475 return "DW_OP_lit27";
5477 return "DW_OP_lit28";
5479 return "DW_OP_lit29";
5481 return "DW_OP_lit30";
5483 return "DW_OP_lit31";
5485 return "DW_OP_reg0";
5487 return "DW_OP_reg1";
5489 return "DW_OP_reg2";
5491 return "DW_OP_reg3";
5493 return "DW_OP_reg4";
5495 return "DW_OP_reg5";
5497 return "DW_OP_reg6";
5499 return "DW_OP_reg7";
5501 return "DW_OP_reg8";
5503 return "DW_OP_reg9";
5505 return "DW_OP_reg10";
5507 return "DW_OP_reg11";
5509 return "DW_OP_reg12";
5511 return "DW_OP_reg13";
5513 return "DW_OP_reg14";
5515 return "DW_OP_reg15";
5517 return "DW_OP_reg16";
5519 return "DW_OP_reg17";
5521 return "DW_OP_reg18";
5523 return "DW_OP_reg19";
5525 return "DW_OP_reg20";
5527 return "DW_OP_reg21";
5529 return "DW_OP_reg22";
5531 return "DW_OP_reg23";
5533 return "DW_OP_reg24";
5535 return "DW_OP_reg25";
5537 return "DW_OP_reg26";
5539 return "DW_OP_reg27";
5541 return "DW_OP_reg28";
5543 return "DW_OP_reg29";
5545 return "DW_OP_reg30";
5547 return "DW_OP_reg31";
5549 return "DW_OP_breg0";
5551 return "DW_OP_breg1";
5553 return "DW_OP_breg2";
5555 return "DW_OP_breg3";
5557 return "DW_OP_breg4";
5559 return "DW_OP_breg5";
5561 return "DW_OP_breg6";
5563 return "DW_OP_breg7";
5565 return "DW_OP_breg8";
5567 return "DW_OP_breg9";
5569 return "DW_OP_breg10";
5571 return "DW_OP_breg11";
5573 return "DW_OP_breg12";
5575 return "DW_OP_breg13";
5577 return "DW_OP_breg14";
5579 return "DW_OP_breg15";
5581 return "DW_OP_breg16";
5583 return "DW_OP_breg17";
5585 return "DW_OP_breg18";
5587 return "DW_OP_breg19";
5589 return "DW_OP_breg20";
5591 return "DW_OP_breg21";
5593 return "DW_OP_breg22";
5595 return "DW_OP_breg23";
5597 return "DW_OP_breg24";
5599 return "DW_OP_breg25";
5601 return "DW_OP_breg26";
5603 return "DW_OP_breg27";
5605 return "DW_OP_breg28";
5607 return "DW_OP_breg29";
5609 return "DW_OP_breg30";
5611 return "DW_OP_breg31";
5613 return "DW_OP_regx";
5615 return "DW_OP_fbreg";
5617 return "DW_OP_bregx";
5619 return "DW_OP_piece";
5620 case DW_OP_deref_size
:
5621 return "DW_OP_deref_size";
5622 case DW_OP_xderef_size
:
5623 return "DW_OP_xderef_size";
5627 return "OP_<unknown>";
5632 dwarf_bool_name (unsigned mybool
)
5640 /* Convert a DWARF type code into its string name. */
5643 dwarf_type_encoding_name (register unsigned enc
)
5647 case DW_ATE_address
:
5648 return "DW_ATE_address";
5649 case DW_ATE_boolean
:
5650 return "DW_ATE_boolean";
5651 case DW_ATE_complex_float
:
5652 return "DW_ATE_complex_float";
5654 return "DW_ATE_float";
5656 return "DW_ATE_signed";
5657 case DW_ATE_signed_char
:
5658 return "DW_ATE_signed_char";
5659 case DW_ATE_unsigned
:
5660 return "DW_ATE_unsigned";
5661 case DW_ATE_unsigned_char
:
5662 return "DW_ATE_unsigned_char";
5664 return "DW_ATE_<unknown>";
5668 /* Convert a DWARF call frame info operation to its string name. */
5672 dwarf_cfi_name (register unsigned cfi_opc
)
5676 case DW_CFA_advance_loc
:
5677 return "DW_CFA_advance_loc";
5679 return "DW_CFA_offset";
5680 case DW_CFA_restore
:
5681 return "DW_CFA_restore";
5683 return "DW_CFA_nop";
5684 case DW_CFA_set_loc
:
5685 return "DW_CFA_set_loc";
5686 case DW_CFA_advance_loc1
:
5687 return "DW_CFA_advance_loc1";
5688 case DW_CFA_advance_loc2
:
5689 return "DW_CFA_advance_loc2";
5690 case DW_CFA_advance_loc4
:
5691 return "DW_CFA_advance_loc4";
5692 case DW_CFA_offset_extended
:
5693 return "DW_CFA_offset_extended";
5694 case DW_CFA_restore_extended
:
5695 return "DW_CFA_restore_extended";
5696 case DW_CFA_undefined
:
5697 return "DW_CFA_undefined";
5698 case DW_CFA_same_value
:
5699 return "DW_CFA_same_value";
5700 case DW_CFA_register
:
5701 return "DW_CFA_register";
5702 case DW_CFA_remember_state
:
5703 return "DW_CFA_remember_state";
5704 case DW_CFA_restore_state
:
5705 return "DW_CFA_restore_state";
5706 case DW_CFA_def_cfa
:
5707 return "DW_CFA_def_cfa";
5708 case DW_CFA_def_cfa_register
:
5709 return "DW_CFA_def_cfa_register";
5710 case DW_CFA_def_cfa_offset
:
5711 return "DW_CFA_def_cfa_offset";
5714 case DW_CFA_def_cfa_expression
:
5715 return "DW_CFA_def_cfa_expression";
5716 case DW_CFA_expression
:
5717 return "DW_CFA_expression";
5718 case DW_CFA_offset_extended_sf
:
5719 return "DW_CFA_offset_extended_sf";
5720 case DW_CFA_def_cfa_sf
:
5721 return "DW_CFA_def_cfa_sf";
5722 case DW_CFA_def_cfa_offset_sf
:
5723 return "DW_CFA_def_cfa_offset_sf";
5725 /* SGI/MIPS specific */
5726 case DW_CFA_MIPS_advance_loc8
:
5727 return "DW_CFA_MIPS_advance_loc8";
5729 /* GNU extensions */
5730 case DW_CFA_GNU_window_save
:
5731 return "DW_CFA_GNU_window_save";
5732 case DW_CFA_GNU_args_size
:
5733 return "DW_CFA_GNU_args_size";
5734 case DW_CFA_GNU_negative_offset_extended
:
5735 return "DW_CFA_GNU_negative_offset_extended";
5738 return "DW_CFA_<unknown>";
5744 dump_die (struct die_info
*die
)
5748 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5749 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5750 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
5751 dwarf_bool_name (die
->has_children
));
5753 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
5754 for (i
= 0; i
< die
->num_attrs
; ++i
)
5756 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
5757 dwarf_attr_name (die
->attrs
[i
].name
),
5758 dwarf_form_name (die
->attrs
[i
].form
));
5759 switch (die
->attrs
[i
].form
)
5761 case DW_FORM_ref_addr
:
5763 fprintf_unfiltered (gdb_stderr
, "address: ");
5764 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5766 case DW_FORM_block2
:
5767 case DW_FORM_block4
:
5769 case DW_FORM_block1
:
5770 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5781 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
5783 case DW_FORM_string
:
5785 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
5786 DW_STRING (&die
->attrs
[i
])
5787 ? DW_STRING (&die
->attrs
[i
]) : "");
5790 if (DW_UNSND (&die
->attrs
[i
]))
5791 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
5793 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
5795 case DW_FORM_indirect
:
5796 /* the reader will have reduced the indirect form to
5797 the "base form" so this form should not occur */
5798 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
5801 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
5802 die
->attrs
[i
].form
);
5804 fprintf_unfiltered (gdb_stderr
, "\n");
5809 dump_die_list (struct die_info
*die
)
5819 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
5822 struct die_info
*old
;
5824 h
= (offset
% REF_HASH_SIZE
);
5825 old
= die_ref_table
[h
];
5826 die
->next_ref
= old
;
5827 die_ref_table
[h
] = die
;
5832 dwarf2_empty_hash_tables (void)
5834 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5838 dwarf2_get_ref_die_offset (struct attribute
*attr
)
5840 unsigned int result
= 0;
5844 case DW_FORM_ref_addr
:
5845 result
= DW_ADDR (attr
);
5851 case DW_FORM_ref_udata
:
5852 result
= cu_header_offset
+ DW_UNSND (attr
);
5855 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5860 static struct die_info
*
5861 follow_die_ref (unsigned int offset
)
5863 struct die_info
*die
;
5866 h
= (offset
% REF_HASH_SIZE
);
5867 die
= die_ref_table
[h
];
5870 if (die
->offset
== offset
)
5874 die
= die
->next_ref
;
5879 static struct type
*
5880 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
5882 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5884 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5888 /* Look for this particular type in the fundamental type vector. If
5889 one is not found, create and install one appropriate for the
5890 current language and the current target machine. */
5892 if (ftypes
[typeid] == NULL
)
5894 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5897 return (ftypes
[typeid]);
5900 /* Decode simple location descriptions.
5901 Given a pointer to a dwarf block that defines a location, compute
5902 the location and return the value.
5904 FIXME: This is a kludge until we figure out a better
5905 way to handle the location descriptions.
5906 Gdb's design does not mesh well with the DWARF2 notion of a location
5907 computing interpreter, which is a shame because the flexibility goes unused.
5908 FIXME: Implement more operations as necessary.
5910 A location description containing no operations indicates that the
5911 object is optimized out. The global optimized_out flag is set for
5912 those, the return value is meaningless.
5914 When the result is a register number, the global isreg flag is set,
5915 otherwise it is cleared.
5917 When the result is a base register offset, the global offreg flag is set
5918 and the register number is returned in basereg, otherwise it is cleared.
5920 When the DW_OP_fbreg operation is encountered without a corresponding
5921 DW_AT_frame_base attribute, the global islocal flag is set.
5922 Hopefully the machine dependent code knows how to set up a virtual
5923 frame pointer for the local references.
5925 Note that stack[0] is unused except as a default error return.
5926 Note that stack overflow is not yet handled. */
5929 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
5930 const struct comp_unit_head
*cu_header
)
5933 int size
= blk
->size
;
5934 char *data
= blk
->data
;
5935 CORE_ADDR stack
[64];
5937 unsigned int bytes_read
, unsnd
;
5987 stack
[++stacki
] = op
- DW_OP_lit0
;
6023 stack
[++stacki
] = op
- DW_OP_reg0
;
6028 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6030 #if defined(HARRIS_TARGET) && defined(_M88K)
6031 /* The Harris 88110 gdb ports have long kept their special reg
6032 numbers between their gp-regs and their x-regs. This is
6033 not how our dwarf is generated. Punt. */
6036 stack
[++stacki
] = unsnd
;
6072 basereg
= op
- DW_OP_breg0
;
6073 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6079 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6081 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6086 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6088 if (frame_base_reg
>= 0)
6091 basereg
= frame_base_reg
;
6092 stack
[stacki
] += frame_base_offset
;
6096 complain (&dwarf2_missing_at_frame_base
);
6102 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
6103 cu_header
, &bytes_read
);
6108 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
6113 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
6118 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
6123 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
6128 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
6133 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
6138 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
6144 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6149 stack
[stacki
+ 1] = stack
[stacki
];
6154 stack
[stacki
- 1] += stack
[stacki
];
6158 case DW_OP_plus_uconst
:
6159 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6164 stack
[stacki
- 1] -= stack
[stacki
];
6170 /* If we're not the last op, then we definitely can't encode
6171 this using GDB's address_class enum. */
6173 complain (&dwarf2_complex_location_expr
);
6177 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
6178 return (stack
[stacki
]);
6181 return (stack
[stacki
]);
6184 /* memory allocation interface */
6188 dwarf2_free_tmp_obstack (PTR ignore
)
6190 obstack_free (&dwarf2_tmp_obstack
, NULL
);
6193 static struct dwarf_block
*
6194 dwarf_alloc_block (void)
6196 struct dwarf_block
*blk
;
6198 blk
= (struct dwarf_block
*)
6199 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
6203 static struct abbrev_info
*
6204 dwarf_alloc_abbrev (void)
6206 struct abbrev_info
*abbrev
;
6208 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
6209 memset (abbrev
, 0, sizeof (struct abbrev_info
));
6213 static struct die_info
*
6214 dwarf_alloc_die (void)
6216 struct die_info
*die
;
6218 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6219 memset (die
, 0, sizeof (struct die_info
));