1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
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 /* Get at parts of an attribute structure */
261 #define DW_STRING(attr) ((attr)->u.str)
262 #define DW_UNSND(attr) ((attr)->u.unsnd)
263 #define DW_BLOCK(attr) ((attr)->u.blk)
264 #define DW_SND(attr) ((attr)->u.snd)
265 #define DW_ADDR(attr) ((attr)->u.addr)
267 /* Blocks are a bunch of untyped bytes. */
274 /* We only hold one compilation unit's abbrevs in
275 memory at any one time. */
276 #ifndef ABBREV_HASH_SIZE
277 #define ABBREV_HASH_SIZE 121
279 #ifndef ATTR_ALLOC_CHUNK
280 #define ATTR_ALLOC_CHUNK 4
283 static struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
285 /* A hash table of die offsets for following references. */
286 #ifndef REF_HASH_SIZE
287 #define REF_HASH_SIZE 1021
290 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
292 /* Obstack for allocating temporary storage used during symbol reading. */
293 static struct obstack dwarf2_tmp_obstack
;
295 /* Offset to the first byte of the current compilation unit header,
296 for resolving relative reference dies. */
297 static unsigned int cu_header_offset
;
299 /* Allocate fields for structs, unions and enums in this size. */
300 #ifndef DW_FIELD_ALLOC_CHUNK
301 #define DW_FIELD_ALLOC_CHUNK 4
304 /* The language we are debugging. */
305 static enum language cu_language
;
306 static const struct language_defn
*cu_language_defn
;
308 /* Actually data from the sections. */
309 static char *dwarf_info_buffer
;
310 static char *dwarf_abbrev_buffer
;
311 static char *dwarf_line_buffer
;
312 static char *dwarf_str_buffer
;
314 /* A zeroed version of a partial die for initialization purposes. */
315 static struct partial_die_info zeroed_partial_die
;
317 /* The generic symbol table building routines have separate lists for
318 file scope symbols and all all other scopes (local scopes). So
319 we need to select the right one to pass to add_symbol_to_list().
320 We do it by keeping a pointer to the correct list in list_in_scope.
322 FIXME: The original dwarf code just treated the file scope as the first
323 local scope, and all other local scopes as nested local scopes, and worked
324 fine. Check to see if we really need to distinguish these
326 static struct pending
**list_in_scope
= &file_symbols
;
328 /* FIXME: decode_locdesc sets these variables to describe the location
329 to the caller. These ought to be a structure or something. If
330 none of the flags are set, the object lives at the address returned
331 by decode_locdesc. */
333 static int optimized_out
; /* No ops in location in expression,
334 so object was optimized out. */
335 static int isreg
; /* Object lives in register.
336 decode_locdesc's return value is
337 the register number. */
338 static int offreg
; /* Object's address is the sum of the
339 register specified by basereg, plus
340 the offset returned. */
341 static int basereg
; /* See `offreg'. */
342 static int isderef
; /* Value described by flags above is
343 the address of a pointer to the object. */
344 static int islocal
; /* Variable is at the returned offset
345 from the frame start, but there's
346 no identified frame pointer for
347 this function, so we can't say
348 which register it's relative to;
351 /* DW_AT_frame_base values for the current function.
352 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
353 contains the register number for the frame register.
354 frame_base_offset is the offset from the frame register to the
355 virtual stack frame. */
356 static int frame_base_reg
;
357 static CORE_ADDR frame_base_offset
;
359 /* This value is added to each symbol value. FIXME: Generalize to
360 the section_offsets structure used by dbxread (once this is done,
361 pass the appropriate section number to end_symtab). */
362 static CORE_ADDR baseaddr
; /* Add to each symbol value */
364 /* We put a pointer to this structure in the read_symtab_private field
366 The complete dwarf information for an objfile is kept in the
367 psymbol_obstack, so that absolute die references can be handled.
368 Most of the information in this structure is related to an entire
369 object file and could be passed via the sym_private field of the objfile.
370 It is however conceivable that dwarf2 might not be the only type
371 of symbols read from an object file. */
375 /* Pointer to start of dwarf info buffer for the objfile. */
377 char *dwarf_info_buffer
;
379 /* Offset in dwarf_info_buffer for this compilation unit. */
381 unsigned long dwarf_info_offset
;
383 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
385 char *dwarf_abbrev_buffer
;
387 /* Size of dwarf abbreviation section for the objfile. */
389 unsigned int dwarf_abbrev_size
;
391 /* Pointer to start of dwarf line buffer for the objfile. */
393 char *dwarf_line_buffer
;
395 /* Pointer to start of dwarf string buffer for the objfile. */
397 char *dwarf_str_buffer
;
399 /* Size of dwarf string section for the objfile. */
401 unsigned int dwarf_str_size
;
404 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
405 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
406 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
407 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
408 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
409 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
410 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
411 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
413 /* Maintain an array of referenced fundamental types for the current
414 compilation unit being read. For DWARF version 1, we have to construct
415 the fundamental types on the fly, since no information about the
416 fundamental types is supplied. Each such fundamental type is created by
417 calling a language dependent routine to create the type, and then a
418 pointer to that type is then placed in the array at the index specified
419 by it's FT_<TYPENAME> value. The array has a fixed size set by the
420 FT_NUM_MEMBERS compile time constant, which is the number of predefined
421 fundamental types gdb knows how to construct. */
422 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
424 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
425 but this would require a corresponding change in unpack_field_as_long
427 static int bits_per_byte
= 8;
429 /* The routines that read and process dies for a C struct or C++ class
430 pass lists of data member fields and lists of member function fields
431 in an instance of a field_info structure, as defined below. */
434 /* List of data member and baseclasses fields. */
437 struct nextfield
*next
;
444 /* Number of fields. */
447 /* Number of baseclasses. */
450 /* Set if the accesibility of one of the fields is not public. */
451 int non_public_fields
;
453 /* Member function fields array, entries are allocated in the order they
454 are encountered in the object file. */
457 struct nextfnfield
*next
;
458 struct fn_field fnfield
;
462 /* Member function fieldlist array, contains name of possibly overloaded
463 member function, number of overloaded member functions and a pointer
464 to the head of the member function field chain. */
469 struct nextfnfield
*head
;
473 /* Number of entries in the fnfieldlists array. */
477 /* Dwarf2 has no clean way to discern C++ static and non-static member
478 functions. G++ helps GDB by marking the first parameter for non-static
479 member functions (which is the this pointer) as artificial.
480 We pass this information between dwarf2_add_member_fn and
481 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
482 #define TYPE_FIELD_ARTIFICIAL TYPE_FIELD_BITPOS
484 /* Various complaints about symbol reading that don't abort the process */
486 static struct complaint dwarf2_const_ignored
=
488 "type qualifier 'const' ignored", 0, 0
490 static struct complaint dwarf2_volatile_ignored
=
492 "type qualifier 'volatile' ignored", 0, 0
494 static struct complaint dwarf2_non_const_array_bound_ignored
=
496 "non-constant array bounds form '%s' ignored", 0, 0
498 static struct complaint dwarf2_missing_line_number_section
=
500 "missing .debug_line section", 0, 0
502 static struct complaint dwarf2_mangled_line_number_section
=
504 "mangled .debug_line section", 0, 0
506 static struct complaint dwarf2_unsupported_die_ref_attr
=
508 "unsupported die ref attribute form: '%s'", 0, 0
510 static struct complaint dwarf2_unsupported_stack_op
=
512 "unsupported stack op: '%s'", 0, 0
514 static struct complaint dwarf2_complex_location_expr
=
516 "location expression too complex", 0, 0
518 static struct complaint dwarf2_unsupported_tag
=
520 "unsupported tag: '%s'", 0, 0
522 static struct complaint dwarf2_unsupported_at_encoding
=
524 "unsupported DW_AT_encoding: '%s'", 0, 0
526 static struct complaint dwarf2_unsupported_at_frame_base
=
528 "unsupported DW_AT_frame_base for function '%s'", 0, 0
530 static struct complaint dwarf2_unexpected_tag
=
532 "unexepected tag in read_type_die: '%s'", 0, 0
534 static struct complaint dwarf2_missing_at_frame_base
=
536 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
538 static struct complaint dwarf2_bad_static_member_name
=
540 "unrecognized static data member name '%s'", 0, 0
542 static struct complaint dwarf2_unsupported_accessibility
=
544 "unsupported accessibility %d", 0, 0
546 static struct complaint dwarf2_bad_member_name_complaint
=
548 "cannot extract member name from '%s'", 0, 0
550 static struct complaint dwarf2_missing_member_fn_type_complaint
=
552 "member function type missing for '%s'", 0, 0
554 static struct complaint dwarf2_vtbl_not_found_complaint
=
556 "virtual function table pointer not found when defining class '%s'", 0, 0
558 static struct complaint dwarf2_absolute_sibling_complaint
=
560 "ignoring absolute DW_AT_sibling", 0, 0
562 static struct complaint dwarf2_const_value_length_mismatch
=
564 "const value length mismatch for '%s', got %d, expected %d", 0, 0
566 static struct complaint dwarf2_unsupported_const_value_attr
=
568 "unsupported const value attribute form: '%s'", 0, 0
571 /* local function prototypes */
573 static void dwarf2_locate_sections (bfd
*, asection
*, PTR
);
576 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
579 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
581 static char *scan_partial_symbols (char *, struct objfile
*,
582 CORE_ADDR
*, CORE_ADDR
*,
583 const struct comp_unit_head
*);
585 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
586 const struct comp_unit_head
*);
588 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
590 static void psymtab_to_symtab_1 (struct partial_symtab
*);
592 char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int);
594 static void dwarf2_read_abbrevs (bfd
*, unsigned int);
596 static void dwarf2_empty_abbrev_table (PTR
);
598 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int);
600 static char *read_partial_die (struct partial_die_info
*,
602 const struct comp_unit_head
*);
604 static char *read_full_die (struct die_info
**, bfd
*, char *,
605 const struct comp_unit_head
*);
607 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
608 bfd
*, char *, const struct comp_unit_head
*);
610 static char *read_attribute_value (struct attribute
*, unsigned,
611 bfd
*, char *, const struct comp_unit_head
*);
613 static unsigned int read_1_byte (bfd
*, char *);
615 static int read_1_signed_byte (bfd
*, char *);
617 static unsigned int read_2_bytes (bfd
*, char *);
619 static unsigned int read_4_bytes (bfd
*, char *);
621 static unsigned long read_8_bytes (bfd
*, char *);
623 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
626 static LONGEST
read_initial_length (bfd
*, char *,
627 struct comp_unit_head
*, int *bytes_read
);
629 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
632 static char *read_n_bytes (bfd
*, char *, unsigned int);
634 static char *read_string (bfd
*, char *, unsigned int *);
636 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
639 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
641 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
643 static void set_cu_language (unsigned int);
645 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
647 static int die_is_declaration (struct die_info
*);
649 static void dwarf_decode_lines (unsigned int, char *, bfd
*,
650 const struct comp_unit_head
*);
652 static void dwarf2_start_subfile (char *, char *);
654 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
655 struct objfile
*, const struct comp_unit_head
*);
657 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
658 struct objfile
*, const struct comp_unit_head
*);
660 static void dwarf2_const_value_data (struct attribute
*attr
,
664 static struct type
*die_type (struct die_info
*, struct objfile
*,
665 const struct comp_unit_head
*);
667 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
668 const struct comp_unit_head
*);
671 static struct type
*type_at_offset (unsigned int, struct objfile
*);
674 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
675 const struct comp_unit_head
*);
677 static void read_type_die (struct die_info
*, struct objfile
*,
678 const struct comp_unit_head
*);
680 static void read_typedef (struct die_info
*, struct objfile
*,
681 const struct comp_unit_head
*);
683 static void read_base_type (struct die_info
*, struct objfile
*);
685 static void read_file_scope (struct die_info
*, struct objfile
*,
686 const struct comp_unit_head
*);
688 static void read_func_scope (struct die_info
*, struct objfile
*,
689 const struct comp_unit_head
*);
691 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
692 const struct comp_unit_head
*);
694 static int dwarf2_get_pc_bounds (struct die_info
*,
695 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*);
697 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
698 struct objfile
*, const struct comp_unit_head
*);
700 static void dwarf2_attach_fields_to_type (struct field_info
*,
701 struct type
*, struct objfile
*);
703 static void dwarf2_add_member_fn (struct field_info
*,
704 struct die_info
*, struct type
*,
705 struct objfile
*objfile
,
706 const struct comp_unit_head
*);
708 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
709 struct type
*, struct objfile
*);
711 static void read_structure_scope (struct die_info
*, struct objfile
*,
712 const struct comp_unit_head
*);
714 static void read_common_block (struct die_info
*, struct objfile
*,
715 const struct comp_unit_head
*);
717 static void read_enumeration (struct die_info
*, struct objfile
*,
718 const struct comp_unit_head
*);
720 static struct type
*dwarf_base_type (int, int, struct objfile
*);
722 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
723 const struct comp_unit_head
*);
725 static void read_array_type (struct die_info
*, struct objfile
*,
726 const struct comp_unit_head
*);
728 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
729 const struct comp_unit_head
*);
731 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
732 const struct comp_unit_head
*);
734 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
735 const struct comp_unit_head
*);
737 static void read_tag_const_type (struct die_info
*, struct objfile
*,
738 const struct comp_unit_head
*);
740 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
741 const struct comp_unit_head
*);
743 static void read_tag_string_type (struct die_info
*, struct objfile
*);
745 static void read_subroutine_type (struct die_info
*, struct objfile
*,
746 const struct comp_unit_head
*);
748 static struct die_info
*read_comp_unit (char *, bfd
*,
749 const struct comp_unit_head
*);
751 static void free_die_list (struct die_info
*);
753 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
755 static void process_die (struct die_info
*, struct objfile
*,
756 const struct comp_unit_head
*);
758 static char *dwarf2_linkage_name (struct die_info
*);
760 static char *dwarf_tag_name (unsigned int);
762 static char *dwarf_attr_name (unsigned int);
764 static char *dwarf_form_name (unsigned int);
766 static char *dwarf_stack_op_name (unsigned int);
768 static char *dwarf_bool_name (unsigned int);
770 static char *dwarf_type_encoding_name (unsigned int);
773 static char *dwarf_cfi_name (unsigned int);
775 struct die_info
*copy_die (struct die_info
*);
778 static struct die_info
*sibling_die (struct die_info
*);
780 static void dump_die (struct die_info
*);
782 static void dump_die_list (struct die_info
*);
784 static void store_in_ref_table (unsigned int, struct die_info
*);
786 static void dwarf2_empty_hash_tables (void);
788 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
790 static struct die_info
*follow_die_ref (unsigned int);
792 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
794 /* memory allocation interface */
796 static void dwarf2_free_tmp_obstack (PTR
);
798 static struct dwarf_block
*dwarf_alloc_block (void);
800 static struct abbrev_info
*dwarf_alloc_abbrev (void);
802 static struct die_info
*dwarf_alloc_die (void);
804 /* Try to locate the sections we need for DWARF 2 debugging
805 information and return true if we have enough to do something. */
808 dwarf2_has_info (bfd
*abfd
)
810 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
811 dwarf_str_offset
= 0;
812 dwarf_frame_offset
= dwarf_eh_frame_offset
= 0;
813 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
814 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
824 /* This function is mapped across the sections and remembers the
825 offset and size of each of the debugging sections we are interested
829 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, PTR ignore_ptr
)
831 if (STREQ (sectp
->name
, INFO_SECTION
))
833 dwarf_info_offset
= sectp
->filepos
;
834 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
836 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
838 dwarf_abbrev_offset
= sectp
->filepos
;
839 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
841 else if (STREQ (sectp
->name
, LINE_SECTION
))
843 dwarf_line_offset
= sectp
->filepos
;
844 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
846 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
848 dwarf_pubnames_offset
= sectp
->filepos
;
849 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
851 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
853 dwarf_aranges_offset
= sectp
->filepos
;
854 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
856 else if (STREQ (sectp
->name
, LOC_SECTION
))
858 dwarf_loc_offset
= sectp
->filepos
;
859 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
861 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
863 dwarf_macinfo_offset
= sectp
->filepos
;
864 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
866 else if (STREQ (sectp
->name
, STR_SECTION
))
868 dwarf_str_offset
= sectp
->filepos
;
869 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
871 else if (STREQ (sectp
->name
, FRAME_SECTION
))
873 dwarf_frame_offset
= sectp
->filepos
;
874 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
876 else if (STREQ (sectp
->name
, EH_FRAME_SECTION
))
878 dwarf_eh_frame_offset
= sectp
->filepos
;
879 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
883 /* Build a partial symbol table. */
886 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
889 /* We definitely need the .debug_info and .debug_abbrev sections */
891 dwarf_info_buffer
= dwarf2_read_section (objfile
,
894 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
897 dwarf_line_buffer
= dwarf2_read_section (objfile
,
901 if (dwarf_str_offset
)
902 dwarf_str_buffer
= dwarf2_read_section (objfile
,
906 dwarf_str_buffer
= NULL
;
909 || (objfile
->global_psymbols
.size
== 0
910 && objfile
->static_psymbols
.size
== 0))
912 init_psymbol_list (objfile
, 1024);
916 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
918 /* Things are significantly easier if we have .debug_aranges and
919 .debug_pubnames sections */
921 dwarf2_build_psymtabs_easy (objfile
, mainline
);
925 /* only test this case for now */
927 /* In this case we have to work a bit harder */
928 dwarf2_build_psymtabs_hard (objfile
, mainline
);
933 /* Build the partial symbol table from the information in the
934 .debug_pubnames and .debug_aranges sections. */
937 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
939 bfd
*abfd
= objfile
->obfd
;
940 char *aranges_buffer
, *pubnames_buffer
;
941 char *aranges_ptr
, *pubnames_ptr
;
942 unsigned int entry_length
, version
, info_offset
, info_size
;
944 pubnames_buffer
= dwarf2_read_section (objfile
,
945 dwarf_pubnames_offset
,
946 dwarf_pubnames_size
);
947 pubnames_ptr
= pubnames_buffer
;
948 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
950 struct comp_unit_head cu_header
;
953 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
955 pubnames_ptr
+= bytes_read
;
956 version
= read_1_byte (abfd
, pubnames_ptr
);
958 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
960 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
964 aranges_buffer
= dwarf2_read_section (objfile
,
965 dwarf_aranges_offset
,
971 /* Read in the comp unit header information from the debug_info at
975 read_comp_unit_head (struct comp_unit_head
*cu_header
,
976 char *info_ptr
, bfd
*abfd
)
980 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
982 info_ptr
+= bytes_read
;
983 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
985 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
987 info_ptr
+= bytes_read
;
988 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
990 signed_addr
= bfd_get_sign_extend_vma (abfd
);
992 internal_error (__FILE__
, __LINE__
,
993 "read_comp_unit_head: dwarf from non elf file");
994 cu_header
->signed_addr_p
= signed_addr
;
998 /* Build the partial symbol table by doing a quick pass through the
999 .debug_info and .debug_abbrev sections. */
1002 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1004 /* Instead of reading this into a big buffer, we should probably use
1005 mmap() on architectures that support it. (FIXME) */
1006 bfd
*abfd
= objfile
->obfd
;
1007 char *info_ptr
, *abbrev_ptr
;
1008 char *beg_of_comp_unit
;
1009 struct partial_die_info comp_unit_die
;
1010 struct partial_symtab
*pst
;
1011 struct cleanup
*back_to
;
1012 CORE_ADDR lowpc
, highpc
;
1014 info_ptr
= dwarf_info_buffer
;
1015 abbrev_ptr
= dwarf_abbrev_buffer
;
1017 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1018 the partial symbol scan, like attribute values.
1020 We could reduce our peak memory consumption during partial symbol
1021 table construction by freeing stuff from this obstack more often
1022 --- say, after processing each compilation unit, or each die ---
1023 but it turns out that this saves almost nothing. For an
1024 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1025 on dwarf2_tmp_obstack. Some investigation showed:
1027 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1028 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1029 all fixed-length values not requiring dynamic allocation.
1031 2) 30% of the attributes used the form DW_FORM_string. For
1032 DW_FORM_string, read_attribute simply hands back a pointer to
1033 the null-terminated string in dwarf_info_buffer, so no dynamic
1034 allocation is needed there either.
1036 3) The remaining 1% of the attributes all used DW_FORM_block1.
1037 75% of those were DW_AT_frame_base location lists for
1038 functions; the rest were DW_AT_location attributes, probably
1039 for the global variables.
1041 Anyway, what this all means is that the memory the dwarf2
1042 reader uses as temporary space reading partial symbols is about
1043 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1045 obstack_init (&dwarf2_tmp_obstack
);
1046 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1048 /* Since the objects we're extracting from dwarf_info_buffer vary in
1049 length, only the individual functions to extract them (like
1050 read_comp_unit_head and read_partial_die) can really know whether
1051 the buffer is large enough to hold another complete object.
1053 At the moment, they don't actually check that. If
1054 dwarf_info_buffer holds just one extra byte after the last
1055 compilation unit's dies, then read_comp_unit_head will happily
1056 read off the end of the buffer. read_partial_die is similarly
1057 casual. Those functions should be fixed.
1059 For this loop condition, simply checking whether there's any data
1060 left at all should be sufficient. */
1061 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1063 struct comp_unit_head cu_header
;
1064 beg_of_comp_unit
= info_ptr
;
1065 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1067 if (cu_header
.version
!= 2)
1069 error ("Dwarf Error: wrong version in compilation unit header.");
1072 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
1074 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
1075 (long) cu_header
.abbrev_offset
,
1076 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1079 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1080 > dwarf_info_buffer
+ dwarf_info_size
)
1082 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
1083 (long) cu_header
.length
,
1084 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1087 /* Read the abbrevs for this compilation unit into a table */
1088 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1089 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1091 /* Read the compilation unit die */
1092 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1095 /* Set the language we're debugging */
1096 set_cu_language (comp_unit_die
.language
);
1098 /* Allocate a new partial symbol table structure */
1099 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1100 comp_unit_die
.name
? comp_unit_die
.name
: "",
1101 comp_unit_die
.lowpc
,
1102 objfile
->global_psymbols
.next
,
1103 objfile
->static_psymbols
.next
);
1105 pst
->read_symtab_private
= (char *)
1106 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1107 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1108 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1109 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1110 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1111 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1112 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1113 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1114 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1115 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1117 /* Store the function that reads in the rest of the symbol table */
1118 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1120 /* Check if comp unit has_children.
1121 If so, read the rest of the partial symbols from this comp unit.
1122 If not, there's no more debug_info for this comp unit. */
1123 if (comp_unit_die
.has_children
)
1125 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1128 /* If the compilation unit didn't have an explicit address range,
1129 then use the information extracted from its child dies. */
1130 if (! comp_unit_die
.has_pc_info
)
1132 comp_unit_die
.lowpc
= lowpc
;
1133 comp_unit_die
.highpc
= highpc
;
1136 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1137 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1139 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1140 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1141 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1142 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1143 sort_pst_symbols (pst
);
1145 /* If there is already a psymtab or symtab for a file of this
1146 name, remove it. (If there is a symtab, more drastic things
1147 also happen.) This happens in VxWorks. */
1148 free_named_symtabs (pst
->filename
);
1150 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1151 + cu_header
.initial_length_size
;
1153 do_cleanups (back_to
);
1156 /* Read in all interesting dies to the end of the compilation unit. */
1159 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1160 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1161 const struct comp_unit_head
*cu_header
)
1163 bfd
*abfd
= objfile
->obfd
;
1164 struct partial_die_info pdi
;
1166 /* This function is called after we've read in the comp_unit_die in
1167 order to read its children. We start the nesting level at 1 since
1168 we have pushed 1 level down in order to read the comp unit's children.
1169 The comp unit itself is at level 0, so we stop reading when we pop
1170 back to that level. */
1172 int nesting_level
= 1;
1174 *lowpc
= ((CORE_ADDR
) -1);
1175 *highpc
= ((CORE_ADDR
) 0);
1177 while (nesting_level
)
1179 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1185 case DW_TAG_subprogram
:
1186 if (pdi
.has_pc_info
)
1188 if (pdi
.lowpc
< *lowpc
)
1192 if (pdi
.highpc
> *highpc
)
1194 *highpc
= pdi
.highpc
;
1196 if ((pdi
.is_external
|| nesting_level
== 1)
1197 && !pdi
.is_declaration
)
1199 add_partial_symbol (&pdi
, objfile
, cu_header
);
1203 case DW_TAG_variable
:
1204 case DW_TAG_typedef
:
1205 case DW_TAG_class_type
:
1206 case DW_TAG_structure_type
:
1207 case DW_TAG_union_type
:
1208 case DW_TAG_enumeration_type
:
1209 if ((pdi
.is_external
|| nesting_level
== 1)
1210 && !pdi
.is_declaration
)
1212 add_partial_symbol (&pdi
, objfile
, cu_header
);
1215 case DW_TAG_enumerator
:
1216 /* File scope enumerators are added to the partial symbol
1218 if (nesting_level
== 2)
1219 add_partial_symbol (&pdi
, objfile
, cu_header
);
1221 case DW_TAG_base_type
:
1222 /* File scope base type definitions are added to the partial
1224 if (nesting_level
== 1)
1225 add_partial_symbol (&pdi
, objfile
, cu_header
);
1232 /* If the die has a sibling, skip to the sibling.
1233 Do not skip enumeration types, we want to record their
1235 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1237 info_ptr
= pdi
.sibling
;
1239 else if (pdi
.has_children
)
1241 /* Die has children, but the optional DW_AT_sibling attribute
1252 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1253 from `maint check'. */
1254 if (*lowpc
== ((CORE_ADDR
) -1))
1260 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1261 const struct comp_unit_head
*cu_header
)
1267 case DW_TAG_subprogram
:
1268 if (pdi
->is_external
)
1270 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1271 mst_text, objfile); */
1272 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1273 VAR_NAMESPACE
, LOC_BLOCK
,
1274 &objfile
->global_psymbols
,
1275 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1279 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1280 mst_file_text, objfile); */
1281 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1282 VAR_NAMESPACE
, LOC_BLOCK
,
1283 &objfile
->static_psymbols
,
1284 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1287 case DW_TAG_variable
:
1288 if (pdi
->is_external
)
1291 Don't enter into the minimal symbol tables as there is
1292 a minimal symbol table entry from the ELF symbols already.
1293 Enter into partial symbol table if it has a location
1294 descriptor or a type.
1295 If the location descriptor is missing, new_symbol will create
1296 a LOC_UNRESOLVED symbol, the address of the variable will then
1297 be determined from the minimal symbol table whenever the variable
1299 The address for the partial symbol table entry is not
1300 used by GDB, but it comes in handy for debugging partial symbol
1304 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1305 if (pdi
->locdesc
|| pdi
->has_type
)
1306 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1307 VAR_NAMESPACE
, LOC_STATIC
,
1308 &objfile
->global_psymbols
,
1309 0, addr
+ baseaddr
, cu_language
, objfile
);
1313 /* Static Variable. Skip symbols without location descriptors. */
1314 if (pdi
->locdesc
== NULL
)
1316 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1317 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1318 mst_file_data, objfile); */
1319 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1320 VAR_NAMESPACE
, LOC_STATIC
,
1321 &objfile
->static_psymbols
,
1322 0, addr
+ baseaddr
, cu_language
, objfile
);
1325 case DW_TAG_typedef
:
1326 case DW_TAG_base_type
:
1327 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1328 VAR_NAMESPACE
, LOC_TYPEDEF
,
1329 &objfile
->static_psymbols
,
1330 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1332 case DW_TAG_class_type
:
1333 case DW_TAG_structure_type
:
1334 case DW_TAG_union_type
:
1335 case DW_TAG_enumeration_type
:
1336 /* Skip aggregate types without children, these are external
1338 if (pdi
->has_children
== 0)
1340 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1341 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1342 &objfile
->static_psymbols
,
1343 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1345 if (cu_language
== language_cplus
)
1347 /* For C++, these implicitly act as typedefs as well. */
1348 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1349 VAR_NAMESPACE
, LOC_TYPEDEF
,
1350 &objfile
->static_psymbols
,
1351 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1354 case DW_TAG_enumerator
:
1355 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1356 VAR_NAMESPACE
, LOC_CONST
,
1357 &objfile
->static_psymbols
,
1358 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1365 /* Expand this partial symbol table into a full symbol table. */
1368 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1370 /* FIXME: This is barely more than a stub. */
1375 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1381 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1382 gdb_flush (gdb_stdout
);
1385 psymtab_to_symtab_1 (pst
);
1387 /* Finish up the debug error message. */
1389 printf_filtered ("done.\n");
1395 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1397 struct objfile
*objfile
= pst
->objfile
;
1398 bfd
*abfd
= objfile
->obfd
;
1399 struct comp_unit_head cu_header
;
1400 struct die_info
*dies
;
1401 unsigned long offset
;
1402 CORE_ADDR lowpc
, highpc
;
1403 struct die_info
*child_die
;
1405 struct symtab
*symtab
;
1406 struct cleanup
*back_to
;
1408 /* Set local variables from the partial symbol table info. */
1409 offset
= DWARF_INFO_OFFSET (pst
);
1410 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1411 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1412 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1413 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1414 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1415 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1416 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1417 cu_header_offset
= offset
;
1418 info_ptr
= dwarf_info_buffer
+ offset
;
1420 obstack_init (&dwarf2_tmp_obstack
);
1421 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1424 make_cleanup (really_free_pendings
, NULL
);
1426 /* read in the comp_unit header */
1427 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1429 /* Read the abbrevs for this compilation unit */
1430 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1431 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1433 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1435 make_cleanup_free_die_list (dies
);
1437 /* Do line number decoding in read_file_scope () */
1438 process_die (dies
, objfile
, &cu_header
);
1440 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1442 /* Some compilers don't define a DW_AT_high_pc attribute for
1443 the compilation unit. If the DW_AT_high_pc is missing,
1444 synthesize it, by scanning the DIE's below the compilation unit. */
1446 if (dies
->has_children
)
1448 child_die
= dies
->next
;
1449 while (child_die
&& child_die
->tag
)
1451 if (child_die
->tag
== DW_TAG_subprogram
)
1453 CORE_ADDR low
, high
;
1455 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1457 highpc
= max (highpc
, high
);
1460 child_die
= sibling_die (child_die
);
1464 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1466 /* Set symtab language to language from DW_AT_language.
1467 If the compilation is from a C file generated by language preprocessors,
1468 do not set the language if it was already deduced by start_subfile. */
1470 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1472 symtab
->language
= cu_language
;
1474 pst
->symtab
= symtab
;
1476 sort_symtab_syms (pst
->symtab
);
1478 do_cleanups (back_to
);
1481 /* Process a die and its children. */
1484 process_die (struct die_info
*die
, struct objfile
*objfile
,
1485 const struct comp_unit_head
*cu_header
)
1489 case DW_TAG_padding
:
1491 case DW_TAG_compile_unit
:
1492 read_file_scope (die
, objfile
, cu_header
);
1494 case DW_TAG_subprogram
:
1495 read_subroutine_type (die
, objfile
, cu_header
);
1496 read_func_scope (die
, objfile
, cu_header
);
1498 case DW_TAG_inlined_subroutine
:
1499 /* FIXME: These are ignored for now.
1500 They could be used to set breakpoints on all inlined instances
1501 of a function and make GDB `next' properly over inlined functions. */
1503 case DW_TAG_lexical_block
:
1504 read_lexical_block_scope (die
, objfile
, cu_header
);
1506 case DW_TAG_class_type
:
1507 case DW_TAG_structure_type
:
1508 case DW_TAG_union_type
:
1509 read_structure_scope (die
, objfile
, cu_header
);
1511 case DW_TAG_enumeration_type
:
1512 read_enumeration (die
, objfile
, cu_header
);
1514 case DW_TAG_subroutine_type
:
1515 read_subroutine_type (die
, objfile
, cu_header
);
1517 case DW_TAG_array_type
:
1518 read_array_type (die
, objfile
, cu_header
);
1520 case DW_TAG_pointer_type
:
1521 read_tag_pointer_type (die
, objfile
, cu_header
);
1523 case DW_TAG_ptr_to_member_type
:
1524 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1526 case DW_TAG_reference_type
:
1527 read_tag_reference_type (die
, objfile
, cu_header
);
1529 case DW_TAG_string_type
:
1530 read_tag_string_type (die
, objfile
);
1532 case DW_TAG_base_type
:
1533 read_base_type (die
, objfile
);
1534 if (dwarf_attr (die
, DW_AT_name
))
1536 /* Add a typedef symbol for the base type definition. */
1537 new_symbol (die
, die
->type
, objfile
, cu_header
);
1540 case DW_TAG_common_block
:
1541 read_common_block (die
, objfile
, cu_header
);
1543 case DW_TAG_common_inclusion
:
1546 new_symbol (die
, NULL
, objfile
, cu_header
);
1552 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1553 const struct comp_unit_head
*cu_header
)
1555 unsigned int line_offset
= 0;
1556 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1557 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1558 struct attribute
*attr
;
1559 char *name
= "<unknown>";
1560 char *comp_dir
= NULL
;
1561 struct die_info
*child_die
;
1562 bfd
*abfd
= objfile
->obfd
;
1564 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1566 if (die
->has_children
)
1568 child_die
= die
->next
;
1569 while (child_die
&& child_die
->tag
)
1571 if (child_die
->tag
== DW_TAG_subprogram
)
1573 CORE_ADDR low
, high
;
1575 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1577 lowpc
= min (lowpc
, low
);
1578 highpc
= max (highpc
, high
);
1581 child_die
= sibling_die (child_die
);
1586 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1587 from finish_block. */
1588 if (lowpc
== ((CORE_ADDR
) -1))
1593 attr
= dwarf_attr (die
, DW_AT_name
);
1596 name
= DW_STRING (attr
);
1598 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1601 comp_dir
= DW_STRING (attr
);
1604 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1605 directory, get rid of it. */
1606 char *cp
= strchr (comp_dir
, ':');
1608 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1613 if (objfile
->ei
.entry_point
>= lowpc
&&
1614 objfile
->ei
.entry_point
< highpc
)
1616 objfile
->ei
.entry_file_lowpc
= lowpc
;
1617 objfile
->ei
.entry_file_highpc
= highpc
;
1620 attr
= dwarf_attr (die
, DW_AT_language
);
1623 set_cu_language (DW_UNSND (attr
));
1626 /* We assume that we're processing GCC output. */
1627 processing_gcc_compilation
= 2;
1629 /* FIXME:Do something here. */
1630 if (dip
->at_producer
!= NULL
)
1632 handle_producer (dip
->at_producer
);
1636 /* The compilation unit may be in a different language or objfile,
1637 zero out all remembered fundamental types. */
1638 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1640 start_symtab (name
, comp_dir
, lowpc
);
1641 record_debugformat ("DWARF 2");
1643 /* Decode line number information if present. */
1644 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1647 line_offset
= DW_UNSND (attr
);
1648 dwarf_decode_lines (line_offset
, comp_dir
, abfd
, cu_header
);
1651 /* Process all dies in compilation unit. */
1652 if (die
->has_children
)
1654 child_die
= die
->next
;
1655 while (child_die
&& child_die
->tag
)
1657 process_die (child_die
, objfile
, cu_header
);
1658 child_die
= sibling_die (child_die
);
1664 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
1665 const struct comp_unit_head
*cu_header
)
1667 register struct context_stack
*new;
1670 struct die_info
*child_die
;
1671 struct attribute
*attr
;
1674 name
= dwarf2_linkage_name (die
);
1676 /* Ignore functions with missing or empty names and functions with
1677 missing or invalid low and high pc attributes. */
1678 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1684 if (objfile
->ei
.entry_point
>= lowpc
&&
1685 objfile
->ei
.entry_point
< highpc
)
1687 objfile
->ei
.entry_func_lowpc
= lowpc
;
1688 objfile
->ei
.entry_func_highpc
= highpc
;
1691 /* Decode DW_AT_frame_base location descriptor if present, keep result
1692 for DW_OP_fbreg operands in decode_locdesc. */
1693 frame_base_reg
= -1;
1694 frame_base_offset
= 0;
1695 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1698 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
1700 complain (&dwarf2_unsupported_at_frame_base
, name
);
1702 frame_base_reg
= addr
;
1705 frame_base_reg
= basereg
;
1706 frame_base_offset
= addr
;
1709 complain (&dwarf2_unsupported_at_frame_base
, name
);
1712 new = push_context (0, lowpc
);
1713 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
1714 list_in_scope
= &local_symbols
;
1716 if (die
->has_children
)
1718 child_die
= die
->next
;
1719 while (child_die
&& child_die
->tag
)
1721 process_die (child_die
, objfile
, cu_header
);
1722 child_die
= sibling_die (child_die
);
1726 new = pop_context ();
1727 /* Make a block for the local symbols within. */
1728 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1729 lowpc
, highpc
, objfile
);
1730 list_in_scope
= &file_symbols
;
1733 /* Process all the DIES contained within a lexical block scope. Start
1734 a new scope, process the dies, and then close the scope. */
1737 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
1738 const struct comp_unit_head
*cu_header
)
1740 register struct context_stack
*new;
1741 CORE_ADDR lowpc
, highpc
;
1742 struct die_info
*child_die
;
1744 /* Ignore blocks with missing or invalid low and high pc attributes. */
1745 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1750 push_context (0, lowpc
);
1751 if (die
->has_children
)
1753 child_die
= die
->next
;
1754 while (child_die
&& child_die
->tag
)
1756 process_die (child_die
, objfile
, cu_header
);
1757 child_die
= sibling_die (child_die
);
1760 new = pop_context ();
1762 if (local_symbols
!= NULL
)
1764 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1767 local_symbols
= new->locals
;
1770 /* Get low and high pc attributes from a die.
1771 Return 1 if the attributes are present and valid, otherwise, return 0. */
1774 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1775 struct objfile
*objfile
)
1777 struct attribute
*attr
;
1781 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1783 low
= DW_ADDR (attr
);
1786 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1788 high
= DW_ADDR (attr
);
1795 /* When using the GNU linker, .gnu.linkonce. sections are used to
1796 eliminate duplicate copies of functions and vtables and such.
1797 The linker will arbitrarily choose one and discard the others.
1798 The AT_*_pc values for such functions refer to local labels in
1799 these sections. If the section from that file was discarded, the
1800 labels are not in the output, so the relocs get a value of 0.
1801 If this is a discarded function, mark the pc bounds as invalid,
1802 so that GDB will ignore it. */
1803 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1811 /* Add an aggregate field to the field list. */
1814 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
1815 struct objfile
*objfile
,
1816 const struct comp_unit_head
*cu_header
)
1818 struct nextfield
*new_field
;
1819 struct attribute
*attr
;
1821 char *fieldname
= "";
1823 /* Allocate a new field list entry and link it in. */
1824 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1825 make_cleanup (xfree
, new_field
);
1826 memset (new_field
, 0, sizeof (struct nextfield
));
1827 new_field
->next
= fip
->fields
;
1828 fip
->fields
= new_field
;
1831 /* Handle accessibility and virtuality of field.
1832 The default accessibility for members is public, the default
1833 accessibility for inheritance is private. */
1834 if (die
->tag
!= DW_TAG_inheritance
)
1835 new_field
->accessibility
= DW_ACCESS_public
;
1837 new_field
->accessibility
= DW_ACCESS_private
;
1838 new_field
->virtuality
= DW_VIRTUALITY_none
;
1840 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1842 new_field
->accessibility
= DW_UNSND (attr
);
1843 if (new_field
->accessibility
!= DW_ACCESS_public
)
1844 fip
->non_public_fields
= 1;
1845 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1847 new_field
->virtuality
= DW_UNSND (attr
);
1849 fp
= &new_field
->field
;
1850 if (die
->tag
== DW_TAG_member
)
1852 /* Get type of field. */
1853 fp
->type
= die_type (die
, objfile
, cu_header
);
1855 /* Get bit size of field (zero if none). */
1856 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1859 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1863 FIELD_BITSIZE (*fp
) = 0;
1866 /* Get bit offset of field. */
1867 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1870 FIELD_BITPOS (*fp
) =
1871 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
1874 FIELD_BITPOS (*fp
) = 0;
1875 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1878 if (BITS_BIG_ENDIAN
)
1880 /* For big endian bits, the DW_AT_bit_offset gives the
1881 additional bit offset from the MSB of the containing
1882 anonymous object to the MSB of the field. We don't
1883 have to do anything special since we don't need to
1884 know the size of the anonymous object. */
1885 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1889 /* For little endian bits, compute the bit offset to the
1890 MSB of the anonymous object, subtract off the number of
1891 bits from the MSB of the field to the MSB of the
1892 object, and then subtract off the number of bits of
1893 the field itself. The result is the bit offset of
1894 the LSB of the field. */
1896 int bit_offset
= DW_UNSND (attr
);
1898 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1901 /* The size of the anonymous object containing
1902 the bit field is explicit, so use the
1903 indicated size (in bytes). */
1904 anonymous_size
= DW_UNSND (attr
);
1908 /* The size of the anonymous object containing
1909 the bit field must be inferred from the type
1910 attribute of the data member containing the
1912 anonymous_size
= TYPE_LENGTH (fp
->type
);
1914 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1915 - bit_offset
- FIELD_BITSIZE (*fp
);
1919 /* Get name of field. */
1920 attr
= dwarf_attr (die
, DW_AT_name
);
1921 if (attr
&& DW_STRING (attr
))
1922 fieldname
= DW_STRING (attr
);
1923 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1924 &objfile
->type_obstack
);
1926 /* Change accessibility for artificial fields (e.g. virtual table
1927 pointer or virtual base class pointer) to private. */
1928 if (dwarf_attr (die
, DW_AT_artificial
))
1930 new_field
->accessibility
= DW_ACCESS_private
;
1931 fip
->non_public_fields
= 1;
1934 else if (die
->tag
== DW_TAG_variable
)
1938 /* C++ static member.
1939 Get name of field. */
1940 attr
= dwarf_attr (die
, DW_AT_name
);
1941 if (attr
&& DW_STRING (attr
))
1942 fieldname
= DW_STRING (attr
);
1946 /* Get physical name. */
1947 physname
= dwarf2_linkage_name (die
);
1949 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1950 &objfile
->type_obstack
));
1951 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1952 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1953 &objfile
->type_obstack
);
1955 else if (die
->tag
== DW_TAG_inheritance
)
1957 /* C++ base class field. */
1958 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1960 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
1962 FIELD_BITSIZE (*fp
) = 0;
1963 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1964 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1965 fip
->nbaseclasses
++;
1969 /* Create the vector of fields, and attach it to the type. */
1972 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
1973 struct objfile
*objfile
)
1975 int nfields
= fip
->nfields
;
1977 /* Record the field count, allocate space for the array of fields,
1978 and create blank accessibility bitfields if necessary. */
1979 TYPE_NFIELDS (type
) = nfields
;
1980 TYPE_FIELDS (type
) = (struct field
*)
1981 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1982 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1984 if (fip
->non_public_fields
)
1986 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1988 TYPE_FIELD_PRIVATE_BITS (type
) =
1989 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1990 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1992 TYPE_FIELD_PROTECTED_BITS (type
) =
1993 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1994 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1996 TYPE_FIELD_IGNORE_BITS (type
) =
1997 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1998 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2001 /* If the type has baseclasses, allocate and clear a bit vector for
2002 TYPE_FIELD_VIRTUAL_BITS. */
2003 if (fip
->nbaseclasses
)
2005 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2008 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2009 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2010 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2011 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2012 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2015 /* Copy the saved-up fields into the field vector. Start from the head
2016 of the list, adding to the tail of the field array, so that they end
2017 up in the same order in the array in which they were added to the list. */
2018 while (nfields
-- > 0)
2020 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2021 switch (fip
->fields
->accessibility
)
2023 case DW_ACCESS_private
:
2024 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2027 case DW_ACCESS_protected
:
2028 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2031 case DW_ACCESS_public
:
2035 /* Unknown accessibility. Complain and treat it as public. */
2037 complain (&dwarf2_unsupported_accessibility
,
2038 fip
->fields
->accessibility
);
2042 if (nfields
< fip
->nbaseclasses
)
2044 switch (fip
->fields
->virtuality
)
2046 case DW_VIRTUALITY_virtual
:
2047 case DW_VIRTUALITY_pure_virtual
:
2048 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2052 fip
->fields
= fip
->fields
->next
;
2056 /* Add a member function to the proper fieldlist. */
2059 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2060 struct type
*type
, struct objfile
*objfile
,
2061 const struct comp_unit_head
*cu_header
)
2063 struct attribute
*attr
;
2064 struct fnfieldlist
*flp
;
2066 struct fn_field
*fnp
;
2069 struct nextfnfield
*new_fnfield
;
2071 /* Get name of member function. */
2072 attr
= dwarf_attr (die
, DW_AT_name
);
2073 if (attr
&& DW_STRING (attr
))
2074 fieldname
= DW_STRING (attr
);
2078 /* Get the mangled name. */
2079 physname
= dwarf2_linkage_name (die
);
2081 /* Look up member function name in fieldlist. */
2082 for (i
= 0; i
< fip
->nfnfields
; i
++)
2084 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2088 /* Create new list element if necessary. */
2089 if (i
< fip
->nfnfields
)
2090 flp
= &fip
->fnfieldlists
[i
];
2093 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2095 fip
->fnfieldlists
= (struct fnfieldlist
*)
2096 xrealloc (fip
->fnfieldlists
,
2097 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2098 * sizeof (struct fnfieldlist
));
2099 if (fip
->nfnfields
== 0)
2100 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2102 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2103 flp
->name
= fieldname
;
2109 /* Create a new member function field and chain it to the field list
2111 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2112 make_cleanup (xfree
, new_fnfield
);
2113 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2114 new_fnfield
->next
= flp
->head
;
2115 flp
->head
= new_fnfield
;
2118 /* Fill in the member function field info. */
2119 fnp
= &new_fnfield
->fnfield
;
2120 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2121 &objfile
->type_obstack
);
2122 fnp
->type
= alloc_type (objfile
);
2123 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2125 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2126 struct type
**arg_types
;
2127 int nparams
= TYPE_NFIELDS (die
->type
);
2130 /* Copy argument types from the subroutine type. */
2131 arg_types
= (struct type
**)
2132 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2133 for (iparams
= 0; iparams
< nparams
; iparams
++)
2134 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2136 /* Set last entry in argument type vector. */
2137 if (TYPE_VARARGS (die
->type
))
2138 arg_types
[nparams
] = NULL
;
2140 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2142 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2144 /* Handle static member functions.
2145 Dwarf2 has no clean way to discern C++ static and non-static
2146 member functions. G++ helps GDB by marking the first
2147 parameter for non-static member functions (which is the
2148 this pointer) as artificial. We obtain this information
2149 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2150 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2151 fnp
->voffset
= VOFFSET_STATIC
;
2154 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2156 /* Get fcontext from DW_AT_containing_type if present. */
2157 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2158 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2160 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2161 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2163 /* Get accessibility. */
2164 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2167 switch (DW_UNSND (attr
))
2169 case DW_ACCESS_private
:
2170 fnp
->is_private
= 1;
2172 case DW_ACCESS_protected
:
2173 fnp
->is_protected
= 1;
2178 /* Get index in virtual function table if it is a virtual member function. */
2179 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2181 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2184 /* Create the vector of member function fields, and attach it to the type. */
2187 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2188 struct objfile
*objfile
)
2190 struct fnfieldlist
*flp
;
2191 int total_length
= 0;
2194 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2195 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2196 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2198 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2200 struct nextfnfield
*nfp
= flp
->head
;
2201 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2204 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2205 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2206 fn_flp
->fn_fields
= (struct fn_field
*)
2207 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2208 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2209 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2211 total_length
+= flp
->length
;
2214 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2215 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2218 /* Called when we find the DIE that starts a structure or union scope
2219 (definition) to process all dies that define the members of the
2222 NOTE: we need to call struct_type regardless of whether or not the
2223 DIE has an at_name attribute, since it might be an anonymous
2224 structure or union. This gets the type entered into our set of
2227 However, if the structure is incomplete (an opaque struct/union)
2228 then suppress creating a symbol table entry for it since gdb only
2229 wants to find the one with the complete definition. Note that if
2230 it is complete, we just call new_symbol, which does it's own
2231 checking about whether the struct/union is anonymous or not (and
2232 suppresses creating a symbol table entry itself). */
2235 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2236 const struct comp_unit_head
*cu_header
)
2239 struct attribute
*attr
;
2241 type
= alloc_type (objfile
);
2243 INIT_CPLUS_SPECIFIC (type
);
2244 attr
= dwarf_attr (die
, DW_AT_name
);
2245 if (attr
&& DW_STRING (attr
))
2247 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2248 strlen (DW_STRING (attr
)),
2249 &objfile
->type_obstack
);
2252 if (die
->tag
== DW_TAG_structure_type
)
2254 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2256 else if (die
->tag
== DW_TAG_union_type
)
2258 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2262 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2264 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2267 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2270 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2274 TYPE_LENGTH (type
) = 0;
2277 /* We need to add the type field to the die immediately so we don't
2278 infinitely recurse when dealing with pointers to the structure
2279 type within the structure itself. */
2282 if (die
->has_children
&& ! die_is_declaration (die
))
2284 struct field_info fi
;
2285 struct die_info
*child_die
;
2286 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2288 memset (&fi
, 0, sizeof (struct field_info
));
2290 child_die
= die
->next
;
2292 while (child_die
&& child_die
->tag
)
2294 if (child_die
->tag
== DW_TAG_member
)
2296 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2298 else if (child_die
->tag
== DW_TAG_variable
)
2300 /* C++ static member. */
2301 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2303 else if (child_die
->tag
== DW_TAG_subprogram
)
2305 /* C++ member function. */
2306 process_die (child_die
, objfile
, cu_header
);
2307 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2309 else if (child_die
->tag
== DW_TAG_inheritance
)
2311 /* C++ base class field. */
2312 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2316 process_die (child_die
, objfile
, cu_header
);
2318 child_die
= sibling_die (child_die
);
2321 /* Attach fields and member functions to the type. */
2323 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2326 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2328 /* Get the type which refers to the base class (possibly this
2329 class itself) which contains the vtable pointer for the current
2330 class from the DW_AT_containing_type attribute. */
2332 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2334 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2336 TYPE_VPTR_BASETYPE (type
) = t
;
2339 static const char vptr_name
[] =
2340 {'_', 'v', 'p', 't', 'r', '\0'};
2343 /* Our own class provides vtbl ptr. */
2344 for (i
= TYPE_NFIELDS (t
) - 1;
2345 i
>= TYPE_N_BASECLASSES (t
);
2348 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2350 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2351 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2353 TYPE_VPTR_FIELDNO (type
) = i
;
2358 /* Complain if virtual function table field not found. */
2359 if (i
< TYPE_N_BASECLASSES (t
))
2360 complain (&dwarf2_vtbl_not_found_complaint
,
2361 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2365 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2370 new_symbol (die
, type
, objfile
, cu_header
);
2372 do_cleanups (back_to
);
2376 /* No children, must be stub. */
2377 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2380 finish_cv_type (die
->type
);
2383 /* Given a pointer to a die which begins an enumeration, process all
2384 the dies that define the members of the enumeration.
2386 This will be much nicer in draft 6 of the DWARF spec when our
2387 members will be dies instead squished into the DW_AT_element_list
2390 NOTE: We reverse the order of the element list. */
2393 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2394 const struct comp_unit_head
*cu_header
)
2396 struct die_info
*child_die
;
2398 struct field
*fields
;
2399 struct attribute
*attr
;
2402 int unsigned_enum
= 1;
2404 type
= alloc_type (objfile
);
2406 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2407 attr
= dwarf_attr (die
, DW_AT_name
);
2408 if (attr
&& DW_STRING (attr
))
2410 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2411 strlen (DW_STRING (attr
)),
2412 &objfile
->type_obstack
);
2415 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2418 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2422 TYPE_LENGTH (type
) = 0;
2427 if (die
->has_children
)
2429 child_die
= die
->next
;
2430 while (child_die
&& child_die
->tag
)
2432 if (child_die
->tag
!= DW_TAG_enumerator
)
2434 process_die (child_die
, objfile
, cu_header
);
2438 attr
= dwarf_attr (child_die
, DW_AT_name
);
2441 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2442 if (SYMBOL_VALUE (sym
) < 0)
2445 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2447 fields
= (struct field
*)
2449 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2450 * sizeof (struct field
));
2453 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2454 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2455 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2456 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2462 child_die
= sibling_die (child_die
);
2467 TYPE_NFIELDS (type
) = num_fields
;
2468 TYPE_FIELDS (type
) = (struct field
*)
2469 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2470 memcpy (TYPE_FIELDS (type
), fields
,
2471 sizeof (struct field
) * num_fields
);
2475 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2478 new_symbol (die
, type
, objfile
, cu_header
);
2481 /* Extract all information from a DW_TAG_array_type DIE and put it in
2482 the DIE's type field. For now, this only handles one dimensional
2486 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
2487 const struct comp_unit_head
*cu_header
)
2489 struct die_info
*child_die
;
2490 struct type
*type
= NULL
;
2491 struct type
*element_type
, *range_type
, *index_type
;
2492 struct type
**range_types
= NULL
;
2493 struct attribute
*attr
;
2495 struct cleanup
*back_to
;
2497 /* Return if we've already decoded this type. */
2503 element_type
= die_type (die
, objfile
, cu_header
);
2505 /* Irix 6.2 native cc creates array types without children for
2506 arrays with unspecified length. */
2507 if (die
->has_children
== 0)
2509 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2510 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2511 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2515 back_to
= make_cleanup (null_cleanup
, NULL
);
2516 child_die
= die
->next
;
2517 while (child_die
&& child_die
->tag
)
2519 if (child_die
->tag
== DW_TAG_subrange_type
)
2521 unsigned int low
, high
;
2523 /* Default bounds to an array with unspecified length. */
2526 if (cu_language
== language_fortran
)
2528 /* FORTRAN implies a lower bound of 1, if not given. */
2532 index_type
= die_type (child_die
, objfile
, cu_header
);
2533 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2536 if (attr
->form
== DW_FORM_sdata
)
2538 low
= DW_SND (attr
);
2540 else if (attr
->form
== DW_FORM_udata
2541 || attr
->form
== DW_FORM_data1
2542 || attr
->form
== DW_FORM_data2
2543 || attr
->form
== DW_FORM_data4
)
2545 low
= DW_UNSND (attr
);
2549 complain (&dwarf2_non_const_array_bound_ignored
,
2550 dwarf_form_name (attr
->form
));
2552 die
->type
= lookup_pointer_type (element_type
);
2559 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2562 if (attr
->form
== DW_FORM_sdata
)
2564 high
= DW_SND (attr
);
2566 else if (attr
->form
== DW_FORM_udata
2567 || attr
->form
== DW_FORM_data1
2568 || attr
->form
== DW_FORM_data2
2569 || attr
->form
== DW_FORM_data4
)
2571 high
= DW_UNSND (attr
);
2573 else if (attr
->form
== DW_FORM_block1
)
2575 /* GCC encodes arrays with unspecified or dynamic length
2576 with a DW_FORM_block1 attribute.
2577 FIXME: GDB does not yet know how to handle dynamic
2578 arrays properly, treat them as arrays with unspecified
2584 complain (&dwarf2_non_const_array_bound_ignored
,
2585 dwarf_form_name (attr
->form
));
2587 die
->type
= lookup_pointer_type (element_type
);
2595 /* Create a range type and save it for array type creation. */
2596 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2598 range_types
= (struct type
**)
2599 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2600 * sizeof (struct type
*));
2602 make_cleanup (free_current_contents
, &range_types
);
2604 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2606 child_die
= sibling_die (child_die
);
2609 /* Dwarf2 dimensions are output from left to right, create the
2610 necessary array types in backwards order. */
2611 type
= element_type
;
2613 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2615 do_cleanups (back_to
);
2617 /* Install the type in the die. */
2621 /* First cut: install each common block member as a global variable. */
2624 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
2625 const struct comp_unit_head
*cu_header
)
2627 struct die_info
*child_die
;
2628 struct attribute
*attr
;
2630 CORE_ADDR base
= (CORE_ADDR
) 0;
2632 attr
= dwarf_attr (die
, DW_AT_location
);
2635 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2637 if (die
->has_children
)
2639 child_die
= die
->next
;
2640 while (child_die
&& child_die
->tag
)
2642 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
2643 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2646 SYMBOL_VALUE_ADDRESS (sym
) =
2647 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2648 add_symbol_to_list (sym
, &global_symbols
);
2650 child_die
= sibling_die (child_die
);
2655 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2656 the user defined type vector. */
2659 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
2660 const struct comp_unit_head
*cu_header
)
2663 struct attribute
*attr
;
2670 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
2671 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2674 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2678 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2683 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2684 the user defined type vector. */
2687 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
2688 const struct comp_unit_head
*cu_header
)
2691 struct type
*to_type
;
2692 struct type
*domain
;
2699 type
= alloc_type (objfile
);
2700 to_type
= die_type (die
, objfile
, cu_header
);
2701 domain
= die_containing_type (die
, objfile
, cu_header
);
2702 smash_to_member_type (type
, domain
, to_type
);
2707 /* Extract all information from a DW_TAG_reference_type DIE and add to
2708 the user defined type vector. */
2711 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
2712 const struct comp_unit_head
*cu_header
)
2715 struct attribute
*attr
;
2722 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
2723 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2726 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2730 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2736 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
2737 const struct comp_unit_head
*cu_header
)
2739 struct type
*base_type
;
2746 base_type
= die_type (die
, objfile
, cu_header
);
2747 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
2751 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
2752 const struct comp_unit_head
*cu_header
)
2754 struct type
*base_type
;
2761 base_type
= die_type (die
, objfile
, cu_header
);
2762 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
2765 /* Extract all information from a DW_TAG_string_type DIE and add to
2766 the user defined type vector. It isn't really a user defined type,
2767 but it behaves like one, with other DIE's using an AT_user_def_type
2768 attribute to reference it. */
2771 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
2773 struct type
*type
, *range_type
, *index_type
, *char_type
;
2774 struct attribute
*attr
;
2775 unsigned int length
;
2782 attr
= dwarf_attr (die
, DW_AT_string_length
);
2785 length
= DW_UNSND (attr
);
2789 /* check for the DW_AT_byte_size attribute */
2790 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2793 length
= DW_UNSND (attr
);
2800 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2801 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2802 if (cu_language
== language_fortran
)
2804 /* Need to create a unique string type for bounds
2806 type
= create_string_type (0, range_type
);
2810 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2811 type
= create_string_type (char_type
, range_type
);
2816 /* Handle DIES due to C code like:
2820 int (*funcp)(int a, long l);
2824 ('funcp' generates a DW_TAG_subroutine_type DIE)
2828 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
2829 const struct comp_unit_head
*cu_header
)
2831 struct type
*type
; /* Type that this function returns */
2832 struct type
*ftype
; /* Function that returns above type */
2833 struct attribute
*attr
;
2835 /* Decode the type that this subroutine returns */
2840 type
= die_type (die
, objfile
, cu_header
);
2841 ftype
= lookup_function_type (type
);
2843 /* All functions in C++ have prototypes. */
2844 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2845 if ((attr
&& (DW_UNSND (attr
) != 0))
2846 || cu_language
== language_cplus
)
2847 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2849 if (die
->has_children
)
2851 struct die_info
*child_die
;
2855 /* Count the number of parameters.
2856 FIXME: GDB currently ignores vararg functions, but knows about
2857 vararg member functions. */
2858 child_die
= die
->next
;
2859 while (child_die
&& child_die
->tag
)
2861 if (child_die
->tag
== DW_TAG_formal_parameter
)
2863 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2864 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2865 child_die
= sibling_die (child_die
);
2868 /* Allocate storage for parameters and fill them in. */
2869 TYPE_NFIELDS (ftype
) = nparams
;
2870 TYPE_FIELDS (ftype
) = (struct field
*)
2871 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2873 child_die
= die
->next
;
2874 while (child_die
&& child_die
->tag
)
2876 if (child_die
->tag
== DW_TAG_formal_parameter
)
2878 /* Dwarf2 has no clean way to discern C++ static and non-static
2879 member functions. G++ helps GDB by marking the first
2880 parameter for non-static member functions (which is the
2881 this pointer) as artificial. We pass this information
2882 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2883 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2885 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2887 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2888 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
2892 child_die
= sibling_die (child_die
);
2900 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
2901 const struct comp_unit_head
*cu_header
)
2903 struct attribute
*attr
;
2908 attr
= dwarf_attr (die
, DW_AT_name
);
2909 if (attr
&& DW_STRING (attr
))
2911 name
= DW_STRING (attr
);
2913 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
2914 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, objfile
, cu_header
);
2918 /* Find a representation of a given base type and install
2919 it in the TYPE field of the die. */
2922 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
2925 struct attribute
*attr
;
2926 int encoding
= 0, size
= 0;
2928 /* If we've already decoded this die, this is a no-op. */
2934 attr
= dwarf_attr (die
, DW_AT_encoding
);
2937 encoding
= DW_UNSND (attr
);
2939 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2942 size
= DW_UNSND (attr
);
2944 attr
= dwarf_attr (die
, DW_AT_name
);
2945 if (attr
&& DW_STRING (attr
))
2947 enum type_code code
= TYPE_CODE_INT
;
2952 case DW_ATE_address
:
2953 /* Turn DW_ATE_address into a void * pointer. */
2954 code
= TYPE_CODE_PTR
;
2955 type_flags
|= TYPE_FLAG_UNSIGNED
;
2957 case DW_ATE_boolean
:
2958 code
= TYPE_CODE_BOOL
;
2959 type_flags
|= TYPE_FLAG_UNSIGNED
;
2961 case DW_ATE_complex_float
:
2962 code
= TYPE_CODE_COMPLEX
;
2965 code
= TYPE_CODE_FLT
;
2968 case DW_ATE_signed_char
:
2970 case DW_ATE_unsigned
:
2971 case DW_ATE_unsigned_char
:
2972 type_flags
|= TYPE_FLAG_UNSIGNED
;
2975 complain (&dwarf2_unsupported_at_encoding
,
2976 dwarf_type_encoding_name (encoding
));
2979 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
2980 if (encoding
== DW_ATE_address
)
2981 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2985 type
= dwarf_base_type (encoding
, size
, objfile
);
2990 /* Read a whole compilation unit into a linked list of dies. */
2992 static struct die_info
*
2993 read_comp_unit (char *info_ptr
, bfd
*abfd
,
2994 const struct comp_unit_head
*cu_header
)
2996 struct die_info
*first_die
, *last_die
, *die
;
3000 /* Reset die reference table; we are
3001 building new ones now. */
3002 dwarf2_empty_hash_tables ();
3006 first_die
= last_die
= NULL
;
3009 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
3010 if (die
->has_children
)
3021 /* Enter die in reference hash table */
3022 store_in_ref_table (die
->offset
, die
);
3026 first_die
= last_die
= die
;
3030 last_die
->next
= die
;
3034 while (nesting_level
> 0);
3038 /* Free a linked list of dies. */
3041 free_die_list (struct die_info
*dies
)
3043 struct die_info
*die
, *next
;
3056 do_free_die_list_cleanup (void *dies
)
3058 free_die_list (dies
);
3061 static struct cleanup
*
3062 make_cleanup_free_die_list (struct die_info
*dies
)
3064 return make_cleanup (do_free_die_list_cleanup
, dies
);
3068 /* Read the contents of the section at OFFSET and of size SIZE from the
3069 object file specified by OBJFILE into the psymbol_obstack and return it. */
3072 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
3075 bfd
*abfd
= objfile
->obfd
;
3081 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3082 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3083 (bfd_bread (buf
, size
, abfd
) != size
))
3086 error ("Dwarf Error: Can't read DWARF data from '%s'",
3087 bfd_get_filename (abfd
));
3092 /* In DWARF version 2, the description of the debugging information is
3093 stored in a separate .debug_abbrev section. Before we read any
3094 dies from a section we read in all abbreviations and install them
3098 dwarf2_read_abbrevs (bfd
*abfd
, unsigned int offset
)
3101 struct abbrev_info
*cur_abbrev
;
3102 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3103 unsigned int abbrev_form
, hash_number
;
3105 /* empty the table */
3106 dwarf2_empty_abbrev_table (NULL
);
3108 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3109 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3110 abbrev_ptr
+= bytes_read
;
3112 /* loop until we reach an abbrev number of 0 */
3113 while (abbrev_number
)
3115 cur_abbrev
= dwarf_alloc_abbrev ();
3117 /* read in abbrev header */
3118 cur_abbrev
->number
= abbrev_number
;
3119 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3120 abbrev_ptr
+= bytes_read
;
3121 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3124 /* now read in declarations */
3125 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3126 abbrev_ptr
+= bytes_read
;
3127 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3128 abbrev_ptr
+= bytes_read
;
3131 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3133 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3134 xrealloc (cur_abbrev
->attrs
,
3135 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3136 * sizeof (struct attr_abbrev
));
3138 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3139 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3140 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3141 abbrev_ptr
+= bytes_read
;
3142 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3143 abbrev_ptr
+= bytes_read
;
3146 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3147 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3148 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3150 /* Get next abbreviation.
3151 Under Irix6 the abbreviations for a compilation unit are not
3152 always properly terminated with an abbrev number of 0.
3153 Exit loop if we encounter an abbreviation which we have
3154 already read (which means we are about to read the abbreviations
3155 for the next compile unit) or if the end of the abbreviation
3156 table is reached. */
3157 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3158 >= dwarf_abbrev_size
)
3160 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3161 abbrev_ptr
+= bytes_read
;
3162 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3167 /* Empty the abbrev table for a new compilation unit. */
3171 dwarf2_empty_abbrev_table (PTR ignore
)
3174 struct abbrev_info
*abbrev
, *next
;
3176 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3179 abbrev
= dwarf2_abbrevs
[i
];
3182 next
= abbrev
->next
;
3183 xfree (abbrev
->attrs
);
3187 dwarf2_abbrevs
[i
] = NULL
;
3191 /* Lookup an abbrev_info structure in the abbrev hash table. */
3193 static struct abbrev_info
*
3194 dwarf2_lookup_abbrev (unsigned int number
)
3196 unsigned int hash_number
;
3197 struct abbrev_info
*abbrev
;
3199 hash_number
= number
% ABBREV_HASH_SIZE
;
3200 abbrev
= dwarf2_abbrevs
[hash_number
];
3204 if (abbrev
->number
== number
)
3207 abbrev
= abbrev
->next
;
3212 /* Read a minimal amount of information into the minimal die structure. */
3215 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3216 char *info_ptr
, const struct comp_unit_head
*cu_header
)
3218 unsigned int abbrev_number
, bytes_read
, i
;
3219 struct abbrev_info
*abbrev
;
3220 struct attribute attr
;
3221 struct attribute spec_attr
;
3222 int found_spec_attr
= 0;
3223 int has_low_pc_attr
= 0;
3224 int has_high_pc_attr
= 0;
3226 *part_die
= zeroed_partial_die
;
3227 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3228 info_ptr
+= bytes_read
;
3232 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3235 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3237 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3238 part_die
->tag
= abbrev
->tag
;
3239 part_die
->has_children
= abbrev
->has_children
;
3240 part_die
->abbrev
= abbrev_number
;
3242 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3244 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3245 info_ptr
, cu_header
);
3247 /* Store the data if it is of an attribute we want to keep in a
3248 partial symbol table. */
3253 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3254 if (part_die
->name
== NULL
)
3255 part_die
->name
= DW_STRING (&attr
);
3257 case DW_AT_MIPS_linkage_name
:
3258 part_die
->name
= DW_STRING (&attr
);
3261 has_low_pc_attr
= 1;
3262 part_die
->lowpc
= DW_ADDR (&attr
);
3265 has_high_pc_attr
= 1;
3266 part_die
->highpc
= DW_ADDR (&attr
);
3268 case DW_AT_location
:
3269 part_die
->locdesc
= DW_BLOCK (&attr
);
3271 case DW_AT_language
:
3272 part_die
->language
= DW_UNSND (&attr
);
3274 case DW_AT_external
:
3275 part_die
->is_external
= DW_UNSND (&attr
);
3277 case DW_AT_declaration
:
3278 part_die
->is_declaration
= DW_UNSND (&attr
);
3281 part_die
->has_type
= 1;
3283 case DW_AT_abstract_origin
:
3284 case DW_AT_specification
:
3285 found_spec_attr
= 1;
3289 /* Ignore absolute siblings, they might point outside of
3290 the current compile unit. */
3291 if (attr
.form
== DW_FORM_ref_addr
)
3292 complain (&dwarf2_absolute_sibling_complaint
);
3295 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3302 /* If we found a reference attribute and the die has no name, try
3303 to find a name in the referred to die. */
3305 if (found_spec_attr
&& part_die
->name
== NULL
)
3307 struct partial_die_info spec_die
;
3311 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3312 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu_header
);
3315 part_die
->name
= spec_die
.name
;
3317 /* Copy DW_AT_external attribute if it is set. */
3318 if (spec_die
.is_external
)
3319 part_die
->is_external
= spec_die
.is_external
;
3323 /* When using the GNU linker, .gnu.linkonce. sections are used to
3324 eliminate duplicate copies of functions and vtables and such.
3325 The linker will arbitrarily choose one and discard the others.
3326 The AT_*_pc values for such functions refer to local labels in
3327 these sections. If the section from that file was discarded, the
3328 labels are not in the output, so the relocs get a value of 0.
3329 If this is a discarded function, mark the pc bounds as invalid,
3330 so that GDB will ignore it. */
3331 if (has_low_pc_attr
&& has_high_pc_attr
3332 && part_die
->lowpc
< part_die
->highpc
3333 && (part_die
->lowpc
!= 0
3334 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3335 part_die
->has_pc_info
= 1;
3339 /* Read the die from the .debug_info section buffer. And set diep to
3340 point to a newly allocated die with its information. */
3343 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3344 const struct comp_unit_head
*cu_header
)
3346 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3347 struct abbrev_info
*abbrev
;
3348 struct die_info
*die
;
3350 offset
= info_ptr
- dwarf_info_buffer
;
3351 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3352 info_ptr
+= bytes_read
;
3355 die
= dwarf_alloc_die ();
3357 die
->abbrev
= abbrev_number
;
3363 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3366 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3368 die
= dwarf_alloc_die ();
3369 die
->offset
= offset
;
3370 die
->tag
= abbrev
->tag
;
3371 die
->has_children
= abbrev
->has_children
;
3372 die
->abbrev
= abbrev_number
;
3375 die
->num_attrs
= abbrev
->num_attrs
;
3376 die
->attrs
= (struct attribute
*)
3377 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3379 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3381 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3382 abfd
, info_ptr
, cu_header
);
3389 /* Read an attribute value described by an attribute form. */
3392 read_attribute_value (struct attribute
*attr
, unsigned form
,
3393 bfd
*abfd
, char *info_ptr
,
3394 const struct comp_unit_head
*cu_header
)
3396 unsigned int bytes_read
;
3397 struct dwarf_block
*blk
;
3403 case DW_FORM_ref_addr
:
3404 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3405 info_ptr
+= bytes_read
;
3407 case DW_FORM_block2
:
3408 blk
= dwarf_alloc_block ();
3409 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3411 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3412 info_ptr
+= blk
->size
;
3413 DW_BLOCK (attr
) = blk
;
3415 case DW_FORM_block4
:
3416 blk
= dwarf_alloc_block ();
3417 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3419 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3420 info_ptr
+= blk
->size
;
3421 DW_BLOCK (attr
) = blk
;
3424 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3428 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3432 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3435 case DW_FORM_string
:
3436 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3437 info_ptr
+= bytes_read
;
3440 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
3442 info_ptr
+= bytes_read
;
3445 blk
= dwarf_alloc_block ();
3446 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3447 info_ptr
+= bytes_read
;
3448 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3449 info_ptr
+= blk
->size
;
3450 DW_BLOCK (attr
) = blk
;
3452 case DW_FORM_block1
:
3453 blk
= dwarf_alloc_block ();
3454 blk
->size
= read_1_byte (abfd
, info_ptr
);
3456 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3457 info_ptr
+= blk
->size
;
3458 DW_BLOCK (attr
) = blk
;
3461 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3465 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3469 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3470 info_ptr
+= bytes_read
;
3473 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3474 info_ptr
+= bytes_read
;
3477 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3481 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3485 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3489 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3492 case DW_FORM_ref_udata
:
3493 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3494 info_ptr
+= bytes_read
;
3496 case DW_FORM_indirect
:
3497 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3498 info_ptr
+= bytes_read
;
3499 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu_header
);
3502 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3503 dwarf_form_name (form
));
3508 /* Read an attribute described by an abbreviated attribute. */
3511 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
3512 bfd
*abfd
, char *info_ptr
,
3513 const struct comp_unit_head
*cu_header
)
3515 attr
->name
= abbrev
->name
;
3516 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu_header
);
3519 /* read dwarf information from a buffer */
3522 read_1_byte (bfd
*abfd
, char *buf
)
3524 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3528 read_1_signed_byte (bfd
*abfd
, char *buf
)
3530 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3534 read_2_bytes (bfd
*abfd
, char *buf
)
3536 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3540 read_2_signed_bytes (bfd
*abfd
, char *buf
)
3542 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3546 read_4_bytes (bfd
*abfd
, char *buf
)
3548 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3552 read_4_signed_bytes (bfd
*abfd
, char *buf
)
3554 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3557 static unsigned long
3558 read_8_bytes (bfd
*abfd
, char *buf
)
3560 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3564 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3567 CORE_ADDR retval
= 0;
3569 if (cu_header
->signed_addr_p
)
3571 switch (cu_header
->addr_size
)
3574 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3577 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3580 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
3583 internal_error (__FILE__
, __LINE__
,
3584 "read_address: bad switch, signed");
3589 switch (cu_header
->addr_size
)
3592 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3595 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3598 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3601 internal_error (__FILE__
, __LINE__
,
3602 "read_address: bad switch, unsigned");
3606 *bytes_read
= cu_header
->addr_size
;
3610 /* Reads the initial length from a section. The (draft) DWARF 2.1
3611 specification allows the initial length to take up either 4 bytes
3612 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
3613 bytes describe the length and all offsets will be 8 bytes in length
3616 The value returned via bytes_read should be used to increment
3617 the relevant pointer after calling read_initial_length().
3619 As a side effect, this function sets the fields initial_length_size
3620 and offset_size in cu_header to the values appropriate for the
3621 length field. (The format of the initial length field determines
3622 the width of file offsets to be fetched later with fetch_offset().)
3624 [ Note: read_initial_length() and read_offset() are based on the
3625 document entitled "DWARF Debugging Information Format", revision
3626 2.1, draft 4, dated July 20, 2000. This document was obtained
3629 http://reality.sgi.com/dehnert_engr/dwarf/dwarf2p1-draft4-000720.pdf
3631 This document is only a draft and is subject to change. (So beware.)
3633 - Kevin, Aug 4, 2000
3637 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
3642 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3644 if (retval
== 0xffffffff)
3646 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
3648 if (cu_header
!= NULL
)
3650 cu_header
->initial_length_size
= 12;
3651 cu_header
->offset_size
= 8;
3657 if (cu_header
!= NULL
)
3659 cu_header
->initial_length_size
= 4;
3660 cu_header
->offset_size
= 4;
3667 /* Read an offset from the data stream. The size of the offset is
3668 given by cu_header->offset_size. */
3671 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3676 switch (cu_header
->offset_size
)
3679 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3683 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3687 internal_error (__FILE__
, __LINE__
,
3688 "read_offset: bad switch");
3695 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
3697 /* If the size of a host char is 8 bits, we can return a pointer
3698 to the buffer, otherwise we have to copy the data to a buffer
3699 allocated on the temporary obstack. */
3700 gdb_assert (HOST_CHAR_BIT
== 8);
3705 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3707 /* If the size of a host char is 8 bits, we can return a pointer
3708 to the string, otherwise we have to copy the string to a buffer
3709 allocated on the temporary obstack. */
3710 gdb_assert (HOST_CHAR_BIT
== 8);
3713 *bytes_read_ptr
= 1;
3716 *bytes_read_ptr
= strlen (buf
) + 1;
3721 read_indirect_string (bfd
*abfd
, char *buf
,
3722 const struct comp_unit_head
*cu_header
,
3723 unsigned int *bytes_read_ptr
)
3725 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
3726 (int *) bytes_read_ptr
);
3728 if (dwarf_str_buffer
== NULL
)
3730 error ("DW_FORM_strp used without .debug_str section");
3733 if (str_offset
>= dwarf_str_size
)
3735 error ("DW_FORM_strp pointing outside of .debug_str section");
3738 gdb_assert (HOST_CHAR_BIT
== 8);
3739 if (dwarf_str_buffer
[str_offset
] == '\0')
3741 return dwarf_str_buffer
+ str_offset
;
3744 static unsigned long
3745 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3747 unsigned long result
;
3748 unsigned int num_read
;
3758 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3761 result
|= ((unsigned long)(byte
& 127) << shift
);
3762 if ((byte
& 128) == 0)
3768 *bytes_read_ptr
= num_read
;
3773 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3776 int i
, shift
, size
, num_read
;
3786 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3789 result
|= ((long)(byte
& 127) << shift
);
3791 if ((byte
& 128) == 0)
3796 if ((shift
< size
) && (byte
& 0x40))
3798 result
|= -(1 << shift
);
3800 *bytes_read_ptr
= num_read
;
3805 set_cu_language (unsigned int lang
)
3811 cu_language
= language_c
;
3813 case DW_LANG_C_plus_plus
:
3814 cu_language
= language_cplus
;
3816 case DW_LANG_Fortran77
:
3817 case DW_LANG_Fortran90
:
3818 case DW_LANG_Fortran95
:
3819 cu_language
= language_fortran
;
3821 case DW_LANG_Mips_Assembler
:
3822 cu_language
= language_asm
;
3825 cu_language
= language_java
;
3828 case DW_LANG_Cobol74
:
3829 case DW_LANG_Cobol85
:
3830 case DW_LANG_Pascal83
:
3831 case DW_LANG_Modula2
:
3833 cu_language
= language_unknown
;
3836 cu_language_defn
= language_def (cu_language
);
3839 /* Return the named attribute or NULL if not there. */
3841 static struct attribute
*
3842 dwarf_attr (struct die_info
*die
, unsigned int name
)
3845 struct attribute
*spec
= NULL
;
3847 for (i
= 0; i
< die
->num_attrs
; ++i
)
3849 if (die
->attrs
[i
].name
== name
)
3851 return &die
->attrs
[i
];
3853 if (die
->attrs
[i
].name
== DW_AT_specification
3854 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3855 spec
= &die
->attrs
[i
];
3859 struct die_info
*ref_die
=
3860 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3863 return dwarf_attr (ref_die
, name
);
3870 die_is_declaration (struct die_info
*die
)
3872 return (dwarf_attr (die
, DW_AT_declaration
)
3873 && ! dwarf_attr (die
, DW_AT_specification
));
3876 /* Decode the line number information for the compilation unit whose
3877 line number info is at OFFSET in the .debug_line section.
3878 The compilation directory of the file is passed in COMP_DIR. */
3882 unsigned int num_files
;
3895 unsigned int num_dirs
;
3900 dwarf_decode_lines (unsigned int offset
, char *comp_dir
, bfd
*abfd
,
3901 const struct comp_unit_head
*cu_header
)
3905 struct line_head lh
;
3906 struct cleanup
*back_to
;
3907 unsigned int i
, bytes_read
;
3908 char *cur_file
, *cur_dir
;
3909 unsigned char op_code
, extended_op
, adj_opcode
;
3911 #define FILE_ALLOC_CHUNK 5
3912 #define DIR_ALLOC_CHUNK 5
3914 struct filenames files
;
3915 struct directories dirs
;
3917 if (dwarf_line_buffer
== NULL
)
3919 complain (&dwarf2_missing_line_number_section
);
3923 files
.num_files
= 0;
3929 line_ptr
= dwarf_line_buffer
+ offset
;
3931 /* read in the prologue */
3932 lh
.total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
3933 line_ptr
+= bytes_read
;
3934 line_end
= line_ptr
+ lh
.total_length
;
3935 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3937 lh
.prologue_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
3938 line_ptr
+= bytes_read
;
3939 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3941 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3943 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3945 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3947 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3949 lh
.standard_opcode_lengths
= (unsigned char *)
3950 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3951 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
3953 lh
.standard_opcode_lengths
[0] = 1;
3954 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3956 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3960 /* Read directory table */
3961 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3963 line_ptr
+= bytes_read
;
3964 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3966 dirs
.dirs
= (char **)
3967 xrealloc (dirs
.dirs
,
3968 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3969 if (dirs
.num_dirs
== 0)
3970 make_cleanup (free_current_contents
, &dirs
.dirs
);
3972 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3974 line_ptr
+= bytes_read
;
3976 /* Read file name table */
3977 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3979 line_ptr
+= bytes_read
;
3980 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3982 files
.files
= (struct fileinfo
*)
3983 xrealloc (files
.files
,
3984 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3985 * sizeof (struct fileinfo
));
3986 if (files
.num_files
== 0)
3987 make_cleanup (free_current_contents
, &files
.files
);
3989 files
.files
[files
.num_files
].name
= cur_file
;
3990 files
.files
[files
.num_files
].dir
=
3991 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3992 line_ptr
+= bytes_read
;
3993 files
.files
[files
.num_files
].time
=
3994 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3995 line_ptr
+= bytes_read
;
3996 files
.files
[files
.num_files
].size
=
3997 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3998 line_ptr
+= bytes_read
;
4001 line_ptr
+= bytes_read
;
4003 /* Read the statement sequences until there's nothing left. */
4004 while (line_ptr
< line_end
)
4006 /* state machine registers */
4007 CORE_ADDR address
= 0;
4008 unsigned int file
= 1;
4009 unsigned int line
= 1;
4010 unsigned int column
= 0;
4011 int is_stmt
= lh
.default_is_stmt
;
4012 int basic_block
= 0;
4013 int end_sequence
= 0;
4015 /* Start a subfile for the current file of the state machine. */
4016 if (files
.num_files
>= file
)
4018 /* The file and directory tables are 0 based, the references
4020 dwarf2_start_subfile (files
.files
[file
- 1].name
,
4021 (files
.files
[file
- 1].dir
4022 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
4026 /* Decode the table. */
4027 while (!end_sequence
)
4029 op_code
= read_1_byte (abfd
, line_ptr
);
4032 if (op_code
>= lh
.opcode_base
)
4033 { /* Special operand. */
4034 adj_opcode
= op_code
- lh
.opcode_base
;
4035 address
+= (adj_opcode
/ lh
.line_range
)
4036 * lh
.minimum_instruction_length
;
4037 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
4038 /* append row to matrix using current values */
4039 record_line (current_subfile
, line
, address
);
4042 else switch (op_code
)
4044 case DW_LNS_extended_op
:
4045 line_ptr
+= 1; /* ignore length */
4046 extended_op
= read_1_byte (abfd
, line_ptr
);
4048 switch (extended_op
)
4050 case DW_LNE_end_sequence
:
4052 /* Don't call record_line here. The end_sequence
4053 instruction provides the address of the first byte
4054 *after* the last line in the sequence; it's not the
4055 address of any real source line. However, the GDB
4056 linetable structure only records the starts of lines,
4057 not the ends. This is a weakness of GDB. */
4059 case DW_LNE_set_address
:
4060 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
4061 line_ptr
+= bytes_read
;
4062 address
+= baseaddr
;
4064 case DW_LNE_define_file
:
4065 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
4066 line_ptr
+= bytes_read
;
4067 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
4069 files
.files
= (struct fileinfo
*)
4070 xrealloc (files
.files
,
4071 (files
.num_files
+ FILE_ALLOC_CHUNK
)
4072 * sizeof (struct fileinfo
));
4073 if (files
.num_files
== 0)
4074 make_cleanup (free_current_contents
, &files
.files
);
4076 files
.files
[files
.num_files
].name
= cur_file
;
4077 files
.files
[files
.num_files
].dir
=
4078 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4079 line_ptr
+= bytes_read
;
4080 files
.files
[files
.num_files
].time
=
4081 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4082 line_ptr
+= bytes_read
;
4083 files
.files
[files
.num_files
].size
=
4084 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4085 line_ptr
+= bytes_read
;
4089 complain (&dwarf2_mangled_line_number_section
);
4094 record_line (current_subfile
, line
, address
);
4097 case DW_LNS_advance_pc
:
4098 address
+= lh
.minimum_instruction_length
4099 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4100 line_ptr
+= bytes_read
;
4102 case DW_LNS_advance_line
:
4103 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
4104 line_ptr
+= bytes_read
;
4106 case DW_LNS_set_file
:
4107 /* The file and directory tables are 0 based, the references
4109 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4110 line_ptr
+= bytes_read
;
4111 dwarf2_start_subfile
4112 (files
.files
[file
- 1].name
,
4113 (files
.files
[file
- 1].dir
4114 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
4117 case DW_LNS_set_column
:
4118 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4119 line_ptr
+= bytes_read
;
4121 case DW_LNS_negate_stmt
:
4122 is_stmt
= (!is_stmt
);
4124 case DW_LNS_set_basic_block
:
4127 /* Add to the address register of the state machine the
4128 address increment value corresponding to special opcode
4129 255. Ie, this value is scaled by the minimum instruction
4130 length since special opcode 255 would have scaled the
4132 case DW_LNS_const_add_pc
:
4133 address
+= (lh
.minimum_instruction_length
4134 * ((255 - lh
.opcode_base
) / lh
.line_range
));
4136 case DW_LNS_fixed_advance_pc
:
4137 address
+= read_2_bytes (abfd
, line_ptr
);
4141 { /* Unknown standard opcode, ignore it. */
4143 for (i
= 0; i
< lh
.standard_opcode_lengths
[op_code
]; i
++)
4145 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4146 line_ptr
+= bytes_read
;
4153 do_cleanups (back_to
);
4156 /* Start a subfile for DWARF. FILENAME is the name of the file and
4157 DIRNAME the name of the source directory which contains FILENAME
4158 or NULL if not known.
4159 This routine tries to keep line numbers from identical absolute and
4160 relative file names in a common subfile.
4162 Using the `list' example from the GDB testsuite, which resides in
4163 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4164 of /srcdir/list0.c yields the following debugging information for list0.c:
4166 DW_AT_name: /srcdir/list0.c
4167 DW_AT_comp_dir: /compdir
4168 files.files[0].name: list0.h
4169 files.files[0].dir: /srcdir
4170 files.files[1].name: list0.c
4171 files.files[1].dir: /srcdir
4173 The line number information for list0.c has to end up in a single
4174 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4177 dwarf2_start_subfile (char *filename
, char *dirname
)
4179 /* If the filename isn't absolute, try to match an existing subfile
4180 with the full pathname. */
4182 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
4184 struct subfile
*subfile
;
4185 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4187 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4189 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
4191 current_subfile
= subfile
;
4198 start_subfile (filename
, dirname
);
4201 /* Given a pointer to a DWARF information entry, figure out if we need
4202 to make a symbol table entry for it, and if so, create a new entry
4203 and return a pointer to it.
4204 If TYPE is NULL, determine symbol type from the die, otherwise
4205 used the passed type. */
4207 static struct symbol
*
4208 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
4209 const struct comp_unit_head
*cu_header
)
4211 struct symbol
*sym
= NULL
;
4213 struct attribute
*attr
= NULL
;
4214 struct attribute
*attr2
= NULL
;
4217 name
= dwarf2_linkage_name (die
);
4220 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4221 sizeof (struct symbol
));
4222 OBJSTAT (objfile
, n_syms
++);
4223 memset (sym
, 0, sizeof (struct symbol
));
4224 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4225 &objfile
->symbol_obstack
);
4227 /* Default assumptions.
4228 Use the passed type or decode it from the die. */
4229 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4230 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4232 SYMBOL_TYPE (sym
) = type
;
4234 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
4235 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4238 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4241 /* If this symbol is from a C++ compilation, then attempt to
4242 cache the demangled form for future reference. This is a
4243 typical time versus space tradeoff, that was decided in favor
4244 of time because it sped up C++ symbol lookups by a factor of
4247 SYMBOL_LANGUAGE (sym
) = cu_language
;
4248 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4252 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4255 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4257 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4259 case DW_TAG_subprogram
:
4260 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4262 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4263 attr2
= dwarf_attr (die
, DW_AT_external
);
4264 if (attr2
&& (DW_UNSND (attr2
) != 0))
4266 add_symbol_to_list (sym
, &global_symbols
);
4270 add_symbol_to_list (sym
, list_in_scope
);
4273 case DW_TAG_variable
:
4274 /* Compilation with minimal debug info may result in variables
4275 with missing type entries. Change the misleading `void' type
4276 to something sensible. */
4277 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4278 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4279 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4280 "<variable, no debug info>",
4282 attr
= dwarf_attr (die
, DW_AT_const_value
);
4285 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4286 attr2
= dwarf_attr (die
, DW_AT_external
);
4287 if (attr2
&& (DW_UNSND (attr2
) != 0))
4288 add_symbol_to_list (sym
, &global_symbols
);
4290 add_symbol_to_list (sym
, list_in_scope
);
4293 attr
= dwarf_attr (die
, DW_AT_location
);
4296 attr2
= dwarf_attr (die
, DW_AT_external
);
4297 if (attr2
&& (DW_UNSND (attr2
) != 0))
4299 SYMBOL_VALUE_ADDRESS (sym
) =
4300 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4301 add_symbol_to_list (sym
, &global_symbols
);
4303 /* In shared libraries the address of the variable
4304 in the location descriptor might still be relocatable,
4305 so its value could be zero.
4306 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4307 value is zero, the address of the variable will then
4308 be determined from the minimal symbol table whenever
4309 the variable is referenced. */
4310 if (SYMBOL_VALUE_ADDRESS (sym
))
4312 fixup_symbol_section (sym
, objfile
);
4313 SYMBOL_VALUE_ADDRESS (sym
) +=
4314 ANOFFSET (objfile
->section_offsets
,
4315 SYMBOL_SECTION (sym
));
4316 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4319 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4323 SYMBOL_VALUE (sym
) = addr
=
4324 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4325 add_symbol_to_list (sym
, list_in_scope
);
4328 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4332 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4333 SYMBOL_VALUE (sym
) =
4334 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4338 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4339 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4343 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4347 fixup_symbol_section (sym
, objfile
);
4348 SYMBOL_VALUE_ADDRESS (sym
) =
4349 addr
+ ANOFFSET (objfile
->section_offsets
,
4350 SYMBOL_SECTION (sym
));
4351 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4357 /* We do not know the address of this symbol.
4358 If it is an external symbol and we have type information
4359 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4360 The address of the variable will then be determined from
4361 the minimal symbol table whenever the variable is
4363 attr2
= dwarf_attr (die
, DW_AT_external
);
4364 if (attr2
&& (DW_UNSND (attr2
) != 0)
4365 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4367 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4368 add_symbol_to_list (sym
, &global_symbols
);
4372 case DW_TAG_formal_parameter
:
4373 attr
= dwarf_attr (die
, DW_AT_location
);
4376 SYMBOL_VALUE (sym
) =
4377 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4380 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4381 SYMBOL_VALUE (sym
) =
4382 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4388 if (basereg
!= frame_base_reg
)
4389 complain (&dwarf2_complex_location_expr
);
4390 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4394 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4395 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4400 SYMBOL_CLASS (sym
) = LOC_ARG
;
4403 attr
= dwarf_attr (die
, DW_AT_const_value
);
4406 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4408 add_symbol_to_list (sym
, list_in_scope
);
4410 case DW_TAG_unspecified_parameters
:
4411 /* From varargs functions; gdb doesn't seem to have any
4412 interest in this information, so just ignore it for now.
4415 case DW_TAG_class_type
:
4416 case DW_TAG_structure_type
:
4417 case DW_TAG_union_type
:
4418 case DW_TAG_enumeration_type
:
4419 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4420 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4421 add_symbol_to_list (sym
, list_in_scope
);
4423 /* The semantics of C++ state that "struct foo { ... }" also
4424 defines a typedef for "foo". Synthesize a typedef symbol so
4425 that "ptype foo" works as expected. */
4426 if (cu_language
== language_cplus
)
4428 struct symbol
*typedef_sym
= (struct symbol
*)
4429 obstack_alloc (&objfile
->symbol_obstack
,
4430 sizeof (struct symbol
));
4431 *typedef_sym
= *sym
;
4432 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4433 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4434 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4435 obsavestring (SYMBOL_NAME (sym
),
4436 strlen (SYMBOL_NAME (sym
)),
4437 &objfile
->type_obstack
);
4438 add_symbol_to_list (typedef_sym
, list_in_scope
);
4441 case DW_TAG_typedef
:
4442 case DW_TAG_base_type
:
4443 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4444 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4445 add_symbol_to_list (sym
, list_in_scope
);
4447 case DW_TAG_enumerator
:
4448 attr
= dwarf_attr (die
, DW_AT_const_value
);
4451 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4453 add_symbol_to_list (sym
, list_in_scope
);
4456 /* Not a tag we recognize. Hopefully we aren't processing
4457 trash data, but since we must specifically ignore things
4458 we don't recognize, there is nothing else we should do at
4460 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4467 /* Copy constant value from an attribute to a symbol. */
4470 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
4471 struct objfile
*objfile
,
4472 const struct comp_unit_head
*cu_header
)
4474 struct dwarf_block
*blk
;
4479 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
4480 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4481 cu_header
->addr_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4482 SYMBOL_VALUE_BYTES (sym
) = (char *)
4483 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
4484 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
4486 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4488 case DW_FORM_block1
:
4489 case DW_FORM_block2
:
4490 case DW_FORM_block4
:
4492 blk
= DW_BLOCK (attr
);
4493 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4494 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4495 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4496 SYMBOL_VALUE_BYTES (sym
) = (char *)
4497 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4498 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4499 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4502 /* The DW_AT_const_value attributes are supposed to carry the
4503 symbol's value "represented as it would be on the target
4504 architecture." By the time we get here, it's already been
4505 converted to host endianness, so we just need to sign- or
4506 zero-extend it as appropriate. */
4508 dwarf2_const_value_data (attr
, sym
, 8);
4511 dwarf2_const_value_data (attr
, sym
, 16);
4514 dwarf2_const_value_data (attr
, sym
, 32);
4517 dwarf2_const_value_data (attr
, sym
, 64);
4521 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4522 SYMBOL_CLASS (sym
) = LOC_CONST
;
4526 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4527 SYMBOL_CLASS (sym
) = LOC_CONST
;
4531 complain (&dwarf2_unsupported_const_value_attr
,
4532 dwarf_form_name (attr
->form
));
4533 SYMBOL_VALUE (sym
) = 0;
4534 SYMBOL_CLASS (sym
) = LOC_CONST
;
4540 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4541 or zero-extend it as appropriate for the symbol's type. */
4543 dwarf2_const_value_data (struct attribute
*attr
,
4547 LONGEST l
= DW_UNSND (attr
);
4549 if (bits
< sizeof (l
) * 8)
4551 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4552 l
&= ((LONGEST
) 1 << bits
) - 1;
4554 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4557 SYMBOL_VALUE (sym
) = l
;
4558 SYMBOL_CLASS (sym
) = LOC_CONST
;
4562 /* Return the type of the die in question using its DW_AT_type attribute. */
4564 static struct type
*
4565 die_type (struct die_info
*die
, struct objfile
*objfile
,
4566 const struct comp_unit_head
*cu_header
)
4569 struct attribute
*type_attr
;
4570 struct die_info
*type_die
;
4573 type_attr
= dwarf_attr (die
, DW_AT_type
);
4576 /* A missing DW_AT_type represents a void type. */
4577 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4581 ref
= dwarf2_get_ref_die_offset (type_attr
);
4582 type_die
= follow_die_ref (ref
);
4585 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4589 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4592 dump_die (type_die
);
4593 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4598 /* Return the containing type of the die in question using its
4599 DW_AT_containing_type attribute. */
4601 static struct type
*
4602 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
4603 const struct comp_unit_head
*cu_header
)
4605 struct type
*type
= NULL
;
4606 struct attribute
*type_attr
;
4607 struct die_info
*type_die
= NULL
;
4610 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4613 ref
= dwarf2_get_ref_die_offset (type_attr
);
4614 type_die
= follow_die_ref (ref
);
4617 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4620 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4625 dump_die (type_die
);
4626 error ("Dwarf Error: Problem turning containing type into gdb type.");
4632 static struct type
*
4633 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
4635 struct die_info
*die
;
4638 die
= follow_die_ref (offset
);
4641 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4644 type
= tag_type_to_type (die
, objfile
);
4649 static struct type
*
4650 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
4651 const struct comp_unit_head
*cu_header
)
4659 read_type_die (die
, objfile
, cu_header
);
4663 error ("Dwarf Error: Cannot find type of die.");
4670 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
4671 const struct comp_unit_head
*cu_header
)
4675 case DW_TAG_class_type
:
4676 case DW_TAG_structure_type
:
4677 case DW_TAG_union_type
:
4678 read_structure_scope (die
, objfile
, cu_header
);
4680 case DW_TAG_enumeration_type
:
4681 read_enumeration (die
, objfile
, cu_header
);
4683 case DW_TAG_subprogram
:
4684 case DW_TAG_subroutine_type
:
4685 read_subroutine_type (die
, objfile
, cu_header
);
4687 case DW_TAG_array_type
:
4688 read_array_type (die
, objfile
, cu_header
);
4690 case DW_TAG_pointer_type
:
4691 read_tag_pointer_type (die
, objfile
, cu_header
);
4693 case DW_TAG_ptr_to_member_type
:
4694 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
4696 case DW_TAG_reference_type
:
4697 read_tag_reference_type (die
, objfile
, cu_header
);
4699 case DW_TAG_const_type
:
4700 read_tag_const_type (die
, objfile
, cu_header
);
4702 case DW_TAG_volatile_type
:
4703 read_tag_volatile_type (die
, objfile
, cu_header
);
4705 case DW_TAG_string_type
:
4706 read_tag_string_type (die
, objfile
);
4708 case DW_TAG_typedef
:
4709 read_typedef (die
, objfile
, cu_header
);
4711 case DW_TAG_base_type
:
4712 read_base_type (die
, objfile
);
4715 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4720 static struct type
*
4721 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
4723 /* FIXME - this should not produce a new (struct type *)
4724 every time. It should cache base types. */
4728 case DW_ATE_address
:
4729 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4731 case DW_ATE_boolean
:
4732 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4734 case DW_ATE_complex_float
:
4737 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4741 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4747 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4751 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4758 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4761 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4765 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4769 case DW_ATE_signed_char
:
4770 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4772 case DW_ATE_unsigned
:
4776 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4779 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4783 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4787 case DW_ATE_unsigned_char
:
4788 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4791 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4798 copy_die (struct die_info
*old_die
)
4800 struct die_info
*new_die
;
4803 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4804 memset (new_die
, 0, sizeof (struct die_info
));
4806 new_die
->tag
= old_die
->tag
;
4807 new_die
->has_children
= old_die
->has_children
;
4808 new_die
->abbrev
= old_die
->abbrev
;
4809 new_die
->offset
= old_die
->offset
;
4810 new_die
->type
= NULL
;
4812 num_attrs
= old_die
->num_attrs
;
4813 new_die
->num_attrs
= num_attrs
;
4814 new_die
->attrs
= (struct attribute
*)
4815 xmalloc (num_attrs
* sizeof (struct attribute
));
4817 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4819 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4820 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4821 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4824 new_die
->next
= NULL
;
4829 /* Return sibling of die, NULL if no sibling. */
4831 static struct die_info
*
4832 sibling_die (struct die_info
*die
)
4834 int nesting_level
= 0;
4836 if (!die
->has_children
)
4838 if (die
->next
&& (die
->next
->tag
== 0))
4851 if (die
->has_children
)
4861 while (nesting_level
);
4862 if (die
&& (die
->tag
== 0))
4873 /* Get linkage name of a die, return NULL if not found. */
4876 dwarf2_linkage_name (struct die_info
*die
)
4878 struct attribute
*attr
;
4880 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4881 if (attr
&& DW_STRING (attr
))
4882 return DW_STRING (attr
);
4883 attr
= dwarf_attr (die
, DW_AT_name
);
4884 if (attr
&& DW_STRING (attr
))
4885 return DW_STRING (attr
);
4889 /* Convert a DIE tag into its string name. */
4892 dwarf_tag_name (register unsigned tag
)
4896 case DW_TAG_padding
:
4897 return "DW_TAG_padding";
4898 case DW_TAG_array_type
:
4899 return "DW_TAG_array_type";
4900 case DW_TAG_class_type
:
4901 return "DW_TAG_class_type";
4902 case DW_TAG_entry_point
:
4903 return "DW_TAG_entry_point";
4904 case DW_TAG_enumeration_type
:
4905 return "DW_TAG_enumeration_type";
4906 case DW_TAG_formal_parameter
:
4907 return "DW_TAG_formal_parameter";
4908 case DW_TAG_imported_declaration
:
4909 return "DW_TAG_imported_declaration";
4911 return "DW_TAG_label";
4912 case DW_TAG_lexical_block
:
4913 return "DW_TAG_lexical_block";
4915 return "DW_TAG_member";
4916 case DW_TAG_pointer_type
:
4917 return "DW_TAG_pointer_type";
4918 case DW_TAG_reference_type
:
4919 return "DW_TAG_reference_type";
4920 case DW_TAG_compile_unit
:
4921 return "DW_TAG_compile_unit";
4922 case DW_TAG_string_type
:
4923 return "DW_TAG_string_type";
4924 case DW_TAG_structure_type
:
4925 return "DW_TAG_structure_type";
4926 case DW_TAG_subroutine_type
:
4927 return "DW_TAG_subroutine_type";
4928 case DW_TAG_typedef
:
4929 return "DW_TAG_typedef";
4930 case DW_TAG_union_type
:
4931 return "DW_TAG_union_type";
4932 case DW_TAG_unspecified_parameters
:
4933 return "DW_TAG_unspecified_parameters";
4934 case DW_TAG_variant
:
4935 return "DW_TAG_variant";
4936 case DW_TAG_common_block
:
4937 return "DW_TAG_common_block";
4938 case DW_TAG_common_inclusion
:
4939 return "DW_TAG_common_inclusion";
4940 case DW_TAG_inheritance
:
4941 return "DW_TAG_inheritance";
4942 case DW_TAG_inlined_subroutine
:
4943 return "DW_TAG_inlined_subroutine";
4945 return "DW_TAG_module";
4946 case DW_TAG_ptr_to_member_type
:
4947 return "DW_TAG_ptr_to_member_type";
4948 case DW_TAG_set_type
:
4949 return "DW_TAG_set_type";
4950 case DW_TAG_subrange_type
:
4951 return "DW_TAG_subrange_type";
4952 case DW_TAG_with_stmt
:
4953 return "DW_TAG_with_stmt";
4954 case DW_TAG_access_declaration
:
4955 return "DW_TAG_access_declaration";
4956 case DW_TAG_base_type
:
4957 return "DW_TAG_base_type";
4958 case DW_TAG_catch_block
:
4959 return "DW_TAG_catch_block";
4960 case DW_TAG_const_type
:
4961 return "DW_TAG_const_type";
4962 case DW_TAG_constant
:
4963 return "DW_TAG_constant";
4964 case DW_TAG_enumerator
:
4965 return "DW_TAG_enumerator";
4966 case DW_TAG_file_type
:
4967 return "DW_TAG_file_type";
4969 return "DW_TAG_friend";
4970 case DW_TAG_namelist
:
4971 return "DW_TAG_namelist";
4972 case DW_TAG_namelist_item
:
4973 return "DW_TAG_namelist_item";
4974 case DW_TAG_packed_type
:
4975 return "DW_TAG_packed_type";
4976 case DW_TAG_subprogram
:
4977 return "DW_TAG_subprogram";
4978 case DW_TAG_template_type_param
:
4979 return "DW_TAG_template_type_param";
4980 case DW_TAG_template_value_param
:
4981 return "DW_TAG_template_value_param";
4982 case DW_TAG_thrown_type
:
4983 return "DW_TAG_thrown_type";
4984 case DW_TAG_try_block
:
4985 return "DW_TAG_try_block";
4986 case DW_TAG_variant_part
:
4987 return "DW_TAG_variant_part";
4988 case DW_TAG_variable
:
4989 return "DW_TAG_variable";
4990 case DW_TAG_volatile_type
:
4991 return "DW_TAG_volatile_type";
4992 case DW_TAG_MIPS_loop
:
4993 return "DW_TAG_MIPS_loop";
4994 case DW_TAG_format_label
:
4995 return "DW_TAG_format_label";
4996 case DW_TAG_function_template
:
4997 return "DW_TAG_function_template";
4998 case DW_TAG_class_template
:
4999 return "DW_TAG_class_template";
5001 return "DW_TAG_<unknown>";
5005 /* Convert a DWARF attribute code into its string name. */
5008 dwarf_attr_name (register unsigned attr
)
5013 return "DW_AT_sibling";
5014 case DW_AT_location
:
5015 return "DW_AT_location";
5017 return "DW_AT_name";
5018 case DW_AT_ordering
:
5019 return "DW_AT_ordering";
5020 case DW_AT_subscr_data
:
5021 return "DW_AT_subscr_data";
5022 case DW_AT_byte_size
:
5023 return "DW_AT_byte_size";
5024 case DW_AT_bit_offset
:
5025 return "DW_AT_bit_offset";
5026 case DW_AT_bit_size
:
5027 return "DW_AT_bit_size";
5028 case DW_AT_element_list
:
5029 return "DW_AT_element_list";
5030 case DW_AT_stmt_list
:
5031 return "DW_AT_stmt_list";
5033 return "DW_AT_low_pc";
5035 return "DW_AT_high_pc";
5036 case DW_AT_language
:
5037 return "DW_AT_language";
5039 return "DW_AT_member";
5041 return "DW_AT_discr";
5042 case DW_AT_discr_value
:
5043 return "DW_AT_discr_value";
5044 case DW_AT_visibility
:
5045 return "DW_AT_visibility";
5047 return "DW_AT_import";
5048 case DW_AT_string_length
:
5049 return "DW_AT_string_length";
5050 case DW_AT_common_reference
:
5051 return "DW_AT_common_reference";
5052 case DW_AT_comp_dir
:
5053 return "DW_AT_comp_dir";
5054 case DW_AT_const_value
:
5055 return "DW_AT_const_value";
5056 case DW_AT_containing_type
:
5057 return "DW_AT_containing_type";
5058 case DW_AT_default_value
:
5059 return "DW_AT_default_value";
5061 return "DW_AT_inline";
5062 case DW_AT_is_optional
:
5063 return "DW_AT_is_optional";
5064 case DW_AT_lower_bound
:
5065 return "DW_AT_lower_bound";
5066 case DW_AT_producer
:
5067 return "DW_AT_producer";
5068 case DW_AT_prototyped
:
5069 return "DW_AT_prototyped";
5070 case DW_AT_return_addr
:
5071 return "DW_AT_return_addr";
5072 case DW_AT_start_scope
:
5073 return "DW_AT_start_scope";
5074 case DW_AT_stride_size
:
5075 return "DW_AT_stride_size";
5076 case DW_AT_upper_bound
:
5077 return "DW_AT_upper_bound";
5078 case DW_AT_abstract_origin
:
5079 return "DW_AT_abstract_origin";
5080 case DW_AT_accessibility
:
5081 return "DW_AT_accessibility";
5082 case DW_AT_address_class
:
5083 return "DW_AT_address_class";
5084 case DW_AT_artificial
:
5085 return "DW_AT_artificial";
5086 case DW_AT_base_types
:
5087 return "DW_AT_base_types";
5088 case DW_AT_calling_convention
:
5089 return "DW_AT_calling_convention";
5091 return "DW_AT_count";
5092 case DW_AT_data_member_location
:
5093 return "DW_AT_data_member_location";
5094 case DW_AT_decl_column
:
5095 return "DW_AT_decl_column";
5096 case DW_AT_decl_file
:
5097 return "DW_AT_decl_file";
5098 case DW_AT_decl_line
:
5099 return "DW_AT_decl_line";
5100 case DW_AT_declaration
:
5101 return "DW_AT_declaration";
5102 case DW_AT_discr_list
:
5103 return "DW_AT_discr_list";
5104 case DW_AT_encoding
:
5105 return "DW_AT_encoding";
5106 case DW_AT_external
:
5107 return "DW_AT_external";
5108 case DW_AT_frame_base
:
5109 return "DW_AT_frame_base";
5111 return "DW_AT_friend";
5112 case DW_AT_identifier_case
:
5113 return "DW_AT_identifier_case";
5114 case DW_AT_macro_info
:
5115 return "DW_AT_macro_info";
5116 case DW_AT_namelist_items
:
5117 return "DW_AT_namelist_items";
5118 case DW_AT_priority
:
5119 return "DW_AT_priority";
5121 return "DW_AT_segment";
5122 case DW_AT_specification
:
5123 return "DW_AT_specification";
5124 case DW_AT_static_link
:
5125 return "DW_AT_static_link";
5127 return "DW_AT_type";
5128 case DW_AT_use_location
:
5129 return "DW_AT_use_location";
5130 case DW_AT_variable_parameter
:
5131 return "DW_AT_variable_parameter";
5132 case DW_AT_virtuality
:
5133 return "DW_AT_virtuality";
5134 case DW_AT_vtable_elem_location
:
5135 return "DW_AT_vtable_elem_location";
5138 case DW_AT_MIPS_fde
:
5139 return "DW_AT_MIPS_fde";
5140 case DW_AT_MIPS_loop_begin
:
5141 return "DW_AT_MIPS_loop_begin";
5142 case DW_AT_MIPS_tail_loop_begin
:
5143 return "DW_AT_MIPS_tail_loop_begin";
5144 case DW_AT_MIPS_epilog_begin
:
5145 return "DW_AT_MIPS_epilog_begin";
5146 case DW_AT_MIPS_loop_unroll_factor
:
5147 return "DW_AT_MIPS_loop_unroll_factor";
5148 case DW_AT_MIPS_software_pipeline_depth
:
5149 return "DW_AT_MIPS_software_pipeline_depth";
5150 case DW_AT_MIPS_linkage_name
:
5151 return "DW_AT_MIPS_linkage_name";
5154 case DW_AT_sf_names
:
5155 return "DW_AT_sf_names";
5156 case DW_AT_src_info
:
5157 return "DW_AT_src_info";
5158 case DW_AT_mac_info
:
5159 return "DW_AT_mac_info";
5160 case DW_AT_src_coords
:
5161 return "DW_AT_src_coords";
5162 case DW_AT_body_begin
:
5163 return "DW_AT_body_begin";
5164 case DW_AT_body_end
:
5165 return "DW_AT_body_end";
5167 return "DW_AT_<unknown>";
5171 /* Convert a DWARF value form code into its string name. */
5174 dwarf_form_name (register unsigned form
)
5179 return "DW_FORM_addr";
5180 case DW_FORM_block2
:
5181 return "DW_FORM_block2";
5182 case DW_FORM_block4
:
5183 return "DW_FORM_block4";
5185 return "DW_FORM_data2";
5187 return "DW_FORM_data4";
5189 return "DW_FORM_data8";
5190 case DW_FORM_string
:
5191 return "DW_FORM_string";
5193 return "DW_FORM_block";
5194 case DW_FORM_block1
:
5195 return "DW_FORM_block1";
5197 return "DW_FORM_data1";
5199 return "DW_FORM_flag";
5201 return "DW_FORM_sdata";
5203 return "DW_FORM_strp";
5205 return "DW_FORM_udata";
5206 case DW_FORM_ref_addr
:
5207 return "DW_FORM_ref_addr";
5209 return "DW_FORM_ref1";
5211 return "DW_FORM_ref2";
5213 return "DW_FORM_ref4";
5215 return "DW_FORM_ref8";
5216 case DW_FORM_ref_udata
:
5217 return "DW_FORM_ref_udata";
5218 case DW_FORM_indirect
:
5219 return "DW_FORM_indirect";
5221 return "DW_FORM_<unknown>";
5225 /* Convert a DWARF stack opcode into its string name. */
5228 dwarf_stack_op_name (register unsigned op
)
5233 return "DW_OP_addr";
5235 return "DW_OP_deref";
5237 return "DW_OP_const1u";
5239 return "DW_OP_const1s";
5241 return "DW_OP_const2u";
5243 return "DW_OP_const2s";
5245 return "DW_OP_const4u";
5247 return "DW_OP_const4s";
5249 return "DW_OP_const8u";
5251 return "DW_OP_const8s";
5253 return "DW_OP_constu";
5255 return "DW_OP_consts";
5259 return "DW_OP_drop";
5261 return "DW_OP_over";
5263 return "DW_OP_pick";
5265 return "DW_OP_swap";
5269 return "DW_OP_xderef";
5277 return "DW_OP_minus";
5289 return "DW_OP_plus";
5290 case DW_OP_plus_uconst
:
5291 return "DW_OP_plus_uconst";
5297 return "DW_OP_shra";
5315 return "DW_OP_skip";
5317 return "DW_OP_lit0";
5319 return "DW_OP_lit1";
5321 return "DW_OP_lit2";
5323 return "DW_OP_lit3";
5325 return "DW_OP_lit4";
5327 return "DW_OP_lit5";
5329 return "DW_OP_lit6";
5331 return "DW_OP_lit7";
5333 return "DW_OP_lit8";
5335 return "DW_OP_lit9";
5337 return "DW_OP_lit10";
5339 return "DW_OP_lit11";
5341 return "DW_OP_lit12";
5343 return "DW_OP_lit13";
5345 return "DW_OP_lit14";
5347 return "DW_OP_lit15";
5349 return "DW_OP_lit16";
5351 return "DW_OP_lit17";
5353 return "DW_OP_lit18";
5355 return "DW_OP_lit19";
5357 return "DW_OP_lit20";
5359 return "DW_OP_lit21";
5361 return "DW_OP_lit22";
5363 return "DW_OP_lit23";
5365 return "DW_OP_lit24";
5367 return "DW_OP_lit25";
5369 return "DW_OP_lit26";
5371 return "DW_OP_lit27";
5373 return "DW_OP_lit28";
5375 return "DW_OP_lit29";
5377 return "DW_OP_lit30";
5379 return "DW_OP_lit31";
5381 return "DW_OP_reg0";
5383 return "DW_OP_reg1";
5385 return "DW_OP_reg2";
5387 return "DW_OP_reg3";
5389 return "DW_OP_reg4";
5391 return "DW_OP_reg5";
5393 return "DW_OP_reg6";
5395 return "DW_OP_reg7";
5397 return "DW_OP_reg8";
5399 return "DW_OP_reg9";
5401 return "DW_OP_reg10";
5403 return "DW_OP_reg11";
5405 return "DW_OP_reg12";
5407 return "DW_OP_reg13";
5409 return "DW_OP_reg14";
5411 return "DW_OP_reg15";
5413 return "DW_OP_reg16";
5415 return "DW_OP_reg17";
5417 return "DW_OP_reg18";
5419 return "DW_OP_reg19";
5421 return "DW_OP_reg20";
5423 return "DW_OP_reg21";
5425 return "DW_OP_reg22";
5427 return "DW_OP_reg23";
5429 return "DW_OP_reg24";
5431 return "DW_OP_reg25";
5433 return "DW_OP_reg26";
5435 return "DW_OP_reg27";
5437 return "DW_OP_reg28";
5439 return "DW_OP_reg29";
5441 return "DW_OP_reg30";
5443 return "DW_OP_reg31";
5445 return "DW_OP_breg0";
5447 return "DW_OP_breg1";
5449 return "DW_OP_breg2";
5451 return "DW_OP_breg3";
5453 return "DW_OP_breg4";
5455 return "DW_OP_breg5";
5457 return "DW_OP_breg6";
5459 return "DW_OP_breg7";
5461 return "DW_OP_breg8";
5463 return "DW_OP_breg9";
5465 return "DW_OP_breg10";
5467 return "DW_OP_breg11";
5469 return "DW_OP_breg12";
5471 return "DW_OP_breg13";
5473 return "DW_OP_breg14";
5475 return "DW_OP_breg15";
5477 return "DW_OP_breg16";
5479 return "DW_OP_breg17";
5481 return "DW_OP_breg18";
5483 return "DW_OP_breg19";
5485 return "DW_OP_breg20";
5487 return "DW_OP_breg21";
5489 return "DW_OP_breg22";
5491 return "DW_OP_breg23";
5493 return "DW_OP_breg24";
5495 return "DW_OP_breg25";
5497 return "DW_OP_breg26";
5499 return "DW_OP_breg27";
5501 return "DW_OP_breg28";
5503 return "DW_OP_breg29";
5505 return "DW_OP_breg30";
5507 return "DW_OP_breg31";
5509 return "DW_OP_regx";
5511 return "DW_OP_fbreg";
5513 return "DW_OP_bregx";
5515 return "DW_OP_piece";
5516 case DW_OP_deref_size
:
5517 return "DW_OP_deref_size";
5518 case DW_OP_xderef_size
:
5519 return "DW_OP_xderef_size";
5523 return "OP_<unknown>";
5528 dwarf_bool_name (unsigned mybool
)
5536 /* Convert a DWARF type code into its string name. */
5539 dwarf_type_encoding_name (register unsigned enc
)
5543 case DW_ATE_address
:
5544 return "DW_ATE_address";
5545 case DW_ATE_boolean
:
5546 return "DW_ATE_boolean";
5547 case DW_ATE_complex_float
:
5548 return "DW_ATE_complex_float";
5550 return "DW_ATE_float";
5552 return "DW_ATE_signed";
5553 case DW_ATE_signed_char
:
5554 return "DW_ATE_signed_char";
5555 case DW_ATE_unsigned
:
5556 return "DW_ATE_unsigned";
5557 case DW_ATE_unsigned_char
:
5558 return "DW_ATE_unsigned_char";
5560 return "DW_ATE_<unknown>";
5564 /* Convert a DWARF call frame info operation to its string name. */
5568 dwarf_cfi_name (register unsigned cfi_opc
)
5572 case DW_CFA_advance_loc
:
5573 return "DW_CFA_advance_loc";
5575 return "DW_CFA_offset";
5576 case DW_CFA_restore
:
5577 return "DW_CFA_restore";
5579 return "DW_CFA_nop";
5580 case DW_CFA_set_loc
:
5581 return "DW_CFA_set_loc";
5582 case DW_CFA_advance_loc1
:
5583 return "DW_CFA_advance_loc1";
5584 case DW_CFA_advance_loc2
:
5585 return "DW_CFA_advance_loc2";
5586 case DW_CFA_advance_loc4
:
5587 return "DW_CFA_advance_loc4";
5588 case DW_CFA_offset_extended
:
5589 return "DW_CFA_offset_extended";
5590 case DW_CFA_restore_extended
:
5591 return "DW_CFA_restore_extended";
5592 case DW_CFA_undefined
:
5593 return "DW_CFA_undefined";
5594 case DW_CFA_same_value
:
5595 return "DW_CFA_same_value";
5596 case DW_CFA_register
:
5597 return "DW_CFA_register";
5598 case DW_CFA_remember_state
:
5599 return "DW_CFA_remember_state";
5600 case DW_CFA_restore_state
:
5601 return "DW_CFA_restore_state";
5602 case DW_CFA_def_cfa
:
5603 return "DW_CFA_def_cfa";
5604 case DW_CFA_def_cfa_register
:
5605 return "DW_CFA_def_cfa_register";
5606 case DW_CFA_def_cfa_offset
:
5607 return "DW_CFA_def_cfa_offset";
5608 /* SGI/MIPS specific */
5609 case DW_CFA_MIPS_advance_loc8
:
5610 return "DW_CFA_MIPS_advance_loc8";
5612 return "DW_CFA_<unknown>";
5618 dump_die (struct die_info
*die
)
5622 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5623 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5624 fprintf (stderr
, "\thas children: %s\n",
5625 dwarf_bool_name (die
->has_children
));
5627 fprintf (stderr
, "\tattributes:\n");
5628 for (i
= 0; i
< die
->num_attrs
; ++i
)
5630 fprintf (stderr
, "\t\t%s (%s) ",
5631 dwarf_attr_name (die
->attrs
[i
].name
),
5632 dwarf_form_name (die
->attrs
[i
].form
));
5633 switch (die
->attrs
[i
].form
)
5635 case DW_FORM_ref_addr
:
5637 fprintf (stderr
, "address: ");
5638 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5640 case DW_FORM_block2
:
5641 case DW_FORM_block4
:
5643 case DW_FORM_block1
:
5644 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5655 fprintf (stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
5657 case DW_FORM_string
:
5659 fprintf (stderr
, "string: \"%s\"",
5660 DW_STRING (&die
->attrs
[i
])
5661 ? DW_STRING (&die
->attrs
[i
]) : "");
5664 if (DW_UNSND (&die
->attrs
[i
]))
5665 fprintf (stderr
, "flag: TRUE");
5667 fprintf (stderr
, "flag: FALSE");
5669 case DW_FORM_indirect
:
5670 /* the reader will have reduced the indirect form to
5671 the "base form" so this form should not occur */
5672 fprintf (stderr
, "unexpected attribute form: DW_FORM_indirect");
5675 fprintf (stderr
, "unsupported attribute form: %d.",
5676 die
->attrs
[i
].form
);
5678 fprintf (stderr
, "\n");
5683 dump_die_list (struct die_info
*die
)
5693 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
5696 struct die_info
*old
;
5698 h
= (offset
% REF_HASH_SIZE
);
5699 old
= die_ref_table
[h
];
5700 die
->next_ref
= old
;
5701 die_ref_table
[h
] = die
;
5706 dwarf2_empty_hash_tables (void)
5708 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5712 dwarf2_get_ref_die_offset (struct attribute
*attr
)
5714 unsigned int result
= 0;
5718 case DW_FORM_ref_addr
:
5719 result
= DW_ADDR (attr
);
5725 case DW_FORM_ref_udata
:
5726 result
= cu_header_offset
+ DW_UNSND (attr
);
5729 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5734 static struct die_info
*
5735 follow_die_ref (unsigned int offset
)
5737 struct die_info
*die
;
5740 h
= (offset
% REF_HASH_SIZE
);
5741 die
= die_ref_table
[h
];
5744 if (die
->offset
== offset
)
5748 die
= die
->next_ref
;
5753 static struct type
*
5754 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
5756 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5758 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5762 /* Look for this particular type in the fundamental type vector. If
5763 one is not found, create and install one appropriate for the
5764 current language and the current target machine. */
5766 if (ftypes
[typeid] == NULL
)
5768 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5771 return (ftypes
[typeid]);
5774 /* Decode simple location descriptions.
5775 Given a pointer to a dwarf block that defines a location, compute
5776 the location and return the value.
5778 FIXME: This is a kludge until we figure out a better
5779 way to handle the location descriptions.
5780 Gdb's design does not mesh well with the DWARF2 notion of a location
5781 computing interpreter, which is a shame because the flexibility goes unused.
5782 FIXME: Implement more operations as necessary.
5784 A location description containing no operations indicates that the
5785 object is optimized out. The global optimized_out flag is set for
5786 those, the return value is meaningless.
5788 When the result is a register number, the global isreg flag is set,
5789 otherwise it is cleared.
5791 When the result is a base register offset, the global offreg flag is set
5792 and the register number is returned in basereg, otherwise it is cleared.
5794 When the DW_OP_fbreg operation is encountered without a corresponding
5795 DW_AT_frame_base attribute, the global islocal flag is set.
5796 Hopefully the machine dependent code knows how to set up a virtual
5797 frame pointer for the local references.
5799 Note that stack[0] is unused except as a default error return.
5800 Note that stack overflow is not yet handled. */
5803 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
5804 const struct comp_unit_head
*cu_header
)
5807 int size
= blk
->size
;
5808 char *data
= blk
->data
;
5809 CORE_ADDR stack
[64];
5811 unsigned int bytes_read
, unsnd
;
5861 stack
[++stacki
] = op
- DW_OP_lit0
;
5897 stack
[++stacki
] = op
- DW_OP_reg0
;
5902 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5904 #if defined(HARRIS_TARGET) && defined(_M88K)
5905 /* The Harris 88110 gdb ports have long kept their special reg
5906 numbers between their gp-regs and their x-regs. This is
5907 not how our dwarf is generated. Punt. */
5910 stack
[++stacki
] = unsnd
;
5946 basereg
= op
- DW_OP_breg0
;
5947 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5953 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5955 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5960 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5962 if (frame_base_reg
>= 0)
5965 basereg
= frame_base_reg
;
5966 stack
[stacki
] += frame_base_offset
;
5970 complain (&dwarf2_missing_at_frame_base
);
5976 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
5977 cu_header
, &bytes_read
);
5982 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5987 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5992 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5997 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
6002 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
6007 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
6012 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
6018 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6023 stack
[stacki
+ 1] = stack
[stacki
];
6028 stack
[stacki
- 1] += stack
[stacki
];
6032 case DW_OP_plus_uconst
:
6033 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6038 stack
[stacki
- 1] -= stack
[stacki
];
6044 /* If we're not the last op, then we definitely can't encode
6045 this using GDB's address_class enum. */
6047 complain (&dwarf2_complex_location_expr
);
6051 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
6052 return (stack
[stacki
]);
6055 return (stack
[stacki
]);
6058 /* memory allocation interface */
6062 dwarf2_free_tmp_obstack (PTR ignore
)
6064 obstack_free (&dwarf2_tmp_obstack
, NULL
);
6067 static struct dwarf_block
*
6068 dwarf_alloc_block (void)
6070 struct dwarf_block
*blk
;
6072 blk
= (struct dwarf_block
*)
6073 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
6077 static struct abbrev_info
*
6078 dwarf_alloc_abbrev (void)
6080 struct abbrev_info
*abbrev
;
6082 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
6083 memset (abbrev
, 0, sizeof (struct abbrev_info
));
6087 static struct die_info
*
6088 dwarf_alloc_die (void)
6090 struct die_info
*die
;
6092 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6093 memset (die
, 0, sizeof (struct die_info
));