1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 Free Software Foundation, Inc.
6 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
7 Inc. with support from Florida State University (under contract
8 with the Ada Joint Program Office), and Silicon Graphics, Inc.
9 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
10 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
11 support in dwarfread.c
13 This file is part of GDB.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or (at
18 your option) any later version.
20 This program is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place - Suite 330,
28 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"
44 #include "dwarf2expr.h"
45 #include "dwarf2loc.h"
46 #include "cp-support.h"
50 #include "gdb_string.h"
51 #include "gdb_assert.h"
52 #include <sys/types.h>
54 /* A note on memory usage for this file.
56 At the present time, this code reads the debug info sections into
57 the objfile's objfile_obstack. A definite improvement for startup
58 time, on platforms which do not emit relocations for debug
59 sections, would be to use mmap instead. The object's complete
60 debug information is loaded into memory, partly to simplify
61 absolute DIE references.
63 Whether using obstacks or mmap, the sections should remain loaded
64 until the objfile is released, and pointers into the section data
65 can be used for any other data associated to the objfile (symbol
66 names, type names, location expressions to name a few). */
68 #ifndef DWARF2_REG_TO_REGNUM
69 #define DWARF2_REG_TO_REGNUM(REG) (REG)
73 /* .debug_info header for a compilation unit
74 Because of alignment constraints, this structure has padding and cannot
75 be mapped directly onto the beginning of the .debug_info section. */
76 typedef struct comp_unit_header
78 unsigned int length
; /* length of the .debug_info
80 unsigned short version
; /* version number -- 2 for DWARF
82 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
83 unsigned char addr_size
; /* byte size of an address -- 4 */
86 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
89 /* .debug_pubnames header
90 Because of alignment constraints, this structure has padding and cannot
91 be mapped directly onto the beginning of the .debug_info section. */
92 typedef struct pubnames_header
94 unsigned int length
; /* length of the .debug_pubnames
96 unsigned char version
; /* version number -- 2 for DWARF
98 unsigned int info_offset
; /* offset into .debug_info section */
99 unsigned int info_size
; /* byte size of .debug_info section
103 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
105 /* .debug_pubnames header
106 Because of alignment constraints, this structure has padding and cannot
107 be mapped directly onto the beginning of the .debug_info section. */
108 typedef struct aranges_header
110 unsigned int length
; /* byte len of the .debug_aranges
112 unsigned short version
; /* version number -- 2 for DWARF
114 unsigned int info_offset
; /* offset into .debug_info section */
115 unsigned char addr_size
; /* byte size of an address */
116 unsigned char seg_size
; /* byte size of segment descriptor */
119 #define _ACTUAL_ARANGES_HEADER_SIZE 12
121 /* .debug_line statement program prologue
122 Because of alignment constraints, this structure has padding and cannot
123 be mapped directly onto the beginning of the .debug_info section. */
124 typedef struct statement_prologue
126 unsigned int total_length
; /* byte length of the statement
128 unsigned short version
; /* version number -- 2 for DWARF
130 unsigned int prologue_length
; /* # bytes between prologue &
132 unsigned char minimum_instruction_length
; /* byte size of
134 unsigned char default_is_stmt
; /* initial value of is_stmt
137 unsigned char line_range
;
138 unsigned char opcode_base
; /* number assigned to first special
140 unsigned char *standard_opcode_lengths
;
144 static const struct objfile_data
*dwarf2_objfile_data_key
;
146 struct dwarf2_per_objfile
148 /* Sizes of debugging sections. */
149 unsigned int info_size
;
150 unsigned int abbrev_size
;
151 unsigned int line_size
;
152 unsigned int pubnames_size
;
153 unsigned int aranges_size
;
154 unsigned int loc_size
;
155 unsigned int macinfo_size
;
156 unsigned int str_size
;
157 unsigned int ranges_size
;
158 unsigned int frame_size
;
159 unsigned int eh_frame_size
;
161 /* Loaded data from the sections. */
166 char *macinfo_buffer
;
171 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
173 static asection
*dwarf_info_section
;
174 static asection
*dwarf_abbrev_section
;
175 static asection
*dwarf_line_section
;
176 static asection
*dwarf_pubnames_section
;
177 static asection
*dwarf_aranges_section
;
178 static asection
*dwarf_loc_section
;
179 static asection
*dwarf_macinfo_section
;
180 static asection
*dwarf_str_section
;
181 static asection
*dwarf_ranges_section
;
182 asection
*dwarf_frame_section
;
183 asection
*dwarf_eh_frame_section
;
185 /* names of the debugging sections */
187 #define INFO_SECTION ".debug_info"
188 #define ABBREV_SECTION ".debug_abbrev"
189 #define LINE_SECTION ".debug_line"
190 #define PUBNAMES_SECTION ".debug_pubnames"
191 #define ARANGES_SECTION ".debug_aranges"
192 #define LOC_SECTION ".debug_loc"
193 #define MACINFO_SECTION ".debug_macinfo"
194 #define STR_SECTION ".debug_str"
195 #define RANGES_SECTION ".debug_ranges"
196 #define FRAME_SECTION ".debug_frame"
197 #define EH_FRAME_SECTION ".eh_frame"
199 /* local data types */
201 /* We hold several abbreviation tables in memory at the same time. */
202 #ifndef ABBREV_HASH_SIZE
203 #define ABBREV_HASH_SIZE 121
206 /* The data in a compilation unit header, after target2host
207 translation, looks like this. */
208 struct comp_unit_head
210 unsigned long length
;
212 unsigned int abbrev_offset
;
213 unsigned char addr_size
;
214 unsigned char signed_addr_p
;
215 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
216 unsigned int initial_length_size
; /* size of the length field; either
219 /* Offset to the first byte of this compilation unit header in the
220 * .debug_info section, for resolving relative reference dies. */
224 /* Pointer to this compilation unit header in the .debug_info
229 /* Pointer to the first die of this compilatio unit. This will
230 * be the first byte following the compilation unit header. */
234 /* Pointer to the next compilation unit header in the program. */
236 struct comp_unit_head
*next
;
238 /* Base address of this compilation unit. */
240 CORE_ADDR base_address
;
242 /* Non-zero if base_address has been set. */
247 /* Internal state when decoding a particular compilation unit. */
250 /* The objfile containing this compilation unit. */
251 struct objfile
*objfile
;
253 /* The header of the compilation unit.
255 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
256 should logically be moved to the dwarf2_cu structure. */
257 struct comp_unit_head header
;
259 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
261 /* The language we are debugging. */
262 enum language language
;
263 const struct language_defn
*language_defn
;
265 /* The generic symbol table building routines have separate lists for
266 file scope symbols and all all other scopes (local scopes). So
267 we need to select the right one to pass to add_symbol_to_list().
268 We do it by keeping a pointer to the correct list in list_in_scope.
270 FIXME: The original dwarf code just treated the file scope as the
271 first local scope, and all other local scopes as nested local
272 scopes, and worked fine. Check to see if we really need to
273 distinguish these in buildsym.c. */
274 struct pending
**list_in_scope
;
276 /* Maintain an array of referenced fundamental types for the current
277 compilation unit being read. For DWARF version 1, we have to construct
278 the fundamental types on the fly, since no information about the
279 fundamental types is supplied. Each such fundamental type is created by
280 calling a language dependent routine to create the type, and then a
281 pointer to that type is then placed in the array at the index specified
282 by it's FT_<TYPENAME> value. The array has a fixed size set by the
283 FT_NUM_MEMBERS compile time constant, which is the number of predefined
284 fundamental types gdb knows how to construct. */
285 struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
287 /* DWARF abbreviation table associated with this compilation unit. */
288 struct abbrev_info
**dwarf2_abbrevs
;
290 /* Storage for the abbrev table. */
291 struct obstack abbrev_obstack
;
293 /* Hash table holding all the loaded partial DIEs. */
296 /* Storage for things with the same lifetime as this read-in compilation
297 unit, including partial DIEs. */
298 struct obstack comp_unit_obstack
;
300 /* This flag will be set if this compilation unit includes any
301 DW_TAG_namespace DIEs. If we know that there are explicit
302 DIEs for namespaces, we don't need to try to infer them
303 from mangled names. */
304 unsigned int has_namespace_info
: 1;
307 /* The line number information for a compilation unit (found in the
308 .debug_line section) begins with a "statement program header",
309 which contains the following information. */
312 unsigned int total_length
;
313 unsigned short version
;
314 unsigned int header_length
;
315 unsigned char minimum_instruction_length
;
316 unsigned char default_is_stmt
;
318 unsigned char line_range
;
319 unsigned char opcode_base
;
321 /* standard_opcode_lengths[i] is the number of operands for the
322 standard opcode whose value is i. This means that
323 standard_opcode_lengths[0] is unused, and the last meaningful
324 element is standard_opcode_lengths[opcode_base - 1]. */
325 unsigned char *standard_opcode_lengths
;
327 /* The include_directories table. NOTE! These strings are not
328 allocated with xmalloc; instead, they are pointers into
329 debug_line_buffer. If you try to free them, `free' will get
331 unsigned int num_include_dirs
, include_dirs_size
;
334 /* The file_names table. NOTE! These strings are not allocated
335 with xmalloc; instead, they are pointers into debug_line_buffer.
336 Don't try to free them directly. */
337 unsigned int num_file_names
, file_names_size
;
341 unsigned int dir_index
;
342 unsigned int mod_time
;
344 int included_p
; /* Non-zero if referenced by the Line Number Program. */
347 /* The start and end of the statement program following this
348 header. These point into dwarf2_per_objfile->line_buffer. */
349 char *statement_program_start
, *statement_program_end
;
352 /* When we construct a partial symbol table entry we only
353 need this much information. */
354 struct partial_die_info
356 /* Offset of this DIE. */
359 /* DWARF-2 tag for this DIE. */
360 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
362 /* Language code associated with this DIE. This is only used
363 for the compilation unit DIE. */
364 unsigned int language
: 8;
366 /* Assorted flags describing the data found in this DIE. */
367 unsigned int has_children
: 1;
368 unsigned int is_external
: 1;
369 unsigned int is_declaration
: 1;
370 unsigned int has_type
: 1;
371 unsigned int has_specification
: 1;
372 unsigned int has_stmt_list
: 1;
373 unsigned int has_pc_info
: 1;
375 /* Flag set if the SCOPE field of this structure has been
377 unsigned int scope_set
: 1;
379 /* The name of this DIE. Normally the value of DW_AT_name, but
380 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
385 /* The scope to prepend to our children. This is generally
386 allocated on the comp_unit_obstack, so will disappear
387 when this compilation unit leaves the cache. */
390 /* The location description associated with this DIE, if any. */
391 struct dwarf_block
*locdesc
;
393 /* If HAS_PC_INFO, the PC range associated with this DIE. */
397 /* Pointer into the info_buffer pointing at the target of
398 DW_AT_sibling, if any. */
401 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
402 DW_AT_specification (or DW_AT_abstract_origin or
404 unsigned int spec_offset
;
406 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
407 unsigned int line_offset
;
409 /* Pointers to this DIE's parent, first child, and next sibling,
411 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
414 /* This data structure holds the information of an abbrev. */
417 unsigned int number
; /* number identifying abbrev */
418 enum dwarf_tag tag
; /* dwarf tag */
419 unsigned short has_children
; /* boolean */
420 unsigned short num_attrs
; /* number of attributes */
421 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
422 struct abbrev_info
*next
; /* next in chain */
427 enum dwarf_attribute name
;
428 enum dwarf_form form
;
431 /* This data structure holds a complete die structure. */
434 enum dwarf_tag tag
; /* Tag indicating type of die */
435 unsigned int abbrev
; /* Abbrev number */
436 unsigned int offset
; /* Offset in .debug_info section */
437 unsigned int num_attrs
; /* Number of attributes */
438 struct attribute
*attrs
; /* An array of attributes */
439 struct die_info
*next_ref
; /* Next die in ref hash table */
441 /* The dies in a compilation unit form an n-ary tree. PARENT
442 points to this die's parent; CHILD points to the first child of
443 this node; and all the children of a given node are chained
444 together via their SIBLING fields, terminated by a die whose
446 struct die_info
*child
; /* Its first child, if any. */
447 struct die_info
*sibling
; /* Its next sibling, if any. */
448 struct die_info
*parent
; /* Its parent, if any. */
450 struct type
*type
; /* Cached type information */
453 /* Attributes have a name and a value */
456 enum dwarf_attribute name
;
457 enum dwarf_form form
;
461 struct dwarf_block
*blk
;
469 struct function_range
472 CORE_ADDR lowpc
, highpc
;
474 struct function_range
*next
;
477 /* Get at parts of an attribute structure */
479 #define DW_STRING(attr) ((attr)->u.str)
480 #define DW_UNSND(attr) ((attr)->u.unsnd)
481 #define DW_BLOCK(attr) ((attr)->u.blk)
482 #define DW_SND(attr) ((attr)->u.snd)
483 #define DW_ADDR(attr) ((attr)->u.addr)
485 /* Blocks are a bunch of untyped bytes. */
492 #ifndef ATTR_ALLOC_CHUNK
493 #define ATTR_ALLOC_CHUNK 4
496 /* A hash table of die offsets for following references. */
497 #ifndef REF_HASH_SIZE
498 #define REF_HASH_SIZE 1021
501 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
503 /* Allocate fields for structs, unions and enums in this size. */
504 #ifndef DW_FIELD_ALLOC_CHUNK
505 #define DW_FIELD_ALLOC_CHUNK 4
508 /* A zeroed version of a partial die for initialization purposes. */
509 static struct partial_die_info zeroed_partial_die
;
511 /* FIXME: decode_locdesc sets these variables to describe the location
512 to the caller. These ought to be a structure or something. If
513 none of the flags are set, the object lives at the address returned
514 by decode_locdesc. */
516 static int isreg
; /* Object lives in register.
517 decode_locdesc's return value is
518 the register number. */
520 /* We put a pointer to this structure in the read_symtab_private field
525 /* Offset in .debug_info for this compilation unit. */
527 unsigned long dwarf_info_offset
;
530 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
531 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
533 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
534 but this would require a corresponding change in unpack_field_as_long
536 static int bits_per_byte
= 8;
538 /* The routines that read and process dies for a C struct or C++ class
539 pass lists of data member fields and lists of member function fields
540 in an instance of a field_info structure, as defined below. */
543 /* List of data member and baseclasses fields. */
546 struct nextfield
*next
;
553 /* Number of fields. */
556 /* Number of baseclasses. */
559 /* Set if the accesibility of one of the fields is not public. */
560 int non_public_fields
;
562 /* Member function fields array, entries are allocated in the order they
563 are encountered in the object file. */
566 struct nextfnfield
*next
;
567 struct fn_field fnfield
;
571 /* Member function fieldlist array, contains name of possibly overloaded
572 member function, number of overloaded member functions and a pointer
573 to the head of the member function field chain. */
578 struct nextfnfield
*head
;
582 /* Number of entries in the fnfieldlists array. */
586 /* Various complaints about symbol reading that don't abort the process */
589 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
591 complaint (&symfile_complaints
,
592 "statement list doesn't fit in .debug_line section");
596 dwarf2_complex_location_expr_complaint (void)
598 complaint (&symfile_complaints
, "location expression too complex");
602 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
605 complaint (&symfile_complaints
,
606 "const value length mismatch for '%s', got %d, expected %d", arg1
,
611 dwarf2_macros_too_long_complaint (void)
613 complaint (&symfile_complaints
,
614 "macro info runs off end of `.debug_macinfo' section");
618 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
620 complaint (&symfile_complaints
,
621 "macro debug info contains a malformed macro definition:\n`%s'",
626 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
628 complaint (&symfile_complaints
,
629 "invalid attribute class or form for '%s' in '%s'", arg1
, arg2
);
632 /* local function prototypes */
634 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
637 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
640 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
643 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
644 struct partial_die_info
*,
645 struct partial_symtab
*);
647 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
649 static void scan_partial_symbols (struct partial_die_info
*,
650 CORE_ADDR
*, CORE_ADDR
*,
653 static void add_partial_symbol (struct partial_die_info
*,
656 static int pdi_needs_namespace (enum dwarf_tag tag
);
658 static void add_partial_namespace (struct partial_die_info
*pdi
,
659 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
660 struct dwarf2_cu
*cu
);
662 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
663 struct dwarf2_cu
*cu
);
665 static char *locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
668 struct dwarf2_cu
*cu
);
670 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
672 static void psymtab_to_symtab_1 (struct partial_symtab
*);
674 char *dwarf2_read_section (struct objfile
*, asection
*);
676 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
678 static void dwarf2_free_abbrev_table (void *);
680 static struct abbrev_info
*peek_die_abbrev (char *, int *, struct dwarf2_cu
*);
682 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
685 static struct partial_die_info
*load_partial_dies (bfd
*, char *, int,
688 static char *read_partial_die (struct partial_die_info
*,
689 struct abbrev_info
*abbrev
, unsigned int,
690 bfd
*, char *, struct dwarf2_cu
*);
692 static struct partial_die_info
*find_partial_die (unsigned long,
694 struct dwarf2_cu
**);
696 static void fixup_partial_die (struct partial_die_info
*,
699 static char *read_full_die (struct die_info
**, bfd
*, char *,
700 struct dwarf2_cu
*, int *);
702 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
703 bfd
*, char *, struct dwarf2_cu
*);
705 static char *read_attribute_value (struct attribute
*, unsigned,
706 bfd
*, char *, struct dwarf2_cu
*);
708 static unsigned int read_1_byte (bfd
*, char *);
710 static int read_1_signed_byte (bfd
*, char *);
712 static unsigned int read_2_bytes (bfd
*, char *);
714 static unsigned int read_4_bytes (bfd
*, char *);
716 static unsigned long read_8_bytes (bfd
*, char *);
718 static CORE_ADDR
read_address (bfd
*, char *ptr
, struct dwarf2_cu
*,
721 static LONGEST
read_initial_length (bfd
*, char *,
722 struct comp_unit_head
*, int *bytes_read
);
724 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
727 static char *read_n_bytes (bfd
*, char *, unsigned int);
729 static char *read_string (bfd
*, char *, unsigned int *);
731 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
734 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
736 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
738 static char *skip_leb128 (bfd
*, char *);
740 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
742 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
745 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
746 struct dwarf2_cu
*cu
);
748 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
750 static struct die_info
*die_specification (struct die_info
*die
,
753 static void free_line_header (struct line_header
*lh
);
755 static void add_file_name (struct line_header
*, char *, unsigned int,
756 unsigned int, unsigned int);
758 static struct line_header
*(dwarf_decode_line_header
759 (unsigned int offset
,
760 bfd
*abfd
, struct dwarf2_cu
*cu
));
762 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
763 struct dwarf2_cu
*, struct partial_symtab
*);
765 static void dwarf2_start_subfile (char *, char *);
767 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
770 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
773 static void dwarf2_const_value_data (struct attribute
*attr
,
777 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
779 static struct type
*die_containing_type (struct die_info
*,
783 static struct type
*type_at_offset (unsigned int, struct objfile
*);
786 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
788 static void read_type_die (struct die_info
*, struct dwarf2_cu
*);
790 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
792 static char *typename_concat (const char *prefix
, const char *suffix
);
794 static void read_typedef (struct die_info
*, struct dwarf2_cu
*);
796 static void read_base_type (struct die_info
*, struct dwarf2_cu
*);
798 static void read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
800 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
802 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
804 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
806 static int dwarf2_get_pc_bounds (struct die_info
*,
807 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
809 static void get_scope_pc_bounds (struct die_info
*,
810 CORE_ADDR
*, CORE_ADDR
*,
813 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
816 static void dwarf2_attach_fields_to_type (struct field_info
*,
817 struct type
*, struct dwarf2_cu
*);
819 static void dwarf2_add_member_fn (struct field_info
*,
820 struct die_info
*, struct type
*,
823 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
824 struct type
*, struct dwarf2_cu
*);
826 static void read_structure_type (struct die_info
*, struct dwarf2_cu
*);
828 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
830 static char *determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
832 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
834 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
836 static const char *namespace_name (struct die_info
*die
,
837 int *is_anonymous
, struct dwarf2_cu
*);
839 static void read_enumeration_type (struct die_info
*, struct dwarf2_cu
*);
841 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
843 static struct type
*dwarf_base_type (int, int, struct dwarf2_cu
*);
845 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
847 static void read_array_type (struct die_info
*, struct dwarf2_cu
*);
849 static void read_tag_pointer_type (struct die_info
*, struct dwarf2_cu
*);
851 static void read_tag_ptr_to_member_type (struct die_info
*,
854 static void read_tag_reference_type (struct die_info
*, struct dwarf2_cu
*);
856 static void read_tag_const_type (struct die_info
*, struct dwarf2_cu
*);
858 static void read_tag_volatile_type (struct die_info
*, struct dwarf2_cu
*);
860 static void read_tag_string_type (struct die_info
*, struct dwarf2_cu
*);
862 static void read_subroutine_type (struct die_info
*, struct dwarf2_cu
*);
864 static struct die_info
*read_comp_unit (char *, bfd
*, struct dwarf2_cu
*);
866 static struct die_info
*read_die_and_children (char *info_ptr
, bfd
*abfd
,
869 struct die_info
*parent
);
871 static struct die_info
*read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
874 struct die_info
*parent
);
876 static void free_die_list (struct die_info
*);
878 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
880 static void process_die (struct die_info
*, struct dwarf2_cu
*);
882 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
884 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
886 static struct die_info
*dwarf2_extension (struct die_info
*die
,
889 static char *dwarf_tag_name (unsigned int);
891 static char *dwarf_attr_name (unsigned int);
893 static char *dwarf_form_name (unsigned int);
895 static char *dwarf_stack_op_name (unsigned int);
897 static char *dwarf_bool_name (unsigned int);
899 static char *dwarf_type_encoding_name (unsigned int);
902 static char *dwarf_cfi_name (unsigned int);
904 struct die_info
*copy_die (struct die_info
*);
907 static struct die_info
*sibling_die (struct die_info
*);
909 static void dump_die (struct die_info
*);
911 static void dump_die_list (struct die_info
*);
913 static void store_in_ref_table (unsigned int, struct die_info
*);
915 static void dwarf2_empty_hash_tables (void);
917 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
920 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
922 static struct die_info
*follow_die_ref (unsigned int);
924 static struct type
*dwarf2_fundamental_type (struct objfile
*, int,
927 /* memory allocation interface */
929 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
931 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
933 static struct die_info
*dwarf_alloc_die (void);
935 static void initialize_cu_func_list (struct dwarf2_cu
*);
937 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
940 static void dwarf_decode_macros (struct line_header
*, unsigned int,
941 char *, bfd
*, struct dwarf2_cu
*);
943 static int attr_form_is_block (struct attribute
*);
946 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
947 struct dwarf2_cu
*cu
);
949 static char *skip_one_die (char *info_ptr
, struct abbrev_info
*abbrev
,
950 struct dwarf2_cu
*cu
);
952 static void free_stack_comp_unit (void *);
954 static void *hashtab_obstack_allocate (void *data
, size_t size
, size_t count
);
956 static void dummy_obstack_deallocate (void *object
, void *data
);
958 static hashval_t
partial_die_hash (const void *item
);
960 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
962 /* Try to locate the sections we need for DWARF 2 debugging
963 information and return true if we have enough to do something. */
966 dwarf2_has_info (struct objfile
*objfile
)
968 struct dwarf2_per_objfile
*data
;
970 /* Initialize per-objfile state. */
971 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
972 memset (data
, 0, sizeof (*data
));
973 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
974 dwarf2_per_objfile
= data
;
976 dwarf_info_section
= 0;
977 dwarf_abbrev_section
= 0;
978 dwarf_line_section
= 0;
979 dwarf_str_section
= 0;
980 dwarf_macinfo_section
= 0;
981 dwarf_frame_section
= 0;
982 dwarf_eh_frame_section
= 0;
983 dwarf_ranges_section
= 0;
984 dwarf_loc_section
= 0;
986 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
987 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
990 /* This function is mapped across the sections and remembers the
991 offset and size of each of the debugging sections we are interested
995 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
997 if (strcmp (sectp
->name
, INFO_SECTION
) == 0)
999 dwarf2_per_objfile
->info_size
= bfd_get_section_size_before_reloc (sectp
);
1000 dwarf_info_section
= sectp
;
1002 else if (strcmp (sectp
->name
, ABBREV_SECTION
) == 0)
1004 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
1005 dwarf_abbrev_section
= sectp
;
1007 else if (strcmp (sectp
->name
, LINE_SECTION
) == 0)
1009 dwarf2_per_objfile
->line_size
= bfd_get_section_size_before_reloc (sectp
);
1010 dwarf_line_section
= sectp
;
1012 else if (strcmp (sectp
->name
, PUBNAMES_SECTION
) == 0)
1014 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
1015 dwarf_pubnames_section
= sectp
;
1017 else if (strcmp (sectp
->name
, ARANGES_SECTION
) == 0)
1019 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size_before_reloc (sectp
);
1020 dwarf_aranges_section
= sectp
;
1022 else if (strcmp (sectp
->name
, LOC_SECTION
) == 0)
1024 dwarf2_per_objfile
->loc_size
= bfd_get_section_size_before_reloc (sectp
);
1025 dwarf_loc_section
= sectp
;
1027 else if (strcmp (sectp
->name
, MACINFO_SECTION
) == 0)
1029 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
1030 dwarf_macinfo_section
= sectp
;
1032 else if (strcmp (sectp
->name
, STR_SECTION
) == 0)
1034 dwarf2_per_objfile
->str_size
= bfd_get_section_size_before_reloc (sectp
);
1035 dwarf_str_section
= sectp
;
1037 else if (strcmp (sectp
->name
, FRAME_SECTION
) == 0)
1039 dwarf2_per_objfile
->frame_size
= bfd_get_section_size_before_reloc (sectp
);
1040 dwarf_frame_section
= sectp
;
1042 else if (strcmp (sectp
->name
, EH_FRAME_SECTION
) == 0)
1044 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1045 if (aflag
& SEC_HAS_CONTENTS
)
1047 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1048 dwarf_eh_frame_section
= sectp
;
1051 else if (strcmp (sectp
->name
, RANGES_SECTION
) == 0)
1053 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size_before_reloc (sectp
);
1054 dwarf_ranges_section
= sectp
;
1058 /* Build a partial symbol table. */
1061 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1063 /* We definitely need the .debug_info and .debug_abbrev sections */
1065 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1066 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1068 if (dwarf_line_section
)
1069 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1071 dwarf2_per_objfile
->line_buffer
= NULL
;
1073 if (dwarf_str_section
)
1074 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1076 dwarf2_per_objfile
->str_buffer
= NULL
;
1078 if (dwarf_macinfo_section
)
1079 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1080 dwarf_macinfo_section
);
1082 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1084 if (dwarf_ranges_section
)
1085 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1087 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1089 if (dwarf_loc_section
)
1090 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1092 dwarf2_per_objfile
->loc_buffer
= NULL
;
1095 || (objfile
->global_psymbols
.size
== 0
1096 && objfile
->static_psymbols
.size
== 0))
1098 init_psymbol_list (objfile
, 1024);
1102 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1104 /* Things are significantly easier if we have .debug_aranges and
1105 .debug_pubnames sections */
1107 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1111 /* only test this case for now */
1113 /* In this case we have to work a bit harder */
1114 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1119 /* Build the partial symbol table from the information in the
1120 .debug_pubnames and .debug_aranges sections. */
1123 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1125 bfd
*abfd
= objfile
->obfd
;
1126 char *aranges_buffer
, *pubnames_buffer
;
1127 char *aranges_ptr
, *pubnames_ptr
;
1128 unsigned int entry_length
, version
, info_offset
, info_size
;
1130 pubnames_buffer
= dwarf2_read_section (objfile
,
1131 dwarf_pubnames_section
);
1132 pubnames_ptr
= pubnames_buffer
;
1133 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1135 struct comp_unit_head cu_header
;
1138 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1140 pubnames_ptr
+= bytes_read
;
1141 version
= read_1_byte (abfd
, pubnames_ptr
);
1143 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1145 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1149 aranges_buffer
= dwarf2_read_section (objfile
,
1150 dwarf_aranges_section
);
1155 /* Read in the comp unit header information from the debug_info at
1159 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1160 char *info_ptr
, bfd
*abfd
)
1164 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1166 info_ptr
+= bytes_read
;
1167 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1169 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1171 info_ptr
+= bytes_read
;
1172 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1174 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1175 if (signed_addr
< 0)
1176 internal_error (__FILE__
, __LINE__
,
1177 "read_comp_unit_head: dwarf from non elf file");
1178 cu_header
->signed_addr_p
= signed_addr
;
1183 partial_read_comp_unit_head (struct comp_unit_head
*header
, char *info_ptr
,
1186 char *beg_of_comp_unit
= info_ptr
;
1188 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1190 if (header
->version
!= 2)
1191 error ("Dwarf Error: wrong version in compilation unit header "
1192 "(is %d, should be %d) [in module %s]", header
->version
,
1193 2, bfd_get_filename (abfd
));
1195 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1196 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1197 "(offset 0x%lx + 6) [in module %s]",
1198 (long) header
->abbrev_offset
,
1199 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1200 bfd_get_filename (abfd
));
1202 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1203 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1204 error ("Dwarf Error: bad length (0x%lx) in compilation unit header "
1205 "(offset 0x%lx + 0) [in module %s]",
1206 (long) header
->length
,
1207 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1208 bfd_get_filename (abfd
));
1213 /* Allocate a new partial symtab for file named NAME and mark this new
1214 partial symtab as being an include of PST. */
1217 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1218 struct objfile
*objfile
)
1220 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1222 subpst
->section_offsets
= pst
->section_offsets
;
1223 subpst
->textlow
= 0;
1224 subpst
->texthigh
= 0;
1226 subpst
->dependencies
= (struct partial_symtab
**)
1227 obstack_alloc (&objfile
->objfile_obstack
,
1228 sizeof (struct partial_symtab
*));
1229 subpst
->dependencies
[0] = pst
;
1230 subpst
->number_of_dependencies
= 1;
1232 subpst
->globals_offset
= 0;
1233 subpst
->n_global_syms
= 0;
1234 subpst
->statics_offset
= 0;
1235 subpst
->n_static_syms
= 0;
1236 subpst
->symtab
= NULL
;
1237 subpst
->read_symtab
= pst
->read_symtab
;
1240 /* No private part is necessary for include psymtabs. This property
1241 can be used to differentiate between such include psymtabs and
1242 the regular ones. If it ever happens that a regular psymtab can
1243 legitimally have a NULL private part, then we'll have to add a
1244 dedicated field for that in the dwarf2_pinfo structure. */
1245 subpst
->read_symtab_private
= NULL
;
1248 /* Read the Line Number Program data and extract the list of files
1249 included by the source file represented by PST. Build an include
1250 partial symtab for each of these included files.
1252 This procedure assumes that there *is* a Line Number Program in
1253 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1254 before calling this procedure. */
1257 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1258 struct partial_die_info
*pdi
,
1259 struct partial_symtab
*pst
)
1261 struct objfile
*objfile
= cu
->objfile
;
1262 bfd
*abfd
= objfile
->obfd
;
1263 struct line_header
*lh
;
1265 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1267 return; /* No linetable, so no includes. */
1269 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1271 free_line_header (lh
);
1275 /* Build the partial symbol table by doing a quick pass through the
1276 .debug_info and .debug_abbrev sections. */
1279 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1281 /* Instead of reading this into a big buffer, we should probably use
1282 mmap() on architectures that support it. (FIXME) */
1283 bfd
*abfd
= objfile
->obfd
;
1285 char *beg_of_comp_unit
;
1286 struct partial_die_info comp_unit_die
;
1287 struct partial_symtab
*pst
;
1288 CORE_ADDR lowpc
, highpc
, baseaddr
;
1290 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1292 /* Since the objects we're extracting from .debug_info vary in
1293 length, only the individual functions to extract them (like
1294 read_comp_unit_head and load_partial_die) can really know whether
1295 the buffer is large enough to hold another complete object.
1297 At the moment, they don't actually check that. If .debug_info
1298 holds just one extra byte after the last compilation unit's dies,
1299 then read_comp_unit_head will happily read off the end of the
1300 buffer. read_partial_die is similarly casual. Those functions
1303 For this loop condition, simply checking whether there's any data
1304 left at all should be sufficient. */
1305 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1306 + dwarf2_per_objfile
->info_size
))
1308 struct cleanup
*back_to_inner
;
1309 struct dwarf2_cu cu
;
1310 struct abbrev_info
*abbrev
;
1311 unsigned int bytes_read
;
1312 struct dwarf2_per_cu_data
*this_cu
;
1314 beg_of_comp_unit
= info_ptr
;
1316 memset (&cu
, 0, sizeof (cu
));
1318 obstack_init (&cu
.comp_unit_obstack
);
1320 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1322 cu
.objfile
= objfile
;
1323 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1325 /* Complete the cu_header */
1326 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1327 cu
.header
.first_die_ptr
= info_ptr
;
1328 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1330 cu
.list_in_scope
= &file_symbols
;
1332 cu
.partial_dies
= NULL
;
1334 /* Read the abbrevs for this compilation unit into a table */
1335 dwarf2_read_abbrevs (abfd
, &cu
);
1336 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1338 /* Read the compilation unit die */
1339 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1340 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1341 abfd
, info_ptr
, &cu
);
1343 /* Set the language we're debugging */
1344 set_cu_language (comp_unit_die
.language
, &cu
);
1346 /* Allocate a new partial symbol table structure */
1347 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1348 comp_unit_die
.name
? comp_unit_die
.name
: "",
1349 comp_unit_die
.lowpc
,
1350 objfile
->global_psymbols
.next
,
1351 objfile
->static_psymbols
.next
);
1353 if (comp_unit_die
.dirname
)
1354 pst
->dirname
= xstrdup (comp_unit_die
.dirname
);
1356 pst
->read_symtab_private
= (char *)
1357 obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct dwarf2_pinfo
));
1358 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1359 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1361 /* Store the function that reads in the rest of the symbol table */
1362 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1364 /* Check if comp unit has_children.
1365 If so, read the rest of the partial symbols from this comp unit.
1366 If not, there's no more debug_info for this comp unit. */
1367 if (comp_unit_die
.has_children
)
1369 struct partial_die_info
*first_die
;
1371 lowpc
= ((CORE_ADDR
) -1);
1372 highpc
= ((CORE_ADDR
) 0);
1374 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1376 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1378 /* If we didn't find a lowpc, set it to highpc to avoid
1379 complaints from `maint check'. */
1380 if (lowpc
== ((CORE_ADDR
) -1))
1383 /* If the compilation unit didn't have an explicit address range,
1384 then use the information extracted from its child dies. */
1385 if (! comp_unit_die
.has_pc_info
)
1387 comp_unit_die
.lowpc
= lowpc
;
1388 comp_unit_die
.highpc
= highpc
;
1391 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1392 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1394 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1395 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1396 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1397 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1398 sort_pst_symbols (pst
);
1400 /* If there is already a psymtab or symtab for a file of this
1401 name, remove it. (If there is a symtab, more drastic things
1402 also happen.) This happens in VxWorks. */
1403 free_named_symtabs (pst
->filename
);
1405 if (comp_unit_die
.has_stmt_list
)
1407 /* Get the list of files included in the current compilation unit,
1408 and build a psymtab for each of them. */
1409 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1412 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1413 + cu
.header
.initial_length_size
;
1415 do_cleanups (back_to_inner
);
1419 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1420 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1424 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1425 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1427 struct objfile
*objfile
= cu
->objfile
;
1428 bfd
*abfd
= objfile
->obfd
;
1429 struct partial_die_info
*pdi
;
1431 /* Now, march along the PDI's, descending into ones which have
1432 interesting children but skipping the children of the other ones,
1433 until we reach the end of the compilation unit. */
1439 fixup_partial_die (pdi
, cu
);
1441 /* Anonymous namespaces have no name but have interesting
1442 children, so we need to look at them. Ditto for anonymous
1445 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1446 || pdi
->tag
== DW_TAG_enumeration_type
)
1450 case DW_TAG_subprogram
:
1451 if (pdi
->has_pc_info
)
1453 if (pdi
->lowpc
< *lowpc
)
1455 *lowpc
= pdi
->lowpc
;
1457 if (pdi
->highpc
> *highpc
)
1459 *highpc
= pdi
->highpc
;
1461 if (!pdi
->is_declaration
)
1463 add_partial_symbol (pdi
, cu
);
1467 case DW_TAG_variable
:
1468 case DW_TAG_typedef
:
1469 case DW_TAG_union_type
:
1470 if (!pdi
->is_declaration
)
1472 add_partial_symbol (pdi
, cu
);
1475 case DW_TAG_class_type
:
1476 case DW_TAG_structure_type
:
1477 if (!pdi
->is_declaration
)
1479 add_partial_symbol (pdi
, cu
);
1482 case DW_TAG_enumeration_type
:
1483 if (!pdi
->is_declaration
)
1484 add_partial_enumeration (pdi
, cu
);
1486 case DW_TAG_base_type
:
1487 case DW_TAG_subrange_type
:
1488 /* File scope base type definitions are added to the partial
1490 add_partial_symbol (pdi
, cu
);
1492 case DW_TAG_namespace
:
1493 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1500 /* If the die has a sibling, skip to the sibling. */
1502 pdi
= pdi
->die_sibling
;
1506 /* Functions used to compute the fully scoped name of a partial DIE.
1508 Normally, this is simple. For C++, the parent DIE's fully scoped
1509 name is concatenated with "::" and the partial DIE's name.
1510 Enumerators are an exception; they use the scope of their parent
1511 enumeration type, i.e. the name of the enumeration type is not
1512 prepended to the enumerator.
1514 There are two complexities. One is DW_AT_specification; in this
1515 case "parent" means the parent of the target of the specification,
1516 instead of the direct parent of the DIE. The other is compilers
1517 which do not emit DW_TAG_namespace; in this case we try to guess
1518 the fully qualified name of structure types from their members'
1519 linkage names. This must be done using the DIE's children rather
1520 than the children of any DW_AT_specification target. We only need
1521 to do this for structures at the top level, i.e. if the target of
1522 any DW_AT_specification (if any; otherwise the DIE itself) does not
1525 /* Compute the scope prefix associated with PDI's parent, in
1526 compilation unit CU. The result will be allocated on CU's
1527 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1528 field. NULL is returned if no prefix is necessary. */
1530 partial_die_parent_scope (struct partial_die_info
*pdi
,
1531 struct dwarf2_cu
*cu
)
1533 char *grandparent_scope
;
1534 struct partial_die_info
*parent
, *real_pdi
;
1535 struct dwarf2_cu
*spec_cu
;
1537 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1538 then this means the parent of the specification DIE. */
1542 while (real_pdi
->has_specification
)
1543 real_pdi
= find_partial_die (real_pdi
->spec_offset
, spec_cu
, &spec_cu
);
1545 parent
= real_pdi
->die_parent
;
1549 if (parent
->scope_set
)
1550 return parent
->scope
;
1552 fixup_partial_die (parent
, cu
);
1554 grandparent_scope
= partial_die_parent_scope (parent
, spec_cu
);
1556 if (parent
->tag
== DW_TAG_namespace
1557 || parent
->tag
== DW_TAG_structure_type
1558 || parent
->tag
== DW_TAG_class_type
1559 || parent
->tag
== DW_TAG_union_type
)
1561 if (grandparent_scope
== NULL
)
1562 parent
->scope
= parent
->name
;
1564 parent
->scope
= obconcat (&cu
->comp_unit_obstack
, grandparent_scope
,
1565 "::", parent
->name
);
1567 else if (parent
->tag
== DW_TAG_enumeration_type
)
1568 /* Enumerators should not get the name of the enumeration as a prefix. */
1569 parent
->scope
= grandparent_scope
;
1572 /* FIXME drow/2004-04-01: What should we be doing with
1573 function-local names? For partial symbols, we should probably be
1575 complaint (&symfile_complaints
,
1576 "unhandled containing DIE tag %d for DIE at %d",
1577 parent
->tag
, pdi
->offset
);
1578 parent
->scope
= grandparent_scope
;
1581 parent
->scope_set
= 1;
1582 return parent
->scope
;
1585 /* Return the fully scoped name associated with PDI, from compilation unit
1586 CU. The result will be allocated with malloc. */
1588 partial_die_full_name (struct partial_die_info
*pdi
,
1589 struct dwarf2_cu
*cu
)
1593 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1594 if (parent_scope
== NULL
)
1597 return concat (parent_scope
, "::", pdi
->name
, NULL
);
1601 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1603 struct objfile
*objfile
= cu
->objfile
;
1606 const char *my_prefix
;
1607 const struct partial_symbol
*psym
= NULL
;
1609 int built_actual_name
= 0;
1611 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1615 if (pdi_needs_namespace (pdi
->tag
))
1617 actual_name
= partial_die_full_name (pdi
, cu
);
1619 built_actual_name
= 1;
1622 if (actual_name
== NULL
)
1623 actual_name
= pdi
->name
;
1627 case DW_TAG_subprogram
:
1628 if (pdi
->is_external
)
1630 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1631 mst_text, objfile); */
1632 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1633 VAR_DOMAIN
, LOC_BLOCK
,
1634 &objfile
->global_psymbols
,
1635 0, pdi
->lowpc
+ baseaddr
,
1636 cu
->language
, objfile
);
1640 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1641 mst_file_text, objfile); */
1642 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1643 VAR_DOMAIN
, LOC_BLOCK
,
1644 &objfile
->static_psymbols
,
1645 0, pdi
->lowpc
+ baseaddr
,
1646 cu
->language
, objfile
);
1649 case DW_TAG_variable
:
1650 if (pdi
->is_external
)
1653 Don't enter into the minimal symbol tables as there is
1654 a minimal symbol table entry from the ELF symbols already.
1655 Enter into partial symbol table if it has a location
1656 descriptor or a type.
1657 If the location descriptor is missing, new_symbol will create
1658 a LOC_UNRESOLVED symbol, the address of the variable will then
1659 be determined from the minimal symbol table whenever the variable
1661 The address for the partial symbol table entry is not
1662 used by GDB, but it comes in handy for debugging partial symbol
1666 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1667 if (pdi
->locdesc
|| pdi
->has_type
)
1668 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1669 VAR_DOMAIN
, LOC_STATIC
,
1670 &objfile
->global_psymbols
,
1672 cu
->language
, objfile
);
1676 /* Static Variable. Skip symbols without location descriptors. */
1677 if (pdi
->locdesc
== NULL
)
1679 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1680 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1681 mst_file_data, objfile); */
1682 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1683 VAR_DOMAIN
, LOC_STATIC
,
1684 &objfile
->static_psymbols
,
1686 cu
->language
, objfile
);
1689 case DW_TAG_typedef
:
1690 case DW_TAG_base_type
:
1691 case DW_TAG_subrange_type
:
1692 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1693 VAR_DOMAIN
, LOC_TYPEDEF
,
1694 &objfile
->static_psymbols
,
1695 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1697 case DW_TAG_namespace
:
1698 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1699 VAR_DOMAIN
, LOC_TYPEDEF
,
1700 &objfile
->global_psymbols
,
1701 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1703 case DW_TAG_class_type
:
1704 case DW_TAG_structure_type
:
1705 case DW_TAG_union_type
:
1706 case DW_TAG_enumeration_type
:
1707 /* Skip aggregate types without children, these are external
1709 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1710 static vs. global. */
1711 if (pdi
->has_children
== 0)
1713 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1714 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1715 cu
->language
== language_cplus
1716 ? &objfile
->global_psymbols
1717 : &objfile
->static_psymbols
,
1718 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1720 if (cu
->language
== language_cplus
)
1722 /* For C++, these implicitly act as typedefs as well. */
1723 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1724 VAR_DOMAIN
, LOC_TYPEDEF
,
1725 &objfile
->global_psymbols
,
1726 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1729 case DW_TAG_enumerator
:
1730 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1731 VAR_DOMAIN
, LOC_CONST
,
1732 cu
->language
== language_cplus
1733 ? &objfile
->global_psymbols
1734 : &objfile
->static_psymbols
,
1735 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1741 /* Check to see if we should scan the name for possible namespace
1742 info. Only do this if this is C++, if we don't have namespace
1743 debugging info in the file, if the psym is of an appropriate type
1744 (otherwise we'll have psym == NULL), and if we actually had a
1745 mangled name to begin with. */
1747 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
1748 cases which do not set PSYM above? */
1750 if (cu
->language
== language_cplus
1751 && cu
->has_namespace_info
== 0
1753 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
1754 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
1757 if (built_actual_name
)
1758 xfree (actual_name
);
1761 /* Determine whether a die of type TAG living in a C++ class or
1762 namespace needs to have the name of the scope prepended to the
1763 name listed in the die. */
1766 pdi_needs_namespace (enum dwarf_tag tag
)
1770 case DW_TAG_namespace
:
1771 case DW_TAG_typedef
:
1772 case DW_TAG_class_type
:
1773 case DW_TAG_structure_type
:
1774 case DW_TAG_union_type
:
1775 case DW_TAG_enumeration_type
:
1776 case DW_TAG_enumerator
:
1783 /* Read a partial die corresponding to a namespace; also, add a symbol
1784 corresponding to that namespace to the symbol table. NAMESPACE is
1785 the name of the enclosing namespace. */
1788 add_partial_namespace (struct partial_die_info
*pdi
,
1789 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1790 struct dwarf2_cu
*cu
)
1792 struct objfile
*objfile
= cu
->objfile
;
1794 /* Add a symbol for the namespace. */
1796 add_partial_symbol (pdi
, cu
);
1798 /* Now scan partial symbols in that namespace. */
1800 if (pdi
->has_children
)
1801 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
1804 /* See if we can figure out if the class lives in a namespace. We do
1805 this by looking for a member function; its demangled name will
1806 contain namespace info, if there is any. */
1809 guess_structure_name (struct partial_die_info
*struct_pdi
,
1810 struct dwarf2_cu
*cu
)
1812 if (cu
->language
== language_cplus
1813 && cu
->has_namespace_info
== 0
1814 && struct_pdi
->has_children
)
1816 /* NOTE: carlton/2003-10-07: Getting the info this way changes
1817 what template types look like, because the demangler
1818 frequently doesn't give the same name as the debug info. We
1819 could fix this by only using the demangled name to get the
1820 prefix (but see comment in read_structure_type). */
1822 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
1823 struct partial_die_info
*real_pdi
;
1824 struct dwarf2_cu
*spec_cu
;
1826 /* If this DIE (this DIE's specification, if any) has a parent, then
1827 we should not do this. We'll prepend the parent's fully qualified
1828 name when we create the partial symbol. */
1830 real_pdi
= struct_pdi
;
1832 while (real_pdi
->has_specification
)
1833 real_pdi
= find_partial_die (real_pdi
->spec_offset
, spec_cu
, &spec_cu
);
1835 if (real_pdi
->die_parent
!= NULL
)
1838 while (child_pdi
!= NULL
)
1840 if (child_pdi
->tag
== DW_TAG_subprogram
)
1842 char *actual_class_name
1843 = class_name_from_physname (child_pdi
->name
);
1844 if (actual_class_name
!= NULL
)
1847 = obsavestring (actual_class_name
,
1848 strlen (actual_class_name
),
1849 &cu
->comp_unit_obstack
);
1850 xfree (actual_class_name
);
1855 child_pdi
= child_pdi
->die_sibling
;
1860 /* Read a partial die corresponding to an enumeration type. */
1863 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1864 struct dwarf2_cu
*cu
)
1866 struct objfile
*objfile
= cu
->objfile
;
1867 bfd
*abfd
= objfile
->obfd
;
1868 struct partial_die_info
*pdi
;
1870 if (enum_pdi
->name
!= NULL
)
1871 add_partial_symbol (enum_pdi
, cu
);
1873 pdi
= enum_pdi
->die_child
;
1876 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
1877 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
1879 add_partial_symbol (pdi
, cu
);
1880 pdi
= pdi
->die_sibling
;
1884 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
1885 Return the corresponding abbrev, or NULL if the number is zero (indicating
1886 an empty DIE). In either case *BYTES_READ will be set to the length of
1887 the initial number. */
1889 static struct abbrev_info
*
1890 peek_die_abbrev (char *info_ptr
, int *bytes_read
, struct dwarf2_cu
*cu
)
1892 bfd
*abfd
= cu
->objfile
->obfd
;
1893 unsigned int abbrev_number
;
1894 struct abbrev_info
*abbrev
;
1896 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
1898 if (abbrev_number
== 0)
1901 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
1904 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
1905 bfd_get_filename (abfd
));
1911 /* Scan the debug information for CU starting at INFO_PTR. Returns a
1912 pointer to the end of a series of DIEs, terminated by an empty
1913 DIE. Any children of the skipped DIEs will also be skipped. */
1916 skip_children (char *info_ptr
, struct dwarf2_cu
*cu
)
1918 struct abbrev_info
*abbrev
;
1919 unsigned int bytes_read
;
1923 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1925 return info_ptr
+ bytes_read
;
1927 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
1931 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
1932 should point just after the initial uleb128 of a DIE, and the
1933 abbrev corresponding to that skipped uleb128 should be passed in
1934 ABBREV. Returns a pointer to this DIE's sibling, skipping any
1938 skip_one_die (char *info_ptr
, struct abbrev_info
*abbrev
,
1939 struct dwarf2_cu
*cu
)
1941 unsigned int bytes_read
;
1942 struct attribute attr
;
1943 bfd
*abfd
= cu
->objfile
->obfd
;
1944 unsigned int form
, i
;
1946 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
1948 /* The only abbrev we care about is DW_AT_sibling. */
1949 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
1951 read_attribute (&attr
, &abbrev
->attrs
[i
],
1952 abfd
, info_ptr
, cu
);
1953 if (attr
.form
== DW_FORM_ref_addr
)
1954 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
1956 return dwarf2_per_objfile
->info_buffer
1957 + dwarf2_get_ref_die_offset (&attr
, cu
);
1960 /* If it isn't DW_AT_sibling, skip this attribute. */
1961 form
= abbrev
->attrs
[i
].form
;
1966 case DW_FORM_ref_addr
:
1967 info_ptr
+= cu
->header
.addr_size
;
1986 case DW_FORM_string
:
1987 read_string (abfd
, info_ptr
, &bytes_read
);
1988 info_ptr
+= bytes_read
;
1991 info_ptr
+= cu
->header
.offset_size
;
1994 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
1995 info_ptr
+= bytes_read
;
1997 case DW_FORM_block1
:
1998 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2000 case DW_FORM_block2
:
2001 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2003 case DW_FORM_block4
:
2004 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2008 case DW_FORM_ref_udata
:
2009 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2011 case DW_FORM_indirect
:
2012 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2013 info_ptr
+= bytes_read
;
2014 /* We need to continue parsing from here, so just go back to
2016 goto skip_attribute
;
2019 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
2020 dwarf_form_name (form
),
2021 bfd_get_filename (abfd
));
2025 if (abbrev
->has_children
)
2026 return skip_children (info_ptr
, cu
);
2031 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2032 the next DIE after ORIG_PDI. */
2035 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, char *info_ptr
,
2036 bfd
*abfd
, struct dwarf2_cu
*cu
)
2038 /* Do we know the sibling already? */
2040 if (orig_pdi
->sibling
)
2041 return orig_pdi
->sibling
;
2043 /* Are there any children to deal with? */
2045 if (!orig_pdi
->has_children
)
2048 /* Skip the children the long way. */
2050 return skip_children (info_ptr
, cu
);
2053 /* Expand this partial symbol table into a full symbol table. */
2056 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2058 /* FIXME: This is barely more than a stub. */
2063 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
2069 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
2070 gdb_flush (gdb_stdout
);
2073 psymtab_to_symtab_1 (pst
);
2075 /* Finish up the debug error message. */
2077 printf_filtered ("done.\n");
2083 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2085 struct objfile
*objfile
= pst
->objfile
;
2086 bfd
*abfd
= objfile
->obfd
;
2087 struct dwarf2_cu cu
;
2088 struct die_info
*dies
;
2089 unsigned long offset
;
2090 CORE_ADDR lowpc
, highpc
;
2091 struct die_info
*child_die
;
2093 struct symtab
*symtab
;
2094 struct cleanup
*back_to
;
2095 struct attribute
*attr
;
2099 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2100 if (!pst
->dependencies
[i
]->readin
)
2102 /* Inform about additional files that need to be read in. */
2105 fputs_filtered (" ", gdb_stdout
);
2107 fputs_filtered ("and ", gdb_stdout
);
2109 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2110 wrap_here (""); /* Flush output */
2111 gdb_flush (gdb_stdout
);
2113 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2116 if (pst
->read_symtab_private
== NULL
)
2118 /* It's an include file, no symbols to read for it.
2119 Everything is in the parent symtab. */
2124 dwarf2_per_objfile
= objfile_data (pst
->objfile
, dwarf2_objfile_data_key
);
2126 /* Set local variables from the partial symbol table info. */
2127 offset
= DWARF_INFO_OFFSET (pst
);
2129 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2130 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2132 /* We're in the global namespace. */
2133 processing_current_prefix
= "";
2135 obstack_init (&cu
.comp_unit_obstack
);
2136 back_to
= make_cleanup (free_stack_comp_unit
, &cu
);
2139 make_cleanup (really_free_pendings
, NULL
);
2141 cu
.objfile
= objfile
;
2143 /* read in the comp_unit header */
2144 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
2146 /* Read the abbrevs for this compilation unit */
2147 dwarf2_read_abbrevs (abfd
, &cu
);
2148 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2150 cu
.header
.offset
= offset
;
2152 cu
.list_in_scope
= &file_symbols
;
2154 dies
= read_comp_unit (info_ptr
, abfd
, &cu
);
2156 make_cleanup_free_die_list (dies
);
2158 /* Find the base address of the compilation unit for range lists and
2159 location lists. It will normally be specified by DW_AT_low_pc.
2160 In DWARF-3 draft 4, the base address could be overridden by
2161 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2162 compilation units with discontinuous ranges. */
2164 cu
.header
.base_known
= 0;
2165 cu
.header
.base_address
= 0;
2167 attr
= dwarf2_attr (dies
, DW_AT_entry_pc
, &cu
);
2170 cu
.header
.base_address
= DW_ADDR (attr
);
2171 cu
.header
.base_known
= 1;
2175 attr
= dwarf2_attr (dies
, DW_AT_low_pc
, &cu
);
2178 cu
.header
.base_address
= DW_ADDR (attr
);
2179 cu
.header
.base_known
= 1;
2183 /* Do line number decoding in read_file_scope () */
2184 process_die (dies
, &cu
);
2186 /* Some compilers don't define a DW_AT_high_pc attribute for the
2187 compilation unit. If the DW_AT_high_pc is missing, synthesize
2188 it, by scanning the DIE's below the compilation unit. */
2189 get_scope_pc_bounds (dies
, &lowpc
, &highpc
, &cu
);
2191 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2193 /* Set symtab language to language from DW_AT_language.
2194 If the compilation is from a C file generated by language preprocessors,
2195 do not set the language if it was already deduced by start_subfile. */
2197 && !(cu
.language
== language_c
&& symtab
->language
!= language_c
))
2199 symtab
->language
= cu
.language
;
2201 pst
->symtab
= symtab
;
2204 do_cleanups (back_to
);
2207 /* Process a die and its children. */
2210 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2214 case DW_TAG_padding
:
2216 case DW_TAG_compile_unit
:
2217 read_file_scope (die
, cu
);
2219 case DW_TAG_subprogram
:
2220 read_subroutine_type (die
, cu
);
2221 read_func_scope (die
, cu
);
2223 case DW_TAG_inlined_subroutine
:
2224 /* FIXME: These are ignored for now.
2225 They could be used to set breakpoints on all inlined instances
2226 of a function and make GDB `next' properly over inlined functions. */
2228 case DW_TAG_lexical_block
:
2229 case DW_TAG_try_block
:
2230 case DW_TAG_catch_block
:
2231 read_lexical_block_scope (die
, cu
);
2233 case DW_TAG_class_type
:
2234 case DW_TAG_structure_type
:
2235 case DW_TAG_union_type
:
2236 read_structure_type (die
, cu
);
2237 process_structure_scope (die
, cu
);
2239 case DW_TAG_enumeration_type
:
2240 read_enumeration_type (die
, cu
);
2241 process_enumeration_scope (die
, cu
);
2244 /* FIXME drow/2004-03-14: These initialize die->type, but do not create
2245 a symbol or process any children. Therefore it doesn't do anything
2246 that won't be done on-demand by read_type_die. */
2247 case DW_TAG_subroutine_type
:
2248 read_subroutine_type (die
, cu
);
2250 case DW_TAG_array_type
:
2251 read_array_type (die
, cu
);
2253 case DW_TAG_pointer_type
:
2254 read_tag_pointer_type (die
, cu
);
2256 case DW_TAG_ptr_to_member_type
:
2257 read_tag_ptr_to_member_type (die
, cu
);
2259 case DW_TAG_reference_type
:
2260 read_tag_reference_type (die
, cu
);
2262 case DW_TAG_string_type
:
2263 read_tag_string_type (die
, cu
);
2267 case DW_TAG_base_type
:
2268 read_base_type (die
, cu
);
2269 /* Add a typedef symbol for the type definition, if it has a
2271 new_symbol (die
, die
->type
, cu
);
2273 case DW_TAG_subrange_type
:
2274 read_subrange_type (die
, cu
);
2275 /* Add a typedef symbol for the type definition, if it has a
2277 new_symbol (die
, die
->type
, cu
);
2279 case DW_TAG_common_block
:
2280 read_common_block (die
, cu
);
2282 case DW_TAG_common_inclusion
:
2284 case DW_TAG_namespace
:
2285 processing_has_namespace_info
= 1;
2286 read_namespace (die
, cu
);
2288 case DW_TAG_imported_declaration
:
2289 case DW_TAG_imported_module
:
2290 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2291 information contained in these. DW_TAG_imported_declaration
2292 dies shouldn't have children; DW_TAG_imported_module dies
2293 shouldn't in the C++ case, but conceivably could in the
2294 Fortran case, so we'll have to replace this gdb_assert if
2295 Fortran compilers start generating that info. */
2296 processing_has_namespace_info
= 1;
2297 gdb_assert (die
->child
== NULL
);
2300 new_symbol (die
, NULL
, cu
);
2306 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2308 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2312 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2314 struct objfile
*objfile
= cu
->objfile
;
2315 struct comp_unit_head
*cu_header
= &cu
->header
;
2316 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2317 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2318 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2319 struct attribute
*attr
;
2320 char *name
= "<unknown>";
2321 char *comp_dir
= NULL
;
2322 struct die_info
*child_die
;
2323 bfd
*abfd
= objfile
->obfd
;
2324 struct line_header
*line_header
= 0;
2327 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2329 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2331 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2332 from finish_block. */
2333 if (lowpc
== ((CORE_ADDR
) -1))
2338 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2341 name
= DW_STRING (attr
);
2343 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2346 comp_dir
= DW_STRING (attr
);
2349 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2350 directory, get rid of it. */
2351 char *cp
= strchr (comp_dir
, ':');
2353 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2358 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2361 set_cu_language (DW_UNSND (attr
), cu
);
2364 /* We assume that we're processing GCC output. */
2365 processing_gcc_compilation
= 2;
2367 /* FIXME:Do something here. */
2368 if (dip
->at_producer
!= NULL
)
2370 handle_producer (dip
->at_producer
);
2374 /* The compilation unit may be in a different language or objfile,
2375 zero out all remembered fundamental types. */
2376 memset (cu
->ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
2378 start_symtab (name
, comp_dir
, lowpc
);
2379 record_debugformat ("DWARF 2");
2381 initialize_cu_func_list (cu
);
2383 /* Process all dies in compilation unit. */
2384 if (die
->child
!= NULL
)
2386 child_die
= die
->child
;
2387 while (child_die
&& child_die
->tag
)
2389 process_die (child_die
, cu
);
2390 child_die
= sibling_die (child_die
);
2394 /* Decode line number information if present. */
2395 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2398 unsigned int line_offset
= DW_UNSND (attr
);
2399 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2402 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
2403 (void *) line_header
);
2404 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2408 /* Decode macro information, if present. Dwarf 2 macro information
2409 refers to information in the line number info statement program
2410 header, so we can only read it if we've read the header
2412 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2413 if (attr
&& line_header
)
2415 unsigned int macro_offset
= DW_UNSND (attr
);
2416 dwarf_decode_macros (line_header
, macro_offset
,
2417 comp_dir
, abfd
, cu
);
2419 do_cleanups (back_to
);
2423 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2424 struct dwarf2_cu
*cu
)
2426 struct function_range
*thisfn
;
2428 thisfn
= (struct function_range
*)
2429 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
2430 thisfn
->name
= name
;
2431 thisfn
->lowpc
= lowpc
;
2432 thisfn
->highpc
= highpc
;
2433 thisfn
->seen_line
= 0;
2434 thisfn
->next
= NULL
;
2436 if (cu
->last_fn
== NULL
)
2437 cu
->first_fn
= thisfn
;
2439 cu
->last_fn
->next
= thisfn
;
2441 cu
->last_fn
= thisfn
;
2445 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2447 struct objfile
*objfile
= cu
->objfile
;
2448 struct context_stack
*new;
2451 struct die_info
*child_die
;
2452 struct attribute
*attr
;
2454 const char *previous_prefix
= processing_current_prefix
;
2455 struct cleanup
*back_to
= NULL
;
2458 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2460 name
= dwarf2_linkage_name (die
, cu
);
2462 /* Ignore functions with missing or empty names and functions with
2463 missing or invalid low and high pc attributes. */
2464 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2467 if (cu
->language
== language_cplus
)
2469 struct die_info
*spec_die
= die_specification (die
, cu
);
2471 /* NOTE: carlton/2004-01-23: We have to be careful in the
2472 presence of DW_AT_specification. For example, with GCC 3.4,
2477 // Definition of N::foo.
2481 then we'll have a tree of DIEs like this:
2483 1: DW_TAG_compile_unit
2484 2: DW_TAG_namespace // N
2485 3: DW_TAG_subprogram // declaration of N::foo
2486 4: DW_TAG_subprogram // definition of N::foo
2487 DW_AT_specification // refers to die #3
2489 Thus, when processing die #4, we have to pretend that we're
2490 in the context of its DW_AT_specification, namely the contex
2493 if (spec_die
!= NULL
)
2495 char *specification_prefix
= determine_prefix (spec_die
, cu
);
2496 processing_current_prefix
= specification_prefix
;
2497 back_to
= make_cleanup (xfree
, specification_prefix
);
2504 /* Record the function range for dwarf_decode_lines. */
2505 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
2507 if (objfile
->ei
.entry_point
>= lowpc
&&
2508 objfile
->ei
.entry_point
< highpc
)
2510 objfile
->ei
.entry_func_lowpc
= lowpc
;
2511 objfile
->ei
.entry_func_highpc
= highpc
;
2514 new = push_context (0, lowpc
);
2515 new->name
= new_symbol (die
, die
->type
, cu
);
2517 /* If there is a location expression for DW_AT_frame_base, record
2519 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
2521 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2522 expression is being recorded directly in the function's symbol
2523 and not in a separate frame-base object. I guess this hack is
2524 to avoid adding some sort of frame-base adjunct/annex to the
2525 function's symbol :-(. The problem with doing this is that it
2526 results in a function symbol with a location expression that
2527 has nothing to do with the location of the function, ouch! The
2528 relationship should be: a function's symbol has-a frame base; a
2529 frame-base has-a location expression. */
2530 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
2532 cu
->list_in_scope
= &local_symbols
;
2534 if (die
->child
!= NULL
)
2536 child_die
= die
->child
;
2537 while (child_die
&& child_die
->tag
)
2539 process_die (child_die
, cu
);
2540 child_die
= sibling_die (child_die
);
2544 new = pop_context ();
2545 /* Make a block for the local symbols within. */
2546 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2547 lowpc
, highpc
, objfile
);
2549 /* In C++, we can have functions nested inside functions (e.g., when
2550 a function declares a class that has methods). This means that
2551 when we finish processing a function scope, we may need to go
2552 back to building a containing block's symbol lists. */
2553 local_symbols
= new->locals
;
2554 param_symbols
= new->params
;
2556 /* If we've finished processing a top-level function, subsequent
2557 symbols go in the file symbol list. */
2558 if (outermost_context_p ())
2559 cu
->list_in_scope
= &file_symbols
;
2561 processing_current_prefix
= previous_prefix
;
2562 if (back_to
!= NULL
)
2563 do_cleanups (back_to
);
2566 /* Process all the DIES contained within a lexical block scope. Start
2567 a new scope, process the dies, and then close the scope. */
2570 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2572 struct objfile
*objfile
= cu
->objfile
;
2573 struct context_stack
*new;
2574 CORE_ADDR lowpc
, highpc
;
2575 struct die_info
*child_die
;
2578 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2580 /* Ignore blocks with missing or invalid low and high pc attributes. */
2581 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2582 as multiple lexical blocks? Handling children in a sane way would
2583 be nasty. Might be easier to properly extend generic blocks to
2585 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2590 push_context (0, lowpc
);
2591 if (die
->child
!= NULL
)
2593 child_die
= die
->child
;
2594 while (child_die
&& child_die
->tag
)
2596 process_die (child_die
, cu
);
2597 child_die
= sibling_die (child_die
);
2600 new = pop_context ();
2602 if (local_symbols
!= NULL
)
2604 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2607 local_symbols
= new->locals
;
2610 /* Get low and high pc attributes from a die. Return 1 if the attributes
2611 are present and valid, otherwise, return 0. Return -1 if the range is
2612 discontinuous, i.e. derived from DW_AT_ranges information. */
2614 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2615 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
2617 struct objfile
*objfile
= cu
->objfile
;
2618 struct comp_unit_head
*cu_header
= &cu
->header
;
2619 struct attribute
*attr
;
2620 bfd
*obfd
= objfile
->obfd
;
2625 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
2628 high
= DW_ADDR (attr
);
2629 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
2631 low
= DW_ADDR (attr
);
2633 /* Found high w/o low attribute. */
2636 /* Found consecutive range of addresses. */
2641 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
2644 unsigned int addr_size
= cu_header
->addr_size
;
2645 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2646 /* Value of the DW_AT_ranges attribute is the offset in the
2647 .debug_ranges section. */
2648 unsigned int offset
= DW_UNSND (attr
);
2649 /* Base address selection entry. */
2657 found_base
= cu_header
->base_known
;
2658 base
= cu_header
->base_address
;
2660 if (offset
>= dwarf2_per_objfile
->ranges_size
)
2662 complaint (&symfile_complaints
,
2663 "Offset %d out of bounds for DW_AT_ranges attribute",
2667 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
2669 /* Read in the largest possible address. */
2670 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
2671 if ((marker
& mask
) == mask
)
2673 /* If we found the largest possible address, then
2674 read the base address. */
2675 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2676 buffer
+= 2 * addr_size
;
2677 offset
+= 2 * addr_size
;
2685 CORE_ADDR range_beginning
, range_end
;
2687 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
2688 buffer
+= addr_size
;
2689 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
2690 buffer
+= addr_size
;
2691 offset
+= 2 * addr_size
;
2693 /* An end of list marker is a pair of zero addresses. */
2694 if (range_beginning
== 0 && range_end
== 0)
2695 /* Found the end of list entry. */
2698 /* Each base address selection entry is a pair of 2 values.
2699 The first is the largest possible address, the second is
2700 the base address. Check for a base address here. */
2701 if ((range_beginning
& mask
) == mask
)
2703 /* If we found the largest possible address, then
2704 read the base address. */
2705 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2712 /* We have no valid base address for the ranges
2714 complaint (&symfile_complaints
,
2715 "Invalid .debug_ranges data (no base address)");
2719 range_beginning
+= base
;
2722 /* FIXME: This is recording everything as a low-high
2723 segment of consecutive addresses. We should have a
2724 data structure for discontiguous block ranges
2728 low
= range_beginning
;
2734 if (range_beginning
< low
)
2735 low
= range_beginning
;
2736 if (range_end
> high
)
2742 /* If the first entry is an end-of-list marker, the range
2743 describes an empty scope, i.e. no instructions. */
2753 /* When using the GNU linker, .gnu.linkonce. sections are used to
2754 eliminate duplicate copies of functions and vtables and such.
2755 The linker will arbitrarily choose one and discard the others.
2756 The AT_*_pc values for such functions refer to local labels in
2757 these sections. If the section from that file was discarded, the
2758 labels are not in the output, so the relocs get a value of 0.
2759 If this is a discarded function, mark the pc bounds as invalid,
2760 so that GDB will ignore it. */
2761 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
2769 /* Get the low and high pc's represented by the scope DIE, and store
2770 them in *LOWPC and *HIGHPC. If the correct values can't be
2771 determined, set *LOWPC to -1 and *HIGHPC to 0. */
2774 get_scope_pc_bounds (struct die_info
*die
,
2775 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2776 struct dwarf2_cu
*cu
)
2778 CORE_ADDR best_low
= (CORE_ADDR
) -1;
2779 CORE_ADDR best_high
= (CORE_ADDR
) 0;
2780 CORE_ADDR current_low
, current_high
;
2782 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
2784 best_low
= current_low
;
2785 best_high
= current_high
;
2789 struct die_info
*child
= die
->child
;
2791 while (child
&& child
->tag
)
2793 switch (child
->tag
) {
2794 case DW_TAG_subprogram
:
2795 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
2797 best_low
= min (best_low
, current_low
);
2798 best_high
= max (best_high
, current_high
);
2801 case DW_TAG_namespace
:
2802 /* FIXME: carlton/2004-01-16: Should we do this for
2803 DW_TAG_class_type/DW_TAG_structure_type, too? I think
2804 that current GCC's always emit the DIEs corresponding
2805 to definitions of methods of classes as children of a
2806 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
2807 the DIEs giving the declarations, which could be
2808 anywhere). But I don't see any reason why the
2809 standards says that they have to be there. */
2810 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
2812 if (current_low
!= ((CORE_ADDR
) -1))
2814 best_low
= min (best_low
, current_low
);
2815 best_high
= max (best_high
, current_high
);
2823 child
= sibling_die (child
);
2828 *highpc
= best_high
;
2831 /* Add an aggregate field to the field list. */
2834 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2835 struct dwarf2_cu
*cu
)
2837 struct objfile
*objfile
= cu
->objfile
;
2838 struct nextfield
*new_field
;
2839 struct attribute
*attr
;
2841 char *fieldname
= "";
2843 /* Allocate a new field list entry and link it in. */
2844 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2845 make_cleanup (xfree
, new_field
);
2846 memset (new_field
, 0, sizeof (struct nextfield
));
2847 new_field
->next
= fip
->fields
;
2848 fip
->fields
= new_field
;
2851 /* Handle accessibility and virtuality of field.
2852 The default accessibility for members is public, the default
2853 accessibility for inheritance is private. */
2854 if (die
->tag
!= DW_TAG_inheritance
)
2855 new_field
->accessibility
= DW_ACCESS_public
;
2857 new_field
->accessibility
= DW_ACCESS_private
;
2858 new_field
->virtuality
= DW_VIRTUALITY_none
;
2860 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
2862 new_field
->accessibility
= DW_UNSND (attr
);
2863 if (new_field
->accessibility
!= DW_ACCESS_public
)
2864 fip
->non_public_fields
= 1;
2865 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
2867 new_field
->virtuality
= DW_UNSND (attr
);
2869 fp
= &new_field
->field
;
2871 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
2873 /* Data member other than a C++ static data member. */
2875 /* Get type of field. */
2876 fp
->type
= die_type (die
, cu
);
2878 FIELD_STATIC_KIND (*fp
) = 0;
2880 /* Get bit size of field (zero if none). */
2881 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
2884 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2888 FIELD_BITSIZE (*fp
) = 0;
2891 /* Get bit offset of field. */
2892 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
2895 FIELD_BITPOS (*fp
) =
2896 decode_locdesc (DW_BLOCK (attr
), cu
) * bits_per_byte
;
2899 FIELD_BITPOS (*fp
) = 0;
2900 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
2903 if (BITS_BIG_ENDIAN
)
2905 /* For big endian bits, the DW_AT_bit_offset gives the
2906 additional bit offset from the MSB of the containing
2907 anonymous object to the MSB of the field. We don't
2908 have to do anything special since we don't need to
2909 know the size of the anonymous object. */
2910 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2914 /* For little endian bits, compute the bit offset to the
2915 MSB of the anonymous object, subtract off the number of
2916 bits from the MSB of the field to the MSB of the
2917 object, and then subtract off the number of bits of
2918 the field itself. The result is the bit offset of
2919 the LSB of the field. */
2921 int bit_offset
= DW_UNSND (attr
);
2923 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
2926 /* The size of the anonymous object containing
2927 the bit field is explicit, so use the
2928 indicated size (in bytes). */
2929 anonymous_size
= DW_UNSND (attr
);
2933 /* The size of the anonymous object containing
2934 the bit field must be inferred from the type
2935 attribute of the data member containing the
2937 anonymous_size
= TYPE_LENGTH (fp
->type
);
2939 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2940 - bit_offset
- FIELD_BITSIZE (*fp
);
2944 /* Get name of field. */
2945 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2946 if (attr
&& DW_STRING (attr
))
2947 fieldname
= DW_STRING (attr
);
2949 /* The name is already allocated along with this objfile, so we don't
2950 need to duplicate it for the type. */
2951 fp
->name
= fieldname
;
2953 /* Change accessibility for artificial fields (e.g. virtual table
2954 pointer or virtual base class pointer) to private. */
2955 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
2957 new_field
->accessibility
= DW_ACCESS_private
;
2958 fip
->non_public_fields
= 1;
2961 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
2963 /* C++ static member. */
2965 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2966 is a declaration, but all versions of G++ as of this writing
2967 (so through at least 3.2.1) incorrectly generate
2968 DW_TAG_variable tags. */
2972 /* Get name of field. */
2973 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2974 if (attr
&& DW_STRING (attr
))
2975 fieldname
= DW_STRING (attr
);
2979 /* Get physical name. */
2980 physname
= dwarf2_linkage_name (die
, cu
);
2982 /* The name is already allocated along with this objfile, so we don't
2983 need to duplicate it for the type. */
2984 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
2985 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2986 FIELD_NAME (*fp
) = fieldname
;
2988 else if (die
->tag
== DW_TAG_inheritance
)
2990 /* C++ base class field. */
2991 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
2993 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
2995 FIELD_BITSIZE (*fp
) = 0;
2996 FIELD_STATIC_KIND (*fp
) = 0;
2997 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2998 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2999 fip
->nbaseclasses
++;
3003 /* Create the vector of fields, and attach it to the type. */
3006 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3007 struct dwarf2_cu
*cu
)
3009 int nfields
= fip
->nfields
;
3011 /* Record the field count, allocate space for the array of fields,
3012 and create blank accessibility bitfields if necessary. */
3013 TYPE_NFIELDS (type
) = nfields
;
3014 TYPE_FIELDS (type
) = (struct field
*)
3015 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3016 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3018 if (fip
->non_public_fields
)
3020 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3022 TYPE_FIELD_PRIVATE_BITS (type
) =
3023 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3024 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3026 TYPE_FIELD_PROTECTED_BITS (type
) =
3027 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3028 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3030 TYPE_FIELD_IGNORE_BITS (type
) =
3031 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3032 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3035 /* If the type has baseclasses, allocate and clear a bit vector for
3036 TYPE_FIELD_VIRTUAL_BITS. */
3037 if (fip
->nbaseclasses
)
3039 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3042 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3043 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
3044 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
3045 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3046 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3049 /* Copy the saved-up fields into the field vector. Start from the head
3050 of the list, adding to the tail of the field array, so that they end
3051 up in the same order in the array in which they were added to the list. */
3052 while (nfields
-- > 0)
3054 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3055 switch (fip
->fields
->accessibility
)
3057 case DW_ACCESS_private
:
3058 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3061 case DW_ACCESS_protected
:
3062 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3065 case DW_ACCESS_public
:
3069 /* Unknown accessibility. Complain and treat it as public. */
3071 complaint (&symfile_complaints
, "unsupported accessibility %d",
3072 fip
->fields
->accessibility
);
3076 if (nfields
< fip
->nbaseclasses
)
3078 switch (fip
->fields
->virtuality
)
3080 case DW_VIRTUALITY_virtual
:
3081 case DW_VIRTUALITY_pure_virtual
:
3082 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3086 fip
->fields
= fip
->fields
->next
;
3090 /* Add a member function to the proper fieldlist. */
3093 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3094 struct type
*type
, struct dwarf2_cu
*cu
)
3096 struct objfile
*objfile
= cu
->objfile
;
3097 struct attribute
*attr
;
3098 struct fnfieldlist
*flp
;
3100 struct fn_field
*fnp
;
3103 struct nextfnfield
*new_fnfield
;
3105 /* Get name of member function. */
3106 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3107 if (attr
&& DW_STRING (attr
))
3108 fieldname
= DW_STRING (attr
);
3112 /* Get the mangled name. */
3113 physname
= dwarf2_linkage_name (die
, cu
);
3115 /* Look up member function name in fieldlist. */
3116 for (i
= 0; i
< fip
->nfnfields
; i
++)
3118 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3122 /* Create new list element if necessary. */
3123 if (i
< fip
->nfnfields
)
3124 flp
= &fip
->fnfieldlists
[i
];
3127 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3129 fip
->fnfieldlists
= (struct fnfieldlist
*)
3130 xrealloc (fip
->fnfieldlists
,
3131 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3132 * sizeof (struct fnfieldlist
));
3133 if (fip
->nfnfields
== 0)
3134 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3136 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3137 flp
->name
= fieldname
;
3143 /* Create a new member function field and chain it to the field list
3145 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3146 make_cleanup (xfree
, new_fnfield
);
3147 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3148 new_fnfield
->next
= flp
->head
;
3149 flp
->head
= new_fnfield
;
3152 /* Fill in the member function field info. */
3153 fnp
= &new_fnfield
->fnfield
;
3154 /* The name is already allocated along with this objfile, so we don't
3155 need to duplicate it for the type. */
3156 fnp
->physname
= physname
? physname
: "";
3157 fnp
->type
= alloc_type (objfile
);
3158 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
3160 int nparams
= TYPE_NFIELDS (die
->type
);
3162 /* TYPE is the domain of this method, and DIE->TYPE is the type
3163 of the method itself (TYPE_CODE_METHOD). */
3164 smash_to_method_type (fnp
->type
, type
,
3165 TYPE_TARGET_TYPE (die
->type
),
3166 TYPE_FIELDS (die
->type
),
3167 TYPE_NFIELDS (die
->type
),
3168 TYPE_VARARGS (die
->type
));
3170 /* Handle static member functions.
3171 Dwarf2 has no clean way to discern C++ static and non-static
3172 member functions. G++ helps GDB by marking the first
3173 parameter for non-static member functions (which is the
3174 this pointer) as artificial. We obtain this information
3175 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3176 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
3177 fnp
->voffset
= VOFFSET_STATIC
;
3180 complaint (&symfile_complaints
, "member function type missing for '%s'",
3183 /* Get fcontext from DW_AT_containing_type if present. */
3184 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3185 fnp
->fcontext
= die_containing_type (die
, cu
);
3187 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3188 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3190 /* Get accessibility. */
3191 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3194 switch (DW_UNSND (attr
))
3196 case DW_ACCESS_private
:
3197 fnp
->is_private
= 1;
3199 case DW_ACCESS_protected
:
3200 fnp
->is_protected
= 1;
3205 /* Check for artificial methods. */
3206 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3207 if (attr
&& DW_UNSND (attr
) != 0)
3208 fnp
->is_artificial
= 1;
3210 /* Get index in virtual function table if it is a virtual member function. */
3211 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3214 /* Support the .debug_loc offsets */
3215 if (attr_form_is_block (attr
))
3217 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3219 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3221 dwarf2_complex_location_expr_complaint ();
3225 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3231 /* Create the vector of member function fields, and attach it to the type. */
3234 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3235 struct dwarf2_cu
*cu
)
3237 struct fnfieldlist
*flp
;
3238 int total_length
= 0;
3241 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3242 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3243 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3245 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3247 struct nextfnfield
*nfp
= flp
->head
;
3248 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3251 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3252 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3253 fn_flp
->fn_fields
= (struct fn_field
*)
3254 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3255 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3256 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3258 total_length
+= flp
->length
;
3261 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3262 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3265 /* Called when we find the DIE that starts a structure or union scope
3266 (definition) to process all dies that define the members of the
3269 NOTE: we need to call struct_type regardless of whether or not the
3270 DIE has an at_name attribute, since it might be an anonymous
3271 structure or union. This gets the type entered into our set of
3274 However, if the structure is incomplete (an opaque struct/union)
3275 then suppress creating a symbol table entry for it since gdb only
3276 wants to find the one with the complete definition. Note that if
3277 it is complete, we just call new_symbol, which does it's own
3278 checking about whether the struct/union is anonymous or not (and
3279 suppresses creating a symbol table entry itself). */
3282 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3284 struct objfile
*objfile
= cu
->objfile
;
3286 struct attribute
*attr
;
3287 const char *previous_prefix
= processing_current_prefix
;
3288 struct cleanup
*back_to
= NULL
;
3293 type
= alloc_type (objfile
);
3295 INIT_CPLUS_SPECIFIC (type
);
3296 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3297 if (attr
&& DW_STRING (attr
))
3299 if (cu
->language
== language_cplus
)
3301 char *new_prefix
= determine_class_name (die
, cu
);
3302 TYPE_TAG_NAME (type
) = obsavestring (new_prefix
,
3303 strlen (new_prefix
),
3304 &objfile
->objfile_obstack
);
3305 back_to
= make_cleanup (xfree
, new_prefix
);
3306 processing_current_prefix
= new_prefix
;
3310 /* The name is already allocated along with this objfile, so
3311 we don't need to duplicate it for the type. */
3312 TYPE_TAG_NAME (type
) = DW_STRING (attr
);
3316 if (die
->tag
== DW_TAG_structure_type
)
3318 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
3320 else if (die
->tag
== DW_TAG_union_type
)
3322 TYPE_CODE (type
) = TYPE_CODE_UNION
;
3326 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
3328 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
3331 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3334 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3338 TYPE_LENGTH (type
) = 0;
3341 if (die_is_declaration (die
, cu
))
3342 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
3344 /* We need to add the type field to the die immediately so we don't
3345 infinitely recurse when dealing with pointers to the structure
3346 type within the structure itself. */
3349 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3351 struct field_info fi
;
3352 struct die_info
*child_die
;
3353 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
3355 memset (&fi
, 0, sizeof (struct field_info
));
3357 child_die
= die
->child
;
3359 while (child_die
&& child_die
->tag
)
3361 if (child_die
->tag
== DW_TAG_member
3362 || child_die
->tag
== DW_TAG_variable
)
3364 /* NOTE: carlton/2002-11-05: A C++ static data member
3365 should be a DW_TAG_member that is a declaration, but
3366 all versions of G++ as of this writing (so through at
3367 least 3.2.1) incorrectly generate DW_TAG_variable
3368 tags for them instead. */
3369 dwarf2_add_field (&fi
, child_die
, cu
);
3371 else if (child_die
->tag
== DW_TAG_subprogram
)
3373 /* C++ member function. */
3374 read_type_die (child_die
, cu
);
3375 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
3377 else if (child_die
->tag
== DW_TAG_inheritance
)
3379 /* C++ base class field. */
3380 dwarf2_add_field (&fi
, child_die
, cu
);
3382 child_die
= sibling_die (child_die
);
3385 /* Attach fields and member functions to the type. */
3387 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
3390 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
3392 /* Get the type which refers to the base class (possibly this
3393 class itself) which contains the vtable pointer for the current
3394 class from the DW_AT_containing_type attribute. */
3396 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3398 struct type
*t
= die_containing_type (die
, cu
);
3400 TYPE_VPTR_BASETYPE (type
) = t
;
3403 static const char vptr_name
[] =
3404 {'_', 'v', 'p', 't', 'r', '\0'};
3407 /* Our own class provides vtbl ptr. */
3408 for (i
= TYPE_NFIELDS (t
) - 1;
3409 i
>= TYPE_N_BASECLASSES (t
);
3412 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
3414 if ((strncmp (fieldname
, vptr_name
,
3415 strlen (vptr_name
) - 1)
3417 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
3419 TYPE_VPTR_FIELDNO (type
) = i
;
3424 /* Complain if virtual function table field not found. */
3425 if (i
< TYPE_N_BASECLASSES (t
))
3426 complaint (&symfile_complaints
,
3427 "virtual function table pointer not found when defining class '%s'",
3428 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
3433 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3438 do_cleanups (back_to
);
3441 processing_current_prefix
= previous_prefix
;
3442 if (back_to
!= NULL
)
3443 do_cleanups (back_to
);
3447 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3449 struct objfile
*objfile
= cu
->objfile
;
3450 const char *previous_prefix
= processing_current_prefix
;
3451 struct die_info
*child_die
= die
->child
;
3453 if (TYPE_TAG_NAME (die
->type
) != NULL
)
3454 processing_current_prefix
= TYPE_TAG_NAME (die
->type
);
3456 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
3457 snapshots) has been known to create a die giving a declaration
3458 for a class that has, as a child, a die giving a definition for a
3459 nested class. So we have to process our children even if the
3460 current die is a declaration. Normally, of course, a declaration
3461 won't have any children at all. */
3463 while (child_die
!= NULL
&& child_die
->tag
)
3465 if (child_die
->tag
== DW_TAG_member
3466 || child_die
->tag
== DW_TAG_variable
3467 || child_die
->tag
== DW_TAG_inheritance
)
3472 process_die (child_die
, cu
);
3474 child_die
= sibling_die (child_die
);
3477 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3478 new_symbol (die
, die
->type
, cu
);
3480 processing_current_prefix
= previous_prefix
;
3483 /* Given a DW_AT_enumeration_type die, set its type. We do not
3484 complete the type's fields yet, or create any symbols. */
3487 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3489 struct objfile
*objfile
= cu
->objfile
;
3491 struct attribute
*attr
;
3496 type
= alloc_type (objfile
);
3498 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3499 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3500 if (attr
&& DW_STRING (attr
))
3502 char *name
= DW_STRING (attr
);
3504 if (processing_has_namespace_info
)
3506 TYPE_TAG_NAME (type
) = obconcat (&objfile
->objfile_obstack
,
3507 processing_current_prefix
,
3508 processing_current_prefix
[0] == '\0'
3514 /* The name is already allocated along with this objfile, so
3515 we don't need to duplicate it for the type. */
3516 TYPE_TAG_NAME (type
) = name
;
3520 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3523 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3527 TYPE_LENGTH (type
) = 0;
3533 /* Determine the name of the type represented by DIE, which should be
3534 a named C++ compound type. Return the name in question; the caller
3535 is responsible for xfree()'ing it. */
3538 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
3540 struct cleanup
*back_to
= NULL
;
3541 struct die_info
*spec_die
= die_specification (die
, cu
);
3542 char *new_prefix
= NULL
;
3544 /* If this is the definition of a class that is declared by another
3545 die, then processing_current_prefix may not be accurate; see
3546 read_func_scope for a similar example. */
3547 if (spec_die
!= NULL
)
3549 char *specification_prefix
= determine_prefix (spec_die
, cu
);
3550 processing_current_prefix
= specification_prefix
;
3551 back_to
= make_cleanup (xfree
, specification_prefix
);
3554 /* If we don't have namespace debug info, guess the name by trying
3555 to demangle the names of members, just like we did in
3556 guess_structure_name. */
3557 if (!processing_has_namespace_info
)
3559 struct die_info
*child
;
3561 for (child
= die
->child
;
3562 child
!= NULL
&& child
->tag
!= 0;
3563 child
= sibling_die (child
))
3565 if (child
->tag
== DW_TAG_subprogram
)
3567 new_prefix
= class_name_from_physname (dwarf2_linkage_name
3570 if (new_prefix
!= NULL
)
3576 if (new_prefix
== NULL
)
3578 const char *name
= dwarf2_name (die
, cu
);
3579 new_prefix
= typename_concat (processing_current_prefix
,
3580 name
? name
: "<<anonymous>>");
3583 if (back_to
!= NULL
)
3584 do_cleanups (back_to
);
3589 /* Given a pointer to a die which begins an enumeration, process all
3590 the dies that define the members of the enumeration, and create the
3591 symbol for the enumeration type.
3593 NOTE: We reverse the order of the element list. */
3596 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3598 struct objfile
*objfile
= cu
->objfile
;
3599 struct die_info
*child_die
;
3600 struct field
*fields
;
3601 struct attribute
*attr
;
3604 int unsigned_enum
= 1;
3608 if (die
->child
!= NULL
)
3610 child_die
= die
->child
;
3611 while (child_die
&& child_die
->tag
)
3613 if (child_die
->tag
!= DW_TAG_enumerator
)
3615 process_die (child_die
, cu
);
3619 attr
= dwarf2_attr (child_die
, DW_AT_name
, cu
);
3622 sym
= new_symbol (child_die
, die
->type
, cu
);
3623 if (SYMBOL_VALUE (sym
) < 0)
3626 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3628 fields
= (struct field
*)
3630 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
3631 * sizeof (struct field
));
3634 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
3635 FIELD_TYPE (fields
[num_fields
]) = NULL
;
3636 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
3637 FIELD_BITSIZE (fields
[num_fields
]) = 0;
3638 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
3644 child_die
= sibling_die (child_die
);
3649 TYPE_NFIELDS (die
->type
) = num_fields
;
3650 TYPE_FIELDS (die
->type
) = (struct field
*)
3651 TYPE_ALLOC (die
->type
, sizeof (struct field
) * num_fields
);
3652 memcpy (TYPE_FIELDS (die
->type
), fields
,
3653 sizeof (struct field
) * num_fields
);
3657 TYPE_FLAGS (die
->type
) |= TYPE_FLAG_UNSIGNED
;
3660 new_symbol (die
, die
->type
, cu
);
3663 /* Extract all information from a DW_TAG_array_type DIE and put it in
3664 the DIE's type field. For now, this only handles one dimensional
3668 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3670 struct objfile
*objfile
= cu
->objfile
;
3671 struct die_info
*child_die
;
3672 struct type
*type
= NULL
;
3673 struct type
*element_type
, *range_type
, *index_type
;
3674 struct type
**range_types
= NULL
;
3675 struct attribute
*attr
;
3677 struct cleanup
*back_to
;
3679 /* Return if we've already decoded this type. */
3685 element_type
= die_type (die
, cu
);
3687 /* Irix 6.2 native cc creates array types without children for
3688 arrays with unspecified length. */
3689 if (die
->child
== NULL
)
3691 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
3692 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3693 die
->type
= create_array_type (NULL
, element_type
, range_type
);
3697 back_to
= make_cleanup (null_cleanup
, NULL
);
3698 child_die
= die
->child
;
3699 while (child_die
&& child_die
->tag
)
3701 if (child_die
->tag
== DW_TAG_subrange_type
)
3703 read_subrange_type (child_die
, cu
);
3705 if (child_die
->type
!= NULL
)
3707 /* The range type was succesfully read. Save it for
3708 the array type creation. */
3709 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3711 range_types
= (struct type
**)
3712 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3713 * sizeof (struct type
*));
3715 make_cleanup (free_current_contents
, &range_types
);
3717 range_types
[ndim
++] = child_die
->type
;
3720 child_die
= sibling_die (child_die
);
3723 /* Dwarf2 dimensions are output from left to right, create the
3724 necessary array types in backwards order. */
3725 type
= element_type
;
3727 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3729 /* Understand Dwarf2 support for vector types (like they occur on
3730 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3731 array type. This is not part of the Dwarf2/3 standard yet, but a
3732 custom vendor extension. The main difference between a regular
3733 array and the vector variant is that vectors are passed by value
3735 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
3737 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3739 do_cleanups (back_to
);
3741 /* Install the type in the die. */
3745 /* First cut: install each common block member as a global variable. */
3748 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
3750 struct die_info
*child_die
;
3751 struct attribute
*attr
;
3753 CORE_ADDR base
= (CORE_ADDR
) 0;
3755 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
3758 /* Support the .debug_loc offsets */
3759 if (attr_form_is_block (attr
))
3761 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
3763 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3765 dwarf2_complex_location_expr_complaint ();
3769 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3770 "common block member");
3773 if (die
->child
!= NULL
)
3775 child_die
= die
->child
;
3776 while (child_die
&& child_die
->tag
)
3778 sym
= new_symbol (child_die
, NULL
, cu
);
3779 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
3782 SYMBOL_VALUE_ADDRESS (sym
) =
3783 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
3784 add_symbol_to_list (sym
, &global_symbols
);
3786 child_die
= sibling_die (child_die
);
3791 /* Read a C++ namespace. */
3794 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3796 struct objfile
*objfile
= cu
->objfile
;
3797 const char *previous_prefix
= processing_current_prefix
;
3800 struct die_info
*current_die
;
3802 name
= namespace_name (die
, &is_anonymous
, cu
);
3804 /* Now build the name of the current namespace. */
3806 if (previous_prefix
[0] == '\0')
3808 processing_current_prefix
= name
;
3812 /* We need temp_name around because processing_current_prefix
3813 is a const char *. */
3814 char *temp_name
= alloca (strlen (previous_prefix
)
3815 + 2 + strlen(name
) + 1);
3816 strcpy (temp_name
, previous_prefix
);
3817 strcat (temp_name
, "::");
3818 strcat (temp_name
, name
);
3820 processing_current_prefix
= temp_name
;
3823 /* Add a symbol associated to this if we haven't seen the namespace
3824 before. Also, add a using directive if it's an anonymous
3827 if (dwarf2_extension (die
, cu
) == NULL
)
3831 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3832 this cast will hopefully become unnecessary. */
3833 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
3834 (char *) processing_current_prefix
,
3836 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
3838 new_symbol (die
, type
, cu
);
3842 cp_add_using_directive (processing_current_prefix
,
3843 strlen (previous_prefix
),
3844 strlen (processing_current_prefix
));
3847 if (die
->child
!= NULL
)
3849 struct die_info
*child_die
= die
->child
;
3851 while (child_die
&& child_die
->tag
)
3853 process_die (child_die
, cu
);
3854 child_die
= sibling_die (child_die
);
3858 processing_current_prefix
= previous_prefix
;
3861 /* Return the name of the namespace represented by DIE. Set
3862 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
3866 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
3868 struct die_info
*current_die
;
3869 const char *name
= NULL
;
3871 /* Loop through the extensions until we find a name. */
3873 for (current_die
= die
;
3874 current_die
!= NULL
;
3875 current_die
= dwarf2_extension (die
, cu
))
3877 name
= dwarf2_name (current_die
, cu
);
3882 /* Is it an anonymous namespace? */
3884 *is_anonymous
= (name
== NULL
);
3886 name
= "(anonymous namespace)";
3891 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3892 the user defined type vector. */
3895 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3897 struct comp_unit_head
*cu_header
= &cu
->header
;
3899 struct attribute
*attr_byte_size
;
3900 struct attribute
*attr_address_class
;
3901 int byte_size
, addr_class
;
3908 type
= lookup_pointer_type (die_type (die
, cu
));
3910 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3912 byte_size
= DW_UNSND (attr_byte_size
);
3914 byte_size
= cu_header
->addr_size
;
3916 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
3917 if (attr_address_class
)
3918 addr_class
= DW_UNSND (attr_address_class
);
3920 addr_class
= DW_ADDR_none
;
3922 /* If the pointer size or address class is different than the
3923 default, create a type variant marked as such and set the
3924 length accordingly. */
3925 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3927 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3931 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3932 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3933 type
= make_type_with_address_space (type
, type_flags
);
3935 else if (TYPE_LENGTH (type
) != byte_size
)
3937 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3940 /* Should we also complain about unhandled address classes? */
3944 TYPE_LENGTH (type
) = byte_size
;
3948 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3949 the user defined type vector. */
3952 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3954 struct objfile
*objfile
= cu
->objfile
;
3956 struct type
*to_type
;
3957 struct type
*domain
;
3964 type
= alloc_type (objfile
);
3965 to_type
= die_type (die
, cu
);
3966 domain
= die_containing_type (die
, cu
);
3967 smash_to_member_type (type
, domain
, to_type
);
3972 /* Extract all information from a DW_TAG_reference_type DIE and add to
3973 the user defined type vector. */
3976 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3978 struct comp_unit_head
*cu_header
= &cu
->header
;
3980 struct attribute
*attr
;
3987 type
= lookup_reference_type (die_type (die
, cu
));
3988 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3991 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3995 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4001 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4003 struct type
*base_type
;
4010 base_type
= die_type (die
, cu
);
4011 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
4015 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4017 struct type
*base_type
;
4024 base_type
= die_type (die
, cu
);
4025 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
4028 /* Extract all information from a DW_TAG_string_type DIE and add to
4029 the user defined type vector. It isn't really a user defined type,
4030 but it behaves like one, with other DIE's using an AT_user_def_type
4031 attribute to reference it. */
4034 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4036 struct objfile
*objfile
= cu
->objfile
;
4037 struct type
*type
, *range_type
, *index_type
, *char_type
;
4038 struct attribute
*attr
;
4039 unsigned int length
;
4046 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4049 length
= DW_UNSND (attr
);
4053 /* check for the DW_AT_byte_size attribute */
4054 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4057 length
= DW_UNSND (attr
);
4064 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
4065 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4066 if (cu
->language
== language_fortran
)
4068 /* Need to create a unique string type for bounds
4070 type
= create_string_type (0, range_type
);
4074 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
, cu
);
4075 type
= create_string_type (char_type
, range_type
);
4080 /* Handle DIES due to C code like:
4084 int (*funcp)(int a, long l);
4088 ('funcp' generates a DW_TAG_subroutine_type DIE)
4092 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4094 struct type
*type
; /* Type that this function returns */
4095 struct type
*ftype
; /* Function that returns above type */
4096 struct attribute
*attr
;
4098 /* Decode the type that this subroutine returns */
4103 type
= die_type (die
, cu
);
4104 ftype
= lookup_function_type (type
);
4106 /* All functions in C++ have prototypes. */
4107 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4108 if ((attr
&& (DW_UNSND (attr
) != 0))
4109 || cu
->language
== language_cplus
)
4110 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
4112 if (die
->child
!= NULL
)
4114 struct die_info
*child_die
;
4118 /* Count the number of parameters.
4119 FIXME: GDB currently ignores vararg functions, but knows about
4120 vararg member functions. */
4121 child_die
= die
->child
;
4122 while (child_die
&& child_die
->tag
)
4124 if (child_die
->tag
== DW_TAG_formal_parameter
)
4126 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4127 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
4128 child_die
= sibling_die (child_die
);
4131 /* Allocate storage for parameters and fill them in. */
4132 TYPE_NFIELDS (ftype
) = nparams
;
4133 TYPE_FIELDS (ftype
) = (struct field
*)
4134 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
4136 child_die
= die
->child
;
4137 while (child_die
&& child_die
->tag
)
4139 if (child_die
->tag
== DW_TAG_formal_parameter
)
4141 /* Dwarf2 has no clean way to discern C++ static and non-static
4142 member functions. G++ helps GDB by marking the first
4143 parameter for non-static member functions (which is the
4144 this pointer) as artificial. We pass this information
4145 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4146 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4148 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4150 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4151 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4154 child_die
= sibling_die (child_die
);
4162 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4164 struct objfile
*objfile
= cu
->objfile
;
4165 struct attribute
*attr
;
4170 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4171 if (attr
&& DW_STRING (attr
))
4173 name
= DW_STRING (attr
);
4175 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
4176 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
4180 /* Find a representation of a given base type and install
4181 it in the TYPE field of the die. */
4184 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4186 struct objfile
*objfile
= cu
->objfile
;
4188 struct attribute
*attr
;
4189 int encoding
= 0, size
= 0;
4191 /* If we've already decoded this die, this is a no-op. */
4197 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4200 encoding
= DW_UNSND (attr
);
4202 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4205 size
= DW_UNSND (attr
);
4207 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4208 if (attr
&& DW_STRING (attr
))
4210 enum type_code code
= TYPE_CODE_INT
;
4215 case DW_ATE_address
:
4216 /* Turn DW_ATE_address into a void * pointer. */
4217 code
= TYPE_CODE_PTR
;
4218 type_flags
|= TYPE_FLAG_UNSIGNED
;
4220 case DW_ATE_boolean
:
4221 code
= TYPE_CODE_BOOL
;
4222 type_flags
|= TYPE_FLAG_UNSIGNED
;
4224 case DW_ATE_complex_float
:
4225 code
= TYPE_CODE_COMPLEX
;
4228 code
= TYPE_CODE_FLT
;
4231 case DW_ATE_signed_char
:
4233 case DW_ATE_unsigned
:
4234 case DW_ATE_unsigned_char
:
4235 type_flags
|= TYPE_FLAG_UNSIGNED
;
4238 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
4239 dwarf_type_encoding_name (encoding
));
4242 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
4243 if (encoding
== DW_ATE_address
)
4244 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
,
4246 else if (encoding
== DW_ATE_complex_float
)
4249 TYPE_TARGET_TYPE (type
)
4250 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
, cu
);
4251 else if (size
== 16)
4252 TYPE_TARGET_TYPE (type
)
4253 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
4255 TYPE_TARGET_TYPE (type
)
4256 = dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
4261 type
= dwarf_base_type (encoding
, size
, cu
);
4266 /* Read the given DW_AT_subrange DIE. */
4269 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4271 struct type
*base_type
;
4272 struct type
*range_type
;
4273 struct attribute
*attr
;
4277 /* If we have already decoded this die, then nothing more to do. */
4281 base_type
= die_type (die
, cu
);
4282 if (base_type
== NULL
)
4284 complaint (&symfile_complaints
,
4285 "DW_AT_type missing from DW_TAG_subrange_type");
4289 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
4290 base_type
= alloc_type (NULL
);
4292 if (cu
->language
== language_fortran
)
4294 /* FORTRAN implies a lower bound of 1, if not given. */
4298 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
4300 low
= dwarf2_get_attr_constant_value (attr
, 0);
4302 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
4305 if (attr
->form
== DW_FORM_block1
)
4307 /* GCC encodes arrays with unspecified or dynamic length
4308 with a DW_FORM_block1 attribute.
4309 FIXME: GDB does not yet know how to handle dynamic
4310 arrays properly, treat them as arrays with unspecified
4313 FIXME: jimb/2003-09-22: GDB does not really know
4314 how to handle arrays of unspecified length
4315 either; we just represent them as zero-length
4316 arrays. Choose an appropriate upper bound given
4317 the lower bound we've computed above. */
4321 high
= dwarf2_get_attr_constant_value (attr
, 1);
4324 range_type
= create_range_type (NULL
, base_type
, low
, high
);
4326 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4327 if (attr
&& DW_STRING (attr
))
4328 TYPE_NAME (range_type
) = DW_STRING (attr
);
4330 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4332 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
4334 die
->type
= range_type
;
4338 /* Read a whole compilation unit into a linked list of dies. */
4340 static struct die_info
*
4341 read_comp_unit (char *info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
4343 /* Reset die reference table; we are
4344 building new ones now. */
4345 dwarf2_empty_hash_tables ();
4347 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
4350 /* Read a single die and all its descendents. Set the die's sibling
4351 field to NULL; set other fields in the die correctly, and set all
4352 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4353 location of the info_ptr after reading all of those dies. PARENT
4354 is the parent of the die in question. */
4356 static struct die_info
*
4357 read_die_and_children (char *info_ptr
, bfd
*abfd
,
4358 struct dwarf2_cu
*cu
,
4359 char **new_info_ptr
,
4360 struct die_info
*parent
)
4362 struct die_info
*die
;
4366 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
4367 store_in_ref_table (die
->offset
, die
);
4371 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
4377 *new_info_ptr
= cur_ptr
;
4380 die
->sibling
= NULL
;
4381 die
->parent
= parent
;
4385 /* Read a die, all of its descendents, and all of its siblings; set
4386 all of the fields of all of the dies correctly. Arguments are as
4387 in read_die_and_children. */
4389 static struct die_info
*
4390 read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
4391 struct dwarf2_cu
*cu
,
4392 char **new_info_ptr
,
4393 struct die_info
*parent
)
4395 struct die_info
*first_die
, *last_sibling
;
4399 first_die
= last_sibling
= NULL
;
4403 struct die_info
*die
4404 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
4412 last_sibling
->sibling
= die
;
4417 *new_info_ptr
= cur_ptr
;
4427 /* Free a linked list of dies. */
4430 free_die_list (struct die_info
*dies
)
4432 struct die_info
*die
, *next
;
4437 if (die
->child
!= NULL
)
4438 free_die_list (die
->child
);
4439 next
= die
->sibling
;
4447 do_free_die_list_cleanup (void *dies
)
4449 free_die_list (dies
);
4452 static struct cleanup
*
4453 make_cleanup_free_die_list (struct die_info
*dies
)
4455 return make_cleanup (do_free_die_list_cleanup
, dies
);
4459 /* Read the contents of the section at OFFSET and of size SIZE from the
4460 object file specified by OBJFILE into the objfile_obstack and return it. */
4463 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
4465 bfd
*abfd
= objfile
->obfd
;
4467 bfd_size_type size
= bfd_get_section_size_before_reloc (sectp
);
4472 buf
= (char *) obstack_alloc (&objfile
->objfile_obstack
, size
);
4474 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
4478 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
4479 || bfd_bread (buf
, size
, abfd
) != size
)
4480 error ("Dwarf Error: Can't read DWARF data from '%s'",
4481 bfd_get_filename (abfd
));
4486 /* In DWARF version 2, the description of the debugging information is
4487 stored in a separate .debug_abbrev section. Before we read any
4488 dies from a section we read in all abbreviations and install them
4489 in a hash table. This function also sets flags in CU describing
4490 the data found in the abbrev table. */
4493 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
4495 struct comp_unit_head
*cu_header
= &cu
->header
;
4497 struct abbrev_info
*cur_abbrev
;
4498 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
4499 unsigned int abbrev_form
, hash_number
;
4500 struct attr_abbrev
*cur_attrs
;
4501 unsigned int allocated_attrs
;
4503 /* Initialize dwarf2 abbrevs */
4504 obstack_init (&cu
->abbrev_obstack
);
4505 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
4507 * sizeof (struct abbrev_info
*)));
4508 memset (cu
->dwarf2_abbrevs
, 0,
4509 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
4511 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
4512 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4513 abbrev_ptr
+= bytes_read
;
4515 allocated_attrs
= ATTR_ALLOC_CHUNK
;
4516 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
4518 /* loop until we reach an abbrev number of 0 */
4519 while (abbrev_number
)
4521 cur_abbrev
= dwarf_alloc_abbrev (cu
);
4523 /* read in abbrev header */
4524 cur_abbrev
->number
= abbrev_number
;
4525 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4526 abbrev_ptr
+= bytes_read
;
4527 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
4530 if (cur_abbrev
->tag
== DW_TAG_namespace
)
4531 cu
->has_namespace_info
= 1;
4533 /* now read in declarations */
4534 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4535 abbrev_ptr
+= bytes_read
;
4536 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4537 abbrev_ptr
+= bytes_read
;
4540 if (cur_abbrev
->num_attrs
== allocated_attrs
)
4542 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
4544 = xrealloc (cur_attrs
, (allocated_attrs
4545 * sizeof (struct attr_abbrev
)));
4547 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
4548 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
4549 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4550 abbrev_ptr
+= bytes_read
;
4551 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4552 abbrev_ptr
+= bytes_read
;
4555 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
4556 (cur_abbrev
->num_attrs
4557 * sizeof (struct attr_abbrev
)));
4558 memcpy (cur_abbrev
->attrs
, cur_attrs
,
4559 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
4561 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
4562 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
4563 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
4565 /* Get next abbreviation.
4566 Under Irix6 the abbreviations for a compilation unit are not
4567 always properly terminated with an abbrev number of 0.
4568 Exit loop if we encounter an abbreviation which we have
4569 already read (which means we are about to read the abbreviations
4570 for the next compile unit) or if the end of the abbreviation
4571 table is reached. */
4572 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
4573 >= dwarf2_per_objfile
->abbrev_size
)
4575 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4576 abbrev_ptr
+= bytes_read
;
4577 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
4584 /* Release the memory used by the abbrev table for a compilation unit. */
4587 dwarf2_free_abbrev_table (void *ptr_to_cu
)
4589 struct dwarf2_cu
*cu
= ptr_to_cu
;
4591 obstack_free (&cu
->abbrev_obstack
, NULL
);
4592 cu
->dwarf2_abbrevs
= NULL
;
4595 /* Lookup an abbrev_info structure in the abbrev hash table. */
4597 static struct abbrev_info
*
4598 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
4600 unsigned int hash_number
;
4601 struct abbrev_info
*abbrev
;
4603 hash_number
= number
% ABBREV_HASH_SIZE
;
4604 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
4608 if (abbrev
->number
== number
)
4611 abbrev
= abbrev
->next
;
4616 /* Returns nonzero if TAG represents a type that we might generate a partial
4620 is_type_tag_for_partial (int tag
)
4625 /* Some types that would be reasonable to generate partial symbols for,
4626 that we don't at present. */
4627 case DW_TAG_array_type
:
4628 case DW_TAG_file_type
:
4629 case DW_TAG_ptr_to_member_type
:
4630 case DW_TAG_set_type
:
4631 case DW_TAG_string_type
:
4632 case DW_TAG_subroutine_type
:
4634 case DW_TAG_base_type
:
4635 case DW_TAG_class_type
:
4636 case DW_TAG_enumeration_type
:
4637 case DW_TAG_structure_type
:
4638 case DW_TAG_subrange_type
:
4639 case DW_TAG_typedef
:
4640 case DW_TAG_union_type
:
4647 /* Load all DIEs that are interesting for partial symbols into memory. */
4649 static struct partial_die_info
*
4650 load_partial_dies (bfd
*abfd
, char *info_ptr
, int building_psymtab
,
4651 struct dwarf2_cu
*cu
)
4653 struct partial_die_info
*part_die
;
4654 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
4655 struct abbrev_info
*abbrev
;
4656 unsigned int bytes_read
;
4658 int nesting_level
= 1;
4664 = htab_create_alloc_ex (cu
->header
.length
/ 12,
4668 &cu
->comp_unit_obstack
,
4669 hashtab_obstack_allocate
,
4670 dummy_obstack_deallocate
);
4672 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
4673 sizeof (struct partial_die_info
));
4677 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4679 /* A NULL abbrev means the end of a series of children. */
4682 if (--nesting_level
== 0)
4684 /* PART_DIE was probably the last thing allocated on the
4685 comp_unit_obstack, so we could call obstack_free
4686 here. We don't do that because the waste is small,
4687 and will be cleaned up when we're done with this
4688 compilation unit. This way, we're also more robust
4689 against other users of the comp_unit_obstack. */
4692 info_ptr
+= bytes_read
;
4693 last_die
= parent_die
;
4694 parent_die
= parent_die
->die_parent
;
4698 /* Check whether this DIE is interesting enough to save. */
4699 if (!is_type_tag_for_partial (abbrev
->tag
)
4700 && abbrev
->tag
!= DW_TAG_enumerator
4701 && abbrev
->tag
!= DW_TAG_subprogram
4702 && abbrev
->tag
!= DW_TAG_variable
4703 && abbrev
->tag
!= DW_TAG_namespace
)
4705 /* Otherwise we skip to the next sibling, if any. */
4706 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
4710 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
4711 abfd
, info_ptr
, cu
);
4713 /* This two-pass algorithm for processing partial symbols has a
4714 high cost in cache pressure. Thus, handle some simple cases
4715 here which cover the majority of C partial symbols. DIEs
4716 which neither have specification tags in them, nor could have
4717 specification tags elsewhere pointing at them, can simply be
4718 processed and discarded.
4720 This segment is also optional; scan_partial_symbols and
4721 add_partial_symbol will handle these DIEs if we chain
4722 them in normally. When compilers which do not emit large
4723 quantities of duplicate debug information are more common,
4724 this code can probably be removed. */
4726 /* Any complete simple types at the top level (pretty much all
4727 of them, for a language without namespaces), can be processed
4729 if (parent_die
== NULL
4730 && part_die
->has_specification
== 0
4731 && part_die
->is_declaration
== 0
4732 && (part_die
->tag
== DW_TAG_typedef
4733 || part_die
->tag
== DW_TAG_base_type
4734 || part_die
->tag
== DW_TAG_subrange_type
))
4736 if (building_psymtab
&& part_die
->name
!= NULL
)
4737 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
4738 VAR_DOMAIN
, LOC_TYPEDEF
,
4739 &cu
->objfile
->static_psymbols
,
4740 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
4741 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
4745 /* If we're at the second level, and we're an enumerator, and
4746 our parent has no specification (meaning possibly lives in a
4747 namespace elsewhere), then we can add the partial symbol now
4748 instead of queueing it. */
4749 if (part_die
->tag
== DW_TAG_enumerator
4750 && parent_die
!= NULL
4751 && parent_die
->die_parent
== NULL
4752 && parent_die
->tag
== DW_TAG_enumeration_type
4753 && parent_die
->has_specification
== 0)
4755 if (part_die
->name
== NULL
)
4756 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
4757 else if (building_psymtab
)
4758 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
4759 VAR_DOMAIN
, LOC_CONST
,
4760 cu
->language
== language_cplus
4761 ? &cu
->objfile
->global_psymbols
4762 : &cu
->objfile
->static_psymbols
,
4763 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
4765 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
4769 /* We'll save this DIE so link it in. */
4770 part_die
->die_parent
= parent_die
;
4771 part_die
->die_sibling
= NULL
;
4772 part_die
->die_child
= NULL
;
4774 if (last_die
&& last_die
== parent_die
)
4775 last_die
->die_child
= part_die
;
4777 last_die
->die_sibling
= part_die
;
4779 last_die
= part_die
;
4781 if (first_die
== NULL
)
4782 first_die
= part_die
;
4784 /* Maybe add the DIE to the hash table. Not all DIEs that we
4785 find interesting need to be in the hash table, because we
4786 also have the parent/sibling/child chains; only those that we
4787 might refer to by offset later during partial symbol reading.
4789 For now this means things that might have be the target of a
4790 DW_AT_specification, DW_AT_abstract_origin, or
4791 DW_AT_extension. DW_AT_extension will refer only to
4792 namespaces; DW_AT_abstract_origin refers to functions (and
4793 many things under the function DIE, but we do not recurse
4794 into function DIEs during partial symbol reading) and
4795 possibly variables as well; DW_AT_specification refers to
4796 declarations. Declarations ought to have the DW_AT_declaration
4797 flag. It happens that GCC forgets to put it in sometimes, but
4798 only for functions, not for types.
4800 Adding more things than necessary to the hash table is harmless
4801 except for the performance cost. Adding too few will result in
4802 internal errors in find_partial_die. */
4804 if (abbrev
->tag
== DW_TAG_subprogram
4805 || abbrev
->tag
== DW_TAG_variable
4806 || abbrev
->tag
== DW_TAG_namespace
4807 || part_die
->is_declaration
)
4811 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
4812 part_die
->offset
, INSERT
);
4816 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
4817 sizeof (struct partial_die_info
));
4819 /* For some DIEs we want to follow their children (if any). For C
4820 we have no reason to follow the children of structures; for other
4821 languages we have to, both so that we can get at method physnames
4822 to infer fully qualified class names, and for DW_AT_specification. */
4823 if (last_die
->has_children
4824 && (last_die
->tag
== DW_TAG_namespace
4825 || last_die
->tag
== DW_TAG_enumeration_type
4826 || (cu
->language
!= language_c
4827 && (last_die
->tag
== DW_TAG_class_type
4828 || last_die
->tag
== DW_TAG_structure_type
4829 || last_die
->tag
== DW_TAG_union_type
))))
4832 parent_die
= last_die
;
4836 /* Otherwise we skip to the next sibling, if any. */
4837 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
4839 /* Back to the top, do it again. */
4843 /* Read a minimal amount of information into the minimal die structure. */
4846 read_partial_die (struct partial_die_info
*part_die
,
4847 struct abbrev_info
*abbrev
,
4848 unsigned int abbrev_len
, bfd
*abfd
,
4849 char *info_ptr
, struct dwarf2_cu
*cu
)
4851 unsigned int bytes_read
, i
;
4852 struct attribute attr
;
4853 int has_low_pc_attr
= 0;
4854 int has_high_pc_attr
= 0;
4856 memset (part_die
, 0, sizeof (struct partial_die_info
));
4858 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
4860 info_ptr
+= abbrev_len
;
4865 part_die
->tag
= abbrev
->tag
;
4866 part_die
->has_children
= abbrev
->has_children
;
4868 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4870 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
4872 /* Store the data if it is of an attribute we want to keep in a
4873 partial symbol table. */
4878 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
4879 if (part_die
->name
== NULL
)
4880 part_die
->name
= DW_STRING (&attr
);
4882 case DW_AT_comp_dir
:
4883 if (part_die
->dirname
== NULL
)
4884 part_die
->dirname
= DW_STRING (&attr
);
4886 case DW_AT_MIPS_linkage_name
:
4887 part_die
->name
= DW_STRING (&attr
);
4890 has_low_pc_attr
= 1;
4891 part_die
->lowpc
= DW_ADDR (&attr
);
4894 has_high_pc_attr
= 1;
4895 part_die
->highpc
= DW_ADDR (&attr
);
4897 case DW_AT_location
:
4898 /* Support the .debug_loc offsets */
4899 if (attr_form_is_block (&attr
))
4901 part_die
->locdesc
= DW_BLOCK (&attr
);
4903 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
4905 dwarf2_complex_location_expr_complaint ();
4909 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4910 "partial symbol information");
4913 case DW_AT_language
:
4914 part_die
->language
= DW_UNSND (&attr
);
4916 case DW_AT_external
:
4917 part_die
->is_external
= DW_UNSND (&attr
);
4919 case DW_AT_declaration
:
4920 part_die
->is_declaration
= DW_UNSND (&attr
);
4923 part_die
->has_type
= 1;
4925 case DW_AT_abstract_origin
:
4926 case DW_AT_specification
:
4927 case DW_AT_extension
:
4928 part_die
->has_specification
= 1;
4929 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
4932 /* Ignore absolute siblings, they might point outside of
4933 the current compile unit. */
4934 if (attr
.form
== DW_FORM_ref_addr
)
4935 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
4937 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
4938 + dwarf2_get_ref_die_offset (&attr
, cu
);
4940 case DW_AT_stmt_list
:
4941 part_die
->has_stmt_list
= 1;
4942 part_die
->line_offset
= DW_UNSND (&attr
);
4949 /* When using the GNU linker, .gnu.linkonce. sections are used to
4950 eliminate duplicate copies of functions and vtables and such.
4951 The linker will arbitrarily choose one and discard the others.
4952 The AT_*_pc values for such functions refer to local labels in
4953 these sections. If the section from that file was discarded, the
4954 labels are not in the output, so the relocs get a value of 0.
4955 If this is a discarded function, mark the pc bounds as invalid,
4956 so that GDB will ignore it. */
4957 if (has_low_pc_attr
&& has_high_pc_attr
4958 && part_die
->lowpc
< part_die
->highpc
4959 && (part_die
->lowpc
!= 0
4960 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
4961 part_die
->has_pc_info
= 1;
4965 /* Find a cached partial DIE at OFFSET in CU. */
4967 static struct partial_die_info
*
4968 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
4970 struct partial_die_info
*lookup_die
= NULL
;
4971 struct partial_die_info part_die
;
4973 part_die
.offset
= offset
;
4974 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
4976 if (lookup_die
== NULL
)
4977 internal_error (__FILE__
, __LINE__
,
4978 "could not find partial DIE in cache\n");
4983 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
4985 static struct partial_die_info
*
4986 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
,
4987 struct dwarf2_cu
**target_cu
)
4989 struct dwarf2_per_cu_data
*per_cu
;
4991 if (offset
>= cu
->header
.offset
4992 && offset
< cu
->header
.offset
+ cu
->header
.length
)
4995 return find_partial_die_in_comp_unit (offset
, cu
);
4998 internal_error (__FILE__
, __LINE__
,
4999 "unsupported inter-compilation-unit reference");
5002 /* Adjust PART_DIE before generating a symbol for it. This function
5003 may set the is_external flag or change the DIE's name. */
5006 fixup_partial_die (struct partial_die_info
*part_die
,
5007 struct dwarf2_cu
*cu
)
5009 /* If we found a reference attribute and the DIE has no name, try
5010 to find a name in the referred to DIE. */
5012 if (part_die
->name
== NULL
&& part_die
->has_specification
)
5014 struct partial_die_info
*spec_die
;
5015 struct dwarf2_cu
*spec_cu
;
5017 spec_die
= find_partial_die (part_die
->spec_offset
, cu
, &spec_cu
);
5019 fixup_partial_die (spec_die
, spec_cu
);
5023 part_die
->name
= spec_die
->name
;
5025 /* Copy DW_AT_external attribute if it is set. */
5026 if (spec_die
->is_external
)
5027 part_die
->is_external
= spec_die
->is_external
;
5031 /* Set default names for some unnamed DIEs. */
5032 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
5033 || part_die
->tag
== DW_TAG_class_type
))
5034 part_die
->name
= "(anonymous class)";
5036 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
5037 part_die
->name
= "(anonymous namespace)";
5039 if (part_die
->tag
== DW_TAG_structure_type
5040 || part_die
->tag
== DW_TAG_class_type
5041 || part_die
->tag
== DW_TAG_union_type
)
5042 guess_structure_name (part_die
, cu
);
5045 /* Read the die from the .debug_info section buffer. Set DIEP to
5046 point to a newly allocated die with its information, except for its
5047 child, sibling, and parent fields. Set HAS_CHILDREN to tell
5048 whether the die has children or not. */
5051 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
5052 struct dwarf2_cu
*cu
, int *has_children
)
5054 unsigned int abbrev_number
, bytes_read
, i
, offset
;
5055 struct abbrev_info
*abbrev
;
5056 struct die_info
*die
;
5058 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5059 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5060 info_ptr
+= bytes_read
;
5063 die
= dwarf_alloc_die ();
5065 die
->abbrev
= abbrev_number
;
5072 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
5075 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
5077 bfd_get_filename (abfd
));
5079 die
= dwarf_alloc_die ();
5080 die
->offset
= offset
;
5081 die
->tag
= abbrev
->tag
;
5082 die
->abbrev
= abbrev_number
;
5085 die
->num_attrs
= abbrev
->num_attrs
;
5086 die
->attrs
= (struct attribute
*)
5087 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
5089 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5091 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
5092 abfd
, info_ptr
, cu
);
5096 *has_children
= abbrev
->has_children
;
5100 /* Read an attribute value described by an attribute form. */
5103 read_attribute_value (struct attribute
*attr
, unsigned form
,
5104 bfd
*abfd
, char *info_ptr
,
5105 struct dwarf2_cu
*cu
)
5107 struct comp_unit_head
*cu_header
= &cu
->header
;
5108 unsigned int bytes_read
;
5109 struct dwarf_block
*blk
;
5115 case DW_FORM_ref_addr
:
5116 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
5117 info_ptr
+= bytes_read
;
5119 case DW_FORM_block2
:
5120 blk
= dwarf_alloc_block (cu
);
5121 blk
->size
= read_2_bytes (abfd
, info_ptr
);
5123 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5124 info_ptr
+= blk
->size
;
5125 DW_BLOCK (attr
) = blk
;
5127 case DW_FORM_block4
:
5128 blk
= dwarf_alloc_block (cu
);
5129 blk
->size
= read_4_bytes (abfd
, info_ptr
);
5131 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5132 info_ptr
+= blk
->size
;
5133 DW_BLOCK (attr
) = blk
;
5136 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
5140 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
5144 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
5147 case DW_FORM_string
:
5148 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
5149 info_ptr
+= bytes_read
;
5152 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
5154 info_ptr
+= bytes_read
;
5157 blk
= dwarf_alloc_block (cu
);
5158 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5159 info_ptr
+= bytes_read
;
5160 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5161 info_ptr
+= blk
->size
;
5162 DW_BLOCK (attr
) = blk
;
5164 case DW_FORM_block1
:
5165 blk
= dwarf_alloc_block (cu
);
5166 blk
->size
= read_1_byte (abfd
, info_ptr
);
5168 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5169 info_ptr
+= blk
->size
;
5170 DW_BLOCK (attr
) = blk
;
5173 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5177 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5181 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
5182 info_ptr
+= bytes_read
;
5185 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5186 info_ptr
+= bytes_read
;
5189 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5193 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
5197 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
5201 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
5204 case DW_FORM_ref_udata
:
5205 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5206 info_ptr
+= bytes_read
;
5208 case DW_FORM_indirect
:
5209 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5210 info_ptr
+= bytes_read
;
5211 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
5214 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
5215 dwarf_form_name (form
),
5216 bfd_get_filename (abfd
));
5221 /* Read an attribute described by an abbreviated attribute. */
5224 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
5225 bfd
*abfd
, char *info_ptr
, struct dwarf2_cu
*cu
)
5227 attr
->name
= abbrev
->name
;
5228 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
5231 /* read dwarf information from a buffer */
5234 read_1_byte (bfd
*abfd
, char *buf
)
5236 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5240 read_1_signed_byte (bfd
*abfd
, char *buf
)
5242 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
5246 read_2_bytes (bfd
*abfd
, char *buf
)
5248 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
5252 read_2_signed_bytes (bfd
*abfd
, char *buf
)
5254 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
5258 read_4_bytes (bfd
*abfd
, char *buf
)
5260 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5264 read_4_signed_bytes (bfd
*abfd
, char *buf
)
5266 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
5269 static unsigned long
5270 read_8_bytes (bfd
*abfd
, char *buf
)
5272 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5276 read_address (bfd
*abfd
, char *buf
, struct dwarf2_cu
*cu
, int *bytes_read
)
5278 struct comp_unit_head
*cu_header
= &cu
->header
;
5279 CORE_ADDR retval
= 0;
5281 if (cu_header
->signed_addr_p
)
5283 switch (cu_header
->addr_size
)
5286 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
5289 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
5292 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
5295 internal_error (__FILE__
, __LINE__
,
5296 "read_address: bad switch, signed [in module %s]",
5297 bfd_get_filename (abfd
));
5302 switch (cu_header
->addr_size
)
5305 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
5308 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5311 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5314 internal_error (__FILE__
, __LINE__
,
5315 "read_address: bad switch, unsigned [in module %s]",
5316 bfd_get_filename (abfd
));
5320 *bytes_read
= cu_header
->addr_size
;
5324 /* Read the initial length from a section. The (draft) DWARF 3
5325 specification allows the initial length to take up either 4 bytes
5326 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
5327 bytes describe the length and all offsets will be 8 bytes in length
5330 An older, non-standard 64-bit format is also handled by this
5331 function. The older format in question stores the initial length
5332 as an 8-byte quantity without an escape value. Lengths greater
5333 than 2^32 aren't very common which means that the initial 4 bytes
5334 is almost always zero. Since a length value of zero doesn't make
5335 sense for the 32-bit format, this initial zero can be considered to
5336 be an escape value which indicates the presence of the older 64-bit
5337 format. As written, the code can't detect (old format) lengths
5338 greater than 4GB. If it becomes necessary to handle lengths somewhat
5339 larger than 4GB, we could allow other small values (such as the
5340 non-sensical values of 1, 2, and 3) to also be used as escape values
5341 indicating the presence of the old format.
5343 The value returned via bytes_read should be used to increment
5344 the relevant pointer after calling read_initial_length().
5346 As a side effect, this function sets the fields initial_length_size
5347 and offset_size in cu_header to the values appropriate for the
5348 length field. (The format of the initial length field determines
5349 the width of file offsets to be fetched later with fetch_offset().)
5351 [ Note: read_initial_length() and read_offset() are based on the
5352 document entitled "DWARF Debugging Information Format", revision
5353 3, draft 8, dated November 19, 2001. This document was obtained
5356 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
5358 This document is only a draft and is subject to change. (So beware.)
5360 Details regarding the older, non-standard 64-bit format were
5361 determined empirically by examining 64-bit ELF files produced
5362 by the SGI toolchain on an IRIX 6.5 machine.
5364 - Kevin, July 16, 2002
5368 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
5373 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5375 if (retval
== 0xffffffff)
5377 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
5379 if (cu_header
!= NULL
)
5381 cu_header
->initial_length_size
= 12;
5382 cu_header
->offset_size
= 8;
5385 else if (retval
== 0)
5387 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
5389 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5391 if (cu_header
!= NULL
)
5393 cu_header
->initial_length_size
= 8;
5394 cu_header
->offset_size
= 8;
5400 if (cu_header
!= NULL
)
5402 cu_header
->initial_length_size
= 4;
5403 cu_header
->offset_size
= 4;
5410 /* Read an offset from the data stream. The size of the offset is
5411 given by cu_header->offset_size. */
5414 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
5419 switch (cu_header
->offset_size
)
5422 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5426 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5430 internal_error (__FILE__
, __LINE__
,
5431 "read_offset: bad switch [in module %s]",
5432 bfd_get_filename (abfd
));
5439 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
5441 /* If the size of a host char is 8 bits, we can return a pointer
5442 to the buffer, otherwise we have to copy the data to a buffer
5443 allocated on the temporary obstack. */
5444 gdb_assert (HOST_CHAR_BIT
== 8);
5449 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5451 /* If the size of a host char is 8 bits, we can return a pointer
5452 to the string, otherwise we have to copy the string to a buffer
5453 allocated on the temporary obstack. */
5454 gdb_assert (HOST_CHAR_BIT
== 8);
5457 *bytes_read_ptr
= 1;
5460 *bytes_read_ptr
= strlen (buf
) + 1;
5465 read_indirect_string (bfd
*abfd
, char *buf
,
5466 const struct comp_unit_head
*cu_header
,
5467 unsigned int *bytes_read_ptr
)
5469 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
5470 (int *) bytes_read_ptr
);
5472 if (dwarf2_per_objfile
->str_buffer
== NULL
)
5474 error ("DW_FORM_strp used without .debug_str section [in module %s]",
5475 bfd_get_filename (abfd
));
5478 if (str_offset
>= dwarf2_per_objfile
->str_size
)
5480 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
5481 bfd_get_filename (abfd
));
5484 gdb_assert (HOST_CHAR_BIT
== 8);
5485 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
5487 return dwarf2_per_objfile
->str_buffer
+ str_offset
;
5490 static unsigned long
5491 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5493 unsigned long result
;
5494 unsigned int num_read
;
5504 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5507 result
|= ((unsigned long)(byte
& 127) << shift
);
5508 if ((byte
& 128) == 0)
5514 *bytes_read_ptr
= num_read
;
5519 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5522 int i
, shift
, size
, num_read
;
5532 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5535 result
|= ((long)(byte
& 127) << shift
);
5537 if ((byte
& 128) == 0)
5542 if ((shift
< size
) && (byte
& 0x40))
5544 result
|= -(1 << shift
);
5546 *bytes_read_ptr
= num_read
;
5550 /* Return a pointer to just past the end of an LEB128 number in BUF. */
5553 skip_leb128 (bfd
*abfd
, char *buf
)
5559 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5561 if ((byte
& 128) == 0)
5567 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
5573 cu
->language
= language_c
;
5575 case DW_LANG_C_plus_plus
:
5576 cu
->language
= language_cplus
;
5578 case DW_LANG_Fortran77
:
5579 case DW_LANG_Fortran90
:
5580 case DW_LANG_Fortran95
:
5581 cu
->language
= language_fortran
;
5583 case DW_LANG_Mips_Assembler
:
5584 cu
->language
= language_asm
;
5587 cu
->language
= language_java
;
5591 case DW_LANG_Cobol74
:
5592 case DW_LANG_Cobol85
:
5593 case DW_LANG_Pascal83
:
5594 case DW_LANG_Modula2
:
5596 cu
->language
= language_minimal
;
5599 cu
->language_defn
= language_def (cu
->language
);
5602 /* Return the named attribute or NULL if not there. */
5604 static struct attribute
*
5605 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
5608 struct attribute
*spec
= NULL
;
5610 for (i
= 0; i
< die
->num_attrs
; ++i
)
5612 if (die
->attrs
[i
].name
== name
)
5614 return &die
->attrs
[i
];
5616 if (die
->attrs
[i
].name
== DW_AT_specification
5617 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
5618 spec
= &die
->attrs
[i
];
5622 struct die_info
*ref_die
=
5623 follow_die_ref (dwarf2_get_ref_die_offset (spec
, cu
));
5626 return dwarf2_attr (ref_die
, name
, cu
);
5632 /* Return non-zero iff the attribute NAME is defined for the given DIE,
5633 and holds a non-zero value. This function should only be used for
5634 DW_FORM_flag attributes. */
5637 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
5639 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
5641 return (attr
&& DW_UNSND (attr
));
5645 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
5647 /* A DIE is a declaration if it has a DW_AT_declaration attribute
5648 which value is non-zero. However, we have to be careful with
5649 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
5650 (via dwarf2_flag_true_p) follows this attribute. So we may
5651 end up accidently finding a declaration attribute that belongs
5652 to a different DIE referenced by the specification attribute,
5653 even though the given DIE does not have a declaration attribute. */
5654 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
5655 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
5658 /* Return the die giving the specification for DIE, if there is
5661 static struct die_info
*
5662 die_specification (struct die_info
*die
, struct dwarf2_cu
*cu
)
5664 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
, cu
);
5666 if (spec_attr
== NULL
)
5669 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr
, cu
));
5672 /* Free the line_header structure *LH, and any arrays and strings it
5675 free_line_header (struct line_header
*lh
)
5677 if (lh
->standard_opcode_lengths
)
5678 xfree (lh
->standard_opcode_lengths
);
5680 /* Remember that all the lh->file_names[i].name pointers are
5681 pointers into debug_line_buffer, and don't need to be freed. */
5683 xfree (lh
->file_names
);
5685 /* Similarly for the include directory names. */
5686 if (lh
->include_dirs
)
5687 xfree (lh
->include_dirs
);
5693 /* Add an entry to LH's include directory table. */
5695 add_include_dir (struct line_header
*lh
, char *include_dir
)
5697 /* Grow the array if necessary. */
5698 if (lh
->include_dirs_size
== 0)
5700 lh
->include_dirs_size
= 1; /* for testing */
5701 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
5702 * sizeof (*lh
->include_dirs
));
5704 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
5706 lh
->include_dirs_size
*= 2;
5707 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
5708 (lh
->include_dirs_size
5709 * sizeof (*lh
->include_dirs
)));
5712 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
5716 /* Add an entry to LH's file name table. */
5718 add_file_name (struct line_header
*lh
,
5720 unsigned int dir_index
,
5721 unsigned int mod_time
,
5722 unsigned int length
)
5724 struct file_entry
*fe
;
5726 /* Grow the array if necessary. */
5727 if (lh
->file_names_size
== 0)
5729 lh
->file_names_size
= 1; /* for testing */
5730 lh
->file_names
= xmalloc (lh
->file_names_size
5731 * sizeof (*lh
->file_names
));
5733 else if (lh
->num_file_names
>= lh
->file_names_size
)
5735 lh
->file_names_size
*= 2;
5736 lh
->file_names
= xrealloc (lh
->file_names
,
5737 (lh
->file_names_size
5738 * sizeof (*lh
->file_names
)));
5741 fe
= &lh
->file_names
[lh
->num_file_names
++];
5743 fe
->dir_index
= dir_index
;
5744 fe
->mod_time
= mod_time
;
5745 fe
->length
= length
;
5750 /* Read the statement program header starting at OFFSET in
5751 .debug_line, according to the endianness of ABFD. Return a pointer
5752 to a struct line_header, allocated using xmalloc.
5754 NOTE: the strings in the include directory and file name tables of
5755 the returned object point into debug_line_buffer, and must not be
5757 static struct line_header
*
5758 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
5759 struct dwarf2_cu
*cu
)
5761 struct cleanup
*back_to
;
5762 struct line_header
*lh
;
5766 char *cur_dir
, *cur_file
;
5768 if (dwarf2_per_objfile
->line_buffer
== NULL
)
5770 complaint (&symfile_complaints
, "missing .debug_line section");
5774 /* Make sure that at least there's room for the total_length field. That
5775 could be 12 bytes long, but we're just going to fudge that. */
5776 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
5778 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5782 lh
= xmalloc (sizeof (*lh
));
5783 memset (lh
, 0, sizeof (*lh
));
5784 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
5787 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
5789 /* read in the header */
5790 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
5791 line_ptr
+= bytes_read
;
5792 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
5793 + dwarf2_per_objfile
->line_size
))
5795 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5798 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
5799 lh
->version
= read_2_bytes (abfd
, line_ptr
);
5801 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
5802 line_ptr
+= bytes_read
;
5803 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
5805 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
5807 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
5809 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
5811 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
5813 lh
->standard_opcode_lengths
5814 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
5816 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
5817 for (i
= 1; i
< lh
->opcode_base
; ++i
)
5819 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
5823 /* Read directory table */
5824 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5826 line_ptr
+= bytes_read
;
5827 add_include_dir (lh
, cur_dir
);
5829 line_ptr
+= bytes_read
;
5831 /* Read file name table */
5832 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5834 unsigned int dir_index
, mod_time
, length
;
5836 line_ptr
+= bytes_read
;
5837 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5838 line_ptr
+= bytes_read
;
5839 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5840 line_ptr
+= bytes_read
;
5841 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5842 line_ptr
+= bytes_read
;
5844 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5846 line_ptr
+= bytes_read
;
5847 lh
->statement_program_start
= line_ptr
;
5849 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
5850 + dwarf2_per_objfile
->line_size
))
5851 complaint (&symfile_complaints
,
5852 "line number info header doesn't fit in `.debug_line' section");
5854 discard_cleanups (back_to
);
5858 /* This function exists to work around a bug in certain compilers
5859 (particularly GCC 2.95), in which the first line number marker of a
5860 function does not show up until after the prologue, right before
5861 the second line number marker. This function shifts ADDRESS down
5862 to the beginning of the function if necessary, and is called on
5863 addresses passed to record_line. */
5866 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
5868 struct function_range
*fn
;
5870 /* Find the function_range containing address. */
5875 cu
->cached_fn
= cu
->first_fn
;
5879 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5885 while (fn
&& fn
!= cu
->cached_fn
)
5886 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5896 if (address
!= fn
->lowpc
)
5897 complaint (&symfile_complaints
,
5898 "misplaced first line number at 0x%lx for '%s'",
5899 (unsigned long) address
, fn
->name
);
5904 /* Decode the Line Number Program (LNP) for the given line_header
5905 structure and CU. The actual information extracted and the type
5906 of structures created from the LNP depends on the value of PST.
5908 1. If PST is NULL, then this procedure uses the data from the program
5909 to create all necessary symbol tables, and their linetables.
5910 The compilation directory of the file is passed in COMP_DIR,
5911 and must not be NULL.
5913 2. If PST is not NULL, this procedure reads the program to determine
5914 the list of files included by the unit represented by PST, and
5915 builds all the associated partial symbol tables. In this case,
5916 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
5917 is not used to compute the full name of the symtab, and therefore
5918 omitting it when building the partial symtab does not introduce
5919 the potential for inconsistency - a partial symtab and its associated
5920 symbtab having a different fullname -). */
5923 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
5924 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
5928 unsigned int bytes_read
;
5929 unsigned char op_code
, extended_op
, adj_opcode
;
5931 struct objfile
*objfile
= cu
->objfile
;
5932 const int decode_for_pst_p
= (pst
!= NULL
);
5934 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5936 line_ptr
= lh
->statement_program_start
;
5937 line_end
= lh
->statement_program_end
;
5939 /* Read the statement sequences until there's nothing left. */
5940 while (line_ptr
< line_end
)
5942 /* state machine registers */
5943 CORE_ADDR address
= 0;
5944 unsigned int file
= 1;
5945 unsigned int line
= 1;
5946 unsigned int column
= 0;
5947 int is_stmt
= lh
->default_is_stmt
;
5948 int basic_block
= 0;
5949 int end_sequence
= 0;
5951 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
5953 /* Start a subfile for the current file of the state machine. */
5954 /* lh->include_dirs and lh->file_names are 0-based, but the
5955 directory and file name numbers in the statement program
5957 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
5960 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5963 dwarf2_start_subfile (fe
->name
, dir
);
5966 /* Decode the table. */
5967 while (!end_sequence
)
5969 op_code
= read_1_byte (abfd
, line_ptr
);
5972 if (op_code
>= lh
->opcode_base
)
5973 { /* Special operand. */
5974 adj_opcode
= op_code
- lh
->opcode_base
;
5975 address
+= (adj_opcode
/ lh
->line_range
)
5976 * lh
->minimum_instruction_length
;
5977 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
5978 if (!decode_for_pst_p
)
5980 /* append row to matrix using current values */
5981 record_line (current_subfile
, line
,
5982 check_cu_functions (address
, cu
));
5986 else switch (op_code
)
5988 case DW_LNS_extended_op
:
5989 line_ptr
+= 1; /* ignore length */
5990 extended_op
= read_1_byte (abfd
, line_ptr
);
5992 switch (extended_op
)
5994 case DW_LNE_end_sequence
:
5996 if (!decode_for_pst_p
)
5997 record_line (current_subfile
, 0, address
);
5999 case DW_LNE_set_address
:
6000 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
6001 line_ptr
+= bytes_read
;
6002 address
+= baseaddr
;
6004 case DW_LNE_define_file
:
6007 unsigned int dir_index
, mod_time
, length
;
6009 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
6010 line_ptr
+= bytes_read
;
6012 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6013 line_ptr
+= bytes_read
;
6015 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6016 line_ptr
+= bytes_read
;
6018 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6019 line_ptr
+= bytes_read
;
6020 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6024 complaint (&symfile_complaints
,
6025 "mangled .debug_line section");
6030 if (!decode_for_pst_p
)
6031 record_line (current_subfile
, line
,
6032 check_cu_functions (address
, cu
));
6035 case DW_LNS_advance_pc
:
6036 address
+= lh
->minimum_instruction_length
6037 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6038 line_ptr
+= bytes_read
;
6040 case DW_LNS_advance_line
:
6041 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
6042 line_ptr
+= bytes_read
;
6044 case DW_LNS_set_file
:
6046 /* lh->include_dirs and lh->file_names are 0-based,
6047 but the directory and file name numbers in the
6048 statement program are 1-based. */
6049 struct file_entry
*fe
;
6051 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6052 line_ptr
+= bytes_read
;
6053 fe
= &lh
->file_names
[file
- 1];
6056 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6059 if (!decode_for_pst_p
)
6060 dwarf2_start_subfile (fe
->name
, dir
);
6063 case DW_LNS_set_column
:
6064 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6065 line_ptr
+= bytes_read
;
6067 case DW_LNS_negate_stmt
:
6068 is_stmt
= (!is_stmt
);
6070 case DW_LNS_set_basic_block
:
6073 /* Add to the address register of the state machine the
6074 address increment value corresponding to special opcode
6075 255. Ie, this value is scaled by the minimum instruction
6076 length since special opcode 255 would have scaled the
6078 case DW_LNS_const_add_pc
:
6079 address
+= (lh
->minimum_instruction_length
6080 * ((255 - lh
->opcode_base
) / lh
->line_range
));
6082 case DW_LNS_fixed_advance_pc
:
6083 address
+= read_2_bytes (abfd
, line_ptr
);
6087 { /* Unknown standard opcode, ignore it. */
6089 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
6091 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6092 line_ptr
+= bytes_read
;
6099 if (decode_for_pst_p
)
6103 /* Now that we're done scanning the Line Header Program, we can
6104 create the psymtab of each included file. */
6105 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
6106 if (lh
->file_names
[file_index
].included_p
== 1)
6108 char *include_name
= lh
->file_names
[file_index
].name
;
6110 if (strcmp (include_name
, pst
->filename
) != 0)
6111 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
6116 /* Start a subfile for DWARF. FILENAME is the name of the file and
6117 DIRNAME the name of the source directory which contains FILENAME
6118 or NULL if not known.
6119 This routine tries to keep line numbers from identical absolute and
6120 relative file names in a common subfile.
6122 Using the `list' example from the GDB testsuite, which resides in
6123 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
6124 of /srcdir/list0.c yields the following debugging information for list0.c:
6126 DW_AT_name: /srcdir/list0.c
6127 DW_AT_comp_dir: /compdir
6128 files.files[0].name: list0.h
6129 files.files[0].dir: /srcdir
6130 files.files[1].name: list0.c
6131 files.files[1].dir: /srcdir
6133 The line number information for list0.c has to end up in a single
6134 subfile, so that `break /srcdir/list0.c:1' works as expected. */
6137 dwarf2_start_subfile (char *filename
, char *dirname
)
6139 /* If the filename isn't absolute, try to match an existing subfile
6140 with the full pathname. */
6142 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
6144 struct subfile
*subfile
;
6145 char *fullname
= concat (dirname
, "/", filename
, NULL
);
6147 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
6149 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
6151 current_subfile
= subfile
;
6158 start_subfile (filename
, dirname
);
6162 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
6163 struct dwarf2_cu
*cu
)
6165 struct objfile
*objfile
= cu
->objfile
;
6166 struct comp_unit_head
*cu_header
= &cu
->header
;
6168 /* NOTE drow/2003-01-30: There used to be a comment and some special
6169 code here to turn a symbol with DW_AT_external and a
6170 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
6171 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
6172 with some versions of binutils) where shared libraries could have
6173 relocations against symbols in their debug information - the
6174 minimal symbol would have the right address, but the debug info
6175 would not. It's no longer necessary, because we will explicitly
6176 apply relocations when we read in the debug information now. */
6178 /* A DW_AT_location attribute with no contents indicates that a
6179 variable has been optimized away. */
6180 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
6182 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
6186 /* Handle one degenerate form of location expression specially, to
6187 preserve GDB's previous behavior when section offsets are
6188 specified. If this is just a DW_OP_addr then mark this symbol
6191 if (attr_form_is_block (attr
)
6192 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
6193 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
6197 SYMBOL_VALUE_ADDRESS (sym
) =
6198 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
6199 fixup_symbol_section (sym
, objfile
);
6200 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
6201 SYMBOL_SECTION (sym
));
6202 SYMBOL_CLASS (sym
) = LOC_STATIC
;
6206 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
6207 expression evaluator, and use LOC_COMPUTED only when necessary
6208 (i.e. when the value of a register or memory location is
6209 referenced, or a thread-local block, etc.). Then again, it might
6210 not be worthwhile. I'm assuming that it isn't unless performance
6211 or memory numbers show me otherwise. */
6213 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
6214 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
6217 /* Given a pointer to a DWARF information entry, figure out if we need
6218 to make a symbol table entry for it, and if so, create a new entry
6219 and return a pointer to it.
6220 If TYPE is NULL, determine symbol type from the die, otherwise
6221 used the passed type. */
6223 static struct symbol
*
6224 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
6226 struct objfile
*objfile
= cu
->objfile
;
6227 struct symbol
*sym
= NULL
;
6229 struct attribute
*attr
= NULL
;
6230 struct attribute
*attr2
= NULL
;
6233 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6235 if (die
->tag
!= DW_TAG_namespace
)
6236 name
= dwarf2_linkage_name (die
, cu
);
6238 name
= TYPE_NAME (type
);
6242 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
6243 sizeof (struct symbol
));
6244 OBJSTAT (objfile
, n_syms
++);
6245 memset (sym
, 0, sizeof (struct symbol
));
6247 /* Cache this symbol's name and the name's demangled form (if any). */
6248 SYMBOL_LANGUAGE (sym
) = cu
->language
;
6249 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
6251 /* Default assumptions.
6252 Use the passed type or decode it from the die. */
6253 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6254 SYMBOL_CLASS (sym
) = LOC_STATIC
;
6256 SYMBOL_TYPE (sym
) = type
;
6258 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
6259 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
6262 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
6267 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6270 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
6272 SYMBOL_CLASS (sym
) = LOC_LABEL
;
6274 case DW_TAG_subprogram
:
6275 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
6277 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
6278 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6279 if (attr2
&& (DW_UNSND (attr2
) != 0))
6281 add_symbol_to_list (sym
, &global_symbols
);
6285 add_symbol_to_list (sym
, cu
->list_in_scope
);
6288 case DW_TAG_variable
:
6289 /* Compilation with minimal debug info may result in variables
6290 with missing type entries. Change the misleading `void' type
6291 to something sensible. */
6292 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
6293 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
6294 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
6295 "<variable, no debug info>",
6297 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6300 dwarf2_const_value (attr
, sym
, cu
);
6301 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6302 if (attr2
&& (DW_UNSND (attr2
) != 0))
6303 add_symbol_to_list (sym
, &global_symbols
);
6305 add_symbol_to_list (sym
, cu
->list_in_scope
);
6308 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6311 var_decode_location (attr
, sym
, cu
);
6312 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6313 if (attr2
&& (DW_UNSND (attr2
) != 0))
6314 add_symbol_to_list (sym
, &global_symbols
);
6316 add_symbol_to_list (sym
, cu
->list_in_scope
);
6320 /* We do not know the address of this symbol.
6321 If it is an external symbol and we have type information
6322 for it, enter the symbol as a LOC_UNRESOLVED symbol.
6323 The address of the variable will then be determined from
6324 the minimal symbol table whenever the variable is
6326 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6327 if (attr2
&& (DW_UNSND (attr2
) != 0)
6328 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
6330 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
6331 add_symbol_to_list (sym
, &global_symbols
);
6335 case DW_TAG_formal_parameter
:
6336 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6339 var_decode_location (attr
, sym
, cu
);
6340 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
6341 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
6342 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
6344 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6347 dwarf2_const_value (attr
, sym
, cu
);
6349 add_symbol_to_list (sym
, cu
->list_in_scope
);
6351 case DW_TAG_unspecified_parameters
:
6352 /* From varargs functions; gdb doesn't seem to have any
6353 interest in this information, so just ignore it for now.
6356 case DW_TAG_class_type
:
6357 case DW_TAG_structure_type
:
6358 case DW_TAG_union_type
:
6359 case DW_TAG_enumeration_type
:
6360 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6361 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6363 /* Make sure that the symbol includes appropriate enclosing
6364 classes/namespaces in its name. These are calculated in
6365 read_structure_type, and the correct name is saved in
6368 if (cu
->language
== language_cplus
)
6370 struct type
*type
= SYMBOL_TYPE (sym
);
6372 if (TYPE_TAG_NAME (type
) != NULL
)
6374 /* FIXME: carlton/2003-11-10: Should this use
6375 SYMBOL_SET_NAMES instead? (The same problem also
6376 arises further down in this function.) */
6377 /* The type's name is already allocated along with
6378 this objfile, so we don't need to duplicate it
6380 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
6385 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
6386 really ever be static objects: otherwise, if you try
6387 to, say, break of a class's method and you're in a file
6388 which doesn't mention that class, it won't work unless
6389 the check for all static symbols in lookup_symbol_aux
6390 saves you. See the OtherFileClass tests in
6391 gdb.c++/namespace.exp. */
6393 struct pending
**list_to_add
;
6395 list_to_add
= (cu
->list_in_scope
== &file_symbols
6396 && cu
->language
== language_cplus
6397 ? &global_symbols
: cu
->list_in_scope
);
6399 add_symbol_to_list (sym
, list_to_add
);
6401 /* The semantics of C++ state that "struct foo { ... }" also
6402 defines a typedef for "foo". Synthesize a typedef symbol so
6403 that "ptype foo" works as expected. */
6404 if (cu
->language
== language_cplus
)
6406 struct symbol
*typedef_sym
= (struct symbol
*)
6407 obstack_alloc (&objfile
->objfile_obstack
,
6408 sizeof (struct symbol
));
6409 *typedef_sym
= *sym
;
6410 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
6411 /* The symbol's name is already allocated along with
6412 this objfile, so we don't need to duplicate it for
6414 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
6415 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NATURAL_NAME (sym
);
6416 add_symbol_to_list (typedef_sym
, list_to_add
);
6420 case DW_TAG_typedef
:
6421 if (processing_has_namespace_info
6422 && processing_current_prefix
[0] != '\0')
6424 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->objfile_obstack
,
6425 processing_current_prefix
,
6429 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6430 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6431 add_symbol_to_list (sym
, cu
->list_in_scope
);
6433 case DW_TAG_base_type
:
6434 case DW_TAG_subrange_type
:
6435 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6436 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6437 add_symbol_to_list (sym
, cu
->list_in_scope
);
6439 case DW_TAG_enumerator
:
6440 if (processing_has_namespace_info
6441 && processing_current_prefix
[0] != '\0')
6443 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->objfile_obstack
,
6444 processing_current_prefix
,
6448 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6451 dwarf2_const_value (attr
, sym
, cu
);
6454 /* NOTE: carlton/2003-11-10: See comment above in the
6455 DW_TAG_class_type, etc. block. */
6457 struct pending
**list_to_add
;
6459 list_to_add
= (cu
->list_in_scope
== &file_symbols
6460 && cu
->language
== language_cplus
6461 ? &global_symbols
: cu
->list_in_scope
);
6463 add_symbol_to_list (sym
, list_to_add
);
6466 case DW_TAG_namespace
:
6467 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6468 add_symbol_to_list (sym
, &global_symbols
);
6471 /* Not a tag we recognize. Hopefully we aren't processing
6472 trash data, but since we must specifically ignore things
6473 we don't recognize, there is nothing else we should do at
6475 complaint (&symfile_complaints
, "unsupported tag: '%s'",
6476 dwarf_tag_name (die
->tag
));
6483 /* Copy constant value from an attribute to a symbol. */
6486 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
6487 struct dwarf2_cu
*cu
)
6489 struct objfile
*objfile
= cu
->objfile
;
6490 struct comp_unit_head
*cu_header
= &cu
->header
;
6491 struct dwarf_block
*blk
;
6496 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
6497 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
6498 cu_header
->addr_size
,
6499 TYPE_LENGTH (SYMBOL_TYPE
6501 SYMBOL_VALUE_BYTES (sym
) = (char *)
6502 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
6503 /* NOTE: cagney/2003-05-09: In-lined store_address call with
6504 it's body - store_unsigned_integer. */
6505 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
6507 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6509 case DW_FORM_block1
:
6510 case DW_FORM_block2
:
6511 case DW_FORM_block4
:
6513 blk
= DW_BLOCK (attr
);
6514 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
6515 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
6517 TYPE_LENGTH (SYMBOL_TYPE
6519 SYMBOL_VALUE_BYTES (sym
) = (char *)
6520 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
6521 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
6522 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6525 /* The DW_AT_const_value attributes are supposed to carry the
6526 symbol's value "represented as it would be on the target
6527 architecture." By the time we get here, it's already been
6528 converted to host endianness, so we just need to sign- or
6529 zero-extend it as appropriate. */
6531 dwarf2_const_value_data (attr
, sym
, 8);
6534 dwarf2_const_value_data (attr
, sym
, 16);
6537 dwarf2_const_value_data (attr
, sym
, 32);
6540 dwarf2_const_value_data (attr
, sym
, 64);
6544 SYMBOL_VALUE (sym
) = DW_SND (attr
);
6545 SYMBOL_CLASS (sym
) = LOC_CONST
;
6549 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
6550 SYMBOL_CLASS (sym
) = LOC_CONST
;
6554 complaint (&symfile_complaints
,
6555 "unsupported const value attribute form: '%s'",
6556 dwarf_form_name (attr
->form
));
6557 SYMBOL_VALUE (sym
) = 0;
6558 SYMBOL_CLASS (sym
) = LOC_CONST
;
6564 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
6565 or zero-extend it as appropriate for the symbol's type. */
6567 dwarf2_const_value_data (struct attribute
*attr
,
6571 LONGEST l
= DW_UNSND (attr
);
6573 if (bits
< sizeof (l
) * 8)
6575 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
6576 l
&= ((LONGEST
) 1 << bits
) - 1;
6578 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
6581 SYMBOL_VALUE (sym
) = l
;
6582 SYMBOL_CLASS (sym
) = LOC_CONST
;
6586 /* Return the type of the die in question using its DW_AT_type attribute. */
6588 static struct type
*
6589 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6592 struct attribute
*type_attr
;
6593 struct die_info
*type_die
;
6596 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
6599 /* A missing DW_AT_type represents a void type. */
6600 return dwarf2_fundamental_type (cu
->objfile
, FT_VOID
, cu
);
6604 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6605 type_die
= follow_die_ref (ref
);
6608 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
6609 ref
, cu
->objfile
->name
);
6613 type
= tag_type_to_type (type_die
, cu
);
6616 dump_die (type_die
);
6617 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
6623 /* Return the containing type of the die in question using its
6624 DW_AT_containing_type attribute. */
6626 static struct type
*
6627 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6629 struct type
*type
= NULL
;
6630 struct attribute
*type_attr
;
6631 struct die_info
*type_die
= NULL
;
6634 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
6637 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6638 type_die
= follow_die_ref (ref
);
6641 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
6645 type
= tag_type_to_type (type_die
, cu
);
6650 dump_die (type_die
);
6651 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
6658 static struct type
*
6659 type_at_offset (unsigned int offset
, struct dwarf2_cu
*cu
)
6661 struct die_info
*die
;
6664 die
= follow_die_ref (offset
);
6667 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
6670 type
= tag_type_to_type (die
, cu
);
6675 static struct type
*
6676 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6684 read_type_die (die
, cu
);
6688 error ("Dwarf Error: Cannot find type of die [in module %s]",
6696 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6698 char *prefix
= determine_prefix (die
, cu
);
6699 const char *old_prefix
= processing_current_prefix
;
6700 struct cleanup
*back_to
= make_cleanup (xfree
, prefix
);
6701 processing_current_prefix
= prefix
;
6705 case DW_TAG_class_type
:
6706 case DW_TAG_structure_type
:
6707 case DW_TAG_union_type
:
6708 read_structure_type (die
, cu
);
6710 case DW_TAG_enumeration_type
:
6711 read_enumeration_type (die
, cu
);
6713 case DW_TAG_subprogram
:
6714 case DW_TAG_subroutine_type
:
6715 read_subroutine_type (die
, cu
);
6717 case DW_TAG_array_type
:
6718 read_array_type (die
, cu
);
6720 case DW_TAG_pointer_type
:
6721 read_tag_pointer_type (die
, cu
);
6723 case DW_TAG_ptr_to_member_type
:
6724 read_tag_ptr_to_member_type (die
, cu
);
6726 case DW_TAG_reference_type
:
6727 read_tag_reference_type (die
, cu
);
6729 case DW_TAG_const_type
:
6730 read_tag_const_type (die
, cu
);
6732 case DW_TAG_volatile_type
:
6733 read_tag_volatile_type (die
, cu
);
6735 case DW_TAG_string_type
:
6736 read_tag_string_type (die
, cu
);
6738 case DW_TAG_typedef
:
6739 read_typedef (die
, cu
);
6741 case DW_TAG_subrange_type
:
6742 read_subrange_type (die
, cu
);
6744 case DW_TAG_base_type
:
6745 read_base_type (die
, cu
);
6748 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
6749 dwarf_tag_name (die
->tag
));
6753 processing_current_prefix
= old_prefix
;
6754 do_cleanups (back_to
);
6757 /* Return the name of the namespace/class that DIE is defined within,
6758 or "" if we can't tell. The caller should xfree the result. */
6760 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
6761 therein) for an example of how to use this function to deal with
6762 DW_AT_specification. */
6765 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
6767 struct die_info
*parent
;
6769 if (cu
->language
!= language_cplus
)
6772 parent
= die
->parent
;
6776 return xstrdup ("");
6780 switch (parent
->tag
) {
6781 case DW_TAG_namespace
:
6783 /* FIXME: carlton/2004-03-05: Should I follow extension dies
6784 before doing this check? */
6785 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
6787 return xstrdup (TYPE_TAG_NAME (parent
->type
));
6792 char *parent_prefix
= determine_prefix (parent
, cu
);
6793 char *retval
= typename_concat (parent_prefix
,
6794 namespace_name (parent
, &dummy
,
6796 xfree (parent_prefix
);
6801 case DW_TAG_class_type
:
6802 case DW_TAG_structure_type
:
6804 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
6806 return xstrdup (TYPE_TAG_NAME (parent
->type
));
6810 const char *old_prefix
= processing_current_prefix
;
6811 char *new_prefix
= determine_prefix (parent
, cu
);
6814 processing_current_prefix
= new_prefix
;
6815 retval
= determine_class_name (parent
, cu
);
6816 processing_current_prefix
= old_prefix
;
6823 return determine_prefix (parent
, cu
);
6828 /* Return a newly-allocated string formed by concatenating PREFIX,
6829 "::", and SUFFIX, except that if PREFIX is NULL or the empty
6830 string, just return a copy of SUFFIX. */
6833 typename_concat (const char *prefix
, const char *suffix
)
6835 if (prefix
== NULL
|| prefix
[0] == '\0')
6836 return xstrdup (suffix
);
6839 char *retval
= xmalloc (strlen (prefix
) + 2 + strlen (suffix
) + 1);
6841 strcpy (retval
, prefix
);
6842 strcat (retval
, "::");
6843 strcat (retval
, suffix
);
6849 static struct type
*
6850 dwarf_base_type (int encoding
, int size
, struct dwarf2_cu
*cu
)
6852 struct objfile
*objfile
= cu
->objfile
;
6854 /* FIXME - this should not produce a new (struct type *)
6855 every time. It should cache base types. */
6859 case DW_ATE_address
:
6860 type
= dwarf2_fundamental_type (objfile
, FT_VOID
, cu
);
6862 case DW_ATE_boolean
:
6863 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
, cu
);
6865 case DW_ATE_complex_float
:
6868 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
, cu
);
6872 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
, cu
);
6878 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
6882 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
6889 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6892 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
, cu
);
6896 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6900 case DW_ATE_signed_char
:
6901 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6903 case DW_ATE_unsigned
:
6907 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6910 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
, cu
);
6914 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
, cu
);
6918 case DW_ATE_unsigned_char
:
6919 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6922 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6929 copy_die (struct die_info
*old_die
)
6931 struct die_info
*new_die
;
6934 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6935 memset (new_die
, 0, sizeof (struct die_info
));
6937 new_die
->tag
= old_die
->tag
;
6938 new_die
->has_children
= old_die
->has_children
;
6939 new_die
->abbrev
= old_die
->abbrev
;
6940 new_die
->offset
= old_die
->offset
;
6941 new_die
->type
= NULL
;
6943 num_attrs
= old_die
->num_attrs
;
6944 new_die
->num_attrs
= num_attrs
;
6945 new_die
->attrs
= (struct attribute
*)
6946 xmalloc (num_attrs
* sizeof (struct attribute
));
6948 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
6950 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
6951 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
6952 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
6955 new_die
->next
= NULL
;
6960 /* Return sibling of die, NULL if no sibling. */
6962 static struct die_info
*
6963 sibling_die (struct die_info
*die
)
6965 return die
->sibling
;
6968 /* Get linkage name of a die, return NULL if not found. */
6971 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6973 struct attribute
*attr
;
6975 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6976 if (attr
&& DW_STRING (attr
))
6977 return DW_STRING (attr
);
6978 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6979 if (attr
&& DW_STRING (attr
))
6980 return DW_STRING (attr
);
6984 /* Get name of a die, return NULL if not found. */
6987 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6989 struct attribute
*attr
;
6991 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6992 if (attr
&& DW_STRING (attr
))
6993 return DW_STRING (attr
);
6997 /* Return the die that this die in an extension of, or NULL if there
7000 static struct die_info
*
7001 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
7003 struct attribute
*attr
;
7004 struct die_info
*extension_die
;
7007 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
7011 ref
= dwarf2_get_ref_die_offset (attr
, cu
);
7012 extension_die
= follow_die_ref (ref
);
7015 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
7018 return extension_die
;
7021 /* Convert a DIE tag into its string name. */
7024 dwarf_tag_name (unsigned tag
)
7028 case DW_TAG_padding
:
7029 return "DW_TAG_padding";
7030 case DW_TAG_array_type
:
7031 return "DW_TAG_array_type";
7032 case DW_TAG_class_type
:
7033 return "DW_TAG_class_type";
7034 case DW_TAG_entry_point
:
7035 return "DW_TAG_entry_point";
7036 case DW_TAG_enumeration_type
:
7037 return "DW_TAG_enumeration_type";
7038 case DW_TAG_formal_parameter
:
7039 return "DW_TAG_formal_parameter";
7040 case DW_TAG_imported_declaration
:
7041 return "DW_TAG_imported_declaration";
7043 return "DW_TAG_label";
7044 case DW_TAG_lexical_block
:
7045 return "DW_TAG_lexical_block";
7047 return "DW_TAG_member";
7048 case DW_TAG_pointer_type
:
7049 return "DW_TAG_pointer_type";
7050 case DW_TAG_reference_type
:
7051 return "DW_TAG_reference_type";
7052 case DW_TAG_compile_unit
:
7053 return "DW_TAG_compile_unit";
7054 case DW_TAG_string_type
:
7055 return "DW_TAG_string_type";
7056 case DW_TAG_structure_type
:
7057 return "DW_TAG_structure_type";
7058 case DW_TAG_subroutine_type
:
7059 return "DW_TAG_subroutine_type";
7060 case DW_TAG_typedef
:
7061 return "DW_TAG_typedef";
7062 case DW_TAG_union_type
:
7063 return "DW_TAG_union_type";
7064 case DW_TAG_unspecified_parameters
:
7065 return "DW_TAG_unspecified_parameters";
7066 case DW_TAG_variant
:
7067 return "DW_TAG_variant";
7068 case DW_TAG_common_block
:
7069 return "DW_TAG_common_block";
7070 case DW_TAG_common_inclusion
:
7071 return "DW_TAG_common_inclusion";
7072 case DW_TAG_inheritance
:
7073 return "DW_TAG_inheritance";
7074 case DW_TAG_inlined_subroutine
:
7075 return "DW_TAG_inlined_subroutine";
7077 return "DW_TAG_module";
7078 case DW_TAG_ptr_to_member_type
:
7079 return "DW_TAG_ptr_to_member_type";
7080 case DW_TAG_set_type
:
7081 return "DW_TAG_set_type";
7082 case DW_TAG_subrange_type
:
7083 return "DW_TAG_subrange_type";
7084 case DW_TAG_with_stmt
:
7085 return "DW_TAG_with_stmt";
7086 case DW_TAG_access_declaration
:
7087 return "DW_TAG_access_declaration";
7088 case DW_TAG_base_type
:
7089 return "DW_TAG_base_type";
7090 case DW_TAG_catch_block
:
7091 return "DW_TAG_catch_block";
7092 case DW_TAG_const_type
:
7093 return "DW_TAG_const_type";
7094 case DW_TAG_constant
:
7095 return "DW_TAG_constant";
7096 case DW_TAG_enumerator
:
7097 return "DW_TAG_enumerator";
7098 case DW_TAG_file_type
:
7099 return "DW_TAG_file_type";
7101 return "DW_TAG_friend";
7102 case DW_TAG_namelist
:
7103 return "DW_TAG_namelist";
7104 case DW_TAG_namelist_item
:
7105 return "DW_TAG_namelist_item";
7106 case DW_TAG_packed_type
:
7107 return "DW_TAG_packed_type";
7108 case DW_TAG_subprogram
:
7109 return "DW_TAG_subprogram";
7110 case DW_TAG_template_type_param
:
7111 return "DW_TAG_template_type_param";
7112 case DW_TAG_template_value_param
:
7113 return "DW_TAG_template_value_param";
7114 case DW_TAG_thrown_type
:
7115 return "DW_TAG_thrown_type";
7116 case DW_TAG_try_block
:
7117 return "DW_TAG_try_block";
7118 case DW_TAG_variant_part
:
7119 return "DW_TAG_variant_part";
7120 case DW_TAG_variable
:
7121 return "DW_TAG_variable";
7122 case DW_TAG_volatile_type
:
7123 return "DW_TAG_volatile_type";
7124 case DW_TAG_dwarf_procedure
:
7125 return "DW_TAG_dwarf_procedure";
7126 case DW_TAG_restrict_type
:
7127 return "DW_TAG_restrict_type";
7128 case DW_TAG_interface_type
:
7129 return "DW_TAG_interface_type";
7130 case DW_TAG_namespace
:
7131 return "DW_TAG_namespace";
7132 case DW_TAG_imported_module
:
7133 return "DW_TAG_imported_module";
7134 case DW_TAG_unspecified_type
:
7135 return "DW_TAG_unspecified_type";
7136 case DW_TAG_partial_unit
:
7137 return "DW_TAG_partial_unit";
7138 case DW_TAG_imported_unit
:
7139 return "DW_TAG_imported_unit";
7140 case DW_TAG_MIPS_loop
:
7141 return "DW_TAG_MIPS_loop";
7142 case DW_TAG_format_label
:
7143 return "DW_TAG_format_label";
7144 case DW_TAG_function_template
:
7145 return "DW_TAG_function_template";
7146 case DW_TAG_class_template
:
7147 return "DW_TAG_class_template";
7149 return "DW_TAG_<unknown>";
7153 /* Convert a DWARF attribute code into its string name. */
7156 dwarf_attr_name (unsigned attr
)
7161 return "DW_AT_sibling";
7162 case DW_AT_location
:
7163 return "DW_AT_location";
7165 return "DW_AT_name";
7166 case DW_AT_ordering
:
7167 return "DW_AT_ordering";
7168 case DW_AT_subscr_data
:
7169 return "DW_AT_subscr_data";
7170 case DW_AT_byte_size
:
7171 return "DW_AT_byte_size";
7172 case DW_AT_bit_offset
:
7173 return "DW_AT_bit_offset";
7174 case DW_AT_bit_size
:
7175 return "DW_AT_bit_size";
7176 case DW_AT_element_list
:
7177 return "DW_AT_element_list";
7178 case DW_AT_stmt_list
:
7179 return "DW_AT_stmt_list";
7181 return "DW_AT_low_pc";
7183 return "DW_AT_high_pc";
7184 case DW_AT_language
:
7185 return "DW_AT_language";
7187 return "DW_AT_member";
7189 return "DW_AT_discr";
7190 case DW_AT_discr_value
:
7191 return "DW_AT_discr_value";
7192 case DW_AT_visibility
:
7193 return "DW_AT_visibility";
7195 return "DW_AT_import";
7196 case DW_AT_string_length
:
7197 return "DW_AT_string_length";
7198 case DW_AT_common_reference
:
7199 return "DW_AT_common_reference";
7200 case DW_AT_comp_dir
:
7201 return "DW_AT_comp_dir";
7202 case DW_AT_const_value
:
7203 return "DW_AT_const_value";
7204 case DW_AT_containing_type
:
7205 return "DW_AT_containing_type";
7206 case DW_AT_default_value
:
7207 return "DW_AT_default_value";
7209 return "DW_AT_inline";
7210 case DW_AT_is_optional
:
7211 return "DW_AT_is_optional";
7212 case DW_AT_lower_bound
:
7213 return "DW_AT_lower_bound";
7214 case DW_AT_producer
:
7215 return "DW_AT_producer";
7216 case DW_AT_prototyped
:
7217 return "DW_AT_prototyped";
7218 case DW_AT_return_addr
:
7219 return "DW_AT_return_addr";
7220 case DW_AT_start_scope
:
7221 return "DW_AT_start_scope";
7222 case DW_AT_stride_size
:
7223 return "DW_AT_stride_size";
7224 case DW_AT_upper_bound
:
7225 return "DW_AT_upper_bound";
7226 case DW_AT_abstract_origin
:
7227 return "DW_AT_abstract_origin";
7228 case DW_AT_accessibility
:
7229 return "DW_AT_accessibility";
7230 case DW_AT_address_class
:
7231 return "DW_AT_address_class";
7232 case DW_AT_artificial
:
7233 return "DW_AT_artificial";
7234 case DW_AT_base_types
:
7235 return "DW_AT_base_types";
7236 case DW_AT_calling_convention
:
7237 return "DW_AT_calling_convention";
7239 return "DW_AT_count";
7240 case DW_AT_data_member_location
:
7241 return "DW_AT_data_member_location";
7242 case DW_AT_decl_column
:
7243 return "DW_AT_decl_column";
7244 case DW_AT_decl_file
:
7245 return "DW_AT_decl_file";
7246 case DW_AT_decl_line
:
7247 return "DW_AT_decl_line";
7248 case DW_AT_declaration
:
7249 return "DW_AT_declaration";
7250 case DW_AT_discr_list
:
7251 return "DW_AT_discr_list";
7252 case DW_AT_encoding
:
7253 return "DW_AT_encoding";
7254 case DW_AT_external
:
7255 return "DW_AT_external";
7256 case DW_AT_frame_base
:
7257 return "DW_AT_frame_base";
7259 return "DW_AT_friend";
7260 case DW_AT_identifier_case
:
7261 return "DW_AT_identifier_case";
7262 case DW_AT_macro_info
:
7263 return "DW_AT_macro_info";
7264 case DW_AT_namelist_items
:
7265 return "DW_AT_namelist_items";
7266 case DW_AT_priority
:
7267 return "DW_AT_priority";
7269 return "DW_AT_segment";
7270 case DW_AT_specification
:
7271 return "DW_AT_specification";
7272 case DW_AT_static_link
:
7273 return "DW_AT_static_link";
7275 return "DW_AT_type";
7276 case DW_AT_use_location
:
7277 return "DW_AT_use_location";
7278 case DW_AT_variable_parameter
:
7279 return "DW_AT_variable_parameter";
7280 case DW_AT_virtuality
:
7281 return "DW_AT_virtuality";
7282 case DW_AT_vtable_elem_location
:
7283 return "DW_AT_vtable_elem_location";
7284 case DW_AT_allocated
:
7285 return "DW_AT_allocated";
7286 case DW_AT_associated
:
7287 return "DW_AT_associated";
7288 case DW_AT_data_location
:
7289 return "DW_AT_data_location";
7291 return "DW_AT_stride";
7292 case DW_AT_entry_pc
:
7293 return "DW_AT_entry_pc";
7294 case DW_AT_use_UTF8
:
7295 return "DW_AT_use_UTF8";
7296 case DW_AT_extension
:
7297 return "DW_AT_extension";
7299 return "DW_AT_ranges";
7300 case DW_AT_trampoline
:
7301 return "DW_AT_trampoline";
7302 case DW_AT_call_column
:
7303 return "DW_AT_call_column";
7304 case DW_AT_call_file
:
7305 return "DW_AT_call_file";
7306 case DW_AT_call_line
:
7307 return "DW_AT_call_line";
7309 case DW_AT_MIPS_fde
:
7310 return "DW_AT_MIPS_fde";
7311 case DW_AT_MIPS_loop_begin
:
7312 return "DW_AT_MIPS_loop_begin";
7313 case DW_AT_MIPS_tail_loop_begin
:
7314 return "DW_AT_MIPS_tail_loop_begin";
7315 case DW_AT_MIPS_epilog_begin
:
7316 return "DW_AT_MIPS_epilog_begin";
7317 case DW_AT_MIPS_loop_unroll_factor
:
7318 return "DW_AT_MIPS_loop_unroll_factor";
7319 case DW_AT_MIPS_software_pipeline_depth
:
7320 return "DW_AT_MIPS_software_pipeline_depth";
7322 case DW_AT_MIPS_linkage_name
:
7323 return "DW_AT_MIPS_linkage_name";
7325 case DW_AT_sf_names
:
7326 return "DW_AT_sf_names";
7327 case DW_AT_src_info
:
7328 return "DW_AT_src_info";
7329 case DW_AT_mac_info
:
7330 return "DW_AT_mac_info";
7331 case DW_AT_src_coords
:
7332 return "DW_AT_src_coords";
7333 case DW_AT_body_begin
:
7334 return "DW_AT_body_begin";
7335 case DW_AT_body_end
:
7336 return "DW_AT_body_end";
7337 case DW_AT_GNU_vector
:
7338 return "DW_AT_GNU_vector";
7340 return "DW_AT_<unknown>";
7344 /* Convert a DWARF value form code into its string name. */
7347 dwarf_form_name (unsigned form
)
7352 return "DW_FORM_addr";
7353 case DW_FORM_block2
:
7354 return "DW_FORM_block2";
7355 case DW_FORM_block4
:
7356 return "DW_FORM_block4";
7358 return "DW_FORM_data2";
7360 return "DW_FORM_data4";
7362 return "DW_FORM_data8";
7363 case DW_FORM_string
:
7364 return "DW_FORM_string";
7366 return "DW_FORM_block";
7367 case DW_FORM_block1
:
7368 return "DW_FORM_block1";
7370 return "DW_FORM_data1";
7372 return "DW_FORM_flag";
7374 return "DW_FORM_sdata";
7376 return "DW_FORM_strp";
7378 return "DW_FORM_udata";
7379 case DW_FORM_ref_addr
:
7380 return "DW_FORM_ref_addr";
7382 return "DW_FORM_ref1";
7384 return "DW_FORM_ref2";
7386 return "DW_FORM_ref4";
7388 return "DW_FORM_ref8";
7389 case DW_FORM_ref_udata
:
7390 return "DW_FORM_ref_udata";
7391 case DW_FORM_indirect
:
7392 return "DW_FORM_indirect";
7394 return "DW_FORM_<unknown>";
7398 /* Convert a DWARF stack opcode into its string name. */
7401 dwarf_stack_op_name (unsigned op
)
7406 return "DW_OP_addr";
7408 return "DW_OP_deref";
7410 return "DW_OP_const1u";
7412 return "DW_OP_const1s";
7414 return "DW_OP_const2u";
7416 return "DW_OP_const2s";
7418 return "DW_OP_const4u";
7420 return "DW_OP_const4s";
7422 return "DW_OP_const8u";
7424 return "DW_OP_const8s";
7426 return "DW_OP_constu";
7428 return "DW_OP_consts";
7432 return "DW_OP_drop";
7434 return "DW_OP_over";
7436 return "DW_OP_pick";
7438 return "DW_OP_swap";
7442 return "DW_OP_xderef";
7450 return "DW_OP_minus";
7462 return "DW_OP_plus";
7463 case DW_OP_plus_uconst
:
7464 return "DW_OP_plus_uconst";
7470 return "DW_OP_shra";
7488 return "DW_OP_skip";
7490 return "DW_OP_lit0";
7492 return "DW_OP_lit1";
7494 return "DW_OP_lit2";
7496 return "DW_OP_lit3";
7498 return "DW_OP_lit4";
7500 return "DW_OP_lit5";
7502 return "DW_OP_lit6";
7504 return "DW_OP_lit7";
7506 return "DW_OP_lit8";
7508 return "DW_OP_lit9";
7510 return "DW_OP_lit10";
7512 return "DW_OP_lit11";
7514 return "DW_OP_lit12";
7516 return "DW_OP_lit13";
7518 return "DW_OP_lit14";
7520 return "DW_OP_lit15";
7522 return "DW_OP_lit16";
7524 return "DW_OP_lit17";
7526 return "DW_OP_lit18";
7528 return "DW_OP_lit19";
7530 return "DW_OP_lit20";
7532 return "DW_OP_lit21";
7534 return "DW_OP_lit22";
7536 return "DW_OP_lit23";
7538 return "DW_OP_lit24";
7540 return "DW_OP_lit25";
7542 return "DW_OP_lit26";
7544 return "DW_OP_lit27";
7546 return "DW_OP_lit28";
7548 return "DW_OP_lit29";
7550 return "DW_OP_lit30";
7552 return "DW_OP_lit31";
7554 return "DW_OP_reg0";
7556 return "DW_OP_reg1";
7558 return "DW_OP_reg2";
7560 return "DW_OP_reg3";
7562 return "DW_OP_reg4";
7564 return "DW_OP_reg5";
7566 return "DW_OP_reg6";
7568 return "DW_OP_reg7";
7570 return "DW_OP_reg8";
7572 return "DW_OP_reg9";
7574 return "DW_OP_reg10";
7576 return "DW_OP_reg11";
7578 return "DW_OP_reg12";
7580 return "DW_OP_reg13";
7582 return "DW_OP_reg14";
7584 return "DW_OP_reg15";
7586 return "DW_OP_reg16";
7588 return "DW_OP_reg17";
7590 return "DW_OP_reg18";
7592 return "DW_OP_reg19";
7594 return "DW_OP_reg20";
7596 return "DW_OP_reg21";
7598 return "DW_OP_reg22";
7600 return "DW_OP_reg23";
7602 return "DW_OP_reg24";
7604 return "DW_OP_reg25";
7606 return "DW_OP_reg26";
7608 return "DW_OP_reg27";
7610 return "DW_OP_reg28";
7612 return "DW_OP_reg29";
7614 return "DW_OP_reg30";
7616 return "DW_OP_reg31";
7618 return "DW_OP_breg0";
7620 return "DW_OP_breg1";
7622 return "DW_OP_breg2";
7624 return "DW_OP_breg3";
7626 return "DW_OP_breg4";
7628 return "DW_OP_breg5";
7630 return "DW_OP_breg6";
7632 return "DW_OP_breg7";
7634 return "DW_OP_breg8";
7636 return "DW_OP_breg9";
7638 return "DW_OP_breg10";
7640 return "DW_OP_breg11";
7642 return "DW_OP_breg12";
7644 return "DW_OP_breg13";
7646 return "DW_OP_breg14";
7648 return "DW_OP_breg15";
7650 return "DW_OP_breg16";
7652 return "DW_OP_breg17";
7654 return "DW_OP_breg18";
7656 return "DW_OP_breg19";
7658 return "DW_OP_breg20";
7660 return "DW_OP_breg21";
7662 return "DW_OP_breg22";
7664 return "DW_OP_breg23";
7666 return "DW_OP_breg24";
7668 return "DW_OP_breg25";
7670 return "DW_OP_breg26";
7672 return "DW_OP_breg27";
7674 return "DW_OP_breg28";
7676 return "DW_OP_breg29";
7678 return "DW_OP_breg30";
7680 return "DW_OP_breg31";
7682 return "DW_OP_regx";
7684 return "DW_OP_fbreg";
7686 return "DW_OP_bregx";
7688 return "DW_OP_piece";
7689 case DW_OP_deref_size
:
7690 return "DW_OP_deref_size";
7691 case DW_OP_xderef_size
:
7692 return "DW_OP_xderef_size";
7695 /* DWARF 3 extensions. */
7696 case DW_OP_push_object_address
:
7697 return "DW_OP_push_object_address";
7699 return "DW_OP_call2";
7701 return "DW_OP_call4";
7702 case DW_OP_call_ref
:
7703 return "DW_OP_call_ref";
7704 /* GNU extensions. */
7705 case DW_OP_GNU_push_tls_address
:
7706 return "DW_OP_GNU_push_tls_address";
7708 return "OP_<unknown>";
7713 dwarf_bool_name (unsigned mybool
)
7721 /* Convert a DWARF type code into its string name. */
7724 dwarf_type_encoding_name (unsigned enc
)
7728 case DW_ATE_address
:
7729 return "DW_ATE_address";
7730 case DW_ATE_boolean
:
7731 return "DW_ATE_boolean";
7732 case DW_ATE_complex_float
:
7733 return "DW_ATE_complex_float";
7735 return "DW_ATE_float";
7737 return "DW_ATE_signed";
7738 case DW_ATE_signed_char
:
7739 return "DW_ATE_signed_char";
7740 case DW_ATE_unsigned
:
7741 return "DW_ATE_unsigned";
7742 case DW_ATE_unsigned_char
:
7743 return "DW_ATE_unsigned_char";
7744 case DW_ATE_imaginary_float
:
7745 return "DW_ATE_imaginary_float";
7747 return "DW_ATE_<unknown>";
7751 /* Convert a DWARF call frame info operation to its string name. */
7755 dwarf_cfi_name (unsigned cfi_opc
)
7759 case DW_CFA_advance_loc
:
7760 return "DW_CFA_advance_loc";
7762 return "DW_CFA_offset";
7763 case DW_CFA_restore
:
7764 return "DW_CFA_restore";
7766 return "DW_CFA_nop";
7767 case DW_CFA_set_loc
:
7768 return "DW_CFA_set_loc";
7769 case DW_CFA_advance_loc1
:
7770 return "DW_CFA_advance_loc1";
7771 case DW_CFA_advance_loc2
:
7772 return "DW_CFA_advance_loc2";
7773 case DW_CFA_advance_loc4
:
7774 return "DW_CFA_advance_loc4";
7775 case DW_CFA_offset_extended
:
7776 return "DW_CFA_offset_extended";
7777 case DW_CFA_restore_extended
:
7778 return "DW_CFA_restore_extended";
7779 case DW_CFA_undefined
:
7780 return "DW_CFA_undefined";
7781 case DW_CFA_same_value
:
7782 return "DW_CFA_same_value";
7783 case DW_CFA_register
:
7784 return "DW_CFA_register";
7785 case DW_CFA_remember_state
:
7786 return "DW_CFA_remember_state";
7787 case DW_CFA_restore_state
:
7788 return "DW_CFA_restore_state";
7789 case DW_CFA_def_cfa
:
7790 return "DW_CFA_def_cfa";
7791 case DW_CFA_def_cfa_register
:
7792 return "DW_CFA_def_cfa_register";
7793 case DW_CFA_def_cfa_offset
:
7794 return "DW_CFA_def_cfa_offset";
7797 case DW_CFA_def_cfa_expression
:
7798 return "DW_CFA_def_cfa_expression";
7799 case DW_CFA_expression
:
7800 return "DW_CFA_expression";
7801 case DW_CFA_offset_extended_sf
:
7802 return "DW_CFA_offset_extended_sf";
7803 case DW_CFA_def_cfa_sf
:
7804 return "DW_CFA_def_cfa_sf";
7805 case DW_CFA_def_cfa_offset_sf
:
7806 return "DW_CFA_def_cfa_offset_sf";
7808 /* SGI/MIPS specific */
7809 case DW_CFA_MIPS_advance_loc8
:
7810 return "DW_CFA_MIPS_advance_loc8";
7812 /* GNU extensions */
7813 case DW_CFA_GNU_window_save
:
7814 return "DW_CFA_GNU_window_save";
7815 case DW_CFA_GNU_args_size
:
7816 return "DW_CFA_GNU_args_size";
7817 case DW_CFA_GNU_negative_offset_extended
:
7818 return "DW_CFA_GNU_negative_offset_extended";
7821 return "DW_CFA_<unknown>";
7827 dump_die (struct die_info
*die
)
7831 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
7832 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
7833 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
7834 dwarf_bool_name (die
->child
!= NULL
));
7836 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
7837 for (i
= 0; i
< die
->num_attrs
; ++i
)
7839 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
7840 dwarf_attr_name (die
->attrs
[i
].name
),
7841 dwarf_form_name (die
->attrs
[i
].form
));
7842 switch (die
->attrs
[i
].form
)
7844 case DW_FORM_ref_addr
:
7846 fprintf_unfiltered (gdb_stderr
, "address: ");
7847 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
7849 case DW_FORM_block2
:
7850 case DW_FORM_block4
:
7852 case DW_FORM_block1
:
7853 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
7864 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
7866 case DW_FORM_string
:
7868 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
7869 DW_STRING (&die
->attrs
[i
])
7870 ? DW_STRING (&die
->attrs
[i
]) : "");
7873 if (DW_UNSND (&die
->attrs
[i
]))
7874 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
7876 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
7878 case DW_FORM_indirect
:
7879 /* the reader will have reduced the indirect form to
7880 the "base form" so this form should not occur */
7881 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
7884 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
7885 die
->attrs
[i
].form
);
7887 fprintf_unfiltered (gdb_stderr
, "\n");
7892 dump_die_list (struct die_info
*die
)
7897 if (die
->child
!= NULL
)
7898 dump_die_list (die
->child
);
7899 if (die
->sibling
!= NULL
)
7900 dump_die_list (die
->sibling
);
7905 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
7908 struct die_info
*old
;
7910 h
= (offset
% REF_HASH_SIZE
);
7911 old
= die_ref_table
[h
];
7912 die
->next_ref
= old
;
7913 die_ref_table
[h
] = die
;
7918 dwarf2_empty_hash_tables (void)
7920 memset (die_ref_table
, 0, sizeof (die_ref_table
));
7924 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
7926 unsigned int result
= 0;
7930 case DW_FORM_ref_addr
:
7931 result
= DW_ADDR (attr
);
7937 case DW_FORM_ref_udata
:
7938 result
= cu
->header
.offset
+ DW_UNSND (attr
);
7941 complaint (&symfile_complaints
,
7942 "unsupported die ref attribute form: '%s'",
7943 dwarf_form_name (attr
->form
));
7948 /* Return the constant value held by the given attribute. Return -1
7949 if the value held by the attribute is not constant. */
7952 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
7954 if (attr
->form
== DW_FORM_sdata
)
7955 return DW_SND (attr
);
7956 else if (attr
->form
== DW_FORM_udata
7957 || attr
->form
== DW_FORM_data1
7958 || attr
->form
== DW_FORM_data2
7959 || attr
->form
== DW_FORM_data4
7960 || attr
->form
== DW_FORM_data8
)
7961 return DW_UNSND (attr
);
7964 complaint (&symfile_complaints
, "Attribute value is not a constant (%s)",
7965 dwarf_form_name (attr
->form
));
7966 return default_value
;
7970 static struct die_info
*
7971 follow_die_ref (unsigned int offset
)
7973 struct die_info
*die
;
7976 h
= (offset
% REF_HASH_SIZE
);
7977 die
= die_ref_table
[h
];
7980 if (die
->offset
== offset
)
7984 die
= die
->next_ref
;
7989 static struct type
*
7990 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid,
7991 struct dwarf2_cu
*cu
)
7993 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
7995 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
7996 typeid, objfile
->name
);
7999 /* Look for this particular type in the fundamental type vector. If
8000 one is not found, create and install one appropriate for the
8001 current language and the current target machine. */
8003 if (cu
->ftypes
[typeid] == NULL
)
8005 cu
->ftypes
[typeid] = cu
->language_defn
->la_fund_type (objfile
, typeid);
8008 return (cu
->ftypes
[typeid]);
8011 /* Decode simple location descriptions.
8012 Given a pointer to a dwarf block that defines a location, compute
8013 the location and return the value.
8015 NOTE drow/2003-11-18: This function is called in two situations
8016 now: for the address of static or global variables (partial symbols
8017 only) and for offsets into structures which are expected to be
8018 (more or less) constant. The partial symbol case should go away,
8019 and only the constant case should remain. That will let this
8020 function complain more accurately. A few special modes are allowed
8021 without complaint for global variables (for instance, global
8022 register values and thread-local values).
8024 A location description containing no operations indicates that the
8025 object is optimized out. The return value is 0 for that case.
8026 FIXME drow/2003-11-16: No callers check for this case any more; soon all
8027 callers will only want a very basic result and this can become a
8030 When the result is a register number, the global isreg flag is set,
8031 otherwise it is cleared.
8033 Note that stack[0] is unused except as a default error return.
8034 Note that stack overflow is not yet handled. */
8037 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
8039 struct objfile
*objfile
= cu
->objfile
;
8040 struct comp_unit_head
*cu_header
= &cu
->header
;
8042 int size
= blk
->size
;
8043 char *data
= blk
->data
;
8044 CORE_ADDR stack
[64];
8046 unsigned int bytes_read
, unsnd
;
8091 stack
[++stacki
] = op
- DW_OP_lit0
;
8127 stack
[++stacki
] = op
- DW_OP_reg0
;
8129 dwarf2_complex_location_expr_complaint ();
8134 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
8136 stack
[++stacki
] = unsnd
;
8138 dwarf2_complex_location_expr_complaint ();
8142 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
8148 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
8153 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
8158 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
8163 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
8168 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
8173 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
8178 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
8184 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
8189 stack
[stacki
+ 1] = stack
[stacki
];
8194 stack
[stacki
- 1] += stack
[stacki
];
8198 case DW_OP_plus_uconst
:
8199 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
8204 stack
[stacki
- 1] -= stack
[stacki
];
8209 /* If we're not the last op, then we definitely can't encode
8210 this using GDB's address_class enum. This is valid for partial
8211 global symbols, although the variable's address will be bogus
8214 dwarf2_complex_location_expr_complaint ();
8217 case DW_OP_GNU_push_tls_address
:
8218 /* The top of the stack has the offset from the beginning
8219 of the thread control block at which the variable is located. */
8220 /* Nothing should follow this operator, so the top of stack would
8222 /* This is valid for partial global symbols, but the variable's
8223 address will be bogus in the psymtab. */
8225 dwarf2_complex_location_expr_complaint ();
8229 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
8230 dwarf_stack_op_name (op
));
8231 return (stack
[stacki
]);
8234 return (stack
[stacki
]);
8237 /* memory allocation interface */
8239 static struct dwarf_block
*
8240 dwarf_alloc_block (struct dwarf2_cu
*cu
)
8242 struct dwarf_block
*blk
;
8244 blk
= (struct dwarf_block
*)
8245 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
8249 static struct abbrev_info
*
8250 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
8252 struct abbrev_info
*abbrev
;
8254 abbrev
= (struct abbrev_info
*)
8255 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
8256 memset (abbrev
, 0, sizeof (struct abbrev_info
));
8260 static struct die_info
*
8261 dwarf_alloc_die (void)
8263 struct die_info
*die
;
8265 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
8266 memset (die
, 0, sizeof (struct die_info
));
8271 /* Macro support. */
8274 /* Return the full name of file number I in *LH's file name table.
8275 Use COMP_DIR as the name of the current directory of the
8276 compilation. The result is allocated using xmalloc; the caller is
8277 responsible for freeing it. */
8279 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
8281 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
8283 if (IS_ABSOLUTE_PATH (fe
->name
))
8284 return xstrdup (fe
->name
);
8292 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8298 dir_len
= strlen (dir
);
8299 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
8300 strcpy (full_name
, dir
);
8301 full_name
[dir_len
] = '/';
8302 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
8306 return xstrdup (fe
->name
);
8311 static struct macro_source_file
*
8312 macro_start_file (int file
, int line
,
8313 struct macro_source_file
*current_file
,
8314 const char *comp_dir
,
8315 struct line_header
*lh
, struct objfile
*objfile
)
8317 /* The full name of this source file. */
8318 char *full_name
= file_full_name (file
, lh
, comp_dir
);
8320 /* We don't create a macro table for this compilation unit
8321 at all until we actually get a filename. */
8322 if (! pending_macros
)
8323 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
8324 objfile
->macro_cache
);
8327 /* If we have no current file, then this must be the start_file
8328 directive for the compilation unit's main source file. */
8329 current_file
= macro_set_main (pending_macros
, full_name
);
8331 current_file
= macro_include (current_file
, line
, full_name
);
8335 return current_file
;
8339 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
8340 followed by a null byte. */
8342 copy_string (const char *buf
, int len
)
8344 char *s
= xmalloc (len
+ 1);
8345 memcpy (s
, buf
, len
);
8353 consume_improper_spaces (const char *p
, const char *body
)
8357 complaint (&symfile_complaints
,
8358 "macro definition contains spaces in formal argument list:\n`%s'",
8370 parse_macro_definition (struct macro_source_file
*file
, int line
,
8375 /* The body string takes one of two forms. For object-like macro
8376 definitions, it should be:
8378 <macro name> " " <definition>
8380 For function-like macro definitions, it should be:
8382 <macro name> "() " <definition>
8384 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
8386 Spaces may appear only where explicitly indicated, and in the
8389 The Dwarf 2 spec says that an object-like macro's name is always
8390 followed by a space, but versions of GCC around March 2002 omit
8391 the space when the macro's definition is the empty string.
8393 The Dwarf 2 spec says that there should be no spaces between the
8394 formal arguments in a function-like macro's formal argument list,
8395 but versions of GCC around March 2002 include spaces after the
8399 /* Find the extent of the macro name. The macro name is terminated
8400 by either a space or null character (for an object-like macro) or
8401 an opening paren (for a function-like macro). */
8402 for (p
= body
; *p
; p
++)
8403 if (*p
== ' ' || *p
== '(')
8406 if (*p
== ' ' || *p
== '\0')
8408 /* It's an object-like macro. */
8409 int name_len
= p
- body
;
8410 char *name
= copy_string (body
, name_len
);
8411 const char *replacement
;
8414 replacement
= body
+ name_len
+ 1;
8417 dwarf2_macro_malformed_definition_complaint (body
);
8418 replacement
= body
+ name_len
;
8421 macro_define_object (file
, line
, name
, replacement
);
8427 /* It's a function-like macro. */
8428 char *name
= copy_string (body
, p
- body
);
8431 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
8435 p
= consume_improper_spaces (p
, body
);
8437 /* Parse the formal argument list. */
8438 while (*p
&& *p
!= ')')
8440 /* Find the extent of the current argument name. */
8441 const char *arg_start
= p
;
8443 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
8446 if (! *p
|| p
== arg_start
)
8447 dwarf2_macro_malformed_definition_complaint (body
);
8450 /* Make sure argv has room for the new argument. */
8451 if (argc
>= argv_size
)
8454 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
8457 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
8460 p
= consume_improper_spaces (p
, body
);
8462 /* Consume the comma, if present. */
8467 p
= consume_improper_spaces (p
, body
);
8476 /* Perfectly formed definition, no complaints. */
8477 macro_define_function (file
, line
, name
,
8478 argc
, (const char **) argv
,
8480 else if (*p
== '\0')
8482 /* Complain, but do define it. */
8483 dwarf2_macro_malformed_definition_complaint (body
);
8484 macro_define_function (file
, line
, name
,
8485 argc
, (const char **) argv
,
8489 /* Just complain. */
8490 dwarf2_macro_malformed_definition_complaint (body
);
8493 /* Just complain. */
8494 dwarf2_macro_malformed_definition_complaint (body
);
8500 for (i
= 0; i
< argc
; i
++)
8506 dwarf2_macro_malformed_definition_complaint (body
);
8511 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
8512 char *comp_dir
, bfd
*abfd
,
8513 struct dwarf2_cu
*cu
)
8515 char *mac_ptr
, *mac_end
;
8516 struct macro_source_file
*current_file
= 0;
8518 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
8520 complaint (&symfile_complaints
, "missing .debug_macinfo section");
8524 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
8525 mac_end
= dwarf2_per_objfile
->macinfo_buffer
8526 + dwarf2_per_objfile
->macinfo_size
;
8530 enum dwarf_macinfo_record_type macinfo_type
;
8532 /* Do we at least have room for a macinfo type byte? */
8533 if (mac_ptr
>= mac_end
)
8535 dwarf2_macros_too_long_complaint ();
8539 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
8542 switch (macinfo_type
)
8544 /* A zero macinfo type indicates the end of the macro
8549 case DW_MACINFO_define
:
8550 case DW_MACINFO_undef
:
8556 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8557 mac_ptr
+= bytes_read
;
8558 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
8559 mac_ptr
+= bytes_read
;
8562 complaint (&symfile_complaints
,
8563 "debug info gives macro %s outside of any file: %s",
8565 DW_MACINFO_define
? "definition" : macinfo_type
==
8566 DW_MACINFO_undef
? "undefinition" :
8567 "something-or-other", body
);
8570 if (macinfo_type
== DW_MACINFO_define
)
8571 parse_macro_definition (current_file
, line
, body
);
8572 else if (macinfo_type
== DW_MACINFO_undef
)
8573 macro_undef (current_file
, line
, body
);
8578 case DW_MACINFO_start_file
:
8583 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8584 mac_ptr
+= bytes_read
;
8585 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8586 mac_ptr
+= bytes_read
;
8588 current_file
= macro_start_file (file
, line
,
8589 current_file
, comp_dir
,
8594 case DW_MACINFO_end_file
:
8596 complaint (&symfile_complaints
,
8597 "macro debug info has an unmatched `close_file' directive");
8600 current_file
= current_file
->included_by
;
8603 enum dwarf_macinfo_record_type next_type
;
8605 /* GCC circa March 2002 doesn't produce the zero
8606 type byte marking the end of the compilation
8607 unit. Complain if it's not there, but exit no
8610 /* Do we at least have room for a macinfo type byte? */
8611 if (mac_ptr
>= mac_end
)
8613 dwarf2_macros_too_long_complaint ();
8617 /* We don't increment mac_ptr here, so this is just
8619 next_type
= read_1_byte (abfd
, mac_ptr
);
8621 complaint (&symfile_complaints
,
8622 "no terminating 0-type entry for macros in `.debug_macinfo' section");
8629 case DW_MACINFO_vendor_ext
:
8635 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8636 mac_ptr
+= bytes_read
;
8637 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
8638 mac_ptr
+= bytes_read
;
8640 /* We don't recognize any vendor extensions. */
8647 /* Check if the attribute's form is a DW_FORM_block*
8648 if so return true else false. */
8650 attr_form_is_block (struct attribute
*attr
)
8652 return (attr
== NULL
? 0 :
8653 attr
->form
== DW_FORM_block1
8654 || attr
->form
== DW_FORM_block2
8655 || attr
->form
== DW_FORM_block4
8656 || attr
->form
== DW_FORM_block
);
8660 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
8661 struct dwarf2_cu
*cu
)
8663 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
8665 struct dwarf2_loclist_baton
*baton
;
8667 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
8668 sizeof (struct dwarf2_loclist_baton
));
8669 baton
->objfile
= cu
->objfile
;
8671 /* We don't know how long the location list is, but make sure we
8672 don't run off the edge of the section. */
8673 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
8674 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
8675 baton
->base_address
= cu
->header
.base_address
;
8676 if (cu
->header
.base_known
== 0)
8677 complaint (&symfile_complaints
,
8678 "Location list used without specifying the CU base address.");
8680 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
8681 SYMBOL_LOCATION_BATON (sym
) = baton
;
8685 struct dwarf2_locexpr_baton
*baton
;
8687 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
8688 sizeof (struct dwarf2_locexpr_baton
));
8689 baton
->objfile
= cu
->objfile
;
8691 if (attr_form_is_block (attr
))
8693 /* Note that we're just copying the block's data pointer
8694 here, not the actual data. We're still pointing into the
8695 info_buffer for SYM's objfile; right now we never release
8696 that buffer, but when we do clean up properly this may
8698 baton
->size
= DW_BLOCK (attr
)->size
;
8699 baton
->data
= DW_BLOCK (attr
)->data
;
8703 dwarf2_invalid_attrib_class_complaint ("location description",
8704 SYMBOL_NATURAL_NAME (sym
));
8709 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
8710 SYMBOL_LOCATION_BATON (sym
) = baton
;
8714 /* This cleanup function is passed the address of a dwarf2_cu on the stack
8715 when we're finished with it. We can't free the pointer itself, but
8716 release any associated storage.
8718 Only used during partial symbol parsing. */
8721 free_stack_comp_unit (void *data
)
8723 struct dwarf2_cu
*cu
= data
;
8725 obstack_free (&cu
->comp_unit_obstack
, NULL
);
8726 cu
->partial_dies
= NULL
;
8729 /* Allocation function for the libiberty hash table which uses an
8733 hashtab_obstack_allocate (void *data
, size_t size
, size_t count
)
8735 unsigned int total
= size
* count
;
8736 void *ptr
= obstack_alloc ((struct obstack
*) data
, total
);
8737 memset (ptr
, 0, total
);
8741 /* Trivial deallocation function for the libiberty splay tree and hash
8742 table - don't deallocate anything. Rely on later deletion of the
8746 dummy_obstack_deallocate (void *object
, void *data
)
8751 /* Trivial hash function for partial_die_info: the hash value of a DIE
8752 is its offset in .debug_info for this objfile. */
8755 partial_die_hash (const void *item
)
8757 const struct partial_die_info
*part_die
= item
;
8758 return part_die
->offset
;
8761 /* Trivial comparison function for partial_die_info structures: two DIEs
8762 are equal if they have the same offset. */
8765 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
8767 const struct partial_die_info
*part_die_lhs
= item_lhs
;
8768 const struct partial_die_info
*part_die_rhs
= item_rhs
;
8769 return part_die_lhs
->offset
== part_die_rhs
->offset
;
8772 void _initialize_dwarf2_read (void);
8775 _initialize_dwarf2_read (void)
8777 dwarf2_objfile_data_key
= register_objfile_data ();