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 <sys/types.h>
48 #ifndef DWARF2_REG_TO_REGNUM
49 #define DWARF2_REG_TO_REGNUM(REG) (REG)
53 /* .debug_info header for a compilation unit
54 Because of alignment constraints, this structure has padding and cannot
55 be mapped directly onto the beginning of the .debug_info section. */
56 typedef struct comp_unit_header
58 unsigned int length
; /* length of the .debug_info
60 unsigned short version
; /* version number -- 2 for DWARF
62 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
63 unsigned char addr_size
; /* byte size of an address -- 4 */
66 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
69 /* .debug_pubnames header
70 Because of alignment constraints, this structure has padding and cannot
71 be mapped directly onto the beginning of the .debug_info section. */
72 typedef struct pubnames_header
74 unsigned int length
; /* length of the .debug_pubnames
76 unsigned char version
; /* version number -- 2 for DWARF
78 unsigned int info_offset
; /* offset into .debug_info section */
79 unsigned int info_size
; /* byte size of .debug_info section
83 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
85 /* .debug_pubnames header
86 Because of alignment constraints, this structure has padding and cannot
87 be mapped directly onto the beginning of the .debug_info section. */
88 typedef struct aranges_header
90 unsigned int length
; /* byte len of the .debug_aranges
92 unsigned short version
; /* version number -- 2 for DWARF
94 unsigned int info_offset
; /* offset into .debug_info section */
95 unsigned char addr_size
; /* byte size of an address */
96 unsigned char seg_size
; /* byte size of segment descriptor */
99 #define _ACTUAL_ARANGES_HEADER_SIZE 12
101 /* .debug_line statement program prologue
102 Because of alignment constraints, this structure has padding and cannot
103 be mapped directly onto the beginning of the .debug_info section. */
104 typedef struct statement_prologue
106 unsigned int total_length
; /* byte length of the statement
108 unsigned short version
; /* version number -- 2 for DWARF
110 unsigned int prologue_length
; /* # bytes between prologue &
112 unsigned char minimum_instruction_length
; /* byte size of
114 unsigned char default_is_stmt
; /* initial value of is_stmt
117 unsigned char line_range
;
118 unsigned char opcode_base
; /* number assigned to first special
120 unsigned char *standard_opcode_lengths
;
124 /* offsets and sizes of debugging sections */
126 static file_ptr dwarf_info_offset
;
127 static file_ptr dwarf_abbrev_offset
;
128 static file_ptr dwarf_line_offset
;
129 static file_ptr dwarf_pubnames_offset
;
130 static file_ptr dwarf_aranges_offset
;
131 static file_ptr dwarf_loc_offset
;
132 static file_ptr dwarf_macinfo_offset
;
133 static file_ptr dwarf_str_offset
;
135 static unsigned int dwarf_info_size
;
136 static unsigned int dwarf_abbrev_size
;
137 static unsigned int dwarf_line_size
;
138 static unsigned int dwarf_pubnames_size
;
139 static unsigned int dwarf_aranges_size
;
140 static unsigned int dwarf_loc_size
;
141 static unsigned int dwarf_macinfo_size
;
142 static unsigned int dwarf_str_size
;
144 /* names of the debugging sections */
146 #define INFO_SECTION ".debug_info"
147 #define ABBREV_SECTION ".debug_abbrev"
148 #define LINE_SECTION ".debug_line"
149 #define PUBNAMES_SECTION ".debug_pubnames"
150 #define ARANGES_SECTION ".debug_aranges"
151 #define LOC_SECTION ".debug_loc"
152 #define MACINFO_SECTION ".debug_macinfo"
153 #define STR_SECTION ".debug_str"
155 /* local data types */
157 /* The data in a compilation unit header, after target2host
158 translation, looks like this. */
159 struct comp_unit_head
161 unsigned long length
;
163 unsigned int abbrev_offset
;
164 unsigned char addr_size
;
165 unsigned char signed_addr_p
;
166 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
167 unsigned int initial_length_size
; /* size of the length field; either
171 /* The data in the .debug_line statement prologue looks like this. */
174 unsigned int total_length
;
175 unsigned short version
;
176 unsigned int prologue_length
;
177 unsigned char minimum_instruction_length
;
178 unsigned char default_is_stmt
;
180 unsigned char line_range
;
181 unsigned char opcode_base
;
182 unsigned char *standard_opcode_lengths
;
185 /* When we construct a partial symbol table entry we only
186 need this much information. */
187 struct partial_die_info
190 unsigned char has_children
;
191 unsigned char is_external
;
192 unsigned char is_declaration
;
193 unsigned char has_type
;
200 struct dwarf_block
*locdesc
;
201 unsigned int language
;
205 /* This data structure holds the information of an abbrev. */
208 unsigned int number
; /* number identifying abbrev */
209 enum dwarf_tag tag
; /* dwarf tag */
210 int has_children
; /* boolean */
211 unsigned int num_attrs
; /* number of attributes */
212 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
213 struct abbrev_info
*next
; /* next in chain */
218 enum dwarf_attribute name
;
219 enum dwarf_form form
;
222 /* This data structure holds a complete die structure. */
225 enum dwarf_tag tag
; /* Tag indicating type of die */
226 unsigned short has_children
; /* Does the die have children */
227 unsigned int abbrev
; /* Abbrev number */
228 unsigned int offset
; /* Offset in .debug_info section */
229 unsigned int num_attrs
; /* Number of attributes */
230 struct attribute
*attrs
; /* An array of attributes */
231 struct die_info
*next_ref
; /* Next die in ref hash table */
232 struct die_info
*next
; /* Next die in linked list */
233 struct type
*type
; /* Cached type information */
236 /* Attributes have a name and a value */
239 enum dwarf_attribute name
;
240 enum dwarf_form form
;
244 struct dwarf_block
*blk
;
252 /* Get at parts of an attribute structure */
254 #define DW_STRING(attr) ((attr)->u.str)
255 #define DW_UNSND(attr) ((attr)->u.unsnd)
256 #define DW_BLOCK(attr) ((attr)->u.blk)
257 #define DW_SND(attr) ((attr)->u.snd)
258 #define DW_ADDR(attr) ((attr)->u.addr)
260 /* Blocks are a bunch of untyped bytes. */
267 /* We only hold one compilation unit's abbrevs in
268 memory at any one time. */
269 #ifndef ABBREV_HASH_SIZE
270 #define ABBREV_HASH_SIZE 121
272 #ifndef ATTR_ALLOC_CHUNK
273 #define ATTR_ALLOC_CHUNK 4
276 static struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
278 /* A hash table of die offsets for following references. */
279 #ifndef REF_HASH_SIZE
280 #define REF_HASH_SIZE 1021
283 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
285 /* Obstack for allocating temporary storage used during symbol reading. */
286 static struct obstack dwarf2_tmp_obstack
;
288 /* Offset to the first byte of the current compilation unit header,
289 for resolving relative reference dies. */
290 static unsigned int cu_header_offset
;
292 /* Allocate fields for structs, unions and enums in this size. */
293 #ifndef DW_FIELD_ALLOC_CHUNK
294 #define DW_FIELD_ALLOC_CHUNK 4
297 /* The language we are debugging. */
298 static enum language cu_language
;
299 static const struct language_defn
*cu_language_defn
;
301 /* Actually data from the sections. */
302 static char *dwarf_info_buffer
;
303 static char *dwarf_abbrev_buffer
;
304 static char *dwarf_line_buffer
;
306 /* A zeroed version of a partial die for initialization purposes. */
307 static struct partial_die_info zeroed_partial_die
;
309 /* The generic symbol table building routines have separate lists for
310 file scope symbols and all all other scopes (local scopes). So
311 we need to select the right one to pass to add_symbol_to_list().
312 We do it by keeping a pointer to the correct list in list_in_scope.
314 FIXME: The original dwarf code just treated the file scope as the first
315 local scope, and all other local scopes as nested local scopes, and worked
316 fine. Check to see if we really need to distinguish these
318 static struct pending
**list_in_scope
= &file_symbols
;
320 /* FIXME: decode_locdesc sets these variables to describe the location
321 to the caller. These ought to be a structure or something. If
322 none of the flags are set, the object lives at the address returned
323 by decode_locdesc. */
325 static int optimized_out
; /* No ops in location in expression,
326 so object was optimized out. */
327 static int isreg
; /* Object lives in register.
328 decode_locdesc's return value is
329 the register number. */
330 static int offreg
; /* Object's address is the sum of the
331 register specified by basereg, plus
332 the offset returned. */
333 static int basereg
; /* See `offreg'. */
334 static int isderef
; /* Value described by flags above is
335 the address of a pointer to the object. */
336 static int islocal
; /* Variable is at the returned offset
337 from the frame start, but there's
338 no identified frame pointer for
339 this function, so we can't say
340 which register it's relative to;
343 /* DW_AT_frame_base values for the current function.
344 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
345 contains the register number for the frame register.
346 frame_base_offset is the offset from the frame register to the
347 virtual stack frame. */
348 static int frame_base_reg
;
349 static CORE_ADDR frame_base_offset
;
351 /* This value is added to each symbol value. FIXME: Generalize to
352 the section_offsets structure used by dbxread (once this is done,
353 pass the appropriate section number to end_symtab). */
354 static CORE_ADDR baseaddr
; /* Add to each symbol value */
356 /* We put a pointer to this structure in the read_symtab_private field
358 The complete dwarf information for an objfile is kept in the
359 psymbol_obstack, so that absolute die references can be handled.
360 Most of the information in this structure is related to an entire
361 object file and could be passed via the sym_private field of the objfile.
362 It is however conceivable that dwarf2 might not be the only type
363 of symbols read from an object file. */
367 /* Pointer to start of dwarf info buffer for the objfile. */
369 char *dwarf_info_buffer
;
371 /* Offset in dwarf_info_buffer for this compilation unit. */
373 unsigned long dwarf_info_offset
;
375 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
377 char *dwarf_abbrev_buffer
;
379 /* Size of dwarf abbreviation section for the objfile. */
381 unsigned int dwarf_abbrev_size
;
383 /* Pointer to start of dwarf line buffer for the objfile. */
385 char *dwarf_line_buffer
;
388 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
389 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
390 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
391 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
392 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
393 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
395 /* Maintain an array of referenced fundamental types for the current
396 compilation unit being read. For DWARF version 1, we have to construct
397 the fundamental types on the fly, since no information about the
398 fundamental types is supplied. Each such fundamental type is created by
399 calling a language dependent routine to create the type, and then a
400 pointer to that type is then placed in the array at the index specified
401 by it's FT_<TYPENAME> value. The array has a fixed size set by the
402 FT_NUM_MEMBERS compile time constant, which is the number of predefined
403 fundamental types gdb knows how to construct. */
404 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
406 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
407 but this would require a corresponding change in unpack_field_as_long
409 static int bits_per_byte
= 8;
411 /* The routines that read and process dies for a C struct or C++ class
412 pass lists of data member fields and lists of member function fields
413 in an instance of a field_info structure, as defined below. */
416 /* List of data member and baseclasses fields. */
419 struct nextfield
*next
;
426 /* Number of fields. */
429 /* Number of baseclasses. */
432 /* Set if the accesibility of one of the fields is not public. */
433 int non_public_fields
;
435 /* Member function fields array, entries are allocated in the order they
436 are encountered in the object file. */
439 struct nextfnfield
*next
;
440 struct fn_field fnfield
;
444 /* Member function fieldlist array, contains name of possibly overloaded
445 member function, number of overloaded member functions and a pointer
446 to the head of the member function field chain. */
451 struct nextfnfield
*head
;
455 /* Number of entries in the fnfieldlists array. */
459 /* FIXME: Kludge to mark a varargs function type for C++ member function
460 argument processing. */
461 #define TYPE_FLAG_VARARGS (1 << 10)
463 /* Dwarf2 has no clean way to discern C++ static and non-static member
464 functions. G++ helps GDB by marking the first parameter for non-static
465 member functions (which is the this pointer) as artificial.
466 We pass this information between dwarf2_add_member_fn and
467 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
468 #define TYPE_FIELD_ARTIFICIAL TYPE_FIELD_BITPOS
470 /* Various complaints about symbol reading that don't abort the process */
472 static struct complaint dwarf2_const_ignored
=
474 "type qualifier 'const' ignored", 0, 0
476 static struct complaint dwarf2_volatile_ignored
=
478 "type qualifier 'volatile' ignored", 0, 0
480 static struct complaint dwarf2_non_const_array_bound_ignored
=
482 "non-constant array bounds form '%s' ignored", 0, 0
484 static struct complaint dwarf2_missing_line_number_section
=
486 "missing .debug_line section", 0, 0
488 static struct complaint dwarf2_mangled_line_number_section
=
490 "mangled .debug_line section", 0, 0
492 static struct complaint dwarf2_unsupported_die_ref_attr
=
494 "unsupported die ref attribute form: '%s'", 0, 0
496 static struct complaint dwarf2_unsupported_stack_op
=
498 "unsupported stack op: '%s'", 0, 0
500 static struct complaint dwarf2_complex_location_expr
=
502 "location expression too complex", 0, 0
504 static struct complaint dwarf2_unsupported_tag
=
506 "unsupported tag: '%s'", 0, 0
508 static struct complaint dwarf2_unsupported_at_encoding
=
510 "unsupported DW_AT_encoding: '%s'", 0, 0
512 static struct complaint dwarf2_unsupported_at_frame_base
=
514 "unsupported DW_AT_frame_base for function '%s'", 0, 0
516 static struct complaint dwarf2_unexpected_tag
=
518 "unexepected tag in read_type_die: '%s'", 0, 0
520 static struct complaint dwarf2_missing_at_frame_base
=
522 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
524 static struct complaint dwarf2_bad_static_member_name
=
526 "unrecognized static data member name '%s'", 0, 0
528 static struct complaint dwarf2_unsupported_accessibility
=
530 "unsupported accessibility %d", 0, 0
532 static struct complaint dwarf2_bad_member_name_complaint
=
534 "cannot extract member name from '%s'", 0, 0
536 static struct complaint dwarf2_missing_member_fn_type_complaint
=
538 "member function type missing for '%s'", 0, 0
540 static struct complaint dwarf2_vtbl_not_found_complaint
=
542 "virtual function table pointer not found when defining class '%s'", 0, 0
544 static struct complaint dwarf2_absolute_sibling_complaint
=
546 "ignoring absolute DW_AT_sibling", 0, 0
548 static struct complaint dwarf2_const_value_length_mismatch
=
550 "const value length mismatch for '%s', got %d, expected %d", 0, 0
552 static struct complaint dwarf2_unsupported_const_value_attr
=
554 "unsupported const value attribute form: '%s'", 0, 0
557 /* Externals references. */
558 extern int info_verbose
; /* From main.c; nonzero => verbose */
560 /* local function prototypes */
562 static void dwarf2_locate_sections (bfd
*, asection
*, PTR
);
565 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
568 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
570 static char *scan_partial_symbols (char *, struct objfile
*,
571 CORE_ADDR
*, CORE_ADDR
*,
572 const struct comp_unit_head
*);
574 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
575 const struct comp_unit_head
*);
577 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
579 static void psymtab_to_symtab_1 (struct partial_symtab
*);
581 static char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int);
583 static void dwarf2_read_abbrevs (bfd
*, unsigned int);
585 static void dwarf2_empty_abbrev_table (PTR
);
587 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int);
589 static char *read_partial_die (struct partial_die_info
*,
591 const struct comp_unit_head
*);
593 static char *read_full_die (struct die_info
**, bfd
*, char *,
594 const struct comp_unit_head
*);
596 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
597 bfd
*, char *, const struct comp_unit_head
*);
599 static unsigned int read_1_byte (bfd
*, char *);
601 static int read_1_signed_byte (bfd
*, char *);
603 static unsigned int read_2_bytes (bfd
*, char *);
605 static unsigned int read_4_bytes (bfd
*, char *);
607 static unsigned long read_8_bytes (bfd
*, char *);
609 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
612 static LONGEST
read_initial_length (bfd
*, char *,
613 struct comp_unit_head
*, int *bytes_read
);
615 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
618 static char *read_n_bytes (bfd
*, char *, unsigned int);
620 static char *read_string (bfd
*, char *, unsigned int *);
622 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
624 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
626 static void set_cu_language (unsigned int);
628 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
630 static int die_is_declaration (struct die_info
*);
632 static void dwarf_decode_lines (unsigned int, char *, bfd
*,
633 const struct comp_unit_head
*);
635 static void dwarf2_start_subfile (char *, char *);
637 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
638 struct objfile
*, const struct comp_unit_head
*);
640 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
641 struct objfile
*, const struct comp_unit_head
*);
643 static void dwarf2_const_value_data (struct attribute
*attr
,
647 static struct type
*die_type (struct die_info
*, struct objfile
*,
648 const struct comp_unit_head
*);
650 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
651 const struct comp_unit_head
*);
654 static struct type
*type_at_offset (unsigned int, struct objfile
*);
657 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
658 const struct comp_unit_head
*);
660 static void read_type_die (struct die_info
*, struct objfile
*,
661 const struct comp_unit_head
*);
663 static void read_typedef (struct die_info
*, struct objfile
*,
664 const struct comp_unit_head
*);
666 static void read_base_type (struct die_info
*, struct objfile
*);
668 static void read_file_scope (struct die_info
*, struct objfile
*,
669 const struct comp_unit_head
*);
671 static void read_func_scope (struct die_info
*, struct objfile
*,
672 const struct comp_unit_head
*);
674 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
675 const struct comp_unit_head
*);
677 static int dwarf2_get_pc_bounds (struct die_info
*,
678 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*);
680 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
681 struct objfile
*, const struct comp_unit_head
*);
683 static void dwarf2_attach_fields_to_type (struct field_info
*,
684 struct type
*, struct objfile
*);
686 static void dwarf2_add_member_fn (struct field_info
*,
687 struct die_info
*, struct type
*,
688 struct objfile
*objfile
,
689 const struct comp_unit_head
*);
691 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
692 struct type
*, struct objfile
*);
694 static void read_structure_scope (struct die_info
*, struct objfile
*,
695 const struct comp_unit_head
*);
697 static void read_common_block (struct die_info
*, struct objfile
*,
698 const struct comp_unit_head
*);
700 static void read_enumeration (struct die_info
*, struct objfile
*,
701 const struct comp_unit_head
*);
703 static struct type
*dwarf_base_type (int, int, struct objfile
*);
705 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
706 const struct comp_unit_head
*);
708 static void read_array_type (struct die_info
*, struct objfile
*,
709 const struct comp_unit_head
*);
711 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
712 const struct comp_unit_head
*);
714 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
715 const struct comp_unit_head
*);
717 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
718 const struct comp_unit_head
*);
720 static void read_tag_const_type (struct die_info
*, struct objfile
*,
721 const struct comp_unit_head
*);
723 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
724 const struct comp_unit_head
*);
726 static void read_tag_string_type (struct die_info
*, struct objfile
*);
728 static void read_subroutine_type (struct die_info
*, struct objfile
*,
729 const struct comp_unit_head
*);
731 static struct die_info
*read_comp_unit (char *, bfd
*,
732 const struct comp_unit_head
*);
734 static void free_die_list (struct die_info
*);
736 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
738 static void process_die (struct die_info
*, struct objfile
*,
739 const struct comp_unit_head
*);
741 static char *dwarf2_linkage_name (struct die_info
*);
743 static char *dwarf_tag_name (unsigned int);
745 static char *dwarf_attr_name (unsigned int);
747 static char *dwarf_form_name (unsigned int);
749 static char *dwarf_stack_op_name (unsigned int);
751 static char *dwarf_bool_name (unsigned int);
753 static char *dwarf_type_encoding_name (unsigned int);
756 static char *dwarf_cfi_name (unsigned int);
758 struct die_info
*copy_die (struct die_info
*);
761 static struct die_info
*sibling_die (struct die_info
*);
763 static void dump_die (struct die_info
*);
765 static void dump_die_list (struct die_info
*);
767 static void store_in_ref_table (unsigned int, struct die_info
*);
769 static void dwarf2_empty_hash_tables (void);
771 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
773 static struct die_info
*follow_die_ref (unsigned int);
775 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
777 /* memory allocation interface */
779 static void dwarf2_free_tmp_obstack (PTR
);
781 static struct dwarf_block
*dwarf_alloc_block (void);
783 static struct abbrev_info
*dwarf_alloc_abbrev (void);
785 static struct die_info
*dwarf_alloc_die (void);
787 /* Try to locate the sections we need for DWARF 2 debugging
788 information and return true if we have enough to do something. */
791 dwarf2_has_info (bfd
*abfd
)
793 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
794 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
795 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
805 /* This function is mapped across the sections and remembers the
806 offset and size of each of the debugging sections we are interested
810 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, PTR ignore_ptr
)
812 if (STREQ (sectp
->name
, INFO_SECTION
))
814 dwarf_info_offset
= sectp
->filepos
;
815 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
817 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
819 dwarf_abbrev_offset
= sectp
->filepos
;
820 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
822 else if (STREQ (sectp
->name
, LINE_SECTION
))
824 dwarf_line_offset
= sectp
->filepos
;
825 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
827 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
829 dwarf_pubnames_offset
= sectp
->filepos
;
830 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
832 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
834 dwarf_aranges_offset
= sectp
->filepos
;
835 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
837 else if (STREQ (sectp
->name
, LOC_SECTION
))
839 dwarf_loc_offset
= sectp
->filepos
;
840 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
842 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
844 dwarf_macinfo_offset
= sectp
->filepos
;
845 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
847 else if (STREQ (sectp
->name
, STR_SECTION
))
849 dwarf_str_offset
= sectp
->filepos
;
850 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
854 /* Build a partial symbol table. */
857 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
860 /* We definitely need the .debug_info and .debug_abbrev sections */
862 dwarf_info_buffer
= dwarf2_read_section (objfile
,
865 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
868 dwarf_line_buffer
= dwarf2_read_section (objfile
,
872 if (mainline
|| objfile
->global_psymbols
.size
== 0 ||
873 objfile
->static_psymbols
.size
== 0)
875 init_psymbol_list (objfile
, 1024);
879 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
881 /* Things are significantly easier if we have .debug_aranges and
882 .debug_pubnames sections */
884 dwarf2_build_psymtabs_easy (objfile
, mainline
);
888 /* only test this case for now */
890 /* In this case we have to work a bit harder */
891 dwarf2_build_psymtabs_hard (objfile
, mainline
);
896 /* Build the partial symbol table from the information in the
897 .debug_pubnames and .debug_aranges sections. */
900 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
902 bfd
*abfd
= objfile
->obfd
;
903 char *aranges_buffer
, *pubnames_buffer
;
904 char *aranges_ptr
, *pubnames_ptr
;
905 unsigned int entry_length
, version
, info_offset
, info_size
;
907 pubnames_buffer
= dwarf2_read_section (objfile
,
908 dwarf_pubnames_offset
,
909 dwarf_pubnames_size
);
910 pubnames_ptr
= pubnames_buffer
;
911 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
913 struct comp_unit_head cu_header
;
916 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
918 pubnames_ptr
+= bytes_read
;
919 version
= read_1_byte (abfd
, pubnames_ptr
);
921 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
923 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
927 aranges_buffer
= dwarf2_read_section (objfile
,
928 dwarf_aranges_offset
,
934 /* Read in the comp unit header information from the debug_info at
938 read_comp_unit_head (struct comp_unit_head
*cu_header
,
939 char *info_ptr
, bfd
*abfd
)
943 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
945 info_ptr
+= bytes_read
;
946 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
948 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
950 info_ptr
+= bytes_read
;
951 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
953 signed_addr
= bfd_get_sign_extend_vma (abfd
);
955 internal_error (__FILE__
, __LINE__
,
956 "read_comp_unit_head: dwarf from non elf file");
957 cu_header
->signed_addr_p
= signed_addr
;
961 /* Build the partial symbol table by doing a quick pass through the
962 .debug_info and .debug_abbrev sections. */
965 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
967 /* Instead of reading this into a big buffer, we should probably use
968 mmap() on architectures that support it. (FIXME) */
969 bfd
*abfd
= objfile
->obfd
;
970 char *info_ptr
, *abbrev_ptr
;
971 char *beg_of_comp_unit
;
972 struct partial_die_info comp_unit_die
;
973 struct partial_symtab
*pst
;
974 struct cleanup
*back_to
;
975 CORE_ADDR lowpc
, highpc
;
977 info_ptr
= dwarf_info_buffer
;
978 abbrev_ptr
= dwarf_abbrev_buffer
;
980 obstack_init (&dwarf2_tmp_obstack
);
981 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
983 /* Since the objects we're extracting from dwarf_info_buffer vary in
984 length, only the individual functions to extract them (like
985 read_comp_unit_head and read_partial_die) can really know whether
986 the buffer is large enough to hold another complete object.
988 At the moment, they don't actually check that. If
989 dwarf_info_buffer holds just one extra byte after the last
990 compilation unit's dies, then read_comp_unit_head will happily
991 read off the end of the buffer. read_partial_die is similarly
992 casual. Those functions should be fixed.
994 For this loop condition, simply checking whether there's any data
995 left at all should be sufficient. */
996 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
998 struct comp_unit_head cu_header
;
999 beg_of_comp_unit
= info_ptr
;
1000 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1002 if (cu_header
.version
!= 2)
1004 error ("Dwarf Error: wrong version in compilation unit header.");
1007 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
1009 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
1010 (long) cu_header
.abbrev_offset
,
1011 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1014 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1015 > dwarf_info_buffer
+ dwarf_info_size
)
1017 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
1018 (long) cu_header
.length
,
1019 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1022 /* Read the abbrevs for this compilation unit into a table */
1023 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1024 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1026 /* Read the compilation unit die */
1027 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1030 /* Set the language we're debugging */
1031 set_cu_language (comp_unit_die
.language
);
1033 /* Allocate a new partial symbol table structure */
1034 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1035 comp_unit_die
.name
? comp_unit_die
.name
: "",
1036 comp_unit_die
.lowpc
,
1037 objfile
->global_psymbols
.next
,
1038 objfile
->static_psymbols
.next
);
1040 pst
->read_symtab_private
= (char *)
1041 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1042 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1043 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1044 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1045 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1046 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1047 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1048 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1050 /* Store the function that reads in the rest of the symbol table */
1051 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1053 /* Check if comp unit has_children.
1054 If so, read the rest of the partial symbols from this comp unit.
1055 If not, there's no more debug_info for this comp unit. */
1056 if (comp_unit_die
.has_children
)
1058 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1061 /* If the compilation unit didn't have an explicit address range,
1062 then use the information extracted from its child dies. */
1063 if (! comp_unit_die
.has_pc_info
)
1065 comp_unit_die
.lowpc
= lowpc
;
1066 comp_unit_die
.highpc
= highpc
;
1069 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1070 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1072 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1073 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1074 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1075 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1076 sort_pst_symbols (pst
);
1078 /* If there is already a psymtab or symtab for a file of this
1079 name, remove it. (If there is a symtab, more drastic things
1080 also happen.) This happens in VxWorks. */
1081 free_named_symtabs (pst
->filename
);
1083 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1084 + cu_header
.initial_length_size
;
1086 do_cleanups (back_to
);
1089 /* Read in all interesting dies to the end of the compilation unit. */
1092 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1093 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1094 const struct comp_unit_head
*cu_header
)
1096 bfd
*abfd
= objfile
->obfd
;
1097 struct partial_die_info pdi
;
1099 /* This function is called after we've read in the comp_unit_die in
1100 order to read its children. We start the nesting level at 1 since
1101 we have pushed 1 level down in order to read the comp unit's children.
1102 The comp unit itself is at level 0, so we stop reading when we pop
1103 back to that level. */
1105 int nesting_level
= 1;
1107 *lowpc
= ((CORE_ADDR
) -1);
1108 *highpc
= ((CORE_ADDR
) 0);
1110 while (nesting_level
)
1112 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1118 case DW_TAG_subprogram
:
1119 if (pdi
.has_pc_info
)
1121 if (pdi
.lowpc
< *lowpc
)
1125 if (pdi
.highpc
> *highpc
)
1127 *highpc
= pdi
.highpc
;
1129 if ((pdi
.is_external
|| nesting_level
== 1)
1130 && !pdi
.is_declaration
)
1132 add_partial_symbol (&pdi
, objfile
, cu_header
);
1136 case DW_TAG_variable
:
1137 case DW_TAG_typedef
:
1138 case DW_TAG_class_type
:
1139 case DW_TAG_structure_type
:
1140 case DW_TAG_union_type
:
1141 case DW_TAG_enumeration_type
:
1142 if ((pdi
.is_external
|| nesting_level
== 1)
1143 && !pdi
.is_declaration
)
1145 add_partial_symbol (&pdi
, objfile
, cu_header
);
1148 case DW_TAG_enumerator
:
1149 /* File scope enumerators are added to the partial symbol
1151 if (nesting_level
== 2)
1152 add_partial_symbol (&pdi
, objfile
, cu_header
);
1154 case DW_TAG_base_type
:
1155 /* File scope base type definitions are added to the partial
1157 if (nesting_level
== 1)
1158 add_partial_symbol (&pdi
, objfile
, cu_header
);
1165 /* If the die has a sibling, skip to the sibling.
1166 Do not skip enumeration types, we want to record their
1168 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1170 info_ptr
= pdi
.sibling
;
1172 else if (pdi
.has_children
)
1174 /* Die has children, but the optional DW_AT_sibling attribute
1185 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1186 from `maint check'. */
1187 if (*lowpc
== ((CORE_ADDR
) -1))
1193 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1194 const struct comp_unit_head
*cu_header
)
1200 case DW_TAG_subprogram
:
1201 if (pdi
->is_external
)
1203 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1204 mst_text, objfile); */
1205 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1206 VAR_NAMESPACE
, LOC_BLOCK
,
1207 &objfile
->global_psymbols
,
1208 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1212 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1213 mst_file_text, objfile); */
1214 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1215 VAR_NAMESPACE
, LOC_BLOCK
,
1216 &objfile
->static_psymbols
,
1217 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1220 case DW_TAG_variable
:
1221 if (pdi
->is_external
)
1224 Don't enter into the minimal symbol tables as there is
1225 a minimal symbol table entry from the ELF symbols already.
1226 Enter into partial symbol table if it has a location
1227 descriptor or a type.
1228 If the location descriptor is missing, new_symbol will create
1229 a LOC_UNRESOLVED symbol, the address of the variable will then
1230 be determined from the minimal symbol table whenever the variable
1232 The address for the partial symbol table entry is not
1233 used by GDB, but it comes in handy for debugging partial symbol
1237 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1238 if (pdi
->locdesc
|| pdi
->has_type
)
1239 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1240 VAR_NAMESPACE
, LOC_STATIC
,
1241 &objfile
->global_psymbols
,
1242 0, addr
+ baseaddr
, cu_language
, objfile
);
1246 /* Static Variable. Skip symbols without location descriptors. */
1247 if (pdi
->locdesc
== NULL
)
1249 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1250 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1251 mst_file_data, objfile); */
1252 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1253 VAR_NAMESPACE
, LOC_STATIC
,
1254 &objfile
->static_psymbols
,
1255 0, addr
+ baseaddr
, cu_language
, objfile
);
1258 case DW_TAG_typedef
:
1259 case DW_TAG_base_type
:
1260 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1261 VAR_NAMESPACE
, LOC_TYPEDEF
,
1262 &objfile
->static_psymbols
,
1263 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1265 case DW_TAG_class_type
:
1266 case DW_TAG_structure_type
:
1267 case DW_TAG_union_type
:
1268 case DW_TAG_enumeration_type
:
1269 /* Skip aggregate types without children, these are external
1271 if (pdi
->has_children
== 0)
1273 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1274 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1275 &objfile
->static_psymbols
,
1276 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1278 if (cu_language
== language_cplus
)
1280 /* For C++, these implicitly act as typedefs as well. */
1281 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1282 VAR_NAMESPACE
, LOC_TYPEDEF
,
1283 &objfile
->static_psymbols
,
1284 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1287 case DW_TAG_enumerator
:
1288 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1289 VAR_NAMESPACE
, LOC_CONST
,
1290 &objfile
->static_psymbols
,
1291 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1298 /* Expand this partial symbol table into a full symbol table. */
1301 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1303 /* FIXME: This is barely more than a stub. */
1308 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1314 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1315 gdb_flush (gdb_stdout
);
1318 psymtab_to_symtab_1 (pst
);
1320 /* Finish up the debug error message. */
1322 printf_filtered ("done.\n");
1328 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1330 struct objfile
*objfile
= pst
->objfile
;
1331 bfd
*abfd
= objfile
->obfd
;
1332 struct comp_unit_head cu_header
;
1333 struct die_info
*dies
;
1334 unsigned long offset
;
1335 CORE_ADDR lowpc
, highpc
;
1336 struct die_info
*child_die
;
1338 struct symtab
*symtab
;
1339 struct cleanup
*back_to
;
1341 /* Set local variables from the partial symbol table info. */
1342 offset
= DWARF_INFO_OFFSET (pst
);
1343 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1344 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1345 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1346 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1347 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1348 cu_header_offset
= offset
;
1349 info_ptr
= dwarf_info_buffer
+ offset
;
1351 obstack_init (&dwarf2_tmp_obstack
);
1352 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1355 make_cleanup (really_free_pendings
, NULL
);
1357 /* read in the comp_unit header */
1358 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1360 /* Read the abbrevs for this compilation unit */
1361 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1362 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1364 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1366 make_cleanup_free_die_list (dies
);
1368 /* Do line number decoding in read_file_scope () */
1369 process_die (dies
, objfile
, &cu_header
);
1371 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1373 /* Some compilers don't define a DW_AT_high_pc attribute for
1374 the compilation unit. If the DW_AT_high_pc is missing,
1375 synthesize it, by scanning the DIE's below the compilation unit. */
1377 if (dies
->has_children
)
1379 child_die
= dies
->next
;
1380 while (child_die
&& child_die
->tag
)
1382 if (child_die
->tag
== DW_TAG_subprogram
)
1384 CORE_ADDR low
, high
;
1386 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1388 highpc
= max (highpc
, high
);
1391 child_die
= sibling_die (child_die
);
1395 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1397 /* Set symtab language to language from DW_AT_language.
1398 If the compilation is from a C file generated by language preprocessors,
1399 do not set the language if it was already deduced by start_subfile. */
1401 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1403 symtab
->language
= cu_language
;
1405 pst
->symtab
= symtab
;
1407 sort_symtab_syms (pst
->symtab
);
1409 do_cleanups (back_to
);
1412 /* Process a die and its children. */
1415 process_die (struct die_info
*die
, struct objfile
*objfile
,
1416 const struct comp_unit_head
*cu_header
)
1420 case DW_TAG_padding
:
1422 case DW_TAG_compile_unit
:
1423 read_file_scope (die
, objfile
, cu_header
);
1425 case DW_TAG_subprogram
:
1426 read_subroutine_type (die
, objfile
, cu_header
);
1427 read_func_scope (die
, objfile
, cu_header
);
1429 case DW_TAG_inlined_subroutine
:
1430 /* FIXME: These are ignored for now.
1431 They could be used to set breakpoints on all inlined instances
1432 of a function and make GDB `next' properly over inlined functions. */
1434 case DW_TAG_lexical_block
:
1435 read_lexical_block_scope (die
, objfile
, cu_header
);
1437 case DW_TAG_class_type
:
1438 case DW_TAG_structure_type
:
1439 case DW_TAG_union_type
:
1440 read_structure_scope (die
, objfile
, cu_header
);
1442 case DW_TAG_enumeration_type
:
1443 read_enumeration (die
, objfile
, cu_header
);
1445 case DW_TAG_subroutine_type
:
1446 read_subroutine_type (die
, objfile
, cu_header
);
1448 case DW_TAG_array_type
:
1449 read_array_type (die
, objfile
, cu_header
);
1451 case DW_TAG_pointer_type
:
1452 read_tag_pointer_type (die
, objfile
, cu_header
);
1454 case DW_TAG_ptr_to_member_type
:
1455 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1457 case DW_TAG_reference_type
:
1458 read_tag_reference_type (die
, objfile
, cu_header
);
1460 case DW_TAG_string_type
:
1461 read_tag_string_type (die
, objfile
);
1463 case DW_TAG_base_type
:
1464 read_base_type (die
, objfile
);
1465 if (dwarf_attr (die
, DW_AT_name
))
1467 /* Add a typedef symbol for the base type definition. */
1468 new_symbol (die
, die
->type
, objfile
, cu_header
);
1471 case DW_TAG_common_block
:
1472 read_common_block (die
, objfile
, cu_header
);
1474 case DW_TAG_common_inclusion
:
1477 new_symbol (die
, NULL
, objfile
, cu_header
);
1483 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1484 const struct comp_unit_head
*cu_header
)
1486 unsigned int line_offset
= 0;
1487 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1488 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1489 struct attribute
*attr
;
1490 char *name
= "<unknown>";
1491 char *comp_dir
= NULL
;
1492 struct die_info
*child_die
;
1493 bfd
*abfd
= objfile
->obfd
;
1495 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1497 if (die
->has_children
)
1499 child_die
= die
->next
;
1500 while (child_die
&& child_die
->tag
)
1502 if (child_die
->tag
== DW_TAG_subprogram
)
1504 CORE_ADDR low
, high
;
1506 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1508 lowpc
= min (lowpc
, low
);
1509 highpc
= max (highpc
, high
);
1512 child_die
= sibling_die (child_die
);
1517 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1518 from finish_block. */
1519 if (lowpc
== ((CORE_ADDR
) -1))
1524 attr
= dwarf_attr (die
, DW_AT_name
);
1527 name
= DW_STRING (attr
);
1529 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1532 comp_dir
= DW_STRING (attr
);
1535 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1536 directory, get rid of it. */
1537 char *cp
= strchr (comp_dir
, ':');
1539 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1544 if (objfile
->ei
.entry_point
>= lowpc
&&
1545 objfile
->ei
.entry_point
< highpc
)
1547 objfile
->ei
.entry_file_lowpc
= lowpc
;
1548 objfile
->ei
.entry_file_highpc
= highpc
;
1551 attr
= dwarf_attr (die
, DW_AT_language
);
1554 set_cu_language (DW_UNSND (attr
));
1557 /* We assume that we're processing GCC output. */
1558 processing_gcc_compilation
= 2;
1560 /* FIXME:Do something here. */
1561 if (dip
->at_producer
!= NULL
)
1563 handle_producer (dip
->at_producer
);
1567 /* The compilation unit may be in a different language or objfile,
1568 zero out all remembered fundamental types. */
1569 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1571 start_symtab (name
, comp_dir
, lowpc
);
1572 record_debugformat ("DWARF 2");
1574 /* Decode line number information if present. */
1575 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1578 line_offset
= DW_UNSND (attr
);
1579 dwarf_decode_lines (line_offset
, comp_dir
, abfd
, cu_header
);
1582 /* Process all dies in compilation unit. */
1583 if (die
->has_children
)
1585 child_die
= die
->next
;
1586 while (child_die
&& child_die
->tag
)
1588 process_die (child_die
, objfile
, cu_header
);
1589 child_die
= sibling_die (child_die
);
1595 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
1596 const struct comp_unit_head
*cu_header
)
1598 register struct context_stack
*new;
1601 struct die_info
*child_die
;
1602 struct attribute
*attr
;
1605 name
= dwarf2_linkage_name (die
);
1607 /* Ignore functions with missing or empty names and functions with
1608 missing or invalid low and high pc attributes. */
1609 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1615 if (objfile
->ei
.entry_point
>= lowpc
&&
1616 objfile
->ei
.entry_point
< highpc
)
1618 objfile
->ei
.entry_func_lowpc
= lowpc
;
1619 objfile
->ei
.entry_func_highpc
= highpc
;
1622 /* Decode DW_AT_frame_base location descriptor if present, keep result
1623 for DW_OP_fbreg operands in decode_locdesc. */
1624 frame_base_reg
= -1;
1625 frame_base_offset
= 0;
1626 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1629 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
1631 complain (&dwarf2_unsupported_at_frame_base
, name
);
1633 frame_base_reg
= addr
;
1636 frame_base_reg
= basereg
;
1637 frame_base_offset
= addr
;
1640 complain (&dwarf2_unsupported_at_frame_base
, name
);
1643 new = push_context (0, lowpc
);
1644 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
1645 list_in_scope
= &local_symbols
;
1647 if (die
->has_children
)
1649 child_die
= die
->next
;
1650 while (child_die
&& child_die
->tag
)
1652 process_die (child_die
, objfile
, cu_header
);
1653 child_die
= sibling_die (child_die
);
1657 new = pop_context ();
1658 /* Make a block for the local symbols within. */
1659 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1660 lowpc
, highpc
, objfile
);
1661 list_in_scope
= &file_symbols
;
1664 /* Process all the DIES contained within a lexical block scope. Start
1665 a new scope, process the dies, and then close the scope. */
1668 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
1669 const struct comp_unit_head
*cu_header
)
1671 register struct context_stack
*new;
1672 CORE_ADDR lowpc
, highpc
;
1673 struct die_info
*child_die
;
1675 /* Ignore blocks with missing or invalid low and high pc attributes. */
1676 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1681 push_context (0, lowpc
);
1682 if (die
->has_children
)
1684 child_die
= die
->next
;
1685 while (child_die
&& child_die
->tag
)
1687 process_die (child_die
, objfile
, cu_header
);
1688 child_die
= sibling_die (child_die
);
1691 new = pop_context ();
1693 if (local_symbols
!= NULL
)
1695 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1698 local_symbols
= new->locals
;
1701 /* Get low and high pc attributes from a die.
1702 Return 1 if the attributes are present and valid, otherwise, return 0. */
1705 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1706 struct objfile
*objfile
)
1708 struct attribute
*attr
;
1712 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1714 low
= DW_ADDR (attr
);
1717 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1719 high
= DW_ADDR (attr
);
1726 /* When using the GNU linker, .gnu.linkonce. sections are used to
1727 eliminate duplicate copies of functions and vtables and such.
1728 The linker will arbitrarily choose one and discard the others.
1729 The AT_*_pc values for such functions refer to local labels in
1730 these sections. If the section from that file was discarded, the
1731 labels are not in the output, so the relocs get a value of 0.
1732 If this is a discarded function, mark the pc bounds as invalid,
1733 so that GDB will ignore it. */
1734 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1742 /* Add an aggregate field to the field list. */
1745 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
1746 struct objfile
*objfile
,
1747 const struct comp_unit_head
*cu_header
)
1749 struct nextfield
*new_field
;
1750 struct attribute
*attr
;
1752 char *fieldname
= "";
1754 /* Allocate a new field list entry and link it in. */
1755 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1756 make_cleanup (xfree
, new_field
);
1757 memset (new_field
, 0, sizeof (struct nextfield
));
1758 new_field
->next
= fip
->fields
;
1759 fip
->fields
= new_field
;
1762 /* Handle accessibility and virtuality of field.
1763 The default accessibility for members is public, the default
1764 accessibility for inheritance is private. */
1765 if (die
->tag
!= DW_TAG_inheritance
)
1766 new_field
->accessibility
= DW_ACCESS_public
;
1768 new_field
->accessibility
= DW_ACCESS_private
;
1769 new_field
->virtuality
= DW_VIRTUALITY_none
;
1771 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1773 new_field
->accessibility
= DW_UNSND (attr
);
1774 if (new_field
->accessibility
!= DW_ACCESS_public
)
1775 fip
->non_public_fields
= 1;
1776 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1778 new_field
->virtuality
= DW_UNSND (attr
);
1780 fp
= &new_field
->field
;
1781 if (die
->tag
== DW_TAG_member
)
1783 /* Get type of field. */
1784 fp
->type
= die_type (die
, objfile
, cu_header
);
1786 /* Get bit size of field (zero if none). */
1787 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1790 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1794 FIELD_BITSIZE (*fp
) = 0;
1797 /* Get bit offset of field. */
1798 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1801 FIELD_BITPOS (*fp
) =
1802 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
1805 FIELD_BITPOS (*fp
) = 0;
1806 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1809 if (BITS_BIG_ENDIAN
)
1811 /* For big endian bits, the DW_AT_bit_offset gives the
1812 additional bit offset from the MSB of the containing
1813 anonymous object to the MSB of the field. We don't
1814 have to do anything special since we don't need to
1815 know the size of the anonymous object. */
1816 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1820 /* For little endian bits, compute the bit offset to the
1821 MSB of the anonymous object, subtract off the number of
1822 bits from the MSB of the field to the MSB of the
1823 object, and then subtract off the number of bits of
1824 the field itself. The result is the bit offset of
1825 the LSB of the field. */
1827 int bit_offset
= DW_UNSND (attr
);
1829 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1832 /* The size of the anonymous object containing
1833 the bit field is explicit, so use the
1834 indicated size (in bytes). */
1835 anonymous_size
= DW_UNSND (attr
);
1839 /* The size of the anonymous object containing
1840 the bit field must be inferred from the type
1841 attribute of the data member containing the
1843 anonymous_size
= TYPE_LENGTH (fp
->type
);
1845 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1846 - bit_offset
- FIELD_BITSIZE (*fp
);
1850 /* Get name of field. */
1851 attr
= dwarf_attr (die
, DW_AT_name
);
1852 if (attr
&& DW_STRING (attr
))
1853 fieldname
= DW_STRING (attr
);
1854 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1855 &objfile
->type_obstack
);
1857 /* Change accessibility for artificial fields (e.g. virtual table
1858 pointer or virtual base class pointer) to private. */
1859 if (dwarf_attr (die
, DW_AT_artificial
))
1861 new_field
->accessibility
= DW_ACCESS_private
;
1862 fip
->non_public_fields
= 1;
1865 else if (die
->tag
== DW_TAG_variable
)
1869 /* C++ static member.
1870 Get name of field. */
1871 attr
= dwarf_attr (die
, DW_AT_name
);
1872 if (attr
&& DW_STRING (attr
))
1873 fieldname
= DW_STRING (attr
);
1877 /* Get physical name. */
1878 physname
= dwarf2_linkage_name (die
);
1880 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1881 &objfile
->type_obstack
));
1882 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1883 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1884 &objfile
->type_obstack
);
1886 else if (die
->tag
== DW_TAG_inheritance
)
1888 /* C++ base class field. */
1889 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1891 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
1893 FIELD_BITSIZE (*fp
) = 0;
1894 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1895 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1896 fip
->nbaseclasses
++;
1900 /* Create the vector of fields, and attach it to the type. */
1903 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
1904 struct objfile
*objfile
)
1906 int nfields
= fip
->nfields
;
1908 /* Record the field count, allocate space for the array of fields,
1909 and create blank accessibility bitfields if necessary. */
1910 TYPE_NFIELDS (type
) = nfields
;
1911 TYPE_FIELDS (type
) = (struct field
*)
1912 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1913 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1915 if (fip
->non_public_fields
)
1917 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1919 TYPE_FIELD_PRIVATE_BITS (type
) =
1920 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1921 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1923 TYPE_FIELD_PROTECTED_BITS (type
) =
1924 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1925 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1927 TYPE_FIELD_IGNORE_BITS (type
) =
1928 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1929 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1932 /* If the type has baseclasses, allocate and clear a bit vector for
1933 TYPE_FIELD_VIRTUAL_BITS. */
1934 if (fip
->nbaseclasses
)
1936 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
1939 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1940 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1941 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1942 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
1943 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
1946 /* Copy the saved-up fields into the field vector. Start from the head
1947 of the list, adding to the tail of the field array, so that they end
1948 up in the same order in the array in which they were added to the list. */
1949 while (nfields
-- > 0)
1951 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
1952 switch (fip
->fields
->accessibility
)
1954 case DW_ACCESS_private
:
1955 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
1958 case DW_ACCESS_protected
:
1959 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
1962 case DW_ACCESS_public
:
1966 /* Unknown accessibility. Complain and treat it as public. */
1968 complain (&dwarf2_unsupported_accessibility
,
1969 fip
->fields
->accessibility
);
1973 if (nfields
< fip
->nbaseclasses
)
1975 switch (fip
->fields
->virtuality
)
1977 case DW_VIRTUALITY_virtual
:
1978 case DW_VIRTUALITY_pure_virtual
:
1979 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
1983 fip
->fields
= fip
->fields
->next
;
1987 /* Add a member function to the proper fieldlist. */
1990 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
1991 struct type
*type
, struct objfile
*objfile
,
1992 const struct comp_unit_head
*cu_header
)
1994 struct attribute
*attr
;
1995 struct fnfieldlist
*flp
;
1997 struct fn_field
*fnp
;
2000 struct nextfnfield
*new_fnfield
;
2002 /* Get name of member function. */
2003 attr
= dwarf_attr (die
, DW_AT_name
);
2004 if (attr
&& DW_STRING (attr
))
2005 fieldname
= DW_STRING (attr
);
2009 /* Get the mangled name. */
2010 physname
= dwarf2_linkage_name (die
);
2012 /* Look up member function name in fieldlist. */
2013 for (i
= 0; i
< fip
->nfnfields
; i
++)
2015 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2019 /* Create new list element if necessary. */
2020 if (i
< fip
->nfnfields
)
2021 flp
= &fip
->fnfieldlists
[i
];
2024 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2026 fip
->fnfieldlists
= (struct fnfieldlist
*)
2027 xrealloc (fip
->fnfieldlists
,
2028 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2029 * sizeof (struct fnfieldlist
));
2030 if (fip
->nfnfields
== 0)
2031 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2033 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2034 flp
->name
= fieldname
;
2040 /* Create a new member function field and chain it to the field list
2042 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2043 make_cleanup (xfree
, new_fnfield
);
2044 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2045 new_fnfield
->next
= flp
->head
;
2046 flp
->head
= new_fnfield
;
2049 /* Fill in the member function field info. */
2050 fnp
= &new_fnfield
->fnfield
;
2051 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2052 &objfile
->type_obstack
);
2053 fnp
->type
= alloc_type (objfile
);
2054 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2056 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2057 struct type
**arg_types
;
2058 int nparams
= TYPE_NFIELDS (die
->type
);
2061 /* Copy argument types from the subroutine type. */
2062 arg_types
= (struct type
**)
2063 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2064 for (iparams
= 0; iparams
< nparams
; iparams
++)
2065 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2067 /* Set last entry in argument type vector. */
2068 if (TYPE_FLAGS (die
->type
) & TYPE_FLAG_VARARGS
)
2069 arg_types
[nparams
] = NULL
;
2071 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2073 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2075 /* Handle static member functions.
2076 Dwarf2 has no clean way to discern C++ static and non-static
2077 member functions. G++ helps GDB by marking the first
2078 parameter for non-static member functions (which is the
2079 this pointer) as artificial. We obtain this information
2080 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2081 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2082 fnp
->voffset
= VOFFSET_STATIC
;
2085 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2087 /* Get fcontext from DW_AT_containing_type if present. */
2088 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2089 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2091 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2092 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2094 /* Get accessibility. */
2095 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2098 switch (DW_UNSND (attr
))
2100 case DW_ACCESS_private
:
2101 fnp
->is_private
= 1;
2103 case DW_ACCESS_protected
:
2104 fnp
->is_protected
= 1;
2109 /* Get index in virtual function table if it is a virtual member function. */
2110 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2112 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2115 /* Create the vector of member function fields, and attach it to the type. */
2118 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2119 struct objfile
*objfile
)
2121 struct fnfieldlist
*flp
;
2122 int total_length
= 0;
2125 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2126 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2127 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2129 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2131 struct nextfnfield
*nfp
= flp
->head
;
2132 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2135 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2136 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2137 fn_flp
->fn_fields
= (struct fn_field
*)
2138 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2139 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2140 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2142 total_length
+= flp
->length
;
2145 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2146 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2149 /* Called when we find the DIE that starts a structure or union scope
2150 (definition) to process all dies that define the members of the
2153 NOTE: we need to call struct_type regardless of whether or not the
2154 DIE has an at_name attribute, since it might be an anonymous
2155 structure or union. This gets the type entered into our set of
2158 However, if the structure is incomplete (an opaque struct/union)
2159 then suppress creating a symbol table entry for it since gdb only
2160 wants to find the one with the complete definition. Note that if
2161 it is complete, we just call new_symbol, which does it's own
2162 checking about whether the struct/union is anonymous or not (and
2163 suppresses creating a symbol table entry itself). */
2166 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2167 const struct comp_unit_head
*cu_header
)
2170 struct attribute
*attr
;
2172 type
= alloc_type (objfile
);
2174 INIT_CPLUS_SPECIFIC (type
);
2175 attr
= dwarf_attr (die
, DW_AT_name
);
2176 if (attr
&& DW_STRING (attr
))
2178 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2179 strlen (DW_STRING (attr
)),
2180 &objfile
->type_obstack
);
2183 if (die
->tag
== DW_TAG_structure_type
)
2185 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2187 else if (die
->tag
== DW_TAG_union_type
)
2189 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2193 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2195 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2198 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2201 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2205 TYPE_LENGTH (type
) = 0;
2208 /* We need to add the type field to the die immediately so we don't
2209 infinitely recurse when dealing with pointers to the structure
2210 type within the structure itself. */
2213 if (die
->has_children
&& ! die_is_declaration (die
))
2215 struct field_info fi
;
2216 struct die_info
*child_die
;
2217 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2219 memset (&fi
, 0, sizeof (struct field_info
));
2221 child_die
= die
->next
;
2223 while (child_die
&& child_die
->tag
)
2225 if (child_die
->tag
== DW_TAG_member
)
2227 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2229 else if (child_die
->tag
== DW_TAG_variable
)
2231 /* C++ static member. */
2232 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2234 else if (child_die
->tag
== DW_TAG_subprogram
)
2236 /* C++ member function. */
2237 process_die (child_die
, objfile
, cu_header
);
2238 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2240 else if (child_die
->tag
== DW_TAG_inheritance
)
2242 /* C++ base class field. */
2243 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2247 process_die (child_die
, objfile
, cu_header
);
2249 child_die
= sibling_die (child_die
);
2252 /* Attach fields and member functions to the type. */
2254 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2257 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2259 /* Get the type which refers to the base class (possibly this
2260 class itself) which contains the vtable pointer for the current
2261 class from the DW_AT_containing_type attribute. */
2263 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2265 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2267 TYPE_VPTR_BASETYPE (type
) = t
;
2270 static const char vptr_name
[] =
2271 {'_', 'v', 'p', 't', 'r', '\0'};
2274 /* Our own class provides vtbl ptr. */
2275 for (i
= TYPE_NFIELDS (t
) - 1;
2276 i
>= TYPE_N_BASECLASSES (t
);
2279 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2281 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2282 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2284 TYPE_VPTR_FIELDNO (type
) = i
;
2289 /* Complain if virtual function table field not found. */
2290 if (i
< TYPE_N_BASECLASSES (t
))
2291 complain (&dwarf2_vtbl_not_found_complaint
,
2292 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2296 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2301 new_symbol (die
, type
, objfile
, cu_header
);
2303 do_cleanups (back_to
);
2307 /* No children, must be stub. */
2308 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2314 /* Given a pointer to a die which begins an enumeration, process all
2315 the dies that define the members of the enumeration.
2317 This will be much nicer in draft 6 of the DWARF spec when our
2318 members will be dies instead squished into the DW_AT_element_list
2321 NOTE: We reverse the order of the element list. */
2324 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2325 const struct comp_unit_head
*cu_header
)
2327 struct die_info
*child_die
;
2329 struct field
*fields
;
2330 struct attribute
*attr
;
2333 int unsigned_enum
= 1;
2335 type
= alloc_type (objfile
);
2337 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2338 attr
= dwarf_attr (die
, DW_AT_name
);
2339 if (attr
&& DW_STRING (attr
))
2341 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2342 strlen (DW_STRING (attr
)),
2343 &objfile
->type_obstack
);
2346 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2349 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2353 TYPE_LENGTH (type
) = 0;
2358 if (die
->has_children
)
2360 child_die
= die
->next
;
2361 while (child_die
&& child_die
->tag
)
2363 if (child_die
->tag
!= DW_TAG_enumerator
)
2365 process_die (child_die
, objfile
, cu_header
);
2369 attr
= dwarf_attr (child_die
, DW_AT_name
);
2372 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2373 if (SYMBOL_VALUE (sym
) < 0)
2376 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2378 fields
= (struct field
*)
2380 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2381 * sizeof (struct field
));
2384 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2385 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2386 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2387 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2393 child_die
= sibling_die (child_die
);
2398 TYPE_NFIELDS (type
) = num_fields
;
2399 TYPE_FIELDS (type
) = (struct field
*)
2400 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2401 memcpy (TYPE_FIELDS (type
), fields
,
2402 sizeof (struct field
) * num_fields
);
2406 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2409 new_symbol (die
, type
, objfile
, cu_header
);
2412 /* Extract all information from a DW_TAG_array_type DIE and put it in
2413 the DIE's type field. For now, this only handles one dimensional
2417 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
2418 const struct comp_unit_head
*cu_header
)
2420 struct die_info
*child_die
;
2421 struct type
*type
= NULL
;
2422 struct type
*element_type
, *range_type
, *index_type
;
2423 struct type
**range_types
= NULL
;
2424 struct attribute
*attr
;
2426 struct cleanup
*back_to
;
2428 /* Return if we've already decoded this type. */
2434 element_type
= die_type (die
, objfile
, cu_header
);
2436 /* Irix 6.2 native cc creates array types without children for
2437 arrays with unspecified length. */
2438 if (die
->has_children
== 0)
2440 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2441 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2442 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2446 back_to
= make_cleanup (null_cleanup
, NULL
);
2447 child_die
= die
->next
;
2448 while (child_die
&& child_die
->tag
)
2450 if (child_die
->tag
== DW_TAG_subrange_type
)
2452 unsigned int low
, high
;
2454 /* Default bounds to an array with unspecified length. */
2457 if (cu_language
== language_fortran
)
2459 /* FORTRAN implies a lower bound of 1, if not given. */
2463 index_type
= die_type (child_die
, objfile
, cu_header
);
2464 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2467 if (attr
->form
== DW_FORM_sdata
)
2469 low
= DW_SND (attr
);
2471 else if (attr
->form
== DW_FORM_udata
2472 || attr
->form
== DW_FORM_data1
2473 || attr
->form
== DW_FORM_data2
2474 || attr
->form
== DW_FORM_data4
)
2476 low
= DW_UNSND (attr
);
2480 complain (&dwarf2_non_const_array_bound_ignored
,
2481 dwarf_form_name (attr
->form
));
2483 die
->type
= lookup_pointer_type (element_type
);
2490 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2493 if (attr
->form
== DW_FORM_sdata
)
2495 high
= DW_SND (attr
);
2497 else if (attr
->form
== DW_FORM_udata
2498 || attr
->form
== DW_FORM_data1
2499 || attr
->form
== DW_FORM_data2
2500 || attr
->form
== DW_FORM_data4
)
2502 high
= DW_UNSND (attr
);
2504 else if (attr
->form
== DW_FORM_block1
)
2506 /* GCC encodes arrays with unspecified or dynamic length
2507 with a DW_FORM_block1 attribute.
2508 FIXME: GDB does not yet know how to handle dynamic
2509 arrays properly, treat them as arrays with unspecified
2515 complain (&dwarf2_non_const_array_bound_ignored
,
2516 dwarf_form_name (attr
->form
));
2518 die
->type
= lookup_pointer_type (element_type
);
2526 /* Create a range type and save it for array type creation. */
2527 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2529 range_types
= (struct type
**)
2530 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2531 * sizeof (struct type
*));
2533 make_cleanup (free_current_contents
, &range_types
);
2535 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2537 child_die
= sibling_die (child_die
);
2540 /* Dwarf2 dimensions are output from left to right, create the
2541 necessary array types in backwards order. */
2542 type
= element_type
;
2544 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2546 do_cleanups (back_to
);
2548 /* Install the type in the die. */
2552 /* First cut: install each common block member as a global variable. */
2555 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
2556 const struct comp_unit_head
*cu_header
)
2558 struct die_info
*child_die
;
2559 struct attribute
*attr
;
2561 CORE_ADDR base
= (CORE_ADDR
) 0;
2563 attr
= dwarf_attr (die
, DW_AT_location
);
2566 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2568 if (die
->has_children
)
2570 child_die
= die
->next
;
2571 while (child_die
&& child_die
->tag
)
2573 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
2574 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2577 SYMBOL_VALUE_ADDRESS (sym
) =
2578 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2579 add_symbol_to_list (sym
, &global_symbols
);
2581 child_die
= sibling_die (child_die
);
2586 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2587 the user defined type vector. */
2590 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
2591 const struct comp_unit_head
*cu_header
)
2594 struct attribute
*attr
;
2601 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
2602 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2605 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2609 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2614 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2615 the user defined type vector. */
2618 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
2619 const struct comp_unit_head
*cu_header
)
2622 struct type
*to_type
;
2623 struct type
*domain
;
2630 type
= alloc_type (objfile
);
2631 to_type
= die_type (die
, objfile
, cu_header
);
2632 domain
= die_containing_type (die
, objfile
, cu_header
);
2633 smash_to_member_type (type
, domain
, to_type
);
2638 /* Extract all information from a DW_TAG_reference_type DIE and add to
2639 the user defined type vector. */
2642 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
2643 const struct comp_unit_head
*cu_header
)
2646 struct attribute
*attr
;
2653 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
2654 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2657 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2661 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2667 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
2668 const struct comp_unit_head
*cu_header
)
2670 struct type
*base_type
;
2677 base_type
= die_type (die
, objfile
, cu_header
);
2678 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
2682 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
2683 const struct comp_unit_head
*cu_header
)
2685 struct type
*base_type
;
2692 base_type
= die_type (die
, objfile
, cu_header
);
2693 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
2696 /* Extract all information from a DW_TAG_string_type DIE and add to
2697 the user defined type vector. It isn't really a user defined type,
2698 but it behaves like one, with other DIE's using an AT_user_def_type
2699 attribute to reference it. */
2702 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
2704 struct type
*type
, *range_type
, *index_type
, *char_type
;
2705 struct attribute
*attr
;
2706 unsigned int length
;
2713 attr
= dwarf_attr (die
, DW_AT_string_length
);
2716 length
= DW_UNSND (attr
);
2722 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2723 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2724 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2725 type
= create_string_type (char_type
, range_type
);
2729 /* Handle DIES due to C code like:
2733 int (*funcp)(int a, long l);
2737 ('funcp' generates a DW_TAG_subroutine_type DIE)
2741 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
2742 const struct comp_unit_head
*cu_header
)
2744 struct type
*type
; /* Type that this function returns */
2745 struct type
*ftype
; /* Function that returns above type */
2746 struct attribute
*attr
;
2748 /* Decode the type that this subroutine returns */
2753 type
= die_type (die
, objfile
, cu_header
);
2754 ftype
= lookup_function_type (type
);
2756 /* All functions in C++ have prototypes. */
2757 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2758 if ((attr
&& (DW_UNSND (attr
) != 0))
2759 || cu_language
== language_cplus
)
2760 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2762 if (die
->has_children
)
2764 struct die_info
*child_die
;
2768 /* Count the number of parameters.
2769 FIXME: GDB currently ignores vararg functions, but knows about
2770 vararg member functions. */
2771 child_die
= die
->next
;
2772 while (child_die
&& child_die
->tag
)
2774 if (child_die
->tag
== DW_TAG_formal_parameter
)
2776 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2777 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2778 child_die
= sibling_die (child_die
);
2781 /* Allocate storage for parameters and fill them in. */
2782 TYPE_NFIELDS (ftype
) = nparams
;
2783 TYPE_FIELDS (ftype
) = (struct field
*)
2784 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2786 child_die
= die
->next
;
2787 while (child_die
&& child_die
->tag
)
2789 if (child_die
->tag
== DW_TAG_formal_parameter
)
2791 /* Dwarf2 has no clean way to discern C++ static and non-static
2792 member functions. G++ helps GDB by marking the first
2793 parameter for non-static member functions (which is the
2794 this pointer) as artificial. We pass this information
2795 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2796 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2798 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2800 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2801 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
2805 child_die
= sibling_die (child_die
);
2813 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
2814 const struct comp_unit_head
*cu_header
)
2820 struct attribute
*attr
;
2823 xtype
= die_type (die
, objfile
, cu_header
);
2825 type
= alloc_type (objfile
);
2826 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2827 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2828 TYPE_TARGET_TYPE (type
) = xtype
;
2829 attr
= dwarf_attr (die
, DW_AT_name
);
2830 if (attr
&& DW_STRING (attr
))
2831 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2832 strlen (DW_STRING (attr
)),
2833 &objfile
->type_obstack
);
2839 /* Find a representation of a given base type and install
2840 it in the TYPE field of the die. */
2843 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
2846 struct attribute
*attr
;
2847 int encoding
= 0, size
= 0;
2849 /* If we've already decoded this die, this is a no-op. */
2855 attr
= dwarf_attr (die
, DW_AT_encoding
);
2858 encoding
= DW_UNSND (attr
);
2860 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2863 size
= DW_UNSND (attr
);
2865 attr
= dwarf_attr (die
, DW_AT_name
);
2866 if (attr
&& DW_STRING (attr
))
2868 enum type_code code
= TYPE_CODE_INT
;
2869 int is_unsigned
= 0;
2873 case DW_ATE_address
:
2874 /* Turn DW_ATE_address into a void * pointer. */
2875 code
= TYPE_CODE_PTR
;
2878 case DW_ATE_boolean
:
2879 code
= TYPE_CODE_BOOL
;
2882 case DW_ATE_complex_float
:
2883 code
= TYPE_CODE_COMPLEX
;
2886 code
= TYPE_CODE_FLT
;
2889 case DW_ATE_signed_char
:
2891 case DW_ATE_unsigned
:
2892 case DW_ATE_unsigned_char
:
2896 complain (&dwarf2_unsupported_at_encoding
,
2897 dwarf_type_encoding_name (encoding
));
2900 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2901 if (encoding
== DW_ATE_address
)
2902 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2906 type
= dwarf_base_type (encoding
, size
, objfile
);
2911 /* Read a whole compilation unit into a linked list of dies. */
2913 static struct die_info
*
2914 read_comp_unit (char *info_ptr
, bfd
*abfd
,
2915 const struct comp_unit_head
*cu_header
)
2917 struct die_info
*first_die
, *last_die
, *die
;
2921 /* Reset die reference table; we are
2922 building new ones now. */
2923 dwarf2_empty_hash_tables ();
2927 first_die
= last_die
= NULL
;
2930 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
2931 if (die
->has_children
)
2942 /* Enter die in reference hash table */
2943 store_in_ref_table (die
->offset
, die
);
2947 first_die
= last_die
= die
;
2951 last_die
->next
= die
;
2955 while (nesting_level
> 0);
2959 /* Free a linked list of dies. */
2962 free_die_list (struct die_info
*dies
)
2964 struct die_info
*die
, *next
;
2977 do_free_die_list_cleanup (void *dies
)
2979 free_die_list (dies
);
2982 static struct cleanup
*
2983 make_cleanup_free_die_list (struct die_info
*dies
)
2985 return make_cleanup (do_free_die_list_cleanup
, dies
);
2989 /* Read the contents of the section at OFFSET and of size SIZE from the
2990 object file specified by OBJFILE into the psymbol_obstack and return it. */
2993 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
2996 bfd
*abfd
= objfile
->obfd
;
3002 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3003 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3004 (bfd_read (buf
, size
, 1, abfd
) != size
))
3007 error ("Dwarf Error: Can't read DWARF data from '%s'",
3008 bfd_get_filename (abfd
));
3013 /* In DWARF version 2, the description of the debugging information is
3014 stored in a separate .debug_abbrev section. Before we read any
3015 dies from a section we read in all abbreviations and install them
3019 dwarf2_read_abbrevs (bfd
*abfd
, unsigned int offset
)
3022 struct abbrev_info
*cur_abbrev
;
3023 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3024 unsigned int abbrev_form
, hash_number
;
3026 /* empty the table */
3027 dwarf2_empty_abbrev_table (NULL
);
3029 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3030 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3031 abbrev_ptr
+= bytes_read
;
3033 /* loop until we reach an abbrev number of 0 */
3034 while (abbrev_number
)
3036 cur_abbrev
= dwarf_alloc_abbrev ();
3038 /* read in abbrev header */
3039 cur_abbrev
->number
= abbrev_number
;
3040 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3041 abbrev_ptr
+= bytes_read
;
3042 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3045 /* now read in declarations */
3046 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3047 abbrev_ptr
+= bytes_read
;
3048 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3049 abbrev_ptr
+= bytes_read
;
3052 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3054 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3055 xrealloc (cur_abbrev
->attrs
,
3056 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3057 * sizeof (struct attr_abbrev
));
3059 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3060 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3061 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3062 abbrev_ptr
+= bytes_read
;
3063 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3064 abbrev_ptr
+= bytes_read
;
3067 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3068 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3069 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3071 /* Get next abbreviation.
3072 Under Irix6 the abbreviations for a compilation unit are not
3073 always properly terminated with an abbrev number of 0.
3074 Exit loop if we encounter an abbreviation which we have
3075 already read (which means we are about to read the abbreviations
3076 for the next compile unit) or if the end of the abbreviation
3077 table is reached. */
3078 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3079 >= dwarf_abbrev_size
)
3081 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3082 abbrev_ptr
+= bytes_read
;
3083 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3088 /* Empty the abbrev table for a new compilation unit. */
3092 dwarf2_empty_abbrev_table (PTR ignore
)
3095 struct abbrev_info
*abbrev
, *next
;
3097 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3100 abbrev
= dwarf2_abbrevs
[i
];
3103 next
= abbrev
->next
;
3104 xfree (abbrev
->attrs
);
3108 dwarf2_abbrevs
[i
] = NULL
;
3112 /* Lookup an abbrev_info structure in the abbrev hash table. */
3114 static struct abbrev_info
*
3115 dwarf2_lookup_abbrev (unsigned int number
)
3117 unsigned int hash_number
;
3118 struct abbrev_info
*abbrev
;
3120 hash_number
= number
% ABBREV_HASH_SIZE
;
3121 abbrev
= dwarf2_abbrevs
[hash_number
];
3125 if (abbrev
->number
== number
)
3128 abbrev
= abbrev
->next
;
3133 /* Read a minimal amount of information into the minimal die structure. */
3136 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3137 char *info_ptr
, const struct comp_unit_head
*cu_header
)
3139 unsigned int abbrev_number
, bytes_read
, i
;
3140 struct abbrev_info
*abbrev
;
3141 struct attribute attr
;
3142 struct attribute spec_attr
;
3143 int found_spec_attr
= 0;
3144 int has_low_pc_attr
= 0;
3145 int has_high_pc_attr
= 0;
3147 *part_die
= zeroed_partial_die
;
3148 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3149 info_ptr
+= bytes_read
;
3153 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3156 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3158 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3159 part_die
->tag
= abbrev
->tag
;
3160 part_die
->has_children
= abbrev
->has_children
;
3161 part_die
->abbrev
= abbrev_number
;
3163 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3165 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3166 info_ptr
, cu_header
);
3168 /* Store the data if it is of an attribute we want to keep in a
3169 partial symbol table. */
3174 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3175 if (part_die
->name
== NULL
)
3176 part_die
->name
= DW_STRING (&attr
);
3178 case DW_AT_MIPS_linkage_name
:
3179 part_die
->name
= DW_STRING (&attr
);
3182 has_low_pc_attr
= 1;
3183 part_die
->lowpc
= DW_ADDR (&attr
);
3186 has_high_pc_attr
= 1;
3187 part_die
->highpc
= DW_ADDR (&attr
);
3189 case DW_AT_location
:
3190 part_die
->locdesc
= DW_BLOCK (&attr
);
3192 case DW_AT_language
:
3193 part_die
->language
= DW_UNSND (&attr
);
3195 case DW_AT_external
:
3196 part_die
->is_external
= DW_UNSND (&attr
);
3198 case DW_AT_declaration
:
3199 part_die
->is_declaration
= DW_UNSND (&attr
);
3202 part_die
->has_type
= 1;
3204 case DW_AT_abstract_origin
:
3205 case DW_AT_specification
:
3206 found_spec_attr
= 1;
3210 /* Ignore absolute siblings, they might point outside of
3211 the current compile unit. */
3212 if (attr
.form
== DW_FORM_ref_addr
)
3213 complain (&dwarf2_absolute_sibling_complaint
);
3216 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3223 /* If we found a reference attribute and the die has no name, try
3224 to find a name in the referred to die. */
3226 if (found_spec_attr
&& part_die
->name
== NULL
)
3228 struct partial_die_info spec_die
;
3232 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3233 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu_header
);
3236 part_die
->name
= spec_die
.name
;
3238 /* Copy DW_AT_external attribute if it is set. */
3239 if (spec_die
.is_external
)
3240 part_die
->is_external
= spec_die
.is_external
;
3244 /* When using the GNU linker, .gnu.linkonce. sections are used to
3245 eliminate duplicate copies of functions and vtables and such.
3246 The linker will arbitrarily choose one and discard the others.
3247 The AT_*_pc values for such functions refer to local labels in
3248 these sections. If the section from that file was discarded, the
3249 labels are not in the output, so the relocs get a value of 0.
3250 If this is a discarded function, mark the pc bounds as invalid,
3251 so that GDB will ignore it. */
3252 if (has_low_pc_attr
&& has_high_pc_attr
3253 && part_die
->lowpc
< part_die
->highpc
3254 && (part_die
->lowpc
!= 0
3255 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3256 part_die
->has_pc_info
= 1;
3260 /* Read the die from the .debug_info section buffer. And set diep to
3261 point to a newly allocated die with its information. */
3264 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3265 const struct comp_unit_head
*cu_header
)
3267 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3268 struct abbrev_info
*abbrev
;
3269 struct die_info
*die
;
3271 offset
= info_ptr
- dwarf_info_buffer
;
3272 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3273 info_ptr
+= bytes_read
;
3276 die
= dwarf_alloc_die ();
3278 die
->abbrev
= abbrev_number
;
3284 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3287 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3289 die
= dwarf_alloc_die ();
3290 die
->offset
= offset
;
3291 die
->tag
= abbrev
->tag
;
3292 die
->has_children
= abbrev
->has_children
;
3293 die
->abbrev
= abbrev_number
;
3296 die
->num_attrs
= abbrev
->num_attrs
;
3297 die
->attrs
= (struct attribute
*)
3298 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3300 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3302 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3303 abfd
, info_ptr
, cu_header
);
3310 /* Read an attribute described by an abbreviated attribute. */
3313 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
3314 bfd
*abfd
, char *info_ptr
,
3315 const struct comp_unit_head
*cu_header
)
3317 unsigned int bytes_read
;
3318 struct dwarf_block
*blk
;
3320 attr
->name
= abbrev
->name
;
3321 attr
->form
= abbrev
->form
;
3322 switch (abbrev
->form
)
3325 case DW_FORM_ref_addr
:
3326 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3327 info_ptr
+= bytes_read
;
3329 case DW_FORM_block2
:
3330 blk
= dwarf_alloc_block ();
3331 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3333 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3334 info_ptr
+= blk
->size
;
3335 DW_BLOCK (attr
) = blk
;
3337 case DW_FORM_block4
:
3338 blk
= dwarf_alloc_block ();
3339 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3341 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3342 info_ptr
+= blk
->size
;
3343 DW_BLOCK (attr
) = blk
;
3346 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3350 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3354 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3357 case DW_FORM_string
:
3358 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3359 info_ptr
+= bytes_read
;
3362 blk
= dwarf_alloc_block ();
3363 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3364 info_ptr
+= bytes_read
;
3365 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3366 info_ptr
+= blk
->size
;
3367 DW_BLOCK (attr
) = blk
;
3369 case DW_FORM_block1
:
3370 blk
= dwarf_alloc_block ();
3371 blk
->size
= read_1_byte (abfd
, info_ptr
);
3373 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3374 info_ptr
+= blk
->size
;
3375 DW_BLOCK (attr
) = blk
;
3378 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3382 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3386 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3387 info_ptr
+= bytes_read
;
3390 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3391 info_ptr
+= bytes_read
;
3394 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3398 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3402 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3406 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3409 case DW_FORM_ref_udata
:
3410 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3411 info_ptr
+= bytes_read
;
3414 case DW_FORM_indirect
:
3416 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3417 dwarf_form_name (abbrev
->form
));
3422 /* read dwarf information from a buffer */
3425 read_1_byte (bfd
*abfd
, char *buf
)
3427 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3431 read_1_signed_byte (bfd
*abfd
, char *buf
)
3433 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3437 read_2_bytes (bfd
*abfd
, char *buf
)
3439 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3443 read_2_signed_bytes (bfd
*abfd
, char *buf
)
3445 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3449 read_4_bytes (bfd
*abfd
, char *buf
)
3451 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3455 read_4_signed_bytes (bfd
*abfd
, char *buf
)
3457 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3460 static unsigned long
3461 read_8_bytes (bfd
*abfd
, char *buf
)
3463 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3467 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3470 CORE_ADDR retval
= 0;
3472 if (cu_header
->signed_addr_p
)
3474 switch (cu_header
->addr_size
)
3477 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3480 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3483 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
3486 internal_error (__FILE__
, __LINE__
,
3487 "read_address: bad switch, signed");
3492 switch (cu_header
->addr_size
)
3495 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3498 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3501 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3504 internal_error (__FILE__
, __LINE__
,
3505 "read_address: bad switch, unsigned");
3509 *bytes_read
= cu_header
->addr_size
;
3513 /* Reads the initial length from a section. The (draft) DWARF 2.1
3514 specification allows the initial length to take up either 4 bytes
3515 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
3516 bytes describe the length and all offsets will be 8 bytes in length
3519 The value returned via bytes_read should be used to increment
3520 the relevant pointer after calling read_initial_length().
3522 As a side effect, this function sets the fields initial_length_size
3523 and offset_size in cu_header to the values appropriate for the
3524 length field. (The format of the initial length field determines
3525 the width of file offsets to be fetched later with fetch_offset().)
3527 [ Note: read_initial_length() and read_offset() are based on the
3528 document entitled "DWARF Debugging Information Format", revision
3529 2.1, draft 4, dated July 20, 2000. This document was obtained
3532 http://reality.sgi.com/dehnert_engr/dwarf/dwarf2p1-draft4-000720.pdf
3534 This document is only a draft and is subject to change. (So beware.)
3536 - Kevin, Aug 4, 2000
3540 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
3545 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3547 if (retval
== 0xffffffff)
3549 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
3551 if (cu_header
!= NULL
)
3553 cu_header
->initial_length_size
= 12;
3554 cu_header
->offset_size
= 8;
3560 if (cu_header
!= NULL
)
3562 cu_header
->initial_length_size
= 4;
3563 cu_header
->offset_size
= 4;
3570 /* Read an offset from the data stream. The size of the offset is
3571 given by cu_header->offset_size. */
3574 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3579 switch (cu_header
->offset_size
)
3582 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3586 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3590 internal_error (__FILE__
, __LINE__
,
3591 "read_offset: bad switch");
3598 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
3600 /* If the size of a host char is 8 bits, we can return a pointer
3601 to the buffer, otherwise we have to copy the data to a buffer
3602 allocated on the temporary obstack. */
3603 #if HOST_CHAR_BIT == 8
3609 ret
= obstack_alloc (&dwarf2_tmp_obstack
, size
);
3610 for (i
= 0; i
< size
; ++i
)
3612 ret
[i
] = bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3620 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3622 /* If the size of a host char is 8 bits, we can return a pointer
3623 to the string, otherwise we have to copy the string to a buffer
3624 allocated on the temporary obstack. */
3625 #if HOST_CHAR_BIT == 8
3628 *bytes_read_ptr
= 1;
3631 *bytes_read_ptr
= strlen (buf
) + 1;
3637 while ((byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
)) != 0)
3639 obstack_1grow (&dwarf2_tmp_obstack
, byte
);
3645 *bytes_read_ptr
= 1;
3648 obstack_1grow (&dwarf2_tmp_obstack
, '\0');
3649 *bytes_read_ptr
= i
+ 1;
3650 return obstack_finish (&dwarf2_tmp_obstack
);
3654 static unsigned long
3655 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3657 unsigned long result
;
3658 unsigned int num_read
;
3668 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3671 result
|= ((unsigned long)(byte
& 127) << shift
);
3672 if ((byte
& 128) == 0)
3678 *bytes_read_ptr
= num_read
;
3683 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3686 int i
, shift
, size
, num_read
;
3696 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3699 result
|= ((long)(byte
& 127) << shift
);
3701 if ((byte
& 128) == 0)
3706 if ((shift
< size
) && (byte
& 0x40))
3708 result
|= -(1 << shift
);
3710 *bytes_read_ptr
= num_read
;
3715 set_cu_language (unsigned int lang
)
3721 cu_language
= language_c
;
3723 case DW_LANG_C_plus_plus
:
3724 cu_language
= language_cplus
;
3726 case DW_LANG_Fortran77
:
3727 case DW_LANG_Fortran90
:
3728 cu_language
= language_fortran
;
3730 case DW_LANG_Mips_Assembler
:
3731 cu_language
= language_asm
;
3734 cu_language
= language_java
;
3737 case DW_LANG_Cobol74
:
3738 case DW_LANG_Cobol85
:
3739 case DW_LANG_Pascal83
:
3740 case DW_LANG_Modula2
:
3742 cu_language
= language_unknown
;
3745 cu_language_defn
= language_def (cu_language
);
3748 /* Return the named attribute or NULL if not there. */
3750 static struct attribute
*
3751 dwarf_attr (struct die_info
*die
, unsigned int name
)
3754 struct attribute
*spec
= NULL
;
3756 for (i
= 0; i
< die
->num_attrs
; ++i
)
3758 if (die
->attrs
[i
].name
== name
)
3760 return &die
->attrs
[i
];
3762 if (die
->attrs
[i
].name
== DW_AT_specification
3763 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3764 spec
= &die
->attrs
[i
];
3768 struct die_info
*ref_die
=
3769 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3772 return dwarf_attr (ref_die
, name
);
3779 die_is_declaration (struct die_info
*die
)
3781 return (dwarf_attr (die
, DW_AT_declaration
)
3782 && ! dwarf_attr (die
, DW_AT_specification
));
3785 /* Decode the line number information for the compilation unit whose
3786 line number info is at OFFSET in the .debug_line section.
3787 The compilation directory of the file is passed in COMP_DIR. */
3791 unsigned int num_files
;
3804 unsigned int num_dirs
;
3809 dwarf_decode_lines (unsigned int offset
, char *comp_dir
, bfd
*abfd
,
3810 const struct comp_unit_head
*cu_header
)
3814 struct line_head lh
;
3815 struct cleanup
*back_to
;
3816 unsigned int i
, bytes_read
;
3817 char *cur_file
, *cur_dir
;
3818 unsigned char op_code
, extended_op
, adj_opcode
;
3820 #define FILE_ALLOC_CHUNK 5
3821 #define DIR_ALLOC_CHUNK 5
3823 struct filenames files
;
3824 struct directories dirs
;
3826 if (dwarf_line_buffer
== NULL
)
3828 complain (&dwarf2_missing_line_number_section
);
3832 files
.num_files
= 0;
3838 line_ptr
= dwarf_line_buffer
+ offset
;
3840 /* read in the prologue */
3841 lh
.total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
3842 line_ptr
+= bytes_read
;
3843 line_end
= line_ptr
+ lh
.total_length
;
3844 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3846 lh
.prologue_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
3847 line_ptr
+= bytes_read
;
3848 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3850 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3852 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3854 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3856 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3858 lh
.standard_opcode_lengths
= (unsigned char *)
3859 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3860 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
3862 lh
.standard_opcode_lengths
[0] = 1;
3863 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3865 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3869 /* Read directory table */
3870 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3872 line_ptr
+= bytes_read
;
3873 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3875 dirs
.dirs
= (char **)
3876 xrealloc (dirs
.dirs
,
3877 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3878 if (dirs
.num_dirs
== 0)
3879 make_cleanup (free_current_contents
, &dirs
.dirs
);
3881 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3883 line_ptr
+= bytes_read
;
3885 /* Read file name table */
3886 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3888 line_ptr
+= bytes_read
;
3889 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3891 files
.files
= (struct fileinfo
*)
3892 xrealloc (files
.files
,
3893 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3894 * sizeof (struct fileinfo
));
3895 if (files
.num_files
== 0)
3896 make_cleanup (free_current_contents
, &files
.files
);
3898 files
.files
[files
.num_files
].name
= cur_file
;
3899 files
.files
[files
.num_files
].dir
=
3900 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3901 line_ptr
+= bytes_read
;
3902 files
.files
[files
.num_files
].time
=
3903 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3904 line_ptr
+= bytes_read
;
3905 files
.files
[files
.num_files
].size
=
3906 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3907 line_ptr
+= bytes_read
;
3910 line_ptr
+= bytes_read
;
3912 /* Read the statement sequences until there's nothing left. */
3913 while (line_ptr
< line_end
)
3915 /* state machine registers */
3916 CORE_ADDR address
= 0;
3917 unsigned int file
= 1;
3918 unsigned int line
= 1;
3919 unsigned int column
= 0;
3920 int is_stmt
= lh
.default_is_stmt
;
3921 int basic_block
= 0;
3922 int end_sequence
= 0;
3924 /* Start a subfile for the current file of the state machine. */
3925 if (files
.num_files
>= file
)
3927 /* The file and directory tables are 0 based, the references
3929 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3930 (files
.files
[file
- 1].dir
3931 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3935 /* Decode the table. */
3936 while (!end_sequence
)
3938 op_code
= read_1_byte (abfd
, line_ptr
);
3942 case DW_LNS_extended_op
:
3943 line_ptr
+= 1; /* ignore length */
3944 extended_op
= read_1_byte (abfd
, line_ptr
);
3946 switch (extended_op
)
3948 case DW_LNE_end_sequence
:
3950 /* Don't call record_line here. The end_sequence
3951 instruction provides the address of the first byte
3952 *after* the last line in the sequence; it's not the
3953 address of any real source line. However, the GDB
3954 linetable structure only records the starts of lines,
3955 not the ends. This is a weakness of GDB. */
3957 case DW_LNE_set_address
:
3958 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
3959 line_ptr
+= bytes_read
;
3960 address
+= baseaddr
;
3962 case DW_LNE_define_file
:
3963 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
3964 line_ptr
+= bytes_read
;
3965 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3967 files
.files
= (struct fileinfo
*)
3968 xrealloc (files
.files
,
3969 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3970 * sizeof (struct fileinfo
));
3971 if (files
.num_files
== 0)
3972 make_cleanup (free_current_contents
, &files
.files
);
3974 files
.files
[files
.num_files
].name
= cur_file
;
3975 files
.files
[files
.num_files
].dir
=
3976 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3977 line_ptr
+= bytes_read
;
3978 files
.files
[files
.num_files
].time
=
3979 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3980 line_ptr
+= bytes_read
;
3981 files
.files
[files
.num_files
].size
=
3982 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3983 line_ptr
+= bytes_read
;
3987 complain (&dwarf2_mangled_line_number_section
);
3992 record_line (current_subfile
, line
, address
);
3995 case DW_LNS_advance_pc
:
3996 address
+= lh
.minimum_instruction_length
3997 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3998 line_ptr
+= bytes_read
;
4000 case DW_LNS_advance_line
:
4001 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
4002 line_ptr
+= bytes_read
;
4004 case DW_LNS_set_file
:
4005 /* The file and directory tables are 0 based, the references
4007 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4008 line_ptr
+= bytes_read
;
4009 dwarf2_start_subfile
4010 (files
.files
[file
- 1].name
,
4011 (files
.files
[file
- 1].dir
4012 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
4015 case DW_LNS_set_column
:
4016 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4017 line_ptr
+= bytes_read
;
4019 case DW_LNS_negate_stmt
:
4020 is_stmt
= (!is_stmt
);
4022 case DW_LNS_set_basic_block
:
4025 /* Add to the address register of the state machine the
4026 address increment value corresponding to special opcode
4027 255. Ie, this value is scaled by the minimum instruction
4028 length since special opcode 255 would have scaled the
4030 case DW_LNS_const_add_pc
:
4031 address
+= (lh
.minimum_instruction_length
4032 * ((255 - lh
.opcode_base
) / lh
.line_range
));
4034 case DW_LNS_fixed_advance_pc
:
4035 address
+= read_2_bytes (abfd
, line_ptr
);
4038 default: /* special operand */
4039 adj_opcode
= op_code
- lh
.opcode_base
;
4040 address
+= (adj_opcode
/ lh
.line_range
)
4041 * lh
.minimum_instruction_length
;
4042 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
4043 /* append row to matrix using current values */
4044 record_line (current_subfile
, line
, address
);
4050 do_cleanups (back_to
);
4053 /* Start a subfile for DWARF. FILENAME is the name of the file and
4054 DIRNAME the name of the source directory which contains FILENAME
4055 or NULL if not known.
4056 This routine tries to keep line numbers from identical absolute and
4057 relative file names in a common subfile.
4059 Using the `list' example from the GDB testsuite, which resides in
4060 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4061 of /srcdir/list0.c yields the following debugging information for list0.c:
4063 DW_AT_name: /srcdir/list0.c
4064 DW_AT_comp_dir: /compdir
4065 files.files[0].name: list0.h
4066 files.files[0].dir: /srcdir
4067 files.files[1].name: list0.c
4068 files.files[1].dir: /srcdir
4070 The line number information for list0.c has to end up in a single
4071 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4074 dwarf2_start_subfile (char *filename
, char *dirname
)
4076 /* If the filename isn't absolute, try to match an existing subfile
4077 with the full pathname. */
4079 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
4081 struct subfile
*subfile
;
4082 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4084 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4086 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
4088 current_subfile
= subfile
;
4095 start_subfile (filename
, dirname
);
4098 /* Given a pointer to a DWARF information entry, figure out if we need
4099 to make a symbol table entry for it, and if so, create a new entry
4100 and return a pointer to it.
4101 If TYPE is NULL, determine symbol type from the die, otherwise
4102 used the passed type. */
4104 static struct symbol
*
4105 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
4106 const struct comp_unit_head
*cu_header
)
4108 struct symbol
*sym
= NULL
;
4110 struct attribute
*attr
= NULL
;
4111 struct attribute
*attr2
= NULL
;
4114 name
= dwarf2_linkage_name (die
);
4117 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4118 sizeof (struct symbol
));
4119 OBJSTAT (objfile
, n_syms
++);
4120 memset (sym
, 0, sizeof (struct symbol
));
4121 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4122 &objfile
->symbol_obstack
);
4124 /* Default assumptions.
4125 Use the passed type or decode it from the die. */
4126 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4127 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4129 SYMBOL_TYPE (sym
) = type
;
4131 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
4132 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4135 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4138 /* If this symbol is from a C++ compilation, then attempt to
4139 cache the demangled form for future reference. This is a
4140 typical time versus space tradeoff, that was decided in favor
4141 of time because it sped up C++ symbol lookups by a factor of
4144 SYMBOL_LANGUAGE (sym
) = cu_language
;
4145 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4149 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4152 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4154 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4156 case DW_TAG_subprogram
:
4157 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4159 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4160 attr2
= dwarf_attr (die
, DW_AT_external
);
4161 if (attr2
&& (DW_UNSND (attr2
) != 0))
4163 add_symbol_to_list (sym
, &global_symbols
);
4167 add_symbol_to_list (sym
, list_in_scope
);
4170 case DW_TAG_variable
:
4171 /* Compilation with minimal debug info may result in variables
4172 with missing type entries. Change the misleading `void' type
4173 to something sensible. */
4174 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4175 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4176 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4177 "<variable, no debug info>",
4179 attr
= dwarf_attr (die
, DW_AT_const_value
);
4182 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4183 attr2
= dwarf_attr (die
, DW_AT_external
);
4184 if (attr2
&& (DW_UNSND (attr2
) != 0))
4185 add_symbol_to_list (sym
, &global_symbols
);
4187 add_symbol_to_list (sym
, list_in_scope
);
4190 attr
= dwarf_attr (die
, DW_AT_location
);
4193 attr2
= dwarf_attr (die
, DW_AT_external
);
4194 if (attr2
&& (DW_UNSND (attr2
) != 0))
4196 SYMBOL_VALUE_ADDRESS (sym
) =
4197 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4198 add_symbol_to_list (sym
, &global_symbols
);
4200 /* In shared libraries the address of the variable
4201 in the location descriptor might still be relocatable,
4202 so its value could be zero.
4203 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4204 value is zero, the address of the variable will then
4205 be determined from the minimal symbol table whenever
4206 the variable is referenced. */
4207 if (SYMBOL_VALUE_ADDRESS (sym
))
4209 fixup_symbol_section (sym
, objfile
);
4210 SYMBOL_VALUE_ADDRESS (sym
) +=
4211 ANOFFSET (objfile
->section_offsets
,
4212 SYMBOL_SECTION (sym
));
4213 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4216 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4220 SYMBOL_VALUE (sym
) = addr
=
4221 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4222 add_symbol_to_list (sym
, list_in_scope
);
4225 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4229 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4230 SYMBOL_VALUE (sym
) =
4231 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4235 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4236 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4240 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4244 fixup_symbol_section (sym
, objfile
);
4245 SYMBOL_VALUE_ADDRESS (sym
) =
4246 addr
+ ANOFFSET (objfile
->section_offsets
,
4247 SYMBOL_SECTION (sym
));
4248 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4254 /* We do not know the address of this symbol.
4255 If it is an external symbol and we have type information
4256 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4257 The address of the variable will then be determined from
4258 the minimal symbol table whenever the variable is
4260 attr2
= dwarf_attr (die
, DW_AT_external
);
4261 if (attr2
&& (DW_UNSND (attr2
) != 0)
4262 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4264 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4265 add_symbol_to_list (sym
, &global_symbols
);
4269 case DW_TAG_formal_parameter
:
4270 attr
= dwarf_attr (die
, DW_AT_location
);
4273 SYMBOL_VALUE (sym
) =
4274 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4277 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4278 SYMBOL_VALUE (sym
) =
4279 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4285 if (basereg
!= frame_base_reg
)
4286 complain (&dwarf2_complex_location_expr
);
4287 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4291 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4292 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4297 SYMBOL_CLASS (sym
) = LOC_ARG
;
4300 attr
= dwarf_attr (die
, DW_AT_const_value
);
4303 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4305 add_symbol_to_list (sym
, list_in_scope
);
4307 case DW_TAG_unspecified_parameters
:
4308 /* From varargs functions; gdb doesn't seem to have any
4309 interest in this information, so just ignore it for now.
4312 case DW_TAG_class_type
:
4313 case DW_TAG_structure_type
:
4314 case DW_TAG_union_type
:
4315 case DW_TAG_enumeration_type
:
4316 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4317 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4318 add_symbol_to_list (sym
, list_in_scope
);
4320 /* The semantics of C++ state that "struct foo { ... }" also
4321 defines a typedef for "foo". Synthesize a typedef symbol so
4322 that "ptype foo" works as expected. */
4323 if (cu_language
== language_cplus
)
4325 struct symbol
*typedef_sym
= (struct symbol
*)
4326 obstack_alloc (&objfile
->symbol_obstack
,
4327 sizeof (struct symbol
));
4328 *typedef_sym
= *sym
;
4329 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4330 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4331 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4332 obsavestring (SYMBOL_NAME (sym
),
4333 strlen (SYMBOL_NAME (sym
)),
4334 &objfile
->type_obstack
);
4335 add_symbol_to_list (typedef_sym
, list_in_scope
);
4338 case DW_TAG_typedef
:
4339 case DW_TAG_base_type
:
4340 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4341 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4342 add_symbol_to_list (sym
, list_in_scope
);
4344 case DW_TAG_enumerator
:
4345 attr
= dwarf_attr (die
, DW_AT_const_value
);
4348 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4350 add_symbol_to_list (sym
, list_in_scope
);
4353 /* Not a tag we recognize. Hopefully we aren't processing
4354 trash data, but since we must specifically ignore things
4355 we don't recognize, there is nothing else we should do at
4357 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4364 /* Copy constant value from an attribute to a symbol. */
4367 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
4368 struct objfile
*objfile
,
4369 const struct comp_unit_head
*cu_header
)
4371 struct dwarf_block
*blk
;
4376 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
4377 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4378 cu_header
->addr_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4379 SYMBOL_VALUE_BYTES (sym
) = (char *)
4380 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
4381 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
4383 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4385 case DW_FORM_block1
:
4386 case DW_FORM_block2
:
4387 case DW_FORM_block4
:
4389 blk
= DW_BLOCK (attr
);
4390 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4391 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4392 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4393 SYMBOL_VALUE_BYTES (sym
) = (char *)
4394 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4395 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4396 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4399 /* The DW_AT_const_value attributes are supposed to carry the
4400 symbol's value "represented as it would be on the target
4401 architecture." By the time we get here, it's already been
4402 converted to host endianness, so we just need to sign- or
4403 zero-extend it as appropriate. */
4405 dwarf2_const_value_data (attr
, sym
, 8);
4408 dwarf2_const_value_data (attr
, sym
, 16);
4411 dwarf2_const_value_data (attr
, sym
, 32);
4414 dwarf2_const_value_data (attr
, sym
, 64);
4418 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4419 SYMBOL_CLASS (sym
) = LOC_CONST
;
4423 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4424 SYMBOL_CLASS (sym
) = LOC_CONST
;
4428 complain (&dwarf2_unsupported_const_value_attr
,
4429 dwarf_form_name (attr
->form
));
4430 SYMBOL_VALUE (sym
) = 0;
4431 SYMBOL_CLASS (sym
) = LOC_CONST
;
4437 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4438 or zero-extend it as appropriate for the symbol's type. */
4440 dwarf2_const_value_data (struct attribute
*attr
,
4444 LONGEST l
= DW_UNSND (attr
);
4446 if (bits
< sizeof (l
) * 8)
4448 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4449 l
&= ((LONGEST
) 1 << bits
) - 1;
4451 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4454 SYMBOL_VALUE (sym
) = l
;
4455 SYMBOL_CLASS (sym
) = LOC_CONST
;
4459 /* Return the type of the die in question using its DW_AT_type attribute. */
4461 static struct type
*
4462 die_type (struct die_info
*die
, struct objfile
*objfile
,
4463 const struct comp_unit_head
*cu_header
)
4466 struct attribute
*type_attr
;
4467 struct die_info
*type_die
;
4470 type_attr
= dwarf_attr (die
, DW_AT_type
);
4473 /* A missing DW_AT_type represents a void type. */
4474 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4478 ref
= dwarf2_get_ref_die_offset (type_attr
);
4479 type_die
= follow_die_ref (ref
);
4482 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4486 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4489 dump_die (type_die
);
4490 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4495 /* Return the containing type of the die in question using its
4496 DW_AT_containing_type attribute. */
4498 static struct type
*
4499 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
4500 const struct comp_unit_head
*cu_header
)
4502 struct type
*type
= NULL
;
4503 struct attribute
*type_attr
;
4504 struct die_info
*type_die
= NULL
;
4507 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4510 ref
= dwarf2_get_ref_die_offset (type_attr
);
4511 type_die
= follow_die_ref (ref
);
4514 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4517 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4522 dump_die (type_die
);
4523 error ("Dwarf Error: Problem turning containing type into gdb type.");
4529 static struct type
*
4530 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
4532 struct die_info
*die
;
4535 die
= follow_die_ref (offset
);
4538 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4541 type
= tag_type_to_type (die
, objfile
);
4546 static struct type
*
4547 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
4548 const struct comp_unit_head
*cu_header
)
4556 read_type_die (die
, objfile
, cu_header
);
4560 error ("Dwarf Error: Cannot find type of die.");
4567 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
4568 const struct comp_unit_head
*cu_header
)
4572 case DW_TAG_class_type
:
4573 case DW_TAG_structure_type
:
4574 case DW_TAG_union_type
:
4575 read_structure_scope (die
, objfile
, cu_header
);
4577 case DW_TAG_enumeration_type
:
4578 read_enumeration (die
, objfile
, cu_header
);
4580 case DW_TAG_subprogram
:
4581 case DW_TAG_subroutine_type
:
4582 read_subroutine_type (die
, objfile
, cu_header
);
4584 case DW_TAG_array_type
:
4585 read_array_type (die
, objfile
, cu_header
);
4587 case DW_TAG_pointer_type
:
4588 read_tag_pointer_type (die
, objfile
, cu_header
);
4590 case DW_TAG_ptr_to_member_type
:
4591 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
4593 case DW_TAG_reference_type
:
4594 read_tag_reference_type (die
, objfile
, cu_header
);
4596 case DW_TAG_const_type
:
4597 read_tag_const_type (die
, objfile
, cu_header
);
4599 case DW_TAG_volatile_type
:
4600 read_tag_volatile_type (die
, objfile
, cu_header
);
4602 case DW_TAG_string_type
:
4603 read_tag_string_type (die
, objfile
);
4605 case DW_TAG_typedef
:
4606 read_typedef (die
, objfile
, cu_header
);
4608 case DW_TAG_base_type
:
4609 read_base_type (die
, objfile
);
4612 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4617 static struct type
*
4618 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
4620 /* FIXME - this should not produce a new (struct type *)
4621 every time. It should cache base types. */
4625 case DW_ATE_address
:
4626 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4628 case DW_ATE_boolean
:
4629 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4631 case DW_ATE_complex_float
:
4634 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4638 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4644 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4648 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4655 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4658 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4662 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4666 case DW_ATE_signed_char
:
4667 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4669 case DW_ATE_unsigned
:
4673 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4676 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4680 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4684 case DW_ATE_unsigned_char
:
4685 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4688 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4695 copy_die (struct die_info
*old_die
)
4697 struct die_info
*new_die
;
4700 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4701 memset (new_die
, 0, sizeof (struct die_info
));
4703 new_die
->tag
= old_die
->tag
;
4704 new_die
->has_children
= old_die
->has_children
;
4705 new_die
->abbrev
= old_die
->abbrev
;
4706 new_die
->offset
= old_die
->offset
;
4707 new_die
->type
= NULL
;
4709 num_attrs
= old_die
->num_attrs
;
4710 new_die
->num_attrs
= num_attrs
;
4711 new_die
->attrs
= (struct attribute
*)
4712 xmalloc (num_attrs
* sizeof (struct attribute
));
4714 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4716 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4717 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4718 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4721 new_die
->next
= NULL
;
4726 /* Return sibling of die, NULL if no sibling. */
4728 static struct die_info
*
4729 sibling_die (struct die_info
*die
)
4731 int nesting_level
= 0;
4733 if (!die
->has_children
)
4735 if (die
->next
&& (die
->next
->tag
== 0))
4748 if (die
->has_children
)
4758 while (nesting_level
);
4759 if (die
&& (die
->tag
== 0))
4770 /* Get linkage name of a die, return NULL if not found. */
4773 dwarf2_linkage_name (struct die_info
*die
)
4775 struct attribute
*attr
;
4777 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4778 if (attr
&& DW_STRING (attr
))
4779 return DW_STRING (attr
);
4780 attr
= dwarf_attr (die
, DW_AT_name
);
4781 if (attr
&& DW_STRING (attr
))
4782 return DW_STRING (attr
);
4786 /* Convert a DIE tag into its string name. */
4789 dwarf_tag_name (register unsigned tag
)
4793 case DW_TAG_padding
:
4794 return "DW_TAG_padding";
4795 case DW_TAG_array_type
:
4796 return "DW_TAG_array_type";
4797 case DW_TAG_class_type
:
4798 return "DW_TAG_class_type";
4799 case DW_TAG_entry_point
:
4800 return "DW_TAG_entry_point";
4801 case DW_TAG_enumeration_type
:
4802 return "DW_TAG_enumeration_type";
4803 case DW_TAG_formal_parameter
:
4804 return "DW_TAG_formal_parameter";
4805 case DW_TAG_imported_declaration
:
4806 return "DW_TAG_imported_declaration";
4808 return "DW_TAG_label";
4809 case DW_TAG_lexical_block
:
4810 return "DW_TAG_lexical_block";
4812 return "DW_TAG_member";
4813 case DW_TAG_pointer_type
:
4814 return "DW_TAG_pointer_type";
4815 case DW_TAG_reference_type
:
4816 return "DW_TAG_reference_type";
4817 case DW_TAG_compile_unit
:
4818 return "DW_TAG_compile_unit";
4819 case DW_TAG_string_type
:
4820 return "DW_TAG_string_type";
4821 case DW_TAG_structure_type
:
4822 return "DW_TAG_structure_type";
4823 case DW_TAG_subroutine_type
:
4824 return "DW_TAG_subroutine_type";
4825 case DW_TAG_typedef
:
4826 return "DW_TAG_typedef";
4827 case DW_TAG_union_type
:
4828 return "DW_TAG_union_type";
4829 case DW_TAG_unspecified_parameters
:
4830 return "DW_TAG_unspecified_parameters";
4831 case DW_TAG_variant
:
4832 return "DW_TAG_variant";
4833 case DW_TAG_common_block
:
4834 return "DW_TAG_common_block";
4835 case DW_TAG_common_inclusion
:
4836 return "DW_TAG_common_inclusion";
4837 case DW_TAG_inheritance
:
4838 return "DW_TAG_inheritance";
4839 case DW_TAG_inlined_subroutine
:
4840 return "DW_TAG_inlined_subroutine";
4842 return "DW_TAG_module";
4843 case DW_TAG_ptr_to_member_type
:
4844 return "DW_TAG_ptr_to_member_type";
4845 case DW_TAG_set_type
:
4846 return "DW_TAG_set_type";
4847 case DW_TAG_subrange_type
:
4848 return "DW_TAG_subrange_type";
4849 case DW_TAG_with_stmt
:
4850 return "DW_TAG_with_stmt";
4851 case DW_TAG_access_declaration
:
4852 return "DW_TAG_access_declaration";
4853 case DW_TAG_base_type
:
4854 return "DW_TAG_base_type";
4855 case DW_TAG_catch_block
:
4856 return "DW_TAG_catch_block";
4857 case DW_TAG_const_type
:
4858 return "DW_TAG_const_type";
4859 case DW_TAG_constant
:
4860 return "DW_TAG_constant";
4861 case DW_TAG_enumerator
:
4862 return "DW_TAG_enumerator";
4863 case DW_TAG_file_type
:
4864 return "DW_TAG_file_type";
4866 return "DW_TAG_friend";
4867 case DW_TAG_namelist
:
4868 return "DW_TAG_namelist";
4869 case DW_TAG_namelist_item
:
4870 return "DW_TAG_namelist_item";
4871 case DW_TAG_packed_type
:
4872 return "DW_TAG_packed_type";
4873 case DW_TAG_subprogram
:
4874 return "DW_TAG_subprogram";
4875 case DW_TAG_template_type_param
:
4876 return "DW_TAG_template_type_param";
4877 case DW_TAG_template_value_param
:
4878 return "DW_TAG_template_value_param";
4879 case DW_TAG_thrown_type
:
4880 return "DW_TAG_thrown_type";
4881 case DW_TAG_try_block
:
4882 return "DW_TAG_try_block";
4883 case DW_TAG_variant_part
:
4884 return "DW_TAG_variant_part";
4885 case DW_TAG_variable
:
4886 return "DW_TAG_variable";
4887 case DW_TAG_volatile_type
:
4888 return "DW_TAG_volatile_type";
4889 case DW_TAG_MIPS_loop
:
4890 return "DW_TAG_MIPS_loop";
4891 case DW_TAG_format_label
:
4892 return "DW_TAG_format_label";
4893 case DW_TAG_function_template
:
4894 return "DW_TAG_function_template";
4895 case DW_TAG_class_template
:
4896 return "DW_TAG_class_template";
4898 return "DW_TAG_<unknown>";
4902 /* Convert a DWARF attribute code into its string name. */
4905 dwarf_attr_name (register unsigned attr
)
4910 return "DW_AT_sibling";
4911 case DW_AT_location
:
4912 return "DW_AT_location";
4914 return "DW_AT_name";
4915 case DW_AT_ordering
:
4916 return "DW_AT_ordering";
4917 case DW_AT_subscr_data
:
4918 return "DW_AT_subscr_data";
4919 case DW_AT_byte_size
:
4920 return "DW_AT_byte_size";
4921 case DW_AT_bit_offset
:
4922 return "DW_AT_bit_offset";
4923 case DW_AT_bit_size
:
4924 return "DW_AT_bit_size";
4925 case DW_AT_element_list
:
4926 return "DW_AT_element_list";
4927 case DW_AT_stmt_list
:
4928 return "DW_AT_stmt_list";
4930 return "DW_AT_low_pc";
4932 return "DW_AT_high_pc";
4933 case DW_AT_language
:
4934 return "DW_AT_language";
4936 return "DW_AT_member";
4938 return "DW_AT_discr";
4939 case DW_AT_discr_value
:
4940 return "DW_AT_discr_value";
4941 case DW_AT_visibility
:
4942 return "DW_AT_visibility";
4944 return "DW_AT_import";
4945 case DW_AT_string_length
:
4946 return "DW_AT_string_length";
4947 case DW_AT_common_reference
:
4948 return "DW_AT_common_reference";
4949 case DW_AT_comp_dir
:
4950 return "DW_AT_comp_dir";
4951 case DW_AT_const_value
:
4952 return "DW_AT_const_value";
4953 case DW_AT_containing_type
:
4954 return "DW_AT_containing_type";
4955 case DW_AT_default_value
:
4956 return "DW_AT_default_value";
4958 return "DW_AT_inline";
4959 case DW_AT_is_optional
:
4960 return "DW_AT_is_optional";
4961 case DW_AT_lower_bound
:
4962 return "DW_AT_lower_bound";
4963 case DW_AT_producer
:
4964 return "DW_AT_producer";
4965 case DW_AT_prototyped
:
4966 return "DW_AT_prototyped";
4967 case DW_AT_return_addr
:
4968 return "DW_AT_return_addr";
4969 case DW_AT_start_scope
:
4970 return "DW_AT_start_scope";
4971 case DW_AT_stride_size
:
4972 return "DW_AT_stride_size";
4973 case DW_AT_upper_bound
:
4974 return "DW_AT_upper_bound";
4975 case DW_AT_abstract_origin
:
4976 return "DW_AT_abstract_origin";
4977 case DW_AT_accessibility
:
4978 return "DW_AT_accessibility";
4979 case DW_AT_address_class
:
4980 return "DW_AT_address_class";
4981 case DW_AT_artificial
:
4982 return "DW_AT_artificial";
4983 case DW_AT_base_types
:
4984 return "DW_AT_base_types";
4985 case DW_AT_calling_convention
:
4986 return "DW_AT_calling_convention";
4988 return "DW_AT_count";
4989 case DW_AT_data_member_location
:
4990 return "DW_AT_data_member_location";
4991 case DW_AT_decl_column
:
4992 return "DW_AT_decl_column";
4993 case DW_AT_decl_file
:
4994 return "DW_AT_decl_file";
4995 case DW_AT_decl_line
:
4996 return "DW_AT_decl_line";
4997 case DW_AT_declaration
:
4998 return "DW_AT_declaration";
4999 case DW_AT_discr_list
:
5000 return "DW_AT_discr_list";
5001 case DW_AT_encoding
:
5002 return "DW_AT_encoding";
5003 case DW_AT_external
:
5004 return "DW_AT_external";
5005 case DW_AT_frame_base
:
5006 return "DW_AT_frame_base";
5008 return "DW_AT_friend";
5009 case DW_AT_identifier_case
:
5010 return "DW_AT_identifier_case";
5011 case DW_AT_macro_info
:
5012 return "DW_AT_macro_info";
5013 case DW_AT_namelist_items
:
5014 return "DW_AT_namelist_items";
5015 case DW_AT_priority
:
5016 return "DW_AT_priority";
5018 return "DW_AT_segment";
5019 case DW_AT_specification
:
5020 return "DW_AT_specification";
5021 case DW_AT_static_link
:
5022 return "DW_AT_static_link";
5024 return "DW_AT_type";
5025 case DW_AT_use_location
:
5026 return "DW_AT_use_location";
5027 case DW_AT_variable_parameter
:
5028 return "DW_AT_variable_parameter";
5029 case DW_AT_virtuality
:
5030 return "DW_AT_virtuality";
5031 case DW_AT_vtable_elem_location
:
5032 return "DW_AT_vtable_elem_location";
5035 case DW_AT_MIPS_fde
:
5036 return "DW_AT_MIPS_fde";
5037 case DW_AT_MIPS_loop_begin
:
5038 return "DW_AT_MIPS_loop_begin";
5039 case DW_AT_MIPS_tail_loop_begin
:
5040 return "DW_AT_MIPS_tail_loop_begin";
5041 case DW_AT_MIPS_epilog_begin
:
5042 return "DW_AT_MIPS_epilog_begin";
5043 case DW_AT_MIPS_loop_unroll_factor
:
5044 return "DW_AT_MIPS_loop_unroll_factor";
5045 case DW_AT_MIPS_software_pipeline_depth
:
5046 return "DW_AT_MIPS_software_pipeline_depth";
5047 case DW_AT_MIPS_linkage_name
:
5048 return "DW_AT_MIPS_linkage_name";
5051 case DW_AT_sf_names
:
5052 return "DW_AT_sf_names";
5053 case DW_AT_src_info
:
5054 return "DW_AT_src_info";
5055 case DW_AT_mac_info
:
5056 return "DW_AT_mac_info";
5057 case DW_AT_src_coords
:
5058 return "DW_AT_src_coords";
5059 case DW_AT_body_begin
:
5060 return "DW_AT_body_begin";
5061 case DW_AT_body_end
:
5062 return "DW_AT_body_end";
5064 return "DW_AT_<unknown>";
5068 /* Convert a DWARF value form code into its string name. */
5071 dwarf_form_name (register unsigned form
)
5076 return "DW_FORM_addr";
5077 case DW_FORM_block2
:
5078 return "DW_FORM_block2";
5079 case DW_FORM_block4
:
5080 return "DW_FORM_block4";
5082 return "DW_FORM_data2";
5084 return "DW_FORM_data4";
5086 return "DW_FORM_data8";
5087 case DW_FORM_string
:
5088 return "DW_FORM_string";
5090 return "DW_FORM_block";
5091 case DW_FORM_block1
:
5092 return "DW_FORM_block1";
5094 return "DW_FORM_data1";
5096 return "DW_FORM_flag";
5098 return "DW_FORM_sdata";
5100 return "DW_FORM_strp";
5102 return "DW_FORM_udata";
5103 case DW_FORM_ref_addr
:
5104 return "DW_FORM_ref_addr";
5106 return "DW_FORM_ref1";
5108 return "DW_FORM_ref2";
5110 return "DW_FORM_ref4";
5112 return "DW_FORM_ref8";
5113 case DW_FORM_ref_udata
:
5114 return "DW_FORM_ref_udata";
5115 case DW_FORM_indirect
:
5116 return "DW_FORM_indirect";
5118 return "DW_FORM_<unknown>";
5122 /* Convert a DWARF stack opcode into its string name. */
5125 dwarf_stack_op_name (register unsigned op
)
5130 return "DW_OP_addr";
5132 return "DW_OP_deref";
5134 return "DW_OP_const1u";
5136 return "DW_OP_const1s";
5138 return "DW_OP_const2u";
5140 return "DW_OP_const2s";
5142 return "DW_OP_const4u";
5144 return "DW_OP_const4s";
5146 return "DW_OP_const8u";
5148 return "DW_OP_const8s";
5150 return "DW_OP_constu";
5152 return "DW_OP_consts";
5156 return "DW_OP_drop";
5158 return "DW_OP_over";
5160 return "DW_OP_pick";
5162 return "DW_OP_swap";
5166 return "DW_OP_xderef";
5174 return "DW_OP_minus";
5186 return "DW_OP_plus";
5187 case DW_OP_plus_uconst
:
5188 return "DW_OP_plus_uconst";
5194 return "DW_OP_shra";
5212 return "DW_OP_skip";
5214 return "DW_OP_lit0";
5216 return "DW_OP_lit1";
5218 return "DW_OP_lit2";
5220 return "DW_OP_lit3";
5222 return "DW_OP_lit4";
5224 return "DW_OP_lit5";
5226 return "DW_OP_lit6";
5228 return "DW_OP_lit7";
5230 return "DW_OP_lit8";
5232 return "DW_OP_lit9";
5234 return "DW_OP_lit10";
5236 return "DW_OP_lit11";
5238 return "DW_OP_lit12";
5240 return "DW_OP_lit13";
5242 return "DW_OP_lit14";
5244 return "DW_OP_lit15";
5246 return "DW_OP_lit16";
5248 return "DW_OP_lit17";
5250 return "DW_OP_lit18";
5252 return "DW_OP_lit19";
5254 return "DW_OP_lit20";
5256 return "DW_OP_lit21";
5258 return "DW_OP_lit22";
5260 return "DW_OP_lit23";
5262 return "DW_OP_lit24";
5264 return "DW_OP_lit25";
5266 return "DW_OP_lit26";
5268 return "DW_OP_lit27";
5270 return "DW_OP_lit28";
5272 return "DW_OP_lit29";
5274 return "DW_OP_lit30";
5276 return "DW_OP_lit31";
5278 return "DW_OP_reg0";
5280 return "DW_OP_reg1";
5282 return "DW_OP_reg2";
5284 return "DW_OP_reg3";
5286 return "DW_OP_reg4";
5288 return "DW_OP_reg5";
5290 return "DW_OP_reg6";
5292 return "DW_OP_reg7";
5294 return "DW_OP_reg8";
5296 return "DW_OP_reg9";
5298 return "DW_OP_reg10";
5300 return "DW_OP_reg11";
5302 return "DW_OP_reg12";
5304 return "DW_OP_reg13";
5306 return "DW_OP_reg14";
5308 return "DW_OP_reg15";
5310 return "DW_OP_reg16";
5312 return "DW_OP_reg17";
5314 return "DW_OP_reg18";
5316 return "DW_OP_reg19";
5318 return "DW_OP_reg20";
5320 return "DW_OP_reg21";
5322 return "DW_OP_reg22";
5324 return "DW_OP_reg23";
5326 return "DW_OP_reg24";
5328 return "DW_OP_reg25";
5330 return "DW_OP_reg26";
5332 return "DW_OP_reg27";
5334 return "DW_OP_reg28";
5336 return "DW_OP_reg29";
5338 return "DW_OP_reg30";
5340 return "DW_OP_reg31";
5342 return "DW_OP_breg0";
5344 return "DW_OP_breg1";
5346 return "DW_OP_breg2";
5348 return "DW_OP_breg3";
5350 return "DW_OP_breg4";
5352 return "DW_OP_breg5";
5354 return "DW_OP_breg6";
5356 return "DW_OP_breg7";
5358 return "DW_OP_breg8";
5360 return "DW_OP_breg9";
5362 return "DW_OP_breg10";
5364 return "DW_OP_breg11";
5366 return "DW_OP_breg12";
5368 return "DW_OP_breg13";
5370 return "DW_OP_breg14";
5372 return "DW_OP_breg15";
5374 return "DW_OP_breg16";
5376 return "DW_OP_breg17";
5378 return "DW_OP_breg18";
5380 return "DW_OP_breg19";
5382 return "DW_OP_breg20";
5384 return "DW_OP_breg21";
5386 return "DW_OP_breg22";
5388 return "DW_OP_breg23";
5390 return "DW_OP_breg24";
5392 return "DW_OP_breg25";
5394 return "DW_OP_breg26";
5396 return "DW_OP_breg27";
5398 return "DW_OP_breg28";
5400 return "DW_OP_breg29";
5402 return "DW_OP_breg30";
5404 return "DW_OP_breg31";
5406 return "DW_OP_regx";
5408 return "DW_OP_fbreg";
5410 return "DW_OP_bregx";
5412 return "DW_OP_piece";
5413 case DW_OP_deref_size
:
5414 return "DW_OP_deref_size";
5415 case DW_OP_xderef_size
:
5416 return "DW_OP_xderef_size";
5420 return "OP_<unknown>";
5425 dwarf_bool_name (unsigned mybool
)
5433 /* Convert a DWARF type code into its string name. */
5436 dwarf_type_encoding_name (register unsigned enc
)
5440 case DW_ATE_address
:
5441 return "DW_ATE_address";
5442 case DW_ATE_boolean
:
5443 return "DW_ATE_boolean";
5444 case DW_ATE_complex_float
:
5445 return "DW_ATE_complex_float";
5447 return "DW_ATE_float";
5449 return "DW_ATE_signed";
5450 case DW_ATE_signed_char
:
5451 return "DW_ATE_signed_char";
5452 case DW_ATE_unsigned
:
5453 return "DW_ATE_unsigned";
5454 case DW_ATE_unsigned_char
:
5455 return "DW_ATE_unsigned_char";
5457 return "DW_ATE_<unknown>";
5461 /* Convert a DWARF call frame info operation to its string name. */
5465 dwarf_cfi_name (register unsigned cfi_opc
)
5469 case DW_CFA_advance_loc
:
5470 return "DW_CFA_advance_loc";
5472 return "DW_CFA_offset";
5473 case DW_CFA_restore
:
5474 return "DW_CFA_restore";
5476 return "DW_CFA_nop";
5477 case DW_CFA_set_loc
:
5478 return "DW_CFA_set_loc";
5479 case DW_CFA_advance_loc1
:
5480 return "DW_CFA_advance_loc1";
5481 case DW_CFA_advance_loc2
:
5482 return "DW_CFA_advance_loc2";
5483 case DW_CFA_advance_loc4
:
5484 return "DW_CFA_advance_loc4";
5485 case DW_CFA_offset_extended
:
5486 return "DW_CFA_offset_extended";
5487 case DW_CFA_restore_extended
:
5488 return "DW_CFA_restore_extended";
5489 case DW_CFA_undefined
:
5490 return "DW_CFA_undefined";
5491 case DW_CFA_same_value
:
5492 return "DW_CFA_same_value";
5493 case DW_CFA_register
:
5494 return "DW_CFA_register";
5495 case DW_CFA_remember_state
:
5496 return "DW_CFA_remember_state";
5497 case DW_CFA_restore_state
:
5498 return "DW_CFA_restore_state";
5499 case DW_CFA_def_cfa
:
5500 return "DW_CFA_def_cfa";
5501 case DW_CFA_def_cfa_register
:
5502 return "DW_CFA_def_cfa_register";
5503 case DW_CFA_def_cfa_offset
:
5504 return "DW_CFA_def_cfa_offset";
5505 /* SGI/MIPS specific */
5506 case DW_CFA_MIPS_advance_loc8
:
5507 return "DW_CFA_MIPS_advance_loc8";
5509 return "DW_CFA_<unknown>";
5515 dump_die (struct die_info
*die
)
5519 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5520 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5521 fprintf (stderr
, "\thas children: %s\n",
5522 dwarf_bool_name (die
->has_children
));
5524 fprintf (stderr
, "\tattributes:\n");
5525 for (i
= 0; i
< die
->num_attrs
; ++i
)
5527 fprintf (stderr
, "\t\t%s (%s) ",
5528 dwarf_attr_name (die
->attrs
[i
].name
),
5529 dwarf_form_name (die
->attrs
[i
].form
));
5530 switch (die
->attrs
[i
].form
)
5532 case DW_FORM_ref_addr
:
5534 fprintf (stderr
, "address: ");
5535 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5537 case DW_FORM_block2
:
5538 case DW_FORM_block4
:
5540 case DW_FORM_block1
:
5541 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5552 fprintf (stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
5554 case DW_FORM_string
:
5555 fprintf (stderr
, "string: \"%s\"",
5556 DW_STRING (&die
->attrs
[i
])
5557 ? DW_STRING (&die
->attrs
[i
]) : "");
5560 if (DW_UNSND (&die
->attrs
[i
]))
5561 fprintf (stderr
, "flag: TRUE");
5563 fprintf (stderr
, "flag: FALSE");
5565 case DW_FORM_strp
: /* we do not support separate string
5567 case DW_FORM_indirect
: /* we do not handle indirect yet */
5569 fprintf (stderr
, "unsupported attribute form: %d.",
5570 die
->attrs
[i
].form
);
5572 fprintf (stderr
, "\n");
5577 dump_die_list (struct die_info
*die
)
5587 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
5590 struct die_info
*old
;
5592 h
= (offset
% REF_HASH_SIZE
);
5593 old
= die_ref_table
[h
];
5594 die
->next_ref
= old
;
5595 die_ref_table
[h
] = die
;
5600 dwarf2_empty_hash_tables (void)
5602 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5606 dwarf2_get_ref_die_offset (struct attribute
*attr
)
5608 unsigned int result
= 0;
5612 case DW_FORM_ref_addr
:
5613 result
= DW_ADDR (attr
);
5619 case DW_FORM_ref_udata
:
5620 result
= cu_header_offset
+ DW_UNSND (attr
);
5623 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5628 static struct die_info
*
5629 follow_die_ref (unsigned int offset
)
5631 struct die_info
*die
;
5634 h
= (offset
% REF_HASH_SIZE
);
5635 die
= die_ref_table
[h
];
5638 if (die
->offset
== offset
)
5642 die
= die
->next_ref
;
5647 static struct type
*
5648 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
5650 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5652 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5656 /* Look for this particular type in the fundamental type vector. If
5657 one is not found, create and install one appropriate for the
5658 current language and the current target machine. */
5660 if (ftypes
[typeid] == NULL
)
5662 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5665 return (ftypes
[typeid]);
5668 /* Decode simple location descriptions.
5669 Given a pointer to a dwarf block that defines a location, compute
5670 the location and return the value.
5672 FIXME: This is a kludge until we figure out a better
5673 way to handle the location descriptions.
5674 Gdb's design does not mesh well with the DWARF2 notion of a location
5675 computing interpreter, which is a shame because the flexibility goes unused.
5676 FIXME: Implement more operations as necessary.
5678 A location description containing no operations indicates that the
5679 object is optimized out. The global optimized_out flag is set for
5680 those, the return value is meaningless.
5682 When the result is a register number, the global isreg flag is set,
5683 otherwise it is cleared.
5685 When the result is a base register offset, the global offreg flag is set
5686 and the register number is returned in basereg, otherwise it is cleared.
5688 When the DW_OP_fbreg operation is encountered without a corresponding
5689 DW_AT_frame_base attribute, the global islocal flag is set.
5690 Hopefully the machine dependent code knows how to set up a virtual
5691 frame pointer for the local references.
5693 Note that stack[0] is unused except as a default error return.
5694 Note that stack overflow is not yet handled. */
5697 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
5698 const struct comp_unit_head
*cu_header
)
5701 int size
= blk
->size
;
5702 char *data
= blk
->data
;
5703 CORE_ADDR stack
[64];
5705 unsigned int bytes_read
, unsnd
;
5756 stack
[++stacki
] = op
- DW_OP_reg0
;
5761 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5763 #if defined(HARRIS_TARGET) && defined(_M88K)
5764 /* The Harris 88110 gdb ports have long kept their special reg
5765 numbers between their gp-regs and their x-regs. This is
5766 not how our dwarf is generated. Punt. */
5769 stack
[++stacki
] = unsnd
;
5805 basereg
= op
- DW_OP_breg0
;
5806 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5812 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5814 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5819 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5821 if (frame_base_reg
>= 0)
5824 basereg
= frame_base_reg
;
5825 stack
[stacki
] += frame_base_offset
;
5829 complain (&dwarf2_missing_at_frame_base
);
5835 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
5836 cu_header
, &bytes_read
);
5841 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5846 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5851 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5856 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5861 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5866 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5871 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5877 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5882 stack
[stacki
- 1] += stack
[stacki
];
5886 case DW_OP_plus_uconst
:
5887 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5892 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5898 /* If we're not the last op, then we definitely can't encode
5899 this using GDB's address_class enum. */
5901 complain (&dwarf2_complex_location_expr
);
5905 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
5906 return (stack
[stacki
]);
5909 return (stack
[stacki
]);
5912 /* memory allocation interface */
5916 dwarf2_free_tmp_obstack (PTR ignore
)
5918 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5921 static struct dwarf_block
*
5922 dwarf_alloc_block (void)
5924 struct dwarf_block
*blk
;
5926 blk
= (struct dwarf_block
*)
5927 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5931 static struct abbrev_info
*
5932 dwarf_alloc_abbrev (void)
5934 struct abbrev_info
*abbrev
;
5936 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5937 memset (abbrev
, 0, sizeof (struct abbrev_info
));
5941 static struct die_info
*
5942 dwarf_alloc_die (void)
5944 struct die_info
*die
;
5946 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5947 memset (die
, 0, sizeof (struct die_info
));