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 struct die_info
*read_comp_unit (char *, bfd
*, const struct comp_unit_head
*);
732 static void free_die_list (struct die_info
*);
734 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
736 static void process_die (struct die_info
*, struct objfile
*,
737 const struct comp_unit_head
*);
739 static char *dwarf2_linkage_name (struct die_info
*);
741 static char *dwarf_tag_name (unsigned int);
743 static char *dwarf_attr_name (unsigned int);
745 static char *dwarf_form_name (unsigned int);
747 static char *dwarf_stack_op_name (unsigned int);
749 static char *dwarf_bool_name (unsigned int);
751 static char *dwarf_type_encoding_name (unsigned int);
754 static char *dwarf_cfi_name (unsigned int);
756 struct die_info
*copy_die (struct die_info
*);
759 struct die_info
*sibling_die (struct die_info
*);
761 void dump_die (struct die_info
*);
763 void dump_die_list (struct die_info
*);
765 void store_in_ref_table (unsigned int, struct die_info
*);
767 static void dwarf2_empty_hash_tables (void);
769 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
771 struct die_info
*follow_die_ref (unsigned int);
773 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
775 /* memory allocation interface */
777 static void dwarf2_free_tmp_obstack (PTR
);
779 static struct dwarf_block
*dwarf_alloc_block (void);
781 static struct abbrev_info
*dwarf_alloc_abbrev (void);
783 static struct die_info
*dwarf_alloc_die (void);
785 /* Try to locate the sections we need for DWARF 2 debugging
786 information and return true if we have enough to do something. */
789 dwarf2_has_info (bfd
*abfd
)
791 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
792 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
793 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
803 /* This function is mapped across the sections and remembers the
804 offset and size of each of the debugging sections we are interested
808 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, PTR ignore_ptr
)
810 if (STREQ (sectp
->name
, INFO_SECTION
))
812 dwarf_info_offset
= sectp
->filepos
;
813 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
815 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
817 dwarf_abbrev_offset
= sectp
->filepos
;
818 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
820 else if (STREQ (sectp
->name
, LINE_SECTION
))
822 dwarf_line_offset
= sectp
->filepos
;
823 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
825 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
827 dwarf_pubnames_offset
= sectp
->filepos
;
828 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
830 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
832 dwarf_aranges_offset
= sectp
->filepos
;
833 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
835 else if (STREQ (sectp
->name
, LOC_SECTION
))
837 dwarf_loc_offset
= sectp
->filepos
;
838 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
840 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
842 dwarf_macinfo_offset
= sectp
->filepos
;
843 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
845 else if (STREQ (sectp
->name
, STR_SECTION
))
847 dwarf_str_offset
= sectp
->filepos
;
848 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
852 /* Build a partial symbol table. */
855 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
858 /* We definitely need the .debug_info and .debug_abbrev sections */
860 dwarf_info_buffer
= dwarf2_read_section (objfile
,
863 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
866 dwarf_line_buffer
= dwarf2_read_section (objfile
,
870 if (mainline
|| objfile
->global_psymbols
.size
== 0 ||
871 objfile
->static_psymbols
.size
== 0)
873 init_psymbol_list (objfile
, 1024);
877 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
879 /* Things are significantly easier if we have .debug_aranges and
880 .debug_pubnames sections */
882 dwarf2_build_psymtabs_easy (objfile
, mainline
);
886 /* only test this case for now */
888 /* In this case we have to work a bit harder */
889 dwarf2_build_psymtabs_hard (objfile
, mainline
);
894 /* Build the partial symbol table from the information in the
895 .debug_pubnames and .debug_aranges sections. */
898 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
900 bfd
*abfd
= objfile
->obfd
;
901 char *aranges_buffer
, *pubnames_buffer
;
902 char *aranges_ptr
, *pubnames_ptr
;
903 unsigned int entry_length
, version
, info_offset
, info_size
;
905 pubnames_buffer
= dwarf2_read_section (objfile
,
906 dwarf_pubnames_offset
,
907 dwarf_pubnames_size
);
908 pubnames_ptr
= pubnames_buffer
;
909 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
911 struct comp_unit_head cu_header
;
914 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
916 pubnames_ptr
+= bytes_read
;
917 version
= read_1_byte (abfd
, pubnames_ptr
);
919 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
921 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
925 aranges_buffer
= dwarf2_read_section (objfile
,
926 dwarf_aranges_offset
,
932 /* Read in the comp unit header information from the debug_info at
936 read_comp_unit_head (struct comp_unit_head
*cu_header
,
937 char *info_ptr
, bfd
*abfd
)
941 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
943 info_ptr
+= bytes_read
;
944 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
946 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
948 info_ptr
+= bytes_read
;
949 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
951 signed_addr
= bfd_get_sign_extend_vma (abfd
);
953 internal_error (__FILE__
, __LINE__
,
954 "read_comp_unit_head: dwarf from non elf file");
955 cu_header
->signed_addr_p
= signed_addr
;
959 /* Build the partial symbol table by doing a quick pass through the
960 .debug_info and .debug_abbrev sections. */
963 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
965 /* Instead of reading this into a big buffer, we should probably use
966 mmap() on architectures that support it. (FIXME) */
967 bfd
*abfd
= objfile
->obfd
;
968 char *info_ptr
, *abbrev_ptr
;
969 char *beg_of_comp_unit
;
970 struct partial_die_info comp_unit_die
;
971 struct partial_symtab
*pst
;
972 struct cleanup
*back_to
;
973 int comp_unit_has_pc_info
;
974 CORE_ADDR lowpc
, highpc
;
976 info_ptr
= dwarf_info_buffer
;
977 abbrev_ptr
= dwarf_abbrev_buffer
;
979 obstack_init (&dwarf2_tmp_obstack
);
980 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
982 while ((unsigned int) (info_ptr
- dwarf_info_buffer
)
983 + ((info_ptr
- dwarf_info_buffer
) % 4) < dwarf_info_size
)
985 struct comp_unit_head cu_header
;
986 beg_of_comp_unit
= info_ptr
;
987 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
989 if (cu_header
.version
!= 2)
991 error ("Dwarf Error: wrong version in compilation unit header.");
994 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
996 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
997 (long) cu_header
.abbrev_offset
,
998 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1001 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1002 > dwarf_info_buffer
+ dwarf_info_size
)
1004 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
1005 (long) cu_header
.length
,
1006 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1009 /* Read the abbrevs for this compilation unit into a table */
1010 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1011 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1013 /* Read the compilation unit die */
1014 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1015 &comp_unit_has_pc_info
, &cu_header
);
1017 /* Set the language we're debugging */
1018 set_cu_language (comp_unit_die
.language
);
1020 /* Allocate a new partial symbol table structure */
1021 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1022 comp_unit_die
.name
? comp_unit_die
.name
: "",
1023 comp_unit_die
.lowpc
,
1024 objfile
->global_psymbols
.next
,
1025 objfile
->static_psymbols
.next
);
1027 pst
->read_symtab_private
= (char *)
1028 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1029 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1030 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1031 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1032 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1033 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1034 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1035 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1037 /* Store the function that reads in the rest of the symbol table */
1038 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1040 /* Check if comp unit has_children.
1041 If so, read the rest of the partial symbols from this comp unit.
1042 If not, there's no more debug_info for this comp unit. */
1043 if (comp_unit_die
.has_children
)
1045 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1048 /* If the compilation unit didn't have an explicit address range,
1049 then use the information extracted from its child dies. */
1050 if (!comp_unit_has_pc_info
)
1052 comp_unit_die
.lowpc
= lowpc
;
1053 comp_unit_die
.highpc
= highpc
;
1056 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1057 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1059 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1060 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1061 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1062 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1063 sort_pst_symbols (pst
);
1065 /* If there is already a psymtab or symtab for a file of this
1066 name, remove it. (If there is a symtab, more drastic things
1067 also happen.) This happens in VxWorks. */
1068 free_named_symtabs (pst
->filename
);
1070 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1071 + cu_header
.initial_length_size
;
1073 do_cleanups (back_to
);
1076 /* Read in all interesting dies to the end of the compilation unit. */
1079 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1080 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1081 const struct comp_unit_head
*cu_header
)
1083 bfd
*abfd
= objfile
->obfd
;
1084 struct partial_die_info pdi
;
1086 /* This function is called after we've read in the comp_unit_die in
1087 order to read its children. We start the nesting level at 1 since
1088 we have pushed 1 level down in order to read the comp unit's children.
1089 The comp unit itself is at level 0, so we stop reading when we pop
1090 back to that level. */
1092 int nesting_level
= 1;
1095 *lowpc
= ((CORE_ADDR
) -1);
1096 *highpc
= ((CORE_ADDR
) 0);
1098 while (nesting_level
)
1100 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
,
1101 &has_pc_info
, cu_header
);
1107 case DW_TAG_subprogram
:
1110 if (pdi
.lowpc
< *lowpc
)
1114 if (pdi
.highpc
> *highpc
)
1116 *highpc
= pdi
.highpc
;
1118 if ((pdi
.is_external
|| nesting_level
== 1)
1119 && !pdi
.is_declaration
)
1121 add_partial_symbol (&pdi
, objfile
, cu_header
);
1125 case DW_TAG_variable
:
1126 case DW_TAG_typedef
:
1127 case DW_TAG_class_type
:
1128 case DW_TAG_structure_type
:
1129 case DW_TAG_union_type
:
1130 case DW_TAG_enumeration_type
:
1131 if ((pdi
.is_external
|| nesting_level
== 1)
1132 && !pdi
.is_declaration
)
1134 add_partial_symbol (&pdi
, objfile
, cu_header
);
1137 case DW_TAG_enumerator
:
1138 /* File scope enumerators are added to the partial symbol
1140 if (nesting_level
== 2)
1141 add_partial_symbol (&pdi
, objfile
, cu_header
);
1143 case DW_TAG_base_type
:
1144 /* File scope base type definitions are added to the partial
1146 if (nesting_level
== 1)
1147 add_partial_symbol (&pdi
, objfile
, cu_header
);
1154 /* If the die has a sibling, skip to the sibling.
1155 Do not skip enumeration types, we want to record their
1157 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1159 info_ptr
= pdi
.sibling
;
1161 else if (pdi
.has_children
)
1163 /* Die has children, but the optional DW_AT_sibling attribute
1174 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1175 from `maint check'. */
1176 if (*lowpc
== ((CORE_ADDR
) -1))
1182 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1183 const struct comp_unit_head
*cu_header
)
1189 case DW_TAG_subprogram
:
1190 if (pdi
->is_external
)
1192 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1193 mst_text, objfile); */
1194 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1195 VAR_NAMESPACE
, LOC_BLOCK
,
1196 &objfile
->global_psymbols
,
1197 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1201 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1202 mst_file_text, objfile); */
1203 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1204 VAR_NAMESPACE
, LOC_BLOCK
,
1205 &objfile
->static_psymbols
,
1206 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1209 case DW_TAG_variable
:
1210 if (pdi
->is_external
)
1213 Don't enter into the minimal symbol tables as there is
1214 a minimal symbol table entry from the ELF symbols already.
1215 Enter into partial symbol table if it has a location
1216 descriptor or a type.
1217 If the location descriptor is missing, new_symbol will create
1218 a LOC_UNRESOLVED symbol, the address of the variable will then
1219 be determined from the minimal symbol table whenever the variable
1221 The address for the partial symbol table entry is not
1222 used by GDB, but it comes in handy for debugging partial symbol
1226 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1227 if (pdi
->locdesc
|| pdi
->has_type
)
1228 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1229 VAR_NAMESPACE
, LOC_STATIC
,
1230 &objfile
->global_psymbols
,
1231 0, addr
+ baseaddr
, cu_language
, objfile
);
1235 /* Static Variable. Skip symbols without location descriptors. */
1236 if (pdi
->locdesc
== NULL
)
1238 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1239 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1240 mst_file_data, objfile); */
1241 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1242 VAR_NAMESPACE
, LOC_STATIC
,
1243 &objfile
->static_psymbols
,
1244 0, addr
+ baseaddr
, cu_language
, objfile
);
1247 case DW_TAG_typedef
:
1248 case DW_TAG_base_type
:
1249 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1250 VAR_NAMESPACE
, LOC_TYPEDEF
,
1251 &objfile
->static_psymbols
,
1252 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1254 case DW_TAG_class_type
:
1255 case DW_TAG_structure_type
:
1256 case DW_TAG_union_type
:
1257 case DW_TAG_enumeration_type
:
1258 /* Skip aggregate types without children, these are external
1260 if (pdi
->has_children
== 0)
1262 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1263 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1264 &objfile
->static_psymbols
,
1265 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1267 if (cu_language
== language_cplus
)
1269 /* For C++, these implicitly act as typedefs as well. */
1270 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1271 VAR_NAMESPACE
, LOC_TYPEDEF
,
1272 &objfile
->static_psymbols
,
1273 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1276 case DW_TAG_enumerator
:
1277 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1278 VAR_NAMESPACE
, LOC_CONST
,
1279 &objfile
->static_psymbols
,
1280 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1287 /* Expand this partial symbol table into a full symbol table. */
1290 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1292 /* FIXME: This is barely more than a stub. */
1297 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1303 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1304 gdb_flush (gdb_stdout
);
1307 psymtab_to_symtab_1 (pst
);
1309 /* Finish up the debug error message. */
1311 printf_filtered ("done.\n");
1317 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1319 struct objfile
*objfile
= pst
->objfile
;
1320 bfd
*abfd
= objfile
->obfd
;
1321 struct comp_unit_head cu_header
;
1322 struct die_info
*dies
;
1323 unsigned long offset
;
1324 CORE_ADDR lowpc
, highpc
;
1325 struct die_info
*child_die
;
1327 struct symtab
*symtab
;
1328 struct cleanup
*back_to
;
1330 /* Set local variables from the partial symbol table info. */
1331 offset
= DWARF_INFO_OFFSET (pst
);
1332 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1333 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1334 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1335 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1336 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1337 cu_header_offset
= offset
;
1338 info_ptr
= dwarf_info_buffer
+ offset
;
1340 obstack_init (&dwarf2_tmp_obstack
);
1341 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1344 make_cleanup (really_free_pendings
, NULL
);
1346 /* read in the comp_unit header */
1347 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1349 /* Read the abbrevs for this compilation unit */
1350 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1351 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1353 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1355 make_cleanup_free_die_list (dies
);
1357 /* Do line number decoding in read_file_scope () */
1358 process_die (dies
, objfile
, &cu_header
);
1360 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1362 /* Some compilers don't define a DW_AT_high_pc attribute for
1363 the compilation unit. If the DW_AT_high_pc is missing,
1364 synthesize it, by scanning the DIE's below the compilation unit. */
1366 if (dies
->has_children
)
1368 child_die
= dies
->next
;
1369 while (child_die
&& child_die
->tag
)
1371 if (child_die
->tag
== DW_TAG_subprogram
)
1373 CORE_ADDR low
, high
;
1375 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1377 highpc
= max (highpc
, high
);
1380 child_die
= sibling_die (child_die
);
1384 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1386 /* Set symtab language to language from DW_AT_language.
1387 If the compilation is from a C file generated by language preprocessors,
1388 do not set the language if it was already deduced by start_subfile. */
1390 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1392 symtab
->language
= cu_language
;
1394 pst
->symtab
= symtab
;
1396 sort_symtab_syms (pst
->symtab
);
1398 do_cleanups (back_to
);
1401 /* Process a die and its children. */
1404 process_die (struct die_info
*die
, struct objfile
*objfile
,
1405 const struct comp_unit_head
*cu_header
)
1409 case DW_TAG_padding
:
1411 case DW_TAG_compile_unit
:
1412 read_file_scope (die
, objfile
, cu_header
);
1414 case DW_TAG_subprogram
:
1415 read_subroutine_type (die
, objfile
, cu_header
);
1416 read_func_scope (die
, objfile
, cu_header
);
1418 case DW_TAG_inlined_subroutine
:
1419 /* FIXME: These are ignored for now.
1420 They could be used to set breakpoints on all inlined instances
1421 of a function and make GDB `next' properly over inlined functions. */
1423 case DW_TAG_lexical_block
:
1424 read_lexical_block_scope (die
, objfile
, cu_header
);
1426 case DW_TAG_class_type
:
1427 case DW_TAG_structure_type
:
1428 case DW_TAG_union_type
:
1429 read_structure_scope (die
, objfile
, cu_header
);
1431 case DW_TAG_enumeration_type
:
1432 read_enumeration (die
, objfile
, cu_header
);
1434 case DW_TAG_subroutine_type
:
1435 read_subroutine_type (die
, objfile
, cu_header
);
1437 case DW_TAG_array_type
:
1438 read_array_type (die
, objfile
, cu_header
);
1440 case DW_TAG_pointer_type
:
1441 read_tag_pointer_type (die
, objfile
, cu_header
);
1443 case DW_TAG_ptr_to_member_type
:
1444 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1446 case DW_TAG_reference_type
:
1447 read_tag_reference_type (die
, objfile
, cu_header
);
1449 case DW_TAG_string_type
:
1450 read_tag_string_type (die
, objfile
);
1452 case DW_TAG_base_type
:
1453 read_base_type (die
, objfile
);
1454 if (dwarf_attr (die
, DW_AT_name
))
1456 /* Add a typedef symbol for the base type definition. */
1457 new_symbol (die
, die
->type
, objfile
, cu_header
);
1460 case DW_TAG_common_block
:
1461 read_common_block (die
, objfile
, cu_header
);
1463 case DW_TAG_common_inclusion
:
1466 new_symbol (die
, NULL
, objfile
, cu_header
);
1472 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1473 const struct comp_unit_head
*cu_header
)
1475 unsigned int line_offset
= 0;
1476 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1477 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1478 struct attribute
*attr
;
1479 char *name
= "<unknown>";
1480 char *comp_dir
= NULL
;
1481 struct die_info
*child_die
;
1482 bfd
*abfd
= objfile
->obfd
;
1484 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1486 if (die
->has_children
)
1488 child_die
= die
->next
;
1489 while (child_die
&& child_die
->tag
)
1491 if (child_die
->tag
== DW_TAG_subprogram
)
1493 CORE_ADDR low
, high
;
1495 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1497 lowpc
= min (lowpc
, low
);
1498 highpc
= max (highpc
, high
);
1501 child_die
= sibling_die (child_die
);
1506 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1507 from finish_block. */
1508 if (lowpc
== ((CORE_ADDR
) -1))
1513 attr
= dwarf_attr (die
, DW_AT_name
);
1516 name
= DW_STRING (attr
);
1518 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1521 comp_dir
= DW_STRING (attr
);
1524 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1525 directory, get rid of it. */
1526 char *cp
= strchr (comp_dir
, ':');
1528 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1533 if (objfile
->ei
.entry_point
>= lowpc
&&
1534 objfile
->ei
.entry_point
< highpc
)
1536 objfile
->ei
.entry_file_lowpc
= lowpc
;
1537 objfile
->ei
.entry_file_highpc
= highpc
;
1540 attr
= dwarf_attr (die
, DW_AT_language
);
1543 set_cu_language (DW_UNSND (attr
));
1546 /* We assume that we're processing GCC output. */
1547 processing_gcc_compilation
= 2;
1549 /* FIXME:Do something here. */
1550 if (dip
->at_producer
!= NULL
)
1552 handle_producer (dip
->at_producer
);
1556 /* The compilation unit may be in a different language or objfile,
1557 zero out all remembered fundamental types. */
1558 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1560 start_symtab (name
, comp_dir
, lowpc
);
1561 record_debugformat ("DWARF 2");
1563 /* Decode line number information if present. */
1564 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1567 line_offset
= DW_UNSND (attr
);
1568 dwarf_decode_lines (line_offset
, comp_dir
, abfd
, cu_header
);
1571 /* Process all dies in compilation unit. */
1572 if (die
->has_children
)
1574 child_die
= die
->next
;
1575 while (child_die
&& child_die
->tag
)
1577 process_die (child_die
, objfile
, cu_header
);
1578 child_die
= sibling_die (child_die
);
1584 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
1585 const struct comp_unit_head
*cu_header
)
1587 register struct context_stack
*new;
1590 struct die_info
*child_die
;
1591 struct attribute
*attr
;
1594 name
= dwarf2_linkage_name (die
);
1596 /* Ignore functions with missing or empty names and functions with
1597 missing or invalid low and high pc attributes. */
1598 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1604 if (objfile
->ei
.entry_point
>= lowpc
&&
1605 objfile
->ei
.entry_point
< highpc
)
1607 objfile
->ei
.entry_func_lowpc
= lowpc
;
1608 objfile
->ei
.entry_func_highpc
= highpc
;
1611 /* Decode DW_AT_frame_base location descriptor if present, keep result
1612 for DW_OP_fbreg operands in decode_locdesc. */
1613 frame_base_reg
= -1;
1614 frame_base_offset
= 0;
1615 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1618 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
1620 complain (&dwarf2_unsupported_at_frame_base
, name
);
1622 frame_base_reg
= addr
;
1625 frame_base_reg
= basereg
;
1626 frame_base_offset
= addr
;
1629 complain (&dwarf2_unsupported_at_frame_base
, name
);
1632 new = push_context (0, lowpc
);
1633 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
1634 list_in_scope
= &local_symbols
;
1636 if (die
->has_children
)
1638 child_die
= die
->next
;
1639 while (child_die
&& child_die
->tag
)
1641 process_die (child_die
, objfile
, cu_header
);
1642 child_die
= sibling_die (child_die
);
1646 new = pop_context ();
1647 /* Make a block for the local symbols within. */
1648 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1649 lowpc
, highpc
, objfile
);
1650 list_in_scope
= &file_symbols
;
1653 /* Process all the DIES contained within a lexical block scope. Start
1654 a new scope, process the dies, and then close the scope. */
1657 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
1658 const struct comp_unit_head
*cu_header
)
1660 register struct context_stack
*new;
1661 CORE_ADDR lowpc
, highpc
;
1662 struct die_info
*child_die
;
1664 /* Ignore blocks with missing or invalid low and high pc attributes. */
1665 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1670 push_context (0, lowpc
);
1671 if (die
->has_children
)
1673 child_die
= die
->next
;
1674 while (child_die
&& child_die
->tag
)
1676 process_die (child_die
, objfile
, cu_header
);
1677 child_die
= sibling_die (child_die
);
1680 new = pop_context ();
1682 if (local_symbols
!= NULL
)
1684 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1687 local_symbols
= new->locals
;
1690 /* Get low and high pc attributes from a die.
1691 Return 1 if the attributes are present and valid, otherwise, return 0. */
1694 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1695 struct objfile
*objfile
)
1697 struct attribute
*attr
;
1701 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1703 low
= DW_ADDR (attr
);
1706 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1708 high
= DW_ADDR (attr
);
1715 /* When using the GNU linker, .gnu.linkonce. sections are used to
1716 eliminate duplicate copies of functions and vtables and such.
1717 The linker will arbitrarily choose one and discard the others.
1718 The AT_*_pc values for such functions refer to local labels in
1719 these sections. If the section from that file was discarded, the
1720 labels are not in the output, so the relocs get a value of 0.
1721 If this is a discarded function, mark the pc bounds as invalid,
1722 so that GDB will ignore it. */
1723 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1731 /* Add an aggregate field to the field list. */
1734 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
1735 struct objfile
*objfile
,
1736 const struct comp_unit_head
*cu_header
)
1738 struct nextfield
*new_field
;
1739 struct attribute
*attr
;
1741 char *fieldname
= "";
1743 /* Allocate a new field list entry and link it in. */
1744 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1745 make_cleanup (xfree
, new_field
);
1746 memset (new_field
, 0, sizeof (struct nextfield
));
1747 new_field
->next
= fip
->fields
;
1748 fip
->fields
= new_field
;
1751 /* Handle accessibility and virtuality of field.
1752 The default accessibility for members is public, the default
1753 accessibility for inheritance is private. */
1754 if (die
->tag
!= DW_TAG_inheritance
)
1755 new_field
->accessibility
= DW_ACCESS_public
;
1757 new_field
->accessibility
= DW_ACCESS_private
;
1758 new_field
->virtuality
= DW_VIRTUALITY_none
;
1760 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1762 new_field
->accessibility
= DW_UNSND (attr
);
1763 if (new_field
->accessibility
!= DW_ACCESS_public
)
1764 fip
->non_public_fields
= 1;
1765 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1767 new_field
->virtuality
= DW_UNSND (attr
);
1769 fp
= &new_field
->field
;
1770 if (die
->tag
== DW_TAG_member
)
1772 /* Get type of field. */
1773 fp
->type
= die_type (die
, objfile
, cu_header
);
1775 /* Get bit size of field (zero if none). */
1776 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1779 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1783 FIELD_BITSIZE (*fp
) = 0;
1786 /* Get bit offset of field. */
1787 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1790 FIELD_BITPOS (*fp
) =
1791 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
1794 FIELD_BITPOS (*fp
) = 0;
1795 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1798 if (BITS_BIG_ENDIAN
)
1800 /* For big endian bits, the DW_AT_bit_offset gives the
1801 additional bit offset from the MSB of the containing
1802 anonymous object to the MSB of the field. We don't
1803 have to do anything special since we don't need to
1804 know the size of the anonymous object. */
1805 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1809 /* For little endian bits, compute the bit offset to the
1810 MSB of the anonymous object, subtract off the number of
1811 bits from the MSB of the field to the MSB of the
1812 object, and then subtract off the number of bits of
1813 the field itself. The result is the bit offset of
1814 the LSB of the field. */
1816 int bit_offset
= DW_UNSND (attr
);
1818 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1821 /* The size of the anonymous object containing
1822 the bit field is explicit, so use the
1823 indicated size (in bytes). */
1824 anonymous_size
= DW_UNSND (attr
);
1828 /* The size of the anonymous object containing
1829 the bit field must be inferred from the type
1830 attribute of the data member containing the
1832 anonymous_size
= TYPE_LENGTH (fp
->type
);
1834 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1835 - bit_offset
- FIELD_BITSIZE (*fp
);
1839 /* Get name of field. */
1840 attr
= dwarf_attr (die
, DW_AT_name
);
1841 if (attr
&& DW_STRING (attr
))
1842 fieldname
= DW_STRING (attr
);
1843 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1844 &objfile
->type_obstack
);
1846 /* Change accessibility for artificial fields (e.g. virtual table
1847 pointer or virtual base class pointer) to private. */
1848 if (dwarf_attr (die
, DW_AT_artificial
))
1850 new_field
->accessibility
= DW_ACCESS_private
;
1851 fip
->non_public_fields
= 1;
1854 else if (die
->tag
== DW_TAG_variable
)
1858 /* C++ static member.
1859 Get name of field. */
1860 attr
= dwarf_attr (die
, DW_AT_name
);
1861 if (attr
&& DW_STRING (attr
))
1862 fieldname
= DW_STRING (attr
);
1866 /* Get physical name. */
1867 physname
= dwarf2_linkage_name (die
);
1869 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1870 &objfile
->type_obstack
));
1871 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1872 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1873 &objfile
->type_obstack
);
1875 else if (die
->tag
== DW_TAG_inheritance
)
1877 /* C++ base class field. */
1878 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1880 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
1882 FIELD_BITSIZE (*fp
) = 0;
1883 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1884 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1885 fip
->nbaseclasses
++;
1889 /* Create the vector of fields, and attach it to the type. */
1892 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
1893 struct objfile
*objfile
)
1895 int nfields
= fip
->nfields
;
1897 /* Record the field count, allocate space for the array of fields,
1898 and create blank accessibility bitfields if necessary. */
1899 TYPE_NFIELDS (type
) = nfields
;
1900 TYPE_FIELDS (type
) = (struct field
*)
1901 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1902 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1904 if (fip
->non_public_fields
)
1906 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1908 TYPE_FIELD_PRIVATE_BITS (type
) =
1909 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1910 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1912 TYPE_FIELD_PROTECTED_BITS (type
) =
1913 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1914 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1916 TYPE_FIELD_IGNORE_BITS (type
) =
1917 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1918 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1921 /* If the type has baseclasses, allocate and clear a bit vector for
1922 TYPE_FIELD_VIRTUAL_BITS. */
1923 if (fip
->nbaseclasses
)
1925 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
1928 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1929 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1930 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1931 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
1932 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
1935 /* Copy the saved-up fields into the field vector. Start from the head
1936 of the list, adding to the tail of the field array, so that they end
1937 up in the same order in the array in which they were added to the list. */
1938 while (nfields
-- > 0)
1940 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
1941 switch (fip
->fields
->accessibility
)
1943 case DW_ACCESS_private
:
1944 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
1947 case DW_ACCESS_protected
:
1948 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
1951 case DW_ACCESS_public
:
1955 /* Unknown accessibility. Complain and treat it as public. */
1957 complain (&dwarf2_unsupported_accessibility
,
1958 fip
->fields
->accessibility
);
1962 if (nfields
< fip
->nbaseclasses
)
1964 switch (fip
->fields
->virtuality
)
1966 case DW_VIRTUALITY_virtual
:
1967 case DW_VIRTUALITY_pure_virtual
:
1968 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
1972 fip
->fields
= fip
->fields
->next
;
1976 /* Add a member function to the proper fieldlist. */
1979 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
1980 struct type
*type
, struct objfile
*objfile
,
1981 const struct comp_unit_head
*cu_header
)
1983 struct attribute
*attr
;
1984 struct fnfieldlist
*flp
;
1986 struct fn_field
*fnp
;
1989 struct nextfnfield
*new_fnfield
;
1991 /* Get name of member function. */
1992 attr
= dwarf_attr (die
, DW_AT_name
);
1993 if (attr
&& DW_STRING (attr
))
1994 fieldname
= DW_STRING (attr
);
1998 /* Get the mangled name. */
1999 physname
= dwarf2_linkage_name (die
);
2001 /* Look up member function name in fieldlist. */
2002 for (i
= 0; i
< fip
->nfnfields
; i
++)
2004 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2008 /* Create new list element if necessary. */
2009 if (i
< fip
->nfnfields
)
2010 flp
= &fip
->fnfieldlists
[i
];
2013 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2015 fip
->fnfieldlists
= (struct fnfieldlist
*)
2016 xrealloc (fip
->fnfieldlists
,
2017 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2018 * sizeof (struct fnfieldlist
));
2019 if (fip
->nfnfields
== 0)
2020 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2022 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2023 flp
->name
= fieldname
;
2029 /* Create a new member function field and chain it to the field list
2031 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2032 make_cleanup (xfree
, new_fnfield
);
2033 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2034 new_fnfield
->next
= flp
->head
;
2035 flp
->head
= new_fnfield
;
2038 /* Fill in the member function field info. */
2039 fnp
= &new_fnfield
->fnfield
;
2040 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2041 &objfile
->type_obstack
);
2042 fnp
->type
= alloc_type (objfile
);
2043 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2045 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2046 struct type
**arg_types
;
2047 int nparams
= TYPE_NFIELDS (die
->type
);
2050 /* Copy argument types from the subroutine type. */
2051 arg_types
= (struct type
**)
2052 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2053 for (iparams
= 0; iparams
< nparams
; iparams
++)
2054 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2056 /* Set last entry in argument type vector. */
2057 if (TYPE_FLAGS (die
->type
) & TYPE_FLAG_VARARGS
)
2058 arg_types
[nparams
] = NULL
;
2060 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2062 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2064 /* Handle static member functions.
2065 Dwarf2 has no clean way to discern C++ static and non-static
2066 member functions. G++ helps GDB by marking the first
2067 parameter for non-static member functions (which is the
2068 this pointer) as artificial. We obtain this information
2069 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2070 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2071 fnp
->voffset
= VOFFSET_STATIC
;
2074 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2076 /* Get fcontext from DW_AT_containing_type if present. */
2077 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2078 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2080 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2081 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2083 /* Get accessibility. */
2084 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2087 switch (DW_UNSND (attr
))
2089 case DW_ACCESS_private
:
2090 fnp
->is_private
= 1;
2092 case DW_ACCESS_protected
:
2093 fnp
->is_protected
= 1;
2098 /* Get index in virtual function table if it is a virtual member function. */
2099 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2101 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2104 /* Create the vector of member function fields, and attach it to the type. */
2107 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2108 struct objfile
*objfile
)
2110 struct fnfieldlist
*flp
;
2111 int total_length
= 0;
2114 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2115 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2116 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2118 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2120 struct nextfnfield
*nfp
= flp
->head
;
2121 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2124 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2125 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2126 fn_flp
->fn_fields
= (struct fn_field
*)
2127 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2128 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2129 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2131 total_length
+= flp
->length
;
2134 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2135 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2138 /* Called when we find the DIE that starts a structure or union scope
2139 (definition) to process all dies that define the members of the
2142 NOTE: we need to call struct_type regardless of whether or not the
2143 DIE has an at_name attribute, since it might be an anonymous
2144 structure or union. This gets the type entered into our set of
2147 However, if the structure is incomplete (an opaque struct/union)
2148 then suppress creating a symbol table entry for it since gdb only
2149 wants to find the one with the complete definition. Note that if
2150 it is complete, we just call new_symbol, which does it's own
2151 checking about whether the struct/union is anonymous or not (and
2152 suppresses creating a symbol table entry itself). */
2155 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2156 const struct comp_unit_head
*cu_header
)
2159 struct attribute
*attr
;
2161 type
= alloc_type (objfile
);
2163 INIT_CPLUS_SPECIFIC (type
);
2164 attr
= dwarf_attr (die
, DW_AT_name
);
2165 if (attr
&& DW_STRING (attr
))
2167 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2168 strlen (DW_STRING (attr
)),
2169 &objfile
->type_obstack
);
2172 if (die
->tag
== DW_TAG_structure_type
)
2174 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2176 else if (die
->tag
== DW_TAG_union_type
)
2178 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2182 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2184 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2187 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2190 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2194 TYPE_LENGTH (type
) = 0;
2197 /* We need to add the type field to the die immediately so we don't
2198 infinitely recurse when dealing with pointers to the structure
2199 type within the structure itself. */
2202 if (die
->has_children
&& ! die_is_declaration (die
))
2204 struct field_info fi
;
2205 struct die_info
*child_die
;
2206 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2208 memset (&fi
, 0, sizeof (struct field_info
));
2210 child_die
= die
->next
;
2212 while (child_die
&& child_die
->tag
)
2214 if (child_die
->tag
== DW_TAG_member
)
2216 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2218 else if (child_die
->tag
== DW_TAG_variable
)
2220 /* C++ static member. */
2221 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2223 else if (child_die
->tag
== DW_TAG_subprogram
)
2225 /* C++ member function. */
2226 process_die (child_die
, objfile
, cu_header
);
2227 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2229 else if (child_die
->tag
== DW_TAG_inheritance
)
2231 /* C++ base class field. */
2232 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2236 process_die (child_die
, objfile
, cu_header
);
2238 child_die
= sibling_die (child_die
);
2241 /* Attach fields and member functions to the type. */
2243 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2246 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2248 /* Get the type which refers to the base class (possibly this
2249 class itself) which contains the vtable pointer for the current
2250 class from the DW_AT_containing_type attribute. */
2252 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2254 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2256 TYPE_VPTR_BASETYPE (type
) = t
;
2259 static const char vptr_name
[] =
2260 {'_', 'v', 'p', 't', 'r', '\0'};
2263 /* Our own class provides vtbl ptr. */
2264 for (i
= TYPE_NFIELDS (t
) - 1;
2265 i
>= TYPE_N_BASECLASSES (t
);
2268 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2270 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2271 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2273 TYPE_VPTR_FIELDNO (type
) = i
;
2278 /* Complain if virtual function table field not found. */
2279 if (i
< TYPE_N_BASECLASSES (t
))
2280 complain (&dwarf2_vtbl_not_found_complaint
,
2281 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2285 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2290 new_symbol (die
, type
, objfile
, cu_header
);
2292 do_cleanups (back_to
);
2296 /* No children, must be stub. */
2297 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2303 /* Given a pointer to a die which begins an enumeration, process all
2304 the dies that define the members of the enumeration.
2306 This will be much nicer in draft 6 of the DWARF spec when our
2307 members will be dies instead squished into the DW_AT_element_list
2310 NOTE: We reverse the order of the element list. */
2313 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2314 const struct comp_unit_head
*cu_header
)
2316 struct die_info
*child_die
;
2318 struct field
*fields
;
2319 struct attribute
*attr
;
2322 int unsigned_enum
= 1;
2324 type
= alloc_type (objfile
);
2326 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2327 attr
= dwarf_attr (die
, DW_AT_name
);
2328 if (attr
&& DW_STRING (attr
))
2330 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2331 strlen (DW_STRING (attr
)),
2332 &objfile
->type_obstack
);
2335 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2338 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2342 TYPE_LENGTH (type
) = 0;
2347 if (die
->has_children
)
2349 child_die
= die
->next
;
2350 while (child_die
&& child_die
->tag
)
2352 if (child_die
->tag
!= DW_TAG_enumerator
)
2354 process_die (child_die
, objfile
, cu_header
);
2358 attr
= dwarf_attr (child_die
, DW_AT_name
);
2361 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2362 if (SYMBOL_VALUE (sym
) < 0)
2365 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2367 fields
= (struct field
*)
2369 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2370 * sizeof (struct field
));
2373 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2374 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2375 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2376 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2382 child_die
= sibling_die (child_die
);
2387 TYPE_NFIELDS (type
) = num_fields
;
2388 TYPE_FIELDS (type
) = (struct field
*)
2389 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2390 memcpy (TYPE_FIELDS (type
), fields
,
2391 sizeof (struct field
) * num_fields
);
2395 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2398 new_symbol (die
, type
, objfile
, cu_header
);
2401 /* Extract all information from a DW_TAG_array_type DIE and put it in
2402 the DIE's type field. For now, this only handles one dimensional
2406 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
2407 const struct comp_unit_head
*cu_header
)
2409 struct die_info
*child_die
;
2410 struct type
*type
= NULL
;
2411 struct type
*element_type
, *range_type
, *index_type
;
2412 struct type
**range_types
= NULL
;
2413 struct attribute
*attr
;
2415 struct cleanup
*back_to
;
2417 /* Return if we've already decoded this type. */
2423 element_type
= die_type (die
, objfile
, cu_header
);
2425 /* Irix 6.2 native cc creates array types without children for
2426 arrays with unspecified length. */
2427 if (die
->has_children
== 0)
2429 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2430 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2431 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2435 back_to
= make_cleanup (null_cleanup
, NULL
);
2436 child_die
= die
->next
;
2437 while (child_die
&& child_die
->tag
)
2439 if (child_die
->tag
== DW_TAG_subrange_type
)
2441 unsigned int low
, high
;
2443 /* Default bounds to an array with unspecified length. */
2446 if (cu_language
== language_fortran
)
2448 /* FORTRAN implies a lower bound of 1, if not given. */
2452 index_type
= die_type (child_die
, objfile
, cu_header
);
2453 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2456 if (attr
->form
== DW_FORM_sdata
)
2458 low
= DW_SND (attr
);
2460 else if (attr
->form
== DW_FORM_udata
2461 || attr
->form
== DW_FORM_data1
2462 || attr
->form
== DW_FORM_data2
2463 || attr
->form
== DW_FORM_data4
)
2465 low
= DW_UNSND (attr
);
2469 complain (&dwarf2_non_const_array_bound_ignored
,
2470 dwarf_form_name (attr
->form
));
2472 die
->type
= lookup_pointer_type (element_type
);
2479 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2482 if (attr
->form
== DW_FORM_sdata
)
2484 high
= DW_SND (attr
);
2486 else if (attr
->form
== DW_FORM_udata
2487 || attr
->form
== DW_FORM_data1
2488 || attr
->form
== DW_FORM_data2
2489 || attr
->form
== DW_FORM_data4
)
2491 high
= DW_UNSND (attr
);
2493 else if (attr
->form
== DW_FORM_block1
)
2495 /* GCC encodes arrays with unspecified or dynamic length
2496 with a DW_FORM_block1 attribute.
2497 FIXME: GDB does not yet know how to handle dynamic
2498 arrays properly, treat them as arrays with unspecified
2504 complain (&dwarf2_non_const_array_bound_ignored
,
2505 dwarf_form_name (attr
->form
));
2507 die
->type
= lookup_pointer_type (element_type
);
2515 /* Create a range type and save it for array type creation. */
2516 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2518 range_types
= (struct type
**)
2519 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2520 * sizeof (struct type
*));
2522 make_cleanup (free_current_contents
, &range_types
);
2524 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2526 child_die
= sibling_die (child_die
);
2529 /* Dwarf2 dimensions are output from left to right, create the
2530 necessary array types in backwards order. */
2531 type
= element_type
;
2533 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2535 do_cleanups (back_to
);
2537 /* Install the type in the die. */
2541 /* First cut: install each common block member as a global variable. */
2544 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
2545 const struct comp_unit_head
*cu_header
)
2547 struct die_info
*child_die
;
2548 struct attribute
*attr
;
2550 CORE_ADDR base
= (CORE_ADDR
) 0;
2552 attr
= dwarf_attr (die
, DW_AT_location
);
2555 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2557 if (die
->has_children
)
2559 child_die
= die
->next
;
2560 while (child_die
&& child_die
->tag
)
2562 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
2563 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2566 SYMBOL_VALUE_ADDRESS (sym
) =
2567 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2568 add_symbol_to_list (sym
, &global_symbols
);
2570 child_die
= sibling_die (child_die
);
2575 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2576 the user defined type vector. */
2579 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
2580 const struct comp_unit_head
*cu_header
)
2583 struct attribute
*attr
;
2590 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
2591 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2594 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2598 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2603 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2604 the user defined type vector. */
2607 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
2608 const struct comp_unit_head
*cu_header
)
2611 struct type
*to_type
;
2612 struct type
*domain
;
2619 type
= alloc_type (objfile
);
2620 to_type
= die_type (die
, objfile
, cu_header
);
2621 domain
= die_containing_type (die
, objfile
, cu_header
);
2622 smash_to_member_type (type
, domain
, to_type
);
2627 /* Extract all information from a DW_TAG_reference_type DIE and add to
2628 the user defined type vector. */
2631 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
2632 const struct comp_unit_head
*cu_header
)
2635 struct attribute
*attr
;
2642 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
2643 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2646 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2650 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2656 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
2657 const struct comp_unit_head
*cu_header
)
2659 struct type
*base_type
;
2666 base_type
= die_type (die
, objfile
, cu_header
);
2667 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
2671 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
2672 const struct comp_unit_head
*cu_header
)
2674 struct type
*base_type
;
2681 base_type
= die_type (die
, objfile
, cu_header
);
2682 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
2685 /* Extract all information from a DW_TAG_string_type DIE and add to
2686 the user defined type vector. It isn't really a user defined type,
2687 but it behaves like one, with other DIE's using an AT_user_def_type
2688 attribute to reference it. */
2691 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
2693 struct type
*type
, *range_type
, *index_type
, *char_type
;
2694 struct attribute
*attr
;
2695 unsigned int length
;
2702 attr
= dwarf_attr (die
, DW_AT_string_length
);
2705 length
= DW_UNSND (attr
);
2711 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2712 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2713 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2714 type
= create_string_type (char_type
, range_type
);
2718 /* Handle DIES due to C code like:
2722 int (*funcp)(int a, long l);
2726 ('funcp' generates a DW_TAG_subroutine_type DIE)
2730 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
2731 const struct comp_unit_head
*cu_header
)
2733 struct type
*type
; /* Type that this function returns */
2734 struct type
*ftype
; /* Function that returns above type */
2735 struct attribute
*attr
;
2737 /* Decode the type that this subroutine returns */
2742 type
= die_type (die
, objfile
, cu_header
);
2743 ftype
= lookup_function_type (type
);
2745 /* All functions in C++ have prototypes. */
2746 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2747 if ((attr
&& (DW_UNSND (attr
) != 0))
2748 || cu_language
== language_cplus
)
2749 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2751 if (die
->has_children
)
2753 struct die_info
*child_die
;
2757 /* Count the number of parameters.
2758 FIXME: GDB currently ignores vararg functions, but knows about
2759 vararg member functions. */
2760 child_die
= die
->next
;
2761 while (child_die
&& child_die
->tag
)
2763 if (child_die
->tag
== DW_TAG_formal_parameter
)
2765 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2766 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2767 child_die
= sibling_die (child_die
);
2770 /* Allocate storage for parameters and fill them in. */
2771 TYPE_NFIELDS (ftype
) = nparams
;
2772 TYPE_FIELDS (ftype
) = (struct field
*)
2773 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2775 child_die
= die
->next
;
2776 while (child_die
&& child_die
->tag
)
2778 if (child_die
->tag
== DW_TAG_formal_parameter
)
2780 /* Dwarf2 has no clean way to discern C++ static and non-static
2781 member functions. G++ helps GDB by marking the first
2782 parameter for non-static member functions (which is the
2783 this pointer) as artificial. We pass this information
2784 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2785 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2787 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2789 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2790 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
2794 child_die
= sibling_die (child_die
);
2802 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
2803 const struct comp_unit_head
*cu_header
)
2809 struct attribute
*attr
;
2812 xtype
= die_type (die
, objfile
, cu_header
);
2814 type
= alloc_type (objfile
);
2815 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2816 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2817 TYPE_TARGET_TYPE (type
) = xtype
;
2818 attr
= dwarf_attr (die
, DW_AT_name
);
2819 if (attr
&& DW_STRING (attr
))
2820 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2821 strlen (DW_STRING (attr
)),
2822 &objfile
->type_obstack
);
2828 /* Find a representation of a given base type and install
2829 it in the TYPE field of the die. */
2832 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
2835 struct attribute
*attr
;
2836 int encoding
= 0, size
= 0;
2838 /* If we've already decoded this die, this is a no-op. */
2844 attr
= dwarf_attr (die
, DW_AT_encoding
);
2847 encoding
= DW_UNSND (attr
);
2849 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2852 size
= DW_UNSND (attr
);
2854 attr
= dwarf_attr (die
, DW_AT_name
);
2855 if (attr
&& DW_STRING (attr
))
2857 enum type_code code
= TYPE_CODE_INT
;
2858 int is_unsigned
= 0;
2862 case DW_ATE_address
:
2863 /* Turn DW_ATE_address into a void * pointer. */
2864 code
= TYPE_CODE_PTR
;
2867 case DW_ATE_boolean
:
2868 code
= TYPE_CODE_BOOL
;
2871 case DW_ATE_complex_float
:
2872 code
= TYPE_CODE_COMPLEX
;
2875 code
= TYPE_CODE_FLT
;
2878 case DW_ATE_signed_char
:
2880 case DW_ATE_unsigned
:
2881 case DW_ATE_unsigned_char
:
2885 complain (&dwarf2_unsupported_at_encoding
,
2886 dwarf_type_encoding_name (encoding
));
2889 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2890 if (encoding
== DW_ATE_address
)
2891 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2895 type
= dwarf_base_type (encoding
, size
, objfile
);
2900 /* Read a whole compilation unit into a linked list of dies. */
2903 read_comp_unit (char *info_ptr
, bfd
*abfd
,
2904 const struct comp_unit_head
*cu_header
)
2906 struct die_info
*first_die
, *last_die
, *die
;
2910 /* Reset die reference table; we are
2911 building new ones now. */
2912 dwarf2_empty_hash_tables ();
2916 first_die
= last_die
= NULL
;
2919 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
2920 if (die
->has_children
)
2931 /* Enter die in reference hash table */
2932 store_in_ref_table (die
->offset
, die
);
2936 first_die
= last_die
= die
;
2940 last_die
->next
= die
;
2944 while (nesting_level
> 0);
2948 /* Free a linked list of dies. */
2951 free_die_list (struct die_info
*dies
)
2953 struct die_info
*die
, *next
;
2966 do_free_die_list_cleanup (void *dies
)
2968 free_die_list (dies
);
2971 static struct cleanup
*
2972 make_cleanup_free_die_list (struct die_info
*dies
)
2974 return make_cleanup (do_free_die_list_cleanup
, dies
);
2978 /* Read the contents of the section at OFFSET and of size SIZE from the
2979 object file specified by OBJFILE into the psymbol_obstack and return it. */
2982 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
2985 bfd
*abfd
= objfile
->obfd
;
2991 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
2992 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
2993 (bfd_read (buf
, size
, 1, abfd
) != size
))
2996 error ("Dwarf Error: Can't read DWARF data from '%s'",
2997 bfd_get_filename (abfd
));
3002 /* In DWARF version 2, the description of the debugging information is
3003 stored in a separate .debug_abbrev section. Before we read any
3004 dies from a section we read in all abbreviations and install them
3008 dwarf2_read_abbrevs (bfd
*abfd
, unsigned int offset
)
3011 struct abbrev_info
*cur_abbrev
;
3012 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3013 unsigned int abbrev_form
, hash_number
;
3015 /* empty the table */
3016 dwarf2_empty_abbrev_table (NULL
);
3018 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3019 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3020 abbrev_ptr
+= bytes_read
;
3022 /* loop until we reach an abbrev number of 0 */
3023 while (abbrev_number
)
3025 cur_abbrev
= dwarf_alloc_abbrev ();
3027 /* read in abbrev header */
3028 cur_abbrev
->number
= abbrev_number
;
3029 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3030 abbrev_ptr
+= bytes_read
;
3031 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3034 /* now read in declarations */
3035 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3036 abbrev_ptr
+= bytes_read
;
3037 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3038 abbrev_ptr
+= bytes_read
;
3041 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3043 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3044 xrealloc (cur_abbrev
->attrs
,
3045 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3046 * sizeof (struct attr_abbrev
));
3048 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3049 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3050 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3051 abbrev_ptr
+= bytes_read
;
3052 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3053 abbrev_ptr
+= bytes_read
;
3056 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3057 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3058 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3060 /* Get next abbreviation.
3061 Under Irix6 the abbreviations for a compilation unit are not
3062 always properly terminated with an abbrev number of 0.
3063 Exit loop if we encounter an abbreviation which we have
3064 already read (which means we are about to read the abbreviations
3065 for the next compile unit) or if the end of the abbreviation
3066 table is reached. */
3067 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3068 >= dwarf_abbrev_size
)
3070 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3071 abbrev_ptr
+= bytes_read
;
3072 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3077 /* Empty the abbrev table for a new compilation unit. */
3081 dwarf2_empty_abbrev_table (PTR ignore
)
3084 struct abbrev_info
*abbrev
, *next
;
3086 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3089 abbrev
= dwarf2_abbrevs
[i
];
3092 next
= abbrev
->next
;
3093 xfree (abbrev
->attrs
);
3097 dwarf2_abbrevs
[i
] = NULL
;
3101 /* Lookup an abbrev_info structure in the abbrev hash table. */
3103 static struct abbrev_info
*
3104 dwarf2_lookup_abbrev (unsigned int number
)
3106 unsigned int hash_number
;
3107 struct abbrev_info
*abbrev
;
3109 hash_number
= number
% ABBREV_HASH_SIZE
;
3110 abbrev
= dwarf2_abbrevs
[hash_number
];
3114 if (abbrev
->number
== number
)
3117 abbrev
= abbrev
->next
;
3122 /* Read a minimal amount of information into the minimal die structure. */
3125 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3126 char *info_ptr
, int *has_pc_info
,
3127 const struct comp_unit_head
*cu_header
)
3129 unsigned int abbrev_number
, bytes_read
, i
;
3130 struct abbrev_info
*abbrev
;
3131 struct attribute attr
;
3132 struct attribute spec_attr
;
3133 int found_spec_attr
= 0;
3134 int has_low_pc_attr
= 0;
3135 int has_high_pc_attr
= 0;
3137 *part_die
= zeroed_partial_die
;
3139 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3140 info_ptr
+= bytes_read
;
3144 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3147 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3149 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3150 part_die
->tag
= abbrev
->tag
;
3151 part_die
->has_children
= abbrev
->has_children
;
3152 part_die
->abbrev
= abbrev_number
;
3154 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3156 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3157 info_ptr
, cu_header
);
3159 /* Store the data if it is of an attribute we want to keep in a
3160 partial symbol table. */
3165 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3166 if (part_die
->name
== NULL
)
3167 part_die
->name
= DW_STRING (&attr
);
3169 case DW_AT_MIPS_linkage_name
:
3170 part_die
->name
= DW_STRING (&attr
);
3173 has_low_pc_attr
= 1;
3174 part_die
->lowpc
= DW_ADDR (&attr
);
3177 has_high_pc_attr
= 1;
3178 part_die
->highpc
= DW_ADDR (&attr
);
3180 case DW_AT_location
:
3181 part_die
->locdesc
= DW_BLOCK (&attr
);
3183 case DW_AT_language
:
3184 part_die
->language
= DW_UNSND (&attr
);
3186 case DW_AT_external
:
3187 part_die
->is_external
= DW_UNSND (&attr
);
3189 case DW_AT_declaration
:
3190 part_die
->is_declaration
= DW_UNSND (&attr
);
3193 part_die
->has_type
= 1;
3195 case DW_AT_abstract_origin
:
3196 case DW_AT_specification
:
3197 found_spec_attr
= 1;
3201 /* Ignore absolute siblings, they might point outside of
3202 the current compile unit. */
3203 if (attr
.form
== DW_FORM_ref_addr
)
3204 complain (&dwarf2_absolute_sibling_complaint
);
3207 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3214 /* If we found a reference attribute and the die has no name, try
3215 to find a name in the referred to die. */
3217 if (found_spec_attr
&& part_die
->name
== NULL
)
3219 struct partial_die_info spec_die
;
3223 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3224 read_partial_die (&spec_die
, abfd
, spec_ptr
, &dummy
, cu_header
);
3227 part_die
->name
= spec_die
.name
;
3229 /* Copy DW_AT_external attribute if it is set. */
3230 if (spec_die
.is_external
)
3231 part_die
->is_external
= spec_die
.is_external
;
3235 /* When using the GNU linker, .gnu.linkonce. sections are used to
3236 eliminate duplicate copies of functions and vtables and such.
3237 The linker will arbitrarily choose one and discard the others.
3238 The AT_*_pc values for such functions refer to local labels in
3239 these sections. If the section from that file was discarded, the
3240 labels are not in the output, so the relocs get a value of 0.
3241 If this is a discarded function, mark the pc bounds as invalid,
3242 so that GDB will ignore it. */
3243 if (has_low_pc_attr
&& has_high_pc_attr
3244 && part_die
->lowpc
< part_die
->highpc
3245 && (part_die
->lowpc
!= 0
3246 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3251 /* Read the die from the .debug_info section buffer. And set diep to
3252 point to a newly allocated die with its information. */
3255 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3256 const struct comp_unit_head
*cu_header
)
3258 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3259 struct abbrev_info
*abbrev
;
3260 struct die_info
*die
;
3262 offset
= info_ptr
- dwarf_info_buffer
;
3263 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3264 info_ptr
+= bytes_read
;
3267 die
= dwarf_alloc_die ();
3269 die
->abbrev
= abbrev_number
;
3275 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3278 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3280 die
= dwarf_alloc_die ();
3281 die
->offset
= offset
;
3282 die
->tag
= abbrev
->tag
;
3283 die
->has_children
= abbrev
->has_children
;
3284 die
->abbrev
= abbrev_number
;
3287 die
->num_attrs
= abbrev
->num_attrs
;
3288 die
->attrs
= (struct attribute
*)
3289 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3291 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3293 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3294 abfd
, info_ptr
, cu_header
);
3301 /* Read an attribute described by an abbreviated attribute. */
3304 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
3305 bfd
*abfd
, char *info_ptr
,
3306 const struct comp_unit_head
*cu_header
)
3308 unsigned int bytes_read
;
3309 struct dwarf_block
*blk
;
3311 attr
->name
= abbrev
->name
;
3312 attr
->form
= abbrev
->form
;
3313 switch (abbrev
->form
)
3316 case DW_FORM_ref_addr
:
3317 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3318 info_ptr
+= bytes_read
;
3320 case DW_FORM_block2
:
3321 blk
= dwarf_alloc_block ();
3322 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3324 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3325 info_ptr
+= blk
->size
;
3326 DW_BLOCK (attr
) = blk
;
3328 case DW_FORM_block4
:
3329 blk
= dwarf_alloc_block ();
3330 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3332 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3333 info_ptr
+= blk
->size
;
3334 DW_BLOCK (attr
) = blk
;
3337 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3341 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3345 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3348 case DW_FORM_string
:
3349 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3350 info_ptr
+= bytes_read
;
3353 blk
= dwarf_alloc_block ();
3354 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3355 info_ptr
+= bytes_read
;
3356 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3357 info_ptr
+= blk
->size
;
3358 DW_BLOCK (attr
) = blk
;
3360 case DW_FORM_block1
:
3361 blk
= dwarf_alloc_block ();
3362 blk
->size
= read_1_byte (abfd
, info_ptr
);
3364 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3365 info_ptr
+= blk
->size
;
3366 DW_BLOCK (attr
) = blk
;
3369 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3373 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3377 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3378 info_ptr
+= bytes_read
;
3381 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3382 info_ptr
+= bytes_read
;
3385 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3389 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3393 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3397 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3400 case DW_FORM_ref_udata
:
3401 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3402 info_ptr
+= bytes_read
;
3405 case DW_FORM_indirect
:
3407 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3408 dwarf_form_name (abbrev
->form
));
3413 /* read dwarf information from a buffer */
3416 read_1_byte (bfd
*abfd
, char *buf
)
3418 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3422 read_1_signed_byte (bfd
*abfd
, char *buf
)
3424 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3428 read_2_bytes (bfd
*abfd
, char *buf
)
3430 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3434 read_2_signed_bytes (bfd
*abfd
, char *buf
)
3436 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3440 read_4_bytes (bfd
*abfd
, char *buf
)
3442 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3446 read_4_signed_bytes (bfd
*abfd
, char *buf
)
3448 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3451 static unsigned long
3452 read_8_bytes (bfd
*abfd
, char *buf
)
3454 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3458 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3461 CORE_ADDR retval
= 0;
3463 if (cu_header
->signed_addr_p
)
3465 switch (cu_header
->addr_size
)
3468 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3471 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3474 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
3477 internal_error (__FILE__
, __LINE__
,
3478 "read_address: bad switch, signed");
3483 switch (cu_header
->addr_size
)
3486 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3489 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3492 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3495 internal_error (__FILE__
, __LINE__
,
3496 "read_address: bad switch, unsigned");
3500 *bytes_read
= cu_header
->addr_size
;
3504 /* Reads the initial length from a section. The (draft) DWARF 2.1
3505 specification allows the initial length to take up either 4 bytes
3506 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
3507 bytes describe the length and all offsets will be 8 bytes in length
3510 The value returned via bytes_read should be used to increment
3511 the relevant pointer after calling read_initial_length().
3513 As a side effect, this function sets the fields initial_length_size
3514 and offset_size in cu_header to the values appropriate for the
3515 length field. (The format of the initial length field determines
3516 the width of file offsets to be fetched later with fetch_offset().)
3518 [ Note: read_initial_length() and read_offset() are based on the
3519 document entitled "DWARF Debugging Information Format", revision
3520 2.1, draft 4, dated July 20, 2000. This document was obtained
3523 http://reality.sgi.com/dehnert_engr/dwarf/dwarf2p1-draft4-000720.pdf
3525 This document is only a draft and is subject to change. (So beware.)
3527 - Kevin, Aug 4, 2000
3531 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
3536 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3538 if (retval
== 0xffffffff)
3540 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
3542 if (cu_header
!= NULL
)
3544 cu_header
->initial_length_size
= 12;
3545 cu_header
->offset_size
= 8;
3551 if (cu_header
!= NULL
)
3553 cu_header
->initial_length_size
= 4;
3554 cu_header
->offset_size
= 4;
3561 /* Read an offset from the data stream. The size of the offset is
3562 given by cu_header->offset_size. */
3565 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3570 switch (cu_header
->offset_size
)
3573 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3577 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3581 internal_error (__FILE__
, __LINE__
,
3582 "read_offset: bad switch");
3589 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
3591 /* If the size of a host char is 8 bits, we can return a pointer
3592 to the buffer, otherwise we have to copy the data to a buffer
3593 allocated on the temporary obstack. */
3594 #if HOST_CHAR_BIT == 8
3600 ret
= obstack_alloc (&dwarf2_tmp_obstack
, size
);
3601 for (i
= 0; i
< size
; ++i
)
3603 ret
[i
] = bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3611 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3613 /* If the size of a host char is 8 bits, we can return a pointer
3614 to the string, otherwise we have to copy the string to a buffer
3615 allocated on the temporary obstack. */
3616 #if HOST_CHAR_BIT == 8
3619 *bytes_read_ptr
= 1;
3622 *bytes_read_ptr
= strlen (buf
) + 1;
3628 while ((byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
)) != 0)
3630 obstack_1grow (&dwarf2_tmp_obstack
, byte
);
3636 *bytes_read_ptr
= 1;
3639 obstack_1grow (&dwarf2_tmp_obstack
, '\0');
3640 *bytes_read_ptr
= i
+ 1;
3641 return obstack_finish (&dwarf2_tmp_obstack
);
3645 static unsigned long
3646 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3648 unsigned long result
;
3649 unsigned int num_read
;
3659 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3662 result
|= ((unsigned long)(byte
& 127) << shift
);
3663 if ((byte
& 128) == 0)
3669 *bytes_read_ptr
= num_read
;
3674 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3677 int i
, shift
, size
, num_read
;
3687 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3690 result
|= ((long)(byte
& 127) << shift
);
3692 if ((byte
& 128) == 0)
3697 if ((shift
< size
) && (byte
& 0x40))
3699 result
|= -(1 << shift
);
3701 *bytes_read_ptr
= num_read
;
3706 set_cu_language (unsigned int lang
)
3712 cu_language
= language_c
;
3714 case DW_LANG_C_plus_plus
:
3715 cu_language
= language_cplus
;
3717 case DW_LANG_Fortran77
:
3718 case DW_LANG_Fortran90
:
3719 cu_language
= language_fortran
;
3721 case DW_LANG_Mips_Assembler
:
3722 cu_language
= language_asm
;
3725 case DW_LANG_Cobol74
:
3726 case DW_LANG_Cobol85
:
3727 case DW_LANG_Pascal83
:
3728 case DW_LANG_Modula2
:
3730 cu_language
= language_unknown
;
3733 cu_language_defn
= language_def (cu_language
);
3736 /* Return the named attribute or NULL if not there. */
3738 static struct attribute
*
3739 dwarf_attr (struct die_info
*die
, unsigned int name
)
3742 struct attribute
*spec
= NULL
;
3744 for (i
= 0; i
< die
->num_attrs
; ++i
)
3746 if (die
->attrs
[i
].name
== name
)
3748 return &die
->attrs
[i
];
3750 if (die
->attrs
[i
].name
== DW_AT_specification
3751 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3752 spec
= &die
->attrs
[i
];
3756 struct die_info
*ref_die
=
3757 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3760 return dwarf_attr (ref_die
, name
);
3767 die_is_declaration (struct die_info
*die
)
3769 return (dwarf_attr (die
, DW_AT_declaration
)
3770 && ! dwarf_attr (die
, DW_AT_specification
));
3773 /* Decode the line number information for the compilation unit whose
3774 line number info is at OFFSET in the .debug_line section.
3775 The compilation directory of the file is passed in COMP_DIR. */
3779 unsigned int num_files
;
3792 unsigned int num_dirs
;
3797 dwarf_decode_lines (unsigned int offset
, char *comp_dir
, bfd
*abfd
,
3798 const struct comp_unit_head
*cu_header
)
3802 struct line_head lh
;
3803 struct cleanup
*back_to
;
3804 unsigned int i
, bytes_read
;
3805 char *cur_file
, *cur_dir
;
3806 unsigned char op_code
, extended_op
, adj_opcode
;
3808 #define FILE_ALLOC_CHUNK 5
3809 #define DIR_ALLOC_CHUNK 5
3811 struct filenames files
;
3812 struct directories dirs
;
3814 if (dwarf_line_buffer
== NULL
)
3816 complain (&dwarf2_missing_line_number_section
);
3820 files
.num_files
= 0;
3826 line_ptr
= dwarf_line_buffer
+ offset
;
3828 /* read in the prologue */
3829 lh
.total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
3830 line_ptr
+= bytes_read
;
3831 line_end
= line_ptr
+ lh
.total_length
;
3832 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3834 lh
.prologue_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
3835 line_ptr
+= bytes_read
;
3836 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3838 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3840 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3842 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3844 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3846 lh
.standard_opcode_lengths
= (unsigned char *)
3847 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3848 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
3850 lh
.standard_opcode_lengths
[0] = 1;
3851 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3853 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3857 /* Read directory table */
3858 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3860 line_ptr
+= bytes_read
;
3861 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3863 dirs
.dirs
= (char **)
3864 xrealloc (dirs
.dirs
,
3865 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3866 if (dirs
.num_dirs
== 0)
3867 make_cleanup (free_current_contents
, &dirs
.dirs
);
3869 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3871 line_ptr
+= bytes_read
;
3873 /* Read file name table */
3874 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3876 line_ptr
+= bytes_read
;
3877 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3879 files
.files
= (struct fileinfo
*)
3880 xrealloc (files
.files
,
3881 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3882 * sizeof (struct fileinfo
));
3883 if (files
.num_files
== 0)
3884 make_cleanup (free_current_contents
, &files
.files
);
3886 files
.files
[files
.num_files
].name
= cur_file
;
3887 files
.files
[files
.num_files
].dir
=
3888 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3889 line_ptr
+= bytes_read
;
3890 files
.files
[files
.num_files
].time
=
3891 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3892 line_ptr
+= bytes_read
;
3893 files
.files
[files
.num_files
].size
=
3894 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3895 line_ptr
+= bytes_read
;
3898 line_ptr
+= bytes_read
;
3900 /* Read the statement sequences until there's nothing left. */
3901 while (line_ptr
< line_end
)
3903 /* state machine registers */
3904 CORE_ADDR address
= 0;
3905 unsigned int file
= 1;
3906 unsigned int line
= 1;
3907 unsigned int column
= 0;
3908 int is_stmt
= lh
.default_is_stmt
;
3909 int basic_block
= 0;
3910 int end_sequence
= 0;
3912 /* Start a subfile for the current file of the state machine. */
3913 if (files
.num_files
>= file
)
3915 /* The file and directory tables are 0 based, the references
3917 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3918 (files
.files
[file
- 1].dir
3919 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3923 /* Decode the table. */
3924 while (!end_sequence
)
3926 op_code
= read_1_byte (abfd
, line_ptr
);
3930 case DW_LNS_extended_op
:
3931 line_ptr
+= 1; /* ignore length */
3932 extended_op
= read_1_byte (abfd
, line_ptr
);
3934 switch (extended_op
)
3936 case DW_LNE_end_sequence
:
3938 /* Don't call record_line here. The end_sequence
3939 instruction provides the address of the first byte
3940 *after* the last line in the sequence; it's not the
3941 address of any real source line. However, the GDB
3942 linetable structure only records the starts of lines,
3943 not the ends. This is a weakness of GDB. */
3945 case DW_LNE_set_address
:
3946 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
3947 line_ptr
+= bytes_read
;
3948 address
+= baseaddr
;
3950 case DW_LNE_define_file
:
3951 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
3952 line_ptr
+= bytes_read
;
3953 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3955 files
.files
= (struct fileinfo
*)
3956 xrealloc (files
.files
,
3957 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3958 * sizeof (struct fileinfo
));
3959 if (files
.num_files
== 0)
3960 make_cleanup (free_current_contents
, &files
.files
);
3962 files
.files
[files
.num_files
].name
= cur_file
;
3963 files
.files
[files
.num_files
].dir
=
3964 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3965 line_ptr
+= bytes_read
;
3966 files
.files
[files
.num_files
].time
=
3967 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3968 line_ptr
+= bytes_read
;
3969 files
.files
[files
.num_files
].size
=
3970 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3971 line_ptr
+= bytes_read
;
3975 complain (&dwarf2_mangled_line_number_section
);
3980 record_line (current_subfile
, line
, address
);
3983 case DW_LNS_advance_pc
:
3984 address
+= lh
.minimum_instruction_length
3985 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3986 line_ptr
+= bytes_read
;
3988 case DW_LNS_advance_line
:
3989 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
3990 line_ptr
+= bytes_read
;
3992 case DW_LNS_set_file
:
3993 /* The file and directory tables are 0 based, the references
3995 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3996 line_ptr
+= bytes_read
;
3997 dwarf2_start_subfile
3998 (files
.files
[file
- 1].name
,
3999 (files
.files
[file
- 1].dir
4000 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
4003 case DW_LNS_set_column
:
4004 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4005 line_ptr
+= bytes_read
;
4007 case DW_LNS_negate_stmt
:
4008 is_stmt
= (!is_stmt
);
4010 case DW_LNS_set_basic_block
:
4013 /* Add to the address register of the state machine the
4014 address increment value corresponding to special opcode
4015 255. Ie, this value is scaled by the minimum instruction
4016 length since special opcode 255 would have scaled the
4018 case DW_LNS_const_add_pc
:
4019 address
+= (lh
.minimum_instruction_length
4020 * ((255 - lh
.opcode_base
) / lh
.line_range
));
4022 case DW_LNS_fixed_advance_pc
:
4023 address
+= read_2_bytes (abfd
, line_ptr
);
4026 default: /* special operand */
4027 adj_opcode
= op_code
- lh
.opcode_base
;
4028 address
+= (adj_opcode
/ lh
.line_range
)
4029 * lh
.minimum_instruction_length
;
4030 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
4031 /* append row to matrix using current values */
4032 record_line (current_subfile
, line
, address
);
4038 do_cleanups (back_to
);
4041 /* Start a subfile for DWARF. FILENAME is the name of the file and
4042 DIRNAME the name of the source directory which contains FILENAME
4043 or NULL if not known.
4044 This routine tries to keep line numbers from identical absolute and
4045 relative file names in a common subfile.
4047 Using the `list' example from the GDB testsuite, which resides in
4048 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4049 of /srcdir/list0.c yields the following debugging information for list0.c:
4051 DW_AT_name: /srcdir/list0.c
4052 DW_AT_comp_dir: /compdir
4053 files.files[0].name: list0.h
4054 files.files[0].dir: /srcdir
4055 files.files[1].name: list0.c
4056 files.files[1].dir: /srcdir
4058 The line number information for list0.c has to end up in a single
4059 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4062 dwarf2_start_subfile (char *filename
, char *dirname
)
4064 /* If the filename isn't absolute, try to match an existing subfile
4065 with the full pathname. */
4067 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
4069 struct subfile
*subfile
;
4070 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4072 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4074 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
4076 current_subfile
= subfile
;
4083 start_subfile (filename
, dirname
);
4086 /* Given a pointer to a DWARF information entry, figure out if we need
4087 to make a symbol table entry for it, and if so, create a new entry
4088 and return a pointer to it.
4089 If TYPE is NULL, determine symbol type from the die, otherwise
4090 used the passed type. */
4092 static struct symbol
*
4093 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
4094 const struct comp_unit_head
*cu_header
)
4096 struct symbol
*sym
= NULL
;
4098 struct attribute
*attr
= NULL
;
4099 struct attribute
*attr2
= NULL
;
4102 name
= dwarf2_linkage_name (die
);
4105 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4106 sizeof (struct symbol
));
4107 OBJSTAT (objfile
, n_syms
++);
4108 memset (sym
, 0, sizeof (struct symbol
));
4109 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4110 &objfile
->symbol_obstack
);
4112 /* Default assumptions.
4113 Use the passed type or decode it from the die. */
4114 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4115 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4117 SYMBOL_TYPE (sym
) = type
;
4119 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
4120 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4123 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4126 /* If this symbol is from a C++ compilation, then attempt to
4127 cache the demangled form for future reference. This is a
4128 typical time versus space tradeoff, that was decided in favor
4129 of time because it sped up C++ symbol lookups by a factor of
4132 SYMBOL_LANGUAGE (sym
) = cu_language
;
4133 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4137 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4140 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4142 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4144 case DW_TAG_subprogram
:
4145 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4147 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4148 attr2
= dwarf_attr (die
, DW_AT_external
);
4149 if (attr2
&& (DW_UNSND (attr2
) != 0))
4151 add_symbol_to_list (sym
, &global_symbols
);
4155 add_symbol_to_list (sym
, list_in_scope
);
4158 case DW_TAG_variable
:
4159 /* Compilation with minimal debug info may result in variables
4160 with missing type entries. Change the misleading `void' type
4161 to something sensible. */
4162 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4163 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4164 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4165 "<variable, no debug info>",
4167 attr
= dwarf_attr (die
, DW_AT_const_value
);
4170 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4171 attr2
= dwarf_attr (die
, DW_AT_external
);
4172 if (attr2
&& (DW_UNSND (attr2
) != 0))
4173 add_symbol_to_list (sym
, &global_symbols
);
4175 add_symbol_to_list (sym
, list_in_scope
);
4178 attr
= dwarf_attr (die
, DW_AT_location
);
4181 attr2
= dwarf_attr (die
, DW_AT_external
);
4182 if (attr2
&& (DW_UNSND (attr2
) != 0))
4184 SYMBOL_VALUE_ADDRESS (sym
) =
4185 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4186 add_symbol_to_list (sym
, &global_symbols
);
4188 /* In shared libraries the address of the variable
4189 in the location descriptor might still be relocatable,
4190 so its value could be zero.
4191 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4192 value is zero, the address of the variable will then
4193 be determined from the minimal symbol table whenever
4194 the variable is referenced. */
4195 if (SYMBOL_VALUE_ADDRESS (sym
))
4197 fixup_symbol_section (sym
, objfile
);
4198 SYMBOL_VALUE_ADDRESS (sym
) +=
4199 ANOFFSET (objfile
->section_offsets
,
4200 SYMBOL_SECTION (sym
));
4201 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4204 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4208 SYMBOL_VALUE (sym
) = addr
=
4209 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4210 add_symbol_to_list (sym
, list_in_scope
);
4213 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4217 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4218 SYMBOL_VALUE (sym
) =
4219 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4223 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4224 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4228 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4232 fixup_symbol_section (sym
, objfile
);
4233 SYMBOL_VALUE_ADDRESS (sym
) =
4234 addr
+ ANOFFSET (objfile
->section_offsets
,
4235 SYMBOL_SECTION (sym
));
4236 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4242 /* We do not know the address of this symbol.
4243 If it is an external symbol and we have type information
4244 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4245 The address of the variable will then be determined from
4246 the minimal symbol table whenever the variable is
4248 attr2
= dwarf_attr (die
, DW_AT_external
);
4249 if (attr2
&& (DW_UNSND (attr2
) != 0)
4250 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4252 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4253 add_symbol_to_list (sym
, &global_symbols
);
4257 case DW_TAG_formal_parameter
:
4258 attr
= dwarf_attr (die
, DW_AT_location
);
4261 SYMBOL_VALUE (sym
) =
4262 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4265 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4266 SYMBOL_VALUE (sym
) =
4267 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4273 if (basereg
!= frame_base_reg
)
4274 complain (&dwarf2_complex_location_expr
);
4275 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4279 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4280 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4285 SYMBOL_CLASS (sym
) = LOC_ARG
;
4288 attr
= dwarf_attr (die
, DW_AT_const_value
);
4291 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4293 add_symbol_to_list (sym
, list_in_scope
);
4295 case DW_TAG_unspecified_parameters
:
4296 /* From varargs functions; gdb doesn't seem to have any
4297 interest in this information, so just ignore it for now.
4300 case DW_TAG_class_type
:
4301 case DW_TAG_structure_type
:
4302 case DW_TAG_union_type
:
4303 case DW_TAG_enumeration_type
:
4304 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4305 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4306 add_symbol_to_list (sym
, list_in_scope
);
4308 /* The semantics of C++ state that "struct foo { ... }" also
4309 defines a typedef for "foo". Synthesize a typedef symbol so
4310 that "ptype foo" works as expected. */
4311 if (cu_language
== language_cplus
)
4313 struct symbol
*typedef_sym
= (struct symbol
*)
4314 obstack_alloc (&objfile
->symbol_obstack
,
4315 sizeof (struct symbol
));
4316 *typedef_sym
= *sym
;
4317 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4318 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4319 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4320 obsavestring (SYMBOL_NAME (sym
),
4321 strlen (SYMBOL_NAME (sym
)),
4322 &objfile
->type_obstack
);
4323 add_symbol_to_list (typedef_sym
, list_in_scope
);
4326 case DW_TAG_typedef
:
4327 case DW_TAG_base_type
:
4328 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4329 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4330 add_symbol_to_list (sym
, list_in_scope
);
4332 case DW_TAG_enumerator
:
4333 attr
= dwarf_attr (die
, DW_AT_const_value
);
4336 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4338 add_symbol_to_list (sym
, list_in_scope
);
4341 /* Not a tag we recognize. Hopefully we aren't processing
4342 trash data, but since we must specifically ignore things
4343 we don't recognize, there is nothing else we should do at
4345 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4352 /* Copy constant value from an attribute to a symbol. */
4355 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
4356 struct objfile
*objfile
,
4357 const struct comp_unit_head
*cu_header
)
4359 struct dwarf_block
*blk
;
4364 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
4365 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4366 cu_header
->addr_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4367 SYMBOL_VALUE_BYTES (sym
) = (char *)
4368 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
4369 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
4371 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4373 case DW_FORM_block1
:
4374 case DW_FORM_block2
:
4375 case DW_FORM_block4
:
4377 blk
= DW_BLOCK (attr
);
4378 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4379 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4380 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4381 SYMBOL_VALUE_BYTES (sym
) = (char *)
4382 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4383 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4384 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4387 /* The DW_AT_const_value attributes are supposed to carry the
4388 symbol's value "represented as it would be on the target
4389 architecture." By the time we get here, it's already been
4390 converted to host endianness, so we just need to sign- or
4391 zero-extend it as appropriate. */
4393 dwarf2_const_value_data (attr
, sym
, 8);
4396 dwarf2_const_value_data (attr
, sym
, 16);
4399 dwarf2_const_value_data (attr
, sym
, 32);
4402 dwarf2_const_value_data (attr
, sym
, 64);
4406 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4407 SYMBOL_CLASS (sym
) = LOC_CONST
;
4411 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4412 SYMBOL_CLASS (sym
) = LOC_CONST
;
4416 complain (&dwarf2_unsupported_const_value_attr
,
4417 dwarf_form_name (attr
->form
));
4418 SYMBOL_VALUE (sym
) = 0;
4419 SYMBOL_CLASS (sym
) = LOC_CONST
;
4425 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4426 or zero-extend it as appropriate for the symbol's type. */
4428 dwarf2_const_value_data (struct attribute
*attr
,
4432 LONGEST l
= DW_UNSND (attr
);
4434 if (bits
< sizeof (l
) * 8)
4436 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4437 l
&= ((LONGEST
) 1 << bits
) - 1;
4439 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4442 SYMBOL_VALUE (sym
) = l
;
4443 SYMBOL_CLASS (sym
) = LOC_CONST
;
4447 /* Return the type of the die in question using its DW_AT_type attribute. */
4449 static struct type
*
4450 die_type (struct die_info
*die
, struct objfile
*objfile
,
4451 const struct comp_unit_head
*cu_header
)
4454 struct attribute
*type_attr
;
4455 struct die_info
*type_die
;
4458 type_attr
= dwarf_attr (die
, DW_AT_type
);
4461 /* A missing DW_AT_type represents a void type. */
4462 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4466 ref
= dwarf2_get_ref_die_offset (type_attr
);
4467 type_die
= follow_die_ref (ref
);
4470 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4474 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4477 dump_die (type_die
);
4478 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4483 /* Return the containing type of the die in question using its
4484 DW_AT_containing_type attribute. */
4486 static struct type
*
4487 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
4488 const struct comp_unit_head
*cu_header
)
4490 struct type
*type
= NULL
;
4491 struct attribute
*type_attr
;
4492 struct die_info
*type_die
= NULL
;
4495 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4498 ref
= dwarf2_get_ref_die_offset (type_attr
);
4499 type_die
= follow_die_ref (ref
);
4502 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4505 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4510 dump_die (type_die
);
4511 error ("Dwarf Error: Problem turning containing type into gdb type.");
4517 static struct type
*
4518 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
4520 struct die_info
*die
;
4523 die
= follow_die_ref (offset
);
4526 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4529 type
= tag_type_to_type (die
, objfile
);
4534 static struct type
*
4535 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
4536 const struct comp_unit_head
*cu_header
)
4544 read_type_die (die
, objfile
, cu_header
);
4548 error ("Dwarf Error: Cannot find type of die.");
4555 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
4556 const struct comp_unit_head
*cu_header
)
4560 case DW_TAG_class_type
:
4561 case DW_TAG_structure_type
:
4562 case DW_TAG_union_type
:
4563 read_structure_scope (die
, objfile
, cu_header
);
4565 case DW_TAG_enumeration_type
:
4566 read_enumeration (die
, objfile
, cu_header
);
4568 case DW_TAG_subprogram
:
4569 case DW_TAG_subroutine_type
:
4570 read_subroutine_type (die
, objfile
, cu_header
);
4572 case DW_TAG_array_type
:
4573 read_array_type (die
, objfile
, cu_header
);
4575 case DW_TAG_pointer_type
:
4576 read_tag_pointer_type (die
, objfile
, cu_header
);
4578 case DW_TAG_ptr_to_member_type
:
4579 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
4581 case DW_TAG_reference_type
:
4582 read_tag_reference_type (die
, objfile
, cu_header
);
4584 case DW_TAG_const_type
:
4585 read_tag_const_type (die
, objfile
, cu_header
);
4587 case DW_TAG_volatile_type
:
4588 read_tag_volatile_type (die
, objfile
, cu_header
);
4590 case DW_TAG_string_type
:
4591 read_tag_string_type (die
, objfile
);
4593 case DW_TAG_typedef
:
4594 read_typedef (die
, objfile
, cu_header
);
4596 case DW_TAG_base_type
:
4597 read_base_type (die
, objfile
);
4600 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4605 static struct type
*
4606 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
4608 /* FIXME - this should not produce a new (struct type *)
4609 every time. It should cache base types. */
4613 case DW_ATE_address
:
4614 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4616 case DW_ATE_boolean
:
4617 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4619 case DW_ATE_complex_float
:
4622 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4626 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4632 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4636 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4643 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4646 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4650 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4654 case DW_ATE_signed_char
:
4655 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4657 case DW_ATE_unsigned
:
4661 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4664 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4668 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4672 case DW_ATE_unsigned_char
:
4673 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4676 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4683 copy_die (struct die_info
*old_die
)
4685 struct die_info
*new_die
;
4688 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4689 memset (new_die
, 0, sizeof (struct die_info
));
4691 new_die
->tag
= old_die
->tag
;
4692 new_die
->has_children
= old_die
->has_children
;
4693 new_die
->abbrev
= old_die
->abbrev
;
4694 new_die
->offset
= old_die
->offset
;
4695 new_die
->type
= NULL
;
4697 num_attrs
= old_die
->num_attrs
;
4698 new_die
->num_attrs
= num_attrs
;
4699 new_die
->attrs
= (struct attribute
*)
4700 xmalloc (num_attrs
* sizeof (struct attribute
));
4702 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4704 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4705 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4706 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4709 new_die
->next
= NULL
;
4714 /* Return sibling of die, NULL if no sibling. */
4717 sibling_die (struct die_info
*die
)
4719 int nesting_level
= 0;
4721 if (!die
->has_children
)
4723 if (die
->next
&& (die
->next
->tag
== 0))
4736 if (die
->has_children
)
4746 while (nesting_level
);
4747 if (die
&& (die
->tag
== 0))
4758 /* Get linkage name of a die, return NULL if not found. */
4761 dwarf2_linkage_name (struct die_info
*die
)
4763 struct attribute
*attr
;
4765 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4766 if (attr
&& DW_STRING (attr
))
4767 return DW_STRING (attr
);
4768 attr
= dwarf_attr (die
, DW_AT_name
);
4769 if (attr
&& DW_STRING (attr
))
4770 return DW_STRING (attr
);
4774 /* Convert a DIE tag into its string name. */
4777 dwarf_tag_name (register unsigned tag
)
4781 case DW_TAG_padding
:
4782 return "DW_TAG_padding";
4783 case DW_TAG_array_type
:
4784 return "DW_TAG_array_type";
4785 case DW_TAG_class_type
:
4786 return "DW_TAG_class_type";
4787 case DW_TAG_entry_point
:
4788 return "DW_TAG_entry_point";
4789 case DW_TAG_enumeration_type
:
4790 return "DW_TAG_enumeration_type";
4791 case DW_TAG_formal_parameter
:
4792 return "DW_TAG_formal_parameter";
4793 case DW_TAG_imported_declaration
:
4794 return "DW_TAG_imported_declaration";
4796 return "DW_TAG_label";
4797 case DW_TAG_lexical_block
:
4798 return "DW_TAG_lexical_block";
4800 return "DW_TAG_member";
4801 case DW_TAG_pointer_type
:
4802 return "DW_TAG_pointer_type";
4803 case DW_TAG_reference_type
:
4804 return "DW_TAG_reference_type";
4805 case DW_TAG_compile_unit
:
4806 return "DW_TAG_compile_unit";
4807 case DW_TAG_string_type
:
4808 return "DW_TAG_string_type";
4809 case DW_TAG_structure_type
:
4810 return "DW_TAG_structure_type";
4811 case DW_TAG_subroutine_type
:
4812 return "DW_TAG_subroutine_type";
4813 case DW_TAG_typedef
:
4814 return "DW_TAG_typedef";
4815 case DW_TAG_union_type
:
4816 return "DW_TAG_union_type";
4817 case DW_TAG_unspecified_parameters
:
4818 return "DW_TAG_unspecified_parameters";
4819 case DW_TAG_variant
:
4820 return "DW_TAG_variant";
4821 case DW_TAG_common_block
:
4822 return "DW_TAG_common_block";
4823 case DW_TAG_common_inclusion
:
4824 return "DW_TAG_common_inclusion";
4825 case DW_TAG_inheritance
:
4826 return "DW_TAG_inheritance";
4827 case DW_TAG_inlined_subroutine
:
4828 return "DW_TAG_inlined_subroutine";
4830 return "DW_TAG_module";
4831 case DW_TAG_ptr_to_member_type
:
4832 return "DW_TAG_ptr_to_member_type";
4833 case DW_TAG_set_type
:
4834 return "DW_TAG_set_type";
4835 case DW_TAG_subrange_type
:
4836 return "DW_TAG_subrange_type";
4837 case DW_TAG_with_stmt
:
4838 return "DW_TAG_with_stmt";
4839 case DW_TAG_access_declaration
:
4840 return "DW_TAG_access_declaration";
4841 case DW_TAG_base_type
:
4842 return "DW_TAG_base_type";
4843 case DW_TAG_catch_block
:
4844 return "DW_TAG_catch_block";
4845 case DW_TAG_const_type
:
4846 return "DW_TAG_const_type";
4847 case DW_TAG_constant
:
4848 return "DW_TAG_constant";
4849 case DW_TAG_enumerator
:
4850 return "DW_TAG_enumerator";
4851 case DW_TAG_file_type
:
4852 return "DW_TAG_file_type";
4854 return "DW_TAG_friend";
4855 case DW_TAG_namelist
:
4856 return "DW_TAG_namelist";
4857 case DW_TAG_namelist_item
:
4858 return "DW_TAG_namelist_item";
4859 case DW_TAG_packed_type
:
4860 return "DW_TAG_packed_type";
4861 case DW_TAG_subprogram
:
4862 return "DW_TAG_subprogram";
4863 case DW_TAG_template_type_param
:
4864 return "DW_TAG_template_type_param";
4865 case DW_TAG_template_value_param
:
4866 return "DW_TAG_template_value_param";
4867 case DW_TAG_thrown_type
:
4868 return "DW_TAG_thrown_type";
4869 case DW_TAG_try_block
:
4870 return "DW_TAG_try_block";
4871 case DW_TAG_variant_part
:
4872 return "DW_TAG_variant_part";
4873 case DW_TAG_variable
:
4874 return "DW_TAG_variable";
4875 case DW_TAG_volatile_type
:
4876 return "DW_TAG_volatile_type";
4877 case DW_TAG_MIPS_loop
:
4878 return "DW_TAG_MIPS_loop";
4879 case DW_TAG_format_label
:
4880 return "DW_TAG_format_label";
4881 case DW_TAG_function_template
:
4882 return "DW_TAG_function_template";
4883 case DW_TAG_class_template
:
4884 return "DW_TAG_class_template";
4886 return "DW_TAG_<unknown>";
4890 /* Convert a DWARF attribute code into its string name. */
4893 dwarf_attr_name (register unsigned attr
)
4898 return "DW_AT_sibling";
4899 case DW_AT_location
:
4900 return "DW_AT_location";
4902 return "DW_AT_name";
4903 case DW_AT_ordering
:
4904 return "DW_AT_ordering";
4905 case DW_AT_subscr_data
:
4906 return "DW_AT_subscr_data";
4907 case DW_AT_byte_size
:
4908 return "DW_AT_byte_size";
4909 case DW_AT_bit_offset
:
4910 return "DW_AT_bit_offset";
4911 case DW_AT_bit_size
:
4912 return "DW_AT_bit_size";
4913 case DW_AT_element_list
:
4914 return "DW_AT_element_list";
4915 case DW_AT_stmt_list
:
4916 return "DW_AT_stmt_list";
4918 return "DW_AT_low_pc";
4920 return "DW_AT_high_pc";
4921 case DW_AT_language
:
4922 return "DW_AT_language";
4924 return "DW_AT_member";
4926 return "DW_AT_discr";
4927 case DW_AT_discr_value
:
4928 return "DW_AT_discr_value";
4929 case DW_AT_visibility
:
4930 return "DW_AT_visibility";
4932 return "DW_AT_import";
4933 case DW_AT_string_length
:
4934 return "DW_AT_string_length";
4935 case DW_AT_common_reference
:
4936 return "DW_AT_common_reference";
4937 case DW_AT_comp_dir
:
4938 return "DW_AT_comp_dir";
4939 case DW_AT_const_value
:
4940 return "DW_AT_const_value";
4941 case DW_AT_containing_type
:
4942 return "DW_AT_containing_type";
4943 case DW_AT_default_value
:
4944 return "DW_AT_default_value";
4946 return "DW_AT_inline";
4947 case DW_AT_is_optional
:
4948 return "DW_AT_is_optional";
4949 case DW_AT_lower_bound
:
4950 return "DW_AT_lower_bound";
4951 case DW_AT_producer
:
4952 return "DW_AT_producer";
4953 case DW_AT_prototyped
:
4954 return "DW_AT_prototyped";
4955 case DW_AT_return_addr
:
4956 return "DW_AT_return_addr";
4957 case DW_AT_start_scope
:
4958 return "DW_AT_start_scope";
4959 case DW_AT_stride_size
:
4960 return "DW_AT_stride_size";
4961 case DW_AT_upper_bound
:
4962 return "DW_AT_upper_bound";
4963 case DW_AT_abstract_origin
:
4964 return "DW_AT_abstract_origin";
4965 case DW_AT_accessibility
:
4966 return "DW_AT_accessibility";
4967 case DW_AT_address_class
:
4968 return "DW_AT_address_class";
4969 case DW_AT_artificial
:
4970 return "DW_AT_artificial";
4971 case DW_AT_base_types
:
4972 return "DW_AT_base_types";
4973 case DW_AT_calling_convention
:
4974 return "DW_AT_calling_convention";
4976 return "DW_AT_count";
4977 case DW_AT_data_member_location
:
4978 return "DW_AT_data_member_location";
4979 case DW_AT_decl_column
:
4980 return "DW_AT_decl_column";
4981 case DW_AT_decl_file
:
4982 return "DW_AT_decl_file";
4983 case DW_AT_decl_line
:
4984 return "DW_AT_decl_line";
4985 case DW_AT_declaration
:
4986 return "DW_AT_declaration";
4987 case DW_AT_discr_list
:
4988 return "DW_AT_discr_list";
4989 case DW_AT_encoding
:
4990 return "DW_AT_encoding";
4991 case DW_AT_external
:
4992 return "DW_AT_external";
4993 case DW_AT_frame_base
:
4994 return "DW_AT_frame_base";
4996 return "DW_AT_friend";
4997 case DW_AT_identifier_case
:
4998 return "DW_AT_identifier_case";
4999 case DW_AT_macro_info
:
5000 return "DW_AT_macro_info";
5001 case DW_AT_namelist_items
:
5002 return "DW_AT_namelist_items";
5003 case DW_AT_priority
:
5004 return "DW_AT_priority";
5006 return "DW_AT_segment";
5007 case DW_AT_specification
:
5008 return "DW_AT_specification";
5009 case DW_AT_static_link
:
5010 return "DW_AT_static_link";
5012 return "DW_AT_type";
5013 case DW_AT_use_location
:
5014 return "DW_AT_use_location";
5015 case DW_AT_variable_parameter
:
5016 return "DW_AT_variable_parameter";
5017 case DW_AT_virtuality
:
5018 return "DW_AT_virtuality";
5019 case DW_AT_vtable_elem_location
:
5020 return "DW_AT_vtable_elem_location";
5023 case DW_AT_MIPS_fde
:
5024 return "DW_AT_MIPS_fde";
5025 case DW_AT_MIPS_loop_begin
:
5026 return "DW_AT_MIPS_loop_begin";
5027 case DW_AT_MIPS_tail_loop_begin
:
5028 return "DW_AT_MIPS_tail_loop_begin";
5029 case DW_AT_MIPS_epilog_begin
:
5030 return "DW_AT_MIPS_epilog_begin";
5031 case DW_AT_MIPS_loop_unroll_factor
:
5032 return "DW_AT_MIPS_loop_unroll_factor";
5033 case DW_AT_MIPS_software_pipeline_depth
:
5034 return "DW_AT_MIPS_software_pipeline_depth";
5035 case DW_AT_MIPS_linkage_name
:
5036 return "DW_AT_MIPS_linkage_name";
5039 case DW_AT_sf_names
:
5040 return "DW_AT_sf_names";
5041 case DW_AT_src_info
:
5042 return "DW_AT_src_info";
5043 case DW_AT_mac_info
:
5044 return "DW_AT_mac_info";
5045 case DW_AT_src_coords
:
5046 return "DW_AT_src_coords";
5047 case DW_AT_body_begin
:
5048 return "DW_AT_body_begin";
5049 case DW_AT_body_end
:
5050 return "DW_AT_body_end";
5052 return "DW_AT_<unknown>";
5056 /* Convert a DWARF value form code into its string name. */
5059 dwarf_form_name (register unsigned form
)
5064 return "DW_FORM_addr";
5065 case DW_FORM_block2
:
5066 return "DW_FORM_block2";
5067 case DW_FORM_block4
:
5068 return "DW_FORM_block4";
5070 return "DW_FORM_data2";
5072 return "DW_FORM_data4";
5074 return "DW_FORM_data8";
5075 case DW_FORM_string
:
5076 return "DW_FORM_string";
5078 return "DW_FORM_block";
5079 case DW_FORM_block1
:
5080 return "DW_FORM_block1";
5082 return "DW_FORM_data1";
5084 return "DW_FORM_flag";
5086 return "DW_FORM_sdata";
5088 return "DW_FORM_strp";
5090 return "DW_FORM_udata";
5091 case DW_FORM_ref_addr
:
5092 return "DW_FORM_ref_addr";
5094 return "DW_FORM_ref1";
5096 return "DW_FORM_ref2";
5098 return "DW_FORM_ref4";
5100 return "DW_FORM_ref8";
5101 case DW_FORM_ref_udata
:
5102 return "DW_FORM_ref_udata";
5103 case DW_FORM_indirect
:
5104 return "DW_FORM_indirect";
5106 return "DW_FORM_<unknown>";
5110 /* Convert a DWARF stack opcode into its string name. */
5113 dwarf_stack_op_name (register unsigned op
)
5118 return "DW_OP_addr";
5120 return "DW_OP_deref";
5122 return "DW_OP_const1u";
5124 return "DW_OP_const1s";
5126 return "DW_OP_const2u";
5128 return "DW_OP_const2s";
5130 return "DW_OP_const4u";
5132 return "DW_OP_const4s";
5134 return "DW_OP_const8u";
5136 return "DW_OP_const8s";
5138 return "DW_OP_constu";
5140 return "DW_OP_consts";
5144 return "DW_OP_drop";
5146 return "DW_OP_over";
5148 return "DW_OP_pick";
5150 return "DW_OP_swap";
5154 return "DW_OP_xderef";
5162 return "DW_OP_minus";
5174 return "DW_OP_plus";
5175 case DW_OP_plus_uconst
:
5176 return "DW_OP_plus_uconst";
5182 return "DW_OP_shra";
5200 return "DW_OP_skip";
5202 return "DW_OP_lit0";
5204 return "DW_OP_lit1";
5206 return "DW_OP_lit2";
5208 return "DW_OP_lit3";
5210 return "DW_OP_lit4";
5212 return "DW_OP_lit5";
5214 return "DW_OP_lit6";
5216 return "DW_OP_lit7";
5218 return "DW_OP_lit8";
5220 return "DW_OP_lit9";
5222 return "DW_OP_lit10";
5224 return "DW_OP_lit11";
5226 return "DW_OP_lit12";
5228 return "DW_OP_lit13";
5230 return "DW_OP_lit14";
5232 return "DW_OP_lit15";
5234 return "DW_OP_lit16";
5236 return "DW_OP_lit17";
5238 return "DW_OP_lit18";
5240 return "DW_OP_lit19";
5242 return "DW_OP_lit20";
5244 return "DW_OP_lit21";
5246 return "DW_OP_lit22";
5248 return "DW_OP_lit23";
5250 return "DW_OP_lit24";
5252 return "DW_OP_lit25";
5254 return "DW_OP_lit26";
5256 return "DW_OP_lit27";
5258 return "DW_OP_lit28";
5260 return "DW_OP_lit29";
5262 return "DW_OP_lit30";
5264 return "DW_OP_lit31";
5266 return "DW_OP_reg0";
5268 return "DW_OP_reg1";
5270 return "DW_OP_reg2";
5272 return "DW_OP_reg3";
5274 return "DW_OP_reg4";
5276 return "DW_OP_reg5";
5278 return "DW_OP_reg6";
5280 return "DW_OP_reg7";
5282 return "DW_OP_reg8";
5284 return "DW_OP_reg9";
5286 return "DW_OP_reg10";
5288 return "DW_OP_reg11";
5290 return "DW_OP_reg12";
5292 return "DW_OP_reg13";
5294 return "DW_OP_reg14";
5296 return "DW_OP_reg15";
5298 return "DW_OP_reg16";
5300 return "DW_OP_reg17";
5302 return "DW_OP_reg18";
5304 return "DW_OP_reg19";
5306 return "DW_OP_reg20";
5308 return "DW_OP_reg21";
5310 return "DW_OP_reg22";
5312 return "DW_OP_reg23";
5314 return "DW_OP_reg24";
5316 return "DW_OP_reg25";
5318 return "DW_OP_reg26";
5320 return "DW_OP_reg27";
5322 return "DW_OP_reg28";
5324 return "DW_OP_reg29";
5326 return "DW_OP_reg30";
5328 return "DW_OP_reg31";
5330 return "DW_OP_breg0";
5332 return "DW_OP_breg1";
5334 return "DW_OP_breg2";
5336 return "DW_OP_breg3";
5338 return "DW_OP_breg4";
5340 return "DW_OP_breg5";
5342 return "DW_OP_breg6";
5344 return "DW_OP_breg7";
5346 return "DW_OP_breg8";
5348 return "DW_OP_breg9";
5350 return "DW_OP_breg10";
5352 return "DW_OP_breg11";
5354 return "DW_OP_breg12";
5356 return "DW_OP_breg13";
5358 return "DW_OP_breg14";
5360 return "DW_OP_breg15";
5362 return "DW_OP_breg16";
5364 return "DW_OP_breg17";
5366 return "DW_OP_breg18";
5368 return "DW_OP_breg19";
5370 return "DW_OP_breg20";
5372 return "DW_OP_breg21";
5374 return "DW_OP_breg22";
5376 return "DW_OP_breg23";
5378 return "DW_OP_breg24";
5380 return "DW_OP_breg25";
5382 return "DW_OP_breg26";
5384 return "DW_OP_breg27";
5386 return "DW_OP_breg28";
5388 return "DW_OP_breg29";
5390 return "DW_OP_breg30";
5392 return "DW_OP_breg31";
5394 return "DW_OP_regx";
5396 return "DW_OP_fbreg";
5398 return "DW_OP_bregx";
5400 return "DW_OP_piece";
5401 case DW_OP_deref_size
:
5402 return "DW_OP_deref_size";
5403 case DW_OP_xderef_size
:
5404 return "DW_OP_xderef_size";
5408 return "OP_<unknown>";
5413 dwarf_bool_name (unsigned mybool
)
5421 /* Convert a DWARF type code into its string name. */
5424 dwarf_type_encoding_name (register unsigned enc
)
5428 case DW_ATE_address
:
5429 return "DW_ATE_address";
5430 case DW_ATE_boolean
:
5431 return "DW_ATE_boolean";
5432 case DW_ATE_complex_float
:
5433 return "DW_ATE_complex_float";
5435 return "DW_ATE_float";
5437 return "DW_ATE_signed";
5438 case DW_ATE_signed_char
:
5439 return "DW_ATE_signed_char";
5440 case DW_ATE_unsigned
:
5441 return "DW_ATE_unsigned";
5442 case DW_ATE_unsigned_char
:
5443 return "DW_ATE_unsigned_char";
5445 return "DW_ATE_<unknown>";
5449 /* Convert a DWARF call frame info operation to its string name. */
5453 dwarf_cfi_name (register unsigned cfi_opc
)
5457 case DW_CFA_advance_loc
:
5458 return "DW_CFA_advance_loc";
5460 return "DW_CFA_offset";
5461 case DW_CFA_restore
:
5462 return "DW_CFA_restore";
5464 return "DW_CFA_nop";
5465 case DW_CFA_set_loc
:
5466 return "DW_CFA_set_loc";
5467 case DW_CFA_advance_loc1
:
5468 return "DW_CFA_advance_loc1";
5469 case DW_CFA_advance_loc2
:
5470 return "DW_CFA_advance_loc2";
5471 case DW_CFA_advance_loc4
:
5472 return "DW_CFA_advance_loc4";
5473 case DW_CFA_offset_extended
:
5474 return "DW_CFA_offset_extended";
5475 case DW_CFA_restore_extended
:
5476 return "DW_CFA_restore_extended";
5477 case DW_CFA_undefined
:
5478 return "DW_CFA_undefined";
5479 case DW_CFA_same_value
:
5480 return "DW_CFA_same_value";
5481 case DW_CFA_register
:
5482 return "DW_CFA_register";
5483 case DW_CFA_remember_state
:
5484 return "DW_CFA_remember_state";
5485 case DW_CFA_restore_state
:
5486 return "DW_CFA_restore_state";
5487 case DW_CFA_def_cfa
:
5488 return "DW_CFA_def_cfa";
5489 case DW_CFA_def_cfa_register
:
5490 return "DW_CFA_def_cfa_register";
5491 case DW_CFA_def_cfa_offset
:
5492 return "DW_CFA_def_cfa_offset";
5493 /* SGI/MIPS specific */
5494 case DW_CFA_MIPS_advance_loc8
:
5495 return "DW_CFA_MIPS_advance_loc8";
5497 return "DW_CFA_<unknown>";
5503 dump_die (struct die_info
*die
)
5507 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5508 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5509 fprintf (stderr
, "\thas children: %s\n",
5510 dwarf_bool_name (die
->has_children
));
5512 fprintf (stderr
, "\tattributes:\n");
5513 for (i
= 0; i
< die
->num_attrs
; ++i
)
5515 fprintf (stderr
, "\t\t%s (%s) ",
5516 dwarf_attr_name (die
->attrs
[i
].name
),
5517 dwarf_form_name (die
->attrs
[i
].form
));
5518 switch (die
->attrs
[i
].form
)
5520 case DW_FORM_ref_addr
:
5522 fprintf (stderr
, "address: ");
5523 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5525 case DW_FORM_block2
:
5526 case DW_FORM_block4
:
5528 case DW_FORM_block1
:
5529 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5540 fprintf (stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
5542 case DW_FORM_string
:
5543 fprintf (stderr
, "string: \"%s\"",
5544 DW_STRING (&die
->attrs
[i
])
5545 ? DW_STRING (&die
->attrs
[i
]) : "");
5548 if (DW_UNSND (&die
->attrs
[i
]))
5549 fprintf (stderr
, "flag: TRUE");
5551 fprintf (stderr
, "flag: FALSE");
5553 case DW_FORM_strp
: /* we do not support separate string
5555 case DW_FORM_indirect
: /* we do not handle indirect yet */
5557 fprintf (stderr
, "unsupported attribute form: %d.",
5558 die
->attrs
[i
].form
);
5560 fprintf (stderr
, "\n");
5565 dump_die_list (struct die_info
*die
)
5575 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
5578 struct die_info
*old
;
5580 h
= (offset
% REF_HASH_SIZE
);
5581 old
= die_ref_table
[h
];
5582 die
->next_ref
= old
;
5583 die_ref_table
[h
] = die
;
5588 dwarf2_empty_hash_tables (void)
5590 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5594 dwarf2_get_ref_die_offset (struct attribute
*attr
)
5596 unsigned int result
= 0;
5600 case DW_FORM_ref_addr
:
5601 result
= DW_ADDR (attr
);
5607 case DW_FORM_ref_udata
:
5608 result
= cu_header_offset
+ DW_UNSND (attr
);
5611 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5617 follow_die_ref (unsigned int offset
)
5619 struct die_info
*die
;
5622 h
= (offset
% REF_HASH_SIZE
);
5623 die
= die_ref_table
[h
];
5626 if (die
->offset
== offset
)
5630 die
= die
->next_ref
;
5635 static struct type
*
5636 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
5638 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5640 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5644 /* Look for this particular type in the fundamental type vector. If
5645 one is not found, create and install one appropriate for the
5646 current language and the current target machine. */
5648 if (ftypes
[typeid] == NULL
)
5650 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5653 return (ftypes
[typeid]);
5656 /* Decode simple location descriptions.
5657 Given a pointer to a dwarf block that defines a location, compute
5658 the location and return the value.
5660 FIXME: This is a kludge until we figure out a better
5661 way to handle the location descriptions.
5662 Gdb's design does not mesh well with the DWARF2 notion of a location
5663 computing interpreter, which is a shame because the flexibility goes unused.
5664 FIXME: Implement more operations as necessary.
5666 A location description containing no operations indicates that the
5667 object is optimized out. The global optimized_out flag is set for
5668 those, the return value is meaningless.
5670 When the result is a register number, the global isreg flag is set,
5671 otherwise it is cleared.
5673 When the result is a base register offset, the global offreg flag is set
5674 and the register number is returned in basereg, otherwise it is cleared.
5676 When the DW_OP_fbreg operation is encountered without a corresponding
5677 DW_AT_frame_base attribute, the global islocal flag is set.
5678 Hopefully the machine dependent code knows how to set up a virtual
5679 frame pointer for the local references.
5681 Note that stack[0] is unused except as a default error return.
5682 Note that stack overflow is not yet handled. */
5685 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
5686 const struct comp_unit_head
*cu_header
)
5689 int size
= blk
->size
;
5690 char *data
= blk
->data
;
5691 CORE_ADDR stack
[64];
5693 unsigned int bytes_read
, unsnd
;
5744 stack
[++stacki
] = op
- DW_OP_reg0
;
5749 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5751 #if defined(HARRIS_TARGET) && defined(_M88K)
5752 /* The Harris 88110 gdb ports have long kept their special reg
5753 numbers between their gp-regs and their x-regs. This is
5754 not how our dwarf is generated. Punt. */
5757 stack
[++stacki
] = unsnd
;
5793 basereg
= op
- DW_OP_breg0
;
5794 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5800 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5802 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5807 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5809 if (frame_base_reg
>= 0)
5812 basereg
= frame_base_reg
;
5813 stack
[stacki
] += frame_base_offset
;
5817 complain (&dwarf2_missing_at_frame_base
);
5823 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
5824 cu_header
, &bytes_read
);
5829 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5834 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5839 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5844 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5849 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5854 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5859 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5865 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5870 stack
[stacki
- 1] += stack
[stacki
];
5874 case DW_OP_plus_uconst
:
5875 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5880 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5886 /* If we're not the last op, then we definitely can't encode
5887 this using GDB's address_class enum. */
5889 complain (&dwarf2_complex_location_expr
);
5893 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
5894 return (stack
[stacki
]);
5897 return (stack
[stacki
]);
5900 /* memory allocation interface */
5904 dwarf2_free_tmp_obstack (PTR ignore
)
5906 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5909 static struct dwarf_block
*
5910 dwarf_alloc_block (void)
5912 struct dwarf_block
*blk
;
5914 blk
= (struct dwarf_block
*)
5915 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5919 static struct abbrev_info
*
5920 dwarf_alloc_abbrev (void)
5922 struct abbrev_info
*abbrev
;
5924 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5925 memset (abbrev
, 0, sizeof (struct abbrev_info
));
5929 static struct die_info
*
5930 dwarf_alloc_die (void)
5932 struct die_info
*die
;
5934 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5935 memset (die
, 0, sizeof (struct die_info
));