1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
10 support in dwarfread.c
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or (at
17 your option) any later version.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. */
35 #include "elf/dwarf2.h"
38 #include "expression.h"
39 #include "filenames.h" /* for DOSish file names */
42 #include "complaints.h"
45 #include "gdb_string.h"
46 #include "gdb_assert.h"
47 #include <sys/types.h>
49 #ifndef DWARF2_REG_TO_REGNUM
50 #define DWARF2_REG_TO_REGNUM(REG) (REG)
54 /* .debug_info header for a compilation unit
55 Because of alignment constraints, this structure has padding and cannot
56 be mapped directly onto the beginning of the .debug_info section. */
57 typedef struct comp_unit_header
59 unsigned int length
; /* length of the .debug_info
61 unsigned short version
; /* version number -- 2 for DWARF
63 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
64 unsigned char addr_size
; /* byte size of an address -- 4 */
67 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
70 /* .debug_pubnames header
71 Because of alignment constraints, this structure has padding and cannot
72 be mapped directly onto the beginning of the .debug_info section. */
73 typedef struct pubnames_header
75 unsigned int length
; /* length of the .debug_pubnames
77 unsigned char version
; /* version number -- 2 for DWARF
79 unsigned int info_offset
; /* offset into .debug_info section */
80 unsigned int info_size
; /* byte size of .debug_info section
84 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
86 /* .debug_pubnames header
87 Because of alignment constraints, this structure has padding and cannot
88 be mapped directly onto the beginning of the .debug_info section. */
89 typedef struct aranges_header
91 unsigned int length
; /* byte len of the .debug_aranges
93 unsigned short version
; /* version number -- 2 for DWARF
95 unsigned int info_offset
; /* offset into .debug_info section */
96 unsigned char addr_size
; /* byte size of an address */
97 unsigned char seg_size
; /* byte size of segment descriptor */
100 #define _ACTUAL_ARANGES_HEADER_SIZE 12
102 /* .debug_line statement program prologue
103 Because of alignment constraints, this structure has padding and cannot
104 be mapped directly onto the beginning of the .debug_info section. */
105 typedef struct statement_prologue
107 unsigned int total_length
; /* byte length of the statement
109 unsigned short version
; /* version number -- 2 for DWARF
111 unsigned int prologue_length
; /* # bytes between prologue &
113 unsigned char minimum_instruction_length
; /* byte size of
115 unsigned char default_is_stmt
; /* initial value of is_stmt
118 unsigned char line_range
;
119 unsigned char opcode_base
; /* number assigned to first special
121 unsigned char *standard_opcode_lengths
;
125 /* offsets and sizes of debugging sections */
127 static file_ptr dwarf_info_offset
;
128 static file_ptr dwarf_abbrev_offset
;
129 static file_ptr dwarf_line_offset
;
130 static file_ptr dwarf_pubnames_offset
;
131 static file_ptr dwarf_aranges_offset
;
132 static file_ptr dwarf_loc_offset
;
133 static file_ptr dwarf_macinfo_offset
;
134 static file_ptr dwarf_str_offset
;
135 file_ptr dwarf_frame_offset
;
136 file_ptr dwarf_eh_frame_offset
;
138 static unsigned int dwarf_info_size
;
139 static unsigned int dwarf_abbrev_size
;
140 static unsigned int dwarf_line_size
;
141 static unsigned int dwarf_pubnames_size
;
142 static unsigned int dwarf_aranges_size
;
143 static unsigned int dwarf_loc_size
;
144 static unsigned int dwarf_macinfo_size
;
145 static unsigned int dwarf_str_size
;
146 unsigned int dwarf_frame_size
;
147 unsigned int dwarf_eh_frame_size
;
149 /* names of the debugging sections */
151 #define INFO_SECTION ".debug_info"
152 #define ABBREV_SECTION ".debug_abbrev"
153 #define LINE_SECTION ".debug_line"
154 #define PUBNAMES_SECTION ".debug_pubnames"
155 #define ARANGES_SECTION ".debug_aranges"
156 #define LOC_SECTION ".debug_loc"
157 #define MACINFO_SECTION ".debug_macinfo"
158 #define STR_SECTION ".debug_str"
159 #define FRAME_SECTION ".debug_frame"
160 #define EH_FRAME_SECTION ".eh_frame"
162 /* local data types */
164 /* The data in a compilation unit header, after target2host
165 translation, looks like this. */
166 struct comp_unit_head
168 unsigned long length
;
170 unsigned int abbrev_offset
;
171 unsigned char addr_size
;
172 unsigned char signed_addr_p
;
173 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
174 unsigned int initial_length_size
; /* size of the length field; either
178 /* The data in the .debug_line statement prologue looks like this. */
181 unsigned int total_length
;
182 unsigned short version
;
183 unsigned int prologue_length
;
184 unsigned char minimum_instruction_length
;
185 unsigned char default_is_stmt
;
187 unsigned char line_range
;
188 unsigned char opcode_base
;
189 unsigned char *standard_opcode_lengths
;
192 /* When we construct a partial symbol table entry we only
193 need this much information. */
194 struct partial_die_info
197 unsigned char has_children
;
198 unsigned char is_external
;
199 unsigned char is_declaration
;
200 unsigned char has_type
;
207 struct dwarf_block
*locdesc
;
208 unsigned int language
;
212 /* This data structure holds the information of an abbrev. */
215 unsigned int number
; /* number identifying abbrev */
216 enum dwarf_tag tag
; /* dwarf tag */
217 int has_children
; /* boolean */
218 unsigned int num_attrs
; /* number of attributes */
219 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
220 struct abbrev_info
*next
; /* next in chain */
225 enum dwarf_attribute name
;
226 enum dwarf_form form
;
229 /* This data structure holds a complete die structure. */
232 enum dwarf_tag tag
; /* Tag indicating type of die */
233 unsigned short has_children
; /* Does the die have children */
234 unsigned int abbrev
; /* Abbrev number */
235 unsigned int offset
; /* Offset in .debug_info section */
236 unsigned int num_attrs
; /* Number of attributes */
237 struct attribute
*attrs
; /* An array of attributes */
238 struct die_info
*next_ref
; /* Next die in ref hash table */
239 struct die_info
*next
; /* Next die in linked list */
240 struct type
*type
; /* Cached type information */
243 /* Attributes have a name and a value */
246 enum dwarf_attribute name
;
247 enum dwarf_form form
;
251 struct dwarf_block
*blk
;
259 /* Get at parts of an attribute structure */
261 #define DW_STRING(attr) ((attr)->u.str)
262 #define DW_UNSND(attr) ((attr)->u.unsnd)
263 #define DW_BLOCK(attr) ((attr)->u.blk)
264 #define DW_SND(attr) ((attr)->u.snd)
265 #define DW_ADDR(attr) ((attr)->u.addr)
267 /* Blocks are a bunch of untyped bytes. */
274 /* We only hold one compilation unit's abbrevs in
275 memory at any one time. */
276 #ifndef ABBREV_HASH_SIZE
277 #define ABBREV_HASH_SIZE 121
279 #ifndef ATTR_ALLOC_CHUNK
280 #define ATTR_ALLOC_CHUNK 4
283 static struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
285 /* A hash table of die offsets for following references. */
286 #ifndef REF_HASH_SIZE
287 #define REF_HASH_SIZE 1021
290 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
292 /* Obstack for allocating temporary storage used during symbol reading. */
293 static struct obstack dwarf2_tmp_obstack
;
295 /* Offset to the first byte of the current compilation unit header,
296 for resolving relative reference dies. */
297 static unsigned int cu_header_offset
;
299 /* Allocate fields for structs, unions and enums in this size. */
300 #ifndef DW_FIELD_ALLOC_CHUNK
301 #define DW_FIELD_ALLOC_CHUNK 4
304 /* The language we are debugging. */
305 static enum language cu_language
;
306 static const struct language_defn
*cu_language_defn
;
308 /* Actually data from the sections. */
309 static char *dwarf_info_buffer
;
310 static char *dwarf_abbrev_buffer
;
311 static char *dwarf_line_buffer
;
312 static char *dwarf_str_buffer
;
314 /* A zeroed version of a partial die for initialization purposes. */
315 static struct partial_die_info zeroed_partial_die
;
317 /* The generic symbol table building routines have separate lists for
318 file scope symbols and all all other scopes (local scopes). So
319 we need to select the right one to pass to add_symbol_to_list().
320 We do it by keeping a pointer to the correct list in list_in_scope.
322 FIXME: The original dwarf code just treated the file scope as the first
323 local scope, and all other local scopes as nested local scopes, and worked
324 fine. Check to see if we really need to distinguish these
326 static struct pending
**list_in_scope
= &file_symbols
;
328 /* FIXME: decode_locdesc sets these variables to describe the location
329 to the caller. These ought to be a structure or something. If
330 none of the flags are set, the object lives at the address returned
331 by decode_locdesc. */
333 static int optimized_out
; /* No ops in location in expression,
334 so object was optimized out. */
335 static int isreg
; /* Object lives in register.
336 decode_locdesc's return value is
337 the register number. */
338 static int offreg
; /* Object's address is the sum of the
339 register specified by basereg, plus
340 the offset returned. */
341 static int basereg
; /* See `offreg'. */
342 static int isderef
; /* Value described by flags above is
343 the address of a pointer to the object. */
344 static int islocal
; /* Variable is at the returned offset
345 from the frame start, but there's
346 no identified frame pointer for
347 this function, so we can't say
348 which register it's relative to;
351 /* DW_AT_frame_base values for the current function.
352 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
353 contains the register number for the frame register.
354 frame_base_offset is the offset from the frame register to the
355 virtual stack frame. */
356 static int frame_base_reg
;
357 static CORE_ADDR frame_base_offset
;
359 /* This value is added to each symbol value. FIXME: Generalize to
360 the section_offsets structure used by dbxread (once this is done,
361 pass the appropriate section number to end_symtab). */
362 static CORE_ADDR baseaddr
; /* Add to each symbol value */
364 /* We put a pointer to this structure in the read_symtab_private field
366 The complete dwarf information for an objfile is kept in the
367 psymbol_obstack, so that absolute die references can be handled.
368 Most of the information in this structure is related to an entire
369 object file and could be passed via the sym_private field of the objfile.
370 It is however conceivable that dwarf2 might not be the only type
371 of symbols read from an object file. */
375 /* Pointer to start of dwarf info buffer for the objfile. */
377 char *dwarf_info_buffer
;
379 /* Offset in dwarf_info_buffer for this compilation unit. */
381 unsigned long dwarf_info_offset
;
383 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
385 char *dwarf_abbrev_buffer
;
387 /* Size of dwarf abbreviation section for the objfile. */
389 unsigned int dwarf_abbrev_size
;
391 /* Pointer to start of dwarf line buffer for the objfile. */
393 char *dwarf_line_buffer
;
395 /* Pointer to start of dwarf string buffer for the objfile. */
397 char *dwarf_str_buffer
;
399 /* Size of dwarf string section for the objfile. */
401 unsigned int dwarf_str_size
;
404 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
405 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
406 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
407 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
408 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
409 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
410 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
411 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
413 /* Maintain an array of referenced fundamental types for the current
414 compilation unit being read. For DWARF version 1, we have to construct
415 the fundamental types on the fly, since no information about the
416 fundamental types is supplied. Each such fundamental type is created by
417 calling a language dependent routine to create the type, and then a
418 pointer to that type is then placed in the array at the index specified
419 by it's FT_<TYPENAME> value. The array has a fixed size set by the
420 FT_NUM_MEMBERS compile time constant, which is the number of predefined
421 fundamental types gdb knows how to construct. */
422 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
424 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
425 but this would require a corresponding change in unpack_field_as_long
427 static int bits_per_byte
= 8;
429 /* The routines that read and process dies for a C struct or C++ class
430 pass lists of data member fields and lists of member function fields
431 in an instance of a field_info structure, as defined below. */
434 /* List of data member and baseclasses fields. */
437 struct nextfield
*next
;
444 /* Number of fields. */
447 /* Number of baseclasses. */
450 /* Set if the accesibility of one of the fields is not public. */
451 int non_public_fields
;
453 /* Member function fields array, entries are allocated in the order they
454 are encountered in the object file. */
457 struct nextfnfield
*next
;
458 struct fn_field fnfield
;
462 /* Member function fieldlist array, contains name of possibly overloaded
463 member function, number of overloaded member functions and a pointer
464 to the head of the member function field chain. */
469 struct nextfnfield
*head
;
473 /* Number of entries in the fnfieldlists array. */
477 /* Various complaints about symbol reading that don't abort the process */
479 static struct complaint dwarf2_const_ignored
=
481 "type qualifier 'const' ignored", 0, 0
483 static struct complaint dwarf2_volatile_ignored
=
485 "type qualifier 'volatile' ignored", 0, 0
487 static struct complaint dwarf2_non_const_array_bound_ignored
=
489 "non-constant array bounds form '%s' ignored", 0, 0
491 static struct complaint dwarf2_missing_line_number_section
=
493 "missing .debug_line section", 0, 0
495 static struct complaint dwarf2_mangled_line_number_section
=
497 "mangled .debug_line section", 0, 0
499 static struct complaint dwarf2_unsupported_die_ref_attr
=
501 "unsupported die ref attribute form: '%s'", 0, 0
503 static struct complaint dwarf2_unsupported_stack_op
=
505 "unsupported stack op: '%s'", 0, 0
507 static struct complaint dwarf2_complex_location_expr
=
509 "location expression too complex", 0, 0
511 static struct complaint dwarf2_unsupported_tag
=
513 "unsupported tag: '%s'", 0, 0
515 static struct complaint dwarf2_unsupported_at_encoding
=
517 "unsupported DW_AT_encoding: '%s'", 0, 0
519 static struct complaint dwarf2_unsupported_at_frame_base
=
521 "unsupported DW_AT_frame_base for function '%s'", 0, 0
523 static struct complaint dwarf2_unexpected_tag
=
525 "unexepected tag in read_type_die: '%s'", 0, 0
527 static struct complaint dwarf2_missing_at_frame_base
=
529 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
531 static struct complaint dwarf2_bad_static_member_name
=
533 "unrecognized static data member name '%s'", 0, 0
535 static struct complaint dwarf2_unsupported_accessibility
=
537 "unsupported accessibility %d", 0, 0
539 static struct complaint dwarf2_bad_member_name_complaint
=
541 "cannot extract member name from '%s'", 0, 0
543 static struct complaint dwarf2_missing_member_fn_type_complaint
=
545 "member function type missing for '%s'", 0, 0
547 static struct complaint dwarf2_vtbl_not_found_complaint
=
549 "virtual function table pointer not found when defining class '%s'", 0, 0
551 static struct complaint dwarf2_absolute_sibling_complaint
=
553 "ignoring absolute DW_AT_sibling", 0, 0
555 static struct complaint dwarf2_const_value_length_mismatch
=
557 "const value length mismatch for '%s', got %d, expected %d", 0, 0
559 static struct complaint dwarf2_unsupported_const_value_attr
=
561 "unsupported const value attribute form: '%s'", 0, 0
564 /* local function prototypes */
566 static void dwarf2_locate_sections (bfd
*, asection
*, PTR
);
569 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
572 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
574 static char *scan_partial_symbols (char *, struct objfile
*,
575 CORE_ADDR
*, CORE_ADDR
*,
576 const struct comp_unit_head
*);
578 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
579 const struct comp_unit_head
*);
581 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
583 static void psymtab_to_symtab_1 (struct partial_symtab
*);
585 char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int);
587 static void dwarf2_read_abbrevs (bfd
*, unsigned int);
589 static void dwarf2_empty_abbrev_table (PTR
);
591 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int);
593 static char *read_partial_die (struct partial_die_info
*,
595 const struct comp_unit_head
*);
597 static char *read_full_die (struct die_info
**, bfd
*, char *,
598 const struct comp_unit_head
*);
600 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
601 bfd
*, char *, const struct comp_unit_head
*);
603 static char *read_attribute_value (struct attribute
*, unsigned,
604 bfd
*, char *, const struct comp_unit_head
*);
606 static unsigned int read_1_byte (bfd
*, char *);
608 static int read_1_signed_byte (bfd
*, char *);
610 static unsigned int read_2_bytes (bfd
*, char *);
612 static unsigned int read_4_bytes (bfd
*, char *);
614 static unsigned long read_8_bytes (bfd
*, char *);
616 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
619 static LONGEST
read_initial_length (bfd
*, char *,
620 struct comp_unit_head
*, int *bytes_read
);
622 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
625 static char *read_n_bytes (bfd
*, char *, unsigned int);
627 static char *read_string (bfd
*, char *, unsigned int *);
629 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
632 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
634 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
636 static void set_cu_language (unsigned int);
638 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
640 static int die_is_declaration (struct die_info
*);
642 static void dwarf_decode_lines (unsigned int, char *, bfd
*,
643 const struct comp_unit_head
*);
645 static void dwarf2_start_subfile (char *, char *);
647 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
648 struct objfile
*, const struct comp_unit_head
*);
650 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
651 struct objfile
*, const struct comp_unit_head
*);
653 static void dwarf2_const_value_data (struct attribute
*attr
,
657 static struct type
*die_type (struct die_info
*, struct objfile
*,
658 const struct comp_unit_head
*);
660 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
661 const struct comp_unit_head
*);
664 static struct type
*type_at_offset (unsigned int, struct objfile
*);
667 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
668 const struct comp_unit_head
*);
670 static void read_type_die (struct die_info
*, struct objfile
*,
671 const struct comp_unit_head
*);
673 static void read_typedef (struct die_info
*, struct objfile
*,
674 const struct comp_unit_head
*);
676 static void read_base_type (struct die_info
*, struct objfile
*);
678 static void read_file_scope (struct die_info
*, struct objfile
*,
679 const struct comp_unit_head
*);
681 static void read_func_scope (struct die_info
*, struct objfile
*,
682 const struct comp_unit_head
*);
684 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
685 const struct comp_unit_head
*);
687 static int dwarf2_get_pc_bounds (struct die_info
*,
688 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*);
690 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
691 struct objfile
*, const struct comp_unit_head
*);
693 static void dwarf2_attach_fields_to_type (struct field_info
*,
694 struct type
*, struct objfile
*);
696 static void dwarf2_add_member_fn (struct field_info
*,
697 struct die_info
*, struct type
*,
698 struct objfile
*objfile
,
699 const struct comp_unit_head
*);
701 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
702 struct type
*, struct objfile
*);
704 static void read_structure_scope (struct die_info
*, struct objfile
*,
705 const struct comp_unit_head
*);
707 static void read_common_block (struct die_info
*, struct objfile
*,
708 const struct comp_unit_head
*);
710 static void read_enumeration (struct die_info
*, struct objfile
*,
711 const struct comp_unit_head
*);
713 static struct type
*dwarf_base_type (int, int, struct objfile
*);
715 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
716 const struct comp_unit_head
*);
718 static void read_array_type (struct die_info
*, struct objfile
*,
719 const struct comp_unit_head
*);
721 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
722 const struct comp_unit_head
*);
724 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
725 const struct comp_unit_head
*);
727 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
728 const struct comp_unit_head
*);
730 static void read_tag_const_type (struct die_info
*, struct objfile
*,
731 const struct comp_unit_head
*);
733 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
734 const struct comp_unit_head
*);
736 static void read_tag_string_type (struct die_info
*, struct objfile
*);
738 static void read_subroutine_type (struct die_info
*, struct objfile
*,
739 const struct comp_unit_head
*);
741 static struct die_info
*read_comp_unit (char *, bfd
*,
742 const struct comp_unit_head
*);
744 static void free_die_list (struct die_info
*);
746 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
748 static void process_die (struct die_info
*, struct objfile
*,
749 const struct comp_unit_head
*);
751 static char *dwarf2_linkage_name (struct die_info
*);
753 static char *dwarf_tag_name (unsigned int);
755 static char *dwarf_attr_name (unsigned int);
757 static char *dwarf_form_name (unsigned int);
759 static char *dwarf_stack_op_name (unsigned int);
761 static char *dwarf_bool_name (unsigned int);
763 static char *dwarf_type_encoding_name (unsigned int);
766 static char *dwarf_cfi_name (unsigned int);
768 struct die_info
*copy_die (struct die_info
*);
771 static struct die_info
*sibling_die (struct die_info
*);
773 static void dump_die (struct die_info
*);
775 static void dump_die_list (struct die_info
*);
777 static void store_in_ref_table (unsigned int, struct die_info
*);
779 static void dwarf2_empty_hash_tables (void);
781 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
783 static struct die_info
*follow_die_ref (unsigned int);
785 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
787 /* memory allocation interface */
789 static void dwarf2_free_tmp_obstack (PTR
);
791 static struct dwarf_block
*dwarf_alloc_block (void);
793 static struct abbrev_info
*dwarf_alloc_abbrev (void);
795 static struct die_info
*dwarf_alloc_die (void);
797 /* Try to locate the sections we need for DWARF 2 debugging
798 information and return true if we have enough to do something. */
801 dwarf2_has_info (bfd
*abfd
)
803 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
804 dwarf_str_offset
= 0;
805 dwarf_frame_offset
= dwarf_eh_frame_offset
= 0;
806 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
807 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
817 /* This function is mapped across the sections and remembers the
818 offset and size of each of the debugging sections we are interested
822 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, PTR ignore_ptr
)
824 if (STREQ (sectp
->name
, INFO_SECTION
))
826 dwarf_info_offset
= sectp
->filepos
;
827 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
829 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
831 dwarf_abbrev_offset
= sectp
->filepos
;
832 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
834 else if (STREQ (sectp
->name
, LINE_SECTION
))
836 dwarf_line_offset
= sectp
->filepos
;
837 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
839 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
841 dwarf_pubnames_offset
= sectp
->filepos
;
842 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
844 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
846 dwarf_aranges_offset
= sectp
->filepos
;
847 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
849 else if (STREQ (sectp
->name
, LOC_SECTION
))
851 dwarf_loc_offset
= sectp
->filepos
;
852 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
854 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
856 dwarf_macinfo_offset
= sectp
->filepos
;
857 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
859 else if (STREQ (sectp
->name
, STR_SECTION
))
861 dwarf_str_offset
= sectp
->filepos
;
862 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
864 else if (STREQ (sectp
->name
, FRAME_SECTION
))
866 dwarf_frame_offset
= sectp
->filepos
;
867 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
869 else if (STREQ (sectp
->name
, EH_FRAME_SECTION
))
871 dwarf_eh_frame_offset
= sectp
->filepos
;
872 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
876 /* Build a partial symbol table. */
879 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
882 /* We definitely need the .debug_info and .debug_abbrev sections */
884 dwarf_info_buffer
= dwarf2_read_section (objfile
,
887 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
890 dwarf_line_buffer
= dwarf2_read_section (objfile
,
894 if (dwarf_str_offset
)
895 dwarf_str_buffer
= dwarf2_read_section (objfile
,
899 dwarf_str_buffer
= NULL
;
902 || (objfile
->global_psymbols
.size
== 0
903 && objfile
->static_psymbols
.size
== 0))
905 init_psymbol_list (objfile
, 1024);
909 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
911 /* Things are significantly easier if we have .debug_aranges and
912 .debug_pubnames sections */
914 dwarf2_build_psymtabs_easy (objfile
, mainline
);
918 /* only test this case for now */
920 /* In this case we have to work a bit harder */
921 dwarf2_build_psymtabs_hard (objfile
, mainline
);
926 /* Build the partial symbol table from the information in the
927 .debug_pubnames and .debug_aranges sections. */
930 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
932 bfd
*abfd
= objfile
->obfd
;
933 char *aranges_buffer
, *pubnames_buffer
;
934 char *aranges_ptr
, *pubnames_ptr
;
935 unsigned int entry_length
, version
, info_offset
, info_size
;
937 pubnames_buffer
= dwarf2_read_section (objfile
,
938 dwarf_pubnames_offset
,
939 dwarf_pubnames_size
);
940 pubnames_ptr
= pubnames_buffer
;
941 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
943 struct comp_unit_head cu_header
;
946 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
948 pubnames_ptr
+= bytes_read
;
949 version
= read_1_byte (abfd
, pubnames_ptr
);
951 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
953 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
957 aranges_buffer
= dwarf2_read_section (objfile
,
958 dwarf_aranges_offset
,
964 /* Read in the comp unit header information from the debug_info at
968 read_comp_unit_head (struct comp_unit_head
*cu_header
,
969 char *info_ptr
, bfd
*abfd
)
973 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
975 info_ptr
+= bytes_read
;
976 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
978 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
980 info_ptr
+= bytes_read
;
981 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
983 signed_addr
= bfd_get_sign_extend_vma (abfd
);
985 internal_error (__FILE__
, __LINE__
,
986 "read_comp_unit_head: dwarf from non elf file");
987 cu_header
->signed_addr_p
= signed_addr
;
991 /* Build the partial symbol table by doing a quick pass through the
992 .debug_info and .debug_abbrev sections. */
995 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
997 /* Instead of reading this into a big buffer, we should probably use
998 mmap() on architectures that support it. (FIXME) */
999 bfd
*abfd
= objfile
->obfd
;
1000 char *info_ptr
, *abbrev_ptr
;
1001 char *beg_of_comp_unit
;
1002 struct partial_die_info comp_unit_die
;
1003 struct partial_symtab
*pst
;
1004 struct cleanup
*back_to
;
1005 CORE_ADDR lowpc
, highpc
;
1007 info_ptr
= dwarf_info_buffer
;
1008 abbrev_ptr
= dwarf_abbrev_buffer
;
1010 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1011 the partial symbol scan, like attribute values.
1013 We could reduce our peak memory consumption during partial symbol
1014 table construction by freeing stuff from this obstack more often
1015 --- say, after processing each compilation unit, or each die ---
1016 but it turns out that this saves almost nothing. For an
1017 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1018 on dwarf2_tmp_obstack. Some investigation showed:
1020 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1021 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1022 all fixed-length values not requiring dynamic allocation.
1024 2) 30% of the attributes used the form DW_FORM_string. For
1025 DW_FORM_string, read_attribute simply hands back a pointer to
1026 the null-terminated string in dwarf_info_buffer, so no dynamic
1027 allocation is needed there either.
1029 3) The remaining 1% of the attributes all used DW_FORM_block1.
1030 75% of those were DW_AT_frame_base location lists for
1031 functions; the rest were DW_AT_location attributes, probably
1032 for the global variables.
1034 Anyway, what this all means is that the memory the dwarf2
1035 reader uses as temporary space reading partial symbols is about
1036 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1038 obstack_init (&dwarf2_tmp_obstack
);
1039 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1041 /* Since the objects we're extracting from dwarf_info_buffer vary in
1042 length, only the individual functions to extract them (like
1043 read_comp_unit_head and read_partial_die) can really know whether
1044 the buffer is large enough to hold another complete object.
1046 At the moment, they don't actually check that. If
1047 dwarf_info_buffer holds just one extra byte after the last
1048 compilation unit's dies, then read_comp_unit_head will happily
1049 read off the end of the buffer. read_partial_die is similarly
1050 casual. Those functions should be fixed.
1052 For this loop condition, simply checking whether there's any data
1053 left at all should be sufficient. */
1054 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1056 struct comp_unit_head cu_header
;
1057 beg_of_comp_unit
= info_ptr
;
1058 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1060 if (cu_header
.version
!= 2)
1062 error ("Dwarf Error: wrong version in compilation unit header.");
1065 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
1067 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
1068 (long) cu_header
.abbrev_offset
,
1069 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1072 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1073 > dwarf_info_buffer
+ dwarf_info_size
)
1075 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
1076 (long) cu_header
.length
,
1077 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1080 /* Read the abbrevs for this compilation unit into a table */
1081 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1082 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1084 /* Read the compilation unit die */
1085 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1088 /* Set the language we're debugging */
1089 set_cu_language (comp_unit_die
.language
);
1091 /* Allocate a new partial symbol table structure */
1092 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1093 comp_unit_die
.name
? comp_unit_die
.name
: "",
1094 comp_unit_die
.lowpc
,
1095 objfile
->global_psymbols
.next
,
1096 objfile
->static_psymbols
.next
);
1098 pst
->read_symtab_private
= (char *)
1099 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1100 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1101 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1102 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1103 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1104 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1105 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1106 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1107 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1108 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1110 /* Store the function that reads in the rest of the symbol table */
1111 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1113 /* Check if comp unit has_children.
1114 If so, read the rest of the partial symbols from this comp unit.
1115 If not, there's no more debug_info for this comp unit. */
1116 if (comp_unit_die
.has_children
)
1118 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1121 /* If the compilation unit didn't have an explicit address range,
1122 then use the information extracted from its child dies. */
1123 if (! comp_unit_die
.has_pc_info
)
1125 comp_unit_die
.lowpc
= lowpc
;
1126 comp_unit_die
.highpc
= highpc
;
1129 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1130 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1132 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1133 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1134 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1135 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1136 sort_pst_symbols (pst
);
1138 /* If there is already a psymtab or symtab for a file of this
1139 name, remove it. (If there is a symtab, more drastic things
1140 also happen.) This happens in VxWorks. */
1141 free_named_symtabs (pst
->filename
);
1143 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1144 + cu_header
.initial_length_size
;
1146 do_cleanups (back_to
);
1149 /* Read in all interesting dies to the end of the compilation unit. */
1152 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1153 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1154 const struct comp_unit_head
*cu_header
)
1156 bfd
*abfd
= objfile
->obfd
;
1157 struct partial_die_info pdi
;
1159 /* This function is called after we've read in the comp_unit_die in
1160 order to read its children. We start the nesting level at 1 since
1161 we have pushed 1 level down in order to read the comp unit's children.
1162 The comp unit itself is at level 0, so we stop reading when we pop
1163 back to that level. */
1165 int nesting_level
= 1;
1167 *lowpc
= ((CORE_ADDR
) -1);
1168 *highpc
= ((CORE_ADDR
) 0);
1170 while (nesting_level
)
1172 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1178 case DW_TAG_subprogram
:
1179 if (pdi
.has_pc_info
)
1181 if (pdi
.lowpc
< *lowpc
)
1185 if (pdi
.highpc
> *highpc
)
1187 *highpc
= pdi
.highpc
;
1189 if ((pdi
.is_external
|| nesting_level
== 1)
1190 && !pdi
.is_declaration
)
1192 add_partial_symbol (&pdi
, objfile
, cu_header
);
1196 case DW_TAG_variable
:
1197 case DW_TAG_typedef
:
1198 case DW_TAG_class_type
:
1199 case DW_TAG_structure_type
:
1200 case DW_TAG_union_type
:
1201 case DW_TAG_enumeration_type
:
1202 if ((pdi
.is_external
|| nesting_level
== 1)
1203 && !pdi
.is_declaration
)
1205 add_partial_symbol (&pdi
, objfile
, cu_header
);
1208 case DW_TAG_enumerator
:
1209 /* File scope enumerators are added to the partial symbol
1211 if (nesting_level
== 2)
1212 add_partial_symbol (&pdi
, objfile
, cu_header
);
1214 case DW_TAG_base_type
:
1215 /* File scope base type definitions are added to the partial
1217 if (nesting_level
== 1)
1218 add_partial_symbol (&pdi
, objfile
, cu_header
);
1225 /* If the die has a sibling, skip to the sibling.
1226 Do not skip enumeration types, we want to record their
1228 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1230 info_ptr
= pdi
.sibling
;
1232 else if (pdi
.has_children
)
1234 /* Die has children, but the optional DW_AT_sibling attribute
1245 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1246 from `maint check'. */
1247 if (*lowpc
== ((CORE_ADDR
) -1))
1253 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1254 const struct comp_unit_head
*cu_header
)
1260 case DW_TAG_subprogram
:
1261 if (pdi
->is_external
)
1263 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1264 mst_text, objfile); */
1265 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1266 VAR_NAMESPACE
, LOC_BLOCK
,
1267 &objfile
->global_psymbols
,
1268 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1272 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1273 mst_file_text, objfile); */
1274 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1275 VAR_NAMESPACE
, LOC_BLOCK
,
1276 &objfile
->static_psymbols
,
1277 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1280 case DW_TAG_variable
:
1281 if (pdi
->is_external
)
1284 Don't enter into the minimal symbol tables as there is
1285 a minimal symbol table entry from the ELF symbols already.
1286 Enter into partial symbol table if it has a location
1287 descriptor or a type.
1288 If the location descriptor is missing, new_symbol will create
1289 a LOC_UNRESOLVED symbol, the address of the variable will then
1290 be determined from the minimal symbol table whenever the variable
1292 The address for the partial symbol table entry is not
1293 used by GDB, but it comes in handy for debugging partial symbol
1297 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1298 if (pdi
->locdesc
|| pdi
->has_type
)
1299 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1300 VAR_NAMESPACE
, LOC_STATIC
,
1301 &objfile
->global_psymbols
,
1302 0, addr
+ baseaddr
, cu_language
, objfile
);
1306 /* Static Variable. Skip symbols without location descriptors. */
1307 if (pdi
->locdesc
== NULL
)
1309 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1310 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1311 mst_file_data, objfile); */
1312 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1313 VAR_NAMESPACE
, LOC_STATIC
,
1314 &objfile
->static_psymbols
,
1315 0, addr
+ baseaddr
, cu_language
, objfile
);
1318 case DW_TAG_typedef
:
1319 case DW_TAG_base_type
:
1320 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1321 VAR_NAMESPACE
, LOC_TYPEDEF
,
1322 &objfile
->static_psymbols
,
1323 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1325 case DW_TAG_class_type
:
1326 case DW_TAG_structure_type
:
1327 case DW_TAG_union_type
:
1328 case DW_TAG_enumeration_type
:
1329 /* Skip aggregate types without children, these are external
1331 if (pdi
->has_children
== 0)
1333 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1334 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1335 &objfile
->static_psymbols
,
1336 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1338 if (cu_language
== language_cplus
)
1340 /* For C++, these implicitly act as typedefs as well. */
1341 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1342 VAR_NAMESPACE
, LOC_TYPEDEF
,
1343 &objfile
->static_psymbols
,
1344 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1347 case DW_TAG_enumerator
:
1348 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1349 VAR_NAMESPACE
, LOC_CONST
,
1350 &objfile
->static_psymbols
,
1351 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1358 /* Expand this partial symbol table into a full symbol table. */
1361 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1363 /* FIXME: This is barely more than a stub. */
1368 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1374 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1375 gdb_flush (gdb_stdout
);
1378 psymtab_to_symtab_1 (pst
);
1380 /* Finish up the debug error message. */
1382 printf_filtered ("done.\n");
1388 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1390 struct objfile
*objfile
= pst
->objfile
;
1391 bfd
*abfd
= objfile
->obfd
;
1392 struct comp_unit_head cu_header
;
1393 struct die_info
*dies
;
1394 unsigned long offset
;
1395 CORE_ADDR lowpc
, highpc
;
1396 struct die_info
*child_die
;
1398 struct symtab
*symtab
;
1399 struct cleanup
*back_to
;
1401 /* Set local variables from the partial symbol table info. */
1402 offset
= DWARF_INFO_OFFSET (pst
);
1403 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1404 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1405 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1406 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1407 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1408 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1409 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1410 cu_header_offset
= offset
;
1411 info_ptr
= dwarf_info_buffer
+ offset
;
1413 obstack_init (&dwarf2_tmp_obstack
);
1414 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1417 make_cleanup (really_free_pendings
, NULL
);
1419 /* read in the comp_unit header */
1420 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1422 /* Read the abbrevs for this compilation unit */
1423 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1424 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1426 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1428 make_cleanup_free_die_list (dies
);
1430 /* Do line number decoding in read_file_scope () */
1431 process_die (dies
, objfile
, &cu_header
);
1433 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1435 /* Some compilers don't define a DW_AT_high_pc attribute for
1436 the compilation unit. If the DW_AT_high_pc is missing,
1437 synthesize it, by scanning the DIE's below the compilation unit. */
1439 if (dies
->has_children
)
1441 child_die
= dies
->next
;
1442 while (child_die
&& child_die
->tag
)
1444 if (child_die
->tag
== DW_TAG_subprogram
)
1446 CORE_ADDR low
, high
;
1448 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1450 highpc
= max (highpc
, high
);
1453 child_die
= sibling_die (child_die
);
1457 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1459 /* Set symtab language to language from DW_AT_language.
1460 If the compilation is from a C file generated by language preprocessors,
1461 do not set the language if it was already deduced by start_subfile. */
1463 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1465 symtab
->language
= cu_language
;
1467 pst
->symtab
= symtab
;
1469 sort_symtab_syms (pst
->symtab
);
1471 do_cleanups (back_to
);
1474 /* Process a die and its children. */
1477 process_die (struct die_info
*die
, struct objfile
*objfile
,
1478 const struct comp_unit_head
*cu_header
)
1482 case DW_TAG_padding
:
1484 case DW_TAG_compile_unit
:
1485 read_file_scope (die
, objfile
, cu_header
);
1487 case DW_TAG_subprogram
:
1488 read_subroutine_type (die
, objfile
, cu_header
);
1489 read_func_scope (die
, objfile
, cu_header
);
1491 case DW_TAG_inlined_subroutine
:
1492 /* FIXME: These are ignored for now.
1493 They could be used to set breakpoints on all inlined instances
1494 of a function and make GDB `next' properly over inlined functions. */
1496 case DW_TAG_lexical_block
:
1497 read_lexical_block_scope (die
, objfile
, cu_header
);
1499 case DW_TAG_class_type
:
1500 case DW_TAG_structure_type
:
1501 case DW_TAG_union_type
:
1502 read_structure_scope (die
, objfile
, cu_header
);
1504 case DW_TAG_enumeration_type
:
1505 read_enumeration (die
, objfile
, cu_header
);
1507 case DW_TAG_subroutine_type
:
1508 read_subroutine_type (die
, objfile
, cu_header
);
1510 case DW_TAG_array_type
:
1511 read_array_type (die
, objfile
, cu_header
);
1513 case DW_TAG_pointer_type
:
1514 read_tag_pointer_type (die
, objfile
, cu_header
);
1516 case DW_TAG_ptr_to_member_type
:
1517 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1519 case DW_TAG_reference_type
:
1520 read_tag_reference_type (die
, objfile
, cu_header
);
1522 case DW_TAG_string_type
:
1523 read_tag_string_type (die
, objfile
);
1525 case DW_TAG_base_type
:
1526 read_base_type (die
, objfile
);
1527 if (dwarf_attr (die
, DW_AT_name
))
1529 /* Add a typedef symbol for the base type definition. */
1530 new_symbol (die
, die
->type
, objfile
, cu_header
);
1533 case DW_TAG_common_block
:
1534 read_common_block (die
, objfile
, cu_header
);
1536 case DW_TAG_common_inclusion
:
1539 new_symbol (die
, NULL
, objfile
, cu_header
);
1545 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1546 const struct comp_unit_head
*cu_header
)
1548 unsigned int line_offset
= 0;
1549 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1550 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1551 struct attribute
*attr
;
1552 char *name
= "<unknown>";
1553 char *comp_dir
= NULL
;
1554 struct die_info
*child_die
;
1555 bfd
*abfd
= objfile
->obfd
;
1557 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1559 if (die
->has_children
)
1561 child_die
= die
->next
;
1562 while (child_die
&& child_die
->tag
)
1564 if (child_die
->tag
== DW_TAG_subprogram
)
1566 CORE_ADDR low
, high
;
1568 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1570 lowpc
= min (lowpc
, low
);
1571 highpc
= max (highpc
, high
);
1574 child_die
= sibling_die (child_die
);
1579 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1580 from finish_block. */
1581 if (lowpc
== ((CORE_ADDR
) -1))
1586 attr
= dwarf_attr (die
, DW_AT_name
);
1589 name
= DW_STRING (attr
);
1591 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1594 comp_dir
= DW_STRING (attr
);
1597 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1598 directory, get rid of it. */
1599 char *cp
= strchr (comp_dir
, ':');
1601 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1606 if (objfile
->ei
.entry_point
>= lowpc
&&
1607 objfile
->ei
.entry_point
< highpc
)
1609 objfile
->ei
.entry_file_lowpc
= lowpc
;
1610 objfile
->ei
.entry_file_highpc
= highpc
;
1613 attr
= dwarf_attr (die
, DW_AT_language
);
1616 set_cu_language (DW_UNSND (attr
));
1619 /* We assume that we're processing GCC output. */
1620 processing_gcc_compilation
= 2;
1622 /* FIXME:Do something here. */
1623 if (dip
->at_producer
!= NULL
)
1625 handle_producer (dip
->at_producer
);
1629 /* The compilation unit may be in a different language or objfile,
1630 zero out all remembered fundamental types. */
1631 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1633 start_symtab (name
, comp_dir
, lowpc
);
1634 record_debugformat ("DWARF 2");
1636 /* Decode line number information if present. */
1637 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1640 line_offset
= DW_UNSND (attr
);
1641 dwarf_decode_lines (line_offset
, comp_dir
, abfd
, cu_header
);
1644 /* Process all dies in compilation unit. */
1645 if (die
->has_children
)
1647 child_die
= die
->next
;
1648 while (child_die
&& child_die
->tag
)
1650 process_die (child_die
, objfile
, cu_header
);
1651 child_die
= sibling_die (child_die
);
1657 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
1658 const struct comp_unit_head
*cu_header
)
1660 register struct context_stack
*new;
1663 struct die_info
*child_die
;
1664 struct attribute
*attr
;
1667 name
= dwarf2_linkage_name (die
);
1669 /* Ignore functions with missing or empty names and functions with
1670 missing or invalid low and high pc attributes. */
1671 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1677 if (objfile
->ei
.entry_point
>= lowpc
&&
1678 objfile
->ei
.entry_point
< highpc
)
1680 objfile
->ei
.entry_func_lowpc
= lowpc
;
1681 objfile
->ei
.entry_func_highpc
= highpc
;
1684 /* Decode DW_AT_frame_base location descriptor if present, keep result
1685 for DW_OP_fbreg operands in decode_locdesc. */
1686 frame_base_reg
= -1;
1687 frame_base_offset
= 0;
1688 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1691 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
1693 complain (&dwarf2_unsupported_at_frame_base
, name
);
1695 frame_base_reg
= addr
;
1698 frame_base_reg
= basereg
;
1699 frame_base_offset
= addr
;
1702 complain (&dwarf2_unsupported_at_frame_base
, name
);
1705 new = push_context (0, lowpc
);
1706 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
1707 list_in_scope
= &local_symbols
;
1709 if (die
->has_children
)
1711 child_die
= die
->next
;
1712 while (child_die
&& child_die
->tag
)
1714 process_die (child_die
, objfile
, cu_header
);
1715 child_die
= sibling_die (child_die
);
1719 new = pop_context ();
1720 /* Make a block for the local symbols within. */
1721 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1722 lowpc
, highpc
, objfile
);
1723 list_in_scope
= &file_symbols
;
1726 /* Process all the DIES contained within a lexical block scope. Start
1727 a new scope, process the dies, and then close the scope. */
1730 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
1731 const struct comp_unit_head
*cu_header
)
1733 register struct context_stack
*new;
1734 CORE_ADDR lowpc
, highpc
;
1735 struct die_info
*child_die
;
1737 /* Ignore blocks with missing or invalid low and high pc attributes. */
1738 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1743 push_context (0, lowpc
);
1744 if (die
->has_children
)
1746 child_die
= die
->next
;
1747 while (child_die
&& child_die
->tag
)
1749 process_die (child_die
, objfile
, cu_header
);
1750 child_die
= sibling_die (child_die
);
1753 new = pop_context ();
1755 if (local_symbols
!= NULL
)
1757 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1760 local_symbols
= new->locals
;
1763 /* Get low and high pc attributes from a die.
1764 Return 1 if the attributes are present and valid, otherwise, return 0. */
1767 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1768 struct objfile
*objfile
)
1770 struct attribute
*attr
;
1774 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1776 low
= DW_ADDR (attr
);
1779 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1781 high
= DW_ADDR (attr
);
1788 /* When using the GNU linker, .gnu.linkonce. sections are used to
1789 eliminate duplicate copies of functions and vtables and such.
1790 The linker will arbitrarily choose one and discard the others.
1791 The AT_*_pc values for such functions refer to local labels in
1792 these sections. If the section from that file was discarded, the
1793 labels are not in the output, so the relocs get a value of 0.
1794 If this is a discarded function, mark the pc bounds as invalid,
1795 so that GDB will ignore it. */
1796 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1804 /* Add an aggregate field to the field list. */
1807 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
1808 struct objfile
*objfile
,
1809 const struct comp_unit_head
*cu_header
)
1811 struct nextfield
*new_field
;
1812 struct attribute
*attr
;
1814 char *fieldname
= "";
1816 /* Allocate a new field list entry and link it in. */
1817 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1818 make_cleanup (xfree
, new_field
);
1819 memset (new_field
, 0, sizeof (struct nextfield
));
1820 new_field
->next
= fip
->fields
;
1821 fip
->fields
= new_field
;
1824 /* Handle accessibility and virtuality of field.
1825 The default accessibility for members is public, the default
1826 accessibility for inheritance is private. */
1827 if (die
->tag
!= DW_TAG_inheritance
)
1828 new_field
->accessibility
= DW_ACCESS_public
;
1830 new_field
->accessibility
= DW_ACCESS_private
;
1831 new_field
->virtuality
= DW_VIRTUALITY_none
;
1833 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1835 new_field
->accessibility
= DW_UNSND (attr
);
1836 if (new_field
->accessibility
!= DW_ACCESS_public
)
1837 fip
->non_public_fields
= 1;
1838 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1840 new_field
->virtuality
= DW_UNSND (attr
);
1842 fp
= &new_field
->field
;
1843 if (die
->tag
== DW_TAG_member
)
1845 /* Get type of field. */
1846 fp
->type
= die_type (die
, objfile
, cu_header
);
1848 /* Get bit size of field (zero if none). */
1849 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1852 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1856 FIELD_BITSIZE (*fp
) = 0;
1859 /* Get bit offset of field. */
1860 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1863 FIELD_BITPOS (*fp
) =
1864 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
1867 FIELD_BITPOS (*fp
) = 0;
1868 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1871 if (BITS_BIG_ENDIAN
)
1873 /* For big endian bits, the DW_AT_bit_offset gives the
1874 additional bit offset from the MSB of the containing
1875 anonymous object to the MSB of the field. We don't
1876 have to do anything special since we don't need to
1877 know the size of the anonymous object. */
1878 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1882 /* For little endian bits, compute the bit offset to the
1883 MSB of the anonymous object, subtract off the number of
1884 bits from the MSB of the field to the MSB of the
1885 object, and then subtract off the number of bits of
1886 the field itself. The result is the bit offset of
1887 the LSB of the field. */
1889 int bit_offset
= DW_UNSND (attr
);
1891 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1894 /* The size of the anonymous object containing
1895 the bit field is explicit, so use the
1896 indicated size (in bytes). */
1897 anonymous_size
= DW_UNSND (attr
);
1901 /* The size of the anonymous object containing
1902 the bit field must be inferred from the type
1903 attribute of the data member containing the
1905 anonymous_size
= TYPE_LENGTH (fp
->type
);
1907 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1908 - bit_offset
- FIELD_BITSIZE (*fp
);
1912 /* Get name of field. */
1913 attr
= dwarf_attr (die
, DW_AT_name
);
1914 if (attr
&& DW_STRING (attr
))
1915 fieldname
= DW_STRING (attr
);
1916 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1917 &objfile
->type_obstack
);
1919 /* Change accessibility for artificial fields (e.g. virtual table
1920 pointer or virtual base class pointer) to private. */
1921 if (dwarf_attr (die
, DW_AT_artificial
))
1923 new_field
->accessibility
= DW_ACCESS_private
;
1924 fip
->non_public_fields
= 1;
1927 else if (die
->tag
== DW_TAG_variable
)
1931 /* C++ static member.
1932 Get name of field. */
1933 attr
= dwarf_attr (die
, DW_AT_name
);
1934 if (attr
&& DW_STRING (attr
))
1935 fieldname
= DW_STRING (attr
);
1939 /* Get physical name. */
1940 physname
= dwarf2_linkage_name (die
);
1942 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1943 &objfile
->type_obstack
));
1944 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1945 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1946 &objfile
->type_obstack
);
1948 else if (die
->tag
== DW_TAG_inheritance
)
1950 /* C++ base class field. */
1951 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1953 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
1955 FIELD_BITSIZE (*fp
) = 0;
1956 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1957 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1958 fip
->nbaseclasses
++;
1962 /* Create the vector of fields, and attach it to the type. */
1965 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
1966 struct objfile
*objfile
)
1968 int nfields
= fip
->nfields
;
1970 /* Record the field count, allocate space for the array of fields,
1971 and create blank accessibility bitfields if necessary. */
1972 TYPE_NFIELDS (type
) = nfields
;
1973 TYPE_FIELDS (type
) = (struct field
*)
1974 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1975 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1977 if (fip
->non_public_fields
)
1979 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1981 TYPE_FIELD_PRIVATE_BITS (type
) =
1982 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1983 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1985 TYPE_FIELD_PROTECTED_BITS (type
) =
1986 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1987 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1989 TYPE_FIELD_IGNORE_BITS (type
) =
1990 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1991 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1994 /* If the type has baseclasses, allocate and clear a bit vector for
1995 TYPE_FIELD_VIRTUAL_BITS. */
1996 if (fip
->nbaseclasses
)
1998 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2001 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2002 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2003 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2004 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2005 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2008 /* Copy the saved-up fields into the field vector. Start from the head
2009 of the list, adding to the tail of the field array, so that they end
2010 up in the same order in the array in which they were added to the list. */
2011 while (nfields
-- > 0)
2013 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2014 switch (fip
->fields
->accessibility
)
2016 case DW_ACCESS_private
:
2017 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2020 case DW_ACCESS_protected
:
2021 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2024 case DW_ACCESS_public
:
2028 /* Unknown accessibility. Complain and treat it as public. */
2030 complain (&dwarf2_unsupported_accessibility
,
2031 fip
->fields
->accessibility
);
2035 if (nfields
< fip
->nbaseclasses
)
2037 switch (fip
->fields
->virtuality
)
2039 case DW_VIRTUALITY_virtual
:
2040 case DW_VIRTUALITY_pure_virtual
:
2041 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2045 fip
->fields
= fip
->fields
->next
;
2049 /* Add a member function to the proper fieldlist. */
2052 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2053 struct type
*type
, struct objfile
*objfile
,
2054 const struct comp_unit_head
*cu_header
)
2056 struct attribute
*attr
;
2057 struct fnfieldlist
*flp
;
2059 struct fn_field
*fnp
;
2062 struct nextfnfield
*new_fnfield
;
2064 /* Get name of member function. */
2065 attr
= dwarf_attr (die
, DW_AT_name
);
2066 if (attr
&& DW_STRING (attr
))
2067 fieldname
= DW_STRING (attr
);
2071 /* Get the mangled name. */
2072 physname
= dwarf2_linkage_name (die
);
2074 /* Look up member function name in fieldlist. */
2075 for (i
= 0; i
< fip
->nfnfields
; i
++)
2077 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2081 /* Create new list element if necessary. */
2082 if (i
< fip
->nfnfields
)
2083 flp
= &fip
->fnfieldlists
[i
];
2086 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2088 fip
->fnfieldlists
= (struct fnfieldlist
*)
2089 xrealloc (fip
->fnfieldlists
,
2090 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2091 * sizeof (struct fnfieldlist
));
2092 if (fip
->nfnfields
== 0)
2093 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2095 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2096 flp
->name
= fieldname
;
2102 /* Create a new member function field and chain it to the field list
2104 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2105 make_cleanup (xfree
, new_fnfield
);
2106 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2107 new_fnfield
->next
= flp
->head
;
2108 flp
->head
= new_fnfield
;
2111 /* Fill in the member function field info. */
2112 fnp
= &new_fnfield
->fnfield
;
2113 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2114 &objfile
->type_obstack
);
2115 fnp
->type
= alloc_type (objfile
);
2116 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2118 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2119 struct type
**arg_types
;
2120 int nparams
= TYPE_NFIELDS (die
->type
);
2123 /* Copy argument types from the subroutine type. */
2124 arg_types
= (struct type
**)
2125 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2126 for (iparams
= 0; iparams
< nparams
; iparams
++)
2127 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2129 /* Set last entry in argument type vector. */
2130 if (TYPE_VARARGS (die
->type
))
2131 arg_types
[nparams
] = NULL
;
2133 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2135 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2137 /* Handle static member functions.
2138 Dwarf2 has no clean way to discern C++ static and non-static
2139 member functions. G++ helps GDB by marking the first
2140 parameter for non-static member functions (which is the
2141 this pointer) as artificial. We obtain this information
2142 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2143 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2144 fnp
->voffset
= VOFFSET_STATIC
;
2147 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2149 /* Get fcontext from DW_AT_containing_type if present. */
2150 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2151 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2153 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2154 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2156 /* Get accessibility. */
2157 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2160 switch (DW_UNSND (attr
))
2162 case DW_ACCESS_private
:
2163 fnp
->is_private
= 1;
2165 case DW_ACCESS_protected
:
2166 fnp
->is_protected
= 1;
2171 /* Check for artificial methods. */
2172 attr
= dwarf_attr (die
, DW_AT_artificial
);
2173 if (attr
&& DW_UNSND (attr
) != 0)
2174 fnp
->is_artificial
= 1;
2176 /* Get index in virtual function table if it is a virtual member function. */
2177 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2179 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2182 /* Create the vector of member function fields, and attach it to the type. */
2185 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2186 struct objfile
*objfile
)
2188 struct fnfieldlist
*flp
;
2189 int total_length
= 0;
2192 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2193 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2194 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2196 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2198 struct nextfnfield
*nfp
= flp
->head
;
2199 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2202 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2203 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2204 fn_flp
->fn_fields
= (struct fn_field
*)
2205 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2206 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2207 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2209 total_length
+= flp
->length
;
2212 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2213 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2216 /* Called when we find the DIE that starts a structure or union scope
2217 (definition) to process all dies that define the members of the
2220 NOTE: we need to call struct_type regardless of whether or not the
2221 DIE has an at_name attribute, since it might be an anonymous
2222 structure or union. This gets the type entered into our set of
2225 However, if the structure is incomplete (an opaque struct/union)
2226 then suppress creating a symbol table entry for it since gdb only
2227 wants to find the one with the complete definition. Note that if
2228 it is complete, we just call new_symbol, which does it's own
2229 checking about whether the struct/union is anonymous or not (and
2230 suppresses creating a symbol table entry itself). */
2233 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2234 const struct comp_unit_head
*cu_header
)
2237 struct attribute
*attr
;
2239 type
= alloc_type (objfile
);
2241 INIT_CPLUS_SPECIFIC (type
);
2242 attr
= dwarf_attr (die
, DW_AT_name
);
2243 if (attr
&& DW_STRING (attr
))
2245 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2246 strlen (DW_STRING (attr
)),
2247 &objfile
->type_obstack
);
2250 if (die
->tag
== DW_TAG_structure_type
)
2252 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2254 else if (die
->tag
== DW_TAG_union_type
)
2256 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2260 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2262 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2265 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2268 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2272 TYPE_LENGTH (type
) = 0;
2275 /* We need to add the type field to the die immediately so we don't
2276 infinitely recurse when dealing with pointers to the structure
2277 type within the structure itself. */
2280 if (die
->has_children
&& ! die_is_declaration (die
))
2282 struct field_info fi
;
2283 struct die_info
*child_die
;
2284 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2286 memset (&fi
, 0, sizeof (struct field_info
));
2288 child_die
= die
->next
;
2290 while (child_die
&& child_die
->tag
)
2292 if (child_die
->tag
== DW_TAG_member
)
2294 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2296 else if (child_die
->tag
== DW_TAG_variable
)
2298 /* C++ static member. */
2299 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2301 else if (child_die
->tag
== DW_TAG_subprogram
)
2303 /* C++ member function. */
2304 process_die (child_die
, objfile
, cu_header
);
2305 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2307 else if (child_die
->tag
== DW_TAG_inheritance
)
2309 /* C++ base class field. */
2310 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2314 process_die (child_die
, objfile
, cu_header
);
2316 child_die
= sibling_die (child_die
);
2319 /* Attach fields and member functions to the type. */
2321 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2324 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2326 /* Get the type which refers to the base class (possibly this
2327 class itself) which contains the vtable pointer for the current
2328 class from the DW_AT_containing_type attribute. */
2330 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2332 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2334 TYPE_VPTR_BASETYPE (type
) = t
;
2337 static const char vptr_name
[] =
2338 {'_', 'v', 'p', 't', 'r', '\0'};
2341 /* Our own class provides vtbl ptr. */
2342 for (i
= TYPE_NFIELDS (t
) - 1;
2343 i
>= TYPE_N_BASECLASSES (t
);
2346 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2348 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2349 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2351 TYPE_VPTR_FIELDNO (type
) = i
;
2356 /* Complain if virtual function table field not found. */
2357 if (i
< TYPE_N_BASECLASSES (t
))
2358 complain (&dwarf2_vtbl_not_found_complaint
,
2359 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2363 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2368 new_symbol (die
, type
, objfile
, cu_header
);
2370 do_cleanups (back_to
);
2374 /* No children, must be stub. */
2375 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2378 finish_cv_type (die
->type
);
2381 /* Given a pointer to a die which begins an enumeration, process all
2382 the dies that define the members of the enumeration.
2384 This will be much nicer in draft 6 of the DWARF spec when our
2385 members will be dies instead squished into the DW_AT_element_list
2388 NOTE: We reverse the order of the element list. */
2391 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2392 const struct comp_unit_head
*cu_header
)
2394 struct die_info
*child_die
;
2396 struct field
*fields
;
2397 struct attribute
*attr
;
2400 int unsigned_enum
= 1;
2402 type
= alloc_type (objfile
);
2404 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2405 attr
= dwarf_attr (die
, DW_AT_name
);
2406 if (attr
&& DW_STRING (attr
))
2408 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2409 strlen (DW_STRING (attr
)),
2410 &objfile
->type_obstack
);
2413 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2416 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2420 TYPE_LENGTH (type
) = 0;
2425 if (die
->has_children
)
2427 child_die
= die
->next
;
2428 while (child_die
&& child_die
->tag
)
2430 if (child_die
->tag
!= DW_TAG_enumerator
)
2432 process_die (child_die
, objfile
, cu_header
);
2436 attr
= dwarf_attr (child_die
, DW_AT_name
);
2439 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2440 if (SYMBOL_VALUE (sym
) < 0)
2443 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2445 fields
= (struct field
*)
2447 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2448 * sizeof (struct field
));
2451 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2452 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2453 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2454 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2460 child_die
= sibling_die (child_die
);
2465 TYPE_NFIELDS (type
) = num_fields
;
2466 TYPE_FIELDS (type
) = (struct field
*)
2467 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2468 memcpy (TYPE_FIELDS (type
), fields
,
2469 sizeof (struct field
) * num_fields
);
2473 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2476 new_symbol (die
, type
, objfile
, cu_header
);
2479 /* Extract all information from a DW_TAG_array_type DIE and put it in
2480 the DIE's type field. For now, this only handles one dimensional
2484 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
2485 const struct comp_unit_head
*cu_header
)
2487 struct die_info
*child_die
;
2488 struct type
*type
= NULL
;
2489 struct type
*element_type
, *range_type
, *index_type
;
2490 struct type
**range_types
= NULL
;
2491 struct attribute
*attr
;
2493 struct cleanup
*back_to
;
2495 /* Return if we've already decoded this type. */
2501 element_type
= die_type (die
, objfile
, cu_header
);
2503 /* Irix 6.2 native cc creates array types without children for
2504 arrays with unspecified length. */
2505 if (die
->has_children
== 0)
2507 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2508 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2509 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2513 back_to
= make_cleanup (null_cleanup
, NULL
);
2514 child_die
= die
->next
;
2515 while (child_die
&& child_die
->tag
)
2517 if (child_die
->tag
== DW_TAG_subrange_type
)
2519 unsigned int low
, high
;
2521 /* Default bounds to an array with unspecified length. */
2524 if (cu_language
== language_fortran
)
2526 /* FORTRAN implies a lower bound of 1, if not given. */
2530 index_type
= die_type (child_die
, objfile
, cu_header
);
2531 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2534 if (attr
->form
== DW_FORM_sdata
)
2536 low
= DW_SND (attr
);
2538 else if (attr
->form
== DW_FORM_udata
2539 || attr
->form
== DW_FORM_data1
2540 || attr
->form
== DW_FORM_data2
2541 || attr
->form
== DW_FORM_data4
)
2543 low
= DW_UNSND (attr
);
2547 complain (&dwarf2_non_const_array_bound_ignored
,
2548 dwarf_form_name (attr
->form
));
2550 die
->type
= lookup_pointer_type (element_type
);
2557 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2560 if (attr
->form
== DW_FORM_sdata
)
2562 high
= DW_SND (attr
);
2564 else if (attr
->form
== DW_FORM_udata
2565 || attr
->form
== DW_FORM_data1
2566 || attr
->form
== DW_FORM_data2
2567 || attr
->form
== DW_FORM_data4
)
2569 high
= DW_UNSND (attr
);
2571 else if (attr
->form
== DW_FORM_block1
)
2573 /* GCC encodes arrays with unspecified or dynamic length
2574 with a DW_FORM_block1 attribute.
2575 FIXME: GDB does not yet know how to handle dynamic
2576 arrays properly, treat them as arrays with unspecified
2582 complain (&dwarf2_non_const_array_bound_ignored
,
2583 dwarf_form_name (attr
->form
));
2585 die
->type
= lookup_pointer_type (element_type
);
2593 /* Create a range type and save it for array type creation. */
2594 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2596 range_types
= (struct type
**)
2597 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2598 * sizeof (struct type
*));
2600 make_cleanup (free_current_contents
, &range_types
);
2602 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2604 child_die
= sibling_die (child_die
);
2607 /* Dwarf2 dimensions are output from left to right, create the
2608 necessary array types in backwards order. */
2609 type
= element_type
;
2611 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2613 do_cleanups (back_to
);
2615 /* Install the type in the die. */
2619 /* First cut: install each common block member as a global variable. */
2622 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
2623 const struct comp_unit_head
*cu_header
)
2625 struct die_info
*child_die
;
2626 struct attribute
*attr
;
2628 CORE_ADDR base
= (CORE_ADDR
) 0;
2630 attr
= dwarf_attr (die
, DW_AT_location
);
2633 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2635 if (die
->has_children
)
2637 child_die
= die
->next
;
2638 while (child_die
&& child_die
->tag
)
2640 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
2641 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2644 SYMBOL_VALUE_ADDRESS (sym
) =
2645 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2646 add_symbol_to_list (sym
, &global_symbols
);
2648 child_die
= sibling_die (child_die
);
2653 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2654 the user defined type vector. */
2657 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
2658 const struct comp_unit_head
*cu_header
)
2661 struct attribute
*attr
;
2668 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
2669 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2672 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2676 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2681 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2682 the user defined type vector. */
2685 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
2686 const struct comp_unit_head
*cu_header
)
2689 struct type
*to_type
;
2690 struct type
*domain
;
2697 type
= alloc_type (objfile
);
2698 to_type
= die_type (die
, objfile
, cu_header
);
2699 domain
= die_containing_type (die
, objfile
, cu_header
);
2700 smash_to_member_type (type
, domain
, to_type
);
2705 /* Extract all information from a DW_TAG_reference_type DIE and add to
2706 the user defined type vector. */
2709 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
2710 const struct comp_unit_head
*cu_header
)
2713 struct attribute
*attr
;
2720 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
2721 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2724 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2728 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2734 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
2735 const struct comp_unit_head
*cu_header
)
2737 struct type
*base_type
;
2744 base_type
= die_type (die
, objfile
, cu_header
);
2745 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
2749 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
2750 const struct comp_unit_head
*cu_header
)
2752 struct type
*base_type
;
2759 base_type
= die_type (die
, objfile
, cu_header
);
2760 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
2763 /* Extract all information from a DW_TAG_string_type DIE and add to
2764 the user defined type vector. It isn't really a user defined type,
2765 but it behaves like one, with other DIE's using an AT_user_def_type
2766 attribute to reference it. */
2769 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
2771 struct type
*type
, *range_type
, *index_type
, *char_type
;
2772 struct attribute
*attr
;
2773 unsigned int length
;
2780 attr
= dwarf_attr (die
, DW_AT_string_length
);
2783 length
= DW_UNSND (attr
);
2787 /* check for the DW_AT_byte_size attribute */
2788 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2791 length
= DW_UNSND (attr
);
2798 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2799 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2800 if (cu_language
== language_fortran
)
2802 /* Need to create a unique string type for bounds
2804 type
= create_string_type (0, range_type
);
2808 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2809 type
= create_string_type (char_type
, range_type
);
2814 /* Handle DIES due to C code like:
2818 int (*funcp)(int a, long l);
2822 ('funcp' generates a DW_TAG_subroutine_type DIE)
2826 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
2827 const struct comp_unit_head
*cu_header
)
2829 struct type
*type
; /* Type that this function returns */
2830 struct type
*ftype
; /* Function that returns above type */
2831 struct attribute
*attr
;
2833 /* Decode the type that this subroutine returns */
2838 type
= die_type (die
, objfile
, cu_header
);
2839 ftype
= lookup_function_type (type
);
2841 /* All functions in C++ have prototypes. */
2842 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2843 if ((attr
&& (DW_UNSND (attr
) != 0))
2844 || cu_language
== language_cplus
)
2845 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2847 if (die
->has_children
)
2849 struct die_info
*child_die
;
2853 /* Count the number of parameters.
2854 FIXME: GDB currently ignores vararg functions, but knows about
2855 vararg member functions. */
2856 child_die
= die
->next
;
2857 while (child_die
&& child_die
->tag
)
2859 if (child_die
->tag
== DW_TAG_formal_parameter
)
2861 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2862 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2863 child_die
= sibling_die (child_die
);
2866 /* Allocate storage for parameters and fill them in. */
2867 TYPE_NFIELDS (ftype
) = nparams
;
2868 TYPE_FIELDS (ftype
) = (struct field
*)
2869 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2871 child_die
= die
->next
;
2872 while (child_die
&& child_die
->tag
)
2874 if (child_die
->tag
== DW_TAG_formal_parameter
)
2876 /* Dwarf2 has no clean way to discern C++ static and non-static
2877 member functions. G++ helps GDB by marking the first
2878 parameter for non-static member functions (which is the
2879 this pointer) as artificial. We pass this information
2880 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2881 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2883 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2885 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2886 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
2890 child_die
= sibling_die (child_die
);
2898 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
2899 const struct comp_unit_head
*cu_header
)
2901 struct attribute
*attr
;
2906 attr
= dwarf_attr (die
, DW_AT_name
);
2907 if (attr
&& DW_STRING (attr
))
2909 name
= DW_STRING (attr
);
2911 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
2912 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, objfile
, cu_header
);
2916 /* Find a representation of a given base type and install
2917 it in the TYPE field of the die. */
2920 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
2923 struct attribute
*attr
;
2924 int encoding
= 0, size
= 0;
2926 /* If we've already decoded this die, this is a no-op. */
2932 attr
= dwarf_attr (die
, DW_AT_encoding
);
2935 encoding
= DW_UNSND (attr
);
2937 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2940 size
= DW_UNSND (attr
);
2942 attr
= dwarf_attr (die
, DW_AT_name
);
2943 if (attr
&& DW_STRING (attr
))
2945 enum type_code code
= TYPE_CODE_INT
;
2950 case DW_ATE_address
:
2951 /* Turn DW_ATE_address into a void * pointer. */
2952 code
= TYPE_CODE_PTR
;
2953 type_flags
|= TYPE_FLAG_UNSIGNED
;
2955 case DW_ATE_boolean
:
2956 code
= TYPE_CODE_BOOL
;
2957 type_flags
|= TYPE_FLAG_UNSIGNED
;
2959 case DW_ATE_complex_float
:
2960 code
= TYPE_CODE_COMPLEX
;
2963 code
= TYPE_CODE_FLT
;
2966 case DW_ATE_signed_char
:
2968 case DW_ATE_unsigned
:
2969 case DW_ATE_unsigned_char
:
2970 type_flags
|= TYPE_FLAG_UNSIGNED
;
2973 complain (&dwarf2_unsupported_at_encoding
,
2974 dwarf_type_encoding_name (encoding
));
2977 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
2978 if (encoding
== DW_ATE_address
)
2979 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2983 type
= dwarf_base_type (encoding
, size
, objfile
);
2988 /* Read a whole compilation unit into a linked list of dies. */
2990 static struct die_info
*
2991 read_comp_unit (char *info_ptr
, bfd
*abfd
,
2992 const struct comp_unit_head
*cu_header
)
2994 struct die_info
*first_die
, *last_die
, *die
;
2998 /* Reset die reference table; we are
2999 building new ones now. */
3000 dwarf2_empty_hash_tables ();
3004 first_die
= last_die
= NULL
;
3007 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
3008 if (die
->has_children
)
3019 /* Enter die in reference hash table */
3020 store_in_ref_table (die
->offset
, die
);
3024 first_die
= last_die
= die
;
3028 last_die
->next
= die
;
3032 while (nesting_level
> 0);
3036 /* Free a linked list of dies. */
3039 free_die_list (struct die_info
*dies
)
3041 struct die_info
*die
, *next
;
3054 do_free_die_list_cleanup (void *dies
)
3056 free_die_list (dies
);
3059 static struct cleanup
*
3060 make_cleanup_free_die_list (struct die_info
*dies
)
3062 return make_cleanup (do_free_die_list_cleanup
, dies
);
3066 /* Read the contents of the section at OFFSET and of size SIZE from the
3067 object file specified by OBJFILE into the psymbol_obstack and return it. */
3070 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
3073 bfd
*abfd
= objfile
->obfd
;
3079 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3080 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3081 (bfd_bread (buf
, size
, abfd
) != size
))
3084 error ("Dwarf Error: Can't read DWARF data from '%s'",
3085 bfd_get_filename (abfd
));
3090 /* In DWARF version 2, the description of the debugging information is
3091 stored in a separate .debug_abbrev section. Before we read any
3092 dies from a section we read in all abbreviations and install them
3096 dwarf2_read_abbrevs (bfd
*abfd
, unsigned int offset
)
3099 struct abbrev_info
*cur_abbrev
;
3100 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3101 unsigned int abbrev_form
, hash_number
;
3103 /* empty the table */
3104 dwarf2_empty_abbrev_table (NULL
);
3106 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3107 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3108 abbrev_ptr
+= bytes_read
;
3110 /* loop until we reach an abbrev number of 0 */
3111 while (abbrev_number
)
3113 cur_abbrev
= dwarf_alloc_abbrev ();
3115 /* read in abbrev header */
3116 cur_abbrev
->number
= abbrev_number
;
3117 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3118 abbrev_ptr
+= bytes_read
;
3119 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3122 /* now read in declarations */
3123 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3124 abbrev_ptr
+= bytes_read
;
3125 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3126 abbrev_ptr
+= bytes_read
;
3129 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3131 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3132 xrealloc (cur_abbrev
->attrs
,
3133 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3134 * sizeof (struct attr_abbrev
));
3136 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3137 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3138 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3139 abbrev_ptr
+= bytes_read
;
3140 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3141 abbrev_ptr
+= bytes_read
;
3144 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3145 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3146 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3148 /* Get next abbreviation.
3149 Under Irix6 the abbreviations for a compilation unit are not
3150 always properly terminated with an abbrev number of 0.
3151 Exit loop if we encounter an abbreviation which we have
3152 already read (which means we are about to read the abbreviations
3153 for the next compile unit) or if the end of the abbreviation
3154 table is reached. */
3155 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3156 >= dwarf_abbrev_size
)
3158 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3159 abbrev_ptr
+= bytes_read
;
3160 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3165 /* Empty the abbrev table for a new compilation unit. */
3169 dwarf2_empty_abbrev_table (PTR ignore
)
3172 struct abbrev_info
*abbrev
, *next
;
3174 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3177 abbrev
= dwarf2_abbrevs
[i
];
3180 next
= abbrev
->next
;
3181 xfree (abbrev
->attrs
);
3185 dwarf2_abbrevs
[i
] = NULL
;
3189 /* Lookup an abbrev_info structure in the abbrev hash table. */
3191 static struct abbrev_info
*
3192 dwarf2_lookup_abbrev (unsigned int number
)
3194 unsigned int hash_number
;
3195 struct abbrev_info
*abbrev
;
3197 hash_number
= number
% ABBREV_HASH_SIZE
;
3198 abbrev
= dwarf2_abbrevs
[hash_number
];
3202 if (abbrev
->number
== number
)
3205 abbrev
= abbrev
->next
;
3210 /* Read a minimal amount of information into the minimal die structure. */
3213 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3214 char *info_ptr
, const struct comp_unit_head
*cu_header
)
3216 unsigned int abbrev_number
, bytes_read
, i
;
3217 struct abbrev_info
*abbrev
;
3218 struct attribute attr
;
3219 struct attribute spec_attr
;
3220 int found_spec_attr
= 0;
3221 int has_low_pc_attr
= 0;
3222 int has_high_pc_attr
= 0;
3224 *part_die
= zeroed_partial_die
;
3225 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3226 info_ptr
+= bytes_read
;
3230 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3233 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3235 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3236 part_die
->tag
= abbrev
->tag
;
3237 part_die
->has_children
= abbrev
->has_children
;
3238 part_die
->abbrev
= abbrev_number
;
3240 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3242 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3243 info_ptr
, cu_header
);
3245 /* Store the data if it is of an attribute we want to keep in a
3246 partial symbol table. */
3251 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3252 if (part_die
->name
== NULL
)
3253 part_die
->name
= DW_STRING (&attr
);
3255 case DW_AT_MIPS_linkage_name
:
3256 part_die
->name
= DW_STRING (&attr
);
3259 has_low_pc_attr
= 1;
3260 part_die
->lowpc
= DW_ADDR (&attr
);
3263 has_high_pc_attr
= 1;
3264 part_die
->highpc
= DW_ADDR (&attr
);
3266 case DW_AT_location
:
3267 part_die
->locdesc
= DW_BLOCK (&attr
);
3269 case DW_AT_language
:
3270 part_die
->language
= DW_UNSND (&attr
);
3272 case DW_AT_external
:
3273 part_die
->is_external
= DW_UNSND (&attr
);
3275 case DW_AT_declaration
:
3276 part_die
->is_declaration
= DW_UNSND (&attr
);
3279 part_die
->has_type
= 1;
3281 case DW_AT_abstract_origin
:
3282 case DW_AT_specification
:
3283 found_spec_attr
= 1;
3287 /* Ignore absolute siblings, they might point outside of
3288 the current compile unit. */
3289 if (attr
.form
== DW_FORM_ref_addr
)
3290 complain (&dwarf2_absolute_sibling_complaint
);
3293 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3300 /* If we found a reference attribute and the die has no name, try
3301 to find a name in the referred to die. */
3303 if (found_spec_attr
&& part_die
->name
== NULL
)
3305 struct partial_die_info spec_die
;
3309 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3310 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu_header
);
3313 part_die
->name
= spec_die
.name
;
3315 /* Copy DW_AT_external attribute if it is set. */
3316 if (spec_die
.is_external
)
3317 part_die
->is_external
= spec_die
.is_external
;
3321 /* When using the GNU linker, .gnu.linkonce. sections are used to
3322 eliminate duplicate copies of functions and vtables and such.
3323 The linker will arbitrarily choose one and discard the others.
3324 The AT_*_pc values for such functions refer to local labels in
3325 these sections. If the section from that file was discarded, the
3326 labels are not in the output, so the relocs get a value of 0.
3327 If this is a discarded function, mark the pc bounds as invalid,
3328 so that GDB will ignore it. */
3329 if (has_low_pc_attr
&& has_high_pc_attr
3330 && part_die
->lowpc
< part_die
->highpc
3331 && (part_die
->lowpc
!= 0
3332 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3333 part_die
->has_pc_info
= 1;
3337 /* Read the die from the .debug_info section buffer. And set diep to
3338 point to a newly allocated die with its information. */
3341 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3342 const struct comp_unit_head
*cu_header
)
3344 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3345 struct abbrev_info
*abbrev
;
3346 struct die_info
*die
;
3348 offset
= info_ptr
- dwarf_info_buffer
;
3349 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3350 info_ptr
+= bytes_read
;
3353 die
= dwarf_alloc_die ();
3355 die
->abbrev
= abbrev_number
;
3361 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3364 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3366 die
= dwarf_alloc_die ();
3367 die
->offset
= offset
;
3368 die
->tag
= abbrev
->tag
;
3369 die
->has_children
= abbrev
->has_children
;
3370 die
->abbrev
= abbrev_number
;
3373 die
->num_attrs
= abbrev
->num_attrs
;
3374 die
->attrs
= (struct attribute
*)
3375 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3377 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3379 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3380 abfd
, info_ptr
, cu_header
);
3387 /* Read an attribute value described by an attribute form. */
3390 read_attribute_value (struct attribute
*attr
, unsigned form
,
3391 bfd
*abfd
, char *info_ptr
,
3392 const struct comp_unit_head
*cu_header
)
3394 unsigned int bytes_read
;
3395 struct dwarf_block
*blk
;
3401 case DW_FORM_ref_addr
:
3402 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3403 info_ptr
+= bytes_read
;
3405 case DW_FORM_block2
:
3406 blk
= dwarf_alloc_block ();
3407 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3409 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3410 info_ptr
+= blk
->size
;
3411 DW_BLOCK (attr
) = blk
;
3413 case DW_FORM_block4
:
3414 blk
= dwarf_alloc_block ();
3415 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3417 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3418 info_ptr
+= blk
->size
;
3419 DW_BLOCK (attr
) = blk
;
3422 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3426 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3430 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3433 case DW_FORM_string
:
3434 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3435 info_ptr
+= bytes_read
;
3438 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
3440 info_ptr
+= bytes_read
;
3443 blk
= dwarf_alloc_block ();
3444 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3445 info_ptr
+= bytes_read
;
3446 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3447 info_ptr
+= blk
->size
;
3448 DW_BLOCK (attr
) = blk
;
3450 case DW_FORM_block1
:
3451 blk
= dwarf_alloc_block ();
3452 blk
->size
= read_1_byte (abfd
, info_ptr
);
3454 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3455 info_ptr
+= blk
->size
;
3456 DW_BLOCK (attr
) = blk
;
3459 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3463 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3467 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3468 info_ptr
+= bytes_read
;
3471 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3472 info_ptr
+= bytes_read
;
3475 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3479 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3483 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3487 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3490 case DW_FORM_ref_udata
:
3491 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3492 info_ptr
+= bytes_read
;
3494 case DW_FORM_indirect
:
3495 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3496 info_ptr
+= bytes_read
;
3497 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu_header
);
3500 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3501 dwarf_form_name (form
));
3506 /* Read an attribute described by an abbreviated attribute. */
3509 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
3510 bfd
*abfd
, char *info_ptr
,
3511 const struct comp_unit_head
*cu_header
)
3513 attr
->name
= abbrev
->name
;
3514 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu_header
);
3517 /* read dwarf information from a buffer */
3520 read_1_byte (bfd
*abfd
, char *buf
)
3522 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3526 read_1_signed_byte (bfd
*abfd
, char *buf
)
3528 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3532 read_2_bytes (bfd
*abfd
, char *buf
)
3534 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3538 read_2_signed_bytes (bfd
*abfd
, char *buf
)
3540 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3544 read_4_bytes (bfd
*abfd
, char *buf
)
3546 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3550 read_4_signed_bytes (bfd
*abfd
, char *buf
)
3552 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3555 static unsigned long
3556 read_8_bytes (bfd
*abfd
, char *buf
)
3558 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3562 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3565 CORE_ADDR retval
= 0;
3567 if (cu_header
->signed_addr_p
)
3569 switch (cu_header
->addr_size
)
3572 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3575 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3578 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
3581 internal_error (__FILE__
, __LINE__
,
3582 "read_address: bad switch, signed");
3587 switch (cu_header
->addr_size
)
3590 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3593 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3596 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3599 internal_error (__FILE__
, __LINE__
,
3600 "read_address: bad switch, unsigned");
3604 *bytes_read
= cu_header
->addr_size
;
3608 /* Reads the initial length from a section. The (draft) DWARF 2.1
3609 specification allows the initial length to take up either 4 bytes
3610 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
3611 bytes describe the length and all offsets will be 8 bytes in length
3614 The value returned via bytes_read should be used to increment
3615 the relevant pointer after calling read_initial_length().
3617 As a side effect, this function sets the fields initial_length_size
3618 and offset_size in cu_header to the values appropriate for the
3619 length field. (The format of the initial length field determines
3620 the width of file offsets to be fetched later with fetch_offset().)
3622 [ Note: read_initial_length() and read_offset() are based on the
3623 document entitled "DWARF Debugging Information Format", revision
3624 2.1, draft 4, dated July 20, 2000. This document was obtained
3627 http://reality.sgi.com/dehnert_engr/dwarf/dwarf2p1-draft4-000720.pdf
3629 This document is only a draft and is subject to change. (So beware.)
3631 - Kevin, Aug 4, 2000
3635 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
3640 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3642 if (retval
== 0xffffffff)
3644 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
3646 if (cu_header
!= NULL
)
3648 cu_header
->initial_length_size
= 12;
3649 cu_header
->offset_size
= 8;
3655 if (cu_header
!= NULL
)
3657 cu_header
->initial_length_size
= 4;
3658 cu_header
->offset_size
= 4;
3665 /* Read an offset from the data stream. The size of the offset is
3666 given by cu_header->offset_size. */
3669 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3674 switch (cu_header
->offset_size
)
3677 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3681 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3685 internal_error (__FILE__
, __LINE__
,
3686 "read_offset: bad switch");
3693 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
3695 /* If the size of a host char is 8 bits, we can return a pointer
3696 to the buffer, otherwise we have to copy the data to a buffer
3697 allocated on the temporary obstack. */
3698 gdb_assert (HOST_CHAR_BIT
== 8);
3703 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3705 /* If the size of a host char is 8 bits, we can return a pointer
3706 to the string, otherwise we have to copy the string to a buffer
3707 allocated on the temporary obstack. */
3708 gdb_assert (HOST_CHAR_BIT
== 8);
3711 *bytes_read_ptr
= 1;
3714 *bytes_read_ptr
= strlen (buf
) + 1;
3719 read_indirect_string (bfd
*abfd
, char *buf
,
3720 const struct comp_unit_head
*cu_header
,
3721 unsigned int *bytes_read_ptr
)
3723 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
3724 (int *) bytes_read_ptr
);
3726 if (dwarf_str_buffer
== NULL
)
3728 error ("DW_FORM_strp used without .debug_str section");
3731 if (str_offset
>= dwarf_str_size
)
3733 error ("DW_FORM_strp pointing outside of .debug_str section");
3736 gdb_assert (HOST_CHAR_BIT
== 8);
3737 if (dwarf_str_buffer
[str_offset
] == '\0')
3739 return dwarf_str_buffer
+ str_offset
;
3742 static unsigned long
3743 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3745 unsigned long result
;
3746 unsigned int num_read
;
3756 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3759 result
|= ((unsigned long)(byte
& 127) << shift
);
3760 if ((byte
& 128) == 0)
3766 *bytes_read_ptr
= num_read
;
3771 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3774 int i
, shift
, size
, num_read
;
3784 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3787 result
|= ((long)(byte
& 127) << shift
);
3789 if ((byte
& 128) == 0)
3794 if ((shift
< size
) && (byte
& 0x40))
3796 result
|= -(1 << shift
);
3798 *bytes_read_ptr
= num_read
;
3803 set_cu_language (unsigned int lang
)
3809 cu_language
= language_c
;
3811 case DW_LANG_C_plus_plus
:
3812 cu_language
= language_cplus
;
3814 case DW_LANG_Fortran77
:
3815 case DW_LANG_Fortran90
:
3816 case DW_LANG_Fortran95
:
3817 cu_language
= language_fortran
;
3819 case DW_LANG_Mips_Assembler
:
3820 cu_language
= language_asm
;
3823 cu_language
= language_java
;
3826 case DW_LANG_Cobol74
:
3827 case DW_LANG_Cobol85
:
3828 case DW_LANG_Pascal83
:
3829 case DW_LANG_Modula2
:
3831 cu_language
= language_unknown
;
3834 cu_language_defn
= language_def (cu_language
);
3837 /* Return the named attribute or NULL if not there. */
3839 static struct attribute
*
3840 dwarf_attr (struct die_info
*die
, unsigned int name
)
3843 struct attribute
*spec
= NULL
;
3845 for (i
= 0; i
< die
->num_attrs
; ++i
)
3847 if (die
->attrs
[i
].name
== name
)
3849 return &die
->attrs
[i
];
3851 if (die
->attrs
[i
].name
== DW_AT_specification
3852 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3853 spec
= &die
->attrs
[i
];
3857 struct die_info
*ref_die
=
3858 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3861 return dwarf_attr (ref_die
, name
);
3868 die_is_declaration (struct die_info
*die
)
3870 return (dwarf_attr (die
, DW_AT_declaration
)
3871 && ! dwarf_attr (die
, DW_AT_specification
));
3874 /* Decode the line number information for the compilation unit whose
3875 line number info is at OFFSET in the .debug_line section.
3876 The compilation directory of the file is passed in COMP_DIR. */
3880 unsigned int num_files
;
3893 unsigned int num_dirs
;
3898 dwarf_decode_lines (unsigned int offset
, char *comp_dir
, bfd
*abfd
,
3899 const struct comp_unit_head
*cu_header
)
3903 struct line_head lh
;
3904 struct cleanup
*back_to
;
3905 unsigned int i
, bytes_read
;
3906 char *cur_file
, *cur_dir
;
3907 unsigned char op_code
, extended_op
, adj_opcode
;
3909 #define FILE_ALLOC_CHUNK 5
3910 #define DIR_ALLOC_CHUNK 5
3912 struct filenames files
;
3913 struct directories dirs
;
3915 if (dwarf_line_buffer
== NULL
)
3917 complain (&dwarf2_missing_line_number_section
);
3921 files
.num_files
= 0;
3927 line_ptr
= dwarf_line_buffer
+ offset
;
3929 /* read in the prologue */
3930 lh
.total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
3931 line_ptr
+= bytes_read
;
3932 line_end
= line_ptr
+ lh
.total_length
;
3933 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3935 lh
.prologue_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
3936 line_ptr
+= bytes_read
;
3937 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3939 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3941 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3943 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3945 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3947 lh
.standard_opcode_lengths
= (unsigned char *)
3948 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3949 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
3951 lh
.standard_opcode_lengths
[0] = 1;
3952 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3954 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3958 /* Read directory table */
3959 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3961 line_ptr
+= bytes_read
;
3962 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3964 dirs
.dirs
= (char **)
3965 xrealloc (dirs
.dirs
,
3966 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3967 if (dirs
.num_dirs
== 0)
3968 make_cleanup (free_current_contents
, &dirs
.dirs
);
3970 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3972 line_ptr
+= bytes_read
;
3974 /* Read file name table */
3975 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3977 line_ptr
+= bytes_read
;
3978 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3980 files
.files
= (struct fileinfo
*)
3981 xrealloc (files
.files
,
3982 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3983 * sizeof (struct fileinfo
));
3984 if (files
.num_files
== 0)
3985 make_cleanup (free_current_contents
, &files
.files
);
3987 files
.files
[files
.num_files
].name
= cur_file
;
3988 files
.files
[files
.num_files
].dir
=
3989 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3990 line_ptr
+= bytes_read
;
3991 files
.files
[files
.num_files
].time
=
3992 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3993 line_ptr
+= bytes_read
;
3994 files
.files
[files
.num_files
].size
=
3995 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3996 line_ptr
+= bytes_read
;
3999 line_ptr
+= bytes_read
;
4001 /* Read the statement sequences until there's nothing left. */
4002 while (line_ptr
< line_end
)
4004 /* state machine registers */
4005 CORE_ADDR address
= 0;
4006 unsigned int file
= 1;
4007 unsigned int line
= 1;
4008 unsigned int column
= 0;
4009 int is_stmt
= lh
.default_is_stmt
;
4010 int basic_block
= 0;
4011 int end_sequence
= 0;
4013 /* Start a subfile for the current file of the state machine. */
4014 if (files
.num_files
>= file
)
4016 /* The file and directory tables are 0 based, the references
4018 dwarf2_start_subfile (files
.files
[file
- 1].name
,
4019 (files
.files
[file
- 1].dir
4020 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
4024 /* Decode the table. */
4025 while (!end_sequence
)
4027 op_code
= read_1_byte (abfd
, line_ptr
);
4030 if (op_code
>= lh
.opcode_base
)
4031 { /* Special operand. */
4032 adj_opcode
= op_code
- lh
.opcode_base
;
4033 address
+= (adj_opcode
/ lh
.line_range
)
4034 * lh
.minimum_instruction_length
;
4035 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
4036 /* append row to matrix using current values */
4037 record_line (current_subfile
, line
, address
);
4040 else switch (op_code
)
4042 case DW_LNS_extended_op
:
4043 line_ptr
+= 1; /* ignore length */
4044 extended_op
= read_1_byte (abfd
, line_ptr
);
4046 switch (extended_op
)
4048 case DW_LNE_end_sequence
:
4050 /* Don't call record_line here. The end_sequence
4051 instruction provides the address of the first byte
4052 *after* the last line in the sequence; it's not the
4053 address of any real source line. However, the GDB
4054 linetable structure only records the starts of lines,
4055 not the ends. This is a weakness of GDB. */
4057 case DW_LNE_set_address
:
4058 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
4059 line_ptr
+= bytes_read
;
4060 address
+= baseaddr
;
4062 case DW_LNE_define_file
:
4063 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
4064 line_ptr
+= bytes_read
;
4065 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
4067 files
.files
= (struct fileinfo
*)
4068 xrealloc (files
.files
,
4069 (files
.num_files
+ FILE_ALLOC_CHUNK
)
4070 * sizeof (struct fileinfo
));
4071 if (files
.num_files
== 0)
4072 make_cleanup (free_current_contents
, &files
.files
);
4074 files
.files
[files
.num_files
].name
= cur_file
;
4075 files
.files
[files
.num_files
].dir
=
4076 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4077 line_ptr
+= bytes_read
;
4078 files
.files
[files
.num_files
].time
=
4079 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4080 line_ptr
+= bytes_read
;
4081 files
.files
[files
.num_files
].size
=
4082 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4083 line_ptr
+= bytes_read
;
4087 complain (&dwarf2_mangled_line_number_section
);
4092 record_line (current_subfile
, line
, address
);
4095 case DW_LNS_advance_pc
:
4096 address
+= lh
.minimum_instruction_length
4097 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4098 line_ptr
+= bytes_read
;
4100 case DW_LNS_advance_line
:
4101 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
4102 line_ptr
+= bytes_read
;
4104 case DW_LNS_set_file
:
4105 /* The file and directory tables are 0 based, the references
4107 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4108 line_ptr
+= bytes_read
;
4109 dwarf2_start_subfile
4110 (files
.files
[file
- 1].name
,
4111 (files
.files
[file
- 1].dir
4112 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
4115 case DW_LNS_set_column
:
4116 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4117 line_ptr
+= bytes_read
;
4119 case DW_LNS_negate_stmt
:
4120 is_stmt
= (!is_stmt
);
4122 case DW_LNS_set_basic_block
:
4125 /* Add to the address register of the state machine the
4126 address increment value corresponding to special opcode
4127 255. Ie, this value is scaled by the minimum instruction
4128 length since special opcode 255 would have scaled the
4130 case DW_LNS_const_add_pc
:
4131 address
+= (lh
.minimum_instruction_length
4132 * ((255 - lh
.opcode_base
) / lh
.line_range
));
4134 case DW_LNS_fixed_advance_pc
:
4135 address
+= read_2_bytes (abfd
, line_ptr
);
4139 { /* Unknown standard opcode, ignore it. */
4141 for (i
= 0; i
< lh
.standard_opcode_lengths
[op_code
]; i
++)
4143 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4144 line_ptr
+= bytes_read
;
4151 do_cleanups (back_to
);
4154 /* Start a subfile for DWARF. FILENAME is the name of the file and
4155 DIRNAME the name of the source directory which contains FILENAME
4156 or NULL if not known.
4157 This routine tries to keep line numbers from identical absolute and
4158 relative file names in a common subfile.
4160 Using the `list' example from the GDB testsuite, which resides in
4161 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4162 of /srcdir/list0.c yields the following debugging information for list0.c:
4164 DW_AT_name: /srcdir/list0.c
4165 DW_AT_comp_dir: /compdir
4166 files.files[0].name: list0.h
4167 files.files[0].dir: /srcdir
4168 files.files[1].name: list0.c
4169 files.files[1].dir: /srcdir
4171 The line number information for list0.c has to end up in a single
4172 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4175 dwarf2_start_subfile (char *filename
, char *dirname
)
4177 /* If the filename isn't absolute, try to match an existing subfile
4178 with the full pathname. */
4180 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
4182 struct subfile
*subfile
;
4183 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4185 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4187 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
4189 current_subfile
= subfile
;
4196 start_subfile (filename
, dirname
);
4199 /* Given a pointer to a DWARF information entry, figure out if we need
4200 to make a symbol table entry for it, and if so, create a new entry
4201 and return a pointer to it.
4202 If TYPE is NULL, determine symbol type from the die, otherwise
4203 used the passed type. */
4205 static struct symbol
*
4206 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
4207 const struct comp_unit_head
*cu_header
)
4209 struct symbol
*sym
= NULL
;
4211 struct attribute
*attr
= NULL
;
4212 struct attribute
*attr2
= NULL
;
4215 name
= dwarf2_linkage_name (die
);
4218 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4219 sizeof (struct symbol
));
4220 OBJSTAT (objfile
, n_syms
++);
4221 memset (sym
, 0, sizeof (struct symbol
));
4222 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4223 &objfile
->symbol_obstack
);
4225 /* Default assumptions.
4226 Use the passed type or decode it from the die. */
4227 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4228 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4230 SYMBOL_TYPE (sym
) = type
;
4232 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
4233 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4236 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4239 /* If this symbol is from a C++ compilation, then attempt to
4240 cache the demangled form for future reference. This is a
4241 typical time versus space tradeoff, that was decided in favor
4242 of time because it sped up C++ symbol lookups by a factor of
4245 SYMBOL_LANGUAGE (sym
) = cu_language
;
4246 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4250 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4253 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4255 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4257 case DW_TAG_subprogram
:
4258 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4260 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4261 attr2
= dwarf_attr (die
, DW_AT_external
);
4262 if (attr2
&& (DW_UNSND (attr2
) != 0))
4264 add_symbol_to_list (sym
, &global_symbols
);
4268 add_symbol_to_list (sym
, list_in_scope
);
4271 case DW_TAG_variable
:
4272 /* Compilation with minimal debug info may result in variables
4273 with missing type entries. Change the misleading `void' type
4274 to something sensible. */
4275 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4276 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4277 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4278 "<variable, no debug info>",
4280 attr
= dwarf_attr (die
, DW_AT_const_value
);
4283 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4284 attr2
= dwarf_attr (die
, DW_AT_external
);
4285 if (attr2
&& (DW_UNSND (attr2
) != 0))
4286 add_symbol_to_list (sym
, &global_symbols
);
4288 add_symbol_to_list (sym
, list_in_scope
);
4291 attr
= dwarf_attr (die
, DW_AT_location
);
4294 attr2
= dwarf_attr (die
, DW_AT_external
);
4295 if (attr2
&& (DW_UNSND (attr2
) != 0))
4297 SYMBOL_VALUE_ADDRESS (sym
) =
4298 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4299 add_symbol_to_list (sym
, &global_symbols
);
4301 /* In shared libraries the address of the variable
4302 in the location descriptor might still be relocatable,
4303 so its value could be zero.
4304 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4305 value is zero, the address of the variable will then
4306 be determined from the minimal symbol table whenever
4307 the variable is referenced. */
4308 if (SYMBOL_VALUE_ADDRESS (sym
))
4310 fixup_symbol_section (sym
, objfile
);
4311 SYMBOL_VALUE_ADDRESS (sym
) +=
4312 ANOFFSET (objfile
->section_offsets
,
4313 SYMBOL_SECTION (sym
));
4314 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4317 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4321 SYMBOL_VALUE (sym
) = addr
=
4322 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4323 add_symbol_to_list (sym
, list_in_scope
);
4326 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4330 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4331 SYMBOL_VALUE (sym
) =
4332 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4336 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4337 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4341 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4345 fixup_symbol_section (sym
, objfile
);
4346 SYMBOL_VALUE_ADDRESS (sym
) =
4347 addr
+ ANOFFSET (objfile
->section_offsets
,
4348 SYMBOL_SECTION (sym
));
4349 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4355 /* We do not know the address of this symbol.
4356 If it is an external symbol and we have type information
4357 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4358 The address of the variable will then be determined from
4359 the minimal symbol table whenever the variable is
4361 attr2
= dwarf_attr (die
, DW_AT_external
);
4362 if (attr2
&& (DW_UNSND (attr2
) != 0)
4363 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4365 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4366 add_symbol_to_list (sym
, &global_symbols
);
4370 case DW_TAG_formal_parameter
:
4371 attr
= dwarf_attr (die
, DW_AT_location
);
4374 SYMBOL_VALUE (sym
) =
4375 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4378 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4379 SYMBOL_VALUE (sym
) =
4380 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4386 if (basereg
!= frame_base_reg
)
4387 complain (&dwarf2_complex_location_expr
);
4388 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4392 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4393 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4398 SYMBOL_CLASS (sym
) = LOC_ARG
;
4401 attr
= dwarf_attr (die
, DW_AT_const_value
);
4404 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4406 add_symbol_to_list (sym
, list_in_scope
);
4408 case DW_TAG_unspecified_parameters
:
4409 /* From varargs functions; gdb doesn't seem to have any
4410 interest in this information, so just ignore it for now.
4413 case DW_TAG_class_type
:
4414 case DW_TAG_structure_type
:
4415 case DW_TAG_union_type
:
4416 case DW_TAG_enumeration_type
:
4417 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4418 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4419 add_symbol_to_list (sym
, list_in_scope
);
4421 /* The semantics of C++ state that "struct foo { ... }" also
4422 defines a typedef for "foo". Synthesize a typedef symbol so
4423 that "ptype foo" works as expected. */
4424 if (cu_language
== language_cplus
)
4426 struct symbol
*typedef_sym
= (struct symbol
*)
4427 obstack_alloc (&objfile
->symbol_obstack
,
4428 sizeof (struct symbol
));
4429 *typedef_sym
= *sym
;
4430 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4431 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4432 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4433 obsavestring (SYMBOL_NAME (sym
),
4434 strlen (SYMBOL_NAME (sym
)),
4435 &objfile
->type_obstack
);
4436 add_symbol_to_list (typedef_sym
, list_in_scope
);
4439 case DW_TAG_typedef
:
4440 case DW_TAG_base_type
:
4441 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4442 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4443 add_symbol_to_list (sym
, list_in_scope
);
4445 case DW_TAG_enumerator
:
4446 attr
= dwarf_attr (die
, DW_AT_const_value
);
4449 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4451 add_symbol_to_list (sym
, list_in_scope
);
4454 /* Not a tag we recognize. Hopefully we aren't processing
4455 trash data, but since we must specifically ignore things
4456 we don't recognize, there is nothing else we should do at
4458 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4465 /* Copy constant value from an attribute to a symbol. */
4468 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
4469 struct objfile
*objfile
,
4470 const struct comp_unit_head
*cu_header
)
4472 struct dwarf_block
*blk
;
4477 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
4478 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4479 cu_header
->addr_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4480 SYMBOL_VALUE_BYTES (sym
) = (char *)
4481 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
4482 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
4484 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4486 case DW_FORM_block1
:
4487 case DW_FORM_block2
:
4488 case DW_FORM_block4
:
4490 blk
= DW_BLOCK (attr
);
4491 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4492 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4493 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4494 SYMBOL_VALUE_BYTES (sym
) = (char *)
4495 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4496 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4497 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4500 /* The DW_AT_const_value attributes are supposed to carry the
4501 symbol's value "represented as it would be on the target
4502 architecture." By the time we get here, it's already been
4503 converted to host endianness, so we just need to sign- or
4504 zero-extend it as appropriate. */
4506 dwarf2_const_value_data (attr
, sym
, 8);
4509 dwarf2_const_value_data (attr
, sym
, 16);
4512 dwarf2_const_value_data (attr
, sym
, 32);
4515 dwarf2_const_value_data (attr
, sym
, 64);
4519 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4520 SYMBOL_CLASS (sym
) = LOC_CONST
;
4524 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4525 SYMBOL_CLASS (sym
) = LOC_CONST
;
4529 complain (&dwarf2_unsupported_const_value_attr
,
4530 dwarf_form_name (attr
->form
));
4531 SYMBOL_VALUE (sym
) = 0;
4532 SYMBOL_CLASS (sym
) = LOC_CONST
;
4538 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4539 or zero-extend it as appropriate for the symbol's type. */
4541 dwarf2_const_value_data (struct attribute
*attr
,
4545 LONGEST l
= DW_UNSND (attr
);
4547 if (bits
< sizeof (l
) * 8)
4549 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4550 l
&= ((LONGEST
) 1 << bits
) - 1;
4552 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4555 SYMBOL_VALUE (sym
) = l
;
4556 SYMBOL_CLASS (sym
) = LOC_CONST
;
4560 /* Return the type of the die in question using its DW_AT_type attribute. */
4562 static struct type
*
4563 die_type (struct die_info
*die
, struct objfile
*objfile
,
4564 const struct comp_unit_head
*cu_header
)
4567 struct attribute
*type_attr
;
4568 struct die_info
*type_die
;
4571 type_attr
= dwarf_attr (die
, DW_AT_type
);
4574 /* A missing DW_AT_type represents a void type. */
4575 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4579 ref
= dwarf2_get_ref_die_offset (type_attr
);
4580 type_die
= follow_die_ref (ref
);
4583 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4587 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4590 dump_die (type_die
);
4591 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4596 /* Return the containing type of the die in question using its
4597 DW_AT_containing_type attribute. */
4599 static struct type
*
4600 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
4601 const struct comp_unit_head
*cu_header
)
4603 struct type
*type
= NULL
;
4604 struct attribute
*type_attr
;
4605 struct die_info
*type_die
= NULL
;
4608 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4611 ref
= dwarf2_get_ref_die_offset (type_attr
);
4612 type_die
= follow_die_ref (ref
);
4615 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4618 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4623 dump_die (type_die
);
4624 error ("Dwarf Error: Problem turning containing type into gdb type.");
4630 static struct type
*
4631 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
4633 struct die_info
*die
;
4636 die
= follow_die_ref (offset
);
4639 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4642 type
= tag_type_to_type (die
, objfile
);
4647 static struct type
*
4648 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
4649 const struct comp_unit_head
*cu_header
)
4657 read_type_die (die
, objfile
, cu_header
);
4661 error ("Dwarf Error: Cannot find type of die.");
4668 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
4669 const struct comp_unit_head
*cu_header
)
4673 case DW_TAG_class_type
:
4674 case DW_TAG_structure_type
:
4675 case DW_TAG_union_type
:
4676 read_structure_scope (die
, objfile
, cu_header
);
4678 case DW_TAG_enumeration_type
:
4679 read_enumeration (die
, objfile
, cu_header
);
4681 case DW_TAG_subprogram
:
4682 case DW_TAG_subroutine_type
:
4683 read_subroutine_type (die
, objfile
, cu_header
);
4685 case DW_TAG_array_type
:
4686 read_array_type (die
, objfile
, cu_header
);
4688 case DW_TAG_pointer_type
:
4689 read_tag_pointer_type (die
, objfile
, cu_header
);
4691 case DW_TAG_ptr_to_member_type
:
4692 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
4694 case DW_TAG_reference_type
:
4695 read_tag_reference_type (die
, objfile
, cu_header
);
4697 case DW_TAG_const_type
:
4698 read_tag_const_type (die
, objfile
, cu_header
);
4700 case DW_TAG_volatile_type
:
4701 read_tag_volatile_type (die
, objfile
, cu_header
);
4703 case DW_TAG_string_type
:
4704 read_tag_string_type (die
, objfile
);
4706 case DW_TAG_typedef
:
4707 read_typedef (die
, objfile
, cu_header
);
4709 case DW_TAG_base_type
:
4710 read_base_type (die
, objfile
);
4713 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4718 static struct type
*
4719 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
4721 /* FIXME - this should not produce a new (struct type *)
4722 every time. It should cache base types. */
4726 case DW_ATE_address
:
4727 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4729 case DW_ATE_boolean
:
4730 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4732 case DW_ATE_complex_float
:
4735 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4739 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4745 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4749 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4756 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4759 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4763 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4767 case DW_ATE_signed_char
:
4768 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4770 case DW_ATE_unsigned
:
4774 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4777 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4781 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4785 case DW_ATE_unsigned_char
:
4786 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4789 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4796 copy_die (struct die_info
*old_die
)
4798 struct die_info
*new_die
;
4801 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4802 memset (new_die
, 0, sizeof (struct die_info
));
4804 new_die
->tag
= old_die
->tag
;
4805 new_die
->has_children
= old_die
->has_children
;
4806 new_die
->abbrev
= old_die
->abbrev
;
4807 new_die
->offset
= old_die
->offset
;
4808 new_die
->type
= NULL
;
4810 num_attrs
= old_die
->num_attrs
;
4811 new_die
->num_attrs
= num_attrs
;
4812 new_die
->attrs
= (struct attribute
*)
4813 xmalloc (num_attrs
* sizeof (struct attribute
));
4815 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4817 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4818 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4819 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4822 new_die
->next
= NULL
;
4827 /* Return sibling of die, NULL if no sibling. */
4829 static struct die_info
*
4830 sibling_die (struct die_info
*die
)
4832 int nesting_level
= 0;
4834 if (!die
->has_children
)
4836 if (die
->next
&& (die
->next
->tag
== 0))
4849 if (die
->has_children
)
4859 while (nesting_level
);
4860 if (die
&& (die
->tag
== 0))
4871 /* Get linkage name of a die, return NULL if not found. */
4874 dwarf2_linkage_name (struct die_info
*die
)
4876 struct attribute
*attr
;
4878 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4879 if (attr
&& DW_STRING (attr
))
4880 return DW_STRING (attr
);
4881 attr
= dwarf_attr (die
, DW_AT_name
);
4882 if (attr
&& DW_STRING (attr
))
4883 return DW_STRING (attr
);
4887 /* Convert a DIE tag into its string name. */
4890 dwarf_tag_name (register unsigned tag
)
4894 case DW_TAG_padding
:
4895 return "DW_TAG_padding";
4896 case DW_TAG_array_type
:
4897 return "DW_TAG_array_type";
4898 case DW_TAG_class_type
:
4899 return "DW_TAG_class_type";
4900 case DW_TAG_entry_point
:
4901 return "DW_TAG_entry_point";
4902 case DW_TAG_enumeration_type
:
4903 return "DW_TAG_enumeration_type";
4904 case DW_TAG_formal_parameter
:
4905 return "DW_TAG_formal_parameter";
4906 case DW_TAG_imported_declaration
:
4907 return "DW_TAG_imported_declaration";
4909 return "DW_TAG_label";
4910 case DW_TAG_lexical_block
:
4911 return "DW_TAG_lexical_block";
4913 return "DW_TAG_member";
4914 case DW_TAG_pointer_type
:
4915 return "DW_TAG_pointer_type";
4916 case DW_TAG_reference_type
:
4917 return "DW_TAG_reference_type";
4918 case DW_TAG_compile_unit
:
4919 return "DW_TAG_compile_unit";
4920 case DW_TAG_string_type
:
4921 return "DW_TAG_string_type";
4922 case DW_TAG_structure_type
:
4923 return "DW_TAG_structure_type";
4924 case DW_TAG_subroutine_type
:
4925 return "DW_TAG_subroutine_type";
4926 case DW_TAG_typedef
:
4927 return "DW_TAG_typedef";
4928 case DW_TAG_union_type
:
4929 return "DW_TAG_union_type";
4930 case DW_TAG_unspecified_parameters
:
4931 return "DW_TAG_unspecified_parameters";
4932 case DW_TAG_variant
:
4933 return "DW_TAG_variant";
4934 case DW_TAG_common_block
:
4935 return "DW_TAG_common_block";
4936 case DW_TAG_common_inclusion
:
4937 return "DW_TAG_common_inclusion";
4938 case DW_TAG_inheritance
:
4939 return "DW_TAG_inheritance";
4940 case DW_TAG_inlined_subroutine
:
4941 return "DW_TAG_inlined_subroutine";
4943 return "DW_TAG_module";
4944 case DW_TAG_ptr_to_member_type
:
4945 return "DW_TAG_ptr_to_member_type";
4946 case DW_TAG_set_type
:
4947 return "DW_TAG_set_type";
4948 case DW_TAG_subrange_type
:
4949 return "DW_TAG_subrange_type";
4950 case DW_TAG_with_stmt
:
4951 return "DW_TAG_with_stmt";
4952 case DW_TAG_access_declaration
:
4953 return "DW_TAG_access_declaration";
4954 case DW_TAG_base_type
:
4955 return "DW_TAG_base_type";
4956 case DW_TAG_catch_block
:
4957 return "DW_TAG_catch_block";
4958 case DW_TAG_const_type
:
4959 return "DW_TAG_const_type";
4960 case DW_TAG_constant
:
4961 return "DW_TAG_constant";
4962 case DW_TAG_enumerator
:
4963 return "DW_TAG_enumerator";
4964 case DW_TAG_file_type
:
4965 return "DW_TAG_file_type";
4967 return "DW_TAG_friend";
4968 case DW_TAG_namelist
:
4969 return "DW_TAG_namelist";
4970 case DW_TAG_namelist_item
:
4971 return "DW_TAG_namelist_item";
4972 case DW_TAG_packed_type
:
4973 return "DW_TAG_packed_type";
4974 case DW_TAG_subprogram
:
4975 return "DW_TAG_subprogram";
4976 case DW_TAG_template_type_param
:
4977 return "DW_TAG_template_type_param";
4978 case DW_TAG_template_value_param
:
4979 return "DW_TAG_template_value_param";
4980 case DW_TAG_thrown_type
:
4981 return "DW_TAG_thrown_type";
4982 case DW_TAG_try_block
:
4983 return "DW_TAG_try_block";
4984 case DW_TAG_variant_part
:
4985 return "DW_TAG_variant_part";
4986 case DW_TAG_variable
:
4987 return "DW_TAG_variable";
4988 case DW_TAG_volatile_type
:
4989 return "DW_TAG_volatile_type";
4990 case DW_TAG_MIPS_loop
:
4991 return "DW_TAG_MIPS_loop";
4992 case DW_TAG_format_label
:
4993 return "DW_TAG_format_label";
4994 case DW_TAG_function_template
:
4995 return "DW_TAG_function_template";
4996 case DW_TAG_class_template
:
4997 return "DW_TAG_class_template";
4999 return "DW_TAG_<unknown>";
5003 /* Convert a DWARF attribute code into its string name. */
5006 dwarf_attr_name (register unsigned attr
)
5011 return "DW_AT_sibling";
5012 case DW_AT_location
:
5013 return "DW_AT_location";
5015 return "DW_AT_name";
5016 case DW_AT_ordering
:
5017 return "DW_AT_ordering";
5018 case DW_AT_subscr_data
:
5019 return "DW_AT_subscr_data";
5020 case DW_AT_byte_size
:
5021 return "DW_AT_byte_size";
5022 case DW_AT_bit_offset
:
5023 return "DW_AT_bit_offset";
5024 case DW_AT_bit_size
:
5025 return "DW_AT_bit_size";
5026 case DW_AT_element_list
:
5027 return "DW_AT_element_list";
5028 case DW_AT_stmt_list
:
5029 return "DW_AT_stmt_list";
5031 return "DW_AT_low_pc";
5033 return "DW_AT_high_pc";
5034 case DW_AT_language
:
5035 return "DW_AT_language";
5037 return "DW_AT_member";
5039 return "DW_AT_discr";
5040 case DW_AT_discr_value
:
5041 return "DW_AT_discr_value";
5042 case DW_AT_visibility
:
5043 return "DW_AT_visibility";
5045 return "DW_AT_import";
5046 case DW_AT_string_length
:
5047 return "DW_AT_string_length";
5048 case DW_AT_common_reference
:
5049 return "DW_AT_common_reference";
5050 case DW_AT_comp_dir
:
5051 return "DW_AT_comp_dir";
5052 case DW_AT_const_value
:
5053 return "DW_AT_const_value";
5054 case DW_AT_containing_type
:
5055 return "DW_AT_containing_type";
5056 case DW_AT_default_value
:
5057 return "DW_AT_default_value";
5059 return "DW_AT_inline";
5060 case DW_AT_is_optional
:
5061 return "DW_AT_is_optional";
5062 case DW_AT_lower_bound
:
5063 return "DW_AT_lower_bound";
5064 case DW_AT_producer
:
5065 return "DW_AT_producer";
5066 case DW_AT_prototyped
:
5067 return "DW_AT_prototyped";
5068 case DW_AT_return_addr
:
5069 return "DW_AT_return_addr";
5070 case DW_AT_start_scope
:
5071 return "DW_AT_start_scope";
5072 case DW_AT_stride_size
:
5073 return "DW_AT_stride_size";
5074 case DW_AT_upper_bound
:
5075 return "DW_AT_upper_bound";
5076 case DW_AT_abstract_origin
:
5077 return "DW_AT_abstract_origin";
5078 case DW_AT_accessibility
:
5079 return "DW_AT_accessibility";
5080 case DW_AT_address_class
:
5081 return "DW_AT_address_class";
5082 case DW_AT_artificial
:
5083 return "DW_AT_artificial";
5084 case DW_AT_base_types
:
5085 return "DW_AT_base_types";
5086 case DW_AT_calling_convention
:
5087 return "DW_AT_calling_convention";
5089 return "DW_AT_count";
5090 case DW_AT_data_member_location
:
5091 return "DW_AT_data_member_location";
5092 case DW_AT_decl_column
:
5093 return "DW_AT_decl_column";
5094 case DW_AT_decl_file
:
5095 return "DW_AT_decl_file";
5096 case DW_AT_decl_line
:
5097 return "DW_AT_decl_line";
5098 case DW_AT_declaration
:
5099 return "DW_AT_declaration";
5100 case DW_AT_discr_list
:
5101 return "DW_AT_discr_list";
5102 case DW_AT_encoding
:
5103 return "DW_AT_encoding";
5104 case DW_AT_external
:
5105 return "DW_AT_external";
5106 case DW_AT_frame_base
:
5107 return "DW_AT_frame_base";
5109 return "DW_AT_friend";
5110 case DW_AT_identifier_case
:
5111 return "DW_AT_identifier_case";
5112 case DW_AT_macro_info
:
5113 return "DW_AT_macro_info";
5114 case DW_AT_namelist_items
:
5115 return "DW_AT_namelist_items";
5116 case DW_AT_priority
:
5117 return "DW_AT_priority";
5119 return "DW_AT_segment";
5120 case DW_AT_specification
:
5121 return "DW_AT_specification";
5122 case DW_AT_static_link
:
5123 return "DW_AT_static_link";
5125 return "DW_AT_type";
5126 case DW_AT_use_location
:
5127 return "DW_AT_use_location";
5128 case DW_AT_variable_parameter
:
5129 return "DW_AT_variable_parameter";
5130 case DW_AT_virtuality
:
5131 return "DW_AT_virtuality";
5132 case DW_AT_vtable_elem_location
:
5133 return "DW_AT_vtable_elem_location";
5136 case DW_AT_MIPS_fde
:
5137 return "DW_AT_MIPS_fde";
5138 case DW_AT_MIPS_loop_begin
:
5139 return "DW_AT_MIPS_loop_begin";
5140 case DW_AT_MIPS_tail_loop_begin
:
5141 return "DW_AT_MIPS_tail_loop_begin";
5142 case DW_AT_MIPS_epilog_begin
:
5143 return "DW_AT_MIPS_epilog_begin";
5144 case DW_AT_MIPS_loop_unroll_factor
:
5145 return "DW_AT_MIPS_loop_unroll_factor";
5146 case DW_AT_MIPS_software_pipeline_depth
:
5147 return "DW_AT_MIPS_software_pipeline_depth";
5148 case DW_AT_MIPS_linkage_name
:
5149 return "DW_AT_MIPS_linkage_name";
5152 case DW_AT_sf_names
:
5153 return "DW_AT_sf_names";
5154 case DW_AT_src_info
:
5155 return "DW_AT_src_info";
5156 case DW_AT_mac_info
:
5157 return "DW_AT_mac_info";
5158 case DW_AT_src_coords
:
5159 return "DW_AT_src_coords";
5160 case DW_AT_body_begin
:
5161 return "DW_AT_body_begin";
5162 case DW_AT_body_end
:
5163 return "DW_AT_body_end";
5165 return "DW_AT_<unknown>";
5169 /* Convert a DWARF value form code into its string name. */
5172 dwarf_form_name (register unsigned form
)
5177 return "DW_FORM_addr";
5178 case DW_FORM_block2
:
5179 return "DW_FORM_block2";
5180 case DW_FORM_block4
:
5181 return "DW_FORM_block4";
5183 return "DW_FORM_data2";
5185 return "DW_FORM_data4";
5187 return "DW_FORM_data8";
5188 case DW_FORM_string
:
5189 return "DW_FORM_string";
5191 return "DW_FORM_block";
5192 case DW_FORM_block1
:
5193 return "DW_FORM_block1";
5195 return "DW_FORM_data1";
5197 return "DW_FORM_flag";
5199 return "DW_FORM_sdata";
5201 return "DW_FORM_strp";
5203 return "DW_FORM_udata";
5204 case DW_FORM_ref_addr
:
5205 return "DW_FORM_ref_addr";
5207 return "DW_FORM_ref1";
5209 return "DW_FORM_ref2";
5211 return "DW_FORM_ref4";
5213 return "DW_FORM_ref8";
5214 case DW_FORM_ref_udata
:
5215 return "DW_FORM_ref_udata";
5216 case DW_FORM_indirect
:
5217 return "DW_FORM_indirect";
5219 return "DW_FORM_<unknown>";
5223 /* Convert a DWARF stack opcode into its string name. */
5226 dwarf_stack_op_name (register unsigned op
)
5231 return "DW_OP_addr";
5233 return "DW_OP_deref";
5235 return "DW_OP_const1u";
5237 return "DW_OP_const1s";
5239 return "DW_OP_const2u";
5241 return "DW_OP_const2s";
5243 return "DW_OP_const4u";
5245 return "DW_OP_const4s";
5247 return "DW_OP_const8u";
5249 return "DW_OP_const8s";
5251 return "DW_OP_constu";
5253 return "DW_OP_consts";
5257 return "DW_OP_drop";
5259 return "DW_OP_over";
5261 return "DW_OP_pick";
5263 return "DW_OP_swap";
5267 return "DW_OP_xderef";
5275 return "DW_OP_minus";
5287 return "DW_OP_plus";
5288 case DW_OP_plus_uconst
:
5289 return "DW_OP_plus_uconst";
5295 return "DW_OP_shra";
5313 return "DW_OP_skip";
5315 return "DW_OP_lit0";
5317 return "DW_OP_lit1";
5319 return "DW_OP_lit2";
5321 return "DW_OP_lit3";
5323 return "DW_OP_lit4";
5325 return "DW_OP_lit5";
5327 return "DW_OP_lit6";
5329 return "DW_OP_lit7";
5331 return "DW_OP_lit8";
5333 return "DW_OP_lit9";
5335 return "DW_OP_lit10";
5337 return "DW_OP_lit11";
5339 return "DW_OP_lit12";
5341 return "DW_OP_lit13";
5343 return "DW_OP_lit14";
5345 return "DW_OP_lit15";
5347 return "DW_OP_lit16";
5349 return "DW_OP_lit17";
5351 return "DW_OP_lit18";
5353 return "DW_OP_lit19";
5355 return "DW_OP_lit20";
5357 return "DW_OP_lit21";
5359 return "DW_OP_lit22";
5361 return "DW_OP_lit23";
5363 return "DW_OP_lit24";
5365 return "DW_OP_lit25";
5367 return "DW_OP_lit26";
5369 return "DW_OP_lit27";
5371 return "DW_OP_lit28";
5373 return "DW_OP_lit29";
5375 return "DW_OP_lit30";
5377 return "DW_OP_lit31";
5379 return "DW_OP_reg0";
5381 return "DW_OP_reg1";
5383 return "DW_OP_reg2";
5385 return "DW_OP_reg3";
5387 return "DW_OP_reg4";
5389 return "DW_OP_reg5";
5391 return "DW_OP_reg6";
5393 return "DW_OP_reg7";
5395 return "DW_OP_reg8";
5397 return "DW_OP_reg9";
5399 return "DW_OP_reg10";
5401 return "DW_OP_reg11";
5403 return "DW_OP_reg12";
5405 return "DW_OP_reg13";
5407 return "DW_OP_reg14";
5409 return "DW_OP_reg15";
5411 return "DW_OP_reg16";
5413 return "DW_OP_reg17";
5415 return "DW_OP_reg18";
5417 return "DW_OP_reg19";
5419 return "DW_OP_reg20";
5421 return "DW_OP_reg21";
5423 return "DW_OP_reg22";
5425 return "DW_OP_reg23";
5427 return "DW_OP_reg24";
5429 return "DW_OP_reg25";
5431 return "DW_OP_reg26";
5433 return "DW_OP_reg27";
5435 return "DW_OP_reg28";
5437 return "DW_OP_reg29";
5439 return "DW_OP_reg30";
5441 return "DW_OP_reg31";
5443 return "DW_OP_breg0";
5445 return "DW_OP_breg1";
5447 return "DW_OP_breg2";
5449 return "DW_OP_breg3";
5451 return "DW_OP_breg4";
5453 return "DW_OP_breg5";
5455 return "DW_OP_breg6";
5457 return "DW_OP_breg7";
5459 return "DW_OP_breg8";
5461 return "DW_OP_breg9";
5463 return "DW_OP_breg10";
5465 return "DW_OP_breg11";
5467 return "DW_OP_breg12";
5469 return "DW_OP_breg13";
5471 return "DW_OP_breg14";
5473 return "DW_OP_breg15";
5475 return "DW_OP_breg16";
5477 return "DW_OP_breg17";
5479 return "DW_OP_breg18";
5481 return "DW_OP_breg19";
5483 return "DW_OP_breg20";
5485 return "DW_OP_breg21";
5487 return "DW_OP_breg22";
5489 return "DW_OP_breg23";
5491 return "DW_OP_breg24";
5493 return "DW_OP_breg25";
5495 return "DW_OP_breg26";
5497 return "DW_OP_breg27";
5499 return "DW_OP_breg28";
5501 return "DW_OP_breg29";
5503 return "DW_OP_breg30";
5505 return "DW_OP_breg31";
5507 return "DW_OP_regx";
5509 return "DW_OP_fbreg";
5511 return "DW_OP_bregx";
5513 return "DW_OP_piece";
5514 case DW_OP_deref_size
:
5515 return "DW_OP_deref_size";
5516 case DW_OP_xderef_size
:
5517 return "DW_OP_xderef_size";
5521 return "OP_<unknown>";
5526 dwarf_bool_name (unsigned mybool
)
5534 /* Convert a DWARF type code into its string name. */
5537 dwarf_type_encoding_name (register unsigned enc
)
5541 case DW_ATE_address
:
5542 return "DW_ATE_address";
5543 case DW_ATE_boolean
:
5544 return "DW_ATE_boolean";
5545 case DW_ATE_complex_float
:
5546 return "DW_ATE_complex_float";
5548 return "DW_ATE_float";
5550 return "DW_ATE_signed";
5551 case DW_ATE_signed_char
:
5552 return "DW_ATE_signed_char";
5553 case DW_ATE_unsigned
:
5554 return "DW_ATE_unsigned";
5555 case DW_ATE_unsigned_char
:
5556 return "DW_ATE_unsigned_char";
5558 return "DW_ATE_<unknown>";
5562 /* Convert a DWARF call frame info operation to its string name. */
5566 dwarf_cfi_name (register unsigned cfi_opc
)
5570 case DW_CFA_advance_loc
:
5571 return "DW_CFA_advance_loc";
5573 return "DW_CFA_offset";
5574 case DW_CFA_restore
:
5575 return "DW_CFA_restore";
5577 return "DW_CFA_nop";
5578 case DW_CFA_set_loc
:
5579 return "DW_CFA_set_loc";
5580 case DW_CFA_advance_loc1
:
5581 return "DW_CFA_advance_loc1";
5582 case DW_CFA_advance_loc2
:
5583 return "DW_CFA_advance_loc2";
5584 case DW_CFA_advance_loc4
:
5585 return "DW_CFA_advance_loc4";
5586 case DW_CFA_offset_extended
:
5587 return "DW_CFA_offset_extended";
5588 case DW_CFA_restore_extended
:
5589 return "DW_CFA_restore_extended";
5590 case DW_CFA_undefined
:
5591 return "DW_CFA_undefined";
5592 case DW_CFA_same_value
:
5593 return "DW_CFA_same_value";
5594 case DW_CFA_register
:
5595 return "DW_CFA_register";
5596 case DW_CFA_remember_state
:
5597 return "DW_CFA_remember_state";
5598 case DW_CFA_restore_state
:
5599 return "DW_CFA_restore_state";
5600 case DW_CFA_def_cfa
:
5601 return "DW_CFA_def_cfa";
5602 case DW_CFA_def_cfa_register
:
5603 return "DW_CFA_def_cfa_register";
5604 case DW_CFA_def_cfa_offset
:
5605 return "DW_CFA_def_cfa_offset";
5606 /* SGI/MIPS specific */
5607 case DW_CFA_MIPS_advance_loc8
:
5608 return "DW_CFA_MIPS_advance_loc8";
5610 return "DW_CFA_<unknown>";
5616 dump_die (struct die_info
*die
)
5620 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5621 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5622 fprintf (stderr
, "\thas children: %s\n",
5623 dwarf_bool_name (die
->has_children
));
5625 fprintf (stderr
, "\tattributes:\n");
5626 for (i
= 0; i
< die
->num_attrs
; ++i
)
5628 fprintf (stderr
, "\t\t%s (%s) ",
5629 dwarf_attr_name (die
->attrs
[i
].name
),
5630 dwarf_form_name (die
->attrs
[i
].form
));
5631 switch (die
->attrs
[i
].form
)
5633 case DW_FORM_ref_addr
:
5635 fprintf (stderr
, "address: ");
5636 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5638 case DW_FORM_block2
:
5639 case DW_FORM_block4
:
5641 case DW_FORM_block1
:
5642 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5653 fprintf (stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
5655 case DW_FORM_string
:
5657 fprintf (stderr
, "string: \"%s\"",
5658 DW_STRING (&die
->attrs
[i
])
5659 ? DW_STRING (&die
->attrs
[i
]) : "");
5662 if (DW_UNSND (&die
->attrs
[i
]))
5663 fprintf (stderr
, "flag: TRUE");
5665 fprintf (stderr
, "flag: FALSE");
5667 case DW_FORM_indirect
:
5668 /* the reader will have reduced the indirect form to
5669 the "base form" so this form should not occur */
5670 fprintf (stderr
, "unexpected attribute form: DW_FORM_indirect");
5673 fprintf (stderr
, "unsupported attribute form: %d.",
5674 die
->attrs
[i
].form
);
5676 fprintf (stderr
, "\n");
5681 dump_die_list (struct die_info
*die
)
5691 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
5694 struct die_info
*old
;
5696 h
= (offset
% REF_HASH_SIZE
);
5697 old
= die_ref_table
[h
];
5698 die
->next_ref
= old
;
5699 die_ref_table
[h
] = die
;
5704 dwarf2_empty_hash_tables (void)
5706 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5710 dwarf2_get_ref_die_offset (struct attribute
*attr
)
5712 unsigned int result
= 0;
5716 case DW_FORM_ref_addr
:
5717 result
= DW_ADDR (attr
);
5723 case DW_FORM_ref_udata
:
5724 result
= cu_header_offset
+ DW_UNSND (attr
);
5727 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5732 static struct die_info
*
5733 follow_die_ref (unsigned int offset
)
5735 struct die_info
*die
;
5738 h
= (offset
% REF_HASH_SIZE
);
5739 die
= die_ref_table
[h
];
5742 if (die
->offset
== offset
)
5746 die
= die
->next_ref
;
5751 static struct type
*
5752 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
5754 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5756 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5760 /* Look for this particular type in the fundamental type vector. If
5761 one is not found, create and install one appropriate for the
5762 current language and the current target machine. */
5764 if (ftypes
[typeid] == NULL
)
5766 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5769 return (ftypes
[typeid]);
5772 /* Decode simple location descriptions.
5773 Given a pointer to a dwarf block that defines a location, compute
5774 the location and return the value.
5776 FIXME: This is a kludge until we figure out a better
5777 way to handle the location descriptions.
5778 Gdb's design does not mesh well with the DWARF2 notion of a location
5779 computing interpreter, which is a shame because the flexibility goes unused.
5780 FIXME: Implement more operations as necessary.
5782 A location description containing no operations indicates that the
5783 object is optimized out. The global optimized_out flag is set for
5784 those, the return value is meaningless.
5786 When the result is a register number, the global isreg flag is set,
5787 otherwise it is cleared.
5789 When the result is a base register offset, the global offreg flag is set
5790 and the register number is returned in basereg, otherwise it is cleared.
5792 When the DW_OP_fbreg operation is encountered without a corresponding
5793 DW_AT_frame_base attribute, the global islocal flag is set.
5794 Hopefully the machine dependent code knows how to set up a virtual
5795 frame pointer for the local references.
5797 Note that stack[0] is unused except as a default error return.
5798 Note that stack overflow is not yet handled. */
5801 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
5802 const struct comp_unit_head
*cu_header
)
5805 int size
= blk
->size
;
5806 char *data
= blk
->data
;
5807 CORE_ADDR stack
[64];
5809 unsigned int bytes_read
, unsnd
;
5859 stack
[++stacki
] = op
- DW_OP_lit0
;
5895 stack
[++stacki
] = op
- DW_OP_reg0
;
5900 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5902 #if defined(HARRIS_TARGET) && defined(_M88K)
5903 /* The Harris 88110 gdb ports have long kept their special reg
5904 numbers between their gp-regs and their x-regs. This is
5905 not how our dwarf is generated. Punt. */
5908 stack
[++stacki
] = unsnd
;
5944 basereg
= op
- DW_OP_breg0
;
5945 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5951 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5953 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5958 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5960 if (frame_base_reg
>= 0)
5963 basereg
= frame_base_reg
;
5964 stack
[stacki
] += frame_base_offset
;
5968 complain (&dwarf2_missing_at_frame_base
);
5974 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
5975 cu_header
, &bytes_read
);
5980 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5985 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5990 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5995 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
6000 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
6005 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
6010 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
6016 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6021 stack
[stacki
+ 1] = stack
[stacki
];
6026 stack
[stacki
- 1] += stack
[stacki
];
6030 case DW_OP_plus_uconst
:
6031 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6036 stack
[stacki
- 1] -= stack
[stacki
];
6042 /* If we're not the last op, then we definitely can't encode
6043 this using GDB's address_class enum. */
6045 complain (&dwarf2_complex_location_expr
);
6049 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
6050 return (stack
[stacki
]);
6053 return (stack
[stacki
]);
6056 /* memory allocation interface */
6060 dwarf2_free_tmp_obstack (PTR ignore
)
6062 obstack_free (&dwarf2_tmp_obstack
, NULL
);
6065 static struct dwarf_block
*
6066 dwarf_alloc_block (void)
6068 struct dwarf_block
*blk
;
6070 blk
= (struct dwarf_block
*)
6071 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
6075 static struct abbrev_info
*
6076 dwarf_alloc_abbrev (void)
6078 struct abbrev_info
*abbrev
;
6080 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
6081 memset (abbrev
, 0, sizeof (struct abbrev_info
));
6085 static struct die_info
*
6086 dwarf_alloc_die (void)
6088 struct die_info
*die
;
6090 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6091 memset (die
, 0, sizeof (struct die_info
));