1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
10 support in dwarfread.c
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or (at
17 your option) any later version.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. */
35 #include "elf/dwarf2.h"
38 #include "expression.h"
39 #include "filenames.h" /* for DOSish file names */
42 #include "complaints.h"
45 #include "gdb_string.h"
46 #include <sys/types.h>
48 #ifndef DWARF2_REG_TO_REGNUM
49 #define DWARF2_REG_TO_REGNUM(REG) (REG)
53 /* .debug_info header for a compilation unit
54 Because of alignment constraints, this structure has padding and cannot
55 be mapped directly onto the beginning of the .debug_info section. */
56 typedef struct comp_unit_header
58 unsigned int length
; /* length of the .debug_info
60 unsigned short version
; /* version number -- 2 for DWARF
62 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
63 unsigned char addr_size
; /* byte size of an address -- 4 */
66 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
69 /* .debug_pubnames header
70 Because of alignment constraints, this structure has padding and cannot
71 be mapped directly onto the beginning of the .debug_info section. */
72 typedef struct pubnames_header
74 unsigned int length
; /* length of the .debug_pubnames
76 unsigned char version
; /* version number -- 2 for DWARF
78 unsigned int info_offset
; /* offset into .debug_info section */
79 unsigned int info_size
; /* byte size of .debug_info section
83 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
85 /* .debug_pubnames header
86 Because of alignment constraints, this structure has padding and cannot
87 be mapped directly onto the beginning of the .debug_info section. */
88 typedef struct aranges_header
90 unsigned int length
; /* byte len of the .debug_aranges
92 unsigned short version
; /* version number -- 2 for DWARF
94 unsigned int info_offset
; /* offset into .debug_info section */
95 unsigned char addr_size
; /* byte size of an address */
96 unsigned char seg_size
; /* byte size of segment descriptor */
99 #define _ACTUAL_ARANGES_HEADER_SIZE 12
101 /* .debug_line statement program prologue
102 Because of alignment constraints, this structure has padding and cannot
103 be mapped directly onto the beginning of the .debug_info section. */
104 typedef struct statement_prologue
106 unsigned int total_length
; /* byte length of the statement
108 unsigned short version
; /* version number -- 2 for DWARF
110 unsigned int prologue_length
; /* # bytes between prologue &
112 unsigned char minimum_instruction_length
; /* byte size of
114 unsigned char default_is_stmt
; /* initial value of is_stmt
117 unsigned char line_range
;
118 unsigned char opcode_base
; /* number assigned to first special
120 unsigned char *standard_opcode_lengths
;
124 /* offsets and sizes of debugging sections */
126 static file_ptr dwarf_info_offset
;
127 static file_ptr dwarf_abbrev_offset
;
128 static file_ptr dwarf_line_offset
;
129 static file_ptr dwarf_pubnames_offset
;
130 static file_ptr dwarf_aranges_offset
;
131 static file_ptr dwarf_loc_offset
;
132 static file_ptr dwarf_macinfo_offset
;
133 static file_ptr dwarf_str_offset
;
135 static unsigned int dwarf_info_size
;
136 static unsigned int dwarf_abbrev_size
;
137 static unsigned int dwarf_line_size
;
138 static unsigned int dwarf_pubnames_size
;
139 static unsigned int dwarf_aranges_size
;
140 static unsigned int dwarf_loc_size
;
141 static unsigned int dwarf_macinfo_size
;
142 static unsigned int dwarf_str_size
;
144 /* names of the debugging sections */
146 #define INFO_SECTION ".debug_info"
147 #define ABBREV_SECTION ".debug_abbrev"
148 #define LINE_SECTION ".debug_line"
149 #define PUBNAMES_SECTION ".debug_pubnames"
150 #define ARANGES_SECTION ".debug_aranges"
151 #define LOC_SECTION ".debug_loc"
152 #define MACINFO_SECTION ".debug_macinfo"
153 #define STR_SECTION ".debug_str"
155 /* local data types */
157 /* The data in a compilation unit header, after target2host
158 translation, looks like this. */
159 struct comp_unit_head
161 unsigned long length
;
163 unsigned int abbrev_offset
;
164 unsigned char addr_size
;
165 unsigned char signed_addr_p
;
166 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
167 unsigned int initial_length_size
; /* size of the length field; either
171 /* The data in the .debug_line statement prologue looks like this. */
174 unsigned int total_length
;
175 unsigned short version
;
176 unsigned int prologue_length
;
177 unsigned char minimum_instruction_length
;
178 unsigned char default_is_stmt
;
180 unsigned char line_range
;
181 unsigned char opcode_base
;
182 unsigned char *standard_opcode_lengths
;
185 /* When we construct a partial symbol table entry we only
186 need this much information. */
187 struct partial_die_info
190 unsigned char has_children
;
191 unsigned char is_external
;
192 unsigned char is_declaration
;
193 unsigned char has_type
;
200 struct dwarf_block
*locdesc
;
201 unsigned int language
;
205 /* This data structure holds the information of an abbrev. */
208 unsigned int number
; /* number identifying abbrev */
209 enum dwarf_tag tag
; /* dwarf tag */
210 int has_children
; /* boolean */
211 unsigned int num_attrs
; /* number of attributes */
212 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
213 struct abbrev_info
*next
; /* next in chain */
218 enum dwarf_attribute name
;
219 enum dwarf_form form
;
222 /* This data structure holds a complete die structure. */
225 enum dwarf_tag tag
; /* Tag indicating type of die */
226 unsigned short has_children
; /* Does the die have children */
227 unsigned int abbrev
; /* Abbrev number */
228 unsigned int offset
; /* Offset in .debug_info section */
229 unsigned int num_attrs
; /* Number of attributes */
230 struct attribute
*attrs
; /* An array of attributes */
231 struct die_info
*next_ref
; /* Next die in ref hash table */
232 struct die_info
*next
; /* Next die in linked list */
233 struct type
*type
; /* Cached type information */
236 /* Attributes have a name and a value */
239 enum dwarf_attribute name
;
240 enum dwarf_form form
;
244 struct dwarf_block
*blk
;
252 /* Get at parts of an attribute structure */
254 #define DW_STRING(attr) ((attr)->u.str)
255 #define DW_UNSND(attr) ((attr)->u.unsnd)
256 #define DW_BLOCK(attr) ((attr)->u.blk)
257 #define DW_SND(attr) ((attr)->u.snd)
258 #define DW_ADDR(attr) ((attr)->u.addr)
260 /* Blocks are a bunch of untyped bytes. */
267 /* We only hold one compilation unit's abbrevs in
268 memory at any one time. */
269 #ifndef ABBREV_HASH_SIZE
270 #define ABBREV_HASH_SIZE 121
272 #ifndef ATTR_ALLOC_CHUNK
273 #define ATTR_ALLOC_CHUNK 4
276 static struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
278 /* A hash table of die offsets for following references. */
279 #ifndef REF_HASH_SIZE
280 #define REF_HASH_SIZE 1021
283 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
285 /* Obstack for allocating temporary storage used during symbol reading. */
286 static struct obstack dwarf2_tmp_obstack
;
288 /* Offset to the first byte of the current compilation unit header,
289 for resolving relative reference dies. */
290 static unsigned int cu_header_offset
;
292 /* Allocate fields for structs, unions and enums in this size. */
293 #ifndef DW_FIELD_ALLOC_CHUNK
294 #define DW_FIELD_ALLOC_CHUNK 4
297 /* The language we are debugging. */
298 static enum language cu_language
;
299 static const struct language_defn
*cu_language_defn
;
301 /* Actually data from the sections. */
302 static char *dwarf_info_buffer
;
303 static char *dwarf_abbrev_buffer
;
304 static char *dwarf_line_buffer
;
306 /* A zeroed version of a partial die for initialization purposes. */
307 static struct partial_die_info zeroed_partial_die
;
309 /* The generic symbol table building routines have separate lists for
310 file scope symbols and all all other scopes (local scopes). So
311 we need to select the right one to pass to add_symbol_to_list().
312 We do it by keeping a pointer to the correct list in list_in_scope.
314 FIXME: The original dwarf code just treated the file scope as the first
315 local scope, and all other local scopes as nested local scopes, and worked
316 fine. Check to see if we really need to distinguish these
318 static struct pending
**list_in_scope
= &file_symbols
;
320 /* FIXME: decode_locdesc sets these variables to describe the location
321 to the caller. These ought to be a structure or something. If
322 none of the flags are set, the object lives at the address returned
323 by decode_locdesc. */
325 static int optimized_out
; /* No ops in location in expression,
326 so object was optimized out. */
327 static int isreg
; /* Object lives in register.
328 decode_locdesc's return value is
329 the register number. */
330 static int offreg
; /* Object's address is the sum of the
331 register specified by basereg, plus
332 the offset returned. */
333 static int basereg
; /* See `offreg'. */
334 static int isderef
; /* Value described by flags above is
335 the address of a pointer to the object. */
336 static int islocal
; /* Variable is at the returned offset
337 from the frame start, but there's
338 no identified frame pointer for
339 this function, so we can't say
340 which register it's relative to;
343 /* DW_AT_frame_base values for the current function.
344 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
345 contains the register number for the frame register.
346 frame_base_offset is the offset from the frame register to the
347 virtual stack frame. */
348 static int frame_base_reg
;
349 static CORE_ADDR frame_base_offset
;
351 /* This value is added to each symbol value. FIXME: Generalize to
352 the section_offsets structure used by dbxread (once this is done,
353 pass the appropriate section number to end_symtab). */
354 static CORE_ADDR baseaddr
; /* Add to each symbol value */
356 /* We put a pointer to this structure in the read_symtab_private field
358 The complete dwarf information for an objfile is kept in the
359 psymbol_obstack, so that absolute die references can be handled.
360 Most of the information in this structure is related to an entire
361 object file and could be passed via the sym_private field of the objfile.
362 It is however conceivable that dwarf2 might not be the only type
363 of symbols read from an object file. */
367 /* Pointer to start of dwarf info buffer for the objfile. */
369 char *dwarf_info_buffer
;
371 /* Offset in dwarf_info_buffer for this compilation unit. */
373 unsigned long dwarf_info_offset
;
375 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
377 char *dwarf_abbrev_buffer
;
379 /* Size of dwarf abbreviation section for the objfile. */
381 unsigned int dwarf_abbrev_size
;
383 /* Pointer to start of dwarf line buffer for the objfile. */
385 char *dwarf_line_buffer
;
388 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
389 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
390 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
391 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
392 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
393 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
395 /* Maintain an array of referenced fundamental types for the current
396 compilation unit being read. For DWARF version 1, we have to construct
397 the fundamental types on the fly, since no information about the
398 fundamental types is supplied. Each such fundamental type is created by
399 calling a language dependent routine to create the type, and then a
400 pointer to that type is then placed in the array at the index specified
401 by it's FT_<TYPENAME> value. The array has a fixed size set by the
402 FT_NUM_MEMBERS compile time constant, which is the number of predefined
403 fundamental types gdb knows how to construct. */
404 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
406 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
407 but this would require a corresponding change in unpack_field_as_long
409 static int bits_per_byte
= 8;
411 /* The routines that read and process dies for a C struct or C++ class
412 pass lists of data member fields and lists of member function fields
413 in an instance of a field_info structure, as defined below. */
416 /* List of data member and baseclasses fields. */
419 struct nextfield
*next
;
426 /* Number of fields. */
429 /* Number of baseclasses. */
432 /* Set if the accesibility of one of the fields is not public. */
433 int non_public_fields
;
435 /* Member function fields array, entries are allocated in the order they
436 are encountered in the object file. */
439 struct nextfnfield
*next
;
440 struct fn_field fnfield
;
444 /* Member function fieldlist array, contains name of possibly overloaded
445 member function, number of overloaded member functions and a pointer
446 to the head of the member function field chain. */
451 struct nextfnfield
*head
;
455 /* Number of entries in the fnfieldlists array. */
459 /* FIXME: Kludge to mark a varargs function type for C++ member function
460 argument processing. */
461 #define TYPE_FLAG_VARARGS (1 << 10)
463 /* Dwarf2 has no clean way to discern C++ static and non-static member
464 functions. G++ helps GDB by marking the first parameter for non-static
465 member functions (which is the this pointer) as artificial.
466 We pass this information between dwarf2_add_member_fn and
467 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
468 #define TYPE_FIELD_ARTIFICIAL TYPE_FIELD_BITPOS
470 /* Various complaints about symbol reading that don't abort the process */
472 static struct complaint dwarf2_const_ignored
=
474 "type qualifier 'const' ignored", 0, 0
476 static struct complaint dwarf2_volatile_ignored
=
478 "type qualifier 'volatile' ignored", 0, 0
480 static struct complaint dwarf2_non_const_array_bound_ignored
=
482 "non-constant array bounds form '%s' ignored", 0, 0
484 static struct complaint dwarf2_missing_line_number_section
=
486 "missing .debug_line section", 0, 0
488 static struct complaint dwarf2_mangled_line_number_section
=
490 "mangled .debug_line section", 0, 0
492 static struct complaint dwarf2_unsupported_die_ref_attr
=
494 "unsupported die ref attribute form: '%s'", 0, 0
496 static struct complaint dwarf2_unsupported_stack_op
=
498 "unsupported stack op: '%s'", 0, 0
500 static struct complaint dwarf2_complex_location_expr
=
502 "location expression too complex", 0, 0
504 static struct complaint dwarf2_unsupported_tag
=
506 "unsupported tag: '%s'", 0, 0
508 static struct complaint dwarf2_unsupported_at_encoding
=
510 "unsupported DW_AT_encoding: '%s'", 0, 0
512 static struct complaint dwarf2_unsupported_at_frame_base
=
514 "unsupported DW_AT_frame_base for function '%s'", 0, 0
516 static struct complaint dwarf2_unexpected_tag
=
518 "unexepected tag in read_type_die: '%s'", 0, 0
520 static struct complaint dwarf2_missing_at_frame_base
=
522 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
524 static struct complaint dwarf2_bad_static_member_name
=
526 "unrecognized static data member name '%s'", 0, 0
528 static struct complaint dwarf2_unsupported_accessibility
=
530 "unsupported accessibility %d", 0, 0
532 static struct complaint dwarf2_bad_member_name_complaint
=
534 "cannot extract member name from '%s'", 0, 0
536 static struct complaint dwarf2_missing_member_fn_type_complaint
=
538 "member function type missing for '%s'", 0, 0
540 static struct complaint dwarf2_vtbl_not_found_complaint
=
542 "virtual function table pointer not found when defining class '%s'", 0, 0
544 static struct complaint dwarf2_absolute_sibling_complaint
=
546 "ignoring absolute DW_AT_sibling", 0, 0
548 static struct complaint dwarf2_const_value_length_mismatch
=
550 "const value length mismatch for '%s', got %d, expected %d", 0, 0
552 static struct complaint dwarf2_unsupported_const_value_attr
=
554 "unsupported const value attribute form: '%s'", 0, 0
557 /* local function prototypes */
559 static void dwarf2_locate_sections (bfd
*, asection
*, PTR
);
562 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
565 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
567 static char *scan_partial_symbols (char *, struct objfile
*,
568 CORE_ADDR
*, CORE_ADDR
*,
569 const struct comp_unit_head
*);
571 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
572 const struct comp_unit_head
*);
574 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
576 static void psymtab_to_symtab_1 (struct partial_symtab
*);
578 static char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int);
580 static void dwarf2_read_abbrevs (bfd
*, unsigned int);
582 static void dwarf2_empty_abbrev_table (PTR
);
584 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int);
586 static char *read_partial_die (struct partial_die_info
*,
588 const struct comp_unit_head
*);
590 static char *read_full_die (struct die_info
**, bfd
*, char *,
591 const struct comp_unit_head
*);
593 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
594 bfd
*, char *, const struct comp_unit_head
*);
596 static unsigned int read_1_byte (bfd
*, char *);
598 static int read_1_signed_byte (bfd
*, char *);
600 static unsigned int read_2_bytes (bfd
*, char *);
602 static unsigned int read_4_bytes (bfd
*, char *);
604 static unsigned long read_8_bytes (bfd
*, char *);
606 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
609 static LONGEST
read_initial_length (bfd
*, char *,
610 struct comp_unit_head
*, int *bytes_read
);
612 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
615 static char *read_n_bytes (bfd
*, char *, unsigned int);
617 static char *read_string (bfd
*, char *, unsigned int *);
619 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
621 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
623 static void set_cu_language (unsigned int);
625 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
627 static int die_is_declaration (struct die_info
*);
629 static void dwarf_decode_lines (unsigned int, char *, bfd
*,
630 const struct comp_unit_head
*);
632 static void dwarf2_start_subfile (char *, char *);
634 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
635 struct objfile
*, const struct comp_unit_head
*);
637 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
638 struct objfile
*, const struct comp_unit_head
*);
640 static void dwarf2_const_value_data (struct attribute
*attr
,
644 static struct type
*die_type (struct die_info
*, struct objfile
*,
645 const struct comp_unit_head
*);
647 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
648 const struct comp_unit_head
*);
651 static struct type
*type_at_offset (unsigned int, struct objfile
*);
654 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
655 const struct comp_unit_head
*);
657 static void read_type_die (struct die_info
*, struct objfile
*,
658 const struct comp_unit_head
*);
660 static void read_typedef (struct die_info
*, struct objfile
*,
661 const struct comp_unit_head
*);
663 static void read_base_type (struct die_info
*, struct objfile
*);
665 static void read_file_scope (struct die_info
*, struct objfile
*,
666 const struct comp_unit_head
*);
668 static void read_func_scope (struct die_info
*, struct objfile
*,
669 const struct comp_unit_head
*);
671 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
672 const struct comp_unit_head
*);
674 static int dwarf2_get_pc_bounds (struct die_info
*,
675 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*);
677 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
678 struct objfile
*, const struct comp_unit_head
*);
680 static void dwarf2_attach_fields_to_type (struct field_info
*,
681 struct type
*, struct objfile
*);
683 static void dwarf2_add_member_fn (struct field_info
*,
684 struct die_info
*, struct type
*,
685 struct objfile
*objfile
,
686 const struct comp_unit_head
*);
688 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
689 struct type
*, struct objfile
*);
691 static void read_structure_scope (struct die_info
*, struct objfile
*,
692 const struct comp_unit_head
*);
694 static void read_common_block (struct die_info
*, struct objfile
*,
695 const struct comp_unit_head
*);
697 static void read_enumeration (struct die_info
*, struct objfile
*,
698 const struct comp_unit_head
*);
700 static struct type
*dwarf_base_type (int, int, struct objfile
*);
702 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
703 const struct comp_unit_head
*);
705 static void read_array_type (struct die_info
*, struct objfile
*,
706 const struct comp_unit_head
*);
708 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
709 const struct comp_unit_head
*);
711 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
712 const struct comp_unit_head
*);
714 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
715 const struct comp_unit_head
*);
717 static void read_tag_const_type (struct die_info
*, struct objfile
*,
718 const struct comp_unit_head
*);
720 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
721 const struct comp_unit_head
*);
723 static void read_tag_string_type (struct die_info
*, struct objfile
*);
725 static void read_subroutine_type (struct die_info
*, struct objfile
*,
726 const struct comp_unit_head
*);
728 static struct die_info
*read_comp_unit (char *, bfd
*,
729 const struct comp_unit_head
*);
731 static void free_die_list (struct die_info
*);
733 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
735 static void process_die (struct die_info
*, struct objfile
*,
736 const struct comp_unit_head
*);
738 static char *dwarf2_linkage_name (struct die_info
*);
740 static char *dwarf_tag_name (unsigned int);
742 static char *dwarf_attr_name (unsigned int);
744 static char *dwarf_form_name (unsigned int);
746 static char *dwarf_stack_op_name (unsigned int);
748 static char *dwarf_bool_name (unsigned int);
750 static char *dwarf_type_encoding_name (unsigned int);
753 static char *dwarf_cfi_name (unsigned int);
755 struct die_info
*copy_die (struct die_info
*);
758 static struct die_info
*sibling_die (struct die_info
*);
760 static void dump_die (struct die_info
*);
762 static void dump_die_list (struct die_info
*);
764 static void store_in_ref_table (unsigned int, struct die_info
*);
766 static void dwarf2_empty_hash_tables (void);
768 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
770 static struct die_info
*follow_die_ref (unsigned int);
772 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
774 /* memory allocation interface */
776 static void dwarf2_free_tmp_obstack (PTR
);
778 static struct dwarf_block
*dwarf_alloc_block (void);
780 static struct abbrev_info
*dwarf_alloc_abbrev (void);
782 static struct die_info
*dwarf_alloc_die (void);
784 /* Try to locate the sections we need for DWARF 2 debugging
785 information and return true if we have enough to do something. */
788 dwarf2_has_info (bfd
*abfd
)
790 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
791 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
792 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
802 /* This function is mapped across the sections and remembers the
803 offset and size of each of the debugging sections we are interested
807 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, PTR ignore_ptr
)
809 if (STREQ (sectp
->name
, INFO_SECTION
))
811 dwarf_info_offset
= sectp
->filepos
;
812 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
814 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
816 dwarf_abbrev_offset
= sectp
->filepos
;
817 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
819 else if (STREQ (sectp
->name
, LINE_SECTION
))
821 dwarf_line_offset
= sectp
->filepos
;
822 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
824 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
826 dwarf_pubnames_offset
= sectp
->filepos
;
827 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
829 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
831 dwarf_aranges_offset
= sectp
->filepos
;
832 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
834 else if (STREQ (sectp
->name
, LOC_SECTION
))
836 dwarf_loc_offset
= sectp
->filepos
;
837 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
839 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
841 dwarf_macinfo_offset
= sectp
->filepos
;
842 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
844 else if (STREQ (sectp
->name
, STR_SECTION
))
846 dwarf_str_offset
= sectp
->filepos
;
847 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
851 /* Build a partial symbol table. */
854 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
857 /* We definitely need the .debug_info and .debug_abbrev sections */
859 dwarf_info_buffer
= dwarf2_read_section (objfile
,
862 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
865 dwarf_line_buffer
= dwarf2_read_section (objfile
,
870 || (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 CORE_ADDR lowpc
, highpc
;
975 info_ptr
= dwarf_info_buffer
;
976 abbrev_ptr
= dwarf_abbrev_buffer
;
978 /* We use dwarf2_tmp_obstack for objects that don't need to survive
979 the partial symbol scan, like attribute values.
981 We could reduce our peak memory consumption during partial symbol
982 table construction by freeing stuff from this obstack more often
983 --- say, after processing each compilation unit, or each die ---
984 but it turns out that this saves almost nothing. For an
985 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
986 on dwarf2_tmp_obstack. Some investigation showed:
988 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
989 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
990 all fixed-length values not requiring dynamic allocation.
992 2) 30% of the attributes used the form DW_FORM_string. For
993 DW_FORM_string, read_attribute simply hands back a pointer to
994 the null-terminated string in dwarf_info_buffer, so no dynamic
995 allocation is needed there either.
997 3) The remaining 1% of the attributes all used DW_FORM_block1.
998 75% of those were DW_AT_frame_base location lists for
999 functions; the rest were DW_AT_location attributes, probably
1000 for the global variables.
1002 Anyway, what this all means is that the memory the dwarf2
1003 reader uses as temporary space reading partial symbols is about
1004 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1006 obstack_init (&dwarf2_tmp_obstack
);
1007 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1009 /* Since the objects we're extracting from dwarf_info_buffer vary in
1010 length, only the individual functions to extract them (like
1011 read_comp_unit_head and read_partial_die) can really know whether
1012 the buffer is large enough to hold another complete object.
1014 At the moment, they don't actually check that. If
1015 dwarf_info_buffer holds just one extra byte after the last
1016 compilation unit's dies, then read_comp_unit_head will happily
1017 read off the end of the buffer. read_partial_die is similarly
1018 casual. Those functions should be fixed.
1020 For this loop condition, simply checking whether there's any data
1021 left at all should be sufficient. */
1022 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1024 struct comp_unit_head cu_header
;
1025 beg_of_comp_unit
= info_ptr
;
1026 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1028 if (cu_header
.version
!= 2)
1030 error ("Dwarf Error: wrong version in compilation unit header.");
1033 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
1035 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
1036 (long) cu_header
.abbrev_offset
,
1037 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1040 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1041 > dwarf_info_buffer
+ dwarf_info_size
)
1043 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
1044 (long) cu_header
.length
,
1045 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1048 /* Read the abbrevs for this compilation unit into a table */
1049 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1050 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1052 /* Read the compilation unit die */
1053 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1056 /* Set the language we're debugging */
1057 set_cu_language (comp_unit_die
.language
);
1059 /* Allocate a new partial symbol table structure */
1060 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1061 comp_unit_die
.name
? comp_unit_die
.name
: "",
1062 comp_unit_die
.lowpc
,
1063 objfile
->global_psymbols
.next
,
1064 objfile
->static_psymbols
.next
);
1066 pst
->read_symtab_private
= (char *)
1067 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1068 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1069 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1070 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1071 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1072 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1073 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1074 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1076 /* Store the function that reads in the rest of the symbol table */
1077 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1079 /* Check if comp unit has_children.
1080 If so, read the rest of the partial symbols from this comp unit.
1081 If not, there's no more debug_info for this comp unit. */
1082 if (comp_unit_die
.has_children
)
1084 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1087 /* If the compilation unit didn't have an explicit address range,
1088 then use the information extracted from its child dies. */
1089 if (! comp_unit_die
.has_pc_info
)
1091 comp_unit_die
.lowpc
= lowpc
;
1092 comp_unit_die
.highpc
= highpc
;
1095 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1096 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1098 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1099 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1100 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1101 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1102 sort_pst_symbols (pst
);
1104 /* If there is already a psymtab or symtab for a file of this
1105 name, remove it. (If there is a symtab, more drastic things
1106 also happen.) This happens in VxWorks. */
1107 free_named_symtabs (pst
->filename
);
1109 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1110 + cu_header
.initial_length_size
;
1112 do_cleanups (back_to
);
1115 /* Read in all interesting dies to the end of the compilation unit. */
1118 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1119 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1120 const struct comp_unit_head
*cu_header
)
1122 bfd
*abfd
= objfile
->obfd
;
1123 struct partial_die_info pdi
;
1125 /* This function is called after we've read in the comp_unit_die in
1126 order to read its children. We start the nesting level at 1 since
1127 we have pushed 1 level down in order to read the comp unit's children.
1128 The comp unit itself is at level 0, so we stop reading when we pop
1129 back to that level. */
1131 int nesting_level
= 1;
1133 *lowpc
= ((CORE_ADDR
) -1);
1134 *highpc
= ((CORE_ADDR
) 0);
1136 while (nesting_level
)
1138 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1144 case DW_TAG_subprogram
:
1145 if (pdi
.has_pc_info
)
1147 if (pdi
.lowpc
< *lowpc
)
1151 if (pdi
.highpc
> *highpc
)
1153 *highpc
= pdi
.highpc
;
1155 if ((pdi
.is_external
|| nesting_level
== 1)
1156 && !pdi
.is_declaration
)
1158 add_partial_symbol (&pdi
, objfile
, cu_header
);
1162 case DW_TAG_variable
:
1163 case DW_TAG_typedef
:
1164 case DW_TAG_class_type
:
1165 case DW_TAG_structure_type
:
1166 case DW_TAG_union_type
:
1167 case DW_TAG_enumeration_type
:
1168 if ((pdi
.is_external
|| nesting_level
== 1)
1169 && !pdi
.is_declaration
)
1171 add_partial_symbol (&pdi
, objfile
, cu_header
);
1174 case DW_TAG_enumerator
:
1175 /* File scope enumerators are added to the partial symbol
1177 if (nesting_level
== 2)
1178 add_partial_symbol (&pdi
, objfile
, cu_header
);
1180 case DW_TAG_base_type
:
1181 /* File scope base type definitions are added to the partial
1183 if (nesting_level
== 1)
1184 add_partial_symbol (&pdi
, objfile
, cu_header
);
1191 /* If the die has a sibling, skip to the sibling.
1192 Do not skip enumeration types, we want to record their
1194 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1196 info_ptr
= pdi
.sibling
;
1198 else if (pdi
.has_children
)
1200 /* Die has children, but the optional DW_AT_sibling attribute
1211 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1212 from `maint check'. */
1213 if (*lowpc
== ((CORE_ADDR
) -1))
1219 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1220 const struct comp_unit_head
*cu_header
)
1226 case DW_TAG_subprogram
:
1227 if (pdi
->is_external
)
1229 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1230 mst_text, objfile); */
1231 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1232 VAR_NAMESPACE
, LOC_BLOCK
,
1233 &objfile
->global_psymbols
,
1234 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1238 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1239 mst_file_text, objfile); */
1240 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1241 VAR_NAMESPACE
, LOC_BLOCK
,
1242 &objfile
->static_psymbols
,
1243 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1246 case DW_TAG_variable
:
1247 if (pdi
->is_external
)
1250 Don't enter into the minimal symbol tables as there is
1251 a minimal symbol table entry from the ELF symbols already.
1252 Enter into partial symbol table if it has a location
1253 descriptor or a type.
1254 If the location descriptor is missing, new_symbol will create
1255 a LOC_UNRESOLVED symbol, the address of the variable will then
1256 be determined from the minimal symbol table whenever the variable
1258 The address for the partial symbol table entry is not
1259 used by GDB, but it comes in handy for debugging partial symbol
1263 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1264 if (pdi
->locdesc
|| pdi
->has_type
)
1265 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1266 VAR_NAMESPACE
, LOC_STATIC
,
1267 &objfile
->global_psymbols
,
1268 0, addr
+ baseaddr
, cu_language
, objfile
);
1272 /* Static Variable. Skip symbols without location descriptors. */
1273 if (pdi
->locdesc
== NULL
)
1275 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1276 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1277 mst_file_data, objfile); */
1278 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1279 VAR_NAMESPACE
, LOC_STATIC
,
1280 &objfile
->static_psymbols
,
1281 0, addr
+ baseaddr
, cu_language
, objfile
);
1284 case DW_TAG_typedef
:
1285 case DW_TAG_base_type
:
1286 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1287 VAR_NAMESPACE
, LOC_TYPEDEF
,
1288 &objfile
->static_psymbols
,
1289 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1291 case DW_TAG_class_type
:
1292 case DW_TAG_structure_type
:
1293 case DW_TAG_union_type
:
1294 case DW_TAG_enumeration_type
:
1295 /* Skip aggregate types without children, these are external
1297 if (pdi
->has_children
== 0)
1299 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1300 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1301 &objfile
->static_psymbols
,
1302 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1304 if (cu_language
== language_cplus
)
1306 /* For C++, these implicitly act as typedefs as well. */
1307 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1308 VAR_NAMESPACE
, LOC_TYPEDEF
,
1309 &objfile
->static_psymbols
,
1310 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1313 case DW_TAG_enumerator
:
1314 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1315 VAR_NAMESPACE
, LOC_CONST
,
1316 &objfile
->static_psymbols
,
1317 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1324 /* Expand this partial symbol table into a full symbol table. */
1327 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1329 /* FIXME: This is barely more than a stub. */
1334 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1340 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1341 gdb_flush (gdb_stdout
);
1344 psymtab_to_symtab_1 (pst
);
1346 /* Finish up the debug error message. */
1348 printf_filtered ("done.\n");
1354 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1356 struct objfile
*objfile
= pst
->objfile
;
1357 bfd
*abfd
= objfile
->obfd
;
1358 struct comp_unit_head cu_header
;
1359 struct die_info
*dies
;
1360 unsigned long offset
;
1361 CORE_ADDR lowpc
, highpc
;
1362 struct die_info
*child_die
;
1364 struct symtab
*symtab
;
1365 struct cleanup
*back_to
;
1367 /* Set local variables from the partial symbol table info. */
1368 offset
= DWARF_INFO_OFFSET (pst
);
1369 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1370 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1371 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1372 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1373 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1374 cu_header_offset
= offset
;
1375 info_ptr
= dwarf_info_buffer
+ offset
;
1377 obstack_init (&dwarf2_tmp_obstack
);
1378 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1381 make_cleanup (really_free_pendings
, NULL
);
1383 /* read in the comp_unit header */
1384 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1386 /* Read the abbrevs for this compilation unit */
1387 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1388 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1390 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1392 make_cleanup_free_die_list (dies
);
1394 /* Do line number decoding in read_file_scope () */
1395 process_die (dies
, objfile
, &cu_header
);
1397 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1399 /* Some compilers don't define a DW_AT_high_pc attribute for
1400 the compilation unit. If the DW_AT_high_pc is missing,
1401 synthesize it, by scanning the DIE's below the compilation unit. */
1403 if (dies
->has_children
)
1405 child_die
= dies
->next
;
1406 while (child_die
&& child_die
->tag
)
1408 if (child_die
->tag
== DW_TAG_subprogram
)
1410 CORE_ADDR low
, high
;
1412 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1414 highpc
= max (highpc
, high
);
1417 child_die
= sibling_die (child_die
);
1421 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1423 /* Set symtab language to language from DW_AT_language.
1424 If the compilation is from a C file generated by language preprocessors,
1425 do not set the language if it was already deduced by start_subfile. */
1427 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1429 symtab
->language
= cu_language
;
1431 pst
->symtab
= symtab
;
1433 sort_symtab_syms (pst
->symtab
);
1435 do_cleanups (back_to
);
1438 /* Process a die and its children. */
1441 process_die (struct die_info
*die
, struct objfile
*objfile
,
1442 const struct comp_unit_head
*cu_header
)
1446 case DW_TAG_padding
:
1448 case DW_TAG_compile_unit
:
1449 read_file_scope (die
, objfile
, cu_header
);
1451 case DW_TAG_subprogram
:
1452 read_subroutine_type (die
, objfile
, cu_header
);
1453 read_func_scope (die
, objfile
, cu_header
);
1455 case DW_TAG_inlined_subroutine
:
1456 /* FIXME: These are ignored for now.
1457 They could be used to set breakpoints on all inlined instances
1458 of a function and make GDB `next' properly over inlined functions. */
1460 case DW_TAG_lexical_block
:
1461 read_lexical_block_scope (die
, objfile
, cu_header
);
1463 case DW_TAG_class_type
:
1464 case DW_TAG_structure_type
:
1465 case DW_TAG_union_type
:
1466 read_structure_scope (die
, objfile
, cu_header
);
1468 case DW_TAG_enumeration_type
:
1469 read_enumeration (die
, objfile
, cu_header
);
1471 case DW_TAG_subroutine_type
:
1472 read_subroutine_type (die
, objfile
, cu_header
);
1474 case DW_TAG_array_type
:
1475 read_array_type (die
, objfile
, cu_header
);
1477 case DW_TAG_pointer_type
:
1478 read_tag_pointer_type (die
, objfile
, cu_header
);
1480 case DW_TAG_ptr_to_member_type
:
1481 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1483 case DW_TAG_reference_type
:
1484 read_tag_reference_type (die
, objfile
, cu_header
);
1486 case DW_TAG_string_type
:
1487 read_tag_string_type (die
, objfile
);
1489 case DW_TAG_base_type
:
1490 read_base_type (die
, objfile
);
1491 if (dwarf_attr (die
, DW_AT_name
))
1493 /* Add a typedef symbol for the base type definition. */
1494 new_symbol (die
, die
->type
, objfile
, cu_header
);
1497 case DW_TAG_common_block
:
1498 read_common_block (die
, objfile
, cu_header
);
1500 case DW_TAG_common_inclusion
:
1503 new_symbol (die
, NULL
, objfile
, cu_header
);
1509 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1510 const struct comp_unit_head
*cu_header
)
1512 unsigned int line_offset
= 0;
1513 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1514 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1515 struct attribute
*attr
;
1516 char *name
= "<unknown>";
1517 char *comp_dir
= NULL
;
1518 struct die_info
*child_die
;
1519 bfd
*abfd
= objfile
->obfd
;
1521 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1523 if (die
->has_children
)
1525 child_die
= die
->next
;
1526 while (child_die
&& child_die
->tag
)
1528 if (child_die
->tag
== DW_TAG_subprogram
)
1530 CORE_ADDR low
, high
;
1532 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1534 lowpc
= min (lowpc
, low
);
1535 highpc
= max (highpc
, high
);
1538 child_die
= sibling_die (child_die
);
1543 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1544 from finish_block. */
1545 if (lowpc
== ((CORE_ADDR
) -1))
1550 attr
= dwarf_attr (die
, DW_AT_name
);
1553 name
= DW_STRING (attr
);
1555 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1558 comp_dir
= DW_STRING (attr
);
1561 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1562 directory, get rid of it. */
1563 char *cp
= strchr (comp_dir
, ':');
1565 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1570 if (objfile
->ei
.entry_point
>= lowpc
&&
1571 objfile
->ei
.entry_point
< highpc
)
1573 objfile
->ei
.entry_file_lowpc
= lowpc
;
1574 objfile
->ei
.entry_file_highpc
= highpc
;
1577 attr
= dwarf_attr (die
, DW_AT_language
);
1580 set_cu_language (DW_UNSND (attr
));
1583 /* We assume that we're processing GCC output. */
1584 processing_gcc_compilation
= 2;
1586 /* FIXME:Do something here. */
1587 if (dip
->at_producer
!= NULL
)
1589 handle_producer (dip
->at_producer
);
1593 /* The compilation unit may be in a different language or objfile,
1594 zero out all remembered fundamental types. */
1595 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1597 start_symtab (name
, comp_dir
, lowpc
);
1598 record_debugformat ("DWARF 2");
1600 /* Decode line number information if present. */
1601 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1604 line_offset
= DW_UNSND (attr
);
1605 dwarf_decode_lines (line_offset
, comp_dir
, abfd
, cu_header
);
1608 /* Process all dies in compilation unit. */
1609 if (die
->has_children
)
1611 child_die
= die
->next
;
1612 while (child_die
&& child_die
->tag
)
1614 process_die (child_die
, objfile
, cu_header
);
1615 child_die
= sibling_die (child_die
);
1621 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
1622 const struct comp_unit_head
*cu_header
)
1624 register struct context_stack
*new;
1627 struct die_info
*child_die
;
1628 struct attribute
*attr
;
1631 name
= dwarf2_linkage_name (die
);
1633 /* Ignore functions with missing or empty names and functions with
1634 missing or invalid low and high pc attributes. */
1635 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1641 if (objfile
->ei
.entry_point
>= lowpc
&&
1642 objfile
->ei
.entry_point
< highpc
)
1644 objfile
->ei
.entry_func_lowpc
= lowpc
;
1645 objfile
->ei
.entry_func_highpc
= highpc
;
1648 /* Decode DW_AT_frame_base location descriptor if present, keep result
1649 for DW_OP_fbreg operands in decode_locdesc. */
1650 frame_base_reg
= -1;
1651 frame_base_offset
= 0;
1652 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1655 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
1657 complain (&dwarf2_unsupported_at_frame_base
, name
);
1659 frame_base_reg
= addr
;
1662 frame_base_reg
= basereg
;
1663 frame_base_offset
= addr
;
1666 complain (&dwarf2_unsupported_at_frame_base
, name
);
1669 new = push_context (0, lowpc
);
1670 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
1671 list_in_scope
= &local_symbols
;
1673 if (die
->has_children
)
1675 child_die
= die
->next
;
1676 while (child_die
&& child_die
->tag
)
1678 process_die (child_die
, objfile
, cu_header
);
1679 child_die
= sibling_die (child_die
);
1683 new = pop_context ();
1684 /* Make a block for the local symbols within. */
1685 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1686 lowpc
, highpc
, objfile
);
1687 list_in_scope
= &file_symbols
;
1690 /* Process all the DIES contained within a lexical block scope. Start
1691 a new scope, process the dies, and then close the scope. */
1694 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
1695 const struct comp_unit_head
*cu_header
)
1697 register struct context_stack
*new;
1698 CORE_ADDR lowpc
, highpc
;
1699 struct die_info
*child_die
;
1701 /* Ignore blocks with missing or invalid low and high pc attributes. */
1702 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1707 push_context (0, lowpc
);
1708 if (die
->has_children
)
1710 child_die
= die
->next
;
1711 while (child_die
&& child_die
->tag
)
1713 process_die (child_die
, objfile
, cu_header
);
1714 child_die
= sibling_die (child_die
);
1717 new = pop_context ();
1719 if (local_symbols
!= NULL
)
1721 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1724 local_symbols
= new->locals
;
1727 /* Get low and high pc attributes from a die.
1728 Return 1 if the attributes are present and valid, otherwise, return 0. */
1731 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1732 struct objfile
*objfile
)
1734 struct attribute
*attr
;
1738 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1740 low
= DW_ADDR (attr
);
1743 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1745 high
= DW_ADDR (attr
);
1752 /* When using the GNU linker, .gnu.linkonce. sections are used to
1753 eliminate duplicate copies of functions and vtables and such.
1754 The linker will arbitrarily choose one and discard the others.
1755 The AT_*_pc values for such functions refer to local labels in
1756 these sections. If the section from that file was discarded, the
1757 labels are not in the output, so the relocs get a value of 0.
1758 If this is a discarded function, mark the pc bounds as invalid,
1759 so that GDB will ignore it. */
1760 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1768 /* Add an aggregate field to the field list. */
1771 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
1772 struct objfile
*objfile
,
1773 const struct comp_unit_head
*cu_header
)
1775 struct nextfield
*new_field
;
1776 struct attribute
*attr
;
1778 char *fieldname
= "";
1780 /* Allocate a new field list entry and link it in. */
1781 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1782 make_cleanup (xfree
, new_field
);
1783 memset (new_field
, 0, sizeof (struct nextfield
));
1784 new_field
->next
= fip
->fields
;
1785 fip
->fields
= new_field
;
1788 /* Handle accessibility and virtuality of field.
1789 The default accessibility for members is public, the default
1790 accessibility for inheritance is private. */
1791 if (die
->tag
!= DW_TAG_inheritance
)
1792 new_field
->accessibility
= DW_ACCESS_public
;
1794 new_field
->accessibility
= DW_ACCESS_private
;
1795 new_field
->virtuality
= DW_VIRTUALITY_none
;
1797 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1799 new_field
->accessibility
= DW_UNSND (attr
);
1800 if (new_field
->accessibility
!= DW_ACCESS_public
)
1801 fip
->non_public_fields
= 1;
1802 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1804 new_field
->virtuality
= DW_UNSND (attr
);
1806 fp
= &new_field
->field
;
1807 if (die
->tag
== DW_TAG_member
)
1809 /* Get type of field. */
1810 fp
->type
= die_type (die
, objfile
, cu_header
);
1812 /* Get bit size of field (zero if none). */
1813 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1816 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1820 FIELD_BITSIZE (*fp
) = 0;
1823 /* Get bit offset of field. */
1824 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1827 FIELD_BITPOS (*fp
) =
1828 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
1831 FIELD_BITPOS (*fp
) = 0;
1832 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1835 if (BITS_BIG_ENDIAN
)
1837 /* For big endian bits, the DW_AT_bit_offset gives the
1838 additional bit offset from the MSB of the containing
1839 anonymous object to the MSB of the field. We don't
1840 have to do anything special since we don't need to
1841 know the size of the anonymous object. */
1842 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1846 /* For little endian bits, compute the bit offset to the
1847 MSB of the anonymous object, subtract off the number of
1848 bits from the MSB of the field to the MSB of the
1849 object, and then subtract off the number of bits of
1850 the field itself. The result is the bit offset of
1851 the LSB of the field. */
1853 int bit_offset
= DW_UNSND (attr
);
1855 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1858 /* The size of the anonymous object containing
1859 the bit field is explicit, so use the
1860 indicated size (in bytes). */
1861 anonymous_size
= DW_UNSND (attr
);
1865 /* The size of the anonymous object containing
1866 the bit field must be inferred from the type
1867 attribute of the data member containing the
1869 anonymous_size
= TYPE_LENGTH (fp
->type
);
1871 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1872 - bit_offset
- FIELD_BITSIZE (*fp
);
1876 /* Get name of field. */
1877 attr
= dwarf_attr (die
, DW_AT_name
);
1878 if (attr
&& DW_STRING (attr
))
1879 fieldname
= DW_STRING (attr
);
1880 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1881 &objfile
->type_obstack
);
1883 /* Change accessibility for artificial fields (e.g. virtual table
1884 pointer or virtual base class pointer) to private. */
1885 if (dwarf_attr (die
, DW_AT_artificial
))
1887 new_field
->accessibility
= DW_ACCESS_private
;
1888 fip
->non_public_fields
= 1;
1891 else if (die
->tag
== DW_TAG_variable
)
1895 /* C++ static member.
1896 Get name of field. */
1897 attr
= dwarf_attr (die
, DW_AT_name
);
1898 if (attr
&& DW_STRING (attr
))
1899 fieldname
= DW_STRING (attr
);
1903 /* Get physical name. */
1904 physname
= dwarf2_linkage_name (die
);
1906 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1907 &objfile
->type_obstack
));
1908 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1909 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1910 &objfile
->type_obstack
);
1912 else if (die
->tag
== DW_TAG_inheritance
)
1914 /* C++ base class field. */
1915 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1917 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
1919 FIELD_BITSIZE (*fp
) = 0;
1920 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1921 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1922 fip
->nbaseclasses
++;
1926 /* Create the vector of fields, and attach it to the type. */
1929 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
1930 struct objfile
*objfile
)
1932 int nfields
= fip
->nfields
;
1934 /* Record the field count, allocate space for the array of fields,
1935 and create blank accessibility bitfields if necessary. */
1936 TYPE_NFIELDS (type
) = nfields
;
1937 TYPE_FIELDS (type
) = (struct field
*)
1938 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1939 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1941 if (fip
->non_public_fields
)
1943 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1945 TYPE_FIELD_PRIVATE_BITS (type
) =
1946 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1947 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1949 TYPE_FIELD_PROTECTED_BITS (type
) =
1950 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1951 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1953 TYPE_FIELD_IGNORE_BITS (type
) =
1954 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1955 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1958 /* If the type has baseclasses, allocate and clear a bit vector for
1959 TYPE_FIELD_VIRTUAL_BITS. */
1960 if (fip
->nbaseclasses
)
1962 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
1965 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1966 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1967 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1968 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
1969 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
1972 /* Copy the saved-up fields into the field vector. Start from the head
1973 of the list, adding to the tail of the field array, so that they end
1974 up in the same order in the array in which they were added to the list. */
1975 while (nfields
-- > 0)
1977 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
1978 switch (fip
->fields
->accessibility
)
1980 case DW_ACCESS_private
:
1981 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
1984 case DW_ACCESS_protected
:
1985 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
1988 case DW_ACCESS_public
:
1992 /* Unknown accessibility. Complain and treat it as public. */
1994 complain (&dwarf2_unsupported_accessibility
,
1995 fip
->fields
->accessibility
);
1999 if (nfields
< fip
->nbaseclasses
)
2001 switch (fip
->fields
->virtuality
)
2003 case DW_VIRTUALITY_virtual
:
2004 case DW_VIRTUALITY_pure_virtual
:
2005 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2009 fip
->fields
= fip
->fields
->next
;
2013 /* Add a member function to the proper fieldlist. */
2016 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2017 struct type
*type
, struct objfile
*objfile
,
2018 const struct comp_unit_head
*cu_header
)
2020 struct attribute
*attr
;
2021 struct fnfieldlist
*flp
;
2023 struct fn_field
*fnp
;
2026 struct nextfnfield
*new_fnfield
;
2028 /* Get name of member function. */
2029 attr
= dwarf_attr (die
, DW_AT_name
);
2030 if (attr
&& DW_STRING (attr
))
2031 fieldname
= DW_STRING (attr
);
2035 /* Get the mangled name. */
2036 physname
= dwarf2_linkage_name (die
);
2038 /* Look up member function name in fieldlist. */
2039 for (i
= 0; i
< fip
->nfnfields
; i
++)
2041 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2045 /* Create new list element if necessary. */
2046 if (i
< fip
->nfnfields
)
2047 flp
= &fip
->fnfieldlists
[i
];
2050 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2052 fip
->fnfieldlists
= (struct fnfieldlist
*)
2053 xrealloc (fip
->fnfieldlists
,
2054 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2055 * sizeof (struct fnfieldlist
));
2056 if (fip
->nfnfields
== 0)
2057 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2059 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2060 flp
->name
= fieldname
;
2066 /* Create a new member function field and chain it to the field list
2068 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2069 make_cleanup (xfree
, new_fnfield
);
2070 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2071 new_fnfield
->next
= flp
->head
;
2072 flp
->head
= new_fnfield
;
2075 /* Fill in the member function field info. */
2076 fnp
= &new_fnfield
->fnfield
;
2077 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2078 &objfile
->type_obstack
);
2079 fnp
->type
= alloc_type (objfile
);
2080 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2082 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2083 struct type
**arg_types
;
2084 int nparams
= TYPE_NFIELDS (die
->type
);
2087 /* Copy argument types from the subroutine type. */
2088 arg_types
= (struct type
**)
2089 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2090 for (iparams
= 0; iparams
< nparams
; iparams
++)
2091 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2093 /* Set last entry in argument type vector. */
2094 if (TYPE_FLAGS (die
->type
) & TYPE_FLAG_VARARGS
)
2095 arg_types
[nparams
] = NULL
;
2097 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2099 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2101 /* Handle static member functions.
2102 Dwarf2 has no clean way to discern C++ static and non-static
2103 member functions. G++ helps GDB by marking the first
2104 parameter for non-static member functions (which is the
2105 this pointer) as artificial. We obtain this information
2106 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2107 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2108 fnp
->voffset
= VOFFSET_STATIC
;
2111 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2113 /* Get fcontext from DW_AT_containing_type if present. */
2114 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2115 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2117 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2118 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2120 /* Get accessibility. */
2121 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2124 switch (DW_UNSND (attr
))
2126 case DW_ACCESS_private
:
2127 fnp
->is_private
= 1;
2129 case DW_ACCESS_protected
:
2130 fnp
->is_protected
= 1;
2135 /* Get index in virtual function table if it is a virtual member function. */
2136 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2138 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2141 /* Create the vector of member function fields, and attach it to the type. */
2144 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2145 struct objfile
*objfile
)
2147 struct fnfieldlist
*flp
;
2148 int total_length
= 0;
2151 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2152 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2153 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2155 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2157 struct nextfnfield
*nfp
= flp
->head
;
2158 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2161 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2162 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2163 fn_flp
->fn_fields
= (struct fn_field
*)
2164 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2165 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2166 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2168 total_length
+= flp
->length
;
2171 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2172 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2175 /* Called when we find the DIE that starts a structure or union scope
2176 (definition) to process all dies that define the members of the
2179 NOTE: we need to call struct_type regardless of whether or not the
2180 DIE has an at_name attribute, since it might be an anonymous
2181 structure or union. This gets the type entered into our set of
2184 However, if the structure is incomplete (an opaque struct/union)
2185 then suppress creating a symbol table entry for it since gdb only
2186 wants to find the one with the complete definition. Note that if
2187 it is complete, we just call new_symbol, which does it's own
2188 checking about whether the struct/union is anonymous or not (and
2189 suppresses creating a symbol table entry itself). */
2192 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2193 const struct comp_unit_head
*cu_header
)
2196 struct attribute
*attr
;
2198 type
= alloc_type (objfile
);
2200 INIT_CPLUS_SPECIFIC (type
);
2201 attr
= dwarf_attr (die
, DW_AT_name
);
2202 if (attr
&& DW_STRING (attr
))
2204 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2205 strlen (DW_STRING (attr
)),
2206 &objfile
->type_obstack
);
2209 if (die
->tag
== DW_TAG_structure_type
)
2211 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2213 else if (die
->tag
== DW_TAG_union_type
)
2215 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2219 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2221 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2224 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2227 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2231 TYPE_LENGTH (type
) = 0;
2234 /* We need to add the type field to the die immediately so we don't
2235 infinitely recurse when dealing with pointers to the structure
2236 type within the structure itself. */
2239 if (die
->has_children
&& ! die_is_declaration (die
))
2241 struct field_info fi
;
2242 struct die_info
*child_die
;
2243 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2245 memset (&fi
, 0, sizeof (struct field_info
));
2247 child_die
= die
->next
;
2249 while (child_die
&& child_die
->tag
)
2251 if (child_die
->tag
== DW_TAG_member
)
2253 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2255 else if (child_die
->tag
== DW_TAG_variable
)
2257 /* C++ static member. */
2258 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2260 else if (child_die
->tag
== DW_TAG_subprogram
)
2262 /* C++ member function. */
2263 process_die (child_die
, objfile
, cu_header
);
2264 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2266 else if (child_die
->tag
== DW_TAG_inheritance
)
2268 /* C++ base class field. */
2269 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2273 process_die (child_die
, objfile
, cu_header
);
2275 child_die
= sibling_die (child_die
);
2278 /* Attach fields and member functions to the type. */
2280 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2283 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2285 /* Get the type which refers to the base class (possibly this
2286 class itself) which contains the vtable pointer for the current
2287 class from the DW_AT_containing_type attribute. */
2289 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2291 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2293 TYPE_VPTR_BASETYPE (type
) = t
;
2296 static const char vptr_name
[] =
2297 {'_', 'v', 'p', 't', 'r', '\0'};
2300 /* Our own class provides vtbl ptr. */
2301 for (i
= TYPE_NFIELDS (t
) - 1;
2302 i
>= TYPE_N_BASECLASSES (t
);
2305 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2307 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2308 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2310 TYPE_VPTR_FIELDNO (type
) = i
;
2315 /* Complain if virtual function table field not found. */
2316 if (i
< TYPE_N_BASECLASSES (t
))
2317 complain (&dwarf2_vtbl_not_found_complaint
,
2318 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2322 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2327 new_symbol (die
, type
, objfile
, cu_header
);
2329 do_cleanups (back_to
);
2333 /* No children, must be stub. */
2334 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2340 /* Given a pointer to a die which begins an enumeration, process all
2341 the dies that define the members of the enumeration.
2343 This will be much nicer in draft 6 of the DWARF spec when our
2344 members will be dies instead squished into the DW_AT_element_list
2347 NOTE: We reverse the order of the element list. */
2350 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2351 const struct comp_unit_head
*cu_header
)
2353 struct die_info
*child_die
;
2355 struct field
*fields
;
2356 struct attribute
*attr
;
2359 int unsigned_enum
= 1;
2361 type
= alloc_type (objfile
);
2363 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2364 attr
= dwarf_attr (die
, DW_AT_name
);
2365 if (attr
&& DW_STRING (attr
))
2367 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2368 strlen (DW_STRING (attr
)),
2369 &objfile
->type_obstack
);
2372 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2375 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2379 TYPE_LENGTH (type
) = 0;
2384 if (die
->has_children
)
2386 child_die
= die
->next
;
2387 while (child_die
&& child_die
->tag
)
2389 if (child_die
->tag
!= DW_TAG_enumerator
)
2391 process_die (child_die
, objfile
, cu_header
);
2395 attr
= dwarf_attr (child_die
, DW_AT_name
);
2398 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2399 if (SYMBOL_VALUE (sym
) < 0)
2402 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2404 fields
= (struct field
*)
2406 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2407 * sizeof (struct field
));
2410 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2411 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2412 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2413 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2419 child_die
= sibling_die (child_die
);
2424 TYPE_NFIELDS (type
) = num_fields
;
2425 TYPE_FIELDS (type
) = (struct field
*)
2426 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2427 memcpy (TYPE_FIELDS (type
), fields
,
2428 sizeof (struct field
) * num_fields
);
2432 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2435 new_symbol (die
, type
, objfile
, cu_header
);
2438 /* Extract all information from a DW_TAG_array_type DIE and put it in
2439 the DIE's type field. For now, this only handles one dimensional
2443 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
2444 const struct comp_unit_head
*cu_header
)
2446 struct die_info
*child_die
;
2447 struct type
*type
= NULL
;
2448 struct type
*element_type
, *range_type
, *index_type
;
2449 struct type
**range_types
= NULL
;
2450 struct attribute
*attr
;
2452 struct cleanup
*back_to
;
2454 /* Return if we've already decoded this type. */
2460 element_type
= die_type (die
, objfile
, cu_header
);
2462 /* Irix 6.2 native cc creates array types without children for
2463 arrays with unspecified length. */
2464 if (die
->has_children
== 0)
2466 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2467 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2468 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2472 back_to
= make_cleanup (null_cleanup
, NULL
);
2473 child_die
= die
->next
;
2474 while (child_die
&& child_die
->tag
)
2476 if (child_die
->tag
== DW_TAG_subrange_type
)
2478 unsigned int low
, high
;
2480 /* Default bounds to an array with unspecified length. */
2483 if (cu_language
== language_fortran
)
2485 /* FORTRAN implies a lower bound of 1, if not given. */
2489 index_type
= die_type (child_die
, objfile
, cu_header
);
2490 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2493 if (attr
->form
== DW_FORM_sdata
)
2495 low
= DW_SND (attr
);
2497 else if (attr
->form
== DW_FORM_udata
2498 || attr
->form
== DW_FORM_data1
2499 || attr
->form
== DW_FORM_data2
2500 || attr
->form
== DW_FORM_data4
)
2502 low
= DW_UNSND (attr
);
2506 complain (&dwarf2_non_const_array_bound_ignored
,
2507 dwarf_form_name (attr
->form
));
2509 die
->type
= lookup_pointer_type (element_type
);
2516 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2519 if (attr
->form
== DW_FORM_sdata
)
2521 high
= DW_SND (attr
);
2523 else if (attr
->form
== DW_FORM_udata
2524 || attr
->form
== DW_FORM_data1
2525 || attr
->form
== DW_FORM_data2
2526 || attr
->form
== DW_FORM_data4
)
2528 high
= DW_UNSND (attr
);
2530 else if (attr
->form
== DW_FORM_block1
)
2532 /* GCC encodes arrays with unspecified or dynamic length
2533 with a DW_FORM_block1 attribute.
2534 FIXME: GDB does not yet know how to handle dynamic
2535 arrays properly, treat them as arrays with unspecified
2541 complain (&dwarf2_non_const_array_bound_ignored
,
2542 dwarf_form_name (attr
->form
));
2544 die
->type
= lookup_pointer_type (element_type
);
2552 /* Create a range type and save it for array type creation. */
2553 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2555 range_types
= (struct type
**)
2556 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2557 * sizeof (struct type
*));
2559 make_cleanup (free_current_contents
, &range_types
);
2561 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2563 child_die
= sibling_die (child_die
);
2566 /* Dwarf2 dimensions are output from left to right, create the
2567 necessary array types in backwards order. */
2568 type
= element_type
;
2570 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2572 do_cleanups (back_to
);
2574 /* Install the type in the die. */
2578 /* First cut: install each common block member as a global variable. */
2581 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
2582 const struct comp_unit_head
*cu_header
)
2584 struct die_info
*child_die
;
2585 struct attribute
*attr
;
2587 CORE_ADDR base
= (CORE_ADDR
) 0;
2589 attr
= dwarf_attr (die
, DW_AT_location
);
2592 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2594 if (die
->has_children
)
2596 child_die
= die
->next
;
2597 while (child_die
&& child_die
->tag
)
2599 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
2600 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2603 SYMBOL_VALUE_ADDRESS (sym
) =
2604 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2605 add_symbol_to_list (sym
, &global_symbols
);
2607 child_die
= sibling_die (child_die
);
2612 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2613 the user defined type vector. */
2616 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
2617 const struct comp_unit_head
*cu_header
)
2620 struct attribute
*attr
;
2627 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
2628 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2631 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2635 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2640 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2641 the user defined type vector. */
2644 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
2645 const struct comp_unit_head
*cu_header
)
2648 struct type
*to_type
;
2649 struct type
*domain
;
2656 type
= alloc_type (objfile
);
2657 to_type
= die_type (die
, objfile
, cu_header
);
2658 domain
= die_containing_type (die
, objfile
, cu_header
);
2659 smash_to_member_type (type
, domain
, to_type
);
2664 /* Extract all information from a DW_TAG_reference_type DIE and add to
2665 the user defined type vector. */
2668 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
2669 const struct comp_unit_head
*cu_header
)
2672 struct attribute
*attr
;
2679 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
2680 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2683 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2687 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2693 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
2694 const struct comp_unit_head
*cu_header
)
2696 struct type
*base_type
;
2703 base_type
= die_type (die
, objfile
, cu_header
);
2704 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
2708 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
2709 const struct comp_unit_head
*cu_header
)
2711 struct type
*base_type
;
2718 base_type
= die_type (die
, objfile
, cu_header
);
2719 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
2722 /* Extract all information from a DW_TAG_string_type DIE and add to
2723 the user defined type vector. It isn't really a user defined type,
2724 but it behaves like one, with other DIE's using an AT_user_def_type
2725 attribute to reference it. */
2728 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
2730 struct type
*type
, *range_type
, *index_type
, *char_type
;
2731 struct attribute
*attr
;
2732 unsigned int length
;
2739 attr
= dwarf_attr (die
, DW_AT_string_length
);
2742 length
= DW_UNSND (attr
);
2748 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2749 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2750 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2751 type
= create_string_type (char_type
, range_type
);
2755 /* Handle DIES due to C code like:
2759 int (*funcp)(int a, long l);
2763 ('funcp' generates a DW_TAG_subroutine_type DIE)
2767 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
2768 const struct comp_unit_head
*cu_header
)
2770 struct type
*type
; /* Type that this function returns */
2771 struct type
*ftype
; /* Function that returns above type */
2772 struct attribute
*attr
;
2774 /* Decode the type that this subroutine returns */
2779 type
= die_type (die
, objfile
, cu_header
);
2780 ftype
= lookup_function_type (type
);
2782 /* All functions in C++ have prototypes. */
2783 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2784 if ((attr
&& (DW_UNSND (attr
) != 0))
2785 || cu_language
== language_cplus
)
2786 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2788 if (die
->has_children
)
2790 struct die_info
*child_die
;
2794 /* Count the number of parameters.
2795 FIXME: GDB currently ignores vararg functions, but knows about
2796 vararg member functions. */
2797 child_die
= die
->next
;
2798 while (child_die
&& child_die
->tag
)
2800 if (child_die
->tag
== DW_TAG_formal_parameter
)
2802 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2803 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2804 child_die
= sibling_die (child_die
);
2807 /* Allocate storage for parameters and fill them in. */
2808 TYPE_NFIELDS (ftype
) = nparams
;
2809 TYPE_FIELDS (ftype
) = (struct field
*)
2810 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2812 child_die
= die
->next
;
2813 while (child_die
&& child_die
->tag
)
2815 if (child_die
->tag
== DW_TAG_formal_parameter
)
2817 /* Dwarf2 has no clean way to discern C++ static and non-static
2818 member functions. G++ helps GDB by marking the first
2819 parameter for non-static member functions (which is the
2820 this pointer) as artificial. We pass this information
2821 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2822 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2824 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2826 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2827 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
2831 child_die
= sibling_die (child_die
);
2839 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
2840 const struct comp_unit_head
*cu_header
)
2846 struct attribute
*attr
;
2849 xtype
= die_type (die
, objfile
, cu_header
);
2851 type
= alloc_type (objfile
);
2852 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2853 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2854 TYPE_TARGET_TYPE (type
) = xtype
;
2855 attr
= dwarf_attr (die
, DW_AT_name
);
2856 if (attr
&& DW_STRING (attr
))
2857 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2858 strlen (DW_STRING (attr
)),
2859 &objfile
->type_obstack
);
2865 /* Find a representation of a given base type and install
2866 it in the TYPE field of the die. */
2869 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
2872 struct attribute
*attr
;
2873 int encoding
= 0, size
= 0;
2875 /* If we've already decoded this die, this is a no-op. */
2881 attr
= dwarf_attr (die
, DW_AT_encoding
);
2884 encoding
= DW_UNSND (attr
);
2886 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2889 size
= DW_UNSND (attr
);
2891 attr
= dwarf_attr (die
, DW_AT_name
);
2892 if (attr
&& DW_STRING (attr
))
2894 enum type_code code
= TYPE_CODE_INT
;
2895 int is_unsigned
= 0;
2899 case DW_ATE_address
:
2900 /* Turn DW_ATE_address into a void * pointer. */
2901 code
= TYPE_CODE_PTR
;
2904 case DW_ATE_boolean
:
2905 code
= TYPE_CODE_BOOL
;
2908 case DW_ATE_complex_float
:
2909 code
= TYPE_CODE_COMPLEX
;
2912 code
= TYPE_CODE_FLT
;
2915 case DW_ATE_signed_char
:
2917 case DW_ATE_unsigned
:
2918 case DW_ATE_unsigned_char
:
2922 complain (&dwarf2_unsupported_at_encoding
,
2923 dwarf_type_encoding_name (encoding
));
2926 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2927 if (encoding
== DW_ATE_address
)
2928 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2932 type
= dwarf_base_type (encoding
, size
, objfile
);
2937 /* Read a whole compilation unit into a linked list of dies. */
2939 static struct die_info
*
2940 read_comp_unit (char *info_ptr
, bfd
*abfd
,
2941 const struct comp_unit_head
*cu_header
)
2943 struct die_info
*first_die
, *last_die
, *die
;
2947 /* Reset die reference table; we are
2948 building new ones now. */
2949 dwarf2_empty_hash_tables ();
2953 first_die
= last_die
= NULL
;
2956 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
2957 if (die
->has_children
)
2968 /* Enter die in reference hash table */
2969 store_in_ref_table (die
->offset
, die
);
2973 first_die
= last_die
= die
;
2977 last_die
->next
= die
;
2981 while (nesting_level
> 0);
2985 /* Free a linked list of dies. */
2988 free_die_list (struct die_info
*dies
)
2990 struct die_info
*die
, *next
;
3003 do_free_die_list_cleanup (void *dies
)
3005 free_die_list (dies
);
3008 static struct cleanup
*
3009 make_cleanup_free_die_list (struct die_info
*dies
)
3011 return make_cleanup (do_free_die_list_cleanup
, dies
);
3015 /* Read the contents of the section at OFFSET and of size SIZE from the
3016 object file specified by OBJFILE into the psymbol_obstack and return it. */
3019 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
3022 bfd
*abfd
= objfile
->obfd
;
3028 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3029 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3030 (bfd_bread (buf
, size
, abfd
) != size
))
3033 error ("Dwarf Error: Can't read DWARF data from '%s'",
3034 bfd_get_filename (abfd
));
3039 /* In DWARF version 2, the description of the debugging information is
3040 stored in a separate .debug_abbrev section. Before we read any
3041 dies from a section we read in all abbreviations and install them
3045 dwarf2_read_abbrevs (bfd
*abfd
, unsigned int offset
)
3048 struct abbrev_info
*cur_abbrev
;
3049 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3050 unsigned int abbrev_form
, hash_number
;
3052 /* empty the table */
3053 dwarf2_empty_abbrev_table (NULL
);
3055 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3056 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3057 abbrev_ptr
+= bytes_read
;
3059 /* loop until we reach an abbrev number of 0 */
3060 while (abbrev_number
)
3062 cur_abbrev
= dwarf_alloc_abbrev ();
3064 /* read in abbrev header */
3065 cur_abbrev
->number
= abbrev_number
;
3066 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3067 abbrev_ptr
+= bytes_read
;
3068 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3071 /* now read in declarations */
3072 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3073 abbrev_ptr
+= bytes_read
;
3074 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3075 abbrev_ptr
+= bytes_read
;
3078 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3080 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3081 xrealloc (cur_abbrev
->attrs
,
3082 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3083 * sizeof (struct attr_abbrev
));
3085 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3086 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3087 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3088 abbrev_ptr
+= bytes_read
;
3089 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3090 abbrev_ptr
+= bytes_read
;
3093 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3094 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3095 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3097 /* Get next abbreviation.
3098 Under Irix6 the abbreviations for a compilation unit are not
3099 always properly terminated with an abbrev number of 0.
3100 Exit loop if we encounter an abbreviation which we have
3101 already read (which means we are about to read the abbreviations
3102 for the next compile unit) or if the end of the abbreviation
3103 table is reached. */
3104 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3105 >= dwarf_abbrev_size
)
3107 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3108 abbrev_ptr
+= bytes_read
;
3109 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3114 /* Empty the abbrev table for a new compilation unit. */
3118 dwarf2_empty_abbrev_table (PTR ignore
)
3121 struct abbrev_info
*abbrev
, *next
;
3123 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3126 abbrev
= dwarf2_abbrevs
[i
];
3129 next
= abbrev
->next
;
3130 xfree (abbrev
->attrs
);
3134 dwarf2_abbrevs
[i
] = NULL
;
3138 /* Lookup an abbrev_info structure in the abbrev hash table. */
3140 static struct abbrev_info
*
3141 dwarf2_lookup_abbrev (unsigned int number
)
3143 unsigned int hash_number
;
3144 struct abbrev_info
*abbrev
;
3146 hash_number
= number
% ABBREV_HASH_SIZE
;
3147 abbrev
= dwarf2_abbrevs
[hash_number
];
3151 if (abbrev
->number
== number
)
3154 abbrev
= abbrev
->next
;
3159 /* Read a minimal amount of information into the minimal die structure. */
3162 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3163 char *info_ptr
, const struct comp_unit_head
*cu_header
)
3165 unsigned int abbrev_number
, bytes_read
, i
;
3166 struct abbrev_info
*abbrev
;
3167 struct attribute attr
;
3168 struct attribute spec_attr
;
3169 int found_spec_attr
= 0;
3170 int has_low_pc_attr
= 0;
3171 int has_high_pc_attr
= 0;
3173 *part_die
= zeroed_partial_die
;
3174 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3175 info_ptr
+= bytes_read
;
3179 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3182 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3184 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3185 part_die
->tag
= abbrev
->tag
;
3186 part_die
->has_children
= abbrev
->has_children
;
3187 part_die
->abbrev
= abbrev_number
;
3189 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3191 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3192 info_ptr
, cu_header
);
3194 /* Store the data if it is of an attribute we want to keep in a
3195 partial symbol table. */
3200 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3201 if (part_die
->name
== NULL
)
3202 part_die
->name
= DW_STRING (&attr
);
3204 case DW_AT_MIPS_linkage_name
:
3205 part_die
->name
= DW_STRING (&attr
);
3208 has_low_pc_attr
= 1;
3209 part_die
->lowpc
= DW_ADDR (&attr
);
3212 has_high_pc_attr
= 1;
3213 part_die
->highpc
= DW_ADDR (&attr
);
3215 case DW_AT_location
:
3216 part_die
->locdesc
= DW_BLOCK (&attr
);
3218 case DW_AT_language
:
3219 part_die
->language
= DW_UNSND (&attr
);
3221 case DW_AT_external
:
3222 part_die
->is_external
= DW_UNSND (&attr
);
3224 case DW_AT_declaration
:
3225 part_die
->is_declaration
= DW_UNSND (&attr
);
3228 part_die
->has_type
= 1;
3230 case DW_AT_abstract_origin
:
3231 case DW_AT_specification
:
3232 found_spec_attr
= 1;
3236 /* Ignore absolute siblings, they might point outside of
3237 the current compile unit. */
3238 if (attr
.form
== DW_FORM_ref_addr
)
3239 complain (&dwarf2_absolute_sibling_complaint
);
3242 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3249 /* If we found a reference attribute and the die has no name, try
3250 to find a name in the referred to die. */
3252 if (found_spec_attr
&& part_die
->name
== NULL
)
3254 struct partial_die_info spec_die
;
3258 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3259 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu_header
);
3262 part_die
->name
= spec_die
.name
;
3264 /* Copy DW_AT_external attribute if it is set. */
3265 if (spec_die
.is_external
)
3266 part_die
->is_external
= spec_die
.is_external
;
3270 /* When using the GNU linker, .gnu.linkonce. sections are used to
3271 eliminate duplicate copies of functions and vtables and such.
3272 The linker will arbitrarily choose one and discard the others.
3273 The AT_*_pc values for such functions refer to local labels in
3274 these sections. If the section from that file was discarded, the
3275 labels are not in the output, so the relocs get a value of 0.
3276 If this is a discarded function, mark the pc bounds as invalid,
3277 so that GDB will ignore it. */
3278 if (has_low_pc_attr
&& has_high_pc_attr
3279 && part_die
->lowpc
< part_die
->highpc
3280 && (part_die
->lowpc
!= 0
3281 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3282 part_die
->has_pc_info
= 1;
3286 /* Read the die from the .debug_info section buffer. And set diep to
3287 point to a newly allocated die with its information. */
3290 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3291 const struct comp_unit_head
*cu_header
)
3293 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3294 struct abbrev_info
*abbrev
;
3295 struct die_info
*die
;
3297 offset
= info_ptr
- dwarf_info_buffer
;
3298 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3299 info_ptr
+= bytes_read
;
3302 die
= dwarf_alloc_die ();
3304 die
->abbrev
= abbrev_number
;
3310 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3313 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3315 die
= dwarf_alloc_die ();
3316 die
->offset
= offset
;
3317 die
->tag
= abbrev
->tag
;
3318 die
->has_children
= abbrev
->has_children
;
3319 die
->abbrev
= abbrev_number
;
3322 die
->num_attrs
= abbrev
->num_attrs
;
3323 die
->attrs
= (struct attribute
*)
3324 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3326 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3328 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3329 abfd
, info_ptr
, cu_header
);
3336 /* Read an attribute described by an abbreviated attribute. */
3339 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
3340 bfd
*abfd
, char *info_ptr
,
3341 const struct comp_unit_head
*cu_header
)
3343 unsigned int bytes_read
;
3344 struct dwarf_block
*blk
;
3346 attr
->name
= abbrev
->name
;
3347 attr
->form
= abbrev
->form
;
3348 switch (abbrev
->form
)
3351 case DW_FORM_ref_addr
:
3352 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3353 info_ptr
+= bytes_read
;
3355 case DW_FORM_block2
:
3356 blk
= dwarf_alloc_block ();
3357 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3359 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3360 info_ptr
+= blk
->size
;
3361 DW_BLOCK (attr
) = blk
;
3363 case DW_FORM_block4
:
3364 blk
= dwarf_alloc_block ();
3365 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3367 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3368 info_ptr
+= blk
->size
;
3369 DW_BLOCK (attr
) = blk
;
3372 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3376 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3380 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3383 case DW_FORM_string
:
3384 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3385 info_ptr
+= bytes_read
;
3388 blk
= dwarf_alloc_block ();
3389 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3390 info_ptr
+= bytes_read
;
3391 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3392 info_ptr
+= blk
->size
;
3393 DW_BLOCK (attr
) = blk
;
3395 case DW_FORM_block1
:
3396 blk
= dwarf_alloc_block ();
3397 blk
->size
= read_1_byte (abfd
, info_ptr
);
3399 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3400 info_ptr
+= blk
->size
;
3401 DW_BLOCK (attr
) = blk
;
3404 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3408 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3412 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3413 info_ptr
+= bytes_read
;
3416 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3417 info_ptr
+= bytes_read
;
3420 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3424 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3428 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3432 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3435 case DW_FORM_ref_udata
:
3436 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3437 info_ptr
+= bytes_read
;
3440 case DW_FORM_indirect
:
3442 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3443 dwarf_form_name (abbrev
->form
));
3448 /* read dwarf information from a buffer */
3451 read_1_byte (bfd
*abfd
, char *buf
)
3453 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3457 read_1_signed_byte (bfd
*abfd
, char *buf
)
3459 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3463 read_2_bytes (bfd
*abfd
, char *buf
)
3465 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3469 read_2_signed_bytes (bfd
*abfd
, char *buf
)
3471 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3475 read_4_bytes (bfd
*abfd
, char *buf
)
3477 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3481 read_4_signed_bytes (bfd
*abfd
, char *buf
)
3483 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3486 static unsigned long
3487 read_8_bytes (bfd
*abfd
, char *buf
)
3489 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3493 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3496 CORE_ADDR retval
= 0;
3498 if (cu_header
->signed_addr_p
)
3500 switch (cu_header
->addr_size
)
3503 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3506 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3509 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
3512 internal_error (__FILE__
, __LINE__
,
3513 "read_address: bad switch, signed");
3518 switch (cu_header
->addr_size
)
3521 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3524 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3527 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3530 internal_error (__FILE__
, __LINE__
,
3531 "read_address: bad switch, unsigned");
3535 *bytes_read
= cu_header
->addr_size
;
3539 /* Reads the initial length from a section. The (draft) DWARF 2.1
3540 specification allows the initial length to take up either 4 bytes
3541 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
3542 bytes describe the length and all offsets will be 8 bytes in length
3545 The value returned via bytes_read should be used to increment
3546 the relevant pointer after calling read_initial_length().
3548 As a side effect, this function sets the fields initial_length_size
3549 and offset_size in cu_header to the values appropriate for the
3550 length field. (The format of the initial length field determines
3551 the width of file offsets to be fetched later with fetch_offset().)
3553 [ Note: read_initial_length() and read_offset() are based on the
3554 document entitled "DWARF Debugging Information Format", revision
3555 2.1, draft 4, dated July 20, 2000. This document was obtained
3558 http://reality.sgi.com/dehnert_engr/dwarf/dwarf2p1-draft4-000720.pdf
3560 This document is only a draft and is subject to change. (So beware.)
3562 - Kevin, Aug 4, 2000
3566 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
3571 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3573 if (retval
== 0xffffffff)
3575 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
3577 if (cu_header
!= NULL
)
3579 cu_header
->initial_length_size
= 12;
3580 cu_header
->offset_size
= 8;
3586 if (cu_header
!= NULL
)
3588 cu_header
->initial_length_size
= 4;
3589 cu_header
->offset_size
= 4;
3596 /* Read an offset from the data stream. The size of the offset is
3597 given by cu_header->offset_size. */
3600 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3605 switch (cu_header
->offset_size
)
3608 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3612 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3616 internal_error (__FILE__
, __LINE__
,
3617 "read_offset: bad switch");
3624 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
3626 /* If the size of a host char is 8 bits, we can return a pointer
3627 to the buffer, otherwise we have to copy the data to a buffer
3628 allocated on the temporary obstack. */
3629 #if HOST_CHAR_BIT == 8
3635 ret
= obstack_alloc (&dwarf2_tmp_obstack
, size
);
3636 for (i
= 0; i
< size
; ++i
)
3638 ret
[i
] = bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3646 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3648 /* If the size of a host char is 8 bits, we can return a pointer
3649 to the string, otherwise we have to copy the string to a buffer
3650 allocated on the temporary obstack. */
3651 #if HOST_CHAR_BIT == 8
3654 *bytes_read_ptr
= 1;
3657 *bytes_read_ptr
= strlen (buf
) + 1;
3663 while ((byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
)) != 0)
3665 obstack_1grow (&dwarf2_tmp_obstack
, byte
);
3671 *bytes_read_ptr
= 1;
3674 obstack_1grow (&dwarf2_tmp_obstack
, '\0');
3675 *bytes_read_ptr
= i
+ 1;
3676 return obstack_finish (&dwarf2_tmp_obstack
);
3680 static unsigned long
3681 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3683 unsigned long result
;
3684 unsigned int num_read
;
3694 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3697 result
|= ((unsigned long)(byte
& 127) << shift
);
3698 if ((byte
& 128) == 0)
3704 *bytes_read_ptr
= num_read
;
3709 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3712 int i
, shift
, size
, num_read
;
3722 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3725 result
|= ((long)(byte
& 127) << shift
);
3727 if ((byte
& 128) == 0)
3732 if ((shift
< size
) && (byte
& 0x40))
3734 result
|= -(1 << shift
);
3736 *bytes_read_ptr
= num_read
;
3741 set_cu_language (unsigned int lang
)
3747 cu_language
= language_c
;
3749 case DW_LANG_C_plus_plus
:
3750 cu_language
= language_cplus
;
3752 case DW_LANG_Fortran77
:
3753 case DW_LANG_Fortran90
:
3754 cu_language
= language_fortran
;
3756 case DW_LANG_Mips_Assembler
:
3757 cu_language
= language_asm
;
3760 cu_language
= language_java
;
3763 case DW_LANG_Cobol74
:
3764 case DW_LANG_Cobol85
:
3765 case DW_LANG_Pascal83
:
3766 case DW_LANG_Modula2
:
3768 cu_language
= language_unknown
;
3771 cu_language_defn
= language_def (cu_language
);
3774 /* Return the named attribute or NULL if not there. */
3776 static struct attribute
*
3777 dwarf_attr (struct die_info
*die
, unsigned int name
)
3780 struct attribute
*spec
= NULL
;
3782 for (i
= 0; i
< die
->num_attrs
; ++i
)
3784 if (die
->attrs
[i
].name
== name
)
3786 return &die
->attrs
[i
];
3788 if (die
->attrs
[i
].name
== DW_AT_specification
3789 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3790 spec
= &die
->attrs
[i
];
3794 struct die_info
*ref_die
=
3795 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3798 return dwarf_attr (ref_die
, name
);
3805 die_is_declaration (struct die_info
*die
)
3807 return (dwarf_attr (die
, DW_AT_declaration
)
3808 && ! dwarf_attr (die
, DW_AT_specification
));
3811 /* Decode the line number information for the compilation unit whose
3812 line number info is at OFFSET in the .debug_line section.
3813 The compilation directory of the file is passed in COMP_DIR. */
3817 unsigned int num_files
;
3830 unsigned int num_dirs
;
3835 dwarf_decode_lines (unsigned int offset
, char *comp_dir
, bfd
*abfd
,
3836 const struct comp_unit_head
*cu_header
)
3840 struct line_head lh
;
3841 struct cleanup
*back_to
;
3842 unsigned int i
, bytes_read
;
3843 char *cur_file
, *cur_dir
;
3844 unsigned char op_code
, extended_op
, adj_opcode
;
3846 #define FILE_ALLOC_CHUNK 5
3847 #define DIR_ALLOC_CHUNK 5
3849 struct filenames files
;
3850 struct directories dirs
;
3852 if (dwarf_line_buffer
== NULL
)
3854 complain (&dwarf2_missing_line_number_section
);
3858 files
.num_files
= 0;
3864 line_ptr
= dwarf_line_buffer
+ offset
;
3866 /* read in the prologue */
3867 lh
.total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
3868 line_ptr
+= bytes_read
;
3869 line_end
= line_ptr
+ lh
.total_length
;
3870 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3872 lh
.prologue_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
3873 line_ptr
+= bytes_read
;
3874 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3876 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3878 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3880 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3882 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3884 lh
.standard_opcode_lengths
= (unsigned char *)
3885 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3886 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
3888 lh
.standard_opcode_lengths
[0] = 1;
3889 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3891 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3895 /* Read directory table */
3896 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3898 line_ptr
+= bytes_read
;
3899 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3901 dirs
.dirs
= (char **)
3902 xrealloc (dirs
.dirs
,
3903 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3904 if (dirs
.num_dirs
== 0)
3905 make_cleanup (free_current_contents
, &dirs
.dirs
);
3907 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3909 line_ptr
+= bytes_read
;
3911 /* Read file name table */
3912 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3914 line_ptr
+= bytes_read
;
3915 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3917 files
.files
= (struct fileinfo
*)
3918 xrealloc (files
.files
,
3919 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3920 * sizeof (struct fileinfo
));
3921 if (files
.num_files
== 0)
3922 make_cleanup (free_current_contents
, &files
.files
);
3924 files
.files
[files
.num_files
].name
= cur_file
;
3925 files
.files
[files
.num_files
].dir
=
3926 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3927 line_ptr
+= bytes_read
;
3928 files
.files
[files
.num_files
].time
=
3929 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3930 line_ptr
+= bytes_read
;
3931 files
.files
[files
.num_files
].size
=
3932 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3933 line_ptr
+= bytes_read
;
3936 line_ptr
+= bytes_read
;
3938 /* Read the statement sequences until there's nothing left. */
3939 while (line_ptr
< line_end
)
3941 /* state machine registers */
3942 CORE_ADDR address
= 0;
3943 unsigned int file
= 1;
3944 unsigned int line
= 1;
3945 unsigned int column
= 0;
3946 int is_stmt
= lh
.default_is_stmt
;
3947 int basic_block
= 0;
3948 int end_sequence
= 0;
3950 /* Start a subfile for the current file of the state machine. */
3951 if (files
.num_files
>= file
)
3953 /* The file and directory tables are 0 based, the references
3955 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3956 (files
.files
[file
- 1].dir
3957 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3961 /* Decode the table. */
3962 while (!end_sequence
)
3964 op_code
= read_1_byte (abfd
, line_ptr
);
3968 case DW_LNS_extended_op
:
3969 line_ptr
+= 1; /* ignore length */
3970 extended_op
= read_1_byte (abfd
, line_ptr
);
3972 switch (extended_op
)
3974 case DW_LNE_end_sequence
:
3976 /* Don't call record_line here. The end_sequence
3977 instruction provides the address of the first byte
3978 *after* the last line in the sequence; it's not the
3979 address of any real source line. However, the GDB
3980 linetable structure only records the starts of lines,
3981 not the ends. This is a weakness of GDB. */
3983 case DW_LNE_set_address
:
3984 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
3985 line_ptr
+= bytes_read
;
3986 address
+= baseaddr
;
3988 case DW_LNE_define_file
:
3989 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
3990 line_ptr
+= bytes_read
;
3991 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3993 files
.files
= (struct fileinfo
*)
3994 xrealloc (files
.files
,
3995 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3996 * sizeof (struct fileinfo
));
3997 if (files
.num_files
== 0)
3998 make_cleanup (free_current_contents
, &files
.files
);
4000 files
.files
[files
.num_files
].name
= cur_file
;
4001 files
.files
[files
.num_files
].dir
=
4002 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4003 line_ptr
+= bytes_read
;
4004 files
.files
[files
.num_files
].time
=
4005 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4006 line_ptr
+= bytes_read
;
4007 files
.files
[files
.num_files
].size
=
4008 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4009 line_ptr
+= bytes_read
;
4013 complain (&dwarf2_mangled_line_number_section
);
4018 record_line (current_subfile
, line
, address
);
4021 case DW_LNS_advance_pc
:
4022 address
+= lh
.minimum_instruction_length
4023 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4024 line_ptr
+= bytes_read
;
4026 case DW_LNS_advance_line
:
4027 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
4028 line_ptr
+= bytes_read
;
4030 case DW_LNS_set_file
:
4031 /* The file and directory tables are 0 based, the references
4033 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4034 line_ptr
+= bytes_read
;
4035 dwarf2_start_subfile
4036 (files
.files
[file
- 1].name
,
4037 (files
.files
[file
- 1].dir
4038 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
4041 case DW_LNS_set_column
:
4042 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4043 line_ptr
+= bytes_read
;
4045 case DW_LNS_negate_stmt
:
4046 is_stmt
= (!is_stmt
);
4048 case DW_LNS_set_basic_block
:
4051 /* Add to the address register of the state machine the
4052 address increment value corresponding to special opcode
4053 255. Ie, this value is scaled by the minimum instruction
4054 length since special opcode 255 would have scaled the
4056 case DW_LNS_const_add_pc
:
4057 address
+= (lh
.minimum_instruction_length
4058 * ((255 - lh
.opcode_base
) / lh
.line_range
));
4060 case DW_LNS_fixed_advance_pc
:
4061 address
+= read_2_bytes (abfd
, line_ptr
);
4064 default: /* special operand */
4065 adj_opcode
= op_code
- lh
.opcode_base
;
4066 address
+= (adj_opcode
/ lh
.line_range
)
4067 * lh
.minimum_instruction_length
;
4068 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
4069 /* append row to matrix using current values */
4070 record_line (current_subfile
, line
, address
);
4076 do_cleanups (back_to
);
4079 /* Start a subfile for DWARF. FILENAME is the name of the file and
4080 DIRNAME the name of the source directory which contains FILENAME
4081 or NULL if not known.
4082 This routine tries to keep line numbers from identical absolute and
4083 relative file names in a common subfile.
4085 Using the `list' example from the GDB testsuite, which resides in
4086 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4087 of /srcdir/list0.c yields the following debugging information for list0.c:
4089 DW_AT_name: /srcdir/list0.c
4090 DW_AT_comp_dir: /compdir
4091 files.files[0].name: list0.h
4092 files.files[0].dir: /srcdir
4093 files.files[1].name: list0.c
4094 files.files[1].dir: /srcdir
4096 The line number information for list0.c has to end up in a single
4097 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4100 dwarf2_start_subfile (char *filename
, char *dirname
)
4102 /* If the filename isn't absolute, try to match an existing subfile
4103 with the full pathname. */
4105 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
4107 struct subfile
*subfile
;
4108 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4110 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4112 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
4114 current_subfile
= subfile
;
4121 start_subfile (filename
, dirname
);
4124 /* Given a pointer to a DWARF information entry, figure out if we need
4125 to make a symbol table entry for it, and if so, create a new entry
4126 and return a pointer to it.
4127 If TYPE is NULL, determine symbol type from the die, otherwise
4128 used the passed type. */
4130 static struct symbol
*
4131 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
4132 const struct comp_unit_head
*cu_header
)
4134 struct symbol
*sym
= NULL
;
4136 struct attribute
*attr
= NULL
;
4137 struct attribute
*attr2
= NULL
;
4140 name
= dwarf2_linkage_name (die
);
4143 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4144 sizeof (struct symbol
));
4145 OBJSTAT (objfile
, n_syms
++);
4146 memset (sym
, 0, sizeof (struct symbol
));
4147 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4148 &objfile
->symbol_obstack
);
4150 /* Default assumptions.
4151 Use the passed type or decode it from the die. */
4152 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4153 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4155 SYMBOL_TYPE (sym
) = type
;
4157 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
4158 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4161 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4164 /* If this symbol is from a C++ compilation, then attempt to
4165 cache the demangled form for future reference. This is a
4166 typical time versus space tradeoff, that was decided in favor
4167 of time because it sped up C++ symbol lookups by a factor of
4170 SYMBOL_LANGUAGE (sym
) = cu_language
;
4171 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4175 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4178 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4180 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4182 case DW_TAG_subprogram
:
4183 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4185 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4186 attr2
= dwarf_attr (die
, DW_AT_external
);
4187 if (attr2
&& (DW_UNSND (attr2
) != 0))
4189 add_symbol_to_list (sym
, &global_symbols
);
4193 add_symbol_to_list (sym
, list_in_scope
);
4196 case DW_TAG_variable
:
4197 /* Compilation with minimal debug info may result in variables
4198 with missing type entries. Change the misleading `void' type
4199 to something sensible. */
4200 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4201 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4202 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4203 "<variable, no debug info>",
4205 attr
= dwarf_attr (die
, DW_AT_const_value
);
4208 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4209 attr2
= dwarf_attr (die
, DW_AT_external
);
4210 if (attr2
&& (DW_UNSND (attr2
) != 0))
4211 add_symbol_to_list (sym
, &global_symbols
);
4213 add_symbol_to_list (sym
, list_in_scope
);
4216 attr
= dwarf_attr (die
, DW_AT_location
);
4219 attr2
= dwarf_attr (die
, DW_AT_external
);
4220 if (attr2
&& (DW_UNSND (attr2
) != 0))
4222 SYMBOL_VALUE_ADDRESS (sym
) =
4223 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4224 add_symbol_to_list (sym
, &global_symbols
);
4226 /* In shared libraries the address of the variable
4227 in the location descriptor might still be relocatable,
4228 so its value could be zero.
4229 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4230 value is zero, the address of the variable will then
4231 be determined from the minimal symbol table whenever
4232 the variable is referenced. */
4233 if (SYMBOL_VALUE_ADDRESS (sym
))
4235 fixup_symbol_section (sym
, objfile
);
4236 SYMBOL_VALUE_ADDRESS (sym
) +=
4237 ANOFFSET (objfile
->section_offsets
,
4238 SYMBOL_SECTION (sym
));
4239 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4242 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4246 SYMBOL_VALUE (sym
) = addr
=
4247 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4248 add_symbol_to_list (sym
, list_in_scope
);
4251 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4255 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4256 SYMBOL_VALUE (sym
) =
4257 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4261 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4262 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4266 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4270 fixup_symbol_section (sym
, objfile
);
4271 SYMBOL_VALUE_ADDRESS (sym
) =
4272 addr
+ ANOFFSET (objfile
->section_offsets
,
4273 SYMBOL_SECTION (sym
));
4274 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4280 /* We do not know the address of this symbol.
4281 If it is an external symbol and we have type information
4282 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4283 The address of the variable will then be determined from
4284 the minimal symbol table whenever the variable is
4286 attr2
= dwarf_attr (die
, DW_AT_external
);
4287 if (attr2
&& (DW_UNSND (attr2
) != 0)
4288 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4290 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4291 add_symbol_to_list (sym
, &global_symbols
);
4295 case DW_TAG_formal_parameter
:
4296 attr
= dwarf_attr (die
, DW_AT_location
);
4299 SYMBOL_VALUE (sym
) =
4300 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4303 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4304 SYMBOL_VALUE (sym
) =
4305 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4311 if (basereg
!= frame_base_reg
)
4312 complain (&dwarf2_complex_location_expr
);
4313 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4317 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4318 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4323 SYMBOL_CLASS (sym
) = LOC_ARG
;
4326 attr
= dwarf_attr (die
, DW_AT_const_value
);
4329 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4331 add_symbol_to_list (sym
, list_in_scope
);
4333 case DW_TAG_unspecified_parameters
:
4334 /* From varargs functions; gdb doesn't seem to have any
4335 interest in this information, so just ignore it for now.
4338 case DW_TAG_class_type
:
4339 case DW_TAG_structure_type
:
4340 case DW_TAG_union_type
:
4341 case DW_TAG_enumeration_type
:
4342 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4343 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4344 add_symbol_to_list (sym
, list_in_scope
);
4346 /* The semantics of C++ state that "struct foo { ... }" also
4347 defines a typedef for "foo". Synthesize a typedef symbol so
4348 that "ptype foo" works as expected. */
4349 if (cu_language
== language_cplus
)
4351 struct symbol
*typedef_sym
= (struct symbol
*)
4352 obstack_alloc (&objfile
->symbol_obstack
,
4353 sizeof (struct symbol
));
4354 *typedef_sym
= *sym
;
4355 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4356 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4357 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4358 obsavestring (SYMBOL_NAME (sym
),
4359 strlen (SYMBOL_NAME (sym
)),
4360 &objfile
->type_obstack
);
4361 add_symbol_to_list (typedef_sym
, list_in_scope
);
4364 case DW_TAG_typedef
:
4365 case DW_TAG_base_type
:
4366 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4367 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4368 add_symbol_to_list (sym
, list_in_scope
);
4370 case DW_TAG_enumerator
:
4371 attr
= dwarf_attr (die
, DW_AT_const_value
);
4374 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4376 add_symbol_to_list (sym
, list_in_scope
);
4379 /* Not a tag we recognize. Hopefully we aren't processing
4380 trash data, but since we must specifically ignore things
4381 we don't recognize, there is nothing else we should do at
4383 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4390 /* Copy constant value from an attribute to a symbol. */
4393 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
4394 struct objfile
*objfile
,
4395 const struct comp_unit_head
*cu_header
)
4397 struct dwarf_block
*blk
;
4402 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
4403 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4404 cu_header
->addr_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4405 SYMBOL_VALUE_BYTES (sym
) = (char *)
4406 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
4407 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
4409 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4411 case DW_FORM_block1
:
4412 case DW_FORM_block2
:
4413 case DW_FORM_block4
:
4415 blk
= DW_BLOCK (attr
);
4416 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4417 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4418 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4419 SYMBOL_VALUE_BYTES (sym
) = (char *)
4420 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4421 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4422 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4425 /* The DW_AT_const_value attributes are supposed to carry the
4426 symbol's value "represented as it would be on the target
4427 architecture." By the time we get here, it's already been
4428 converted to host endianness, so we just need to sign- or
4429 zero-extend it as appropriate. */
4431 dwarf2_const_value_data (attr
, sym
, 8);
4434 dwarf2_const_value_data (attr
, sym
, 16);
4437 dwarf2_const_value_data (attr
, sym
, 32);
4440 dwarf2_const_value_data (attr
, sym
, 64);
4444 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4445 SYMBOL_CLASS (sym
) = LOC_CONST
;
4449 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4450 SYMBOL_CLASS (sym
) = LOC_CONST
;
4454 complain (&dwarf2_unsupported_const_value_attr
,
4455 dwarf_form_name (attr
->form
));
4456 SYMBOL_VALUE (sym
) = 0;
4457 SYMBOL_CLASS (sym
) = LOC_CONST
;
4463 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4464 or zero-extend it as appropriate for the symbol's type. */
4466 dwarf2_const_value_data (struct attribute
*attr
,
4470 LONGEST l
= DW_UNSND (attr
);
4472 if (bits
< sizeof (l
) * 8)
4474 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4475 l
&= ((LONGEST
) 1 << bits
) - 1;
4477 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4480 SYMBOL_VALUE (sym
) = l
;
4481 SYMBOL_CLASS (sym
) = LOC_CONST
;
4485 /* Return the type of the die in question using its DW_AT_type attribute. */
4487 static struct type
*
4488 die_type (struct die_info
*die
, struct objfile
*objfile
,
4489 const struct comp_unit_head
*cu_header
)
4492 struct attribute
*type_attr
;
4493 struct die_info
*type_die
;
4496 type_attr
= dwarf_attr (die
, DW_AT_type
);
4499 /* A missing DW_AT_type represents a void type. */
4500 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4504 ref
= dwarf2_get_ref_die_offset (type_attr
);
4505 type_die
= follow_die_ref (ref
);
4508 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4512 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4515 dump_die (type_die
);
4516 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4521 /* Return the containing type of the die in question using its
4522 DW_AT_containing_type attribute. */
4524 static struct type
*
4525 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
4526 const struct comp_unit_head
*cu_header
)
4528 struct type
*type
= NULL
;
4529 struct attribute
*type_attr
;
4530 struct die_info
*type_die
= NULL
;
4533 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4536 ref
= dwarf2_get_ref_die_offset (type_attr
);
4537 type_die
= follow_die_ref (ref
);
4540 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4543 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4548 dump_die (type_die
);
4549 error ("Dwarf Error: Problem turning containing type into gdb type.");
4555 static struct type
*
4556 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
4558 struct die_info
*die
;
4561 die
= follow_die_ref (offset
);
4564 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4567 type
= tag_type_to_type (die
, objfile
);
4572 static struct type
*
4573 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
4574 const struct comp_unit_head
*cu_header
)
4582 read_type_die (die
, objfile
, cu_header
);
4586 error ("Dwarf Error: Cannot find type of die.");
4593 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
4594 const struct comp_unit_head
*cu_header
)
4598 case DW_TAG_class_type
:
4599 case DW_TAG_structure_type
:
4600 case DW_TAG_union_type
:
4601 read_structure_scope (die
, objfile
, cu_header
);
4603 case DW_TAG_enumeration_type
:
4604 read_enumeration (die
, objfile
, cu_header
);
4606 case DW_TAG_subprogram
:
4607 case DW_TAG_subroutine_type
:
4608 read_subroutine_type (die
, objfile
, cu_header
);
4610 case DW_TAG_array_type
:
4611 read_array_type (die
, objfile
, cu_header
);
4613 case DW_TAG_pointer_type
:
4614 read_tag_pointer_type (die
, objfile
, cu_header
);
4616 case DW_TAG_ptr_to_member_type
:
4617 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
4619 case DW_TAG_reference_type
:
4620 read_tag_reference_type (die
, objfile
, cu_header
);
4622 case DW_TAG_const_type
:
4623 read_tag_const_type (die
, objfile
, cu_header
);
4625 case DW_TAG_volatile_type
:
4626 read_tag_volatile_type (die
, objfile
, cu_header
);
4628 case DW_TAG_string_type
:
4629 read_tag_string_type (die
, objfile
);
4631 case DW_TAG_typedef
:
4632 read_typedef (die
, objfile
, cu_header
);
4634 case DW_TAG_base_type
:
4635 read_base_type (die
, objfile
);
4638 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4643 static struct type
*
4644 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
4646 /* FIXME - this should not produce a new (struct type *)
4647 every time. It should cache base types. */
4651 case DW_ATE_address
:
4652 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4654 case DW_ATE_boolean
:
4655 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4657 case DW_ATE_complex_float
:
4660 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4664 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4670 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4674 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4681 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4684 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4688 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4692 case DW_ATE_signed_char
:
4693 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4695 case DW_ATE_unsigned
:
4699 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4702 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4706 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4710 case DW_ATE_unsigned_char
:
4711 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4714 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4721 copy_die (struct die_info
*old_die
)
4723 struct die_info
*new_die
;
4726 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4727 memset (new_die
, 0, sizeof (struct die_info
));
4729 new_die
->tag
= old_die
->tag
;
4730 new_die
->has_children
= old_die
->has_children
;
4731 new_die
->abbrev
= old_die
->abbrev
;
4732 new_die
->offset
= old_die
->offset
;
4733 new_die
->type
= NULL
;
4735 num_attrs
= old_die
->num_attrs
;
4736 new_die
->num_attrs
= num_attrs
;
4737 new_die
->attrs
= (struct attribute
*)
4738 xmalloc (num_attrs
* sizeof (struct attribute
));
4740 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4742 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4743 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4744 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4747 new_die
->next
= NULL
;
4752 /* Return sibling of die, NULL if no sibling. */
4754 static struct die_info
*
4755 sibling_die (struct die_info
*die
)
4757 int nesting_level
= 0;
4759 if (!die
->has_children
)
4761 if (die
->next
&& (die
->next
->tag
== 0))
4774 if (die
->has_children
)
4784 while (nesting_level
);
4785 if (die
&& (die
->tag
== 0))
4796 /* Get linkage name of a die, return NULL if not found. */
4799 dwarf2_linkage_name (struct die_info
*die
)
4801 struct attribute
*attr
;
4803 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4804 if (attr
&& DW_STRING (attr
))
4805 return DW_STRING (attr
);
4806 attr
= dwarf_attr (die
, DW_AT_name
);
4807 if (attr
&& DW_STRING (attr
))
4808 return DW_STRING (attr
);
4812 /* Convert a DIE tag into its string name. */
4815 dwarf_tag_name (register unsigned tag
)
4819 case DW_TAG_padding
:
4820 return "DW_TAG_padding";
4821 case DW_TAG_array_type
:
4822 return "DW_TAG_array_type";
4823 case DW_TAG_class_type
:
4824 return "DW_TAG_class_type";
4825 case DW_TAG_entry_point
:
4826 return "DW_TAG_entry_point";
4827 case DW_TAG_enumeration_type
:
4828 return "DW_TAG_enumeration_type";
4829 case DW_TAG_formal_parameter
:
4830 return "DW_TAG_formal_parameter";
4831 case DW_TAG_imported_declaration
:
4832 return "DW_TAG_imported_declaration";
4834 return "DW_TAG_label";
4835 case DW_TAG_lexical_block
:
4836 return "DW_TAG_lexical_block";
4838 return "DW_TAG_member";
4839 case DW_TAG_pointer_type
:
4840 return "DW_TAG_pointer_type";
4841 case DW_TAG_reference_type
:
4842 return "DW_TAG_reference_type";
4843 case DW_TAG_compile_unit
:
4844 return "DW_TAG_compile_unit";
4845 case DW_TAG_string_type
:
4846 return "DW_TAG_string_type";
4847 case DW_TAG_structure_type
:
4848 return "DW_TAG_structure_type";
4849 case DW_TAG_subroutine_type
:
4850 return "DW_TAG_subroutine_type";
4851 case DW_TAG_typedef
:
4852 return "DW_TAG_typedef";
4853 case DW_TAG_union_type
:
4854 return "DW_TAG_union_type";
4855 case DW_TAG_unspecified_parameters
:
4856 return "DW_TAG_unspecified_parameters";
4857 case DW_TAG_variant
:
4858 return "DW_TAG_variant";
4859 case DW_TAG_common_block
:
4860 return "DW_TAG_common_block";
4861 case DW_TAG_common_inclusion
:
4862 return "DW_TAG_common_inclusion";
4863 case DW_TAG_inheritance
:
4864 return "DW_TAG_inheritance";
4865 case DW_TAG_inlined_subroutine
:
4866 return "DW_TAG_inlined_subroutine";
4868 return "DW_TAG_module";
4869 case DW_TAG_ptr_to_member_type
:
4870 return "DW_TAG_ptr_to_member_type";
4871 case DW_TAG_set_type
:
4872 return "DW_TAG_set_type";
4873 case DW_TAG_subrange_type
:
4874 return "DW_TAG_subrange_type";
4875 case DW_TAG_with_stmt
:
4876 return "DW_TAG_with_stmt";
4877 case DW_TAG_access_declaration
:
4878 return "DW_TAG_access_declaration";
4879 case DW_TAG_base_type
:
4880 return "DW_TAG_base_type";
4881 case DW_TAG_catch_block
:
4882 return "DW_TAG_catch_block";
4883 case DW_TAG_const_type
:
4884 return "DW_TAG_const_type";
4885 case DW_TAG_constant
:
4886 return "DW_TAG_constant";
4887 case DW_TAG_enumerator
:
4888 return "DW_TAG_enumerator";
4889 case DW_TAG_file_type
:
4890 return "DW_TAG_file_type";
4892 return "DW_TAG_friend";
4893 case DW_TAG_namelist
:
4894 return "DW_TAG_namelist";
4895 case DW_TAG_namelist_item
:
4896 return "DW_TAG_namelist_item";
4897 case DW_TAG_packed_type
:
4898 return "DW_TAG_packed_type";
4899 case DW_TAG_subprogram
:
4900 return "DW_TAG_subprogram";
4901 case DW_TAG_template_type_param
:
4902 return "DW_TAG_template_type_param";
4903 case DW_TAG_template_value_param
:
4904 return "DW_TAG_template_value_param";
4905 case DW_TAG_thrown_type
:
4906 return "DW_TAG_thrown_type";
4907 case DW_TAG_try_block
:
4908 return "DW_TAG_try_block";
4909 case DW_TAG_variant_part
:
4910 return "DW_TAG_variant_part";
4911 case DW_TAG_variable
:
4912 return "DW_TAG_variable";
4913 case DW_TAG_volatile_type
:
4914 return "DW_TAG_volatile_type";
4915 case DW_TAG_MIPS_loop
:
4916 return "DW_TAG_MIPS_loop";
4917 case DW_TAG_format_label
:
4918 return "DW_TAG_format_label";
4919 case DW_TAG_function_template
:
4920 return "DW_TAG_function_template";
4921 case DW_TAG_class_template
:
4922 return "DW_TAG_class_template";
4924 return "DW_TAG_<unknown>";
4928 /* Convert a DWARF attribute code into its string name. */
4931 dwarf_attr_name (register unsigned attr
)
4936 return "DW_AT_sibling";
4937 case DW_AT_location
:
4938 return "DW_AT_location";
4940 return "DW_AT_name";
4941 case DW_AT_ordering
:
4942 return "DW_AT_ordering";
4943 case DW_AT_subscr_data
:
4944 return "DW_AT_subscr_data";
4945 case DW_AT_byte_size
:
4946 return "DW_AT_byte_size";
4947 case DW_AT_bit_offset
:
4948 return "DW_AT_bit_offset";
4949 case DW_AT_bit_size
:
4950 return "DW_AT_bit_size";
4951 case DW_AT_element_list
:
4952 return "DW_AT_element_list";
4953 case DW_AT_stmt_list
:
4954 return "DW_AT_stmt_list";
4956 return "DW_AT_low_pc";
4958 return "DW_AT_high_pc";
4959 case DW_AT_language
:
4960 return "DW_AT_language";
4962 return "DW_AT_member";
4964 return "DW_AT_discr";
4965 case DW_AT_discr_value
:
4966 return "DW_AT_discr_value";
4967 case DW_AT_visibility
:
4968 return "DW_AT_visibility";
4970 return "DW_AT_import";
4971 case DW_AT_string_length
:
4972 return "DW_AT_string_length";
4973 case DW_AT_common_reference
:
4974 return "DW_AT_common_reference";
4975 case DW_AT_comp_dir
:
4976 return "DW_AT_comp_dir";
4977 case DW_AT_const_value
:
4978 return "DW_AT_const_value";
4979 case DW_AT_containing_type
:
4980 return "DW_AT_containing_type";
4981 case DW_AT_default_value
:
4982 return "DW_AT_default_value";
4984 return "DW_AT_inline";
4985 case DW_AT_is_optional
:
4986 return "DW_AT_is_optional";
4987 case DW_AT_lower_bound
:
4988 return "DW_AT_lower_bound";
4989 case DW_AT_producer
:
4990 return "DW_AT_producer";
4991 case DW_AT_prototyped
:
4992 return "DW_AT_prototyped";
4993 case DW_AT_return_addr
:
4994 return "DW_AT_return_addr";
4995 case DW_AT_start_scope
:
4996 return "DW_AT_start_scope";
4997 case DW_AT_stride_size
:
4998 return "DW_AT_stride_size";
4999 case DW_AT_upper_bound
:
5000 return "DW_AT_upper_bound";
5001 case DW_AT_abstract_origin
:
5002 return "DW_AT_abstract_origin";
5003 case DW_AT_accessibility
:
5004 return "DW_AT_accessibility";
5005 case DW_AT_address_class
:
5006 return "DW_AT_address_class";
5007 case DW_AT_artificial
:
5008 return "DW_AT_artificial";
5009 case DW_AT_base_types
:
5010 return "DW_AT_base_types";
5011 case DW_AT_calling_convention
:
5012 return "DW_AT_calling_convention";
5014 return "DW_AT_count";
5015 case DW_AT_data_member_location
:
5016 return "DW_AT_data_member_location";
5017 case DW_AT_decl_column
:
5018 return "DW_AT_decl_column";
5019 case DW_AT_decl_file
:
5020 return "DW_AT_decl_file";
5021 case DW_AT_decl_line
:
5022 return "DW_AT_decl_line";
5023 case DW_AT_declaration
:
5024 return "DW_AT_declaration";
5025 case DW_AT_discr_list
:
5026 return "DW_AT_discr_list";
5027 case DW_AT_encoding
:
5028 return "DW_AT_encoding";
5029 case DW_AT_external
:
5030 return "DW_AT_external";
5031 case DW_AT_frame_base
:
5032 return "DW_AT_frame_base";
5034 return "DW_AT_friend";
5035 case DW_AT_identifier_case
:
5036 return "DW_AT_identifier_case";
5037 case DW_AT_macro_info
:
5038 return "DW_AT_macro_info";
5039 case DW_AT_namelist_items
:
5040 return "DW_AT_namelist_items";
5041 case DW_AT_priority
:
5042 return "DW_AT_priority";
5044 return "DW_AT_segment";
5045 case DW_AT_specification
:
5046 return "DW_AT_specification";
5047 case DW_AT_static_link
:
5048 return "DW_AT_static_link";
5050 return "DW_AT_type";
5051 case DW_AT_use_location
:
5052 return "DW_AT_use_location";
5053 case DW_AT_variable_parameter
:
5054 return "DW_AT_variable_parameter";
5055 case DW_AT_virtuality
:
5056 return "DW_AT_virtuality";
5057 case DW_AT_vtable_elem_location
:
5058 return "DW_AT_vtable_elem_location";
5061 case DW_AT_MIPS_fde
:
5062 return "DW_AT_MIPS_fde";
5063 case DW_AT_MIPS_loop_begin
:
5064 return "DW_AT_MIPS_loop_begin";
5065 case DW_AT_MIPS_tail_loop_begin
:
5066 return "DW_AT_MIPS_tail_loop_begin";
5067 case DW_AT_MIPS_epilog_begin
:
5068 return "DW_AT_MIPS_epilog_begin";
5069 case DW_AT_MIPS_loop_unroll_factor
:
5070 return "DW_AT_MIPS_loop_unroll_factor";
5071 case DW_AT_MIPS_software_pipeline_depth
:
5072 return "DW_AT_MIPS_software_pipeline_depth";
5073 case DW_AT_MIPS_linkage_name
:
5074 return "DW_AT_MIPS_linkage_name";
5077 case DW_AT_sf_names
:
5078 return "DW_AT_sf_names";
5079 case DW_AT_src_info
:
5080 return "DW_AT_src_info";
5081 case DW_AT_mac_info
:
5082 return "DW_AT_mac_info";
5083 case DW_AT_src_coords
:
5084 return "DW_AT_src_coords";
5085 case DW_AT_body_begin
:
5086 return "DW_AT_body_begin";
5087 case DW_AT_body_end
:
5088 return "DW_AT_body_end";
5090 return "DW_AT_<unknown>";
5094 /* Convert a DWARF value form code into its string name. */
5097 dwarf_form_name (register unsigned form
)
5102 return "DW_FORM_addr";
5103 case DW_FORM_block2
:
5104 return "DW_FORM_block2";
5105 case DW_FORM_block4
:
5106 return "DW_FORM_block4";
5108 return "DW_FORM_data2";
5110 return "DW_FORM_data4";
5112 return "DW_FORM_data8";
5113 case DW_FORM_string
:
5114 return "DW_FORM_string";
5116 return "DW_FORM_block";
5117 case DW_FORM_block1
:
5118 return "DW_FORM_block1";
5120 return "DW_FORM_data1";
5122 return "DW_FORM_flag";
5124 return "DW_FORM_sdata";
5126 return "DW_FORM_strp";
5128 return "DW_FORM_udata";
5129 case DW_FORM_ref_addr
:
5130 return "DW_FORM_ref_addr";
5132 return "DW_FORM_ref1";
5134 return "DW_FORM_ref2";
5136 return "DW_FORM_ref4";
5138 return "DW_FORM_ref8";
5139 case DW_FORM_ref_udata
:
5140 return "DW_FORM_ref_udata";
5141 case DW_FORM_indirect
:
5142 return "DW_FORM_indirect";
5144 return "DW_FORM_<unknown>";
5148 /* Convert a DWARF stack opcode into its string name. */
5151 dwarf_stack_op_name (register unsigned op
)
5156 return "DW_OP_addr";
5158 return "DW_OP_deref";
5160 return "DW_OP_const1u";
5162 return "DW_OP_const1s";
5164 return "DW_OP_const2u";
5166 return "DW_OP_const2s";
5168 return "DW_OP_const4u";
5170 return "DW_OP_const4s";
5172 return "DW_OP_const8u";
5174 return "DW_OP_const8s";
5176 return "DW_OP_constu";
5178 return "DW_OP_consts";
5182 return "DW_OP_drop";
5184 return "DW_OP_over";
5186 return "DW_OP_pick";
5188 return "DW_OP_swap";
5192 return "DW_OP_xderef";
5200 return "DW_OP_minus";
5212 return "DW_OP_plus";
5213 case DW_OP_plus_uconst
:
5214 return "DW_OP_plus_uconst";
5220 return "DW_OP_shra";
5238 return "DW_OP_skip";
5240 return "DW_OP_lit0";
5242 return "DW_OP_lit1";
5244 return "DW_OP_lit2";
5246 return "DW_OP_lit3";
5248 return "DW_OP_lit4";
5250 return "DW_OP_lit5";
5252 return "DW_OP_lit6";
5254 return "DW_OP_lit7";
5256 return "DW_OP_lit8";
5258 return "DW_OP_lit9";
5260 return "DW_OP_lit10";
5262 return "DW_OP_lit11";
5264 return "DW_OP_lit12";
5266 return "DW_OP_lit13";
5268 return "DW_OP_lit14";
5270 return "DW_OP_lit15";
5272 return "DW_OP_lit16";
5274 return "DW_OP_lit17";
5276 return "DW_OP_lit18";
5278 return "DW_OP_lit19";
5280 return "DW_OP_lit20";
5282 return "DW_OP_lit21";
5284 return "DW_OP_lit22";
5286 return "DW_OP_lit23";
5288 return "DW_OP_lit24";
5290 return "DW_OP_lit25";
5292 return "DW_OP_lit26";
5294 return "DW_OP_lit27";
5296 return "DW_OP_lit28";
5298 return "DW_OP_lit29";
5300 return "DW_OP_lit30";
5302 return "DW_OP_lit31";
5304 return "DW_OP_reg0";
5306 return "DW_OP_reg1";
5308 return "DW_OP_reg2";
5310 return "DW_OP_reg3";
5312 return "DW_OP_reg4";
5314 return "DW_OP_reg5";
5316 return "DW_OP_reg6";
5318 return "DW_OP_reg7";
5320 return "DW_OP_reg8";
5322 return "DW_OP_reg9";
5324 return "DW_OP_reg10";
5326 return "DW_OP_reg11";
5328 return "DW_OP_reg12";
5330 return "DW_OP_reg13";
5332 return "DW_OP_reg14";
5334 return "DW_OP_reg15";
5336 return "DW_OP_reg16";
5338 return "DW_OP_reg17";
5340 return "DW_OP_reg18";
5342 return "DW_OP_reg19";
5344 return "DW_OP_reg20";
5346 return "DW_OP_reg21";
5348 return "DW_OP_reg22";
5350 return "DW_OP_reg23";
5352 return "DW_OP_reg24";
5354 return "DW_OP_reg25";
5356 return "DW_OP_reg26";
5358 return "DW_OP_reg27";
5360 return "DW_OP_reg28";
5362 return "DW_OP_reg29";
5364 return "DW_OP_reg30";
5366 return "DW_OP_reg31";
5368 return "DW_OP_breg0";
5370 return "DW_OP_breg1";
5372 return "DW_OP_breg2";
5374 return "DW_OP_breg3";
5376 return "DW_OP_breg4";
5378 return "DW_OP_breg5";
5380 return "DW_OP_breg6";
5382 return "DW_OP_breg7";
5384 return "DW_OP_breg8";
5386 return "DW_OP_breg9";
5388 return "DW_OP_breg10";
5390 return "DW_OP_breg11";
5392 return "DW_OP_breg12";
5394 return "DW_OP_breg13";
5396 return "DW_OP_breg14";
5398 return "DW_OP_breg15";
5400 return "DW_OP_breg16";
5402 return "DW_OP_breg17";
5404 return "DW_OP_breg18";
5406 return "DW_OP_breg19";
5408 return "DW_OP_breg20";
5410 return "DW_OP_breg21";
5412 return "DW_OP_breg22";
5414 return "DW_OP_breg23";
5416 return "DW_OP_breg24";
5418 return "DW_OP_breg25";
5420 return "DW_OP_breg26";
5422 return "DW_OP_breg27";
5424 return "DW_OP_breg28";
5426 return "DW_OP_breg29";
5428 return "DW_OP_breg30";
5430 return "DW_OP_breg31";
5432 return "DW_OP_regx";
5434 return "DW_OP_fbreg";
5436 return "DW_OP_bregx";
5438 return "DW_OP_piece";
5439 case DW_OP_deref_size
:
5440 return "DW_OP_deref_size";
5441 case DW_OP_xderef_size
:
5442 return "DW_OP_xderef_size";
5446 return "OP_<unknown>";
5451 dwarf_bool_name (unsigned mybool
)
5459 /* Convert a DWARF type code into its string name. */
5462 dwarf_type_encoding_name (register unsigned enc
)
5466 case DW_ATE_address
:
5467 return "DW_ATE_address";
5468 case DW_ATE_boolean
:
5469 return "DW_ATE_boolean";
5470 case DW_ATE_complex_float
:
5471 return "DW_ATE_complex_float";
5473 return "DW_ATE_float";
5475 return "DW_ATE_signed";
5476 case DW_ATE_signed_char
:
5477 return "DW_ATE_signed_char";
5478 case DW_ATE_unsigned
:
5479 return "DW_ATE_unsigned";
5480 case DW_ATE_unsigned_char
:
5481 return "DW_ATE_unsigned_char";
5483 return "DW_ATE_<unknown>";
5487 /* Convert a DWARF call frame info operation to its string name. */
5491 dwarf_cfi_name (register unsigned cfi_opc
)
5495 case DW_CFA_advance_loc
:
5496 return "DW_CFA_advance_loc";
5498 return "DW_CFA_offset";
5499 case DW_CFA_restore
:
5500 return "DW_CFA_restore";
5502 return "DW_CFA_nop";
5503 case DW_CFA_set_loc
:
5504 return "DW_CFA_set_loc";
5505 case DW_CFA_advance_loc1
:
5506 return "DW_CFA_advance_loc1";
5507 case DW_CFA_advance_loc2
:
5508 return "DW_CFA_advance_loc2";
5509 case DW_CFA_advance_loc4
:
5510 return "DW_CFA_advance_loc4";
5511 case DW_CFA_offset_extended
:
5512 return "DW_CFA_offset_extended";
5513 case DW_CFA_restore_extended
:
5514 return "DW_CFA_restore_extended";
5515 case DW_CFA_undefined
:
5516 return "DW_CFA_undefined";
5517 case DW_CFA_same_value
:
5518 return "DW_CFA_same_value";
5519 case DW_CFA_register
:
5520 return "DW_CFA_register";
5521 case DW_CFA_remember_state
:
5522 return "DW_CFA_remember_state";
5523 case DW_CFA_restore_state
:
5524 return "DW_CFA_restore_state";
5525 case DW_CFA_def_cfa
:
5526 return "DW_CFA_def_cfa";
5527 case DW_CFA_def_cfa_register
:
5528 return "DW_CFA_def_cfa_register";
5529 case DW_CFA_def_cfa_offset
:
5530 return "DW_CFA_def_cfa_offset";
5531 /* SGI/MIPS specific */
5532 case DW_CFA_MIPS_advance_loc8
:
5533 return "DW_CFA_MIPS_advance_loc8";
5535 return "DW_CFA_<unknown>";
5541 dump_die (struct die_info
*die
)
5545 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5546 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5547 fprintf (stderr
, "\thas children: %s\n",
5548 dwarf_bool_name (die
->has_children
));
5550 fprintf (stderr
, "\tattributes:\n");
5551 for (i
= 0; i
< die
->num_attrs
; ++i
)
5553 fprintf (stderr
, "\t\t%s (%s) ",
5554 dwarf_attr_name (die
->attrs
[i
].name
),
5555 dwarf_form_name (die
->attrs
[i
].form
));
5556 switch (die
->attrs
[i
].form
)
5558 case DW_FORM_ref_addr
:
5560 fprintf (stderr
, "address: ");
5561 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5563 case DW_FORM_block2
:
5564 case DW_FORM_block4
:
5566 case DW_FORM_block1
:
5567 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5578 fprintf (stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
5580 case DW_FORM_string
:
5581 fprintf (stderr
, "string: \"%s\"",
5582 DW_STRING (&die
->attrs
[i
])
5583 ? DW_STRING (&die
->attrs
[i
]) : "");
5586 if (DW_UNSND (&die
->attrs
[i
]))
5587 fprintf (stderr
, "flag: TRUE");
5589 fprintf (stderr
, "flag: FALSE");
5591 case DW_FORM_strp
: /* we do not support separate string
5593 case DW_FORM_indirect
: /* we do not handle indirect yet */
5595 fprintf (stderr
, "unsupported attribute form: %d.",
5596 die
->attrs
[i
].form
);
5598 fprintf (stderr
, "\n");
5603 dump_die_list (struct die_info
*die
)
5613 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
5616 struct die_info
*old
;
5618 h
= (offset
% REF_HASH_SIZE
);
5619 old
= die_ref_table
[h
];
5620 die
->next_ref
= old
;
5621 die_ref_table
[h
] = die
;
5626 dwarf2_empty_hash_tables (void)
5628 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5632 dwarf2_get_ref_die_offset (struct attribute
*attr
)
5634 unsigned int result
= 0;
5638 case DW_FORM_ref_addr
:
5639 result
= DW_ADDR (attr
);
5645 case DW_FORM_ref_udata
:
5646 result
= cu_header_offset
+ DW_UNSND (attr
);
5649 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5654 static struct die_info
*
5655 follow_die_ref (unsigned int offset
)
5657 struct die_info
*die
;
5660 h
= (offset
% REF_HASH_SIZE
);
5661 die
= die_ref_table
[h
];
5664 if (die
->offset
== offset
)
5668 die
= die
->next_ref
;
5673 static struct type
*
5674 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
5676 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5678 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5682 /* Look for this particular type in the fundamental type vector. If
5683 one is not found, create and install one appropriate for the
5684 current language and the current target machine. */
5686 if (ftypes
[typeid] == NULL
)
5688 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5691 return (ftypes
[typeid]);
5694 /* Decode simple location descriptions.
5695 Given a pointer to a dwarf block that defines a location, compute
5696 the location and return the value.
5698 FIXME: This is a kludge until we figure out a better
5699 way to handle the location descriptions.
5700 Gdb's design does not mesh well with the DWARF2 notion of a location
5701 computing interpreter, which is a shame because the flexibility goes unused.
5702 FIXME: Implement more operations as necessary.
5704 A location description containing no operations indicates that the
5705 object is optimized out. The global optimized_out flag is set for
5706 those, the return value is meaningless.
5708 When the result is a register number, the global isreg flag is set,
5709 otherwise it is cleared.
5711 When the result is a base register offset, the global offreg flag is set
5712 and the register number is returned in basereg, otherwise it is cleared.
5714 When the DW_OP_fbreg operation is encountered without a corresponding
5715 DW_AT_frame_base attribute, the global islocal flag is set.
5716 Hopefully the machine dependent code knows how to set up a virtual
5717 frame pointer for the local references.
5719 Note that stack[0] is unused except as a default error return.
5720 Note that stack overflow is not yet handled. */
5723 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
5724 const struct comp_unit_head
*cu_header
)
5727 int size
= blk
->size
;
5728 char *data
= blk
->data
;
5729 CORE_ADDR stack
[64];
5731 unsigned int bytes_read
, unsnd
;
5782 stack
[++stacki
] = op
- DW_OP_reg0
;
5787 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5789 #if defined(HARRIS_TARGET) && defined(_M88K)
5790 /* The Harris 88110 gdb ports have long kept their special reg
5791 numbers between their gp-regs and their x-regs. This is
5792 not how our dwarf is generated. Punt. */
5795 stack
[++stacki
] = unsnd
;
5831 basereg
= op
- DW_OP_breg0
;
5832 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5838 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5840 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5845 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5847 if (frame_base_reg
>= 0)
5850 basereg
= frame_base_reg
;
5851 stack
[stacki
] += frame_base_offset
;
5855 complain (&dwarf2_missing_at_frame_base
);
5861 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
5862 cu_header
, &bytes_read
);
5867 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5872 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5877 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5882 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5887 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5892 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5897 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5903 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5908 stack
[stacki
- 1] += stack
[stacki
];
5912 case DW_OP_plus_uconst
:
5913 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5918 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5924 /* If we're not the last op, then we definitely can't encode
5925 this using GDB's address_class enum. */
5927 complain (&dwarf2_complex_location_expr
);
5931 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
5932 return (stack
[stacki
]);
5935 return (stack
[stacki
]);
5938 /* memory allocation interface */
5942 dwarf2_free_tmp_obstack (PTR ignore
)
5944 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5947 static struct dwarf_block
*
5948 dwarf_alloc_block (void)
5950 struct dwarf_block
*blk
;
5952 blk
= (struct dwarf_block
*)
5953 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5957 static struct abbrev_info
*
5958 dwarf_alloc_abbrev (void)
5960 struct abbrev_info
*abbrev
;
5962 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5963 memset (abbrev
, 0, sizeof (struct abbrev_info
));
5967 static struct die_info
*
5968 dwarf_alloc_die (void)
5970 struct die_info
*die
;
5972 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5973 memset (die
, 0, sizeof (struct die_info
));