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 const char *producer
;
267 /* The generic symbol table building routines have separate lists for
268 file scope symbols and all all other scopes (local scopes). So
269 we need to select the right one to pass to add_symbol_to_list().
270 We do it by keeping a pointer to the correct list in list_in_scope.
272 FIXME: The original dwarf code just treated the file scope as the
273 first local scope, and all other local scopes as nested local
274 scopes, and worked fine. Check to see if we really need to
275 distinguish these in buildsym.c. */
276 struct pending
**list_in_scope
;
278 /* Maintain an array of referenced fundamental types for the current
279 compilation unit being read. For DWARF version 1, we have to construct
280 the fundamental types on the fly, since no information about the
281 fundamental types is supplied. Each such fundamental type is created by
282 calling a language dependent routine to create the type, and then a
283 pointer to that type is then placed in the array at the index specified
284 by it's FT_<TYPENAME> value. The array has a fixed size set by the
285 FT_NUM_MEMBERS compile time constant, which is the number of predefined
286 fundamental types gdb knows how to construct. */
287 struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
289 /* DWARF abbreviation table associated with this compilation unit. */
290 struct abbrev_info
**dwarf2_abbrevs
;
292 /* Storage for the abbrev table. */
293 struct obstack abbrev_obstack
;
295 /* Hash table holding all the loaded partial DIEs. */
298 /* Storage for things with the same lifetime as this read-in compilation
299 unit, including partial DIEs. */
300 struct obstack comp_unit_obstack
;
302 /* This flag will be set if this compilation unit includes any
303 DW_TAG_namespace DIEs. If we know that there are explicit
304 DIEs for namespaces, we don't need to try to infer them
305 from mangled names. */
306 unsigned int has_namespace_info
: 1;
309 /* The line number information for a compilation unit (found in the
310 .debug_line section) begins with a "statement program header",
311 which contains the following information. */
314 unsigned int total_length
;
315 unsigned short version
;
316 unsigned int header_length
;
317 unsigned char minimum_instruction_length
;
318 unsigned char default_is_stmt
;
320 unsigned char line_range
;
321 unsigned char opcode_base
;
323 /* standard_opcode_lengths[i] is the number of operands for the
324 standard opcode whose value is i. This means that
325 standard_opcode_lengths[0] is unused, and the last meaningful
326 element is standard_opcode_lengths[opcode_base - 1]. */
327 unsigned char *standard_opcode_lengths
;
329 /* The include_directories table. NOTE! These strings are not
330 allocated with xmalloc; instead, they are pointers into
331 debug_line_buffer. If you try to free them, `free' will get
333 unsigned int num_include_dirs
, include_dirs_size
;
336 /* The file_names table. NOTE! These strings are not allocated
337 with xmalloc; instead, they are pointers into debug_line_buffer.
338 Don't try to free them directly. */
339 unsigned int num_file_names
, file_names_size
;
343 unsigned int dir_index
;
344 unsigned int mod_time
;
346 int included_p
; /* Non-zero if referenced by the Line Number Program. */
349 /* The start and end of the statement program following this
350 header. These point into dwarf2_per_objfile->line_buffer. */
351 char *statement_program_start
, *statement_program_end
;
354 /* When we construct a partial symbol table entry we only
355 need this much information. */
356 struct partial_die_info
358 /* Offset of this DIE. */
361 /* DWARF-2 tag for this DIE. */
362 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
364 /* Language code associated with this DIE. This is only used
365 for the compilation unit DIE. */
366 unsigned int language
: 8;
368 /* Assorted flags describing the data found in this DIE. */
369 unsigned int has_children
: 1;
370 unsigned int is_external
: 1;
371 unsigned int is_declaration
: 1;
372 unsigned int has_type
: 1;
373 unsigned int has_specification
: 1;
374 unsigned int has_stmt_list
: 1;
375 unsigned int has_pc_info
: 1;
377 /* Flag set if the SCOPE field of this structure has been
379 unsigned int scope_set
: 1;
381 /* The name of this DIE. Normally the value of DW_AT_name, but
382 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
387 /* The scope to prepend to our children. This is generally
388 allocated on the comp_unit_obstack, so will disappear
389 when this compilation unit leaves the cache. */
392 /* The location description associated with this DIE, if any. */
393 struct dwarf_block
*locdesc
;
395 /* If HAS_PC_INFO, the PC range associated with this DIE. */
399 /* Pointer into the info_buffer pointing at the target of
400 DW_AT_sibling, if any. */
403 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
404 DW_AT_specification (or DW_AT_abstract_origin or
406 unsigned int spec_offset
;
408 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
409 unsigned int line_offset
;
411 /* Pointers to this DIE's parent, first child, and next sibling,
413 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
416 /* This data structure holds the information of an abbrev. */
419 unsigned int number
; /* number identifying abbrev */
420 enum dwarf_tag tag
; /* dwarf tag */
421 unsigned short has_children
; /* boolean */
422 unsigned short num_attrs
; /* number of attributes */
423 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
424 struct abbrev_info
*next
; /* next in chain */
429 enum dwarf_attribute name
;
430 enum dwarf_form form
;
433 /* This data structure holds a complete die structure. */
436 enum dwarf_tag tag
; /* Tag indicating type of die */
437 unsigned int abbrev
; /* Abbrev number */
438 unsigned int offset
; /* Offset in .debug_info section */
439 unsigned int num_attrs
; /* Number of attributes */
440 struct attribute
*attrs
; /* An array of attributes */
441 struct die_info
*next_ref
; /* Next die in ref hash table */
443 /* The dies in a compilation unit form an n-ary tree. PARENT
444 points to this die's parent; CHILD points to the first child of
445 this node; and all the children of a given node are chained
446 together via their SIBLING fields, terminated by a die whose
448 struct die_info
*child
; /* Its first child, if any. */
449 struct die_info
*sibling
; /* Its next sibling, if any. */
450 struct die_info
*parent
; /* Its parent, if any. */
452 struct type
*type
; /* Cached type information */
455 /* Attributes have a name and a value */
458 enum dwarf_attribute name
;
459 enum dwarf_form form
;
463 struct dwarf_block
*blk
;
471 struct function_range
474 CORE_ADDR lowpc
, highpc
;
476 struct function_range
*next
;
479 /* Get at parts of an attribute structure */
481 #define DW_STRING(attr) ((attr)->u.str)
482 #define DW_UNSND(attr) ((attr)->u.unsnd)
483 #define DW_BLOCK(attr) ((attr)->u.blk)
484 #define DW_SND(attr) ((attr)->u.snd)
485 #define DW_ADDR(attr) ((attr)->u.addr)
487 /* Blocks are a bunch of untyped bytes. */
494 #ifndef ATTR_ALLOC_CHUNK
495 #define ATTR_ALLOC_CHUNK 4
498 /* A hash table of die offsets for following references. */
499 #ifndef REF_HASH_SIZE
500 #define REF_HASH_SIZE 1021
503 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
505 /* Allocate fields for structs, unions and enums in this size. */
506 #ifndef DW_FIELD_ALLOC_CHUNK
507 #define DW_FIELD_ALLOC_CHUNK 4
510 /* A zeroed version of a partial die for initialization purposes. */
511 static struct partial_die_info zeroed_partial_die
;
513 /* FIXME: decode_locdesc sets these variables to describe the location
514 to the caller. These ought to be a structure or something. If
515 none of the flags are set, the object lives at the address returned
516 by decode_locdesc. */
518 static int isreg
; /* Object lives in register.
519 decode_locdesc's return value is
520 the register number. */
522 /* We put a pointer to this structure in the read_symtab_private field
527 /* Offset in .debug_info for this compilation unit. */
529 unsigned long dwarf_info_offset
;
532 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
533 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
535 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
536 but this would require a corresponding change in unpack_field_as_long
538 static int bits_per_byte
= 8;
540 /* The routines that read and process dies for a C struct or C++ class
541 pass lists of data member fields and lists of member function fields
542 in an instance of a field_info structure, as defined below. */
545 /* List of data member and baseclasses fields. */
548 struct nextfield
*next
;
555 /* Number of fields. */
558 /* Number of baseclasses. */
561 /* Set if the accesibility of one of the fields is not public. */
562 int non_public_fields
;
564 /* Member function fields array, entries are allocated in the order they
565 are encountered in the object file. */
568 struct nextfnfield
*next
;
569 struct fn_field fnfield
;
573 /* Member function fieldlist array, contains name of possibly overloaded
574 member function, number of overloaded member functions and a pointer
575 to the head of the member function field chain. */
580 struct nextfnfield
*head
;
584 /* Number of entries in the fnfieldlists array. */
588 /* Various complaints about symbol reading that don't abort the process */
591 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
593 complaint (&symfile_complaints
,
594 "statement list doesn't fit in .debug_line section");
598 dwarf2_complex_location_expr_complaint (void)
600 complaint (&symfile_complaints
, "location expression too complex");
604 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
607 complaint (&symfile_complaints
,
608 "const value length mismatch for '%s', got %d, expected %d", arg1
,
613 dwarf2_macros_too_long_complaint (void)
615 complaint (&symfile_complaints
,
616 "macro info runs off end of `.debug_macinfo' section");
620 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
622 complaint (&symfile_complaints
,
623 "macro debug info contains a malformed macro definition:\n`%s'",
628 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
630 complaint (&symfile_complaints
,
631 "invalid attribute class or form for '%s' in '%s'", arg1
, arg2
);
634 /* local function prototypes */
636 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
639 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
642 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
645 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
646 struct partial_die_info
*,
647 struct partial_symtab
*);
649 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
651 static void scan_partial_symbols (struct partial_die_info
*,
652 CORE_ADDR
*, CORE_ADDR
*,
655 static void add_partial_symbol (struct partial_die_info
*,
658 static int pdi_needs_namespace (enum dwarf_tag tag
);
660 static void add_partial_namespace (struct partial_die_info
*pdi
,
661 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
662 struct dwarf2_cu
*cu
);
664 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
665 struct dwarf2_cu
*cu
);
667 static char *locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
670 struct dwarf2_cu
*cu
);
672 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
674 static void psymtab_to_symtab_1 (struct partial_symtab
*);
676 char *dwarf2_read_section (struct objfile
*, asection
*);
678 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
680 static void dwarf2_free_abbrev_table (void *);
682 static struct abbrev_info
*peek_die_abbrev (char *, int *, struct dwarf2_cu
*);
684 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
687 static struct partial_die_info
*load_partial_dies (bfd
*, char *, int,
690 static char *read_partial_die (struct partial_die_info
*,
691 struct abbrev_info
*abbrev
, unsigned int,
692 bfd
*, char *, struct dwarf2_cu
*);
694 static struct partial_die_info
*find_partial_die (unsigned long,
696 struct dwarf2_cu
**);
698 static void fixup_partial_die (struct partial_die_info
*,
701 static char *read_full_die (struct die_info
**, bfd
*, char *,
702 struct dwarf2_cu
*, int *);
704 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
705 bfd
*, char *, struct dwarf2_cu
*);
707 static char *read_attribute_value (struct attribute
*, unsigned,
708 bfd
*, char *, struct dwarf2_cu
*);
710 static unsigned int read_1_byte (bfd
*, char *);
712 static int read_1_signed_byte (bfd
*, char *);
714 static unsigned int read_2_bytes (bfd
*, char *);
716 static unsigned int read_4_bytes (bfd
*, char *);
718 static unsigned long read_8_bytes (bfd
*, char *);
720 static CORE_ADDR
read_address (bfd
*, char *ptr
, struct dwarf2_cu
*,
723 static LONGEST
read_initial_length (bfd
*, char *,
724 struct comp_unit_head
*, int *bytes_read
);
726 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
729 static char *read_n_bytes (bfd
*, char *, unsigned int);
731 static char *read_string (bfd
*, char *, unsigned int *);
733 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
736 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
738 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
740 static char *skip_leb128 (bfd
*, char *);
742 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
744 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
747 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
748 struct dwarf2_cu
*cu
);
750 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
752 static struct die_info
*die_specification (struct die_info
*die
,
755 static void free_line_header (struct line_header
*lh
);
757 static void add_file_name (struct line_header
*, char *, unsigned int,
758 unsigned int, unsigned int);
760 static struct line_header
*(dwarf_decode_line_header
761 (unsigned int offset
,
762 bfd
*abfd
, struct dwarf2_cu
*cu
));
764 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
765 struct dwarf2_cu
*, struct partial_symtab
*);
767 static void dwarf2_start_subfile (char *, char *);
769 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
772 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
775 static void dwarf2_const_value_data (struct attribute
*attr
,
779 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
781 static struct type
*die_containing_type (struct die_info
*,
785 static struct type
*type_at_offset (unsigned int, struct objfile
*);
788 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
790 static void read_type_die (struct die_info
*, struct dwarf2_cu
*);
792 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
794 static char *typename_concat (const char *prefix
, const char *suffix
);
796 static void read_typedef (struct die_info
*, struct dwarf2_cu
*);
798 static void read_base_type (struct die_info
*, struct dwarf2_cu
*);
800 static void read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
802 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
804 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
806 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
808 static int dwarf2_get_pc_bounds (struct die_info
*,
809 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
811 static void get_scope_pc_bounds (struct die_info
*,
812 CORE_ADDR
*, CORE_ADDR
*,
815 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
818 static void dwarf2_attach_fields_to_type (struct field_info
*,
819 struct type
*, struct dwarf2_cu
*);
821 static void dwarf2_add_member_fn (struct field_info
*,
822 struct die_info
*, struct type
*,
825 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
826 struct type
*, struct dwarf2_cu
*);
828 static void read_structure_type (struct die_info
*, struct dwarf2_cu
*);
830 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
832 static char *determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
834 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
836 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
838 static const char *namespace_name (struct die_info
*die
,
839 int *is_anonymous
, struct dwarf2_cu
*);
841 static void read_enumeration_type (struct die_info
*, struct dwarf2_cu
*);
843 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
845 static struct type
*dwarf_base_type (int, int, struct dwarf2_cu
*);
847 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
849 static void read_array_type (struct die_info
*, struct dwarf2_cu
*);
851 static void read_tag_pointer_type (struct die_info
*, struct dwarf2_cu
*);
853 static void read_tag_ptr_to_member_type (struct die_info
*,
856 static void read_tag_reference_type (struct die_info
*, struct dwarf2_cu
*);
858 static void read_tag_const_type (struct die_info
*, struct dwarf2_cu
*);
860 static void read_tag_volatile_type (struct die_info
*, struct dwarf2_cu
*);
862 static void read_tag_string_type (struct die_info
*, struct dwarf2_cu
*);
864 static void read_subroutine_type (struct die_info
*, struct dwarf2_cu
*);
866 static struct die_info
*read_comp_unit (char *, bfd
*, struct dwarf2_cu
*);
868 static struct die_info
*read_die_and_children (char *info_ptr
, bfd
*abfd
,
871 struct die_info
*parent
);
873 static struct die_info
*read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
876 struct die_info
*parent
);
878 static void free_die_list (struct die_info
*);
880 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
882 static void process_die (struct die_info
*, struct dwarf2_cu
*);
884 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
886 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
888 static struct die_info
*dwarf2_extension (struct die_info
*die
,
891 static char *dwarf_tag_name (unsigned int);
893 static char *dwarf_attr_name (unsigned int);
895 static char *dwarf_form_name (unsigned int);
897 static char *dwarf_stack_op_name (unsigned int);
899 static char *dwarf_bool_name (unsigned int);
901 static char *dwarf_type_encoding_name (unsigned int);
904 static char *dwarf_cfi_name (unsigned int);
906 struct die_info
*copy_die (struct die_info
*);
909 static struct die_info
*sibling_die (struct die_info
*);
911 static void dump_die (struct die_info
*);
913 static void dump_die_list (struct die_info
*);
915 static void store_in_ref_table (unsigned int, struct die_info
*);
917 static void dwarf2_empty_hash_tables (void);
919 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
922 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
924 static struct die_info
*follow_die_ref (unsigned int);
926 static struct type
*dwarf2_fundamental_type (struct objfile
*, int,
929 /* memory allocation interface */
931 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
933 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
935 static struct die_info
*dwarf_alloc_die (void);
937 static void initialize_cu_func_list (struct dwarf2_cu
*);
939 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
942 static void dwarf_decode_macros (struct line_header
*, unsigned int,
943 char *, bfd
*, struct dwarf2_cu
*);
945 static int attr_form_is_block (struct attribute
*);
948 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
949 struct dwarf2_cu
*cu
);
951 static char *skip_one_die (char *info_ptr
, struct abbrev_info
*abbrev
,
952 struct dwarf2_cu
*cu
);
954 static void free_stack_comp_unit (void *);
956 static void *hashtab_obstack_allocate (void *data
, size_t size
, size_t count
);
958 static void dummy_obstack_deallocate (void *object
, void *data
);
960 static hashval_t
partial_die_hash (const void *item
);
962 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
964 /* Try to locate the sections we need for DWARF 2 debugging
965 information and return true if we have enough to do something. */
968 dwarf2_has_info (struct objfile
*objfile
)
970 struct dwarf2_per_objfile
*data
;
972 /* Initialize per-objfile state. */
973 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
974 memset (data
, 0, sizeof (*data
));
975 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
976 dwarf2_per_objfile
= data
;
978 dwarf_info_section
= 0;
979 dwarf_abbrev_section
= 0;
980 dwarf_line_section
= 0;
981 dwarf_str_section
= 0;
982 dwarf_macinfo_section
= 0;
983 dwarf_frame_section
= 0;
984 dwarf_eh_frame_section
= 0;
985 dwarf_ranges_section
= 0;
986 dwarf_loc_section
= 0;
988 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
989 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
992 /* This function is mapped across the sections and remembers the
993 offset and size of each of the debugging sections we are interested
997 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
999 if (strcmp (sectp
->name
, INFO_SECTION
) == 0)
1001 dwarf2_per_objfile
->info_size
= bfd_get_section_size (sectp
);
1002 dwarf_info_section
= sectp
;
1004 else if (strcmp (sectp
->name
, ABBREV_SECTION
) == 0)
1006 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size (sectp
);
1007 dwarf_abbrev_section
= sectp
;
1009 else if (strcmp (sectp
->name
, LINE_SECTION
) == 0)
1011 dwarf2_per_objfile
->line_size
= bfd_get_section_size (sectp
);
1012 dwarf_line_section
= sectp
;
1014 else if (strcmp (sectp
->name
, PUBNAMES_SECTION
) == 0)
1016 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size (sectp
);
1017 dwarf_pubnames_section
= sectp
;
1019 else if (strcmp (sectp
->name
, ARANGES_SECTION
) == 0)
1021 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size (sectp
);
1022 dwarf_aranges_section
= sectp
;
1024 else if (strcmp (sectp
->name
, LOC_SECTION
) == 0)
1026 dwarf2_per_objfile
->loc_size
= bfd_get_section_size (sectp
);
1027 dwarf_loc_section
= sectp
;
1029 else if (strcmp (sectp
->name
, MACINFO_SECTION
) == 0)
1031 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size (sectp
);
1032 dwarf_macinfo_section
= sectp
;
1034 else if (strcmp (sectp
->name
, STR_SECTION
) == 0)
1036 dwarf2_per_objfile
->str_size
= bfd_get_section_size (sectp
);
1037 dwarf_str_section
= sectp
;
1039 else if (strcmp (sectp
->name
, FRAME_SECTION
) == 0)
1041 dwarf2_per_objfile
->frame_size
= bfd_get_section_size (sectp
);
1042 dwarf_frame_section
= sectp
;
1044 else if (strcmp (sectp
->name
, EH_FRAME_SECTION
) == 0)
1046 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1047 if (aflag
& SEC_HAS_CONTENTS
)
1049 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size (sectp
);
1050 dwarf_eh_frame_section
= sectp
;
1053 else if (strcmp (sectp
->name
, RANGES_SECTION
) == 0)
1055 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size (sectp
);
1056 dwarf_ranges_section
= sectp
;
1060 /* Build a partial symbol table. */
1063 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1065 /* We definitely need the .debug_info and .debug_abbrev sections */
1067 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1068 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1070 if (dwarf_line_section
)
1071 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1073 dwarf2_per_objfile
->line_buffer
= NULL
;
1075 if (dwarf_str_section
)
1076 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1078 dwarf2_per_objfile
->str_buffer
= NULL
;
1080 if (dwarf_macinfo_section
)
1081 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1082 dwarf_macinfo_section
);
1084 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1086 if (dwarf_ranges_section
)
1087 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1089 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1091 if (dwarf_loc_section
)
1092 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1094 dwarf2_per_objfile
->loc_buffer
= NULL
;
1097 || (objfile
->global_psymbols
.size
== 0
1098 && objfile
->static_psymbols
.size
== 0))
1100 init_psymbol_list (objfile
, 1024);
1104 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1106 /* Things are significantly easier if we have .debug_aranges and
1107 .debug_pubnames sections */
1109 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1113 /* only test this case for now */
1115 /* In this case we have to work a bit harder */
1116 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1121 /* Build the partial symbol table from the information in the
1122 .debug_pubnames and .debug_aranges sections. */
1125 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1127 bfd
*abfd
= objfile
->obfd
;
1128 char *aranges_buffer
, *pubnames_buffer
;
1129 char *aranges_ptr
, *pubnames_ptr
;
1130 unsigned int entry_length
, version
, info_offset
, info_size
;
1132 pubnames_buffer
= dwarf2_read_section (objfile
,
1133 dwarf_pubnames_section
);
1134 pubnames_ptr
= pubnames_buffer
;
1135 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1137 struct comp_unit_head cu_header
;
1140 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1142 pubnames_ptr
+= bytes_read
;
1143 version
= read_1_byte (abfd
, pubnames_ptr
);
1145 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1147 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1151 aranges_buffer
= dwarf2_read_section (objfile
,
1152 dwarf_aranges_section
);
1157 /* Read in the comp unit header information from the debug_info at
1161 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1162 char *info_ptr
, bfd
*abfd
)
1166 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1168 info_ptr
+= bytes_read
;
1169 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1171 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1173 info_ptr
+= bytes_read
;
1174 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1176 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1177 if (signed_addr
< 0)
1178 internal_error (__FILE__
, __LINE__
,
1179 "read_comp_unit_head: dwarf from non elf file");
1180 cu_header
->signed_addr_p
= signed_addr
;
1185 partial_read_comp_unit_head (struct comp_unit_head
*header
, char *info_ptr
,
1188 char *beg_of_comp_unit
= info_ptr
;
1190 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1192 if (header
->version
!= 2)
1193 error ("Dwarf Error: wrong version in compilation unit header "
1194 "(is %d, should be %d) [in module %s]", header
->version
,
1195 2, bfd_get_filename (abfd
));
1197 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1198 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1199 "(offset 0x%lx + 6) [in module %s]",
1200 (long) header
->abbrev_offset
,
1201 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1202 bfd_get_filename (abfd
));
1204 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1205 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1206 error ("Dwarf Error: bad length (0x%lx) in compilation unit header "
1207 "(offset 0x%lx + 0) [in module %s]",
1208 (long) header
->length
,
1209 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1210 bfd_get_filename (abfd
));
1215 /* Allocate a new partial symtab for file named NAME and mark this new
1216 partial symtab as being an include of PST. */
1219 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1220 struct objfile
*objfile
)
1222 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1224 subpst
->section_offsets
= pst
->section_offsets
;
1225 subpst
->textlow
= 0;
1226 subpst
->texthigh
= 0;
1228 subpst
->dependencies
= (struct partial_symtab
**)
1229 obstack_alloc (&objfile
->objfile_obstack
,
1230 sizeof (struct partial_symtab
*));
1231 subpst
->dependencies
[0] = pst
;
1232 subpst
->number_of_dependencies
= 1;
1234 subpst
->globals_offset
= 0;
1235 subpst
->n_global_syms
= 0;
1236 subpst
->statics_offset
= 0;
1237 subpst
->n_static_syms
= 0;
1238 subpst
->symtab
= NULL
;
1239 subpst
->read_symtab
= pst
->read_symtab
;
1242 /* No private part is necessary for include psymtabs. This property
1243 can be used to differentiate between such include psymtabs and
1244 the regular ones. If it ever happens that a regular psymtab can
1245 legitimally have a NULL private part, then we'll have to add a
1246 dedicated field for that in the dwarf2_pinfo structure. */
1247 subpst
->read_symtab_private
= NULL
;
1250 /* Read the Line Number Program data and extract the list of files
1251 included by the source file represented by PST. Build an include
1252 partial symtab for each of these included files.
1254 This procedure assumes that there *is* a Line Number Program in
1255 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1256 before calling this procedure. */
1259 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1260 struct partial_die_info
*pdi
,
1261 struct partial_symtab
*pst
)
1263 struct objfile
*objfile
= cu
->objfile
;
1264 bfd
*abfd
= objfile
->obfd
;
1265 struct line_header
*lh
;
1267 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1269 return; /* No linetable, so no includes. */
1271 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1273 free_line_header (lh
);
1277 /* Build the partial symbol table by doing a quick pass through the
1278 .debug_info and .debug_abbrev sections. */
1281 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1283 /* Instead of reading this into a big buffer, we should probably use
1284 mmap() on architectures that support it. (FIXME) */
1285 bfd
*abfd
= objfile
->obfd
;
1287 char *beg_of_comp_unit
;
1288 struct partial_die_info comp_unit_die
;
1289 struct partial_symtab
*pst
;
1290 CORE_ADDR lowpc
, highpc
, baseaddr
;
1292 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1294 /* Since the objects we're extracting from .debug_info vary in
1295 length, only the individual functions to extract them (like
1296 read_comp_unit_head and load_partial_die) can really know whether
1297 the buffer is large enough to hold another complete object.
1299 At the moment, they don't actually check that. If .debug_info
1300 holds just one extra byte after the last compilation unit's dies,
1301 then read_comp_unit_head will happily read off the end of the
1302 buffer. read_partial_die is similarly casual. Those functions
1305 For this loop condition, simply checking whether there's any data
1306 left at all should be sufficient. */
1307 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1308 + dwarf2_per_objfile
->info_size
))
1310 struct cleanup
*back_to_inner
;
1311 struct dwarf2_cu cu
;
1312 struct abbrev_info
*abbrev
;
1313 unsigned int bytes_read
;
1314 struct dwarf2_per_cu_data
*this_cu
;
1316 beg_of_comp_unit
= info_ptr
;
1318 memset (&cu
, 0, sizeof (cu
));
1320 obstack_init (&cu
.comp_unit_obstack
);
1322 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1324 cu
.objfile
= objfile
;
1325 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1327 /* Complete the cu_header */
1328 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1329 cu
.header
.first_die_ptr
= info_ptr
;
1330 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1332 cu
.list_in_scope
= &file_symbols
;
1334 cu
.partial_dies
= NULL
;
1336 /* Read the abbrevs for this compilation unit into a table */
1337 dwarf2_read_abbrevs (abfd
, &cu
);
1338 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1340 /* Read the compilation unit die */
1341 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1342 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1343 abfd
, info_ptr
, &cu
);
1345 /* Set the language we're debugging */
1346 set_cu_language (comp_unit_die
.language
, &cu
);
1348 /* Allocate a new partial symbol table structure */
1349 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1350 comp_unit_die
.name
? comp_unit_die
.name
: "",
1351 comp_unit_die
.lowpc
,
1352 objfile
->global_psymbols
.next
,
1353 objfile
->static_psymbols
.next
);
1355 if (comp_unit_die
.dirname
)
1356 pst
->dirname
= xstrdup (comp_unit_die
.dirname
);
1358 pst
->read_symtab_private
= (char *)
1359 obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct dwarf2_pinfo
));
1360 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1361 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1363 /* Store the function that reads in the rest of the symbol table */
1364 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1366 /* Check if comp unit has_children.
1367 If so, read the rest of the partial symbols from this comp unit.
1368 If not, there's no more debug_info for this comp unit. */
1369 if (comp_unit_die
.has_children
)
1371 struct partial_die_info
*first_die
;
1373 lowpc
= ((CORE_ADDR
) -1);
1374 highpc
= ((CORE_ADDR
) 0);
1376 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1378 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1380 /* If we didn't find a lowpc, set it to highpc to avoid
1381 complaints from `maint check'. */
1382 if (lowpc
== ((CORE_ADDR
) -1))
1385 /* If the compilation unit didn't have an explicit address range,
1386 then use the information extracted from its child dies. */
1387 if (! comp_unit_die
.has_pc_info
)
1389 comp_unit_die
.lowpc
= lowpc
;
1390 comp_unit_die
.highpc
= highpc
;
1393 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1394 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1396 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1397 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1398 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1399 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1400 sort_pst_symbols (pst
);
1402 /* If there is already a psymtab or symtab for a file of this
1403 name, remove it. (If there is a symtab, more drastic things
1404 also happen.) This happens in VxWorks. */
1405 free_named_symtabs (pst
->filename
);
1407 if (comp_unit_die
.has_stmt_list
)
1409 /* Get the list of files included in the current compilation unit,
1410 and build a psymtab for each of them. */
1411 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1414 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1415 + cu
.header
.initial_length_size
;
1417 do_cleanups (back_to_inner
);
1421 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1422 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1426 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1427 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1429 struct objfile
*objfile
= cu
->objfile
;
1430 bfd
*abfd
= objfile
->obfd
;
1431 struct partial_die_info
*pdi
;
1433 /* Now, march along the PDI's, descending into ones which have
1434 interesting children but skipping the children of the other ones,
1435 until we reach the end of the compilation unit. */
1441 fixup_partial_die (pdi
, cu
);
1443 /* Anonymous namespaces have no name but have interesting
1444 children, so we need to look at them. Ditto for anonymous
1447 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1448 || pdi
->tag
== DW_TAG_enumeration_type
)
1452 case DW_TAG_subprogram
:
1453 if (pdi
->has_pc_info
)
1455 if (pdi
->lowpc
< *lowpc
)
1457 *lowpc
= pdi
->lowpc
;
1459 if (pdi
->highpc
> *highpc
)
1461 *highpc
= pdi
->highpc
;
1463 if (!pdi
->is_declaration
)
1465 add_partial_symbol (pdi
, cu
);
1469 case DW_TAG_variable
:
1470 case DW_TAG_typedef
:
1471 case DW_TAG_union_type
:
1472 if (!pdi
->is_declaration
)
1474 add_partial_symbol (pdi
, cu
);
1477 case DW_TAG_class_type
:
1478 case DW_TAG_structure_type
:
1479 if (!pdi
->is_declaration
)
1481 add_partial_symbol (pdi
, cu
);
1484 case DW_TAG_enumeration_type
:
1485 if (!pdi
->is_declaration
)
1486 add_partial_enumeration (pdi
, cu
);
1488 case DW_TAG_base_type
:
1489 case DW_TAG_subrange_type
:
1490 /* File scope base type definitions are added to the partial
1492 add_partial_symbol (pdi
, cu
);
1494 case DW_TAG_namespace
:
1495 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1502 /* If the die has a sibling, skip to the sibling. */
1504 pdi
= pdi
->die_sibling
;
1508 /* Functions used to compute the fully scoped name of a partial DIE.
1510 Normally, this is simple. For C++, the parent DIE's fully scoped
1511 name is concatenated with "::" and the partial DIE's name.
1512 Enumerators are an exception; they use the scope of their parent
1513 enumeration type, i.e. the name of the enumeration type is not
1514 prepended to the enumerator.
1516 There are two complexities. One is DW_AT_specification; in this
1517 case "parent" means the parent of the target of the specification,
1518 instead of the direct parent of the DIE. The other is compilers
1519 which do not emit DW_TAG_namespace; in this case we try to guess
1520 the fully qualified name of structure types from their members'
1521 linkage names. This must be done using the DIE's children rather
1522 than the children of any DW_AT_specification target. We only need
1523 to do this for structures at the top level, i.e. if the target of
1524 any DW_AT_specification (if any; otherwise the DIE itself) does not
1527 /* Compute the scope prefix associated with PDI's parent, in
1528 compilation unit CU. The result will be allocated on CU's
1529 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1530 field. NULL is returned if no prefix is necessary. */
1532 partial_die_parent_scope (struct partial_die_info
*pdi
,
1533 struct dwarf2_cu
*cu
)
1535 char *grandparent_scope
;
1536 struct partial_die_info
*parent
, *real_pdi
;
1537 struct dwarf2_cu
*spec_cu
;
1539 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1540 then this means the parent of the specification DIE. */
1544 while (real_pdi
->has_specification
)
1545 real_pdi
= find_partial_die (real_pdi
->spec_offset
, spec_cu
, &spec_cu
);
1547 parent
= real_pdi
->die_parent
;
1551 if (parent
->scope_set
)
1552 return parent
->scope
;
1554 fixup_partial_die (parent
, cu
);
1556 grandparent_scope
= partial_die_parent_scope (parent
, spec_cu
);
1558 if (parent
->tag
== DW_TAG_namespace
1559 || parent
->tag
== DW_TAG_structure_type
1560 || parent
->tag
== DW_TAG_class_type
1561 || parent
->tag
== DW_TAG_union_type
)
1563 if (grandparent_scope
== NULL
)
1564 parent
->scope
= parent
->name
;
1566 parent
->scope
= obconcat (&cu
->comp_unit_obstack
, grandparent_scope
,
1567 "::", parent
->name
);
1569 else if (parent
->tag
== DW_TAG_enumeration_type
)
1570 /* Enumerators should not get the name of the enumeration as a prefix. */
1571 parent
->scope
= grandparent_scope
;
1574 /* FIXME drow/2004-04-01: What should we be doing with
1575 function-local names? For partial symbols, we should probably be
1577 complaint (&symfile_complaints
,
1578 "unhandled containing DIE tag %d for DIE at %d",
1579 parent
->tag
, pdi
->offset
);
1580 parent
->scope
= grandparent_scope
;
1583 parent
->scope_set
= 1;
1584 return parent
->scope
;
1587 /* Return the fully scoped name associated with PDI, from compilation unit
1588 CU. The result will be allocated with malloc. */
1590 partial_die_full_name (struct partial_die_info
*pdi
,
1591 struct dwarf2_cu
*cu
)
1595 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1596 if (parent_scope
== NULL
)
1599 return concat (parent_scope
, "::", pdi
->name
, NULL
);
1603 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1605 struct objfile
*objfile
= cu
->objfile
;
1608 const char *my_prefix
;
1609 const struct partial_symbol
*psym
= NULL
;
1611 int built_actual_name
= 0;
1613 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1617 if (pdi_needs_namespace (pdi
->tag
))
1619 actual_name
= partial_die_full_name (pdi
, cu
);
1621 built_actual_name
= 1;
1624 if (actual_name
== NULL
)
1625 actual_name
= pdi
->name
;
1629 case DW_TAG_subprogram
:
1630 if (pdi
->is_external
)
1632 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1633 mst_text, objfile); */
1634 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1635 VAR_DOMAIN
, LOC_BLOCK
,
1636 &objfile
->global_psymbols
,
1637 0, pdi
->lowpc
+ baseaddr
,
1638 cu
->language
, objfile
);
1642 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1643 mst_file_text, objfile); */
1644 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1645 VAR_DOMAIN
, LOC_BLOCK
,
1646 &objfile
->static_psymbols
,
1647 0, pdi
->lowpc
+ baseaddr
,
1648 cu
->language
, objfile
);
1651 case DW_TAG_variable
:
1652 if (pdi
->is_external
)
1655 Don't enter into the minimal symbol tables as there is
1656 a minimal symbol table entry from the ELF symbols already.
1657 Enter into partial symbol table if it has a location
1658 descriptor or a type.
1659 If the location descriptor is missing, new_symbol will create
1660 a LOC_UNRESOLVED symbol, the address of the variable will then
1661 be determined from the minimal symbol table whenever the variable
1663 The address for the partial symbol table entry is not
1664 used by GDB, but it comes in handy for debugging partial symbol
1668 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1669 if (pdi
->locdesc
|| pdi
->has_type
)
1670 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1671 VAR_DOMAIN
, LOC_STATIC
,
1672 &objfile
->global_psymbols
,
1674 cu
->language
, objfile
);
1678 /* Static Variable. Skip symbols without location descriptors. */
1679 if (pdi
->locdesc
== NULL
)
1681 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1682 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1683 mst_file_data, objfile); */
1684 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1685 VAR_DOMAIN
, LOC_STATIC
,
1686 &objfile
->static_psymbols
,
1688 cu
->language
, objfile
);
1691 case DW_TAG_typedef
:
1692 case DW_TAG_base_type
:
1693 case DW_TAG_subrange_type
:
1694 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1695 VAR_DOMAIN
, LOC_TYPEDEF
,
1696 &objfile
->static_psymbols
,
1697 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1699 case DW_TAG_namespace
:
1700 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1701 VAR_DOMAIN
, LOC_TYPEDEF
,
1702 &objfile
->global_psymbols
,
1703 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1705 case DW_TAG_class_type
:
1706 case DW_TAG_structure_type
:
1707 case DW_TAG_union_type
:
1708 case DW_TAG_enumeration_type
:
1709 /* Skip aggregate types without children, these are external
1711 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1712 static vs. global. */
1713 if (pdi
->has_children
== 0)
1715 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1716 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1717 cu
->language
== language_cplus
1718 ? &objfile
->global_psymbols
1719 : &objfile
->static_psymbols
,
1720 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1722 if (cu
->language
== language_cplus
)
1724 /* For C++, these implicitly act as typedefs as well. */
1725 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1726 VAR_DOMAIN
, LOC_TYPEDEF
,
1727 &objfile
->global_psymbols
,
1728 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1731 case DW_TAG_enumerator
:
1732 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1733 VAR_DOMAIN
, LOC_CONST
,
1734 cu
->language
== language_cplus
1735 ? &objfile
->global_psymbols
1736 : &objfile
->static_psymbols
,
1737 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1743 /* Check to see if we should scan the name for possible namespace
1744 info. Only do this if this is C++, if we don't have namespace
1745 debugging info in the file, if the psym is of an appropriate type
1746 (otherwise we'll have psym == NULL), and if we actually had a
1747 mangled name to begin with. */
1749 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
1750 cases which do not set PSYM above? */
1752 if (cu
->language
== language_cplus
1753 && cu
->has_namespace_info
== 0
1755 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
1756 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
1759 if (built_actual_name
)
1760 xfree (actual_name
);
1763 /* Determine whether a die of type TAG living in a C++ class or
1764 namespace needs to have the name of the scope prepended to the
1765 name listed in the die. */
1768 pdi_needs_namespace (enum dwarf_tag tag
)
1772 case DW_TAG_namespace
:
1773 case DW_TAG_typedef
:
1774 case DW_TAG_class_type
:
1775 case DW_TAG_structure_type
:
1776 case DW_TAG_union_type
:
1777 case DW_TAG_enumeration_type
:
1778 case DW_TAG_enumerator
:
1785 /* Read a partial die corresponding to a namespace; also, add a symbol
1786 corresponding to that namespace to the symbol table. NAMESPACE is
1787 the name of the enclosing namespace. */
1790 add_partial_namespace (struct partial_die_info
*pdi
,
1791 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1792 struct dwarf2_cu
*cu
)
1794 struct objfile
*objfile
= cu
->objfile
;
1796 /* Add a symbol for the namespace. */
1798 add_partial_symbol (pdi
, cu
);
1800 /* Now scan partial symbols in that namespace. */
1802 if (pdi
->has_children
)
1803 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
1806 /* See if we can figure out if the class lives in a namespace. We do
1807 this by looking for a member function; its demangled name will
1808 contain namespace info, if there is any. */
1811 guess_structure_name (struct partial_die_info
*struct_pdi
,
1812 struct dwarf2_cu
*cu
)
1814 if (cu
->language
== language_cplus
1815 && cu
->has_namespace_info
== 0
1816 && struct_pdi
->has_children
)
1818 /* NOTE: carlton/2003-10-07: Getting the info this way changes
1819 what template types look like, because the demangler
1820 frequently doesn't give the same name as the debug info. We
1821 could fix this by only using the demangled name to get the
1822 prefix (but see comment in read_structure_type). */
1824 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
1825 struct partial_die_info
*real_pdi
;
1826 struct dwarf2_cu
*spec_cu
;
1828 /* If this DIE (this DIE's specification, if any) has a parent, then
1829 we should not do this. We'll prepend the parent's fully qualified
1830 name when we create the partial symbol. */
1832 real_pdi
= struct_pdi
;
1834 while (real_pdi
->has_specification
)
1835 real_pdi
= find_partial_die (real_pdi
->spec_offset
, spec_cu
, &spec_cu
);
1837 if (real_pdi
->die_parent
!= NULL
)
1840 while (child_pdi
!= NULL
)
1842 if (child_pdi
->tag
== DW_TAG_subprogram
)
1844 char *actual_class_name
1845 = language_class_name_from_physname (cu
->language_defn
,
1847 if (actual_class_name
!= NULL
)
1850 = obsavestring (actual_class_name
,
1851 strlen (actual_class_name
),
1852 &cu
->comp_unit_obstack
);
1853 xfree (actual_class_name
);
1858 child_pdi
= child_pdi
->die_sibling
;
1863 /* Read a partial die corresponding to an enumeration type. */
1866 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1867 struct dwarf2_cu
*cu
)
1869 struct objfile
*objfile
= cu
->objfile
;
1870 bfd
*abfd
= objfile
->obfd
;
1871 struct partial_die_info
*pdi
;
1873 if (enum_pdi
->name
!= NULL
)
1874 add_partial_symbol (enum_pdi
, cu
);
1876 pdi
= enum_pdi
->die_child
;
1879 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
1880 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
1882 add_partial_symbol (pdi
, cu
);
1883 pdi
= pdi
->die_sibling
;
1887 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
1888 Return the corresponding abbrev, or NULL if the number is zero (indicating
1889 an empty DIE). In either case *BYTES_READ will be set to the length of
1890 the initial number. */
1892 static struct abbrev_info
*
1893 peek_die_abbrev (char *info_ptr
, int *bytes_read
, struct dwarf2_cu
*cu
)
1895 bfd
*abfd
= cu
->objfile
->obfd
;
1896 unsigned int abbrev_number
;
1897 struct abbrev_info
*abbrev
;
1899 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
1901 if (abbrev_number
== 0)
1904 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
1907 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
1908 bfd_get_filename (abfd
));
1914 /* Scan the debug information for CU starting at INFO_PTR. Returns a
1915 pointer to the end of a series of DIEs, terminated by an empty
1916 DIE. Any children of the skipped DIEs will also be skipped. */
1919 skip_children (char *info_ptr
, struct dwarf2_cu
*cu
)
1921 struct abbrev_info
*abbrev
;
1922 unsigned int bytes_read
;
1926 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1928 return info_ptr
+ bytes_read
;
1930 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
1934 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
1935 should point just after the initial uleb128 of a DIE, and the
1936 abbrev corresponding to that skipped uleb128 should be passed in
1937 ABBREV. Returns a pointer to this DIE's sibling, skipping any
1941 skip_one_die (char *info_ptr
, struct abbrev_info
*abbrev
,
1942 struct dwarf2_cu
*cu
)
1944 unsigned int bytes_read
;
1945 struct attribute attr
;
1946 bfd
*abfd
= cu
->objfile
->obfd
;
1947 unsigned int form
, i
;
1949 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
1951 /* The only abbrev we care about is DW_AT_sibling. */
1952 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
1954 read_attribute (&attr
, &abbrev
->attrs
[i
],
1955 abfd
, info_ptr
, cu
);
1956 if (attr
.form
== DW_FORM_ref_addr
)
1957 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
1959 return dwarf2_per_objfile
->info_buffer
1960 + dwarf2_get_ref_die_offset (&attr
, cu
);
1963 /* If it isn't DW_AT_sibling, skip this attribute. */
1964 form
= abbrev
->attrs
[i
].form
;
1969 case DW_FORM_ref_addr
:
1970 info_ptr
+= cu
->header
.addr_size
;
1989 case DW_FORM_string
:
1990 read_string (abfd
, info_ptr
, &bytes_read
);
1991 info_ptr
+= bytes_read
;
1994 info_ptr
+= cu
->header
.offset_size
;
1997 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
1998 info_ptr
+= bytes_read
;
2000 case DW_FORM_block1
:
2001 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2003 case DW_FORM_block2
:
2004 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2006 case DW_FORM_block4
:
2007 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2011 case DW_FORM_ref_udata
:
2012 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2014 case DW_FORM_indirect
:
2015 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2016 info_ptr
+= bytes_read
;
2017 /* We need to continue parsing from here, so just go back to
2019 goto skip_attribute
;
2022 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
2023 dwarf_form_name (form
),
2024 bfd_get_filename (abfd
));
2028 if (abbrev
->has_children
)
2029 return skip_children (info_ptr
, cu
);
2034 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2035 the next DIE after ORIG_PDI. */
2038 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, char *info_ptr
,
2039 bfd
*abfd
, struct dwarf2_cu
*cu
)
2041 /* Do we know the sibling already? */
2043 if (orig_pdi
->sibling
)
2044 return orig_pdi
->sibling
;
2046 /* Are there any children to deal with? */
2048 if (!orig_pdi
->has_children
)
2051 /* Skip the children the long way. */
2053 return skip_children (info_ptr
, cu
);
2056 /* Expand this partial symbol table into a full symbol table. */
2059 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2061 /* FIXME: This is barely more than a stub. */
2066 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
2072 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
2073 gdb_flush (gdb_stdout
);
2076 psymtab_to_symtab_1 (pst
);
2078 /* Finish up the debug error message. */
2080 printf_filtered ("done.\n");
2086 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2088 struct objfile
*objfile
= pst
->objfile
;
2089 bfd
*abfd
= objfile
->obfd
;
2090 struct dwarf2_cu cu
;
2091 struct die_info
*dies
;
2092 unsigned long offset
;
2093 CORE_ADDR lowpc
, highpc
;
2094 struct die_info
*child_die
;
2096 struct symtab
*symtab
;
2097 struct cleanup
*back_to
;
2098 struct attribute
*attr
;
2102 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2103 if (!pst
->dependencies
[i
]->readin
)
2105 /* Inform about additional files that need to be read in. */
2108 fputs_filtered (" ", gdb_stdout
);
2110 fputs_filtered ("and ", gdb_stdout
);
2112 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2113 wrap_here (""); /* Flush output */
2114 gdb_flush (gdb_stdout
);
2116 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2119 if (pst
->read_symtab_private
== NULL
)
2121 /* It's an include file, no symbols to read for it.
2122 Everything is in the parent symtab. */
2127 dwarf2_per_objfile
= objfile_data (pst
->objfile
, dwarf2_objfile_data_key
);
2129 /* Set local variables from the partial symbol table info. */
2130 offset
= DWARF_INFO_OFFSET (pst
);
2132 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2133 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2135 /* We're in the global namespace. */
2136 processing_current_prefix
= "";
2138 obstack_init (&cu
.comp_unit_obstack
);
2139 back_to
= make_cleanup (free_stack_comp_unit
, &cu
);
2142 make_cleanup (really_free_pendings
, NULL
);
2144 cu
.objfile
= objfile
;
2146 /* read in the comp_unit header */
2147 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
2149 /* Read the abbrevs for this compilation unit */
2150 dwarf2_read_abbrevs (abfd
, &cu
);
2151 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2153 cu
.header
.offset
= offset
;
2155 cu
.list_in_scope
= &file_symbols
;
2157 dies
= read_comp_unit (info_ptr
, abfd
, &cu
);
2159 make_cleanup_free_die_list (dies
);
2161 /* Find the base address of the compilation unit for range lists and
2162 location lists. It will normally be specified by DW_AT_low_pc.
2163 In DWARF-3 draft 4, the base address could be overridden by
2164 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2165 compilation units with discontinuous ranges. */
2167 cu
.header
.base_known
= 0;
2168 cu
.header
.base_address
= 0;
2170 attr
= dwarf2_attr (dies
, DW_AT_entry_pc
, &cu
);
2173 cu
.header
.base_address
= DW_ADDR (attr
);
2174 cu
.header
.base_known
= 1;
2178 attr
= dwarf2_attr (dies
, DW_AT_low_pc
, &cu
);
2181 cu
.header
.base_address
= DW_ADDR (attr
);
2182 cu
.header
.base_known
= 1;
2186 /* Do line number decoding in read_file_scope () */
2187 process_die (dies
, &cu
);
2189 /* Some compilers don't define a DW_AT_high_pc attribute for the
2190 compilation unit. If the DW_AT_high_pc is missing, synthesize
2191 it, by scanning the DIE's below the compilation unit. */
2192 get_scope_pc_bounds (dies
, &lowpc
, &highpc
, &cu
);
2194 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2196 /* Set symtab language to language from DW_AT_language.
2197 If the compilation is from a C file generated by language preprocessors,
2198 do not set the language if it was already deduced by start_subfile. */
2200 && !(cu
.language
== language_c
&& symtab
->language
!= language_c
))
2202 symtab
->language
= cu
.language
;
2204 pst
->symtab
= symtab
;
2207 do_cleanups (back_to
);
2210 /* Process a die and its children. */
2213 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2217 case DW_TAG_padding
:
2219 case DW_TAG_compile_unit
:
2220 read_file_scope (die
, cu
);
2222 case DW_TAG_subprogram
:
2223 read_subroutine_type (die
, cu
);
2224 read_func_scope (die
, cu
);
2226 case DW_TAG_inlined_subroutine
:
2227 /* FIXME: These are ignored for now.
2228 They could be used to set breakpoints on all inlined instances
2229 of a function and make GDB `next' properly over inlined functions. */
2231 case DW_TAG_lexical_block
:
2232 case DW_TAG_try_block
:
2233 case DW_TAG_catch_block
:
2234 read_lexical_block_scope (die
, cu
);
2236 case DW_TAG_class_type
:
2237 case DW_TAG_structure_type
:
2238 case DW_TAG_union_type
:
2239 read_structure_type (die
, cu
);
2240 process_structure_scope (die
, cu
);
2242 case DW_TAG_enumeration_type
:
2243 read_enumeration_type (die
, cu
);
2244 process_enumeration_scope (die
, cu
);
2247 /* FIXME drow/2004-03-14: These initialize die->type, but do not create
2248 a symbol or process any children. Therefore it doesn't do anything
2249 that won't be done on-demand by read_type_die. */
2250 case DW_TAG_subroutine_type
:
2251 read_subroutine_type (die
, cu
);
2253 case DW_TAG_array_type
:
2254 read_array_type (die
, cu
);
2256 case DW_TAG_pointer_type
:
2257 read_tag_pointer_type (die
, cu
);
2259 case DW_TAG_ptr_to_member_type
:
2260 read_tag_ptr_to_member_type (die
, cu
);
2262 case DW_TAG_reference_type
:
2263 read_tag_reference_type (die
, cu
);
2265 case DW_TAG_string_type
:
2266 read_tag_string_type (die
, cu
);
2270 case DW_TAG_base_type
:
2271 read_base_type (die
, cu
);
2272 /* Add a typedef symbol for the type definition, if it has a
2274 new_symbol (die
, die
->type
, cu
);
2276 case DW_TAG_subrange_type
:
2277 read_subrange_type (die
, cu
);
2278 /* Add a typedef symbol for the type definition, if it has a
2280 new_symbol (die
, die
->type
, cu
);
2282 case DW_TAG_common_block
:
2283 read_common_block (die
, cu
);
2285 case DW_TAG_common_inclusion
:
2287 case DW_TAG_namespace
:
2288 processing_has_namespace_info
= 1;
2289 read_namespace (die
, cu
);
2291 case DW_TAG_imported_declaration
:
2292 case DW_TAG_imported_module
:
2293 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2294 information contained in these. DW_TAG_imported_declaration
2295 dies shouldn't have children; DW_TAG_imported_module dies
2296 shouldn't in the C++ case, but conceivably could in the
2297 Fortran case, so we'll have to replace this gdb_assert if
2298 Fortran compilers start generating that info. */
2299 processing_has_namespace_info
= 1;
2300 gdb_assert (die
->child
== NULL
);
2303 new_symbol (die
, NULL
, cu
);
2309 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2311 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2315 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2317 struct objfile
*objfile
= cu
->objfile
;
2318 struct comp_unit_head
*cu_header
= &cu
->header
;
2319 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2320 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2321 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2322 struct attribute
*attr
;
2323 char *name
= "<unknown>";
2324 char *comp_dir
= NULL
;
2325 struct die_info
*child_die
;
2326 bfd
*abfd
= objfile
->obfd
;
2327 struct line_header
*line_header
= 0;
2330 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2332 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2334 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2335 from finish_block. */
2336 if (lowpc
== ((CORE_ADDR
) -1))
2341 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2344 name
= DW_STRING (attr
);
2346 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2349 comp_dir
= DW_STRING (attr
);
2352 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2353 directory, get rid of it. */
2354 char *cp
= strchr (comp_dir
, ':');
2356 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2361 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2364 set_cu_language (DW_UNSND (attr
), cu
);
2367 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
2369 cu
->producer
= DW_STRING (attr
);
2371 /* We assume that we're processing GCC output. */
2372 processing_gcc_compilation
= 2;
2374 /* FIXME:Do something here. */
2375 if (dip
->at_producer
!= NULL
)
2377 handle_producer (dip
->at_producer
);
2381 /* The compilation unit may be in a different language or objfile,
2382 zero out all remembered fundamental types. */
2383 memset (cu
->ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
2385 start_symtab (name
, comp_dir
, lowpc
);
2386 record_debugformat ("DWARF 2");
2388 initialize_cu_func_list (cu
);
2390 /* Process all dies in compilation unit. */
2391 if (die
->child
!= NULL
)
2393 child_die
= die
->child
;
2394 while (child_die
&& child_die
->tag
)
2396 process_die (child_die
, cu
);
2397 child_die
= sibling_die (child_die
);
2401 /* Decode line number information if present. */
2402 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2405 unsigned int line_offset
= DW_UNSND (attr
);
2406 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2409 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
2410 (void *) line_header
);
2411 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2415 /* Decode macro information, if present. Dwarf 2 macro information
2416 refers to information in the line number info statement program
2417 header, so we can only read it if we've read the header
2419 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2420 if (attr
&& line_header
)
2422 unsigned int macro_offset
= DW_UNSND (attr
);
2423 dwarf_decode_macros (line_header
, macro_offset
,
2424 comp_dir
, abfd
, cu
);
2426 do_cleanups (back_to
);
2430 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2431 struct dwarf2_cu
*cu
)
2433 struct function_range
*thisfn
;
2435 thisfn
= (struct function_range
*)
2436 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
2437 thisfn
->name
= name
;
2438 thisfn
->lowpc
= lowpc
;
2439 thisfn
->highpc
= highpc
;
2440 thisfn
->seen_line
= 0;
2441 thisfn
->next
= NULL
;
2443 if (cu
->last_fn
== NULL
)
2444 cu
->first_fn
= thisfn
;
2446 cu
->last_fn
->next
= thisfn
;
2448 cu
->last_fn
= thisfn
;
2452 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2454 struct objfile
*objfile
= cu
->objfile
;
2455 struct context_stack
*new;
2458 struct die_info
*child_die
;
2459 struct attribute
*attr
;
2461 const char *previous_prefix
= processing_current_prefix
;
2462 struct cleanup
*back_to
= NULL
;
2465 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2467 name
= dwarf2_linkage_name (die
, cu
);
2469 /* Ignore functions with missing or empty names and functions with
2470 missing or invalid low and high pc attributes. */
2471 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2474 if (cu
->language
== language_cplus
)
2476 struct die_info
*spec_die
= die_specification (die
, cu
);
2478 /* NOTE: carlton/2004-01-23: We have to be careful in the
2479 presence of DW_AT_specification. For example, with GCC 3.4,
2484 // Definition of N::foo.
2488 then we'll have a tree of DIEs like this:
2490 1: DW_TAG_compile_unit
2491 2: DW_TAG_namespace // N
2492 3: DW_TAG_subprogram // declaration of N::foo
2493 4: DW_TAG_subprogram // definition of N::foo
2494 DW_AT_specification // refers to die #3
2496 Thus, when processing die #4, we have to pretend that we're
2497 in the context of its DW_AT_specification, namely the contex
2500 if (spec_die
!= NULL
)
2502 char *specification_prefix
= determine_prefix (spec_die
, cu
);
2503 processing_current_prefix
= specification_prefix
;
2504 back_to
= make_cleanup (xfree
, specification_prefix
);
2511 /* Record the function range for dwarf_decode_lines. */
2512 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
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
)
3568 = language_class_name_from_physname (cu
->language_defn
,
3572 if (new_prefix
!= NULL
)
3578 if (new_prefix
== NULL
)
3580 const char *name
= dwarf2_name (die
, cu
);
3581 new_prefix
= typename_concat (processing_current_prefix
,
3582 name
? name
: "<<anonymous>>");
3585 if (back_to
!= NULL
)
3586 do_cleanups (back_to
);
3591 /* Given a pointer to a die which begins an enumeration, process all
3592 the dies that define the members of the enumeration, and create the
3593 symbol for the enumeration type.
3595 NOTE: We reverse the order of the element list. */
3598 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3600 struct objfile
*objfile
= cu
->objfile
;
3601 struct die_info
*child_die
;
3602 struct field
*fields
;
3603 struct attribute
*attr
;
3606 int unsigned_enum
= 1;
3610 if (die
->child
!= NULL
)
3612 child_die
= die
->child
;
3613 while (child_die
&& child_die
->tag
)
3615 if (child_die
->tag
!= DW_TAG_enumerator
)
3617 process_die (child_die
, cu
);
3621 attr
= dwarf2_attr (child_die
, DW_AT_name
, cu
);
3624 sym
= new_symbol (child_die
, die
->type
, cu
);
3625 if (SYMBOL_VALUE (sym
) < 0)
3628 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3630 fields
= (struct field
*)
3632 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
3633 * sizeof (struct field
));
3636 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
3637 FIELD_TYPE (fields
[num_fields
]) = NULL
;
3638 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
3639 FIELD_BITSIZE (fields
[num_fields
]) = 0;
3640 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
3646 child_die
= sibling_die (child_die
);
3651 TYPE_NFIELDS (die
->type
) = num_fields
;
3652 TYPE_FIELDS (die
->type
) = (struct field
*)
3653 TYPE_ALLOC (die
->type
, sizeof (struct field
) * num_fields
);
3654 memcpy (TYPE_FIELDS (die
->type
), fields
,
3655 sizeof (struct field
) * num_fields
);
3659 TYPE_FLAGS (die
->type
) |= TYPE_FLAG_UNSIGNED
;
3662 new_symbol (die
, die
->type
, cu
);
3665 /* Extract all information from a DW_TAG_array_type DIE and put it in
3666 the DIE's type field. For now, this only handles one dimensional
3670 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3672 struct objfile
*objfile
= cu
->objfile
;
3673 struct die_info
*child_die
;
3674 struct type
*type
= NULL
;
3675 struct type
*element_type
, *range_type
, *index_type
;
3676 struct type
**range_types
= NULL
;
3677 struct attribute
*attr
;
3679 struct cleanup
*back_to
;
3681 /* Return if we've already decoded this type. */
3687 element_type
= die_type (die
, cu
);
3689 /* Irix 6.2 native cc creates array types without children for
3690 arrays with unspecified length. */
3691 if (die
->child
== NULL
)
3693 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
3694 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3695 die
->type
= create_array_type (NULL
, element_type
, range_type
);
3699 back_to
= make_cleanup (null_cleanup
, NULL
);
3700 child_die
= die
->child
;
3701 while (child_die
&& child_die
->tag
)
3703 if (child_die
->tag
== DW_TAG_subrange_type
)
3705 read_subrange_type (child_die
, cu
);
3707 if (child_die
->type
!= NULL
)
3709 /* The range type was succesfully read. Save it for
3710 the array type creation. */
3711 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3713 range_types
= (struct type
**)
3714 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3715 * sizeof (struct type
*));
3717 make_cleanup (free_current_contents
, &range_types
);
3719 range_types
[ndim
++] = child_die
->type
;
3722 child_die
= sibling_die (child_die
);
3725 /* Dwarf2 dimensions are output from left to right, create the
3726 necessary array types in backwards order. */
3727 type
= element_type
;
3729 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3731 /* Understand Dwarf2 support for vector types (like they occur on
3732 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3733 array type. This is not part of the Dwarf2/3 standard yet, but a
3734 custom vendor extension. The main difference between a regular
3735 array and the vector variant is that vectors are passed by value
3737 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
3739 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3741 do_cleanups (back_to
);
3743 /* Install the type in the die. */
3747 /* First cut: install each common block member as a global variable. */
3750 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
3752 struct die_info
*child_die
;
3753 struct attribute
*attr
;
3755 CORE_ADDR base
= (CORE_ADDR
) 0;
3757 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
3760 /* Support the .debug_loc offsets */
3761 if (attr_form_is_block (attr
))
3763 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
3765 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3767 dwarf2_complex_location_expr_complaint ();
3771 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3772 "common block member");
3775 if (die
->child
!= NULL
)
3777 child_die
= die
->child
;
3778 while (child_die
&& child_die
->tag
)
3780 sym
= new_symbol (child_die
, NULL
, cu
);
3781 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
3784 SYMBOL_VALUE_ADDRESS (sym
) =
3785 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
3786 add_symbol_to_list (sym
, &global_symbols
);
3788 child_die
= sibling_die (child_die
);
3793 /* Read a C++ namespace. */
3796 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3798 struct objfile
*objfile
= cu
->objfile
;
3799 const char *previous_prefix
= processing_current_prefix
;
3802 struct die_info
*current_die
;
3804 name
= namespace_name (die
, &is_anonymous
, cu
);
3806 /* Now build the name of the current namespace. */
3808 if (previous_prefix
[0] == '\0')
3810 processing_current_prefix
= name
;
3814 /* We need temp_name around because processing_current_prefix
3815 is a const char *. */
3816 char *temp_name
= alloca (strlen (previous_prefix
)
3817 + 2 + strlen(name
) + 1);
3818 strcpy (temp_name
, previous_prefix
);
3819 strcat (temp_name
, "::");
3820 strcat (temp_name
, name
);
3822 processing_current_prefix
= temp_name
;
3825 /* Add a symbol associated to this if we haven't seen the namespace
3826 before. Also, add a using directive if it's an anonymous
3829 if (dwarf2_extension (die
, cu
) == NULL
)
3833 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3834 this cast will hopefully become unnecessary. */
3835 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
3836 (char *) processing_current_prefix
,
3838 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
3840 new_symbol (die
, type
, cu
);
3844 cp_add_using_directive (processing_current_prefix
,
3845 strlen (previous_prefix
),
3846 strlen (processing_current_prefix
));
3849 if (die
->child
!= NULL
)
3851 struct die_info
*child_die
= die
->child
;
3853 while (child_die
&& child_die
->tag
)
3855 process_die (child_die
, cu
);
3856 child_die
= sibling_die (child_die
);
3860 processing_current_prefix
= previous_prefix
;
3863 /* Return the name of the namespace represented by DIE. Set
3864 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
3868 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
3870 struct die_info
*current_die
;
3871 const char *name
= NULL
;
3873 /* Loop through the extensions until we find a name. */
3875 for (current_die
= die
;
3876 current_die
!= NULL
;
3877 current_die
= dwarf2_extension (die
, cu
))
3879 name
= dwarf2_name (current_die
, cu
);
3884 /* Is it an anonymous namespace? */
3886 *is_anonymous
= (name
== NULL
);
3888 name
= "(anonymous namespace)";
3893 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3894 the user defined type vector. */
3897 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3899 struct comp_unit_head
*cu_header
= &cu
->header
;
3901 struct attribute
*attr_byte_size
;
3902 struct attribute
*attr_address_class
;
3903 int byte_size
, addr_class
;
3910 type
= lookup_pointer_type (die_type (die
, cu
));
3912 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3914 byte_size
= DW_UNSND (attr_byte_size
);
3916 byte_size
= cu_header
->addr_size
;
3918 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
3919 if (attr_address_class
)
3920 addr_class
= DW_UNSND (attr_address_class
);
3922 addr_class
= DW_ADDR_none
;
3924 /* If the pointer size or address class is different than the
3925 default, create a type variant marked as such and set the
3926 length accordingly. */
3927 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3929 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3933 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3934 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3935 type
= make_type_with_address_space (type
, type_flags
);
3937 else if (TYPE_LENGTH (type
) != byte_size
)
3939 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3942 /* Should we also complain about unhandled address classes? */
3946 TYPE_LENGTH (type
) = byte_size
;
3950 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3951 the user defined type vector. */
3954 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3956 struct objfile
*objfile
= cu
->objfile
;
3958 struct type
*to_type
;
3959 struct type
*domain
;
3966 type
= alloc_type (objfile
);
3967 to_type
= die_type (die
, cu
);
3968 domain
= die_containing_type (die
, cu
);
3969 smash_to_member_type (type
, domain
, to_type
);
3974 /* Extract all information from a DW_TAG_reference_type DIE and add to
3975 the user defined type vector. */
3978 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3980 struct comp_unit_head
*cu_header
= &cu
->header
;
3982 struct attribute
*attr
;
3989 type
= lookup_reference_type (die_type (die
, cu
));
3990 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3993 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3997 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4003 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4005 struct type
*base_type
;
4012 base_type
= die_type (die
, cu
);
4013 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
4017 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4019 struct type
*base_type
;
4026 base_type
= die_type (die
, cu
);
4027 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
4030 /* Extract all information from a DW_TAG_string_type DIE and add to
4031 the user defined type vector. It isn't really a user defined type,
4032 but it behaves like one, with other DIE's using an AT_user_def_type
4033 attribute to reference it. */
4036 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4038 struct objfile
*objfile
= cu
->objfile
;
4039 struct type
*type
, *range_type
, *index_type
, *char_type
;
4040 struct attribute
*attr
;
4041 unsigned int length
;
4048 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4051 length
= DW_UNSND (attr
);
4055 /* check for the DW_AT_byte_size attribute */
4056 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4059 length
= DW_UNSND (attr
);
4066 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
4067 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4068 if (cu
->language
== language_fortran
)
4070 /* Need to create a unique string type for bounds
4072 type
= create_string_type (0, range_type
);
4076 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
, cu
);
4077 type
= create_string_type (char_type
, range_type
);
4082 /* Handle DIES due to C code like:
4086 int (*funcp)(int a, long l);
4090 ('funcp' generates a DW_TAG_subroutine_type DIE)
4094 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4096 struct type
*type
; /* Type that this function returns */
4097 struct type
*ftype
; /* Function that returns above type */
4098 struct attribute
*attr
;
4100 /* Decode the type that this subroutine returns */
4105 type
= die_type (die
, cu
);
4106 ftype
= lookup_function_type (type
);
4108 /* All functions in C++ have prototypes. */
4109 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4110 if ((attr
&& (DW_UNSND (attr
) != 0))
4111 || cu
->language
== language_cplus
)
4112 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
4114 if (die
->child
!= NULL
)
4116 struct die_info
*child_die
;
4120 /* Count the number of parameters.
4121 FIXME: GDB currently ignores vararg functions, but knows about
4122 vararg member functions. */
4123 child_die
= die
->child
;
4124 while (child_die
&& child_die
->tag
)
4126 if (child_die
->tag
== DW_TAG_formal_parameter
)
4128 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4129 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
4130 child_die
= sibling_die (child_die
);
4133 /* Allocate storage for parameters and fill them in. */
4134 TYPE_NFIELDS (ftype
) = nparams
;
4135 TYPE_FIELDS (ftype
) = (struct field
*)
4136 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
4138 child_die
= die
->child
;
4139 while (child_die
&& child_die
->tag
)
4141 if (child_die
->tag
== DW_TAG_formal_parameter
)
4143 /* Dwarf2 has no clean way to discern C++ static and non-static
4144 member functions. G++ helps GDB by marking the first
4145 parameter for non-static member functions (which is the
4146 this pointer) as artificial. We pass this information
4147 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4148 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4150 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4152 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4153 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4156 child_die
= sibling_die (child_die
);
4164 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4166 struct objfile
*objfile
= cu
->objfile
;
4167 struct attribute
*attr
;
4172 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4173 if (attr
&& DW_STRING (attr
))
4175 name
= DW_STRING (attr
);
4177 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
4178 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
4182 /* Find a representation of a given base type and install
4183 it in the TYPE field of the die. */
4186 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4188 struct objfile
*objfile
= cu
->objfile
;
4190 struct attribute
*attr
;
4191 int encoding
= 0, size
= 0;
4193 /* If we've already decoded this die, this is a no-op. */
4199 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4202 encoding
= DW_UNSND (attr
);
4204 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4207 size
= DW_UNSND (attr
);
4209 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4210 if (attr
&& DW_STRING (attr
))
4212 enum type_code code
= TYPE_CODE_INT
;
4217 case DW_ATE_address
:
4218 /* Turn DW_ATE_address into a void * pointer. */
4219 code
= TYPE_CODE_PTR
;
4220 type_flags
|= TYPE_FLAG_UNSIGNED
;
4222 case DW_ATE_boolean
:
4223 code
= TYPE_CODE_BOOL
;
4224 type_flags
|= TYPE_FLAG_UNSIGNED
;
4226 case DW_ATE_complex_float
:
4227 code
= TYPE_CODE_COMPLEX
;
4230 code
= TYPE_CODE_FLT
;
4233 case DW_ATE_signed_char
:
4235 case DW_ATE_unsigned
:
4236 case DW_ATE_unsigned_char
:
4237 type_flags
|= TYPE_FLAG_UNSIGNED
;
4240 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
4241 dwarf_type_encoding_name (encoding
));
4244 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
4245 if (encoding
== DW_ATE_address
)
4246 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
,
4248 else if (encoding
== DW_ATE_complex_float
)
4251 TYPE_TARGET_TYPE (type
)
4252 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
, cu
);
4253 else if (size
== 16)
4254 TYPE_TARGET_TYPE (type
)
4255 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
4257 TYPE_TARGET_TYPE (type
)
4258 = dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
4263 type
= dwarf_base_type (encoding
, size
, cu
);
4268 /* Read the given DW_AT_subrange DIE. */
4271 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4273 struct type
*base_type
;
4274 struct type
*range_type
;
4275 struct attribute
*attr
;
4279 /* If we have already decoded this die, then nothing more to do. */
4283 base_type
= die_type (die
, cu
);
4284 if (base_type
== NULL
)
4286 complaint (&symfile_complaints
,
4287 "DW_AT_type missing from DW_TAG_subrange_type");
4291 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
4292 base_type
= alloc_type (NULL
);
4294 if (cu
->language
== language_fortran
)
4296 /* FORTRAN implies a lower bound of 1, if not given. */
4300 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
4302 low
= dwarf2_get_attr_constant_value (attr
, 0);
4304 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
4307 if (attr
->form
== DW_FORM_block1
)
4309 /* GCC encodes arrays with unspecified or dynamic length
4310 with a DW_FORM_block1 attribute.
4311 FIXME: GDB does not yet know how to handle dynamic
4312 arrays properly, treat them as arrays with unspecified
4315 FIXME: jimb/2003-09-22: GDB does not really know
4316 how to handle arrays of unspecified length
4317 either; we just represent them as zero-length
4318 arrays. Choose an appropriate upper bound given
4319 the lower bound we've computed above. */
4323 high
= dwarf2_get_attr_constant_value (attr
, 1);
4326 range_type
= create_range_type (NULL
, base_type
, low
, high
);
4328 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4329 if (attr
&& DW_STRING (attr
))
4330 TYPE_NAME (range_type
) = DW_STRING (attr
);
4332 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4334 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
4336 die
->type
= range_type
;
4340 /* Read a whole compilation unit into a linked list of dies. */
4342 static struct die_info
*
4343 read_comp_unit (char *info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
4345 /* Reset die reference table; we are
4346 building new ones now. */
4347 dwarf2_empty_hash_tables ();
4349 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
4352 /* Read a single die and all its descendents. Set the die's sibling
4353 field to NULL; set other fields in the die correctly, and set all
4354 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4355 location of the info_ptr after reading all of those dies. PARENT
4356 is the parent of the die in question. */
4358 static struct die_info
*
4359 read_die_and_children (char *info_ptr
, bfd
*abfd
,
4360 struct dwarf2_cu
*cu
,
4361 char **new_info_ptr
,
4362 struct die_info
*parent
)
4364 struct die_info
*die
;
4368 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
4369 store_in_ref_table (die
->offset
, die
);
4373 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
4379 *new_info_ptr
= cur_ptr
;
4382 die
->sibling
= NULL
;
4383 die
->parent
= parent
;
4387 /* Read a die, all of its descendents, and all of its siblings; set
4388 all of the fields of all of the dies correctly. Arguments are as
4389 in read_die_and_children. */
4391 static struct die_info
*
4392 read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
4393 struct dwarf2_cu
*cu
,
4394 char **new_info_ptr
,
4395 struct die_info
*parent
)
4397 struct die_info
*first_die
, *last_sibling
;
4401 first_die
= last_sibling
= NULL
;
4405 struct die_info
*die
4406 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
4414 last_sibling
->sibling
= die
;
4419 *new_info_ptr
= cur_ptr
;
4429 /* Free a linked list of dies. */
4432 free_die_list (struct die_info
*dies
)
4434 struct die_info
*die
, *next
;
4439 if (die
->child
!= NULL
)
4440 free_die_list (die
->child
);
4441 next
= die
->sibling
;
4449 do_free_die_list_cleanup (void *dies
)
4451 free_die_list (dies
);
4454 static struct cleanup
*
4455 make_cleanup_free_die_list (struct die_info
*dies
)
4457 return make_cleanup (do_free_die_list_cleanup
, dies
);
4461 /* Read the contents of the section at OFFSET and of size SIZE from the
4462 object file specified by OBJFILE into the objfile_obstack and return it. */
4465 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
4467 bfd
*abfd
= objfile
->obfd
;
4469 bfd_size_type size
= bfd_get_section_size (sectp
);
4474 buf
= (char *) obstack_alloc (&objfile
->objfile_obstack
, size
);
4476 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
4480 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
4481 || bfd_bread (buf
, size
, abfd
) != size
)
4482 error ("Dwarf Error: Can't read DWARF data from '%s'",
4483 bfd_get_filename (abfd
));
4488 /* In DWARF version 2, the description of the debugging information is
4489 stored in a separate .debug_abbrev section. Before we read any
4490 dies from a section we read in all abbreviations and install them
4491 in a hash table. This function also sets flags in CU describing
4492 the data found in the abbrev table. */
4495 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
4497 struct comp_unit_head
*cu_header
= &cu
->header
;
4499 struct abbrev_info
*cur_abbrev
;
4500 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
4501 unsigned int abbrev_form
, hash_number
;
4502 struct attr_abbrev
*cur_attrs
;
4503 unsigned int allocated_attrs
;
4505 /* Initialize dwarf2 abbrevs */
4506 obstack_init (&cu
->abbrev_obstack
);
4507 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
4509 * sizeof (struct abbrev_info
*)));
4510 memset (cu
->dwarf2_abbrevs
, 0,
4511 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
4513 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
4514 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4515 abbrev_ptr
+= bytes_read
;
4517 allocated_attrs
= ATTR_ALLOC_CHUNK
;
4518 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
4520 /* loop until we reach an abbrev number of 0 */
4521 while (abbrev_number
)
4523 cur_abbrev
= dwarf_alloc_abbrev (cu
);
4525 /* read in abbrev header */
4526 cur_abbrev
->number
= abbrev_number
;
4527 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4528 abbrev_ptr
+= bytes_read
;
4529 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
4532 if (cur_abbrev
->tag
== DW_TAG_namespace
)
4533 cu
->has_namespace_info
= 1;
4535 /* now read in declarations */
4536 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4537 abbrev_ptr
+= bytes_read
;
4538 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4539 abbrev_ptr
+= bytes_read
;
4542 if (cur_abbrev
->num_attrs
== allocated_attrs
)
4544 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
4546 = xrealloc (cur_attrs
, (allocated_attrs
4547 * sizeof (struct attr_abbrev
)));
4549 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
4550 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
4551 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4552 abbrev_ptr
+= bytes_read
;
4553 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4554 abbrev_ptr
+= bytes_read
;
4557 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
4558 (cur_abbrev
->num_attrs
4559 * sizeof (struct attr_abbrev
)));
4560 memcpy (cur_abbrev
->attrs
, cur_attrs
,
4561 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
4563 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
4564 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
4565 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
4567 /* Get next abbreviation.
4568 Under Irix6 the abbreviations for a compilation unit are not
4569 always properly terminated with an abbrev number of 0.
4570 Exit loop if we encounter an abbreviation which we have
4571 already read (which means we are about to read the abbreviations
4572 for the next compile unit) or if the end of the abbreviation
4573 table is reached. */
4574 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
4575 >= dwarf2_per_objfile
->abbrev_size
)
4577 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4578 abbrev_ptr
+= bytes_read
;
4579 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
4586 /* Release the memory used by the abbrev table for a compilation unit. */
4589 dwarf2_free_abbrev_table (void *ptr_to_cu
)
4591 struct dwarf2_cu
*cu
= ptr_to_cu
;
4593 obstack_free (&cu
->abbrev_obstack
, NULL
);
4594 cu
->dwarf2_abbrevs
= NULL
;
4597 /* Lookup an abbrev_info structure in the abbrev hash table. */
4599 static struct abbrev_info
*
4600 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
4602 unsigned int hash_number
;
4603 struct abbrev_info
*abbrev
;
4605 hash_number
= number
% ABBREV_HASH_SIZE
;
4606 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
4610 if (abbrev
->number
== number
)
4613 abbrev
= abbrev
->next
;
4618 /* Returns nonzero if TAG represents a type that we might generate a partial
4622 is_type_tag_for_partial (int tag
)
4627 /* Some types that would be reasonable to generate partial symbols for,
4628 that we don't at present. */
4629 case DW_TAG_array_type
:
4630 case DW_TAG_file_type
:
4631 case DW_TAG_ptr_to_member_type
:
4632 case DW_TAG_set_type
:
4633 case DW_TAG_string_type
:
4634 case DW_TAG_subroutine_type
:
4636 case DW_TAG_base_type
:
4637 case DW_TAG_class_type
:
4638 case DW_TAG_enumeration_type
:
4639 case DW_TAG_structure_type
:
4640 case DW_TAG_subrange_type
:
4641 case DW_TAG_typedef
:
4642 case DW_TAG_union_type
:
4649 /* Load all DIEs that are interesting for partial symbols into memory. */
4651 static struct partial_die_info
*
4652 load_partial_dies (bfd
*abfd
, char *info_ptr
, int building_psymtab
,
4653 struct dwarf2_cu
*cu
)
4655 struct partial_die_info
*part_die
;
4656 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
4657 struct abbrev_info
*abbrev
;
4658 unsigned int bytes_read
;
4660 int nesting_level
= 1;
4666 = htab_create_alloc_ex (cu
->header
.length
/ 12,
4670 &cu
->comp_unit_obstack
,
4671 hashtab_obstack_allocate
,
4672 dummy_obstack_deallocate
);
4674 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
4675 sizeof (struct partial_die_info
));
4679 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4681 /* A NULL abbrev means the end of a series of children. */
4684 if (--nesting_level
== 0)
4686 /* PART_DIE was probably the last thing allocated on the
4687 comp_unit_obstack, so we could call obstack_free
4688 here. We don't do that because the waste is small,
4689 and will be cleaned up when we're done with this
4690 compilation unit. This way, we're also more robust
4691 against other users of the comp_unit_obstack. */
4694 info_ptr
+= bytes_read
;
4695 last_die
= parent_die
;
4696 parent_die
= parent_die
->die_parent
;
4700 /* Check whether this DIE is interesting enough to save. */
4701 if (!is_type_tag_for_partial (abbrev
->tag
)
4702 && abbrev
->tag
!= DW_TAG_enumerator
4703 && abbrev
->tag
!= DW_TAG_subprogram
4704 && abbrev
->tag
!= DW_TAG_variable
4705 && abbrev
->tag
!= DW_TAG_namespace
)
4707 /* Otherwise we skip to the next sibling, if any. */
4708 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
4712 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
4713 abfd
, info_ptr
, cu
);
4715 /* This two-pass algorithm for processing partial symbols has a
4716 high cost in cache pressure. Thus, handle some simple cases
4717 here which cover the majority of C partial symbols. DIEs
4718 which neither have specification tags in them, nor could have
4719 specification tags elsewhere pointing at them, can simply be
4720 processed and discarded.
4722 This segment is also optional; scan_partial_symbols and
4723 add_partial_symbol will handle these DIEs if we chain
4724 them in normally. When compilers which do not emit large
4725 quantities of duplicate debug information are more common,
4726 this code can probably be removed. */
4728 /* Any complete simple types at the top level (pretty much all
4729 of them, for a language without namespaces), can be processed
4731 if (parent_die
== NULL
4732 && part_die
->has_specification
== 0
4733 && part_die
->is_declaration
== 0
4734 && (part_die
->tag
== DW_TAG_typedef
4735 || part_die
->tag
== DW_TAG_base_type
4736 || part_die
->tag
== DW_TAG_subrange_type
))
4738 if (building_psymtab
&& part_die
->name
!= NULL
)
4739 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
4740 VAR_DOMAIN
, LOC_TYPEDEF
,
4741 &cu
->objfile
->static_psymbols
,
4742 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
4743 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
4747 /* If we're at the second level, and we're an enumerator, and
4748 our parent has no specification (meaning possibly lives in a
4749 namespace elsewhere), then we can add the partial symbol now
4750 instead of queueing it. */
4751 if (part_die
->tag
== DW_TAG_enumerator
4752 && parent_die
!= NULL
4753 && parent_die
->die_parent
== NULL
4754 && parent_die
->tag
== DW_TAG_enumeration_type
4755 && parent_die
->has_specification
== 0)
4757 if (part_die
->name
== NULL
)
4758 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
4759 else if (building_psymtab
)
4760 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
4761 VAR_DOMAIN
, LOC_CONST
,
4762 cu
->language
== language_cplus
4763 ? &cu
->objfile
->global_psymbols
4764 : &cu
->objfile
->static_psymbols
,
4765 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
4767 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
4771 /* We'll save this DIE so link it in. */
4772 part_die
->die_parent
= parent_die
;
4773 part_die
->die_sibling
= NULL
;
4774 part_die
->die_child
= NULL
;
4776 if (last_die
&& last_die
== parent_die
)
4777 last_die
->die_child
= part_die
;
4779 last_die
->die_sibling
= part_die
;
4781 last_die
= part_die
;
4783 if (first_die
== NULL
)
4784 first_die
= part_die
;
4786 /* Maybe add the DIE to the hash table. Not all DIEs that we
4787 find interesting need to be in the hash table, because we
4788 also have the parent/sibling/child chains; only those that we
4789 might refer to by offset later during partial symbol reading.
4791 For now this means things that might have be the target of a
4792 DW_AT_specification, DW_AT_abstract_origin, or
4793 DW_AT_extension. DW_AT_extension will refer only to
4794 namespaces; DW_AT_abstract_origin refers to functions (and
4795 many things under the function DIE, but we do not recurse
4796 into function DIEs during partial symbol reading) and
4797 possibly variables as well; DW_AT_specification refers to
4798 declarations. Declarations ought to have the DW_AT_declaration
4799 flag. It happens that GCC forgets to put it in sometimes, but
4800 only for functions, not for types.
4802 Adding more things than necessary to the hash table is harmless
4803 except for the performance cost. Adding too few will result in
4804 internal errors in find_partial_die. */
4806 if (abbrev
->tag
== DW_TAG_subprogram
4807 || abbrev
->tag
== DW_TAG_variable
4808 || abbrev
->tag
== DW_TAG_namespace
4809 || part_die
->is_declaration
)
4813 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
4814 part_die
->offset
, INSERT
);
4818 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
4819 sizeof (struct partial_die_info
));
4821 /* For some DIEs we want to follow their children (if any). For C
4822 we have no reason to follow the children of structures; for other
4823 languages we have to, both so that we can get at method physnames
4824 to infer fully qualified class names, and for DW_AT_specification. */
4825 if (last_die
->has_children
4826 && (last_die
->tag
== DW_TAG_namespace
4827 || last_die
->tag
== DW_TAG_enumeration_type
4828 || (cu
->language
!= language_c
4829 && (last_die
->tag
== DW_TAG_class_type
4830 || last_die
->tag
== DW_TAG_structure_type
4831 || last_die
->tag
== DW_TAG_union_type
))))
4834 parent_die
= last_die
;
4838 /* Otherwise we skip to the next sibling, if any. */
4839 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
4841 /* Back to the top, do it again. */
4845 /* Read a minimal amount of information into the minimal die structure. */
4848 read_partial_die (struct partial_die_info
*part_die
,
4849 struct abbrev_info
*abbrev
,
4850 unsigned int abbrev_len
, bfd
*abfd
,
4851 char *info_ptr
, struct dwarf2_cu
*cu
)
4853 unsigned int bytes_read
, i
;
4854 struct attribute attr
;
4855 int has_low_pc_attr
= 0;
4856 int has_high_pc_attr
= 0;
4858 memset (part_die
, 0, sizeof (struct partial_die_info
));
4860 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
4862 info_ptr
+= abbrev_len
;
4867 part_die
->tag
= abbrev
->tag
;
4868 part_die
->has_children
= abbrev
->has_children
;
4870 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4872 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
4874 /* Store the data if it is of an attribute we want to keep in a
4875 partial symbol table. */
4880 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
4881 if (part_die
->name
== NULL
)
4882 part_die
->name
= DW_STRING (&attr
);
4884 case DW_AT_comp_dir
:
4885 if (part_die
->dirname
== NULL
)
4886 part_die
->dirname
= DW_STRING (&attr
);
4888 case DW_AT_MIPS_linkage_name
:
4889 part_die
->name
= DW_STRING (&attr
);
4892 has_low_pc_attr
= 1;
4893 part_die
->lowpc
= DW_ADDR (&attr
);
4896 has_high_pc_attr
= 1;
4897 part_die
->highpc
= DW_ADDR (&attr
);
4899 case DW_AT_location
:
4900 /* Support the .debug_loc offsets */
4901 if (attr_form_is_block (&attr
))
4903 part_die
->locdesc
= DW_BLOCK (&attr
);
4905 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
4907 dwarf2_complex_location_expr_complaint ();
4911 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4912 "partial symbol information");
4915 case DW_AT_language
:
4916 part_die
->language
= DW_UNSND (&attr
);
4918 case DW_AT_external
:
4919 part_die
->is_external
= DW_UNSND (&attr
);
4921 case DW_AT_declaration
:
4922 part_die
->is_declaration
= DW_UNSND (&attr
);
4925 part_die
->has_type
= 1;
4927 case DW_AT_abstract_origin
:
4928 case DW_AT_specification
:
4929 case DW_AT_extension
:
4930 part_die
->has_specification
= 1;
4931 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
4934 /* Ignore absolute siblings, they might point outside of
4935 the current compile unit. */
4936 if (attr
.form
== DW_FORM_ref_addr
)
4937 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
4939 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
4940 + dwarf2_get_ref_die_offset (&attr
, cu
);
4942 case DW_AT_stmt_list
:
4943 part_die
->has_stmt_list
= 1;
4944 part_die
->line_offset
= DW_UNSND (&attr
);
4951 /* When using the GNU linker, .gnu.linkonce. sections are used to
4952 eliminate duplicate copies of functions and vtables and such.
4953 The linker will arbitrarily choose one and discard the others.
4954 The AT_*_pc values for such functions refer to local labels in
4955 these sections. If the section from that file was discarded, the
4956 labels are not in the output, so the relocs get a value of 0.
4957 If this is a discarded function, mark the pc bounds as invalid,
4958 so that GDB will ignore it. */
4959 if (has_low_pc_attr
&& has_high_pc_attr
4960 && part_die
->lowpc
< part_die
->highpc
4961 && (part_die
->lowpc
!= 0
4962 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
4963 part_die
->has_pc_info
= 1;
4967 /* Find a cached partial DIE at OFFSET in CU. */
4969 static struct partial_die_info
*
4970 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
4972 struct partial_die_info
*lookup_die
= NULL
;
4973 struct partial_die_info part_die
;
4975 part_die
.offset
= offset
;
4976 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
4978 if (lookup_die
== NULL
)
4979 internal_error (__FILE__
, __LINE__
,
4980 "could not find partial DIE in cache\n");
4985 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
4987 static struct partial_die_info
*
4988 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
,
4989 struct dwarf2_cu
**target_cu
)
4991 struct dwarf2_per_cu_data
*per_cu
;
4993 if (offset
>= cu
->header
.offset
4994 && offset
< cu
->header
.offset
+ cu
->header
.length
)
4997 return find_partial_die_in_comp_unit (offset
, cu
);
5000 internal_error (__FILE__
, __LINE__
,
5001 "unsupported inter-compilation-unit reference");
5004 /* Adjust PART_DIE before generating a symbol for it. This function
5005 may set the is_external flag or change the DIE's name. */
5008 fixup_partial_die (struct partial_die_info
*part_die
,
5009 struct dwarf2_cu
*cu
)
5011 /* If we found a reference attribute and the DIE has no name, try
5012 to find a name in the referred to DIE. */
5014 if (part_die
->name
== NULL
&& part_die
->has_specification
)
5016 struct partial_die_info
*spec_die
;
5017 struct dwarf2_cu
*spec_cu
;
5019 spec_die
= find_partial_die (part_die
->spec_offset
, cu
, &spec_cu
);
5021 fixup_partial_die (spec_die
, spec_cu
);
5025 part_die
->name
= spec_die
->name
;
5027 /* Copy DW_AT_external attribute if it is set. */
5028 if (spec_die
->is_external
)
5029 part_die
->is_external
= spec_die
->is_external
;
5033 /* Set default names for some unnamed DIEs. */
5034 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
5035 || part_die
->tag
== DW_TAG_class_type
))
5036 part_die
->name
= "(anonymous class)";
5038 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
5039 part_die
->name
= "(anonymous namespace)";
5041 if (part_die
->tag
== DW_TAG_structure_type
5042 || part_die
->tag
== DW_TAG_class_type
5043 || part_die
->tag
== DW_TAG_union_type
)
5044 guess_structure_name (part_die
, cu
);
5047 /* Read the die from the .debug_info section buffer. Set DIEP to
5048 point to a newly allocated die with its information, except for its
5049 child, sibling, and parent fields. Set HAS_CHILDREN to tell
5050 whether the die has children or not. */
5053 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
5054 struct dwarf2_cu
*cu
, int *has_children
)
5056 unsigned int abbrev_number
, bytes_read
, i
, offset
;
5057 struct abbrev_info
*abbrev
;
5058 struct die_info
*die
;
5060 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5061 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5062 info_ptr
+= bytes_read
;
5065 die
= dwarf_alloc_die ();
5067 die
->abbrev
= abbrev_number
;
5074 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
5077 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
5079 bfd_get_filename (abfd
));
5081 die
= dwarf_alloc_die ();
5082 die
->offset
= offset
;
5083 die
->tag
= abbrev
->tag
;
5084 die
->abbrev
= abbrev_number
;
5087 die
->num_attrs
= abbrev
->num_attrs
;
5088 die
->attrs
= (struct attribute
*)
5089 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
5091 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5093 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
5094 abfd
, info_ptr
, cu
);
5098 *has_children
= abbrev
->has_children
;
5102 /* Read an attribute value described by an attribute form. */
5105 read_attribute_value (struct attribute
*attr
, unsigned form
,
5106 bfd
*abfd
, char *info_ptr
,
5107 struct dwarf2_cu
*cu
)
5109 struct comp_unit_head
*cu_header
= &cu
->header
;
5110 unsigned int bytes_read
;
5111 struct dwarf_block
*blk
;
5117 case DW_FORM_ref_addr
:
5118 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
5119 info_ptr
+= bytes_read
;
5121 case DW_FORM_block2
:
5122 blk
= dwarf_alloc_block (cu
);
5123 blk
->size
= read_2_bytes (abfd
, info_ptr
);
5125 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5126 info_ptr
+= blk
->size
;
5127 DW_BLOCK (attr
) = blk
;
5129 case DW_FORM_block4
:
5130 blk
= dwarf_alloc_block (cu
);
5131 blk
->size
= read_4_bytes (abfd
, info_ptr
);
5133 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5134 info_ptr
+= blk
->size
;
5135 DW_BLOCK (attr
) = blk
;
5138 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
5142 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
5146 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
5149 case DW_FORM_string
:
5150 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
5151 info_ptr
+= bytes_read
;
5154 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
5156 info_ptr
+= bytes_read
;
5159 blk
= dwarf_alloc_block (cu
);
5160 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5161 info_ptr
+= bytes_read
;
5162 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5163 info_ptr
+= blk
->size
;
5164 DW_BLOCK (attr
) = blk
;
5166 case DW_FORM_block1
:
5167 blk
= dwarf_alloc_block (cu
);
5168 blk
->size
= read_1_byte (abfd
, info_ptr
);
5170 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5171 info_ptr
+= blk
->size
;
5172 DW_BLOCK (attr
) = blk
;
5175 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5179 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5183 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
5184 info_ptr
+= bytes_read
;
5187 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5188 info_ptr
+= bytes_read
;
5191 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5195 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
5199 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
5203 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
5206 case DW_FORM_ref_udata
:
5207 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5208 info_ptr
+= bytes_read
;
5210 case DW_FORM_indirect
:
5211 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5212 info_ptr
+= bytes_read
;
5213 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
5216 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
5217 dwarf_form_name (form
),
5218 bfd_get_filename (abfd
));
5223 /* Read an attribute described by an abbreviated attribute. */
5226 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
5227 bfd
*abfd
, char *info_ptr
, struct dwarf2_cu
*cu
)
5229 attr
->name
= abbrev
->name
;
5230 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
5233 /* read dwarf information from a buffer */
5236 read_1_byte (bfd
*abfd
, char *buf
)
5238 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5242 read_1_signed_byte (bfd
*abfd
, char *buf
)
5244 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
5248 read_2_bytes (bfd
*abfd
, char *buf
)
5250 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
5254 read_2_signed_bytes (bfd
*abfd
, char *buf
)
5256 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
5260 read_4_bytes (bfd
*abfd
, char *buf
)
5262 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5266 read_4_signed_bytes (bfd
*abfd
, char *buf
)
5268 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
5271 static unsigned long
5272 read_8_bytes (bfd
*abfd
, char *buf
)
5274 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5278 read_address (bfd
*abfd
, char *buf
, struct dwarf2_cu
*cu
, int *bytes_read
)
5280 struct comp_unit_head
*cu_header
= &cu
->header
;
5281 CORE_ADDR retval
= 0;
5283 if (cu_header
->signed_addr_p
)
5285 switch (cu_header
->addr_size
)
5288 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
5291 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
5294 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
5297 internal_error (__FILE__
, __LINE__
,
5298 "read_address: bad switch, signed [in module %s]",
5299 bfd_get_filename (abfd
));
5304 switch (cu_header
->addr_size
)
5307 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
5310 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5313 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5316 internal_error (__FILE__
, __LINE__
,
5317 "read_address: bad switch, unsigned [in module %s]",
5318 bfd_get_filename (abfd
));
5322 *bytes_read
= cu_header
->addr_size
;
5326 /* Read the initial length from a section. The (draft) DWARF 3
5327 specification allows the initial length to take up either 4 bytes
5328 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
5329 bytes describe the length and all offsets will be 8 bytes in length
5332 An older, non-standard 64-bit format is also handled by this
5333 function. The older format in question stores the initial length
5334 as an 8-byte quantity without an escape value. Lengths greater
5335 than 2^32 aren't very common which means that the initial 4 bytes
5336 is almost always zero. Since a length value of zero doesn't make
5337 sense for the 32-bit format, this initial zero can be considered to
5338 be an escape value which indicates the presence of the older 64-bit
5339 format. As written, the code can't detect (old format) lengths
5340 greater than 4GB. If it becomes necessary to handle lengths somewhat
5341 larger than 4GB, we could allow other small values (such as the
5342 non-sensical values of 1, 2, and 3) to also be used as escape values
5343 indicating the presence of the old format.
5345 The value returned via bytes_read should be used to increment
5346 the relevant pointer after calling read_initial_length().
5348 As a side effect, this function sets the fields initial_length_size
5349 and offset_size in cu_header to the values appropriate for the
5350 length field. (The format of the initial length field determines
5351 the width of file offsets to be fetched later with fetch_offset().)
5353 [ Note: read_initial_length() and read_offset() are based on the
5354 document entitled "DWARF Debugging Information Format", revision
5355 3, draft 8, dated November 19, 2001. This document was obtained
5358 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
5360 This document is only a draft and is subject to change. (So beware.)
5362 Details regarding the older, non-standard 64-bit format were
5363 determined empirically by examining 64-bit ELF files produced
5364 by the SGI toolchain on an IRIX 6.5 machine.
5366 - Kevin, July 16, 2002
5370 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
5375 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5377 if (retval
== 0xffffffff)
5379 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
5381 if (cu_header
!= NULL
)
5383 cu_header
->initial_length_size
= 12;
5384 cu_header
->offset_size
= 8;
5387 else if (retval
== 0)
5389 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
5391 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5393 if (cu_header
!= NULL
)
5395 cu_header
->initial_length_size
= 8;
5396 cu_header
->offset_size
= 8;
5402 if (cu_header
!= NULL
)
5404 cu_header
->initial_length_size
= 4;
5405 cu_header
->offset_size
= 4;
5412 /* Read an offset from the data stream. The size of the offset is
5413 given by cu_header->offset_size. */
5416 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
5421 switch (cu_header
->offset_size
)
5424 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5428 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5432 internal_error (__FILE__
, __LINE__
,
5433 "read_offset: bad switch [in module %s]",
5434 bfd_get_filename (abfd
));
5441 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
5443 /* If the size of a host char is 8 bits, we can return a pointer
5444 to the buffer, otherwise we have to copy the data to a buffer
5445 allocated on the temporary obstack. */
5446 gdb_assert (HOST_CHAR_BIT
== 8);
5451 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5453 /* If the size of a host char is 8 bits, we can return a pointer
5454 to the string, otherwise we have to copy the string to a buffer
5455 allocated on the temporary obstack. */
5456 gdb_assert (HOST_CHAR_BIT
== 8);
5459 *bytes_read_ptr
= 1;
5462 *bytes_read_ptr
= strlen (buf
) + 1;
5467 read_indirect_string (bfd
*abfd
, char *buf
,
5468 const struct comp_unit_head
*cu_header
,
5469 unsigned int *bytes_read_ptr
)
5471 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
5472 (int *) bytes_read_ptr
);
5474 if (dwarf2_per_objfile
->str_buffer
== NULL
)
5476 error ("DW_FORM_strp used without .debug_str section [in module %s]",
5477 bfd_get_filename (abfd
));
5480 if (str_offset
>= dwarf2_per_objfile
->str_size
)
5482 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
5483 bfd_get_filename (abfd
));
5486 gdb_assert (HOST_CHAR_BIT
== 8);
5487 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
5489 return dwarf2_per_objfile
->str_buffer
+ str_offset
;
5492 static unsigned long
5493 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5495 unsigned long result
;
5496 unsigned int num_read
;
5506 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5509 result
|= ((unsigned long)(byte
& 127) << shift
);
5510 if ((byte
& 128) == 0)
5516 *bytes_read_ptr
= num_read
;
5521 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5524 int i
, shift
, size
, num_read
;
5534 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5537 result
|= ((long)(byte
& 127) << shift
);
5539 if ((byte
& 128) == 0)
5544 if ((shift
< size
) && (byte
& 0x40))
5546 result
|= -(1 << shift
);
5548 *bytes_read_ptr
= num_read
;
5552 /* Return a pointer to just past the end of an LEB128 number in BUF. */
5555 skip_leb128 (bfd
*abfd
, char *buf
)
5561 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5563 if ((byte
& 128) == 0)
5569 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
5575 cu
->language
= language_c
;
5577 case DW_LANG_C_plus_plus
:
5578 cu
->language
= language_cplus
;
5580 case DW_LANG_Fortran77
:
5581 case DW_LANG_Fortran90
:
5582 case DW_LANG_Fortran95
:
5583 cu
->language
= language_fortran
;
5585 case DW_LANG_Mips_Assembler
:
5586 cu
->language
= language_asm
;
5589 cu
->language
= language_java
;
5593 case DW_LANG_Cobol74
:
5594 case DW_LANG_Cobol85
:
5595 case DW_LANG_Pascal83
:
5596 case DW_LANG_Modula2
:
5598 cu
->language
= language_minimal
;
5601 cu
->language_defn
= language_def (cu
->language
);
5604 /* Return the named attribute or NULL if not there. */
5606 static struct attribute
*
5607 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
5610 struct attribute
*spec
= NULL
;
5612 for (i
= 0; i
< die
->num_attrs
; ++i
)
5614 if (die
->attrs
[i
].name
== name
)
5616 return &die
->attrs
[i
];
5618 if (die
->attrs
[i
].name
== DW_AT_specification
5619 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
5620 spec
= &die
->attrs
[i
];
5624 struct die_info
*ref_die
=
5625 follow_die_ref (dwarf2_get_ref_die_offset (spec
, cu
));
5628 return dwarf2_attr (ref_die
, name
, cu
);
5634 /* Return non-zero iff the attribute NAME is defined for the given DIE,
5635 and holds a non-zero value. This function should only be used for
5636 DW_FORM_flag attributes. */
5639 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
5641 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
5643 return (attr
&& DW_UNSND (attr
));
5647 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
5649 /* A DIE is a declaration if it has a DW_AT_declaration attribute
5650 which value is non-zero. However, we have to be careful with
5651 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
5652 (via dwarf2_flag_true_p) follows this attribute. So we may
5653 end up accidently finding a declaration attribute that belongs
5654 to a different DIE referenced by the specification attribute,
5655 even though the given DIE does not have a declaration attribute. */
5656 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
5657 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
5660 /* Return the die giving the specification for DIE, if there is
5663 static struct die_info
*
5664 die_specification (struct die_info
*die
, struct dwarf2_cu
*cu
)
5666 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
, cu
);
5668 if (spec_attr
== NULL
)
5671 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr
, cu
));
5674 /* Free the line_header structure *LH, and any arrays and strings it
5677 free_line_header (struct line_header
*lh
)
5679 if (lh
->standard_opcode_lengths
)
5680 xfree (lh
->standard_opcode_lengths
);
5682 /* Remember that all the lh->file_names[i].name pointers are
5683 pointers into debug_line_buffer, and don't need to be freed. */
5685 xfree (lh
->file_names
);
5687 /* Similarly for the include directory names. */
5688 if (lh
->include_dirs
)
5689 xfree (lh
->include_dirs
);
5695 /* Add an entry to LH's include directory table. */
5697 add_include_dir (struct line_header
*lh
, char *include_dir
)
5699 /* Grow the array if necessary. */
5700 if (lh
->include_dirs_size
== 0)
5702 lh
->include_dirs_size
= 1; /* for testing */
5703 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
5704 * sizeof (*lh
->include_dirs
));
5706 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
5708 lh
->include_dirs_size
*= 2;
5709 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
5710 (lh
->include_dirs_size
5711 * sizeof (*lh
->include_dirs
)));
5714 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
5718 /* Add an entry to LH's file name table. */
5720 add_file_name (struct line_header
*lh
,
5722 unsigned int dir_index
,
5723 unsigned int mod_time
,
5724 unsigned int length
)
5726 struct file_entry
*fe
;
5728 /* Grow the array if necessary. */
5729 if (lh
->file_names_size
== 0)
5731 lh
->file_names_size
= 1; /* for testing */
5732 lh
->file_names
= xmalloc (lh
->file_names_size
5733 * sizeof (*lh
->file_names
));
5735 else if (lh
->num_file_names
>= lh
->file_names_size
)
5737 lh
->file_names_size
*= 2;
5738 lh
->file_names
= xrealloc (lh
->file_names
,
5739 (lh
->file_names_size
5740 * sizeof (*lh
->file_names
)));
5743 fe
= &lh
->file_names
[lh
->num_file_names
++];
5745 fe
->dir_index
= dir_index
;
5746 fe
->mod_time
= mod_time
;
5747 fe
->length
= length
;
5752 /* Read the statement program header starting at OFFSET in
5753 .debug_line, according to the endianness of ABFD. Return a pointer
5754 to a struct line_header, allocated using xmalloc.
5756 NOTE: the strings in the include directory and file name tables of
5757 the returned object point into debug_line_buffer, and must not be
5759 static struct line_header
*
5760 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
5761 struct dwarf2_cu
*cu
)
5763 struct cleanup
*back_to
;
5764 struct line_header
*lh
;
5768 char *cur_dir
, *cur_file
;
5770 if (dwarf2_per_objfile
->line_buffer
== NULL
)
5772 complaint (&symfile_complaints
, "missing .debug_line section");
5776 /* Make sure that at least there's room for the total_length field. That
5777 could be 12 bytes long, but we're just going to fudge that. */
5778 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
5780 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5784 lh
= xmalloc (sizeof (*lh
));
5785 memset (lh
, 0, sizeof (*lh
));
5786 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
5789 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
5791 /* read in the header */
5792 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
5793 line_ptr
+= bytes_read
;
5794 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
5795 + dwarf2_per_objfile
->line_size
))
5797 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5800 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
5801 lh
->version
= read_2_bytes (abfd
, line_ptr
);
5803 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
5804 line_ptr
+= bytes_read
;
5805 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
5807 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
5809 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
5811 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
5813 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
5815 lh
->standard_opcode_lengths
5816 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
5818 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
5819 for (i
= 1; i
< lh
->opcode_base
; ++i
)
5821 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
5825 /* Read directory table */
5826 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5828 line_ptr
+= bytes_read
;
5829 add_include_dir (lh
, cur_dir
);
5831 line_ptr
+= bytes_read
;
5833 /* Read file name table */
5834 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5836 unsigned int dir_index
, mod_time
, length
;
5838 line_ptr
+= bytes_read
;
5839 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5840 line_ptr
+= bytes_read
;
5841 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5842 line_ptr
+= bytes_read
;
5843 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5844 line_ptr
+= bytes_read
;
5846 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5848 line_ptr
+= bytes_read
;
5849 lh
->statement_program_start
= line_ptr
;
5851 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
5852 + dwarf2_per_objfile
->line_size
))
5853 complaint (&symfile_complaints
,
5854 "line number info header doesn't fit in `.debug_line' section");
5856 discard_cleanups (back_to
);
5860 /* This function exists to work around a bug in certain compilers
5861 (particularly GCC 2.95), in which the first line number marker of a
5862 function does not show up until after the prologue, right before
5863 the second line number marker. This function shifts ADDRESS down
5864 to the beginning of the function if necessary, and is called on
5865 addresses passed to record_line. */
5868 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
5870 struct function_range
*fn
;
5872 /* Find the function_range containing address. */
5877 cu
->cached_fn
= cu
->first_fn
;
5881 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5887 while (fn
&& fn
!= cu
->cached_fn
)
5888 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5898 if (address
!= fn
->lowpc
)
5899 complaint (&symfile_complaints
,
5900 "misplaced first line number at 0x%lx for '%s'",
5901 (unsigned long) address
, fn
->name
);
5906 /* Decode the Line Number Program (LNP) for the given line_header
5907 structure and CU. The actual information extracted and the type
5908 of structures created from the LNP depends on the value of PST.
5910 1. If PST is NULL, then this procedure uses the data from the program
5911 to create all necessary symbol tables, and their linetables.
5912 The compilation directory of the file is passed in COMP_DIR,
5913 and must not be NULL.
5915 2. If PST is not NULL, this procedure reads the program to determine
5916 the list of files included by the unit represented by PST, and
5917 builds all the associated partial symbol tables. In this case,
5918 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
5919 is not used to compute the full name of the symtab, and therefore
5920 omitting it when building the partial symtab does not introduce
5921 the potential for inconsistency - a partial symtab and its associated
5922 symbtab having a different fullname -). */
5925 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
5926 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
5930 unsigned int bytes_read
;
5931 unsigned char op_code
, extended_op
, adj_opcode
;
5933 struct objfile
*objfile
= cu
->objfile
;
5934 const int decode_for_pst_p
= (pst
!= NULL
);
5936 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5938 line_ptr
= lh
->statement_program_start
;
5939 line_end
= lh
->statement_program_end
;
5941 /* Read the statement sequences until there's nothing left. */
5942 while (line_ptr
< line_end
)
5944 /* state machine registers */
5945 CORE_ADDR address
= 0;
5946 unsigned int file
= 1;
5947 unsigned int line
= 1;
5948 unsigned int column
= 0;
5949 int is_stmt
= lh
->default_is_stmt
;
5950 int basic_block
= 0;
5951 int end_sequence
= 0;
5953 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
5955 /* Start a subfile for the current file of the state machine. */
5956 /* lh->include_dirs and lh->file_names are 0-based, but the
5957 directory and file name numbers in the statement program
5959 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
5962 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5965 dwarf2_start_subfile (fe
->name
, dir
);
5968 /* Decode the table. */
5969 while (!end_sequence
)
5971 op_code
= read_1_byte (abfd
, line_ptr
);
5974 if (op_code
>= lh
->opcode_base
)
5975 { /* Special operand. */
5976 adj_opcode
= op_code
- lh
->opcode_base
;
5977 address
+= (adj_opcode
/ lh
->line_range
)
5978 * lh
->minimum_instruction_length
;
5979 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
5980 if (!decode_for_pst_p
)
5982 /* append row to matrix using current values */
5983 record_line (current_subfile
, line
,
5984 check_cu_functions (address
, cu
));
5988 else switch (op_code
)
5990 case DW_LNS_extended_op
:
5991 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5992 line_ptr
+= bytes_read
;
5993 extended_op
= read_1_byte (abfd
, line_ptr
);
5995 switch (extended_op
)
5997 case DW_LNE_end_sequence
:
5999 if (!decode_for_pst_p
)
6000 record_line (current_subfile
, 0, address
);
6002 case DW_LNE_set_address
:
6003 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
6004 line_ptr
+= bytes_read
;
6005 address
+= baseaddr
;
6007 case DW_LNE_define_file
:
6010 unsigned int dir_index
, mod_time
, length
;
6012 cur_file
= read_string (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
;
6021 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6022 line_ptr
+= bytes_read
;
6023 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6027 complaint (&symfile_complaints
,
6028 "mangled .debug_line section");
6033 if (!decode_for_pst_p
)
6034 record_line (current_subfile
, line
,
6035 check_cu_functions (address
, cu
));
6038 case DW_LNS_advance_pc
:
6039 address
+= lh
->minimum_instruction_length
6040 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6041 line_ptr
+= bytes_read
;
6043 case DW_LNS_advance_line
:
6044 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
6045 line_ptr
+= bytes_read
;
6047 case DW_LNS_set_file
:
6049 /* lh->include_dirs and lh->file_names are 0-based,
6050 but the directory and file name numbers in the
6051 statement program are 1-based. */
6052 struct file_entry
*fe
;
6054 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6055 line_ptr
+= bytes_read
;
6056 fe
= &lh
->file_names
[file
- 1];
6059 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6062 if (!decode_for_pst_p
)
6063 dwarf2_start_subfile (fe
->name
, dir
);
6066 case DW_LNS_set_column
:
6067 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6068 line_ptr
+= bytes_read
;
6070 case DW_LNS_negate_stmt
:
6071 is_stmt
= (!is_stmt
);
6073 case DW_LNS_set_basic_block
:
6076 /* Add to the address register of the state machine the
6077 address increment value corresponding to special opcode
6078 255. Ie, this value is scaled by the minimum instruction
6079 length since special opcode 255 would have scaled the
6081 case DW_LNS_const_add_pc
:
6082 address
+= (lh
->minimum_instruction_length
6083 * ((255 - lh
->opcode_base
) / lh
->line_range
));
6085 case DW_LNS_fixed_advance_pc
:
6086 address
+= read_2_bytes (abfd
, line_ptr
);
6090 { /* Unknown standard opcode, ignore it. */
6092 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
6094 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6095 line_ptr
+= bytes_read
;
6102 if (decode_for_pst_p
)
6106 /* Now that we're done scanning the Line Header Program, we can
6107 create the psymtab of each included file. */
6108 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
6109 if (lh
->file_names
[file_index
].included_p
== 1)
6111 char *include_name
= lh
->file_names
[file_index
].name
;
6113 if (strcmp (include_name
, pst
->filename
) != 0)
6114 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
6119 /* Start a subfile for DWARF. FILENAME is the name of the file and
6120 DIRNAME the name of the source directory which contains FILENAME
6121 or NULL if not known.
6122 This routine tries to keep line numbers from identical absolute and
6123 relative file names in a common subfile.
6125 Using the `list' example from the GDB testsuite, which resides in
6126 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
6127 of /srcdir/list0.c yields the following debugging information for list0.c:
6129 DW_AT_name: /srcdir/list0.c
6130 DW_AT_comp_dir: /compdir
6131 files.files[0].name: list0.h
6132 files.files[0].dir: /srcdir
6133 files.files[1].name: list0.c
6134 files.files[1].dir: /srcdir
6136 The line number information for list0.c has to end up in a single
6137 subfile, so that `break /srcdir/list0.c:1' works as expected. */
6140 dwarf2_start_subfile (char *filename
, char *dirname
)
6142 /* If the filename isn't absolute, try to match an existing subfile
6143 with the full pathname. */
6145 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
6147 struct subfile
*subfile
;
6148 char *fullname
= concat (dirname
, "/", filename
, NULL
);
6150 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
6152 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
6154 current_subfile
= subfile
;
6161 start_subfile (filename
, dirname
);
6165 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
6166 struct dwarf2_cu
*cu
)
6168 struct objfile
*objfile
= cu
->objfile
;
6169 struct comp_unit_head
*cu_header
= &cu
->header
;
6171 /* NOTE drow/2003-01-30: There used to be a comment and some special
6172 code here to turn a symbol with DW_AT_external and a
6173 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
6174 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
6175 with some versions of binutils) where shared libraries could have
6176 relocations against symbols in their debug information - the
6177 minimal symbol would have the right address, but the debug info
6178 would not. It's no longer necessary, because we will explicitly
6179 apply relocations when we read in the debug information now. */
6181 /* A DW_AT_location attribute with no contents indicates that a
6182 variable has been optimized away. */
6183 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
6185 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
6189 /* Handle one degenerate form of location expression specially, to
6190 preserve GDB's previous behavior when section offsets are
6191 specified. If this is just a DW_OP_addr then mark this symbol
6194 if (attr_form_is_block (attr
)
6195 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
6196 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
6200 SYMBOL_VALUE_ADDRESS (sym
) =
6201 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
6202 fixup_symbol_section (sym
, objfile
);
6203 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
6204 SYMBOL_SECTION (sym
));
6205 SYMBOL_CLASS (sym
) = LOC_STATIC
;
6209 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
6210 expression evaluator, and use LOC_COMPUTED only when necessary
6211 (i.e. when the value of a register or memory location is
6212 referenced, or a thread-local block, etc.). Then again, it might
6213 not be worthwhile. I'm assuming that it isn't unless performance
6214 or memory numbers show me otherwise. */
6216 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
6217 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
6220 /* Given a pointer to a DWARF information entry, figure out if we need
6221 to make a symbol table entry for it, and if so, create a new entry
6222 and return a pointer to it.
6223 If TYPE is NULL, determine symbol type from the die, otherwise
6224 used the passed type. */
6226 static struct symbol
*
6227 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
6229 struct objfile
*objfile
= cu
->objfile
;
6230 struct symbol
*sym
= NULL
;
6232 struct attribute
*attr
= NULL
;
6233 struct attribute
*attr2
= NULL
;
6236 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6238 if (die
->tag
!= DW_TAG_namespace
)
6239 name
= dwarf2_linkage_name (die
, cu
);
6241 name
= TYPE_NAME (type
);
6245 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
6246 sizeof (struct symbol
));
6247 OBJSTAT (objfile
, n_syms
++);
6248 memset (sym
, 0, sizeof (struct symbol
));
6250 /* Cache this symbol's name and the name's demangled form (if any). */
6251 SYMBOL_LANGUAGE (sym
) = cu
->language
;
6252 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
6254 /* Default assumptions.
6255 Use the passed type or decode it from the die. */
6256 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6257 SYMBOL_CLASS (sym
) = LOC_STATIC
;
6259 SYMBOL_TYPE (sym
) = type
;
6261 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
6262 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
6265 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
6270 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6273 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
6275 SYMBOL_CLASS (sym
) = LOC_LABEL
;
6277 case DW_TAG_subprogram
:
6278 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
6280 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
6281 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6282 if (attr2
&& (DW_UNSND (attr2
) != 0))
6284 add_symbol_to_list (sym
, &global_symbols
);
6288 add_symbol_to_list (sym
, cu
->list_in_scope
);
6291 case DW_TAG_variable
:
6292 /* Compilation with minimal debug info may result in variables
6293 with missing type entries. Change the misleading `void' type
6294 to something sensible. */
6295 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
6296 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
6297 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
6298 "<variable, no debug info>",
6300 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6303 dwarf2_const_value (attr
, sym
, cu
);
6304 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6305 if (attr2
&& (DW_UNSND (attr2
) != 0))
6306 add_symbol_to_list (sym
, &global_symbols
);
6308 add_symbol_to_list (sym
, cu
->list_in_scope
);
6311 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6314 var_decode_location (attr
, sym
, cu
);
6315 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6316 if (attr2
&& (DW_UNSND (attr2
) != 0))
6317 add_symbol_to_list (sym
, &global_symbols
);
6319 add_symbol_to_list (sym
, cu
->list_in_scope
);
6323 /* We do not know the address of this symbol.
6324 If it is an external symbol and we have type information
6325 for it, enter the symbol as a LOC_UNRESOLVED symbol.
6326 The address of the variable will then be determined from
6327 the minimal symbol table whenever the variable is
6329 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6330 if (attr2
&& (DW_UNSND (attr2
) != 0)
6331 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
6333 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
6334 add_symbol_to_list (sym
, &global_symbols
);
6338 case DW_TAG_formal_parameter
:
6339 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6342 var_decode_location (attr
, sym
, cu
);
6343 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
6344 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
6345 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
6347 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6350 dwarf2_const_value (attr
, sym
, cu
);
6352 add_symbol_to_list (sym
, cu
->list_in_scope
);
6354 case DW_TAG_unspecified_parameters
:
6355 /* From varargs functions; gdb doesn't seem to have any
6356 interest in this information, so just ignore it for now.
6359 case DW_TAG_class_type
:
6360 case DW_TAG_structure_type
:
6361 case DW_TAG_union_type
:
6362 case DW_TAG_enumeration_type
:
6363 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6364 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6366 /* Make sure that the symbol includes appropriate enclosing
6367 classes/namespaces in its name. These are calculated in
6368 read_structure_type, and the correct name is saved in
6371 if (cu
->language
== language_cplus
)
6373 struct type
*type
= SYMBOL_TYPE (sym
);
6375 if (TYPE_TAG_NAME (type
) != NULL
)
6377 /* FIXME: carlton/2003-11-10: Should this use
6378 SYMBOL_SET_NAMES instead? (The same problem also
6379 arises further down in this function.) */
6380 /* The type's name is already allocated along with
6381 this objfile, so we don't need to duplicate it
6383 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
6388 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
6389 really ever be static objects: otherwise, if you try
6390 to, say, break of a class's method and you're in a file
6391 which doesn't mention that class, it won't work unless
6392 the check for all static symbols in lookup_symbol_aux
6393 saves you. See the OtherFileClass tests in
6394 gdb.c++/namespace.exp. */
6396 struct pending
**list_to_add
;
6398 list_to_add
= (cu
->list_in_scope
== &file_symbols
6399 && cu
->language
== language_cplus
6400 ? &global_symbols
: cu
->list_in_scope
);
6402 add_symbol_to_list (sym
, list_to_add
);
6404 /* The semantics of C++ state that "struct foo { ... }" also
6405 defines a typedef for "foo". Synthesize a typedef symbol so
6406 that "ptype foo" works as expected. */
6407 if (cu
->language
== language_cplus
)
6409 struct symbol
*typedef_sym
= (struct symbol
*)
6410 obstack_alloc (&objfile
->objfile_obstack
,
6411 sizeof (struct symbol
));
6412 *typedef_sym
= *sym
;
6413 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
6414 /* The symbol's name is already allocated along with
6415 this objfile, so we don't need to duplicate it for
6417 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
6418 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NATURAL_NAME (sym
);
6419 add_symbol_to_list (typedef_sym
, list_to_add
);
6423 case DW_TAG_typedef
:
6424 if (processing_has_namespace_info
6425 && processing_current_prefix
[0] != '\0')
6427 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->objfile_obstack
,
6428 processing_current_prefix
,
6432 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6433 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6434 add_symbol_to_list (sym
, cu
->list_in_scope
);
6436 case DW_TAG_base_type
:
6437 case DW_TAG_subrange_type
:
6438 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6439 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6440 add_symbol_to_list (sym
, cu
->list_in_scope
);
6442 case DW_TAG_enumerator
:
6443 if (processing_has_namespace_info
6444 && processing_current_prefix
[0] != '\0')
6446 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->objfile_obstack
,
6447 processing_current_prefix
,
6451 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6454 dwarf2_const_value (attr
, sym
, cu
);
6457 /* NOTE: carlton/2003-11-10: See comment above in the
6458 DW_TAG_class_type, etc. block. */
6460 struct pending
**list_to_add
;
6462 list_to_add
= (cu
->list_in_scope
== &file_symbols
6463 && cu
->language
== language_cplus
6464 ? &global_symbols
: cu
->list_in_scope
);
6466 add_symbol_to_list (sym
, list_to_add
);
6469 case DW_TAG_namespace
:
6470 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6471 add_symbol_to_list (sym
, &global_symbols
);
6474 /* Not a tag we recognize. Hopefully we aren't processing
6475 trash data, but since we must specifically ignore things
6476 we don't recognize, there is nothing else we should do at
6478 complaint (&symfile_complaints
, "unsupported tag: '%s'",
6479 dwarf_tag_name (die
->tag
));
6486 /* Copy constant value from an attribute to a symbol. */
6489 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
6490 struct dwarf2_cu
*cu
)
6492 struct objfile
*objfile
= cu
->objfile
;
6493 struct comp_unit_head
*cu_header
= &cu
->header
;
6494 struct dwarf_block
*blk
;
6499 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
6500 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
6501 cu_header
->addr_size
,
6502 TYPE_LENGTH (SYMBOL_TYPE
6504 SYMBOL_VALUE_BYTES (sym
) = (char *)
6505 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
6506 /* NOTE: cagney/2003-05-09: In-lined store_address call with
6507 it's body - store_unsigned_integer. */
6508 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
6510 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6512 case DW_FORM_block1
:
6513 case DW_FORM_block2
:
6514 case DW_FORM_block4
:
6516 blk
= DW_BLOCK (attr
);
6517 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
6518 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
6520 TYPE_LENGTH (SYMBOL_TYPE
6522 SYMBOL_VALUE_BYTES (sym
) = (char *)
6523 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
6524 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
6525 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6528 /* The DW_AT_const_value attributes are supposed to carry the
6529 symbol's value "represented as it would be on the target
6530 architecture." By the time we get here, it's already been
6531 converted to host endianness, so we just need to sign- or
6532 zero-extend it as appropriate. */
6534 dwarf2_const_value_data (attr
, sym
, 8);
6537 dwarf2_const_value_data (attr
, sym
, 16);
6540 dwarf2_const_value_data (attr
, sym
, 32);
6543 dwarf2_const_value_data (attr
, sym
, 64);
6547 SYMBOL_VALUE (sym
) = DW_SND (attr
);
6548 SYMBOL_CLASS (sym
) = LOC_CONST
;
6552 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
6553 SYMBOL_CLASS (sym
) = LOC_CONST
;
6557 complaint (&symfile_complaints
,
6558 "unsupported const value attribute form: '%s'",
6559 dwarf_form_name (attr
->form
));
6560 SYMBOL_VALUE (sym
) = 0;
6561 SYMBOL_CLASS (sym
) = LOC_CONST
;
6567 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
6568 or zero-extend it as appropriate for the symbol's type. */
6570 dwarf2_const_value_data (struct attribute
*attr
,
6574 LONGEST l
= DW_UNSND (attr
);
6576 if (bits
< sizeof (l
) * 8)
6578 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
6579 l
&= ((LONGEST
) 1 << bits
) - 1;
6581 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
6584 SYMBOL_VALUE (sym
) = l
;
6585 SYMBOL_CLASS (sym
) = LOC_CONST
;
6589 /* Return the type of the die in question using its DW_AT_type attribute. */
6591 static struct type
*
6592 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6595 struct attribute
*type_attr
;
6596 struct die_info
*type_die
;
6599 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
6602 /* A missing DW_AT_type represents a void type. */
6603 return dwarf2_fundamental_type (cu
->objfile
, FT_VOID
, cu
);
6607 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6608 type_die
= follow_die_ref (ref
);
6611 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
6612 ref
, cu
->objfile
->name
);
6616 type
= tag_type_to_type (type_die
, cu
);
6619 dump_die (type_die
);
6620 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
6626 /* Return the containing type of the die in question using its
6627 DW_AT_containing_type attribute. */
6629 static struct type
*
6630 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6632 struct type
*type
= NULL
;
6633 struct attribute
*type_attr
;
6634 struct die_info
*type_die
= NULL
;
6637 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
6640 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6641 type_die
= follow_die_ref (ref
);
6644 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
6648 type
= tag_type_to_type (type_die
, cu
);
6653 dump_die (type_die
);
6654 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
6661 static struct type
*
6662 type_at_offset (unsigned int offset
, struct dwarf2_cu
*cu
)
6664 struct die_info
*die
;
6667 die
= follow_die_ref (offset
);
6670 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
6673 type
= tag_type_to_type (die
, cu
);
6678 static struct type
*
6679 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6687 read_type_die (die
, cu
);
6691 error ("Dwarf Error: Cannot find type of die [in module %s]",
6699 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6701 char *prefix
= determine_prefix (die
, cu
);
6702 const char *old_prefix
= processing_current_prefix
;
6703 struct cleanup
*back_to
= make_cleanup (xfree
, prefix
);
6704 processing_current_prefix
= prefix
;
6708 case DW_TAG_class_type
:
6709 case DW_TAG_structure_type
:
6710 case DW_TAG_union_type
:
6711 read_structure_type (die
, cu
);
6713 case DW_TAG_enumeration_type
:
6714 read_enumeration_type (die
, cu
);
6716 case DW_TAG_subprogram
:
6717 case DW_TAG_subroutine_type
:
6718 read_subroutine_type (die
, cu
);
6720 case DW_TAG_array_type
:
6721 read_array_type (die
, cu
);
6723 case DW_TAG_pointer_type
:
6724 read_tag_pointer_type (die
, cu
);
6726 case DW_TAG_ptr_to_member_type
:
6727 read_tag_ptr_to_member_type (die
, cu
);
6729 case DW_TAG_reference_type
:
6730 read_tag_reference_type (die
, cu
);
6732 case DW_TAG_const_type
:
6733 read_tag_const_type (die
, cu
);
6735 case DW_TAG_volatile_type
:
6736 read_tag_volatile_type (die
, cu
);
6738 case DW_TAG_string_type
:
6739 read_tag_string_type (die
, cu
);
6741 case DW_TAG_typedef
:
6742 read_typedef (die
, cu
);
6744 case DW_TAG_subrange_type
:
6745 read_subrange_type (die
, cu
);
6747 case DW_TAG_base_type
:
6748 read_base_type (die
, cu
);
6751 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
6752 dwarf_tag_name (die
->tag
));
6756 processing_current_prefix
= old_prefix
;
6757 do_cleanups (back_to
);
6760 /* Return the name of the namespace/class that DIE is defined within,
6761 or "" if we can't tell. The caller should xfree the result. */
6763 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
6764 therein) for an example of how to use this function to deal with
6765 DW_AT_specification. */
6768 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
6770 struct die_info
*parent
;
6772 if (cu
->language
!= language_cplus
)
6775 parent
= die
->parent
;
6779 return xstrdup ("");
6783 switch (parent
->tag
) {
6784 case DW_TAG_namespace
:
6786 /* FIXME: carlton/2004-03-05: Should I follow extension dies
6787 before doing this check? */
6788 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
6790 return xstrdup (TYPE_TAG_NAME (parent
->type
));
6795 char *parent_prefix
= determine_prefix (parent
, cu
);
6796 char *retval
= typename_concat (parent_prefix
,
6797 namespace_name (parent
, &dummy
,
6799 xfree (parent_prefix
);
6804 case DW_TAG_class_type
:
6805 case DW_TAG_structure_type
:
6807 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
6809 return xstrdup (TYPE_TAG_NAME (parent
->type
));
6813 const char *old_prefix
= processing_current_prefix
;
6814 char *new_prefix
= determine_prefix (parent
, cu
);
6817 processing_current_prefix
= new_prefix
;
6818 retval
= determine_class_name (parent
, cu
);
6819 processing_current_prefix
= old_prefix
;
6826 return determine_prefix (parent
, cu
);
6831 /* Return a newly-allocated string formed by concatenating PREFIX,
6832 "::", and SUFFIX, except that if PREFIX is NULL or the empty
6833 string, just return a copy of SUFFIX. */
6836 typename_concat (const char *prefix
, const char *suffix
)
6838 if (prefix
== NULL
|| prefix
[0] == '\0')
6839 return xstrdup (suffix
);
6842 char *retval
= xmalloc (strlen (prefix
) + 2 + strlen (suffix
) + 1);
6844 strcpy (retval
, prefix
);
6845 strcat (retval
, "::");
6846 strcat (retval
, suffix
);
6852 static struct type
*
6853 dwarf_base_type (int encoding
, int size
, struct dwarf2_cu
*cu
)
6855 struct objfile
*objfile
= cu
->objfile
;
6857 /* FIXME - this should not produce a new (struct type *)
6858 every time. It should cache base types. */
6862 case DW_ATE_address
:
6863 type
= dwarf2_fundamental_type (objfile
, FT_VOID
, cu
);
6865 case DW_ATE_boolean
:
6866 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
, cu
);
6868 case DW_ATE_complex_float
:
6871 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
, cu
);
6875 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
, cu
);
6881 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
6885 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
6892 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6895 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
, cu
);
6899 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6903 case DW_ATE_signed_char
:
6904 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6906 case DW_ATE_unsigned
:
6910 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6913 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
, cu
);
6917 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
, cu
);
6921 case DW_ATE_unsigned_char
:
6922 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6925 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6932 copy_die (struct die_info
*old_die
)
6934 struct die_info
*new_die
;
6937 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6938 memset (new_die
, 0, sizeof (struct die_info
));
6940 new_die
->tag
= old_die
->tag
;
6941 new_die
->has_children
= old_die
->has_children
;
6942 new_die
->abbrev
= old_die
->abbrev
;
6943 new_die
->offset
= old_die
->offset
;
6944 new_die
->type
= NULL
;
6946 num_attrs
= old_die
->num_attrs
;
6947 new_die
->num_attrs
= num_attrs
;
6948 new_die
->attrs
= (struct attribute
*)
6949 xmalloc (num_attrs
* sizeof (struct attribute
));
6951 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
6953 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
6954 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
6955 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
6958 new_die
->next
= NULL
;
6963 /* Return sibling of die, NULL if no sibling. */
6965 static struct die_info
*
6966 sibling_die (struct die_info
*die
)
6968 return die
->sibling
;
6971 /* Get linkage name of a die, return NULL if not found. */
6974 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6976 struct attribute
*attr
;
6978 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6979 if (attr
&& DW_STRING (attr
))
6980 return DW_STRING (attr
);
6981 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6982 if (attr
&& DW_STRING (attr
))
6983 return DW_STRING (attr
);
6987 /* Get name of a die, return NULL if not found. */
6990 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6992 struct attribute
*attr
;
6994 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6995 if (attr
&& DW_STRING (attr
))
6996 return DW_STRING (attr
);
7000 /* Return the die that this die in an extension of, or NULL if there
7003 static struct die_info
*
7004 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
7006 struct attribute
*attr
;
7007 struct die_info
*extension_die
;
7010 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
7014 ref
= dwarf2_get_ref_die_offset (attr
, cu
);
7015 extension_die
= follow_die_ref (ref
);
7018 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
7021 return extension_die
;
7024 /* Convert a DIE tag into its string name. */
7027 dwarf_tag_name (unsigned tag
)
7031 case DW_TAG_padding
:
7032 return "DW_TAG_padding";
7033 case DW_TAG_array_type
:
7034 return "DW_TAG_array_type";
7035 case DW_TAG_class_type
:
7036 return "DW_TAG_class_type";
7037 case DW_TAG_entry_point
:
7038 return "DW_TAG_entry_point";
7039 case DW_TAG_enumeration_type
:
7040 return "DW_TAG_enumeration_type";
7041 case DW_TAG_formal_parameter
:
7042 return "DW_TAG_formal_parameter";
7043 case DW_TAG_imported_declaration
:
7044 return "DW_TAG_imported_declaration";
7046 return "DW_TAG_label";
7047 case DW_TAG_lexical_block
:
7048 return "DW_TAG_lexical_block";
7050 return "DW_TAG_member";
7051 case DW_TAG_pointer_type
:
7052 return "DW_TAG_pointer_type";
7053 case DW_TAG_reference_type
:
7054 return "DW_TAG_reference_type";
7055 case DW_TAG_compile_unit
:
7056 return "DW_TAG_compile_unit";
7057 case DW_TAG_string_type
:
7058 return "DW_TAG_string_type";
7059 case DW_TAG_structure_type
:
7060 return "DW_TAG_structure_type";
7061 case DW_TAG_subroutine_type
:
7062 return "DW_TAG_subroutine_type";
7063 case DW_TAG_typedef
:
7064 return "DW_TAG_typedef";
7065 case DW_TAG_union_type
:
7066 return "DW_TAG_union_type";
7067 case DW_TAG_unspecified_parameters
:
7068 return "DW_TAG_unspecified_parameters";
7069 case DW_TAG_variant
:
7070 return "DW_TAG_variant";
7071 case DW_TAG_common_block
:
7072 return "DW_TAG_common_block";
7073 case DW_TAG_common_inclusion
:
7074 return "DW_TAG_common_inclusion";
7075 case DW_TAG_inheritance
:
7076 return "DW_TAG_inheritance";
7077 case DW_TAG_inlined_subroutine
:
7078 return "DW_TAG_inlined_subroutine";
7080 return "DW_TAG_module";
7081 case DW_TAG_ptr_to_member_type
:
7082 return "DW_TAG_ptr_to_member_type";
7083 case DW_TAG_set_type
:
7084 return "DW_TAG_set_type";
7085 case DW_TAG_subrange_type
:
7086 return "DW_TAG_subrange_type";
7087 case DW_TAG_with_stmt
:
7088 return "DW_TAG_with_stmt";
7089 case DW_TAG_access_declaration
:
7090 return "DW_TAG_access_declaration";
7091 case DW_TAG_base_type
:
7092 return "DW_TAG_base_type";
7093 case DW_TAG_catch_block
:
7094 return "DW_TAG_catch_block";
7095 case DW_TAG_const_type
:
7096 return "DW_TAG_const_type";
7097 case DW_TAG_constant
:
7098 return "DW_TAG_constant";
7099 case DW_TAG_enumerator
:
7100 return "DW_TAG_enumerator";
7101 case DW_TAG_file_type
:
7102 return "DW_TAG_file_type";
7104 return "DW_TAG_friend";
7105 case DW_TAG_namelist
:
7106 return "DW_TAG_namelist";
7107 case DW_TAG_namelist_item
:
7108 return "DW_TAG_namelist_item";
7109 case DW_TAG_packed_type
:
7110 return "DW_TAG_packed_type";
7111 case DW_TAG_subprogram
:
7112 return "DW_TAG_subprogram";
7113 case DW_TAG_template_type_param
:
7114 return "DW_TAG_template_type_param";
7115 case DW_TAG_template_value_param
:
7116 return "DW_TAG_template_value_param";
7117 case DW_TAG_thrown_type
:
7118 return "DW_TAG_thrown_type";
7119 case DW_TAG_try_block
:
7120 return "DW_TAG_try_block";
7121 case DW_TAG_variant_part
:
7122 return "DW_TAG_variant_part";
7123 case DW_TAG_variable
:
7124 return "DW_TAG_variable";
7125 case DW_TAG_volatile_type
:
7126 return "DW_TAG_volatile_type";
7127 case DW_TAG_dwarf_procedure
:
7128 return "DW_TAG_dwarf_procedure";
7129 case DW_TAG_restrict_type
:
7130 return "DW_TAG_restrict_type";
7131 case DW_TAG_interface_type
:
7132 return "DW_TAG_interface_type";
7133 case DW_TAG_namespace
:
7134 return "DW_TAG_namespace";
7135 case DW_TAG_imported_module
:
7136 return "DW_TAG_imported_module";
7137 case DW_TAG_unspecified_type
:
7138 return "DW_TAG_unspecified_type";
7139 case DW_TAG_partial_unit
:
7140 return "DW_TAG_partial_unit";
7141 case DW_TAG_imported_unit
:
7142 return "DW_TAG_imported_unit";
7143 case DW_TAG_MIPS_loop
:
7144 return "DW_TAG_MIPS_loop";
7145 case DW_TAG_format_label
:
7146 return "DW_TAG_format_label";
7147 case DW_TAG_function_template
:
7148 return "DW_TAG_function_template";
7149 case DW_TAG_class_template
:
7150 return "DW_TAG_class_template";
7152 return "DW_TAG_<unknown>";
7156 /* Convert a DWARF attribute code into its string name. */
7159 dwarf_attr_name (unsigned attr
)
7164 return "DW_AT_sibling";
7165 case DW_AT_location
:
7166 return "DW_AT_location";
7168 return "DW_AT_name";
7169 case DW_AT_ordering
:
7170 return "DW_AT_ordering";
7171 case DW_AT_subscr_data
:
7172 return "DW_AT_subscr_data";
7173 case DW_AT_byte_size
:
7174 return "DW_AT_byte_size";
7175 case DW_AT_bit_offset
:
7176 return "DW_AT_bit_offset";
7177 case DW_AT_bit_size
:
7178 return "DW_AT_bit_size";
7179 case DW_AT_element_list
:
7180 return "DW_AT_element_list";
7181 case DW_AT_stmt_list
:
7182 return "DW_AT_stmt_list";
7184 return "DW_AT_low_pc";
7186 return "DW_AT_high_pc";
7187 case DW_AT_language
:
7188 return "DW_AT_language";
7190 return "DW_AT_member";
7192 return "DW_AT_discr";
7193 case DW_AT_discr_value
:
7194 return "DW_AT_discr_value";
7195 case DW_AT_visibility
:
7196 return "DW_AT_visibility";
7198 return "DW_AT_import";
7199 case DW_AT_string_length
:
7200 return "DW_AT_string_length";
7201 case DW_AT_common_reference
:
7202 return "DW_AT_common_reference";
7203 case DW_AT_comp_dir
:
7204 return "DW_AT_comp_dir";
7205 case DW_AT_const_value
:
7206 return "DW_AT_const_value";
7207 case DW_AT_containing_type
:
7208 return "DW_AT_containing_type";
7209 case DW_AT_default_value
:
7210 return "DW_AT_default_value";
7212 return "DW_AT_inline";
7213 case DW_AT_is_optional
:
7214 return "DW_AT_is_optional";
7215 case DW_AT_lower_bound
:
7216 return "DW_AT_lower_bound";
7217 case DW_AT_producer
:
7218 return "DW_AT_producer";
7219 case DW_AT_prototyped
:
7220 return "DW_AT_prototyped";
7221 case DW_AT_return_addr
:
7222 return "DW_AT_return_addr";
7223 case DW_AT_start_scope
:
7224 return "DW_AT_start_scope";
7225 case DW_AT_stride_size
:
7226 return "DW_AT_stride_size";
7227 case DW_AT_upper_bound
:
7228 return "DW_AT_upper_bound";
7229 case DW_AT_abstract_origin
:
7230 return "DW_AT_abstract_origin";
7231 case DW_AT_accessibility
:
7232 return "DW_AT_accessibility";
7233 case DW_AT_address_class
:
7234 return "DW_AT_address_class";
7235 case DW_AT_artificial
:
7236 return "DW_AT_artificial";
7237 case DW_AT_base_types
:
7238 return "DW_AT_base_types";
7239 case DW_AT_calling_convention
:
7240 return "DW_AT_calling_convention";
7242 return "DW_AT_count";
7243 case DW_AT_data_member_location
:
7244 return "DW_AT_data_member_location";
7245 case DW_AT_decl_column
:
7246 return "DW_AT_decl_column";
7247 case DW_AT_decl_file
:
7248 return "DW_AT_decl_file";
7249 case DW_AT_decl_line
:
7250 return "DW_AT_decl_line";
7251 case DW_AT_declaration
:
7252 return "DW_AT_declaration";
7253 case DW_AT_discr_list
:
7254 return "DW_AT_discr_list";
7255 case DW_AT_encoding
:
7256 return "DW_AT_encoding";
7257 case DW_AT_external
:
7258 return "DW_AT_external";
7259 case DW_AT_frame_base
:
7260 return "DW_AT_frame_base";
7262 return "DW_AT_friend";
7263 case DW_AT_identifier_case
:
7264 return "DW_AT_identifier_case";
7265 case DW_AT_macro_info
:
7266 return "DW_AT_macro_info";
7267 case DW_AT_namelist_items
:
7268 return "DW_AT_namelist_items";
7269 case DW_AT_priority
:
7270 return "DW_AT_priority";
7272 return "DW_AT_segment";
7273 case DW_AT_specification
:
7274 return "DW_AT_specification";
7275 case DW_AT_static_link
:
7276 return "DW_AT_static_link";
7278 return "DW_AT_type";
7279 case DW_AT_use_location
:
7280 return "DW_AT_use_location";
7281 case DW_AT_variable_parameter
:
7282 return "DW_AT_variable_parameter";
7283 case DW_AT_virtuality
:
7284 return "DW_AT_virtuality";
7285 case DW_AT_vtable_elem_location
:
7286 return "DW_AT_vtable_elem_location";
7287 case DW_AT_allocated
:
7288 return "DW_AT_allocated";
7289 case DW_AT_associated
:
7290 return "DW_AT_associated";
7291 case DW_AT_data_location
:
7292 return "DW_AT_data_location";
7294 return "DW_AT_stride";
7295 case DW_AT_entry_pc
:
7296 return "DW_AT_entry_pc";
7297 case DW_AT_use_UTF8
:
7298 return "DW_AT_use_UTF8";
7299 case DW_AT_extension
:
7300 return "DW_AT_extension";
7302 return "DW_AT_ranges";
7303 case DW_AT_trampoline
:
7304 return "DW_AT_trampoline";
7305 case DW_AT_call_column
:
7306 return "DW_AT_call_column";
7307 case DW_AT_call_file
:
7308 return "DW_AT_call_file";
7309 case DW_AT_call_line
:
7310 return "DW_AT_call_line";
7312 case DW_AT_MIPS_fde
:
7313 return "DW_AT_MIPS_fde";
7314 case DW_AT_MIPS_loop_begin
:
7315 return "DW_AT_MIPS_loop_begin";
7316 case DW_AT_MIPS_tail_loop_begin
:
7317 return "DW_AT_MIPS_tail_loop_begin";
7318 case DW_AT_MIPS_epilog_begin
:
7319 return "DW_AT_MIPS_epilog_begin";
7320 case DW_AT_MIPS_loop_unroll_factor
:
7321 return "DW_AT_MIPS_loop_unroll_factor";
7322 case DW_AT_MIPS_software_pipeline_depth
:
7323 return "DW_AT_MIPS_software_pipeline_depth";
7325 case DW_AT_MIPS_linkage_name
:
7326 return "DW_AT_MIPS_linkage_name";
7328 case DW_AT_sf_names
:
7329 return "DW_AT_sf_names";
7330 case DW_AT_src_info
:
7331 return "DW_AT_src_info";
7332 case DW_AT_mac_info
:
7333 return "DW_AT_mac_info";
7334 case DW_AT_src_coords
:
7335 return "DW_AT_src_coords";
7336 case DW_AT_body_begin
:
7337 return "DW_AT_body_begin";
7338 case DW_AT_body_end
:
7339 return "DW_AT_body_end";
7340 case DW_AT_GNU_vector
:
7341 return "DW_AT_GNU_vector";
7343 return "DW_AT_<unknown>";
7347 /* Convert a DWARF value form code into its string name. */
7350 dwarf_form_name (unsigned form
)
7355 return "DW_FORM_addr";
7356 case DW_FORM_block2
:
7357 return "DW_FORM_block2";
7358 case DW_FORM_block4
:
7359 return "DW_FORM_block4";
7361 return "DW_FORM_data2";
7363 return "DW_FORM_data4";
7365 return "DW_FORM_data8";
7366 case DW_FORM_string
:
7367 return "DW_FORM_string";
7369 return "DW_FORM_block";
7370 case DW_FORM_block1
:
7371 return "DW_FORM_block1";
7373 return "DW_FORM_data1";
7375 return "DW_FORM_flag";
7377 return "DW_FORM_sdata";
7379 return "DW_FORM_strp";
7381 return "DW_FORM_udata";
7382 case DW_FORM_ref_addr
:
7383 return "DW_FORM_ref_addr";
7385 return "DW_FORM_ref1";
7387 return "DW_FORM_ref2";
7389 return "DW_FORM_ref4";
7391 return "DW_FORM_ref8";
7392 case DW_FORM_ref_udata
:
7393 return "DW_FORM_ref_udata";
7394 case DW_FORM_indirect
:
7395 return "DW_FORM_indirect";
7397 return "DW_FORM_<unknown>";
7401 /* Convert a DWARF stack opcode into its string name. */
7404 dwarf_stack_op_name (unsigned op
)
7409 return "DW_OP_addr";
7411 return "DW_OP_deref";
7413 return "DW_OP_const1u";
7415 return "DW_OP_const1s";
7417 return "DW_OP_const2u";
7419 return "DW_OP_const2s";
7421 return "DW_OP_const4u";
7423 return "DW_OP_const4s";
7425 return "DW_OP_const8u";
7427 return "DW_OP_const8s";
7429 return "DW_OP_constu";
7431 return "DW_OP_consts";
7435 return "DW_OP_drop";
7437 return "DW_OP_over";
7439 return "DW_OP_pick";
7441 return "DW_OP_swap";
7445 return "DW_OP_xderef";
7453 return "DW_OP_minus";
7465 return "DW_OP_plus";
7466 case DW_OP_plus_uconst
:
7467 return "DW_OP_plus_uconst";
7473 return "DW_OP_shra";
7491 return "DW_OP_skip";
7493 return "DW_OP_lit0";
7495 return "DW_OP_lit1";
7497 return "DW_OP_lit2";
7499 return "DW_OP_lit3";
7501 return "DW_OP_lit4";
7503 return "DW_OP_lit5";
7505 return "DW_OP_lit6";
7507 return "DW_OP_lit7";
7509 return "DW_OP_lit8";
7511 return "DW_OP_lit9";
7513 return "DW_OP_lit10";
7515 return "DW_OP_lit11";
7517 return "DW_OP_lit12";
7519 return "DW_OP_lit13";
7521 return "DW_OP_lit14";
7523 return "DW_OP_lit15";
7525 return "DW_OP_lit16";
7527 return "DW_OP_lit17";
7529 return "DW_OP_lit18";
7531 return "DW_OP_lit19";
7533 return "DW_OP_lit20";
7535 return "DW_OP_lit21";
7537 return "DW_OP_lit22";
7539 return "DW_OP_lit23";
7541 return "DW_OP_lit24";
7543 return "DW_OP_lit25";
7545 return "DW_OP_lit26";
7547 return "DW_OP_lit27";
7549 return "DW_OP_lit28";
7551 return "DW_OP_lit29";
7553 return "DW_OP_lit30";
7555 return "DW_OP_lit31";
7557 return "DW_OP_reg0";
7559 return "DW_OP_reg1";
7561 return "DW_OP_reg2";
7563 return "DW_OP_reg3";
7565 return "DW_OP_reg4";
7567 return "DW_OP_reg5";
7569 return "DW_OP_reg6";
7571 return "DW_OP_reg7";
7573 return "DW_OP_reg8";
7575 return "DW_OP_reg9";
7577 return "DW_OP_reg10";
7579 return "DW_OP_reg11";
7581 return "DW_OP_reg12";
7583 return "DW_OP_reg13";
7585 return "DW_OP_reg14";
7587 return "DW_OP_reg15";
7589 return "DW_OP_reg16";
7591 return "DW_OP_reg17";
7593 return "DW_OP_reg18";
7595 return "DW_OP_reg19";
7597 return "DW_OP_reg20";
7599 return "DW_OP_reg21";
7601 return "DW_OP_reg22";
7603 return "DW_OP_reg23";
7605 return "DW_OP_reg24";
7607 return "DW_OP_reg25";
7609 return "DW_OP_reg26";
7611 return "DW_OP_reg27";
7613 return "DW_OP_reg28";
7615 return "DW_OP_reg29";
7617 return "DW_OP_reg30";
7619 return "DW_OP_reg31";
7621 return "DW_OP_breg0";
7623 return "DW_OP_breg1";
7625 return "DW_OP_breg2";
7627 return "DW_OP_breg3";
7629 return "DW_OP_breg4";
7631 return "DW_OP_breg5";
7633 return "DW_OP_breg6";
7635 return "DW_OP_breg7";
7637 return "DW_OP_breg8";
7639 return "DW_OP_breg9";
7641 return "DW_OP_breg10";
7643 return "DW_OP_breg11";
7645 return "DW_OP_breg12";
7647 return "DW_OP_breg13";
7649 return "DW_OP_breg14";
7651 return "DW_OP_breg15";
7653 return "DW_OP_breg16";
7655 return "DW_OP_breg17";
7657 return "DW_OP_breg18";
7659 return "DW_OP_breg19";
7661 return "DW_OP_breg20";
7663 return "DW_OP_breg21";
7665 return "DW_OP_breg22";
7667 return "DW_OP_breg23";
7669 return "DW_OP_breg24";
7671 return "DW_OP_breg25";
7673 return "DW_OP_breg26";
7675 return "DW_OP_breg27";
7677 return "DW_OP_breg28";
7679 return "DW_OP_breg29";
7681 return "DW_OP_breg30";
7683 return "DW_OP_breg31";
7685 return "DW_OP_regx";
7687 return "DW_OP_fbreg";
7689 return "DW_OP_bregx";
7691 return "DW_OP_piece";
7692 case DW_OP_deref_size
:
7693 return "DW_OP_deref_size";
7694 case DW_OP_xderef_size
:
7695 return "DW_OP_xderef_size";
7698 /* DWARF 3 extensions. */
7699 case DW_OP_push_object_address
:
7700 return "DW_OP_push_object_address";
7702 return "DW_OP_call2";
7704 return "DW_OP_call4";
7705 case DW_OP_call_ref
:
7706 return "DW_OP_call_ref";
7707 /* GNU extensions. */
7708 case DW_OP_GNU_push_tls_address
:
7709 return "DW_OP_GNU_push_tls_address";
7711 return "OP_<unknown>";
7716 dwarf_bool_name (unsigned mybool
)
7724 /* Convert a DWARF type code into its string name. */
7727 dwarf_type_encoding_name (unsigned enc
)
7731 case DW_ATE_address
:
7732 return "DW_ATE_address";
7733 case DW_ATE_boolean
:
7734 return "DW_ATE_boolean";
7735 case DW_ATE_complex_float
:
7736 return "DW_ATE_complex_float";
7738 return "DW_ATE_float";
7740 return "DW_ATE_signed";
7741 case DW_ATE_signed_char
:
7742 return "DW_ATE_signed_char";
7743 case DW_ATE_unsigned
:
7744 return "DW_ATE_unsigned";
7745 case DW_ATE_unsigned_char
:
7746 return "DW_ATE_unsigned_char";
7747 case DW_ATE_imaginary_float
:
7748 return "DW_ATE_imaginary_float";
7750 return "DW_ATE_<unknown>";
7754 /* Convert a DWARF call frame info operation to its string name. */
7758 dwarf_cfi_name (unsigned cfi_opc
)
7762 case DW_CFA_advance_loc
:
7763 return "DW_CFA_advance_loc";
7765 return "DW_CFA_offset";
7766 case DW_CFA_restore
:
7767 return "DW_CFA_restore";
7769 return "DW_CFA_nop";
7770 case DW_CFA_set_loc
:
7771 return "DW_CFA_set_loc";
7772 case DW_CFA_advance_loc1
:
7773 return "DW_CFA_advance_loc1";
7774 case DW_CFA_advance_loc2
:
7775 return "DW_CFA_advance_loc2";
7776 case DW_CFA_advance_loc4
:
7777 return "DW_CFA_advance_loc4";
7778 case DW_CFA_offset_extended
:
7779 return "DW_CFA_offset_extended";
7780 case DW_CFA_restore_extended
:
7781 return "DW_CFA_restore_extended";
7782 case DW_CFA_undefined
:
7783 return "DW_CFA_undefined";
7784 case DW_CFA_same_value
:
7785 return "DW_CFA_same_value";
7786 case DW_CFA_register
:
7787 return "DW_CFA_register";
7788 case DW_CFA_remember_state
:
7789 return "DW_CFA_remember_state";
7790 case DW_CFA_restore_state
:
7791 return "DW_CFA_restore_state";
7792 case DW_CFA_def_cfa
:
7793 return "DW_CFA_def_cfa";
7794 case DW_CFA_def_cfa_register
:
7795 return "DW_CFA_def_cfa_register";
7796 case DW_CFA_def_cfa_offset
:
7797 return "DW_CFA_def_cfa_offset";
7800 case DW_CFA_def_cfa_expression
:
7801 return "DW_CFA_def_cfa_expression";
7802 case DW_CFA_expression
:
7803 return "DW_CFA_expression";
7804 case DW_CFA_offset_extended_sf
:
7805 return "DW_CFA_offset_extended_sf";
7806 case DW_CFA_def_cfa_sf
:
7807 return "DW_CFA_def_cfa_sf";
7808 case DW_CFA_def_cfa_offset_sf
:
7809 return "DW_CFA_def_cfa_offset_sf";
7811 /* SGI/MIPS specific */
7812 case DW_CFA_MIPS_advance_loc8
:
7813 return "DW_CFA_MIPS_advance_loc8";
7815 /* GNU extensions */
7816 case DW_CFA_GNU_window_save
:
7817 return "DW_CFA_GNU_window_save";
7818 case DW_CFA_GNU_args_size
:
7819 return "DW_CFA_GNU_args_size";
7820 case DW_CFA_GNU_negative_offset_extended
:
7821 return "DW_CFA_GNU_negative_offset_extended";
7824 return "DW_CFA_<unknown>";
7830 dump_die (struct die_info
*die
)
7834 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
7835 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
7836 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
7837 dwarf_bool_name (die
->child
!= NULL
));
7839 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
7840 for (i
= 0; i
< die
->num_attrs
; ++i
)
7842 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
7843 dwarf_attr_name (die
->attrs
[i
].name
),
7844 dwarf_form_name (die
->attrs
[i
].form
));
7845 switch (die
->attrs
[i
].form
)
7847 case DW_FORM_ref_addr
:
7849 fprintf_unfiltered (gdb_stderr
, "address: ");
7850 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
7852 case DW_FORM_block2
:
7853 case DW_FORM_block4
:
7855 case DW_FORM_block1
:
7856 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
7867 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
7869 case DW_FORM_string
:
7871 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
7872 DW_STRING (&die
->attrs
[i
])
7873 ? DW_STRING (&die
->attrs
[i
]) : "");
7876 if (DW_UNSND (&die
->attrs
[i
]))
7877 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
7879 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
7881 case DW_FORM_indirect
:
7882 /* the reader will have reduced the indirect form to
7883 the "base form" so this form should not occur */
7884 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
7887 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
7888 die
->attrs
[i
].form
);
7890 fprintf_unfiltered (gdb_stderr
, "\n");
7895 dump_die_list (struct die_info
*die
)
7900 if (die
->child
!= NULL
)
7901 dump_die_list (die
->child
);
7902 if (die
->sibling
!= NULL
)
7903 dump_die_list (die
->sibling
);
7908 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
7911 struct die_info
*old
;
7913 h
= (offset
% REF_HASH_SIZE
);
7914 old
= die_ref_table
[h
];
7915 die
->next_ref
= old
;
7916 die_ref_table
[h
] = die
;
7921 dwarf2_empty_hash_tables (void)
7923 memset (die_ref_table
, 0, sizeof (die_ref_table
));
7927 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
7929 unsigned int result
= 0;
7933 case DW_FORM_ref_addr
:
7934 result
= DW_ADDR (attr
);
7940 case DW_FORM_ref_udata
:
7941 result
= cu
->header
.offset
+ DW_UNSND (attr
);
7944 complaint (&symfile_complaints
,
7945 "unsupported die ref attribute form: '%s'",
7946 dwarf_form_name (attr
->form
));
7951 /* Return the constant value held by the given attribute. Return -1
7952 if the value held by the attribute is not constant. */
7955 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
7957 if (attr
->form
== DW_FORM_sdata
)
7958 return DW_SND (attr
);
7959 else if (attr
->form
== DW_FORM_udata
7960 || attr
->form
== DW_FORM_data1
7961 || attr
->form
== DW_FORM_data2
7962 || attr
->form
== DW_FORM_data4
7963 || attr
->form
== DW_FORM_data8
)
7964 return DW_UNSND (attr
);
7967 complaint (&symfile_complaints
, "Attribute value is not a constant (%s)",
7968 dwarf_form_name (attr
->form
));
7969 return default_value
;
7973 static struct die_info
*
7974 follow_die_ref (unsigned int offset
)
7976 struct die_info
*die
;
7979 h
= (offset
% REF_HASH_SIZE
);
7980 die
= die_ref_table
[h
];
7983 if (die
->offset
== offset
)
7987 die
= die
->next_ref
;
7992 static struct type
*
7993 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid,
7994 struct dwarf2_cu
*cu
)
7996 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
7998 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
7999 typeid, objfile
->name
);
8002 /* Look for this particular type in the fundamental type vector. If
8003 one is not found, create and install one appropriate for the
8004 current language and the current target machine. */
8006 if (cu
->ftypes
[typeid] == NULL
)
8008 cu
->ftypes
[typeid] = cu
->language_defn
->la_fund_type (objfile
, typeid);
8011 return (cu
->ftypes
[typeid]);
8014 /* Decode simple location descriptions.
8015 Given a pointer to a dwarf block that defines a location, compute
8016 the location and return the value.
8018 NOTE drow/2003-11-18: This function is called in two situations
8019 now: for the address of static or global variables (partial symbols
8020 only) and for offsets into structures which are expected to be
8021 (more or less) constant. The partial symbol case should go away,
8022 and only the constant case should remain. That will let this
8023 function complain more accurately. A few special modes are allowed
8024 without complaint for global variables (for instance, global
8025 register values and thread-local values).
8027 A location description containing no operations indicates that the
8028 object is optimized out. The return value is 0 for that case.
8029 FIXME drow/2003-11-16: No callers check for this case any more; soon all
8030 callers will only want a very basic result and this can become a
8033 When the result is a register number, the global isreg flag is set,
8034 otherwise it is cleared.
8036 Note that stack[0] is unused except as a default error return.
8037 Note that stack overflow is not yet handled. */
8040 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
8042 struct objfile
*objfile
= cu
->objfile
;
8043 struct comp_unit_head
*cu_header
= &cu
->header
;
8045 int size
= blk
->size
;
8046 char *data
= blk
->data
;
8047 CORE_ADDR stack
[64];
8049 unsigned int bytes_read
, unsnd
;
8094 stack
[++stacki
] = op
- DW_OP_lit0
;
8130 stack
[++stacki
] = op
- DW_OP_reg0
;
8132 dwarf2_complex_location_expr_complaint ();
8137 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
8139 stack
[++stacki
] = unsnd
;
8141 dwarf2_complex_location_expr_complaint ();
8145 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
8151 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
8156 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
8161 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
8166 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
8171 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
8176 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
8181 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
8187 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
8192 stack
[stacki
+ 1] = stack
[stacki
];
8197 stack
[stacki
- 1] += stack
[stacki
];
8201 case DW_OP_plus_uconst
:
8202 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
8207 stack
[stacki
- 1] -= stack
[stacki
];
8212 /* If we're not the last op, then we definitely can't encode
8213 this using GDB's address_class enum. This is valid for partial
8214 global symbols, although the variable's address will be bogus
8217 dwarf2_complex_location_expr_complaint ();
8220 case DW_OP_GNU_push_tls_address
:
8221 /* The top of the stack has the offset from the beginning
8222 of the thread control block at which the variable is located. */
8223 /* Nothing should follow this operator, so the top of stack would
8225 /* This is valid for partial global symbols, but the variable's
8226 address will be bogus in the psymtab. */
8228 dwarf2_complex_location_expr_complaint ();
8232 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
8233 dwarf_stack_op_name (op
));
8234 return (stack
[stacki
]);
8237 return (stack
[stacki
]);
8240 /* memory allocation interface */
8242 static struct dwarf_block
*
8243 dwarf_alloc_block (struct dwarf2_cu
*cu
)
8245 struct dwarf_block
*blk
;
8247 blk
= (struct dwarf_block
*)
8248 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
8252 static struct abbrev_info
*
8253 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
8255 struct abbrev_info
*abbrev
;
8257 abbrev
= (struct abbrev_info
*)
8258 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
8259 memset (abbrev
, 0, sizeof (struct abbrev_info
));
8263 static struct die_info
*
8264 dwarf_alloc_die (void)
8266 struct die_info
*die
;
8268 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
8269 memset (die
, 0, sizeof (struct die_info
));
8274 /* Macro support. */
8277 /* Return the full name of file number I in *LH's file name table.
8278 Use COMP_DIR as the name of the current directory of the
8279 compilation. The result is allocated using xmalloc; the caller is
8280 responsible for freeing it. */
8282 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
8284 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
8286 if (IS_ABSOLUTE_PATH (fe
->name
))
8287 return xstrdup (fe
->name
);
8295 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8301 dir_len
= strlen (dir
);
8302 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
8303 strcpy (full_name
, dir
);
8304 full_name
[dir_len
] = '/';
8305 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
8309 return xstrdup (fe
->name
);
8314 static struct macro_source_file
*
8315 macro_start_file (int file
, int line
,
8316 struct macro_source_file
*current_file
,
8317 const char *comp_dir
,
8318 struct line_header
*lh
, struct objfile
*objfile
)
8320 /* The full name of this source file. */
8321 char *full_name
= file_full_name (file
, lh
, comp_dir
);
8323 /* We don't create a macro table for this compilation unit
8324 at all until we actually get a filename. */
8325 if (! pending_macros
)
8326 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
8327 objfile
->macro_cache
);
8330 /* If we have no current file, then this must be the start_file
8331 directive for the compilation unit's main source file. */
8332 current_file
= macro_set_main (pending_macros
, full_name
);
8334 current_file
= macro_include (current_file
, line
, full_name
);
8338 return current_file
;
8342 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
8343 followed by a null byte. */
8345 copy_string (const char *buf
, int len
)
8347 char *s
= xmalloc (len
+ 1);
8348 memcpy (s
, buf
, len
);
8356 consume_improper_spaces (const char *p
, const char *body
)
8360 complaint (&symfile_complaints
,
8361 "macro definition contains spaces in formal argument list:\n`%s'",
8373 parse_macro_definition (struct macro_source_file
*file
, int line
,
8378 /* The body string takes one of two forms. For object-like macro
8379 definitions, it should be:
8381 <macro name> " " <definition>
8383 For function-like macro definitions, it should be:
8385 <macro name> "() " <definition>
8387 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
8389 Spaces may appear only where explicitly indicated, and in the
8392 The Dwarf 2 spec says that an object-like macro's name is always
8393 followed by a space, but versions of GCC around March 2002 omit
8394 the space when the macro's definition is the empty string.
8396 The Dwarf 2 spec says that there should be no spaces between the
8397 formal arguments in a function-like macro's formal argument list,
8398 but versions of GCC around March 2002 include spaces after the
8402 /* Find the extent of the macro name. The macro name is terminated
8403 by either a space or null character (for an object-like macro) or
8404 an opening paren (for a function-like macro). */
8405 for (p
= body
; *p
; p
++)
8406 if (*p
== ' ' || *p
== '(')
8409 if (*p
== ' ' || *p
== '\0')
8411 /* It's an object-like macro. */
8412 int name_len
= p
- body
;
8413 char *name
= copy_string (body
, name_len
);
8414 const char *replacement
;
8417 replacement
= body
+ name_len
+ 1;
8420 dwarf2_macro_malformed_definition_complaint (body
);
8421 replacement
= body
+ name_len
;
8424 macro_define_object (file
, line
, name
, replacement
);
8430 /* It's a function-like macro. */
8431 char *name
= copy_string (body
, p
- body
);
8434 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
8438 p
= consume_improper_spaces (p
, body
);
8440 /* Parse the formal argument list. */
8441 while (*p
&& *p
!= ')')
8443 /* Find the extent of the current argument name. */
8444 const char *arg_start
= p
;
8446 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
8449 if (! *p
|| p
== arg_start
)
8450 dwarf2_macro_malformed_definition_complaint (body
);
8453 /* Make sure argv has room for the new argument. */
8454 if (argc
>= argv_size
)
8457 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
8460 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
8463 p
= consume_improper_spaces (p
, body
);
8465 /* Consume the comma, if present. */
8470 p
= consume_improper_spaces (p
, body
);
8479 /* Perfectly formed definition, no complaints. */
8480 macro_define_function (file
, line
, name
,
8481 argc
, (const char **) argv
,
8483 else if (*p
== '\0')
8485 /* Complain, but do define it. */
8486 dwarf2_macro_malformed_definition_complaint (body
);
8487 macro_define_function (file
, line
, name
,
8488 argc
, (const char **) argv
,
8492 /* Just complain. */
8493 dwarf2_macro_malformed_definition_complaint (body
);
8496 /* Just complain. */
8497 dwarf2_macro_malformed_definition_complaint (body
);
8503 for (i
= 0; i
< argc
; i
++)
8509 dwarf2_macro_malformed_definition_complaint (body
);
8514 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
8515 char *comp_dir
, bfd
*abfd
,
8516 struct dwarf2_cu
*cu
)
8518 char *mac_ptr
, *mac_end
;
8519 struct macro_source_file
*current_file
= 0;
8521 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
8523 complaint (&symfile_complaints
, "missing .debug_macinfo section");
8527 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
8528 mac_end
= dwarf2_per_objfile
->macinfo_buffer
8529 + dwarf2_per_objfile
->macinfo_size
;
8533 enum dwarf_macinfo_record_type macinfo_type
;
8535 /* Do we at least have room for a macinfo type byte? */
8536 if (mac_ptr
>= mac_end
)
8538 dwarf2_macros_too_long_complaint ();
8542 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
8545 switch (macinfo_type
)
8547 /* A zero macinfo type indicates the end of the macro
8552 case DW_MACINFO_define
:
8553 case DW_MACINFO_undef
:
8559 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8560 mac_ptr
+= bytes_read
;
8561 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
8562 mac_ptr
+= bytes_read
;
8565 complaint (&symfile_complaints
,
8566 "debug info gives macro %s outside of any file: %s",
8568 DW_MACINFO_define
? "definition" : macinfo_type
==
8569 DW_MACINFO_undef
? "undefinition" :
8570 "something-or-other", body
);
8573 if (macinfo_type
== DW_MACINFO_define
)
8574 parse_macro_definition (current_file
, line
, body
);
8575 else if (macinfo_type
== DW_MACINFO_undef
)
8576 macro_undef (current_file
, line
, body
);
8581 case DW_MACINFO_start_file
:
8586 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8587 mac_ptr
+= bytes_read
;
8588 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8589 mac_ptr
+= bytes_read
;
8591 current_file
= macro_start_file (file
, line
,
8592 current_file
, comp_dir
,
8597 case DW_MACINFO_end_file
:
8599 complaint (&symfile_complaints
,
8600 "macro debug info has an unmatched `close_file' directive");
8603 current_file
= current_file
->included_by
;
8606 enum dwarf_macinfo_record_type next_type
;
8608 /* GCC circa March 2002 doesn't produce the zero
8609 type byte marking the end of the compilation
8610 unit. Complain if it's not there, but exit no
8613 /* Do we at least have room for a macinfo type byte? */
8614 if (mac_ptr
>= mac_end
)
8616 dwarf2_macros_too_long_complaint ();
8620 /* We don't increment mac_ptr here, so this is just
8622 next_type
= read_1_byte (abfd
, mac_ptr
);
8624 complaint (&symfile_complaints
,
8625 "no terminating 0-type entry for macros in `.debug_macinfo' section");
8632 case DW_MACINFO_vendor_ext
:
8638 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8639 mac_ptr
+= bytes_read
;
8640 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
8641 mac_ptr
+= bytes_read
;
8643 /* We don't recognize any vendor extensions. */
8650 /* Check if the attribute's form is a DW_FORM_block*
8651 if so return true else false. */
8653 attr_form_is_block (struct attribute
*attr
)
8655 return (attr
== NULL
? 0 :
8656 attr
->form
== DW_FORM_block1
8657 || attr
->form
== DW_FORM_block2
8658 || attr
->form
== DW_FORM_block4
8659 || attr
->form
== DW_FORM_block
);
8663 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
8664 struct dwarf2_cu
*cu
)
8666 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
8668 struct dwarf2_loclist_baton
*baton
;
8670 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
8671 sizeof (struct dwarf2_loclist_baton
));
8672 baton
->objfile
= cu
->objfile
;
8674 /* We don't know how long the location list is, but make sure we
8675 don't run off the edge of the section. */
8676 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
8677 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
8678 baton
->base_address
= cu
->header
.base_address
;
8679 if (cu
->header
.base_known
== 0)
8680 complaint (&symfile_complaints
,
8681 "Location list used without specifying the CU base address.");
8683 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
8684 SYMBOL_LOCATION_BATON (sym
) = baton
;
8688 struct dwarf2_locexpr_baton
*baton
;
8690 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
8691 sizeof (struct dwarf2_locexpr_baton
));
8692 baton
->objfile
= cu
->objfile
;
8694 if (attr_form_is_block (attr
))
8696 /* Note that we're just copying the block's data pointer
8697 here, not the actual data. We're still pointing into the
8698 info_buffer for SYM's objfile; right now we never release
8699 that buffer, but when we do clean up properly this may
8701 baton
->size
= DW_BLOCK (attr
)->size
;
8702 baton
->data
= DW_BLOCK (attr
)->data
;
8706 dwarf2_invalid_attrib_class_complaint ("location description",
8707 SYMBOL_NATURAL_NAME (sym
));
8712 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
8713 SYMBOL_LOCATION_BATON (sym
) = baton
;
8717 /* This cleanup function is passed the address of a dwarf2_cu on the stack
8718 when we're finished with it. We can't free the pointer itself, but
8719 release any associated storage.
8721 Only used during partial symbol parsing. */
8724 free_stack_comp_unit (void *data
)
8726 struct dwarf2_cu
*cu
= data
;
8728 obstack_free (&cu
->comp_unit_obstack
, NULL
);
8729 cu
->partial_dies
= NULL
;
8732 /* Allocation function for the libiberty hash table which uses an
8736 hashtab_obstack_allocate (void *data
, size_t size
, size_t count
)
8738 unsigned int total
= size
* count
;
8739 void *ptr
= obstack_alloc ((struct obstack
*) data
, total
);
8740 memset (ptr
, 0, total
);
8744 /* Trivial deallocation function for the libiberty splay tree and hash
8745 table - don't deallocate anything. Rely on later deletion of the
8749 dummy_obstack_deallocate (void *object
, void *data
)
8754 /* Trivial hash function for partial_die_info: the hash value of a DIE
8755 is its offset in .debug_info for this objfile. */
8758 partial_die_hash (const void *item
)
8760 const struct partial_die_info
*part_die
= item
;
8761 return part_die
->offset
;
8764 /* Trivial comparison function for partial_die_info structures: two DIEs
8765 are equal if they have the same offset. */
8768 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
8770 const struct partial_die_info
*part_die_lhs
= item_lhs
;
8771 const struct partial_die_info
*part_die_rhs
= item_rhs
;
8772 return part_die_lhs
->offset
== part_die_rhs
->offset
;
8775 void _initialize_dwarf2_read (void);
8778 _initialize_dwarf2_read (void)
8780 dwarf2_objfile_data_key
= register_objfile_data ();