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
;
199 struct dwarf_block
*locdesc
;
200 unsigned int language
;
204 /* This data structure holds the information of an abbrev. */
207 unsigned int number
; /* number identifying abbrev */
208 enum dwarf_tag tag
; /* dwarf tag */
209 int has_children
; /* boolean */
210 unsigned int num_attrs
; /* number of attributes */
211 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
212 struct abbrev_info
*next
; /* next in chain */
217 enum dwarf_attribute name
;
218 enum dwarf_form form
;
221 /* This data structure holds a complete die structure. */
224 enum dwarf_tag tag
; /* Tag indicating type of die */
225 unsigned short has_children
; /* Does the die have children */
226 unsigned int abbrev
; /* Abbrev number */
227 unsigned int offset
; /* Offset in .debug_info section */
228 unsigned int num_attrs
; /* Number of attributes */
229 struct attribute
*attrs
; /* An array of attributes */
230 struct die_info
*next_ref
; /* Next die in ref hash table */
231 struct die_info
*next
; /* Next die in linked list */
232 struct type
*type
; /* Cached type information */
235 /* Attributes have a name and a value */
238 enum dwarf_attribute name
;
239 enum dwarf_form form
;
243 struct dwarf_block
*blk
;
251 /* Get at parts of an attribute structure */
253 #define DW_STRING(attr) ((attr)->u.str)
254 #define DW_UNSND(attr) ((attr)->u.unsnd)
255 #define DW_BLOCK(attr) ((attr)->u.blk)
256 #define DW_SND(attr) ((attr)->u.snd)
257 #define DW_ADDR(attr) ((attr)->u.addr)
259 /* Blocks are a bunch of untyped bytes. */
266 /* We only hold one compilation unit's abbrevs in
267 memory at any one time. */
268 #ifndef ABBREV_HASH_SIZE
269 #define ABBREV_HASH_SIZE 121
271 #ifndef ATTR_ALLOC_CHUNK
272 #define ATTR_ALLOC_CHUNK 4
275 static struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
277 /* A hash table of die offsets for following references. */
278 #ifndef REF_HASH_SIZE
279 #define REF_HASH_SIZE 1021
282 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
284 /* Obstack for allocating temporary storage used during symbol reading. */
285 static struct obstack dwarf2_tmp_obstack
;
287 /* Offset to the first byte of the current compilation unit header,
288 for resolving relative reference dies. */
289 static unsigned int cu_header_offset
;
291 /* Allocate fields for structs, unions and enums in this size. */
292 #ifndef DW_FIELD_ALLOC_CHUNK
293 #define DW_FIELD_ALLOC_CHUNK 4
296 /* The language we are debugging. */
297 static enum language cu_language
;
298 static const struct language_defn
*cu_language_defn
;
300 /* Actually data from the sections. */
301 static char *dwarf_info_buffer
;
302 static char *dwarf_abbrev_buffer
;
303 static char *dwarf_line_buffer
;
305 /* A zeroed version of a partial die for initialization purposes. */
306 static struct partial_die_info zeroed_partial_die
;
308 /* The generic symbol table building routines have separate lists for
309 file scope symbols and all all other scopes (local scopes). So
310 we need to select the right one to pass to add_symbol_to_list().
311 We do it by keeping a pointer to the correct list in list_in_scope.
313 FIXME: The original dwarf code just treated the file scope as the first
314 local scope, and all other local scopes as nested local scopes, and worked
315 fine. Check to see if we really need to distinguish these
317 static struct pending
**list_in_scope
= &file_symbols
;
319 /* FIXME: decode_locdesc sets these variables to describe the location
320 to the caller. These ought to be a structure or something. If
321 none of the flags are set, the object lives at the address returned
322 by decode_locdesc. */
324 static int optimized_out
; /* No ops in location in expression,
325 so object was optimized out. */
326 static int isreg
; /* Object lives in register.
327 decode_locdesc's return value is
328 the register number. */
329 static int offreg
; /* Object's address is the sum of the
330 register specified by basereg, plus
331 the offset returned. */
332 static int basereg
; /* See `offreg'. */
333 static int isderef
; /* Value described by flags above is
334 the address of a pointer to the object. */
335 static int islocal
; /* Variable is at the returned offset
336 from the frame start, but there's
337 no identified frame pointer for
338 this function, so we can't say
339 which register it's relative to;
342 /* DW_AT_frame_base values for the current function.
343 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
344 contains the register number for the frame register.
345 frame_base_offset is the offset from the frame register to the
346 virtual stack frame. */
347 static int frame_base_reg
;
348 static CORE_ADDR frame_base_offset
;
350 /* This value is added to each symbol value. FIXME: Generalize to
351 the section_offsets structure used by dbxread (once this is done,
352 pass the appropriate section number to end_symtab). */
353 static CORE_ADDR baseaddr
; /* Add to each symbol value */
355 /* We put a pointer to this structure in the read_symtab_private field
357 The complete dwarf information for an objfile is kept in the
358 psymbol_obstack, so that absolute die references can be handled.
359 Most of the information in this structure is related to an entire
360 object file and could be passed via the sym_private field of the objfile.
361 It is however conceivable that dwarf2 might not be the only type
362 of symbols read from an object file. */
366 /* Pointer to start of dwarf info buffer for the objfile. */
368 char *dwarf_info_buffer
;
370 /* Offset in dwarf_info_buffer for this compilation unit. */
372 unsigned long dwarf_info_offset
;
374 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
376 char *dwarf_abbrev_buffer
;
378 /* Size of dwarf abbreviation section for the objfile. */
380 unsigned int dwarf_abbrev_size
;
382 /* Pointer to start of dwarf line buffer for the objfile. */
384 char *dwarf_line_buffer
;
387 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
388 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
389 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
390 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
391 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
392 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
394 /* Maintain an array of referenced fundamental types for the current
395 compilation unit being read. For DWARF version 1, we have to construct
396 the fundamental types on the fly, since no information about the
397 fundamental types is supplied. Each such fundamental type is created by
398 calling a language dependent routine to create the type, and then a
399 pointer to that type is then placed in the array at the index specified
400 by it's FT_<TYPENAME> value. The array has a fixed size set by the
401 FT_NUM_MEMBERS compile time constant, which is the number of predefined
402 fundamental types gdb knows how to construct. */
403 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
405 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
406 but this would require a corresponding change in unpack_field_as_long
408 static int bits_per_byte
= 8;
410 /* The routines that read and process dies for a C struct or C++ class
411 pass lists of data member fields and lists of member function fields
412 in an instance of a field_info structure, as defined below. */
415 /* List of data member and baseclasses fields. */
418 struct nextfield
*next
;
425 /* Number of fields. */
428 /* Number of baseclasses. */
431 /* Set if the accesibility of one of the fields is not public. */
432 int non_public_fields
;
434 /* Member function fields array, entries are allocated in the order they
435 are encountered in the object file. */
438 struct nextfnfield
*next
;
439 struct fn_field fnfield
;
443 /* Member function fieldlist array, contains name of possibly overloaded
444 member function, number of overloaded member functions and a pointer
445 to the head of the member function field chain. */
450 struct nextfnfield
*head
;
454 /* Number of entries in the fnfieldlists array. */
458 /* FIXME: Kludge to mark a varargs function type for C++ member function
459 argument processing. */
460 #define TYPE_FLAG_VARARGS (1 << 10)
462 /* Dwarf2 has no clean way to discern C++ static and non-static member
463 functions. G++ helps GDB by marking the first parameter for non-static
464 member functions (which is the this pointer) as artificial.
465 We pass this information between dwarf2_add_member_fn and
466 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
467 #define TYPE_FIELD_ARTIFICIAL TYPE_FIELD_BITPOS
469 /* Various complaints about symbol reading that don't abort the process */
471 static struct complaint dwarf2_const_ignored
=
473 "type qualifier 'const' ignored", 0, 0
475 static struct complaint dwarf2_volatile_ignored
=
477 "type qualifier 'volatile' ignored", 0, 0
479 static struct complaint dwarf2_non_const_array_bound_ignored
=
481 "non-constant array bounds form '%s' ignored", 0, 0
483 static struct complaint dwarf2_missing_line_number_section
=
485 "missing .debug_line section", 0, 0
487 static struct complaint dwarf2_mangled_line_number_section
=
489 "mangled .debug_line section", 0, 0
491 static struct complaint dwarf2_unsupported_die_ref_attr
=
493 "unsupported die ref attribute form: '%s'", 0, 0
495 static struct complaint dwarf2_unsupported_stack_op
=
497 "unsupported stack op: '%s'", 0, 0
499 static struct complaint dwarf2_complex_location_expr
=
501 "location expression too complex", 0, 0
503 static struct complaint dwarf2_unsupported_tag
=
505 "unsupported tag: '%s'", 0, 0
507 static struct complaint dwarf2_unsupported_at_encoding
=
509 "unsupported DW_AT_encoding: '%s'", 0, 0
511 static struct complaint dwarf2_unsupported_at_frame_base
=
513 "unsupported DW_AT_frame_base for function '%s'", 0, 0
515 static struct complaint dwarf2_unexpected_tag
=
517 "unexepected tag in read_type_die: '%s'", 0, 0
519 static struct complaint dwarf2_missing_at_frame_base
=
521 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
523 static struct complaint dwarf2_bad_static_member_name
=
525 "unrecognized static data member name '%s'", 0, 0
527 static struct complaint dwarf2_unsupported_accessibility
=
529 "unsupported accessibility %d", 0, 0
531 static struct complaint dwarf2_bad_member_name_complaint
=
533 "cannot extract member name from '%s'", 0, 0
535 static struct complaint dwarf2_missing_member_fn_type_complaint
=
537 "member function type missing for '%s'", 0, 0
539 static struct complaint dwarf2_vtbl_not_found_complaint
=
541 "virtual function table pointer not found when defining class '%s'", 0, 0
543 static struct complaint dwarf2_absolute_sibling_complaint
=
545 "ignoring absolute DW_AT_sibling", 0, 0
547 static struct complaint dwarf2_const_value_length_mismatch
=
549 "const value length mismatch for '%s', got %d, expected %d", 0, 0
551 static struct complaint dwarf2_unsupported_const_value_attr
=
553 "unsupported const value attribute form: '%s'", 0, 0
556 /* Externals references. */
557 extern int info_verbose
; /* From main.c; nonzero => verbose */
559 /* local function prototypes */
561 static void dwarf2_locate_sections (bfd
*, asection
*, PTR
);
564 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
567 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
569 static char *scan_partial_symbols (char *, struct objfile
*,
570 CORE_ADDR
*, CORE_ADDR
*,
571 const struct comp_unit_head
*);
573 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
574 const struct comp_unit_head
*);
576 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
578 static void psymtab_to_symtab_1 (struct partial_symtab
*);
580 static char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int);
582 static void dwarf2_read_abbrevs (bfd
*, unsigned int);
584 static void dwarf2_empty_abbrev_table (PTR
);
586 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int);
588 static char *read_partial_die (struct partial_die_info
*,
589 bfd
*, char *, int *,
590 const struct comp_unit_head
*);
592 static char *read_full_die (struct die_info
**, bfd
*, char *,
593 const struct comp_unit_head
*);
595 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
596 bfd
*, char *, const struct comp_unit_head
*);
598 static unsigned int read_1_byte (bfd
*, char *);
600 static int read_1_signed_byte (bfd
*, char *);
602 static unsigned int read_2_bytes (bfd
*, char *);
604 static unsigned int read_4_bytes (bfd
*, char *);
606 static unsigned long read_8_bytes (bfd
*, char *);
608 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
611 static LONGEST
read_initial_length (bfd
*, char *,
612 struct comp_unit_head
*, int *bytes_read
);
614 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
617 static char *read_n_bytes (bfd
*, char *, unsigned int);
619 static char *read_string (bfd
*, char *, unsigned int *);
621 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
623 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
625 static void set_cu_language (unsigned int);
627 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
629 static int die_is_declaration (struct die_info
*);
631 static void dwarf_decode_lines (unsigned int, char *, bfd
*,
632 const struct comp_unit_head
*);
634 static void dwarf2_start_subfile (char *, char *);
636 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
637 struct objfile
*, const struct comp_unit_head
*);
639 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
640 struct objfile
*, const struct comp_unit_head
*);
642 static void dwarf2_const_value_data (struct attribute
*attr
,
646 static struct type
*die_type (struct die_info
*, struct objfile
*,
647 const struct comp_unit_head
*);
649 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
650 const struct comp_unit_head
*);
653 static struct type
*type_at_offset (unsigned int, struct objfile
*);
656 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
657 const struct comp_unit_head
*);
659 static void read_type_die (struct die_info
*, struct objfile
*,
660 const struct comp_unit_head
*);
662 static void read_typedef (struct die_info
*, struct objfile
*,
663 const struct comp_unit_head
*);
665 static void read_base_type (struct die_info
*, struct objfile
*);
667 static void read_file_scope (struct die_info
*, struct objfile
*,
668 const struct comp_unit_head
*);
670 static void read_func_scope (struct die_info
*, struct objfile
*,
671 const struct comp_unit_head
*);
673 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
674 const struct comp_unit_head
*);
676 static int dwarf2_get_pc_bounds (struct die_info
*,
677 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*);
679 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
680 struct objfile
*, const struct comp_unit_head
*);
682 static void dwarf2_attach_fields_to_type (struct field_info
*,
683 struct type
*, struct objfile
*);
685 static void dwarf2_add_member_fn (struct field_info
*,
686 struct die_info
*, struct type
*,
687 struct objfile
*objfile
,
688 const struct comp_unit_head
*);
690 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
691 struct type
*, struct objfile
*);
693 static void read_structure_scope (struct die_info
*, struct objfile
*,
694 const struct comp_unit_head
*);
696 static void read_common_block (struct die_info
*, struct objfile
*,
697 const struct comp_unit_head
*);
699 static void read_enumeration (struct die_info
*, struct objfile
*,
700 const struct comp_unit_head
*);
702 static struct type
*dwarf_base_type (int, int, struct objfile
*);
704 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
705 const struct comp_unit_head
*);
707 static void read_array_type (struct die_info
*, struct objfile
*,
708 const struct comp_unit_head
*);
710 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
711 const struct comp_unit_head
*);
713 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
714 const struct comp_unit_head
*);
716 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
717 const struct comp_unit_head
*);
719 static void read_tag_const_type (struct die_info
*, struct objfile
*,
720 const struct comp_unit_head
*);
722 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
723 const struct comp_unit_head
*);
725 static void read_tag_string_type (struct die_info
*, struct objfile
*);
727 static void read_subroutine_type (struct die_info
*, struct objfile
*,
728 const struct comp_unit_head
*);
730 static struct die_info
*read_comp_unit (char *, bfd
*,
731 const struct comp_unit_head
*);
733 static void free_die_list (struct die_info
*);
735 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
737 static void process_die (struct die_info
*, struct objfile
*,
738 const struct comp_unit_head
*);
740 static char *dwarf2_linkage_name (struct die_info
*);
742 static char *dwarf_tag_name (unsigned int);
744 static char *dwarf_attr_name (unsigned int);
746 static char *dwarf_form_name (unsigned int);
748 static char *dwarf_stack_op_name (unsigned int);
750 static char *dwarf_bool_name (unsigned int);
752 static char *dwarf_type_encoding_name (unsigned int);
755 static char *dwarf_cfi_name (unsigned int);
757 struct die_info
*copy_die (struct die_info
*);
760 static struct die_info
*sibling_die (struct die_info
*);
762 static void dump_die (struct die_info
*);
764 static void dump_die_list (struct die_info
*);
766 static void store_in_ref_table (unsigned int, struct die_info
*);
768 static void dwarf2_empty_hash_tables (void);
770 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
772 static struct die_info
*follow_die_ref (unsigned int);
774 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
776 /* memory allocation interface */
778 static void dwarf2_free_tmp_obstack (PTR
);
780 static struct dwarf_block
*dwarf_alloc_block (void);
782 static struct abbrev_info
*dwarf_alloc_abbrev (void);
784 static struct die_info
*dwarf_alloc_die (void);
786 /* Try to locate the sections we need for DWARF 2 debugging
787 information and return true if we have enough to do something. */
790 dwarf2_has_info (bfd
*abfd
)
792 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
793 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
794 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
804 /* This function is mapped across the sections and remembers the
805 offset and size of each of the debugging sections we are interested
809 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, PTR ignore_ptr
)
811 if (STREQ (sectp
->name
, INFO_SECTION
))
813 dwarf_info_offset
= sectp
->filepos
;
814 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
816 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
818 dwarf_abbrev_offset
= sectp
->filepos
;
819 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
821 else if (STREQ (sectp
->name
, LINE_SECTION
))
823 dwarf_line_offset
= sectp
->filepos
;
824 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
826 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
828 dwarf_pubnames_offset
= sectp
->filepos
;
829 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
831 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
833 dwarf_aranges_offset
= sectp
->filepos
;
834 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
836 else if (STREQ (sectp
->name
, LOC_SECTION
))
838 dwarf_loc_offset
= sectp
->filepos
;
839 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
841 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
843 dwarf_macinfo_offset
= sectp
->filepos
;
844 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
846 else if (STREQ (sectp
->name
, STR_SECTION
))
848 dwarf_str_offset
= sectp
->filepos
;
849 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
853 /* Build a partial symbol table. */
856 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
859 /* We definitely need the .debug_info and .debug_abbrev sections */
861 dwarf_info_buffer
= dwarf2_read_section (objfile
,
864 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
867 dwarf_line_buffer
= dwarf2_read_section (objfile
,
871 if (mainline
|| objfile
->global_psymbols
.size
== 0 ||
872 objfile
->static_psymbols
.size
== 0)
874 init_psymbol_list (objfile
, 1024);
878 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
880 /* Things are significantly easier if we have .debug_aranges and
881 .debug_pubnames sections */
883 dwarf2_build_psymtabs_easy (objfile
, mainline
);
887 /* only test this case for now */
889 /* In this case we have to work a bit harder */
890 dwarf2_build_psymtabs_hard (objfile
, mainline
);
895 /* Build the partial symbol table from the information in the
896 .debug_pubnames and .debug_aranges sections. */
899 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
901 bfd
*abfd
= objfile
->obfd
;
902 char *aranges_buffer
, *pubnames_buffer
;
903 char *aranges_ptr
, *pubnames_ptr
;
904 unsigned int entry_length
, version
, info_offset
, info_size
;
906 pubnames_buffer
= dwarf2_read_section (objfile
,
907 dwarf_pubnames_offset
,
908 dwarf_pubnames_size
);
909 pubnames_ptr
= pubnames_buffer
;
910 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
912 struct comp_unit_head cu_header
;
915 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
917 pubnames_ptr
+= bytes_read
;
918 version
= read_1_byte (abfd
, pubnames_ptr
);
920 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
922 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
926 aranges_buffer
= dwarf2_read_section (objfile
,
927 dwarf_aranges_offset
,
933 /* Read in the comp unit header information from the debug_info at
937 read_comp_unit_head (struct comp_unit_head
*cu_header
,
938 char *info_ptr
, bfd
*abfd
)
942 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
944 info_ptr
+= bytes_read
;
945 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
947 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
949 info_ptr
+= bytes_read
;
950 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
952 signed_addr
= bfd_get_sign_extend_vma (abfd
);
954 internal_error (__FILE__
, __LINE__
,
955 "read_comp_unit_head: dwarf from non elf file");
956 cu_header
->signed_addr_p
= signed_addr
;
960 /* Build the partial symbol table by doing a quick pass through the
961 .debug_info and .debug_abbrev sections. */
964 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
966 /* Instead of reading this into a big buffer, we should probably use
967 mmap() on architectures that support it. (FIXME) */
968 bfd
*abfd
= objfile
->obfd
;
969 char *info_ptr
, *abbrev_ptr
;
970 char *beg_of_comp_unit
;
971 struct partial_die_info comp_unit_die
;
972 struct partial_symtab
*pst
;
973 struct cleanup
*back_to
;
974 int comp_unit_has_pc_info
;
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 while ((unsigned int) (info_ptr
- dwarf_info_buffer
)
984 + ((info_ptr
- dwarf_info_buffer
) % 4) < dwarf_info_size
)
986 struct comp_unit_head cu_header
;
987 beg_of_comp_unit
= info_ptr
;
988 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
990 if (cu_header
.version
!= 2)
992 error ("Dwarf Error: wrong version in compilation unit header.");
995 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
997 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
998 (long) cu_header
.abbrev_offset
,
999 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1002 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1003 > dwarf_info_buffer
+ dwarf_info_size
)
1005 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
1006 (long) cu_header
.length
,
1007 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1010 /* Read the abbrevs for this compilation unit into a table */
1011 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1012 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1014 /* Read the compilation unit die */
1015 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1016 &comp_unit_has_pc_info
, &cu_header
);
1018 /* Set the language we're debugging */
1019 set_cu_language (comp_unit_die
.language
);
1021 /* Allocate a new partial symbol table structure */
1022 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1023 comp_unit_die
.name
? comp_unit_die
.name
: "",
1024 comp_unit_die
.lowpc
,
1025 objfile
->global_psymbols
.next
,
1026 objfile
->static_psymbols
.next
);
1028 pst
->read_symtab_private
= (char *)
1029 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1030 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1031 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1032 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1033 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1034 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1035 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1036 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1038 /* Store the function that reads in the rest of the symbol table */
1039 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1041 /* Check if comp unit has_children.
1042 If so, read the rest of the partial symbols from this comp unit.
1043 If not, there's no more debug_info for this comp unit. */
1044 if (comp_unit_die
.has_children
)
1046 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1049 /* If the compilation unit didn't have an explicit address range,
1050 then use the information extracted from its child dies. */
1051 if (!comp_unit_has_pc_info
)
1053 comp_unit_die
.lowpc
= lowpc
;
1054 comp_unit_die
.highpc
= highpc
;
1057 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1058 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1060 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1061 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1062 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1063 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1064 sort_pst_symbols (pst
);
1066 /* If there is already a psymtab or symtab for a file of this
1067 name, remove it. (If there is a symtab, more drastic things
1068 also happen.) This happens in VxWorks. */
1069 free_named_symtabs (pst
->filename
);
1071 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1072 + cu_header
.initial_length_size
;
1074 do_cleanups (back_to
);
1077 /* Read in all interesting dies to the end of the compilation unit. */
1080 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1081 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1082 const struct comp_unit_head
*cu_header
)
1084 bfd
*abfd
= objfile
->obfd
;
1085 struct partial_die_info pdi
;
1087 /* This function is called after we've read in the comp_unit_die in
1088 order to read its children. We start the nesting level at 1 since
1089 we have pushed 1 level down in order to read the comp unit's children.
1090 The comp unit itself is at level 0, so we stop reading when we pop
1091 back to that level. */
1093 int nesting_level
= 1;
1096 *lowpc
= ((CORE_ADDR
) -1);
1097 *highpc
= ((CORE_ADDR
) 0);
1099 while (nesting_level
)
1101 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
,
1102 &has_pc_info
, cu_header
);
1108 case DW_TAG_subprogram
:
1111 if (pdi
.lowpc
< *lowpc
)
1115 if (pdi
.highpc
> *highpc
)
1117 *highpc
= pdi
.highpc
;
1119 if ((pdi
.is_external
|| nesting_level
== 1)
1120 && !pdi
.is_declaration
)
1122 add_partial_symbol (&pdi
, objfile
, cu_header
);
1126 case DW_TAG_variable
:
1127 case DW_TAG_typedef
:
1128 case DW_TAG_class_type
:
1129 case DW_TAG_structure_type
:
1130 case DW_TAG_union_type
:
1131 case DW_TAG_enumeration_type
:
1132 if ((pdi
.is_external
|| nesting_level
== 1)
1133 && !pdi
.is_declaration
)
1135 add_partial_symbol (&pdi
, objfile
, cu_header
);
1138 case DW_TAG_enumerator
:
1139 /* File scope enumerators are added to the partial symbol
1141 if (nesting_level
== 2)
1142 add_partial_symbol (&pdi
, objfile
, cu_header
);
1144 case DW_TAG_base_type
:
1145 /* File scope base type definitions are added to the partial
1147 if (nesting_level
== 1)
1148 add_partial_symbol (&pdi
, objfile
, cu_header
);
1155 /* If the die has a sibling, skip to the sibling.
1156 Do not skip enumeration types, we want to record their
1158 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1160 info_ptr
= pdi
.sibling
;
1162 else if (pdi
.has_children
)
1164 /* Die has children, but the optional DW_AT_sibling attribute
1175 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1176 from `maint check'. */
1177 if (*lowpc
== ((CORE_ADDR
) -1))
1183 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1184 const struct comp_unit_head
*cu_header
)
1190 case DW_TAG_subprogram
:
1191 if (pdi
->is_external
)
1193 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1194 mst_text, objfile); */
1195 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1196 VAR_NAMESPACE
, LOC_BLOCK
,
1197 &objfile
->global_psymbols
,
1198 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1202 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1203 mst_file_text, objfile); */
1204 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1205 VAR_NAMESPACE
, LOC_BLOCK
,
1206 &objfile
->static_psymbols
,
1207 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1210 case DW_TAG_variable
:
1211 if (pdi
->is_external
)
1214 Don't enter into the minimal symbol tables as there is
1215 a minimal symbol table entry from the ELF symbols already.
1216 Enter into partial symbol table if it has a location
1217 descriptor or a type.
1218 If the location descriptor is missing, new_symbol will create
1219 a LOC_UNRESOLVED symbol, the address of the variable will then
1220 be determined from the minimal symbol table whenever the variable
1222 The address for the partial symbol table entry is not
1223 used by GDB, but it comes in handy for debugging partial symbol
1227 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1228 if (pdi
->locdesc
|| pdi
->has_type
)
1229 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1230 VAR_NAMESPACE
, LOC_STATIC
,
1231 &objfile
->global_psymbols
,
1232 0, addr
+ baseaddr
, cu_language
, objfile
);
1236 /* Static Variable. Skip symbols without location descriptors. */
1237 if (pdi
->locdesc
== NULL
)
1239 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1240 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1241 mst_file_data, objfile); */
1242 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1243 VAR_NAMESPACE
, LOC_STATIC
,
1244 &objfile
->static_psymbols
,
1245 0, addr
+ baseaddr
, cu_language
, objfile
);
1248 case DW_TAG_typedef
:
1249 case DW_TAG_base_type
:
1250 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1251 VAR_NAMESPACE
, LOC_TYPEDEF
,
1252 &objfile
->static_psymbols
,
1253 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1255 case DW_TAG_class_type
:
1256 case DW_TAG_structure_type
:
1257 case DW_TAG_union_type
:
1258 case DW_TAG_enumeration_type
:
1259 /* Skip aggregate types without children, these are external
1261 if (pdi
->has_children
== 0)
1263 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1264 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1265 &objfile
->static_psymbols
,
1266 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1268 if (cu_language
== language_cplus
)
1270 /* For C++, these implicitly act as typedefs as well. */
1271 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1272 VAR_NAMESPACE
, LOC_TYPEDEF
,
1273 &objfile
->static_psymbols
,
1274 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1277 case DW_TAG_enumerator
:
1278 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1279 VAR_NAMESPACE
, LOC_CONST
,
1280 &objfile
->static_psymbols
,
1281 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1288 /* Expand this partial symbol table into a full symbol table. */
1291 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1293 /* FIXME: This is barely more than a stub. */
1298 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1304 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1305 gdb_flush (gdb_stdout
);
1308 psymtab_to_symtab_1 (pst
);
1310 /* Finish up the debug error message. */
1312 printf_filtered ("done.\n");
1318 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1320 struct objfile
*objfile
= pst
->objfile
;
1321 bfd
*abfd
= objfile
->obfd
;
1322 struct comp_unit_head cu_header
;
1323 struct die_info
*dies
;
1324 unsigned long offset
;
1325 CORE_ADDR lowpc
, highpc
;
1326 struct die_info
*child_die
;
1328 struct symtab
*symtab
;
1329 struct cleanup
*back_to
;
1331 /* Set local variables from the partial symbol table info. */
1332 offset
= DWARF_INFO_OFFSET (pst
);
1333 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1334 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1335 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1336 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1337 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1338 cu_header_offset
= offset
;
1339 info_ptr
= dwarf_info_buffer
+ offset
;
1341 obstack_init (&dwarf2_tmp_obstack
);
1342 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1345 make_cleanup (really_free_pendings
, NULL
);
1347 /* read in the comp_unit header */
1348 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1350 /* Read the abbrevs for this compilation unit */
1351 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1352 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1354 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1356 make_cleanup_free_die_list (dies
);
1358 /* Do line number decoding in read_file_scope () */
1359 process_die (dies
, objfile
, &cu_header
);
1361 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1363 /* Some compilers don't define a DW_AT_high_pc attribute for
1364 the compilation unit. If the DW_AT_high_pc is missing,
1365 synthesize it, by scanning the DIE's below the compilation unit. */
1367 if (dies
->has_children
)
1369 child_die
= dies
->next
;
1370 while (child_die
&& child_die
->tag
)
1372 if (child_die
->tag
== DW_TAG_subprogram
)
1374 CORE_ADDR low
, high
;
1376 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1378 highpc
= max (highpc
, high
);
1381 child_die
= sibling_die (child_die
);
1385 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1387 /* Set symtab language to language from DW_AT_language.
1388 If the compilation is from a C file generated by language preprocessors,
1389 do not set the language if it was already deduced by start_subfile. */
1391 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1393 symtab
->language
= cu_language
;
1395 pst
->symtab
= symtab
;
1397 sort_symtab_syms (pst
->symtab
);
1399 do_cleanups (back_to
);
1402 /* Process a die and its children. */
1405 process_die (struct die_info
*die
, struct objfile
*objfile
,
1406 const struct comp_unit_head
*cu_header
)
1410 case DW_TAG_padding
:
1412 case DW_TAG_compile_unit
:
1413 read_file_scope (die
, objfile
, cu_header
);
1415 case DW_TAG_subprogram
:
1416 read_subroutine_type (die
, objfile
, cu_header
);
1417 read_func_scope (die
, objfile
, cu_header
);
1419 case DW_TAG_inlined_subroutine
:
1420 /* FIXME: These are ignored for now.
1421 They could be used to set breakpoints on all inlined instances
1422 of a function and make GDB `next' properly over inlined functions. */
1424 case DW_TAG_lexical_block
:
1425 read_lexical_block_scope (die
, objfile
, cu_header
);
1427 case DW_TAG_class_type
:
1428 case DW_TAG_structure_type
:
1429 case DW_TAG_union_type
:
1430 read_structure_scope (die
, objfile
, cu_header
);
1432 case DW_TAG_enumeration_type
:
1433 read_enumeration (die
, objfile
, cu_header
);
1435 case DW_TAG_subroutine_type
:
1436 read_subroutine_type (die
, objfile
, cu_header
);
1438 case DW_TAG_array_type
:
1439 read_array_type (die
, objfile
, cu_header
);
1441 case DW_TAG_pointer_type
:
1442 read_tag_pointer_type (die
, objfile
, cu_header
);
1444 case DW_TAG_ptr_to_member_type
:
1445 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1447 case DW_TAG_reference_type
:
1448 read_tag_reference_type (die
, objfile
, cu_header
);
1450 case DW_TAG_string_type
:
1451 read_tag_string_type (die
, objfile
);
1453 case DW_TAG_base_type
:
1454 read_base_type (die
, objfile
);
1455 if (dwarf_attr (die
, DW_AT_name
))
1457 /* Add a typedef symbol for the base type definition. */
1458 new_symbol (die
, die
->type
, objfile
, cu_header
);
1461 case DW_TAG_common_block
:
1462 read_common_block (die
, objfile
, cu_header
);
1464 case DW_TAG_common_inclusion
:
1467 new_symbol (die
, NULL
, objfile
, cu_header
);
1473 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1474 const struct comp_unit_head
*cu_header
)
1476 unsigned int line_offset
= 0;
1477 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1478 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1479 struct attribute
*attr
;
1480 char *name
= "<unknown>";
1481 char *comp_dir
= NULL
;
1482 struct die_info
*child_die
;
1483 bfd
*abfd
= objfile
->obfd
;
1485 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1487 if (die
->has_children
)
1489 child_die
= die
->next
;
1490 while (child_die
&& child_die
->tag
)
1492 if (child_die
->tag
== DW_TAG_subprogram
)
1494 CORE_ADDR low
, high
;
1496 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1498 lowpc
= min (lowpc
, low
);
1499 highpc
= max (highpc
, high
);
1502 child_die
= sibling_die (child_die
);
1507 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1508 from finish_block. */
1509 if (lowpc
== ((CORE_ADDR
) -1))
1514 attr
= dwarf_attr (die
, DW_AT_name
);
1517 name
= DW_STRING (attr
);
1519 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1522 comp_dir
= DW_STRING (attr
);
1525 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1526 directory, get rid of it. */
1527 char *cp
= strchr (comp_dir
, ':');
1529 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1534 if (objfile
->ei
.entry_point
>= lowpc
&&
1535 objfile
->ei
.entry_point
< highpc
)
1537 objfile
->ei
.entry_file_lowpc
= lowpc
;
1538 objfile
->ei
.entry_file_highpc
= highpc
;
1541 attr
= dwarf_attr (die
, DW_AT_language
);
1544 set_cu_language (DW_UNSND (attr
));
1547 /* We assume that we're processing GCC output. */
1548 processing_gcc_compilation
= 2;
1550 /* FIXME:Do something here. */
1551 if (dip
->at_producer
!= NULL
)
1553 handle_producer (dip
->at_producer
);
1557 /* The compilation unit may be in a different language or objfile,
1558 zero out all remembered fundamental types. */
1559 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1561 start_symtab (name
, comp_dir
, lowpc
);
1562 record_debugformat ("DWARF 2");
1564 /* Decode line number information if present. */
1565 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1568 line_offset
= DW_UNSND (attr
);
1569 dwarf_decode_lines (line_offset
, comp_dir
, abfd
, cu_header
);
1572 /* Process all dies in compilation unit. */
1573 if (die
->has_children
)
1575 child_die
= die
->next
;
1576 while (child_die
&& child_die
->tag
)
1578 process_die (child_die
, objfile
, cu_header
);
1579 child_die
= sibling_die (child_die
);
1585 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
1586 const struct comp_unit_head
*cu_header
)
1588 register struct context_stack
*new;
1591 struct die_info
*child_die
;
1592 struct attribute
*attr
;
1595 name
= dwarf2_linkage_name (die
);
1597 /* Ignore functions with missing or empty names and functions with
1598 missing or invalid low and high pc attributes. */
1599 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1605 if (objfile
->ei
.entry_point
>= lowpc
&&
1606 objfile
->ei
.entry_point
< highpc
)
1608 objfile
->ei
.entry_func_lowpc
= lowpc
;
1609 objfile
->ei
.entry_func_highpc
= highpc
;
1612 /* Decode DW_AT_frame_base location descriptor if present, keep result
1613 for DW_OP_fbreg operands in decode_locdesc. */
1614 frame_base_reg
= -1;
1615 frame_base_offset
= 0;
1616 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1619 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
1621 complain (&dwarf2_unsupported_at_frame_base
, name
);
1623 frame_base_reg
= addr
;
1626 frame_base_reg
= basereg
;
1627 frame_base_offset
= addr
;
1630 complain (&dwarf2_unsupported_at_frame_base
, name
);
1633 new = push_context (0, lowpc
);
1634 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
1635 list_in_scope
= &local_symbols
;
1637 if (die
->has_children
)
1639 child_die
= die
->next
;
1640 while (child_die
&& child_die
->tag
)
1642 process_die (child_die
, objfile
, cu_header
);
1643 child_die
= sibling_die (child_die
);
1647 new = pop_context ();
1648 /* Make a block for the local symbols within. */
1649 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1650 lowpc
, highpc
, objfile
);
1651 list_in_scope
= &file_symbols
;
1654 /* Process all the DIES contained within a lexical block scope. Start
1655 a new scope, process the dies, and then close the scope. */
1658 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
1659 const struct comp_unit_head
*cu_header
)
1661 register struct context_stack
*new;
1662 CORE_ADDR lowpc
, highpc
;
1663 struct die_info
*child_die
;
1665 /* Ignore blocks with missing or invalid low and high pc attributes. */
1666 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1671 push_context (0, lowpc
);
1672 if (die
->has_children
)
1674 child_die
= die
->next
;
1675 while (child_die
&& child_die
->tag
)
1677 process_die (child_die
, objfile
, cu_header
);
1678 child_die
= sibling_die (child_die
);
1681 new = pop_context ();
1683 if (local_symbols
!= NULL
)
1685 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1688 local_symbols
= new->locals
;
1691 /* Get low and high pc attributes from a die.
1692 Return 1 if the attributes are present and valid, otherwise, return 0. */
1695 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1696 struct objfile
*objfile
)
1698 struct attribute
*attr
;
1702 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1704 low
= DW_ADDR (attr
);
1707 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1709 high
= DW_ADDR (attr
);
1716 /* When using the GNU linker, .gnu.linkonce. sections are used to
1717 eliminate duplicate copies of functions and vtables and such.
1718 The linker will arbitrarily choose one and discard the others.
1719 The AT_*_pc values for such functions refer to local labels in
1720 these sections. If the section from that file was discarded, the
1721 labels are not in the output, so the relocs get a value of 0.
1722 If this is a discarded function, mark the pc bounds as invalid,
1723 so that GDB will ignore it. */
1724 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1732 /* Add an aggregate field to the field list. */
1735 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
1736 struct objfile
*objfile
,
1737 const struct comp_unit_head
*cu_header
)
1739 struct nextfield
*new_field
;
1740 struct attribute
*attr
;
1742 char *fieldname
= "";
1744 /* Allocate a new field list entry and link it in. */
1745 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1746 make_cleanup (xfree
, new_field
);
1747 memset (new_field
, 0, sizeof (struct nextfield
));
1748 new_field
->next
= fip
->fields
;
1749 fip
->fields
= new_field
;
1752 /* Handle accessibility and virtuality of field.
1753 The default accessibility for members is public, the default
1754 accessibility for inheritance is private. */
1755 if (die
->tag
!= DW_TAG_inheritance
)
1756 new_field
->accessibility
= DW_ACCESS_public
;
1758 new_field
->accessibility
= DW_ACCESS_private
;
1759 new_field
->virtuality
= DW_VIRTUALITY_none
;
1761 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1763 new_field
->accessibility
= DW_UNSND (attr
);
1764 if (new_field
->accessibility
!= DW_ACCESS_public
)
1765 fip
->non_public_fields
= 1;
1766 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1768 new_field
->virtuality
= DW_UNSND (attr
);
1770 fp
= &new_field
->field
;
1771 if (die
->tag
== DW_TAG_member
)
1773 /* Get type of field. */
1774 fp
->type
= die_type (die
, objfile
, cu_header
);
1776 /* Get bit size of field (zero if none). */
1777 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1780 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1784 FIELD_BITSIZE (*fp
) = 0;
1787 /* Get bit offset of field. */
1788 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1791 FIELD_BITPOS (*fp
) =
1792 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
1795 FIELD_BITPOS (*fp
) = 0;
1796 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1799 if (BITS_BIG_ENDIAN
)
1801 /* For big endian bits, the DW_AT_bit_offset gives the
1802 additional bit offset from the MSB of the containing
1803 anonymous object to the MSB of the field. We don't
1804 have to do anything special since we don't need to
1805 know the size of the anonymous object. */
1806 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1810 /* For little endian bits, compute the bit offset to the
1811 MSB of the anonymous object, subtract off the number of
1812 bits from the MSB of the field to the MSB of the
1813 object, and then subtract off the number of bits of
1814 the field itself. The result is the bit offset of
1815 the LSB of the field. */
1817 int bit_offset
= DW_UNSND (attr
);
1819 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1822 /* The size of the anonymous object containing
1823 the bit field is explicit, so use the
1824 indicated size (in bytes). */
1825 anonymous_size
= DW_UNSND (attr
);
1829 /* The size of the anonymous object containing
1830 the bit field must be inferred from the type
1831 attribute of the data member containing the
1833 anonymous_size
= TYPE_LENGTH (fp
->type
);
1835 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1836 - bit_offset
- FIELD_BITSIZE (*fp
);
1840 /* Get name of field. */
1841 attr
= dwarf_attr (die
, DW_AT_name
);
1842 if (attr
&& DW_STRING (attr
))
1843 fieldname
= DW_STRING (attr
);
1844 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1845 &objfile
->type_obstack
);
1847 /* Change accessibility for artificial fields (e.g. virtual table
1848 pointer or virtual base class pointer) to private. */
1849 if (dwarf_attr (die
, DW_AT_artificial
))
1851 new_field
->accessibility
= DW_ACCESS_private
;
1852 fip
->non_public_fields
= 1;
1855 else if (die
->tag
== DW_TAG_variable
)
1859 /* C++ static member.
1860 Get name of field. */
1861 attr
= dwarf_attr (die
, DW_AT_name
);
1862 if (attr
&& DW_STRING (attr
))
1863 fieldname
= DW_STRING (attr
);
1867 /* Get physical name. */
1868 physname
= dwarf2_linkage_name (die
);
1870 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1871 &objfile
->type_obstack
));
1872 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1873 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1874 &objfile
->type_obstack
);
1876 else if (die
->tag
== DW_TAG_inheritance
)
1878 /* C++ base class field. */
1879 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1881 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
1883 FIELD_BITSIZE (*fp
) = 0;
1884 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1885 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1886 fip
->nbaseclasses
++;
1890 /* Create the vector of fields, and attach it to the type. */
1893 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
1894 struct objfile
*objfile
)
1896 int nfields
= fip
->nfields
;
1898 /* Record the field count, allocate space for the array of fields,
1899 and create blank accessibility bitfields if necessary. */
1900 TYPE_NFIELDS (type
) = nfields
;
1901 TYPE_FIELDS (type
) = (struct field
*)
1902 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1903 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1905 if (fip
->non_public_fields
)
1907 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1909 TYPE_FIELD_PRIVATE_BITS (type
) =
1910 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1911 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1913 TYPE_FIELD_PROTECTED_BITS (type
) =
1914 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1915 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1917 TYPE_FIELD_IGNORE_BITS (type
) =
1918 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1919 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1922 /* If the type has baseclasses, allocate and clear a bit vector for
1923 TYPE_FIELD_VIRTUAL_BITS. */
1924 if (fip
->nbaseclasses
)
1926 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
1929 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1930 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1931 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1932 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
1933 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
1936 /* Copy the saved-up fields into the field vector. Start from the head
1937 of the list, adding to the tail of the field array, so that they end
1938 up in the same order in the array in which they were added to the list. */
1939 while (nfields
-- > 0)
1941 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
1942 switch (fip
->fields
->accessibility
)
1944 case DW_ACCESS_private
:
1945 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
1948 case DW_ACCESS_protected
:
1949 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
1952 case DW_ACCESS_public
:
1956 /* Unknown accessibility. Complain and treat it as public. */
1958 complain (&dwarf2_unsupported_accessibility
,
1959 fip
->fields
->accessibility
);
1963 if (nfields
< fip
->nbaseclasses
)
1965 switch (fip
->fields
->virtuality
)
1967 case DW_VIRTUALITY_virtual
:
1968 case DW_VIRTUALITY_pure_virtual
:
1969 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
1973 fip
->fields
= fip
->fields
->next
;
1977 /* Add a member function to the proper fieldlist. */
1980 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
1981 struct type
*type
, struct objfile
*objfile
,
1982 const struct comp_unit_head
*cu_header
)
1984 struct attribute
*attr
;
1985 struct fnfieldlist
*flp
;
1987 struct fn_field
*fnp
;
1990 struct nextfnfield
*new_fnfield
;
1992 /* Get name of member function. */
1993 attr
= dwarf_attr (die
, DW_AT_name
);
1994 if (attr
&& DW_STRING (attr
))
1995 fieldname
= DW_STRING (attr
);
1999 /* Get the mangled name. */
2000 physname
= dwarf2_linkage_name (die
);
2002 /* Look up member function name in fieldlist. */
2003 for (i
= 0; i
< fip
->nfnfields
; i
++)
2005 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2009 /* Create new list element if necessary. */
2010 if (i
< fip
->nfnfields
)
2011 flp
= &fip
->fnfieldlists
[i
];
2014 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2016 fip
->fnfieldlists
= (struct fnfieldlist
*)
2017 xrealloc (fip
->fnfieldlists
,
2018 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2019 * sizeof (struct fnfieldlist
));
2020 if (fip
->nfnfields
== 0)
2021 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2023 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2024 flp
->name
= fieldname
;
2030 /* Create a new member function field and chain it to the field list
2032 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2033 make_cleanup (xfree
, new_fnfield
);
2034 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2035 new_fnfield
->next
= flp
->head
;
2036 flp
->head
= new_fnfield
;
2039 /* Fill in the member function field info. */
2040 fnp
= &new_fnfield
->fnfield
;
2041 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2042 &objfile
->type_obstack
);
2043 fnp
->type
= alloc_type (objfile
);
2044 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2046 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2047 struct type
**arg_types
;
2048 int nparams
= TYPE_NFIELDS (die
->type
);
2051 /* Copy argument types from the subroutine type. */
2052 arg_types
= (struct type
**)
2053 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2054 for (iparams
= 0; iparams
< nparams
; iparams
++)
2055 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2057 /* Set last entry in argument type vector. */
2058 if (TYPE_FLAGS (die
->type
) & TYPE_FLAG_VARARGS
)
2059 arg_types
[nparams
] = NULL
;
2061 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2063 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2065 /* Handle static member functions.
2066 Dwarf2 has no clean way to discern C++ static and non-static
2067 member functions. G++ helps GDB by marking the first
2068 parameter for non-static member functions (which is the
2069 this pointer) as artificial. We obtain this information
2070 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2071 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2072 fnp
->voffset
= VOFFSET_STATIC
;
2075 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2077 /* Get fcontext from DW_AT_containing_type if present. */
2078 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2079 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2081 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2082 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2084 /* Get accessibility. */
2085 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2088 switch (DW_UNSND (attr
))
2090 case DW_ACCESS_private
:
2091 fnp
->is_private
= 1;
2093 case DW_ACCESS_protected
:
2094 fnp
->is_protected
= 1;
2099 /* Get index in virtual function table if it is a virtual member function. */
2100 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2102 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2105 /* Create the vector of member function fields, and attach it to the type. */
2108 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2109 struct objfile
*objfile
)
2111 struct fnfieldlist
*flp
;
2112 int total_length
= 0;
2115 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2116 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2117 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2119 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2121 struct nextfnfield
*nfp
= flp
->head
;
2122 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2125 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2126 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2127 fn_flp
->fn_fields
= (struct fn_field
*)
2128 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2129 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2130 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2132 total_length
+= flp
->length
;
2135 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2136 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2139 /* Called when we find the DIE that starts a structure or union scope
2140 (definition) to process all dies that define the members of the
2143 NOTE: we need to call struct_type regardless of whether or not the
2144 DIE has an at_name attribute, since it might be an anonymous
2145 structure or union. This gets the type entered into our set of
2148 However, if the structure is incomplete (an opaque struct/union)
2149 then suppress creating a symbol table entry for it since gdb only
2150 wants to find the one with the complete definition. Note that if
2151 it is complete, we just call new_symbol, which does it's own
2152 checking about whether the struct/union is anonymous or not (and
2153 suppresses creating a symbol table entry itself). */
2156 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2157 const struct comp_unit_head
*cu_header
)
2160 struct attribute
*attr
;
2162 type
= alloc_type (objfile
);
2164 INIT_CPLUS_SPECIFIC (type
);
2165 attr
= dwarf_attr (die
, DW_AT_name
);
2166 if (attr
&& DW_STRING (attr
))
2168 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2169 strlen (DW_STRING (attr
)),
2170 &objfile
->type_obstack
);
2173 if (die
->tag
== DW_TAG_structure_type
)
2175 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2177 else if (die
->tag
== DW_TAG_union_type
)
2179 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2183 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2185 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2188 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2191 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2195 TYPE_LENGTH (type
) = 0;
2198 /* We need to add the type field to the die immediately so we don't
2199 infinitely recurse when dealing with pointers to the structure
2200 type within the structure itself. */
2203 if (die
->has_children
&& ! die_is_declaration (die
))
2205 struct field_info fi
;
2206 struct die_info
*child_die
;
2207 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2209 memset (&fi
, 0, sizeof (struct field_info
));
2211 child_die
= die
->next
;
2213 while (child_die
&& child_die
->tag
)
2215 if (child_die
->tag
== DW_TAG_member
)
2217 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2219 else if (child_die
->tag
== DW_TAG_variable
)
2221 /* C++ static member. */
2222 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2224 else if (child_die
->tag
== DW_TAG_subprogram
)
2226 /* C++ member function. */
2227 process_die (child_die
, objfile
, cu_header
);
2228 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2230 else if (child_die
->tag
== DW_TAG_inheritance
)
2232 /* C++ base class field. */
2233 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2237 process_die (child_die
, objfile
, cu_header
);
2239 child_die
= sibling_die (child_die
);
2242 /* Attach fields and member functions to the type. */
2244 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2247 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2249 /* Get the type which refers to the base class (possibly this
2250 class itself) which contains the vtable pointer for the current
2251 class from the DW_AT_containing_type attribute. */
2253 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2255 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2257 TYPE_VPTR_BASETYPE (type
) = t
;
2260 static const char vptr_name
[] =
2261 {'_', 'v', 'p', 't', 'r', '\0'};
2264 /* Our own class provides vtbl ptr. */
2265 for (i
= TYPE_NFIELDS (t
) - 1;
2266 i
>= TYPE_N_BASECLASSES (t
);
2269 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2271 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2272 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2274 TYPE_VPTR_FIELDNO (type
) = i
;
2279 /* Complain if virtual function table field not found. */
2280 if (i
< TYPE_N_BASECLASSES (t
))
2281 complain (&dwarf2_vtbl_not_found_complaint
,
2282 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2286 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2291 new_symbol (die
, type
, objfile
, cu_header
);
2293 do_cleanups (back_to
);
2297 /* No children, must be stub. */
2298 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2304 /* Given a pointer to a die which begins an enumeration, process all
2305 the dies that define the members of the enumeration.
2307 This will be much nicer in draft 6 of the DWARF spec when our
2308 members will be dies instead squished into the DW_AT_element_list
2311 NOTE: We reverse the order of the element list. */
2314 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2315 const struct comp_unit_head
*cu_header
)
2317 struct die_info
*child_die
;
2319 struct field
*fields
;
2320 struct attribute
*attr
;
2323 int unsigned_enum
= 1;
2325 type
= alloc_type (objfile
);
2327 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2328 attr
= dwarf_attr (die
, DW_AT_name
);
2329 if (attr
&& DW_STRING (attr
))
2331 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2332 strlen (DW_STRING (attr
)),
2333 &objfile
->type_obstack
);
2336 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2339 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2343 TYPE_LENGTH (type
) = 0;
2348 if (die
->has_children
)
2350 child_die
= die
->next
;
2351 while (child_die
&& child_die
->tag
)
2353 if (child_die
->tag
!= DW_TAG_enumerator
)
2355 process_die (child_die
, objfile
, cu_header
);
2359 attr
= dwarf_attr (child_die
, DW_AT_name
);
2362 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2363 if (SYMBOL_VALUE (sym
) < 0)
2366 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2368 fields
= (struct field
*)
2370 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2371 * sizeof (struct field
));
2374 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2375 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2376 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2377 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2383 child_die
= sibling_die (child_die
);
2388 TYPE_NFIELDS (type
) = num_fields
;
2389 TYPE_FIELDS (type
) = (struct field
*)
2390 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2391 memcpy (TYPE_FIELDS (type
), fields
,
2392 sizeof (struct field
) * num_fields
);
2396 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2399 new_symbol (die
, type
, objfile
, cu_header
);
2402 /* Extract all information from a DW_TAG_array_type DIE and put it in
2403 the DIE's type field. For now, this only handles one dimensional
2407 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
2408 const struct comp_unit_head
*cu_header
)
2410 struct die_info
*child_die
;
2411 struct type
*type
= NULL
;
2412 struct type
*element_type
, *range_type
, *index_type
;
2413 struct type
**range_types
= NULL
;
2414 struct attribute
*attr
;
2416 struct cleanup
*back_to
;
2418 /* Return if we've already decoded this type. */
2424 element_type
= die_type (die
, objfile
, cu_header
);
2426 /* Irix 6.2 native cc creates array types without children for
2427 arrays with unspecified length. */
2428 if (die
->has_children
== 0)
2430 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2431 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2432 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2436 back_to
= make_cleanup (null_cleanup
, NULL
);
2437 child_die
= die
->next
;
2438 while (child_die
&& child_die
->tag
)
2440 if (child_die
->tag
== DW_TAG_subrange_type
)
2442 unsigned int low
, high
;
2444 /* Default bounds to an array with unspecified length. */
2447 if (cu_language
== language_fortran
)
2449 /* FORTRAN implies a lower bound of 1, if not given. */
2453 index_type
= die_type (child_die
, objfile
, cu_header
);
2454 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2457 if (attr
->form
== DW_FORM_sdata
)
2459 low
= DW_SND (attr
);
2461 else if (attr
->form
== DW_FORM_udata
2462 || attr
->form
== DW_FORM_data1
2463 || attr
->form
== DW_FORM_data2
2464 || attr
->form
== DW_FORM_data4
)
2466 low
= DW_UNSND (attr
);
2470 complain (&dwarf2_non_const_array_bound_ignored
,
2471 dwarf_form_name (attr
->form
));
2473 die
->type
= lookup_pointer_type (element_type
);
2480 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2483 if (attr
->form
== DW_FORM_sdata
)
2485 high
= DW_SND (attr
);
2487 else if (attr
->form
== DW_FORM_udata
2488 || attr
->form
== DW_FORM_data1
2489 || attr
->form
== DW_FORM_data2
2490 || attr
->form
== DW_FORM_data4
)
2492 high
= DW_UNSND (attr
);
2494 else if (attr
->form
== DW_FORM_block1
)
2496 /* GCC encodes arrays with unspecified or dynamic length
2497 with a DW_FORM_block1 attribute.
2498 FIXME: GDB does not yet know how to handle dynamic
2499 arrays properly, treat them as arrays with unspecified
2505 complain (&dwarf2_non_const_array_bound_ignored
,
2506 dwarf_form_name (attr
->form
));
2508 die
->type
= lookup_pointer_type (element_type
);
2516 /* Create a range type and save it for array type creation. */
2517 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2519 range_types
= (struct type
**)
2520 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2521 * sizeof (struct type
*));
2523 make_cleanup (free_current_contents
, &range_types
);
2525 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2527 child_die
= sibling_die (child_die
);
2530 /* Dwarf2 dimensions are output from left to right, create the
2531 necessary array types in backwards order. */
2532 type
= element_type
;
2534 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2536 do_cleanups (back_to
);
2538 /* Install the type in the die. */
2542 /* First cut: install each common block member as a global variable. */
2545 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
2546 const struct comp_unit_head
*cu_header
)
2548 struct die_info
*child_die
;
2549 struct attribute
*attr
;
2551 CORE_ADDR base
= (CORE_ADDR
) 0;
2553 attr
= dwarf_attr (die
, DW_AT_location
);
2556 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2558 if (die
->has_children
)
2560 child_die
= die
->next
;
2561 while (child_die
&& child_die
->tag
)
2563 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
2564 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2567 SYMBOL_VALUE_ADDRESS (sym
) =
2568 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2569 add_symbol_to_list (sym
, &global_symbols
);
2571 child_die
= sibling_die (child_die
);
2576 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2577 the user defined type vector. */
2580 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
2581 const struct comp_unit_head
*cu_header
)
2584 struct attribute
*attr
;
2591 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
2592 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2595 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2599 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2604 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2605 the user defined type vector. */
2608 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
2609 const struct comp_unit_head
*cu_header
)
2612 struct type
*to_type
;
2613 struct type
*domain
;
2620 type
= alloc_type (objfile
);
2621 to_type
= die_type (die
, objfile
, cu_header
);
2622 domain
= die_containing_type (die
, objfile
, cu_header
);
2623 smash_to_member_type (type
, domain
, to_type
);
2628 /* Extract all information from a DW_TAG_reference_type DIE and add to
2629 the user defined type vector. */
2632 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
2633 const struct comp_unit_head
*cu_header
)
2636 struct attribute
*attr
;
2643 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
2644 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2647 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2651 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2657 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
2658 const struct comp_unit_head
*cu_header
)
2660 struct type
*base_type
;
2667 base_type
= die_type (die
, objfile
, cu_header
);
2668 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
2672 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
2673 const struct comp_unit_head
*cu_header
)
2675 struct type
*base_type
;
2682 base_type
= die_type (die
, objfile
, cu_header
);
2683 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
2686 /* Extract all information from a DW_TAG_string_type DIE and add to
2687 the user defined type vector. It isn't really a user defined type,
2688 but it behaves like one, with other DIE's using an AT_user_def_type
2689 attribute to reference it. */
2692 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
2694 struct type
*type
, *range_type
, *index_type
, *char_type
;
2695 struct attribute
*attr
;
2696 unsigned int length
;
2703 attr
= dwarf_attr (die
, DW_AT_string_length
);
2706 length
= DW_UNSND (attr
);
2712 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2713 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2714 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2715 type
= create_string_type (char_type
, range_type
);
2719 /* Handle DIES due to C code like:
2723 int (*funcp)(int a, long l);
2727 ('funcp' generates a DW_TAG_subroutine_type DIE)
2731 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
2732 const struct comp_unit_head
*cu_header
)
2734 struct type
*type
; /* Type that this function returns */
2735 struct type
*ftype
; /* Function that returns above type */
2736 struct attribute
*attr
;
2738 /* Decode the type that this subroutine returns */
2743 type
= die_type (die
, objfile
, cu_header
);
2744 ftype
= lookup_function_type (type
);
2746 /* All functions in C++ have prototypes. */
2747 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2748 if ((attr
&& (DW_UNSND (attr
) != 0))
2749 || cu_language
== language_cplus
)
2750 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2752 if (die
->has_children
)
2754 struct die_info
*child_die
;
2758 /* Count the number of parameters.
2759 FIXME: GDB currently ignores vararg functions, but knows about
2760 vararg member functions. */
2761 child_die
= die
->next
;
2762 while (child_die
&& child_die
->tag
)
2764 if (child_die
->tag
== DW_TAG_formal_parameter
)
2766 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2767 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2768 child_die
= sibling_die (child_die
);
2771 /* Allocate storage for parameters and fill them in. */
2772 TYPE_NFIELDS (ftype
) = nparams
;
2773 TYPE_FIELDS (ftype
) = (struct field
*)
2774 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2776 child_die
= die
->next
;
2777 while (child_die
&& child_die
->tag
)
2779 if (child_die
->tag
== DW_TAG_formal_parameter
)
2781 /* Dwarf2 has no clean way to discern C++ static and non-static
2782 member functions. G++ helps GDB by marking the first
2783 parameter for non-static member functions (which is the
2784 this pointer) as artificial. We pass this information
2785 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2786 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2788 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2790 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2791 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
2795 child_die
= sibling_die (child_die
);
2803 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
2804 const struct comp_unit_head
*cu_header
)
2810 struct attribute
*attr
;
2813 xtype
= die_type (die
, objfile
, cu_header
);
2815 type
= alloc_type (objfile
);
2816 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2817 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2818 TYPE_TARGET_TYPE (type
) = xtype
;
2819 attr
= dwarf_attr (die
, DW_AT_name
);
2820 if (attr
&& DW_STRING (attr
))
2821 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2822 strlen (DW_STRING (attr
)),
2823 &objfile
->type_obstack
);
2829 /* Find a representation of a given base type and install
2830 it in the TYPE field of the die. */
2833 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
2836 struct attribute
*attr
;
2837 int encoding
= 0, size
= 0;
2839 /* If we've already decoded this die, this is a no-op. */
2845 attr
= dwarf_attr (die
, DW_AT_encoding
);
2848 encoding
= DW_UNSND (attr
);
2850 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2853 size
= DW_UNSND (attr
);
2855 attr
= dwarf_attr (die
, DW_AT_name
);
2856 if (attr
&& DW_STRING (attr
))
2858 enum type_code code
= TYPE_CODE_INT
;
2859 int is_unsigned
= 0;
2863 case DW_ATE_address
:
2864 /* Turn DW_ATE_address into a void * pointer. */
2865 code
= TYPE_CODE_PTR
;
2868 case DW_ATE_boolean
:
2869 code
= TYPE_CODE_BOOL
;
2872 case DW_ATE_complex_float
:
2873 code
= TYPE_CODE_COMPLEX
;
2876 code
= TYPE_CODE_FLT
;
2879 case DW_ATE_signed_char
:
2881 case DW_ATE_unsigned
:
2882 case DW_ATE_unsigned_char
:
2886 complain (&dwarf2_unsupported_at_encoding
,
2887 dwarf_type_encoding_name (encoding
));
2890 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2891 if (encoding
== DW_ATE_address
)
2892 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2896 type
= dwarf_base_type (encoding
, size
, objfile
);
2901 /* Read a whole compilation unit into a linked list of dies. */
2903 static struct die_info
*
2904 read_comp_unit (char *info_ptr
, bfd
*abfd
,
2905 const struct comp_unit_head
*cu_header
)
2907 struct die_info
*first_die
, *last_die
, *die
;
2911 /* Reset die reference table; we are
2912 building new ones now. */
2913 dwarf2_empty_hash_tables ();
2917 first_die
= last_die
= NULL
;
2920 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
2921 if (die
->has_children
)
2932 /* Enter die in reference hash table */
2933 store_in_ref_table (die
->offset
, die
);
2937 first_die
= last_die
= die
;
2941 last_die
->next
= die
;
2945 while (nesting_level
> 0);
2949 /* Free a linked list of dies. */
2952 free_die_list (struct die_info
*dies
)
2954 struct die_info
*die
, *next
;
2967 do_free_die_list_cleanup (void *dies
)
2969 free_die_list (dies
);
2972 static struct cleanup
*
2973 make_cleanup_free_die_list (struct die_info
*dies
)
2975 return make_cleanup (do_free_die_list_cleanup
, dies
);
2979 /* Read the contents of the section at OFFSET and of size SIZE from the
2980 object file specified by OBJFILE into the psymbol_obstack and return it. */
2983 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
2986 bfd
*abfd
= objfile
->obfd
;
2992 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
2993 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
2994 (bfd_read (buf
, size
, 1, abfd
) != size
))
2997 error ("Dwarf Error: Can't read DWARF data from '%s'",
2998 bfd_get_filename (abfd
));
3003 /* In DWARF version 2, the description of the debugging information is
3004 stored in a separate .debug_abbrev section. Before we read any
3005 dies from a section we read in all abbreviations and install them
3009 dwarf2_read_abbrevs (bfd
*abfd
, unsigned int offset
)
3012 struct abbrev_info
*cur_abbrev
;
3013 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3014 unsigned int abbrev_form
, hash_number
;
3016 /* empty the table */
3017 dwarf2_empty_abbrev_table (NULL
);
3019 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3020 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3021 abbrev_ptr
+= bytes_read
;
3023 /* loop until we reach an abbrev number of 0 */
3024 while (abbrev_number
)
3026 cur_abbrev
= dwarf_alloc_abbrev ();
3028 /* read in abbrev header */
3029 cur_abbrev
->number
= abbrev_number
;
3030 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3031 abbrev_ptr
+= bytes_read
;
3032 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3035 /* now read in declarations */
3036 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3037 abbrev_ptr
+= bytes_read
;
3038 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3039 abbrev_ptr
+= bytes_read
;
3042 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3044 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3045 xrealloc (cur_abbrev
->attrs
,
3046 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3047 * sizeof (struct attr_abbrev
));
3049 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3050 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3051 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3052 abbrev_ptr
+= bytes_read
;
3053 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3054 abbrev_ptr
+= bytes_read
;
3057 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3058 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3059 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3061 /* Get next abbreviation.
3062 Under Irix6 the abbreviations for a compilation unit are not
3063 always properly terminated with an abbrev number of 0.
3064 Exit loop if we encounter an abbreviation which we have
3065 already read (which means we are about to read the abbreviations
3066 for the next compile unit) or if the end of the abbreviation
3067 table is reached. */
3068 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3069 >= dwarf_abbrev_size
)
3071 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3072 abbrev_ptr
+= bytes_read
;
3073 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3078 /* Empty the abbrev table for a new compilation unit. */
3082 dwarf2_empty_abbrev_table (PTR ignore
)
3085 struct abbrev_info
*abbrev
, *next
;
3087 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3090 abbrev
= dwarf2_abbrevs
[i
];
3093 next
= abbrev
->next
;
3094 xfree (abbrev
->attrs
);
3098 dwarf2_abbrevs
[i
] = NULL
;
3102 /* Lookup an abbrev_info structure in the abbrev hash table. */
3104 static struct abbrev_info
*
3105 dwarf2_lookup_abbrev (unsigned int number
)
3107 unsigned int hash_number
;
3108 struct abbrev_info
*abbrev
;
3110 hash_number
= number
% ABBREV_HASH_SIZE
;
3111 abbrev
= dwarf2_abbrevs
[hash_number
];
3115 if (abbrev
->number
== number
)
3118 abbrev
= abbrev
->next
;
3123 /* Read a minimal amount of information into the minimal die structure. */
3126 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3127 char *info_ptr
, int *has_pc_info
,
3128 const struct comp_unit_head
*cu_header
)
3130 unsigned int abbrev_number
, bytes_read
, i
;
3131 struct abbrev_info
*abbrev
;
3132 struct attribute attr
;
3133 struct attribute spec_attr
;
3134 int found_spec_attr
= 0;
3135 int has_low_pc_attr
= 0;
3136 int has_high_pc_attr
= 0;
3138 *part_die
= zeroed_partial_die
;
3140 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3141 info_ptr
+= bytes_read
;
3145 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3148 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3150 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3151 part_die
->tag
= abbrev
->tag
;
3152 part_die
->has_children
= abbrev
->has_children
;
3153 part_die
->abbrev
= abbrev_number
;
3155 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3157 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3158 info_ptr
, cu_header
);
3160 /* Store the data if it is of an attribute we want to keep in a
3161 partial symbol table. */
3166 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3167 if (part_die
->name
== NULL
)
3168 part_die
->name
= DW_STRING (&attr
);
3170 case DW_AT_MIPS_linkage_name
:
3171 part_die
->name
= DW_STRING (&attr
);
3174 has_low_pc_attr
= 1;
3175 part_die
->lowpc
= DW_ADDR (&attr
);
3178 has_high_pc_attr
= 1;
3179 part_die
->highpc
= DW_ADDR (&attr
);
3181 case DW_AT_location
:
3182 part_die
->locdesc
= DW_BLOCK (&attr
);
3184 case DW_AT_language
:
3185 part_die
->language
= DW_UNSND (&attr
);
3187 case DW_AT_external
:
3188 part_die
->is_external
= DW_UNSND (&attr
);
3190 case DW_AT_declaration
:
3191 part_die
->is_declaration
= DW_UNSND (&attr
);
3194 part_die
->has_type
= 1;
3196 case DW_AT_abstract_origin
:
3197 case DW_AT_specification
:
3198 found_spec_attr
= 1;
3202 /* Ignore absolute siblings, they might point outside of
3203 the current compile unit. */
3204 if (attr
.form
== DW_FORM_ref_addr
)
3205 complain (&dwarf2_absolute_sibling_complaint
);
3208 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3215 /* If we found a reference attribute and the die has no name, try
3216 to find a name in the referred to die. */
3218 if (found_spec_attr
&& part_die
->name
== NULL
)
3220 struct partial_die_info spec_die
;
3224 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3225 read_partial_die (&spec_die
, abfd
, spec_ptr
, &dummy
, cu_header
);
3228 part_die
->name
= spec_die
.name
;
3230 /* Copy DW_AT_external attribute if it is set. */
3231 if (spec_die
.is_external
)
3232 part_die
->is_external
= spec_die
.is_external
;
3236 /* When using the GNU linker, .gnu.linkonce. sections are used to
3237 eliminate duplicate copies of functions and vtables and such.
3238 The linker will arbitrarily choose one and discard the others.
3239 The AT_*_pc values for such functions refer to local labels in
3240 these sections. If the section from that file was discarded, the
3241 labels are not in the output, so the relocs get a value of 0.
3242 If this is a discarded function, mark the pc bounds as invalid,
3243 so that GDB will ignore it. */
3244 if (has_low_pc_attr
&& has_high_pc_attr
3245 && part_die
->lowpc
< part_die
->highpc
3246 && (part_die
->lowpc
!= 0
3247 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3252 /* Read the die from the .debug_info section buffer. And set diep to
3253 point to a newly allocated die with its information. */
3256 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3257 const struct comp_unit_head
*cu_header
)
3259 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3260 struct abbrev_info
*abbrev
;
3261 struct die_info
*die
;
3263 offset
= info_ptr
- dwarf_info_buffer
;
3264 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3265 info_ptr
+= bytes_read
;
3268 die
= dwarf_alloc_die ();
3270 die
->abbrev
= abbrev_number
;
3276 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3279 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3281 die
= dwarf_alloc_die ();
3282 die
->offset
= offset
;
3283 die
->tag
= abbrev
->tag
;
3284 die
->has_children
= abbrev
->has_children
;
3285 die
->abbrev
= abbrev_number
;
3288 die
->num_attrs
= abbrev
->num_attrs
;
3289 die
->attrs
= (struct attribute
*)
3290 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3292 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3294 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3295 abfd
, info_ptr
, cu_header
);
3302 /* Read an attribute described by an abbreviated attribute. */
3305 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
3306 bfd
*abfd
, char *info_ptr
,
3307 const struct comp_unit_head
*cu_header
)
3309 unsigned int bytes_read
;
3310 struct dwarf_block
*blk
;
3312 attr
->name
= abbrev
->name
;
3313 attr
->form
= abbrev
->form
;
3314 switch (abbrev
->form
)
3317 case DW_FORM_ref_addr
:
3318 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3319 info_ptr
+= bytes_read
;
3321 case DW_FORM_block2
:
3322 blk
= dwarf_alloc_block ();
3323 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3325 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3326 info_ptr
+= blk
->size
;
3327 DW_BLOCK (attr
) = blk
;
3329 case DW_FORM_block4
:
3330 blk
= dwarf_alloc_block ();
3331 blk
->size
= read_4_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
;
3338 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3342 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3346 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3349 case DW_FORM_string
:
3350 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3351 info_ptr
+= bytes_read
;
3354 blk
= dwarf_alloc_block ();
3355 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3356 info_ptr
+= bytes_read
;
3357 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3358 info_ptr
+= blk
->size
;
3359 DW_BLOCK (attr
) = blk
;
3361 case DW_FORM_block1
:
3362 blk
= dwarf_alloc_block ();
3363 blk
->size
= read_1_byte (abfd
, info_ptr
);
3365 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3366 info_ptr
+= blk
->size
;
3367 DW_BLOCK (attr
) = blk
;
3370 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3374 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3378 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3379 info_ptr
+= bytes_read
;
3382 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3383 info_ptr
+= bytes_read
;
3386 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3390 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3394 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3398 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3401 case DW_FORM_ref_udata
:
3402 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3403 info_ptr
+= bytes_read
;
3406 case DW_FORM_indirect
:
3408 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3409 dwarf_form_name (abbrev
->form
));
3414 /* read dwarf information from a buffer */
3417 read_1_byte (bfd
*abfd
, char *buf
)
3419 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3423 read_1_signed_byte (bfd
*abfd
, char *buf
)
3425 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3429 read_2_bytes (bfd
*abfd
, char *buf
)
3431 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3435 read_2_signed_bytes (bfd
*abfd
, char *buf
)
3437 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3441 read_4_bytes (bfd
*abfd
, char *buf
)
3443 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3447 read_4_signed_bytes (bfd
*abfd
, char *buf
)
3449 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3452 static unsigned long
3453 read_8_bytes (bfd
*abfd
, char *buf
)
3455 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3459 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3462 CORE_ADDR retval
= 0;
3464 if (cu_header
->signed_addr_p
)
3466 switch (cu_header
->addr_size
)
3469 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3472 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3475 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
3478 internal_error (__FILE__
, __LINE__
,
3479 "read_address: bad switch, signed");
3484 switch (cu_header
->addr_size
)
3487 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3490 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3493 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3496 internal_error (__FILE__
, __LINE__
,
3497 "read_address: bad switch, unsigned");
3501 *bytes_read
= cu_header
->addr_size
;
3505 /* Reads the initial length from a section. The (draft) DWARF 2.1
3506 specification allows the initial length to take up either 4 bytes
3507 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
3508 bytes describe the length and all offsets will be 8 bytes in length
3511 The value returned via bytes_read should be used to increment
3512 the relevant pointer after calling read_initial_length().
3514 As a side effect, this function sets the fields initial_length_size
3515 and offset_size in cu_header to the values appropriate for the
3516 length field. (The format of the initial length field determines
3517 the width of file offsets to be fetched later with fetch_offset().)
3519 [ Note: read_initial_length() and read_offset() are based on the
3520 document entitled "DWARF Debugging Information Format", revision
3521 2.1, draft 4, dated July 20, 2000. This document was obtained
3524 http://reality.sgi.com/dehnert_engr/dwarf/dwarf2p1-draft4-000720.pdf
3526 This document is only a draft and is subject to change. (So beware.)
3528 - Kevin, Aug 4, 2000
3532 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
3537 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3539 if (retval
== 0xffffffff)
3541 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
3543 if (cu_header
!= NULL
)
3545 cu_header
->initial_length_size
= 12;
3546 cu_header
->offset_size
= 8;
3552 if (cu_header
!= NULL
)
3554 cu_header
->initial_length_size
= 4;
3555 cu_header
->offset_size
= 4;
3562 /* Read an offset from the data stream. The size of the offset is
3563 given by cu_header->offset_size. */
3566 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3571 switch (cu_header
->offset_size
)
3574 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3578 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3582 internal_error (__FILE__
, __LINE__
,
3583 "read_offset: bad switch");
3590 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
3592 /* If the size of a host char is 8 bits, we can return a pointer
3593 to the buffer, otherwise we have to copy the data to a buffer
3594 allocated on the temporary obstack. */
3595 #if HOST_CHAR_BIT == 8
3601 ret
= obstack_alloc (&dwarf2_tmp_obstack
, size
);
3602 for (i
= 0; i
< size
; ++i
)
3604 ret
[i
] = bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3612 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3614 /* If the size of a host char is 8 bits, we can return a pointer
3615 to the string, otherwise we have to copy the string to a buffer
3616 allocated on the temporary obstack. */
3617 #if HOST_CHAR_BIT == 8
3620 *bytes_read_ptr
= 1;
3623 *bytes_read_ptr
= strlen (buf
) + 1;
3629 while ((byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
)) != 0)
3631 obstack_1grow (&dwarf2_tmp_obstack
, byte
);
3637 *bytes_read_ptr
= 1;
3640 obstack_1grow (&dwarf2_tmp_obstack
, '\0');
3641 *bytes_read_ptr
= i
+ 1;
3642 return obstack_finish (&dwarf2_tmp_obstack
);
3646 static unsigned long
3647 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3649 unsigned long result
;
3650 unsigned int num_read
;
3660 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3663 result
|= ((unsigned long)(byte
& 127) << shift
);
3664 if ((byte
& 128) == 0)
3670 *bytes_read_ptr
= num_read
;
3675 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3678 int i
, shift
, size
, num_read
;
3688 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3691 result
|= ((long)(byte
& 127) << shift
);
3693 if ((byte
& 128) == 0)
3698 if ((shift
< size
) && (byte
& 0x40))
3700 result
|= -(1 << shift
);
3702 *bytes_read_ptr
= num_read
;
3707 set_cu_language (unsigned int lang
)
3713 cu_language
= language_c
;
3715 case DW_LANG_C_plus_plus
:
3716 cu_language
= language_cplus
;
3718 case DW_LANG_Fortran77
:
3719 case DW_LANG_Fortran90
:
3720 cu_language
= language_fortran
;
3722 case DW_LANG_Mips_Assembler
:
3723 cu_language
= language_asm
;
3726 cu_language
= language_java
;
3729 case DW_LANG_Cobol74
:
3730 case DW_LANG_Cobol85
:
3731 case DW_LANG_Pascal83
:
3732 case DW_LANG_Modula2
:
3734 cu_language
= language_unknown
;
3737 cu_language_defn
= language_def (cu_language
);
3740 /* Return the named attribute or NULL if not there. */
3742 static struct attribute
*
3743 dwarf_attr (struct die_info
*die
, unsigned int name
)
3746 struct attribute
*spec
= NULL
;
3748 for (i
= 0; i
< die
->num_attrs
; ++i
)
3750 if (die
->attrs
[i
].name
== name
)
3752 return &die
->attrs
[i
];
3754 if (die
->attrs
[i
].name
== DW_AT_specification
3755 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3756 spec
= &die
->attrs
[i
];
3760 struct die_info
*ref_die
=
3761 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3764 return dwarf_attr (ref_die
, name
);
3771 die_is_declaration (struct die_info
*die
)
3773 return (dwarf_attr (die
, DW_AT_declaration
)
3774 && ! dwarf_attr (die
, DW_AT_specification
));
3777 /* Decode the line number information for the compilation unit whose
3778 line number info is at OFFSET in the .debug_line section.
3779 The compilation directory of the file is passed in COMP_DIR. */
3783 unsigned int num_files
;
3796 unsigned int num_dirs
;
3801 dwarf_decode_lines (unsigned int offset
, char *comp_dir
, bfd
*abfd
,
3802 const struct comp_unit_head
*cu_header
)
3806 struct line_head lh
;
3807 struct cleanup
*back_to
;
3808 unsigned int i
, bytes_read
;
3809 char *cur_file
, *cur_dir
;
3810 unsigned char op_code
, extended_op
, adj_opcode
;
3812 #define FILE_ALLOC_CHUNK 5
3813 #define DIR_ALLOC_CHUNK 5
3815 struct filenames files
;
3816 struct directories dirs
;
3818 if (dwarf_line_buffer
== NULL
)
3820 complain (&dwarf2_missing_line_number_section
);
3824 files
.num_files
= 0;
3830 line_ptr
= dwarf_line_buffer
+ offset
;
3832 /* read in the prologue */
3833 lh
.total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
3834 line_ptr
+= bytes_read
;
3835 line_end
= line_ptr
+ lh
.total_length
;
3836 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3838 lh
.prologue_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
3839 line_ptr
+= bytes_read
;
3840 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3842 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3844 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3846 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3848 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3850 lh
.standard_opcode_lengths
= (unsigned char *)
3851 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3852 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
3854 lh
.standard_opcode_lengths
[0] = 1;
3855 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3857 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3861 /* Read directory table */
3862 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3864 line_ptr
+= bytes_read
;
3865 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3867 dirs
.dirs
= (char **)
3868 xrealloc (dirs
.dirs
,
3869 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3870 if (dirs
.num_dirs
== 0)
3871 make_cleanup (free_current_contents
, &dirs
.dirs
);
3873 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3875 line_ptr
+= bytes_read
;
3877 /* Read file name table */
3878 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3880 line_ptr
+= bytes_read
;
3881 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3883 files
.files
= (struct fileinfo
*)
3884 xrealloc (files
.files
,
3885 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3886 * sizeof (struct fileinfo
));
3887 if (files
.num_files
== 0)
3888 make_cleanup (free_current_contents
, &files
.files
);
3890 files
.files
[files
.num_files
].name
= cur_file
;
3891 files
.files
[files
.num_files
].dir
=
3892 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3893 line_ptr
+= bytes_read
;
3894 files
.files
[files
.num_files
].time
=
3895 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3896 line_ptr
+= bytes_read
;
3897 files
.files
[files
.num_files
].size
=
3898 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3899 line_ptr
+= bytes_read
;
3902 line_ptr
+= bytes_read
;
3904 /* Read the statement sequences until there's nothing left. */
3905 while (line_ptr
< line_end
)
3907 /* state machine registers */
3908 CORE_ADDR address
= 0;
3909 unsigned int file
= 1;
3910 unsigned int line
= 1;
3911 unsigned int column
= 0;
3912 int is_stmt
= lh
.default_is_stmt
;
3913 int basic_block
= 0;
3914 int end_sequence
= 0;
3916 /* Start a subfile for the current file of the state machine. */
3917 if (files
.num_files
>= file
)
3919 /* The file and directory tables are 0 based, the references
3921 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3922 (files
.files
[file
- 1].dir
3923 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3927 /* Decode the table. */
3928 while (!end_sequence
)
3930 op_code
= read_1_byte (abfd
, line_ptr
);
3934 case DW_LNS_extended_op
:
3935 line_ptr
+= 1; /* ignore length */
3936 extended_op
= read_1_byte (abfd
, line_ptr
);
3938 switch (extended_op
)
3940 case DW_LNE_end_sequence
:
3942 /* Don't call record_line here. The end_sequence
3943 instruction provides the address of the first byte
3944 *after* the last line in the sequence; it's not the
3945 address of any real source line. However, the GDB
3946 linetable structure only records the starts of lines,
3947 not the ends. This is a weakness of GDB. */
3949 case DW_LNE_set_address
:
3950 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
3951 line_ptr
+= bytes_read
;
3952 address
+= baseaddr
;
3954 case DW_LNE_define_file
:
3955 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
3956 line_ptr
+= bytes_read
;
3957 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3959 files
.files
= (struct fileinfo
*)
3960 xrealloc (files
.files
,
3961 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3962 * sizeof (struct fileinfo
));
3963 if (files
.num_files
== 0)
3964 make_cleanup (free_current_contents
, &files
.files
);
3966 files
.files
[files
.num_files
].name
= cur_file
;
3967 files
.files
[files
.num_files
].dir
=
3968 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3969 line_ptr
+= bytes_read
;
3970 files
.files
[files
.num_files
].time
=
3971 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3972 line_ptr
+= bytes_read
;
3973 files
.files
[files
.num_files
].size
=
3974 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3975 line_ptr
+= bytes_read
;
3979 complain (&dwarf2_mangled_line_number_section
);
3984 record_line (current_subfile
, line
, address
);
3987 case DW_LNS_advance_pc
:
3988 address
+= lh
.minimum_instruction_length
3989 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3990 line_ptr
+= bytes_read
;
3992 case DW_LNS_advance_line
:
3993 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
3994 line_ptr
+= bytes_read
;
3996 case DW_LNS_set_file
:
3997 /* The file and directory tables are 0 based, the references
3999 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4000 line_ptr
+= bytes_read
;
4001 dwarf2_start_subfile
4002 (files
.files
[file
- 1].name
,
4003 (files
.files
[file
- 1].dir
4004 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
4007 case DW_LNS_set_column
:
4008 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4009 line_ptr
+= bytes_read
;
4011 case DW_LNS_negate_stmt
:
4012 is_stmt
= (!is_stmt
);
4014 case DW_LNS_set_basic_block
:
4017 /* Add to the address register of the state machine the
4018 address increment value corresponding to special opcode
4019 255. Ie, this value is scaled by the minimum instruction
4020 length since special opcode 255 would have scaled the
4022 case DW_LNS_const_add_pc
:
4023 address
+= (lh
.minimum_instruction_length
4024 * ((255 - lh
.opcode_base
) / lh
.line_range
));
4026 case DW_LNS_fixed_advance_pc
:
4027 address
+= read_2_bytes (abfd
, line_ptr
);
4030 default: /* special operand */
4031 adj_opcode
= op_code
- lh
.opcode_base
;
4032 address
+= (adj_opcode
/ lh
.line_range
)
4033 * lh
.minimum_instruction_length
;
4034 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
4035 /* append row to matrix using current values */
4036 record_line (current_subfile
, line
, address
);
4042 do_cleanups (back_to
);
4045 /* Start a subfile for DWARF. FILENAME is the name of the file and
4046 DIRNAME the name of the source directory which contains FILENAME
4047 or NULL if not known.
4048 This routine tries to keep line numbers from identical absolute and
4049 relative file names in a common subfile.
4051 Using the `list' example from the GDB testsuite, which resides in
4052 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4053 of /srcdir/list0.c yields the following debugging information for list0.c:
4055 DW_AT_name: /srcdir/list0.c
4056 DW_AT_comp_dir: /compdir
4057 files.files[0].name: list0.h
4058 files.files[0].dir: /srcdir
4059 files.files[1].name: list0.c
4060 files.files[1].dir: /srcdir
4062 The line number information for list0.c has to end up in a single
4063 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4066 dwarf2_start_subfile (char *filename
, char *dirname
)
4068 /* If the filename isn't absolute, try to match an existing subfile
4069 with the full pathname. */
4071 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
4073 struct subfile
*subfile
;
4074 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4076 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4078 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
4080 current_subfile
= subfile
;
4087 start_subfile (filename
, dirname
);
4090 /* Given a pointer to a DWARF information entry, figure out if we need
4091 to make a symbol table entry for it, and if so, create a new entry
4092 and return a pointer to it.
4093 If TYPE is NULL, determine symbol type from the die, otherwise
4094 used the passed type. */
4096 static struct symbol
*
4097 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
4098 const struct comp_unit_head
*cu_header
)
4100 struct symbol
*sym
= NULL
;
4102 struct attribute
*attr
= NULL
;
4103 struct attribute
*attr2
= NULL
;
4106 name
= dwarf2_linkage_name (die
);
4109 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4110 sizeof (struct symbol
));
4111 OBJSTAT (objfile
, n_syms
++);
4112 memset (sym
, 0, sizeof (struct symbol
));
4113 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4114 &objfile
->symbol_obstack
);
4116 /* Default assumptions.
4117 Use the passed type or decode it from the die. */
4118 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4119 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4121 SYMBOL_TYPE (sym
) = type
;
4123 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
4124 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4127 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4130 /* If this symbol is from a C++ compilation, then attempt to
4131 cache the demangled form for future reference. This is a
4132 typical time versus space tradeoff, that was decided in favor
4133 of time because it sped up C++ symbol lookups by a factor of
4136 SYMBOL_LANGUAGE (sym
) = cu_language
;
4137 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4141 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4144 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4146 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4148 case DW_TAG_subprogram
:
4149 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4151 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4152 attr2
= dwarf_attr (die
, DW_AT_external
);
4153 if (attr2
&& (DW_UNSND (attr2
) != 0))
4155 add_symbol_to_list (sym
, &global_symbols
);
4159 add_symbol_to_list (sym
, list_in_scope
);
4162 case DW_TAG_variable
:
4163 /* Compilation with minimal debug info may result in variables
4164 with missing type entries. Change the misleading `void' type
4165 to something sensible. */
4166 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4167 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4168 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4169 "<variable, no debug info>",
4171 attr
= dwarf_attr (die
, DW_AT_const_value
);
4174 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4175 attr2
= dwarf_attr (die
, DW_AT_external
);
4176 if (attr2
&& (DW_UNSND (attr2
) != 0))
4177 add_symbol_to_list (sym
, &global_symbols
);
4179 add_symbol_to_list (sym
, list_in_scope
);
4182 attr
= dwarf_attr (die
, DW_AT_location
);
4185 attr2
= dwarf_attr (die
, DW_AT_external
);
4186 if (attr2
&& (DW_UNSND (attr2
) != 0))
4188 SYMBOL_VALUE_ADDRESS (sym
) =
4189 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4190 add_symbol_to_list (sym
, &global_symbols
);
4192 /* In shared libraries the address of the variable
4193 in the location descriptor might still be relocatable,
4194 so its value could be zero.
4195 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4196 value is zero, the address of the variable will then
4197 be determined from the minimal symbol table whenever
4198 the variable is referenced. */
4199 if (SYMBOL_VALUE_ADDRESS (sym
))
4201 fixup_symbol_section (sym
, objfile
);
4202 SYMBOL_VALUE_ADDRESS (sym
) +=
4203 ANOFFSET (objfile
->section_offsets
,
4204 SYMBOL_SECTION (sym
));
4205 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4208 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4212 SYMBOL_VALUE (sym
) = addr
=
4213 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4214 add_symbol_to_list (sym
, list_in_scope
);
4217 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4221 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4222 SYMBOL_VALUE (sym
) =
4223 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4227 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4228 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4232 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4236 fixup_symbol_section (sym
, objfile
);
4237 SYMBOL_VALUE_ADDRESS (sym
) =
4238 addr
+ ANOFFSET (objfile
->section_offsets
,
4239 SYMBOL_SECTION (sym
));
4240 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4246 /* We do not know the address of this symbol.
4247 If it is an external symbol and we have type information
4248 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4249 The address of the variable will then be determined from
4250 the minimal symbol table whenever the variable is
4252 attr2
= dwarf_attr (die
, DW_AT_external
);
4253 if (attr2
&& (DW_UNSND (attr2
) != 0)
4254 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4256 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4257 add_symbol_to_list (sym
, &global_symbols
);
4261 case DW_TAG_formal_parameter
:
4262 attr
= dwarf_attr (die
, DW_AT_location
);
4265 SYMBOL_VALUE (sym
) =
4266 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4269 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4270 SYMBOL_VALUE (sym
) =
4271 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4277 if (basereg
!= frame_base_reg
)
4278 complain (&dwarf2_complex_location_expr
);
4279 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4283 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4284 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4289 SYMBOL_CLASS (sym
) = LOC_ARG
;
4292 attr
= dwarf_attr (die
, DW_AT_const_value
);
4295 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4297 add_symbol_to_list (sym
, list_in_scope
);
4299 case DW_TAG_unspecified_parameters
:
4300 /* From varargs functions; gdb doesn't seem to have any
4301 interest in this information, so just ignore it for now.
4304 case DW_TAG_class_type
:
4305 case DW_TAG_structure_type
:
4306 case DW_TAG_union_type
:
4307 case DW_TAG_enumeration_type
:
4308 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4309 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4310 add_symbol_to_list (sym
, list_in_scope
);
4312 /* The semantics of C++ state that "struct foo { ... }" also
4313 defines a typedef for "foo". Synthesize a typedef symbol so
4314 that "ptype foo" works as expected. */
4315 if (cu_language
== language_cplus
)
4317 struct symbol
*typedef_sym
= (struct symbol
*)
4318 obstack_alloc (&objfile
->symbol_obstack
,
4319 sizeof (struct symbol
));
4320 *typedef_sym
= *sym
;
4321 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4322 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4323 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4324 obsavestring (SYMBOL_NAME (sym
),
4325 strlen (SYMBOL_NAME (sym
)),
4326 &objfile
->type_obstack
);
4327 add_symbol_to_list (typedef_sym
, list_in_scope
);
4330 case DW_TAG_typedef
:
4331 case DW_TAG_base_type
:
4332 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4333 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4334 add_symbol_to_list (sym
, list_in_scope
);
4336 case DW_TAG_enumerator
:
4337 attr
= dwarf_attr (die
, DW_AT_const_value
);
4340 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4342 add_symbol_to_list (sym
, list_in_scope
);
4345 /* Not a tag we recognize. Hopefully we aren't processing
4346 trash data, but since we must specifically ignore things
4347 we don't recognize, there is nothing else we should do at
4349 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4356 /* Copy constant value from an attribute to a symbol. */
4359 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
4360 struct objfile
*objfile
,
4361 const struct comp_unit_head
*cu_header
)
4363 struct dwarf_block
*blk
;
4368 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
4369 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4370 cu_header
->addr_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4371 SYMBOL_VALUE_BYTES (sym
) = (char *)
4372 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
4373 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
4375 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4377 case DW_FORM_block1
:
4378 case DW_FORM_block2
:
4379 case DW_FORM_block4
:
4381 blk
= DW_BLOCK (attr
);
4382 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4383 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4384 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4385 SYMBOL_VALUE_BYTES (sym
) = (char *)
4386 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4387 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4388 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4391 /* The DW_AT_const_value attributes are supposed to carry the
4392 symbol's value "represented as it would be on the target
4393 architecture." By the time we get here, it's already been
4394 converted to host endianness, so we just need to sign- or
4395 zero-extend it as appropriate. */
4397 dwarf2_const_value_data (attr
, sym
, 8);
4400 dwarf2_const_value_data (attr
, sym
, 16);
4403 dwarf2_const_value_data (attr
, sym
, 32);
4406 dwarf2_const_value_data (attr
, sym
, 64);
4410 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4411 SYMBOL_CLASS (sym
) = LOC_CONST
;
4415 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4416 SYMBOL_CLASS (sym
) = LOC_CONST
;
4420 complain (&dwarf2_unsupported_const_value_attr
,
4421 dwarf_form_name (attr
->form
));
4422 SYMBOL_VALUE (sym
) = 0;
4423 SYMBOL_CLASS (sym
) = LOC_CONST
;
4429 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4430 or zero-extend it as appropriate for the symbol's type. */
4432 dwarf2_const_value_data (struct attribute
*attr
,
4436 LONGEST l
= DW_UNSND (attr
);
4438 if (bits
< sizeof (l
) * 8)
4440 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4441 l
&= ((LONGEST
) 1 << bits
) - 1;
4443 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4446 SYMBOL_VALUE (sym
) = l
;
4447 SYMBOL_CLASS (sym
) = LOC_CONST
;
4451 /* Return the type of the die in question using its DW_AT_type attribute. */
4453 static struct type
*
4454 die_type (struct die_info
*die
, struct objfile
*objfile
,
4455 const struct comp_unit_head
*cu_header
)
4458 struct attribute
*type_attr
;
4459 struct die_info
*type_die
;
4462 type_attr
= dwarf_attr (die
, DW_AT_type
);
4465 /* A missing DW_AT_type represents a void type. */
4466 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4470 ref
= dwarf2_get_ref_die_offset (type_attr
);
4471 type_die
= follow_die_ref (ref
);
4474 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4478 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4481 dump_die (type_die
);
4482 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4487 /* Return the containing type of the die in question using its
4488 DW_AT_containing_type attribute. */
4490 static struct type
*
4491 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
4492 const struct comp_unit_head
*cu_header
)
4494 struct type
*type
= NULL
;
4495 struct attribute
*type_attr
;
4496 struct die_info
*type_die
= NULL
;
4499 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4502 ref
= dwarf2_get_ref_die_offset (type_attr
);
4503 type_die
= follow_die_ref (ref
);
4506 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4509 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4514 dump_die (type_die
);
4515 error ("Dwarf Error: Problem turning containing type into gdb type.");
4521 static struct type
*
4522 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
4524 struct die_info
*die
;
4527 die
= follow_die_ref (offset
);
4530 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4533 type
= tag_type_to_type (die
, objfile
);
4538 static struct type
*
4539 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
4540 const struct comp_unit_head
*cu_header
)
4548 read_type_die (die
, objfile
, cu_header
);
4552 error ("Dwarf Error: Cannot find type of die.");
4559 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
4560 const struct comp_unit_head
*cu_header
)
4564 case DW_TAG_class_type
:
4565 case DW_TAG_structure_type
:
4566 case DW_TAG_union_type
:
4567 read_structure_scope (die
, objfile
, cu_header
);
4569 case DW_TAG_enumeration_type
:
4570 read_enumeration (die
, objfile
, cu_header
);
4572 case DW_TAG_subprogram
:
4573 case DW_TAG_subroutine_type
:
4574 read_subroutine_type (die
, objfile
, cu_header
);
4576 case DW_TAG_array_type
:
4577 read_array_type (die
, objfile
, cu_header
);
4579 case DW_TAG_pointer_type
:
4580 read_tag_pointer_type (die
, objfile
, cu_header
);
4582 case DW_TAG_ptr_to_member_type
:
4583 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
4585 case DW_TAG_reference_type
:
4586 read_tag_reference_type (die
, objfile
, cu_header
);
4588 case DW_TAG_const_type
:
4589 read_tag_const_type (die
, objfile
, cu_header
);
4591 case DW_TAG_volatile_type
:
4592 read_tag_volatile_type (die
, objfile
, cu_header
);
4594 case DW_TAG_string_type
:
4595 read_tag_string_type (die
, objfile
);
4597 case DW_TAG_typedef
:
4598 read_typedef (die
, objfile
, cu_header
);
4600 case DW_TAG_base_type
:
4601 read_base_type (die
, objfile
);
4604 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4609 static struct type
*
4610 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
4612 /* FIXME - this should not produce a new (struct type *)
4613 every time. It should cache base types. */
4617 case DW_ATE_address
:
4618 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4620 case DW_ATE_boolean
:
4621 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4623 case DW_ATE_complex_float
:
4626 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4630 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4636 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4640 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4647 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4650 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4654 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4658 case DW_ATE_signed_char
:
4659 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4661 case DW_ATE_unsigned
:
4665 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4668 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4672 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4676 case DW_ATE_unsigned_char
:
4677 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4680 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4687 copy_die (struct die_info
*old_die
)
4689 struct die_info
*new_die
;
4692 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4693 memset (new_die
, 0, sizeof (struct die_info
));
4695 new_die
->tag
= old_die
->tag
;
4696 new_die
->has_children
= old_die
->has_children
;
4697 new_die
->abbrev
= old_die
->abbrev
;
4698 new_die
->offset
= old_die
->offset
;
4699 new_die
->type
= NULL
;
4701 num_attrs
= old_die
->num_attrs
;
4702 new_die
->num_attrs
= num_attrs
;
4703 new_die
->attrs
= (struct attribute
*)
4704 xmalloc (num_attrs
* sizeof (struct attribute
));
4706 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4708 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4709 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4710 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4713 new_die
->next
= NULL
;
4718 /* Return sibling of die, NULL if no sibling. */
4720 static struct die_info
*
4721 sibling_die (struct die_info
*die
)
4723 int nesting_level
= 0;
4725 if (!die
->has_children
)
4727 if (die
->next
&& (die
->next
->tag
== 0))
4740 if (die
->has_children
)
4750 while (nesting_level
);
4751 if (die
&& (die
->tag
== 0))
4762 /* Get linkage name of a die, return NULL if not found. */
4765 dwarf2_linkage_name (struct die_info
*die
)
4767 struct attribute
*attr
;
4769 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4770 if (attr
&& DW_STRING (attr
))
4771 return DW_STRING (attr
);
4772 attr
= dwarf_attr (die
, DW_AT_name
);
4773 if (attr
&& DW_STRING (attr
))
4774 return DW_STRING (attr
);
4778 /* Convert a DIE tag into its string name. */
4781 dwarf_tag_name (register unsigned tag
)
4785 case DW_TAG_padding
:
4786 return "DW_TAG_padding";
4787 case DW_TAG_array_type
:
4788 return "DW_TAG_array_type";
4789 case DW_TAG_class_type
:
4790 return "DW_TAG_class_type";
4791 case DW_TAG_entry_point
:
4792 return "DW_TAG_entry_point";
4793 case DW_TAG_enumeration_type
:
4794 return "DW_TAG_enumeration_type";
4795 case DW_TAG_formal_parameter
:
4796 return "DW_TAG_formal_parameter";
4797 case DW_TAG_imported_declaration
:
4798 return "DW_TAG_imported_declaration";
4800 return "DW_TAG_label";
4801 case DW_TAG_lexical_block
:
4802 return "DW_TAG_lexical_block";
4804 return "DW_TAG_member";
4805 case DW_TAG_pointer_type
:
4806 return "DW_TAG_pointer_type";
4807 case DW_TAG_reference_type
:
4808 return "DW_TAG_reference_type";
4809 case DW_TAG_compile_unit
:
4810 return "DW_TAG_compile_unit";
4811 case DW_TAG_string_type
:
4812 return "DW_TAG_string_type";
4813 case DW_TAG_structure_type
:
4814 return "DW_TAG_structure_type";
4815 case DW_TAG_subroutine_type
:
4816 return "DW_TAG_subroutine_type";
4817 case DW_TAG_typedef
:
4818 return "DW_TAG_typedef";
4819 case DW_TAG_union_type
:
4820 return "DW_TAG_union_type";
4821 case DW_TAG_unspecified_parameters
:
4822 return "DW_TAG_unspecified_parameters";
4823 case DW_TAG_variant
:
4824 return "DW_TAG_variant";
4825 case DW_TAG_common_block
:
4826 return "DW_TAG_common_block";
4827 case DW_TAG_common_inclusion
:
4828 return "DW_TAG_common_inclusion";
4829 case DW_TAG_inheritance
:
4830 return "DW_TAG_inheritance";
4831 case DW_TAG_inlined_subroutine
:
4832 return "DW_TAG_inlined_subroutine";
4834 return "DW_TAG_module";
4835 case DW_TAG_ptr_to_member_type
:
4836 return "DW_TAG_ptr_to_member_type";
4837 case DW_TAG_set_type
:
4838 return "DW_TAG_set_type";
4839 case DW_TAG_subrange_type
:
4840 return "DW_TAG_subrange_type";
4841 case DW_TAG_with_stmt
:
4842 return "DW_TAG_with_stmt";
4843 case DW_TAG_access_declaration
:
4844 return "DW_TAG_access_declaration";
4845 case DW_TAG_base_type
:
4846 return "DW_TAG_base_type";
4847 case DW_TAG_catch_block
:
4848 return "DW_TAG_catch_block";
4849 case DW_TAG_const_type
:
4850 return "DW_TAG_const_type";
4851 case DW_TAG_constant
:
4852 return "DW_TAG_constant";
4853 case DW_TAG_enumerator
:
4854 return "DW_TAG_enumerator";
4855 case DW_TAG_file_type
:
4856 return "DW_TAG_file_type";
4858 return "DW_TAG_friend";
4859 case DW_TAG_namelist
:
4860 return "DW_TAG_namelist";
4861 case DW_TAG_namelist_item
:
4862 return "DW_TAG_namelist_item";
4863 case DW_TAG_packed_type
:
4864 return "DW_TAG_packed_type";
4865 case DW_TAG_subprogram
:
4866 return "DW_TAG_subprogram";
4867 case DW_TAG_template_type_param
:
4868 return "DW_TAG_template_type_param";
4869 case DW_TAG_template_value_param
:
4870 return "DW_TAG_template_value_param";
4871 case DW_TAG_thrown_type
:
4872 return "DW_TAG_thrown_type";
4873 case DW_TAG_try_block
:
4874 return "DW_TAG_try_block";
4875 case DW_TAG_variant_part
:
4876 return "DW_TAG_variant_part";
4877 case DW_TAG_variable
:
4878 return "DW_TAG_variable";
4879 case DW_TAG_volatile_type
:
4880 return "DW_TAG_volatile_type";
4881 case DW_TAG_MIPS_loop
:
4882 return "DW_TAG_MIPS_loop";
4883 case DW_TAG_format_label
:
4884 return "DW_TAG_format_label";
4885 case DW_TAG_function_template
:
4886 return "DW_TAG_function_template";
4887 case DW_TAG_class_template
:
4888 return "DW_TAG_class_template";
4890 return "DW_TAG_<unknown>";
4894 /* Convert a DWARF attribute code into its string name. */
4897 dwarf_attr_name (register unsigned attr
)
4902 return "DW_AT_sibling";
4903 case DW_AT_location
:
4904 return "DW_AT_location";
4906 return "DW_AT_name";
4907 case DW_AT_ordering
:
4908 return "DW_AT_ordering";
4909 case DW_AT_subscr_data
:
4910 return "DW_AT_subscr_data";
4911 case DW_AT_byte_size
:
4912 return "DW_AT_byte_size";
4913 case DW_AT_bit_offset
:
4914 return "DW_AT_bit_offset";
4915 case DW_AT_bit_size
:
4916 return "DW_AT_bit_size";
4917 case DW_AT_element_list
:
4918 return "DW_AT_element_list";
4919 case DW_AT_stmt_list
:
4920 return "DW_AT_stmt_list";
4922 return "DW_AT_low_pc";
4924 return "DW_AT_high_pc";
4925 case DW_AT_language
:
4926 return "DW_AT_language";
4928 return "DW_AT_member";
4930 return "DW_AT_discr";
4931 case DW_AT_discr_value
:
4932 return "DW_AT_discr_value";
4933 case DW_AT_visibility
:
4934 return "DW_AT_visibility";
4936 return "DW_AT_import";
4937 case DW_AT_string_length
:
4938 return "DW_AT_string_length";
4939 case DW_AT_common_reference
:
4940 return "DW_AT_common_reference";
4941 case DW_AT_comp_dir
:
4942 return "DW_AT_comp_dir";
4943 case DW_AT_const_value
:
4944 return "DW_AT_const_value";
4945 case DW_AT_containing_type
:
4946 return "DW_AT_containing_type";
4947 case DW_AT_default_value
:
4948 return "DW_AT_default_value";
4950 return "DW_AT_inline";
4951 case DW_AT_is_optional
:
4952 return "DW_AT_is_optional";
4953 case DW_AT_lower_bound
:
4954 return "DW_AT_lower_bound";
4955 case DW_AT_producer
:
4956 return "DW_AT_producer";
4957 case DW_AT_prototyped
:
4958 return "DW_AT_prototyped";
4959 case DW_AT_return_addr
:
4960 return "DW_AT_return_addr";
4961 case DW_AT_start_scope
:
4962 return "DW_AT_start_scope";
4963 case DW_AT_stride_size
:
4964 return "DW_AT_stride_size";
4965 case DW_AT_upper_bound
:
4966 return "DW_AT_upper_bound";
4967 case DW_AT_abstract_origin
:
4968 return "DW_AT_abstract_origin";
4969 case DW_AT_accessibility
:
4970 return "DW_AT_accessibility";
4971 case DW_AT_address_class
:
4972 return "DW_AT_address_class";
4973 case DW_AT_artificial
:
4974 return "DW_AT_artificial";
4975 case DW_AT_base_types
:
4976 return "DW_AT_base_types";
4977 case DW_AT_calling_convention
:
4978 return "DW_AT_calling_convention";
4980 return "DW_AT_count";
4981 case DW_AT_data_member_location
:
4982 return "DW_AT_data_member_location";
4983 case DW_AT_decl_column
:
4984 return "DW_AT_decl_column";
4985 case DW_AT_decl_file
:
4986 return "DW_AT_decl_file";
4987 case DW_AT_decl_line
:
4988 return "DW_AT_decl_line";
4989 case DW_AT_declaration
:
4990 return "DW_AT_declaration";
4991 case DW_AT_discr_list
:
4992 return "DW_AT_discr_list";
4993 case DW_AT_encoding
:
4994 return "DW_AT_encoding";
4995 case DW_AT_external
:
4996 return "DW_AT_external";
4997 case DW_AT_frame_base
:
4998 return "DW_AT_frame_base";
5000 return "DW_AT_friend";
5001 case DW_AT_identifier_case
:
5002 return "DW_AT_identifier_case";
5003 case DW_AT_macro_info
:
5004 return "DW_AT_macro_info";
5005 case DW_AT_namelist_items
:
5006 return "DW_AT_namelist_items";
5007 case DW_AT_priority
:
5008 return "DW_AT_priority";
5010 return "DW_AT_segment";
5011 case DW_AT_specification
:
5012 return "DW_AT_specification";
5013 case DW_AT_static_link
:
5014 return "DW_AT_static_link";
5016 return "DW_AT_type";
5017 case DW_AT_use_location
:
5018 return "DW_AT_use_location";
5019 case DW_AT_variable_parameter
:
5020 return "DW_AT_variable_parameter";
5021 case DW_AT_virtuality
:
5022 return "DW_AT_virtuality";
5023 case DW_AT_vtable_elem_location
:
5024 return "DW_AT_vtable_elem_location";
5027 case DW_AT_MIPS_fde
:
5028 return "DW_AT_MIPS_fde";
5029 case DW_AT_MIPS_loop_begin
:
5030 return "DW_AT_MIPS_loop_begin";
5031 case DW_AT_MIPS_tail_loop_begin
:
5032 return "DW_AT_MIPS_tail_loop_begin";
5033 case DW_AT_MIPS_epilog_begin
:
5034 return "DW_AT_MIPS_epilog_begin";
5035 case DW_AT_MIPS_loop_unroll_factor
:
5036 return "DW_AT_MIPS_loop_unroll_factor";
5037 case DW_AT_MIPS_software_pipeline_depth
:
5038 return "DW_AT_MIPS_software_pipeline_depth";
5039 case DW_AT_MIPS_linkage_name
:
5040 return "DW_AT_MIPS_linkage_name";
5043 case DW_AT_sf_names
:
5044 return "DW_AT_sf_names";
5045 case DW_AT_src_info
:
5046 return "DW_AT_src_info";
5047 case DW_AT_mac_info
:
5048 return "DW_AT_mac_info";
5049 case DW_AT_src_coords
:
5050 return "DW_AT_src_coords";
5051 case DW_AT_body_begin
:
5052 return "DW_AT_body_begin";
5053 case DW_AT_body_end
:
5054 return "DW_AT_body_end";
5056 return "DW_AT_<unknown>";
5060 /* Convert a DWARF value form code into its string name. */
5063 dwarf_form_name (register unsigned form
)
5068 return "DW_FORM_addr";
5069 case DW_FORM_block2
:
5070 return "DW_FORM_block2";
5071 case DW_FORM_block4
:
5072 return "DW_FORM_block4";
5074 return "DW_FORM_data2";
5076 return "DW_FORM_data4";
5078 return "DW_FORM_data8";
5079 case DW_FORM_string
:
5080 return "DW_FORM_string";
5082 return "DW_FORM_block";
5083 case DW_FORM_block1
:
5084 return "DW_FORM_block1";
5086 return "DW_FORM_data1";
5088 return "DW_FORM_flag";
5090 return "DW_FORM_sdata";
5092 return "DW_FORM_strp";
5094 return "DW_FORM_udata";
5095 case DW_FORM_ref_addr
:
5096 return "DW_FORM_ref_addr";
5098 return "DW_FORM_ref1";
5100 return "DW_FORM_ref2";
5102 return "DW_FORM_ref4";
5104 return "DW_FORM_ref8";
5105 case DW_FORM_ref_udata
:
5106 return "DW_FORM_ref_udata";
5107 case DW_FORM_indirect
:
5108 return "DW_FORM_indirect";
5110 return "DW_FORM_<unknown>";
5114 /* Convert a DWARF stack opcode into its string name. */
5117 dwarf_stack_op_name (register unsigned op
)
5122 return "DW_OP_addr";
5124 return "DW_OP_deref";
5126 return "DW_OP_const1u";
5128 return "DW_OP_const1s";
5130 return "DW_OP_const2u";
5132 return "DW_OP_const2s";
5134 return "DW_OP_const4u";
5136 return "DW_OP_const4s";
5138 return "DW_OP_const8u";
5140 return "DW_OP_const8s";
5142 return "DW_OP_constu";
5144 return "DW_OP_consts";
5148 return "DW_OP_drop";
5150 return "DW_OP_over";
5152 return "DW_OP_pick";
5154 return "DW_OP_swap";
5158 return "DW_OP_xderef";
5166 return "DW_OP_minus";
5178 return "DW_OP_plus";
5179 case DW_OP_plus_uconst
:
5180 return "DW_OP_plus_uconst";
5186 return "DW_OP_shra";
5204 return "DW_OP_skip";
5206 return "DW_OP_lit0";
5208 return "DW_OP_lit1";
5210 return "DW_OP_lit2";
5212 return "DW_OP_lit3";
5214 return "DW_OP_lit4";
5216 return "DW_OP_lit5";
5218 return "DW_OP_lit6";
5220 return "DW_OP_lit7";
5222 return "DW_OP_lit8";
5224 return "DW_OP_lit9";
5226 return "DW_OP_lit10";
5228 return "DW_OP_lit11";
5230 return "DW_OP_lit12";
5232 return "DW_OP_lit13";
5234 return "DW_OP_lit14";
5236 return "DW_OP_lit15";
5238 return "DW_OP_lit16";
5240 return "DW_OP_lit17";
5242 return "DW_OP_lit18";
5244 return "DW_OP_lit19";
5246 return "DW_OP_lit20";
5248 return "DW_OP_lit21";
5250 return "DW_OP_lit22";
5252 return "DW_OP_lit23";
5254 return "DW_OP_lit24";
5256 return "DW_OP_lit25";
5258 return "DW_OP_lit26";
5260 return "DW_OP_lit27";
5262 return "DW_OP_lit28";
5264 return "DW_OP_lit29";
5266 return "DW_OP_lit30";
5268 return "DW_OP_lit31";
5270 return "DW_OP_reg0";
5272 return "DW_OP_reg1";
5274 return "DW_OP_reg2";
5276 return "DW_OP_reg3";
5278 return "DW_OP_reg4";
5280 return "DW_OP_reg5";
5282 return "DW_OP_reg6";
5284 return "DW_OP_reg7";
5286 return "DW_OP_reg8";
5288 return "DW_OP_reg9";
5290 return "DW_OP_reg10";
5292 return "DW_OP_reg11";
5294 return "DW_OP_reg12";
5296 return "DW_OP_reg13";
5298 return "DW_OP_reg14";
5300 return "DW_OP_reg15";
5302 return "DW_OP_reg16";
5304 return "DW_OP_reg17";
5306 return "DW_OP_reg18";
5308 return "DW_OP_reg19";
5310 return "DW_OP_reg20";
5312 return "DW_OP_reg21";
5314 return "DW_OP_reg22";
5316 return "DW_OP_reg23";
5318 return "DW_OP_reg24";
5320 return "DW_OP_reg25";
5322 return "DW_OP_reg26";
5324 return "DW_OP_reg27";
5326 return "DW_OP_reg28";
5328 return "DW_OP_reg29";
5330 return "DW_OP_reg30";
5332 return "DW_OP_reg31";
5334 return "DW_OP_breg0";
5336 return "DW_OP_breg1";
5338 return "DW_OP_breg2";
5340 return "DW_OP_breg3";
5342 return "DW_OP_breg4";
5344 return "DW_OP_breg5";
5346 return "DW_OP_breg6";
5348 return "DW_OP_breg7";
5350 return "DW_OP_breg8";
5352 return "DW_OP_breg9";
5354 return "DW_OP_breg10";
5356 return "DW_OP_breg11";
5358 return "DW_OP_breg12";
5360 return "DW_OP_breg13";
5362 return "DW_OP_breg14";
5364 return "DW_OP_breg15";
5366 return "DW_OP_breg16";
5368 return "DW_OP_breg17";
5370 return "DW_OP_breg18";
5372 return "DW_OP_breg19";
5374 return "DW_OP_breg20";
5376 return "DW_OP_breg21";
5378 return "DW_OP_breg22";
5380 return "DW_OP_breg23";
5382 return "DW_OP_breg24";
5384 return "DW_OP_breg25";
5386 return "DW_OP_breg26";
5388 return "DW_OP_breg27";
5390 return "DW_OP_breg28";
5392 return "DW_OP_breg29";
5394 return "DW_OP_breg30";
5396 return "DW_OP_breg31";
5398 return "DW_OP_regx";
5400 return "DW_OP_fbreg";
5402 return "DW_OP_bregx";
5404 return "DW_OP_piece";
5405 case DW_OP_deref_size
:
5406 return "DW_OP_deref_size";
5407 case DW_OP_xderef_size
:
5408 return "DW_OP_xderef_size";
5412 return "OP_<unknown>";
5417 dwarf_bool_name (unsigned mybool
)
5425 /* Convert a DWARF type code into its string name. */
5428 dwarf_type_encoding_name (register unsigned enc
)
5432 case DW_ATE_address
:
5433 return "DW_ATE_address";
5434 case DW_ATE_boolean
:
5435 return "DW_ATE_boolean";
5436 case DW_ATE_complex_float
:
5437 return "DW_ATE_complex_float";
5439 return "DW_ATE_float";
5441 return "DW_ATE_signed";
5442 case DW_ATE_signed_char
:
5443 return "DW_ATE_signed_char";
5444 case DW_ATE_unsigned
:
5445 return "DW_ATE_unsigned";
5446 case DW_ATE_unsigned_char
:
5447 return "DW_ATE_unsigned_char";
5449 return "DW_ATE_<unknown>";
5453 /* Convert a DWARF call frame info operation to its string name. */
5457 dwarf_cfi_name (register unsigned cfi_opc
)
5461 case DW_CFA_advance_loc
:
5462 return "DW_CFA_advance_loc";
5464 return "DW_CFA_offset";
5465 case DW_CFA_restore
:
5466 return "DW_CFA_restore";
5468 return "DW_CFA_nop";
5469 case DW_CFA_set_loc
:
5470 return "DW_CFA_set_loc";
5471 case DW_CFA_advance_loc1
:
5472 return "DW_CFA_advance_loc1";
5473 case DW_CFA_advance_loc2
:
5474 return "DW_CFA_advance_loc2";
5475 case DW_CFA_advance_loc4
:
5476 return "DW_CFA_advance_loc4";
5477 case DW_CFA_offset_extended
:
5478 return "DW_CFA_offset_extended";
5479 case DW_CFA_restore_extended
:
5480 return "DW_CFA_restore_extended";
5481 case DW_CFA_undefined
:
5482 return "DW_CFA_undefined";
5483 case DW_CFA_same_value
:
5484 return "DW_CFA_same_value";
5485 case DW_CFA_register
:
5486 return "DW_CFA_register";
5487 case DW_CFA_remember_state
:
5488 return "DW_CFA_remember_state";
5489 case DW_CFA_restore_state
:
5490 return "DW_CFA_restore_state";
5491 case DW_CFA_def_cfa
:
5492 return "DW_CFA_def_cfa";
5493 case DW_CFA_def_cfa_register
:
5494 return "DW_CFA_def_cfa_register";
5495 case DW_CFA_def_cfa_offset
:
5496 return "DW_CFA_def_cfa_offset";
5497 /* SGI/MIPS specific */
5498 case DW_CFA_MIPS_advance_loc8
:
5499 return "DW_CFA_MIPS_advance_loc8";
5501 return "DW_CFA_<unknown>";
5507 dump_die (struct die_info
*die
)
5511 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5512 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5513 fprintf (stderr
, "\thas children: %s\n",
5514 dwarf_bool_name (die
->has_children
));
5516 fprintf (stderr
, "\tattributes:\n");
5517 for (i
= 0; i
< die
->num_attrs
; ++i
)
5519 fprintf (stderr
, "\t\t%s (%s) ",
5520 dwarf_attr_name (die
->attrs
[i
].name
),
5521 dwarf_form_name (die
->attrs
[i
].form
));
5522 switch (die
->attrs
[i
].form
)
5524 case DW_FORM_ref_addr
:
5526 fprintf (stderr
, "address: ");
5527 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5529 case DW_FORM_block2
:
5530 case DW_FORM_block4
:
5532 case DW_FORM_block1
:
5533 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5544 fprintf (stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
5546 case DW_FORM_string
:
5547 fprintf (stderr
, "string: \"%s\"",
5548 DW_STRING (&die
->attrs
[i
])
5549 ? DW_STRING (&die
->attrs
[i
]) : "");
5552 if (DW_UNSND (&die
->attrs
[i
]))
5553 fprintf (stderr
, "flag: TRUE");
5555 fprintf (stderr
, "flag: FALSE");
5557 case DW_FORM_strp
: /* we do not support separate string
5559 case DW_FORM_indirect
: /* we do not handle indirect yet */
5561 fprintf (stderr
, "unsupported attribute form: %d.",
5562 die
->attrs
[i
].form
);
5564 fprintf (stderr
, "\n");
5569 dump_die_list (struct die_info
*die
)
5579 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
5582 struct die_info
*old
;
5584 h
= (offset
% REF_HASH_SIZE
);
5585 old
= die_ref_table
[h
];
5586 die
->next_ref
= old
;
5587 die_ref_table
[h
] = die
;
5592 dwarf2_empty_hash_tables (void)
5594 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5598 dwarf2_get_ref_die_offset (struct attribute
*attr
)
5600 unsigned int result
= 0;
5604 case DW_FORM_ref_addr
:
5605 result
= DW_ADDR (attr
);
5611 case DW_FORM_ref_udata
:
5612 result
= cu_header_offset
+ DW_UNSND (attr
);
5615 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5620 static struct die_info
*
5621 follow_die_ref (unsigned int offset
)
5623 struct die_info
*die
;
5626 h
= (offset
% REF_HASH_SIZE
);
5627 die
= die_ref_table
[h
];
5630 if (die
->offset
== offset
)
5634 die
= die
->next_ref
;
5639 static struct type
*
5640 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
5642 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5644 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5648 /* Look for this particular type in the fundamental type vector. If
5649 one is not found, create and install one appropriate for the
5650 current language and the current target machine. */
5652 if (ftypes
[typeid] == NULL
)
5654 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5657 return (ftypes
[typeid]);
5660 /* Decode simple location descriptions.
5661 Given a pointer to a dwarf block that defines a location, compute
5662 the location and return the value.
5664 FIXME: This is a kludge until we figure out a better
5665 way to handle the location descriptions.
5666 Gdb's design does not mesh well with the DWARF2 notion of a location
5667 computing interpreter, which is a shame because the flexibility goes unused.
5668 FIXME: Implement more operations as necessary.
5670 A location description containing no operations indicates that the
5671 object is optimized out. The global optimized_out flag is set for
5672 those, the return value is meaningless.
5674 When the result is a register number, the global isreg flag is set,
5675 otherwise it is cleared.
5677 When the result is a base register offset, the global offreg flag is set
5678 and the register number is returned in basereg, otherwise it is cleared.
5680 When the DW_OP_fbreg operation is encountered without a corresponding
5681 DW_AT_frame_base attribute, the global islocal flag is set.
5682 Hopefully the machine dependent code knows how to set up a virtual
5683 frame pointer for the local references.
5685 Note that stack[0] is unused except as a default error return.
5686 Note that stack overflow is not yet handled. */
5689 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
5690 const struct comp_unit_head
*cu_header
)
5693 int size
= blk
->size
;
5694 char *data
= blk
->data
;
5695 CORE_ADDR stack
[64];
5697 unsigned int bytes_read
, unsnd
;
5748 stack
[++stacki
] = op
- DW_OP_reg0
;
5753 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5755 #if defined(HARRIS_TARGET) && defined(_M88K)
5756 /* The Harris 88110 gdb ports have long kept their special reg
5757 numbers between their gp-regs and their x-regs. This is
5758 not how our dwarf is generated. Punt. */
5761 stack
[++stacki
] = unsnd
;
5797 basereg
= op
- DW_OP_breg0
;
5798 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5804 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5806 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5811 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5813 if (frame_base_reg
>= 0)
5816 basereg
= frame_base_reg
;
5817 stack
[stacki
] += frame_base_offset
;
5821 complain (&dwarf2_missing_at_frame_base
);
5827 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
5828 cu_header
, &bytes_read
);
5833 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5838 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5843 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5848 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5853 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5858 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5863 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5869 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5874 stack
[stacki
- 1] += stack
[stacki
];
5878 case DW_OP_plus_uconst
:
5879 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5884 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5890 /* If we're not the last op, then we definitely can't encode
5891 this using GDB's address_class enum. */
5893 complain (&dwarf2_complex_location_expr
);
5897 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
5898 return (stack
[stacki
]);
5901 return (stack
[stacki
]);
5904 /* memory allocation interface */
5908 dwarf2_free_tmp_obstack (PTR ignore
)
5910 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5913 static struct dwarf_block
*
5914 dwarf_alloc_block (void)
5916 struct dwarf_block
*blk
;
5918 blk
= (struct dwarf_block
*)
5919 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5923 static struct abbrev_info
*
5924 dwarf_alloc_abbrev (void)
5926 struct abbrev_info
*abbrev
;
5928 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5929 memset (abbrev
, 0, sizeof (struct abbrev_info
));
5933 static struct die_info
*
5934 dwarf_alloc_die (void)
5936 struct die_info
*die
;
5938 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5939 memset (die
, 0, sizeof (struct die_info
));