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 lh
->file_names
[file
- 1].included_p
= 1;
5981 if (!decode_for_pst_p
)
5983 /* append row to matrix using current values */
5984 record_line (current_subfile
, line
,
5985 check_cu_functions (address
, cu
));
5989 else switch (op_code
)
5991 case DW_LNS_extended_op
:
5992 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5993 line_ptr
+= bytes_read
;
5994 extended_op
= read_1_byte (abfd
, line_ptr
);
5996 switch (extended_op
)
5998 case DW_LNE_end_sequence
:
6000 lh
->file_names
[file
- 1].included_p
= 1;
6001 if (!decode_for_pst_p
)
6002 record_line (current_subfile
, 0, address
);
6004 case DW_LNE_set_address
:
6005 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
6006 line_ptr
+= bytes_read
;
6007 address
+= baseaddr
;
6009 case DW_LNE_define_file
:
6012 unsigned int dir_index
, mod_time
, length
;
6014 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
6015 line_ptr
+= bytes_read
;
6017 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6018 line_ptr
+= bytes_read
;
6020 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6021 line_ptr
+= bytes_read
;
6023 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6024 line_ptr
+= bytes_read
;
6025 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6029 complaint (&symfile_complaints
,
6030 "mangled .debug_line section");
6035 lh
->file_names
[file
- 1].included_p
= 1;
6036 if (!decode_for_pst_p
)
6037 record_line (current_subfile
, line
,
6038 check_cu_functions (address
, cu
));
6041 case DW_LNS_advance_pc
:
6042 address
+= lh
->minimum_instruction_length
6043 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6044 line_ptr
+= bytes_read
;
6046 case DW_LNS_advance_line
:
6047 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
6048 line_ptr
+= bytes_read
;
6050 case DW_LNS_set_file
:
6052 /* lh->include_dirs and lh->file_names are 0-based,
6053 but the directory and file name numbers in the
6054 statement program are 1-based. */
6055 struct file_entry
*fe
;
6057 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6058 line_ptr
+= bytes_read
;
6059 fe
= &lh
->file_names
[file
- 1];
6061 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6064 if (!decode_for_pst_p
)
6065 dwarf2_start_subfile (fe
->name
, dir
);
6068 case DW_LNS_set_column
:
6069 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6070 line_ptr
+= bytes_read
;
6072 case DW_LNS_negate_stmt
:
6073 is_stmt
= (!is_stmt
);
6075 case DW_LNS_set_basic_block
:
6078 /* Add to the address register of the state machine the
6079 address increment value corresponding to special opcode
6080 255. Ie, this value is scaled by the minimum instruction
6081 length since special opcode 255 would have scaled the
6083 case DW_LNS_const_add_pc
:
6084 address
+= (lh
->minimum_instruction_length
6085 * ((255 - lh
->opcode_base
) / lh
->line_range
));
6087 case DW_LNS_fixed_advance_pc
:
6088 address
+= read_2_bytes (abfd
, line_ptr
);
6092 { /* Unknown standard opcode, ignore it. */
6094 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
6096 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6097 line_ptr
+= bytes_read
;
6104 if (decode_for_pst_p
)
6108 /* Now that we're done scanning the Line Header Program, we can
6109 create the psymtab of each included file. */
6110 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
6111 if (lh
->file_names
[file_index
].included_p
== 1)
6113 char *include_name
= lh
->file_names
[file_index
].name
;
6115 if (strcmp (include_name
, pst
->filename
) != 0)
6116 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
6121 /* Start a subfile for DWARF. FILENAME is the name of the file and
6122 DIRNAME the name of the source directory which contains FILENAME
6123 or NULL if not known.
6124 This routine tries to keep line numbers from identical absolute and
6125 relative file names in a common subfile.
6127 Using the `list' example from the GDB testsuite, which resides in
6128 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
6129 of /srcdir/list0.c yields the following debugging information for list0.c:
6131 DW_AT_name: /srcdir/list0.c
6132 DW_AT_comp_dir: /compdir
6133 files.files[0].name: list0.h
6134 files.files[0].dir: /srcdir
6135 files.files[1].name: list0.c
6136 files.files[1].dir: /srcdir
6138 The line number information for list0.c has to end up in a single
6139 subfile, so that `break /srcdir/list0.c:1' works as expected. */
6142 dwarf2_start_subfile (char *filename
, char *dirname
)
6144 /* If the filename isn't absolute, try to match an existing subfile
6145 with the full pathname. */
6147 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
6149 struct subfile
*subfile
;
6150 char *fullname
= concat (dirname
, "/", filename
, NULL
);
6152 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
6154 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
6156 current_subfile
= subfile
;
6163 start_subfile (filename
, dirname
);
6167 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
6168 struct dwarf2_cu
*cu
)
6170 struct objfile
*objfile
= cu
->objfile
;
6171 struct comp_unit_head
*cu_header
= &cu
->header
;
6173 /* NOTE drow/2003-01-30: There used to be a comment and some special
6174 code here to turn a symbol with DW_AT_external and a
6175 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
6176 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
6177 with some versions of binutils) where shared libraries could have
6178 relocations against symbols in their debug information - the
6179 minimal symbol would have the right address, but the debug info
6180 would not. It's no longer necessary, because we will explicitly
6181 apply relocations when we read in the debug information now. */
6183 /* A DW_AT_location attribute with no contents indicates that a
6184 variable has been optimized away. */
6185 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
6187 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
6191 /* Handle one degenerate form of location expression specially, to
6192 preserve GDB's previous behavior when section offsets are
6193 specified. If this is just a DW_OP_addr then mark this symbol
6196 if (attr_form_is_block (attr
)
6197 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
6198 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
6202 SYMBOL_VALUE_ADDRESS (sym
) =
6203 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
6204 fixup_symbol_section (sym
, objfile
);
6205 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
6206 SYMBOL_SECTION (sym
));
6207 SYMBOL_CLASS (sym
) = LOC_STATIC
;
6211 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
6212 expression evaluator, and use LOC_COMPUTED only when necessary
6213 (i.e. when the value of a register or memory location is
6214 referenced, or a thread-local block, etc.). Then again, it might
6215 not be worthwhile. I'm assuming that it isn't unless performance
6216 or memory numbers show me otherwise. */
6218 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
6219 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
6222 /* Given a pointer to a DWARF information entry, figure out if we need
6223 to make a symbol table entry for it, and if so, create a new entry
6224 and return a pointer to it.
6225 If TYPE is NULL, determine symbol type from the die, otherwise
6226 used the passed type. */
6228 static struct symbol
*
6229 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
6231 struct objfile
*objfile
= cu
->objfile
;
6232 struct symbol
*sym
= NULL
;
6234 struct attribute
*attr
= NULL
;
6235 struct attribute
*attr2
= NULL
;
6238 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6240 if (die
->tag
!= DW_TAG_namespace
)
6241 name
= dwarf2_linkage_name (die
, cu
);
6243 name
= TYPE_NAME (type
);
6247 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
6248 sizeof (struct symbol
));
6249 OBJSTAT (objfile
, n_syms
++);
6250 memset (sym
, 0, sizeof (struct symbol
));
6252 /* Cache this symbol's name and the name's demangled form (if any). */
6253 SYMBOL_LANGUAGE (sym
) = cu
->language
;
6254 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
6256 /* Default assumptions.
6257 Use the passed type or decode it from the die. */
6258 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6259 SYMBOL_CLASS (sym
) = LOC_STATIC
;
6261 SYMBOL_TYPE (sym
) = type
;
6263 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
6264 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
6267 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
6272 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6275 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
6277 SYMBOL_CLASS (sym
) = LOC_LABEL
;
6279 case DW_TAG_subprogram
:
6280 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
6282 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
6283 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6284 if (attr2
&& (DW_UNSND (attr2
) != 0))
6286 add_symbol_to_list (sym
, &global_symbols
);
6290 add_symbol_to_list (sym
, cu
->list_in_scope
);
6293 case DW_TAG_variable
:
6294 /* Compilation with minimal debug info may result in variables
6295 with missing type entries. Change the misleading `void' type
6296 to something sensible. */
6297 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
6298 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
6299 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
6300 "<variable, no debug info>",
6302 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6305 dwarf2_const_value (attr
, sym
, cu
);
6306 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6307 if (attr2
&& (DW_UNSND (attr2
) != 0))
6308 add_symbol_to_list (sym
, &global_symbols
);
6310 add_symbol_to_list (sym
, cu
->list_in_scope
);
6313 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6316 var_decode_location (attr
, sym
, cu
);
6317 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6318 if (attr2
&& (DW_UNSND (attr2
) != 0))
6319 add_symbol_to_list (sym
, &global_symbols
);
6321 add_symbol_to_list (sym
, cu
->list_in_scope
);
6325 /* We do not know the address of this symbol.
6326 If it is an external symbol and we have type information
6327 for it, enter the symbol as a LOC_UNRESOLVED symbol.
6328 The address of the variable will then be determined from
6329 the minimal symbol table whenever the variable is
6331 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6332 if (attr2
&& (DW_UNSND (attr2
) != 0)
6333 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
6335 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
6336 add_symbol_to_list (sym
, &global_symbols
);
6340 case DW_TAG_formal_parameter
:
6341 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6344 var_decode_location (attr
, sym
, cu
);
6345 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
6346 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
6347 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
6349 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6352 dwarf2_const_value (attr
, sym
, cu
);
6354 add_symbol_to_list (sym
, cu
->list_in_scope
);
6356 case DW_TAG_unspecified_parameters
:
6357 /* From varargs functions; gdb doesn't seem to have any
6358 interest in this information, so just ignore it for now.
6361 case DW_TAG_class_type
:
6362 case DW_TAG_structure_type
:
6363 case DW_TAG_union_type
:
6364 case DW_TAG_enumeration_type
:
6365 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6366 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6368 /* Make sure that the symbol includes appropriate enclosing
6369 classes/namespaces in its name. These are calculated in
6370 read_structure_type, and the correct name is saved in
6373 if (cu
->language
== language_cplus
)
6375 struct type
*type
= SYMBOL_TYPE (sym
);
6377 if (TYPE_TAG_NAME (type
) != NULL
)
6379 /* FIXME: carlton/2003-11-10: Should this use
6380 SYMBOL_SET_NAMES instead? (The same problem also
6381 arises further down in this function.) */
6382 /* The type's name is already allocated along with
6383 this objfile, so we don't need to duplicate it
6385 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
6390 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
6391 really ever be static objects: otherwise, if you try
6392 to, say, break of a class's method and you're in a file
6393 which doesn't mention that class, it won't work unless
6394 the check for all static symbols in lookup_symbol_aux
6395 saves you. See the OtherFileClass tests in
6396 gdb.c++/namespace.exp. */
6398 struct pending
**list_to_add
;
6400 list_to_add
= (cu
->list_in_scope
== &file_symbols
6401 && cu
->language
== language_cplus
6402 ? &global_symbols
: cu
->list_in_scope
);
6404 add_symbol_to_list (sym
, list_to_add
);
6406 /* The semantics of C++ state that "struct foo { ... }" also
6407 defines a typedef for "foo". Synthesize a typedef symbol so
6408 that "ptype foo" works as expected. */
6409 if (cu
->language
== language_cplus
)
6411 struct symbol
*typedef_sym
= (struct symbol
*)
6412 obstack_alloc (&objfile
->objfile_obstack
,
6413 sizeof (struct symbol
));
6414 *typedef_sym
= *sym
;
6415 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
6416 /* The symbol's name is already allocated along with
6417 this objfile, so we don't need to duplicate it for
6419 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
6420 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NATURAL_NAME (sym
);
6421 add_symbol_to_list (typedef_sym
, list_to_add
);
6425 case DW_TAG_typedef
:
6426 if (processing_has_namespace_info
6427 && processing_current_prefix
[0] != '\0')
6429 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->objfile_obstack
,
6430 processing_current_prefix
,
6434 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6435 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6436 add_symbol_to_list (sym
, cu
->list_in_scope
);
6438 case DW_TAG_base_type
:
6439 case DW_TAG_subrange_type
:
6440 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6441 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6442 add_symbol_to_list (sym
, cu
->list_in_scope
);
6444 case DW_TAG_enumerator
:
6445 if (processing_has_namespace_info
6446 && processing_current_prefix
[0] != '\0')
6448 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->objfile_obstack
,
6449 processing_current_prefix
,
6453 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6456 dwarf2_const_value (attr
, sym
, cu
);
6459 /* NOTE: carlton/2003-11-10: See comment above in the
6460 DW_TAG_class_type, etc. block. */
6462 struct pending
**list_to_add
;
6464 list_to_add
= (cu
->list_in_scope
== &file_symbols
6465 && cu
->language
== language_cplus
6466 ? &global_symbols
: cu
->list_in_scope
);
6468 add_symbol_to_list (sym
, list_to_add
);
6471 case DW_TAG_namespace
:
6472 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6473 add_symbol_to_list (sym
, &global_symbols
);
6476 /* Not a tag we recognize. Hopefully we aren't processing
6477 trash data, but since we must specifically ignore things
6478 we don't recognize, there is nothing else we should do at
6480 complaint (&symfile_complaints
, "unsupported tag: '%s'",
6481 dwarf_tag_name (die
->tag
));
6488 /* Copy constant value from an attribute to a symbol. */
6491 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
6492 struct dwarf2_cu
*cu
)
6494 struct objfile
*objfile
= cu
->objfile
;
6495 struct comp_unit_head
*cu_header
= &cu
->header
;
6496 struct dwarf_block
*blk
;
6501 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
6502 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
6503 cu_header
->addr_size
,
6504 TYPE_LENGTH (SYMBOL_TYPE
6506 SYMBOL_VALUE_BYTES (sym
) = (char *)
6507 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
6508 /* NOTE: cagney/2003-05-09: In-lined store_address call with
6509 it's body - store_unsigned_integer. */
6510 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
6512 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6514 case DW_FORM_block1
:
6515 case DW_FORM_block2
:
6516 case DW_FORM_block4
:
6518 blk
= DW_BLOCK (attr
);
6519 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
6520 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
6522 TYPE_LENGTH (SYMBOL_TYPE
6524 SYMBOL_VALUE_BYTES (sym
) = (char *)
6525 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
6526 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
6527 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6530 /* The DW_AT_const_value attributes are supposed to carry the
6531 symbol's value "represented as it would be on the target
6532 architecture." By the time we get here, it's already been
6533 converted to host endianness, so we just need to sign- or
6534 zero-extend it as appropriate. */
6536 dwarf2_const_value_data (attr
, sym
, 8);
6539 dwarf2_const_value_data (attr
, sym
, 16);
6542 dwarf2_const_value_data (attr
, sym
, 32);
6545 dwarf2_const_value_data (attr
, sym
, 64);
6549 SYMBOL_VALUE (sym
) = DW_SND (attr
);
6550 SYMBOL_CLASS (sym
) = LOC_CONST
;
6554 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
6555 SYMBOL_CLASS (sym
) = LOC_CONST
;
6559 complaint (&symfile_complaints
,
6560 "unsupported const value attribute form: '%s'",
6561 dwarf_form_name (attr
->form
));
6562 SYMBOL_VALUE (sym
) = 0;
6563 SYMBOL_CLASS (sym
) = LOC_CONST
;
6569 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
6570 or zero-extend it as appropriate for the symbol's type. */
6572 dwarf2_const_value_data (struct attribute
*attr
,
6576 LONGEST l
= DW_UNSND (attr
);
6578 if (bits
< sizeof (l
) * 8)
6580 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
6581 l
&= ((LONGEST
) 1 << bits
) - 1;
6583 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
6586 SYMBOL_VALUE (sym
) = l
;
6587 SYMBOL_CLASS (sym
) = LOC_CONST
;
6591 /* Return the type of the die in question using its DW_AT_type attribute. */
6593 static struct type
*
6594 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6597 struct attribute
*type_attr
;
6598 struct die_info
*type_die
;
6601 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
6604 /* A missing DW_AT_type represents a void type. */
6605 return dwarf2_fundamental_type (cu
->objfile
, FT_VOID
, cu
);
6609 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6610 type_die
= follow_die_ref (ref
);
6613 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
6614 ref
, cu
->objfile
->name
);
6618 type
= tag_type_to_type (type_die
, cu
);
6621 dump_die (type_die
);
6622 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
6628 /* Return the containing type of the die in question using its
6629 DW_AT_containing_type attribute. */
6631 static struct type
*
6632 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6634 struct type
*type
= NULL
;
6635 struct attribute
*type_attr
;
6636 struct die_info
*type_die
= NULL
;
6639 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
6642 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6643 type_die
= follow_die_ref (ref
);
6646 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
6650 type
= tag_type_to_type (type_die
, cu
);
6655 dump_die (type_die
);
6656 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
6663 static struct type
*
6664 type_at_offset (unsigned int offset
, struct dwarf2_cu
*cu
)
6666 struct die_info
*die
;
6669 die
= follow_die_ref (offset
);
6672 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
6675 type
= tag_type_to_type (die
, cu
);
6680 static struct type
*
6681 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6689 read_type_die (die
, cu
);
6693 error ("Dwarf Error: Cannot find type of die [in module %s]",
6701 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6703 char *prefix
= determine_prefix (die
, cu
);
6704 const char *old_prefix
= processing_current_prefix
;
6705 struct cleanup
*back_to
= make_cleanup (xfree
, prefix
);
6706 processing_current_prefix
= prefix
;
6710 case DW_TAG_class_type
:
6711 case DW_TAG_structure_type
:
6712 case DW_TAG_union_type
:
6713 read_structure_type (die
, cu
);
6715 case DW_TAG_enumeration_type
:
6716 read_enumeration_type (die
, cu
);
6718 case DW_TAG_subprogram
:
6719 case DW_TAG_subroutine_type
:
6720 read_subroutine_type (die
, cu
);
6722 case DW_TAG_array_type
:
6723 read_array_type (die
, cu
);
6725 case DW_TAG_pointer_type
:
6726 read_tag_pointer_type (die
, cu
);
6728 case DW_TAG_ptr_to_member_type
:
6729 read_tag_ptr_to_member_type (die
, cu
);
6731 case DW_TAG_reference_type
:
6732 read_tag_reference_type (die
, cu
);
6734 case DW_TAG_const_type
:
6735 read_tag_const_type (die
, cu
);
6737 case DW_TAG_volatile_type
:
6738 read_tag_volatile_type (die
, cu
);
6740 case DW_TAG_string_type
:
6741 read_tag_string_type (die
, cu
);
6743 case DW_TAG_typedef
:
6744 read_typedef (die
, cu
);
6746 case DW_TAG_subrange_type
:
6747 read_subrange_type (die
, cu
);
6749 case DW_TAG_base_type
:
6750 read_base_type (die
, cu
);
6753 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
6754 dwarf_tag_name (die
->tag
));
6758 processing_current_prefix
= old_prefix
;
6759 do_cleanups (back_to
);
6762 /* Return the name of the namespace/class that DIE is defined within,
6763 or "" if we can't tell. The caller should xfree the result. */
6765 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
6766 therein) for an example of how to use this function to deal with
6767 DW_AT_specification. */
6770 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
6772 struct die_info
*parent
;
6774 if (cu
->language
!= language_cplus
)
6777 parent
= die
->parent
;
6781 return xstrdup ("");
6785 switch (parent
->tag
) {
6786 case DW_TAG_namespace
:
6788 /* FIXME: carlton/2004-03-05: Should I follow extension dies
6789 before doing this check? */
6790 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
6792 return xstrdup (TYPE_TAG_NAME (parent
->type
));
6797 char *parent_prefix
= determine_prefix (parent
, cu
);
6798 char *retval
= typename_concat (parent_prefix
,
6799 namespace_name (parent
, &dummy
,
6801 xfree (parent_prefix
);
6806 case DW_TAG_class_type
:
6807 case DW_TAG_structure_type
:
6809 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
6811 return xstrdup (TYPE_TAG_NAME (parent
->type
));
6815 const char *old_prefix
= processing_current_prefix
;
6816 char *new_prefix
= determine_prefix (parent
, cu
);
6819 processing_current_prefix
= new_prefix
;
6820 retval
= determine_class_name (parent
, cu
);
6821 processing_current_prefix
= old_prefix
;
6828 return determine_prefix (parent
, cu
);
6833 /* Return a newly-allocated string formed by concatenating PREFIX,
6834 "::", and SUFFIX, except that if PREFIX is NULL or the empty
6835 string, just return a copy of SUFFIX. */
6838 typename_concat (const char *prefix
, const char *suffix
)
6840 if (prefix
== NULL
|| prefix
[0] == '\0')
6841 return xstrdup (suffix
);
6844 char *retval
= xmalloc (strlen (prefix
) + 2 + strlen (suffix
) + 1);
6846 strcpy (retval
, prefix
);
6847 strcat (retval
, "::");
6848 strcat (retval
, suffix
);
6854 static struct type
*
6855 dwarf_base_type (int encoding
, int size
, struct dwarf2_cu
*cu
)
6857 struct objfile
*objfile
= cu
->objfile
;
6859 /* FIXME - this should not produce a new (struct type *)
6860 every time. It should cache base types. */
6864 case DW_ATE_address
:
6865 type
= dwarf2_fundamental_type (objfile
, FT_VOID
, cu
);
6867 case DW_ATE_boolean
:
6868 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
, cu
);
6870 case DW_ATE_complex_float
:
6873 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
, cu
);
6877 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
, cu
);
6883 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
6887 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
6894 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6897 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
, cu
);
6901 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6905 case DW_ATE_signed_char
:
6906 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6908 case DW_ATE_unsigned
:
6912 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6915 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
, cu
);
6919 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
, cu
);
6923 case DW_ATE_unsigned_char
:
6924 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6927 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6934 copy_die (struct die_info
*old_die
)
6936 struct die_info
*new_die
;
6939 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6940 memset (new_die
, 0, sizeof (struct die_info
));
6942 new_die
->tag
= old_die
->tag
;
6943 new_die
->has_children
= old_die
->has_children
;
6944 new_die
->abbrev
= old_die
->abbrev
;
6945 new_die
->offset
= old_die
->offset
;
6946 new_die
->type
= NULL
;
6948 num_attrs
= old_die
->num_attrs
;
6949 new_die
->num_attrs
= num_attrs
;
6950 new_die
->attrs
= (struct attribute
*)
6951 xmalloc (num_attrs
* sizeof (struct attribute
));
6953 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
6955 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
6956 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
6957 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
6960 new_die
->next
= NULL
;
6965 /* Return sibling of die, NULL if no sibling. */
6967 static struct die_info
*
6968 sibling_die (struct die_info
*die
)
6970 return die
->sibling
;
6973 /* Get linkage name of a die, return NULL if not found. */
6976 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6978 struct attribute
*attr
;
6980 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6981 if (attr
&& DW_STRING (attr
))
6982 return DW_STRING (attr
);
6983 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6984 if (attr
&& DW_STRING (attr
))
6985 return DW_STRING (attr
);
6989 /* Get name of a die, return NULL if not found. */
6992 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6994 struct attribute
*attr
;
6996 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6997 if (attr
&& DW_STRING (attr
))
6998 return DW_STRING (attr
);
7002 /* Return the die that this die in an extension of, or NULL if there
7005 static struct die_info
*
7006 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
7008 struct attribute
*attr
;
7009 struct die_info
*extension_die
;
7012 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
7016 ref
= dwarf2_get_ref_die_offset (attr
, cu
);
7017 extension_die
= follow_die_ref (ref
);
7020 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
7023 return extension_die
;
7026 /* Convert a DIE tag into its string name. */
7029 dwarf_tag_name (unsigned tag
)
7033 case DW_TAG_padding
:
7034 return "DW_TAG_padding";
7035 case DW_TAG_array_type
:
7036 return "DW_TAG_array_type";
7037 case DW_TAG_class_type
:
7038 return "DW_TAG_class_type";
7039 case DW_TAG_entry_point
:
7040 return "DW_TAG_entry_point";
7041 case DW_TAG_enumeration_type
:
7042 return "DW_TAG_enumeration_type";
7043 case DW_TAG_formal_parameter
:
7044 return "DW_TAG_formal_parameter";
7045 case DW_TAG_imported_declaration
:
7046 return "DW_TAG_imported_declaration";
7048 return "DW_TAG_label";
7049 case DW_TAG_lexical_block
:
7050 return "DW_TAG_lexical_block";
7052 return "DW_TAG_member";
7053 case DW_TAG_pointer_type
:
7054 return "DW_TAG_pointer_type";
7055 case DW_TAG_reference_type
:
7056 return "DW_TAG_reference_type";
7057 case DW_TAG_compile_unit
:
7058 return "DW_TAG_compile_unit";
7059 case DW_TAG_string_type
:
7060 return "DW_TAG_string_type";
7061 case DW_TAG_structure_type
:
7062 return "DW_TAG_structure_type";
7063 case DW_TAG_subroutine_type
:
7064 return "DW_TAG_subroutine_type";
7065 case DW_TAG_typedef
:
7066 return "DW_TAG_typedef";
7067 case DW_TAG_union_type
:
7068 return "DW_TAG_union_type";
7069 case DW_TAG_unspecified_parameters
:
7070 return "DW_TAG_unspecified_parameters";
7071 case DW_TAG_variant
:
7072 return "DW_TAG_variant";
7073 case DW_TAG_common_block
:
7074 return "DW_TAG_common_block";
7075 case DW_TAG_common_inclusion
:
7076 return "DW_TAG_common_inclusion";
7077 case DW_TAG_inheritance
:
7078 return "DW_TAG_inheritance";
7079 case DW_TAG_inlined_subroutine
:
7080 return "DW_TAG_inlined_subroutine";
7082 return "DW_TAG_module";
7083 case DW_TAG_ptr_to_member_type
:
7084 return "DW_TAG_ptr_to_member_type";
7085 case DW_TAG_set_type
:
7086 return "DW_TAG_set_type";
7087 case DW_TAG_subrange_type
:
7088 return "DW_TAG_subrange_type";
7089 case DW_TAG_with_stmt
:
7090 return "DW_TAG_with_stmt";
7091 case DW_TAG_access_declaration
:
7092 return "DW_TAG_access_declaration";
7093 case DW_TAG_base_type
:
7094 return "DW_TAG_base_type";
7095 case DW_TAG_catch_block
:
7096 return "DW_TAG_catch_block";
7097 case DW_TAG_const_type
:
7098 return "DW_TAG_const_type";
7099 case DW_TAG_constant
:
7100 return "DW_TAG_constant";
7101 case DW_TAG_enumerator
:
7102 return "DW_TAG_enumerator";
7103 case DW_TAG_file_type
:
7104 return "DW_TAG_file_type";
7106 return "DW_TAG_friend";
7107 case DW_TAG_namelist
:
7108 return "DW_TAG_namelist";
7109 case DW_TAG_namelist_item
:
7110 return "DW_TAG_namelist_item";
7111 case DW_TAG_packed_type
:
7112 return "DW_TAG_packed_type";
7113 case DW_TAG_subprogram
:
7114 return "DW_TAG_subprogram";
7115 case DW_TAG_template_type_param
:
7116 return "DW_TAG_template_type_param";
7117 case DW_TAG_template_value_param
:
7118 return "DW_TAG_template_value_param";
7119 case DW_TAG_thrown_type
:
7120 return "DW_TAG_thrown_type";
7121 case DW_TAG_try_block
:
7122 return "DW_TAG_try_block";
7123 case DW_TAG_variant_part
:
7124 return "DW_TAG_variant_part";
7125 case DW_TAG_variable
:
7126 return "DW_TAG_variable";
7127 case DW_TAG_volatile_type
:
7128 return "DW_TAG_volatile_type";
7129 case DW_TAG_dwarf_procedure
:
7130 return "DW_TAG_dwarf_procedure";
7131 case DW_TAG_restrict_type
:
7132 return "DW_TAG_restrict_type";
7133 case DW_TAG_interface_type
:
7134 return "DW_TAG_interface_type";
7135 case DW_TAG_namespace
:
7136 return "DW_TAG_namespace";
7137 case DW_TAG_imported_module
:
7138 return "DW_TAG_imported_module";
7139 case DW_TAG_unspecified_type
:
7140 return "DW_TAG_unspecified_type";
7141 case DW_TAG_partial_unit
:
7142 return "DW_TAG_partial_unit";
7143 case DW_TAG_imported_unit
:
7144 return "DW_TAG_imported_unit";
7145 case DW_TAG_MIPS_loop
:
7146 return "DW_TAG_MIPS_loop";
7147 case DW_TAG_format_label
:
7148 return "DW_TAG_format_label";
7149 case DW_TAG_function_template
:
7150 return "DW_TAG_function_template";
7151 case DW_TAG_class_template
:
7152 return "DW_TAG_class_template";
7154 return "DW_TAG_<unknown>";
7158 /* Convert a DWARF attribute code into its string name. */
7161 dwarf_attr_name (unsigned attr
)
7166 return "DW_AT_sibling";
7167 case DW_AT_location
:
7168 return "DW_AT_location";
7170 return "DW_AT_name";
7171 case DW_AT_ordering
:
7172 return "DW_AT_ordering";
7173 case DW_AT_subscr_data
:
7174 return "DW_AT_subscr_data";
7175 case DW_AT_byte_size
:
7176 return "DW_AT_byte_size";
7177 case DW_AT_bit_offset
:
7178 return "DW_AT_bit_offset";
7179 case DW_AT_bit_size
:
7180 return "DW_AT_bit_size";
7181 case DW_AT_element_list
:
7182 return "DW_AT_element_list";
7183 case DW_AT_stmt_list
:
7184 return "DW_AT_stmt_list";
7186 return "DW_AT_low_pc";
7188 return "DW_AT_high_pc";
7189 case DW_AT_language
:
7190 return "DW_AT_language";
7192 return "DW_AT_member";
7194 return "DW_AT_discr";
7195 case DW_AT_discr_value
:
7196 return "DW_AT_discr_value";
7197 case DW_AT_visibility
:
7198 return "DW_AT_visibility";
7200 return "DW_AT_import";
7201 case DW_AT_string_length
:
7202 return "DW_AT_string_length";
7203 case DW_AT_common_reference
:
7204 return "DW_AT_common_reference";
7205 case DW_AT_comp_dir
:
7206 return "DW_AT_comp_dir";
7207 case DW_AT_const_value
:
7208 return "DW_AT_const_value";
7209 case DW_AT_containing_type
:
7210 return "DW_AT_containing_type";
7211 case DW_AT_default_value
:
7212 return "DW_AT_default_value";
7214 return "DW_AT_inline";
7215 case DW_AT_is_optional
:
7216 return "DW_AT_is_optional";
7217 case DW_AT_lower_bound
:
7218 return "DW_AT_lower_bound";
7219 case DW_AT_producer
:
7220 return "DW_AT_producer";
7221 case DW_AT_prototyped
:
7222 return "DW_AT_prototyped";
7223 case DW_AT_return_addr
:
7224 return "DW_AT_return_addr";
7225 case DW_AT_start_scope
:
7226 return "DW_AT_start_scope";
7227 case DW_AT_stride_size
:
7228 return "DW_AT_stride_size";
7229 case DW_AT_upper_bound
:
7230 return "DW_AT_upper_bound";
7231 case DW_AT_abstract_origin
:
7232 return "DW_AT_abstract_origin";
7233 case DW_AT_accessibility
:
7234 return "DW_AT_accessibility";
7235 case DW_AT_address_class
:
7236 return "DW_AT_address_class";
7237 case DW_AT_artificial
:
7238 return "DW_AT_artificial";
7239 case DW_AT_base_types
:
7240 return "DW_AT_base_types";
7241 case DW_AT_calling_convention
:
7242 return "DW_AT_calling_convention";
7244 return "DW_AT_count";
7245 case DW_AT_data_member_location
:
7246 return "DW_AT_data_member_location";
7247 case DW_AT_decl_column
:
7248 return "DW_AT_decl_column";
7249 case DW_AT_decl_file
:
7250 return "DW_AT_decl_file";
7251 case DW_AT_decl_line
:
7252 return "DW_AT_decl_line";
7253 case DW_AT_declaration
:
7254 return "DW_AT_declaration";
7255 case DW_AT_discr_list
:
7256 return "DW_AT_discr_list";
7257 case DW_AT_encoding
:
7258 return "DW_AT_encoding";
7259 case DW_AT_external
:
7260 return "DW_AT_external";
7261 case DW_AT_frame_base
:
7262 return "DW_AT_frame_base";
7264 return "DW_AT_friend";
7265 case DW_AT_identifier_case
:
7266 return "DW_AT_identifier_case";
7267 case DW_AT_macro_info
:
7268 return "DW_AT_macro_info";
7269 case DW_AT_namelist_items
:
7270 return "DW_AT_namelist_items";
7271 case DW_AT_priority
:
7272 return "DW_AT_priority";
7274 return "DW_AT_segment";
7275 case DW_AT_specification
:
7276 return "DW_AT_specification";
7277 case DW_AT_static_link
:
7278 return "DW_AT_static_link";
7280 return "DW_AT_type";
7281 case DW_AT_use_location
:
7282 return "DW_AT_use_location";
7283 case DW_AT_variable_parameter
:
7284 return "DW_AT_variable_parameter";
7285 case DW_AT_virtuality
:
7286 return "DW_AT_virtuality";
7287 case DW_AT_vtable_elem_location
:
7288 return "DW_AT_vtable_elem_location";
7289 case DW_AT_allocated
:
7290 return "DW_AT_allocated";
7291 case DW_AT_associated
:
7292 return "DW_AT_associated";
7293 case DW_AT_data_location
:
7294 return "DW_AT_data_location";
7296 return "DW_AT_stride";
7297 case DW_AT_entry_pc
:
7298 return "DW_AT_entry_pc";
7299 case DW_AT_use_UTF8
:
7300 return "DW_AT_use_UTF8";
7301 case DW_AT_extension
:
7302 return "DW_AT_extension";
7304 return "DW_AT_ranges";
7305 case DW_AT_trampoline
:
7306 return "DW_AT_trampoline";
7307 case DW_AT_call_column
:
7308 return "DW_AT_call_column";
7309 case DW_AT_call_file
:
7310 return "DW_AT_call_file";
7311 case DW_AT_call_line
:
7312 return "DW_AT_call_line";
7314 case DW_AT_MIPS_fde
:
7315 return "DW_AT_MIPS_fde";
7316 case DW_AT_MIPS_loop_begin
:
7317 return "DW_AT_MIPS_loop_begin";
7318 case DW_AT_MIPS_tail_loop_begin
:
7319 return "DW_AT_MIPS_tail_loop_begin";
7320 case DW_AT_MIPS_epilog_begin
:
7321 return "DW_AT_MIPS_epilog_begin";
7322 case DW_AT_MIPS_loop_unroll_factor
:
7323 return "DW_AT_MIPS_loop_unroll_factor";
7324 case DW_AT_MIPS_software_pipeline_depth
:
7325 return "DW_AT_MIPS_software_pipeline_depth";
7327 case DW_AT_MIPS_linkage_name
:
7328 return "DW_AT_MIPS_linkage_name";
7330 case DW_AT_sf_names
:
7331 return "DW_AT_sf_names";
7332 case DW_AT_src_info
:
7333 return "DW_AT_src_info";
7334 case DW_AT_mac_info
:
7335 return "DW_AT_mac_info";
7336 case DW_AT_src_coords
:
7337 return "DW_AT_src_coords";
7338 case DW_AT_body_begin
:
7339 return "DW_AT_body_begin";
7340 case DW_AT_body_end
:
7341 return "DW_AT_body_end";
7342 case DW_AT_GNU_vector
:
7343 return "DW_AT_GNU_vector";
7345 return "DW_AT_<unknown>";
7349 /* Convert a DWARF value form code into its string name. */
7352 dwarf_form_name (unsigned form
)
7357 return "DW_FORM_addr";
7358 case DW_FORM_block2
:
7359 return "DW_FORM_block2";
7360 case DW_FORM_block4
:
7361 return "DW_FORM_block4";
7363 return "DW_FORM_data2";
7365 return "DW_FORM_data4";
7367 return "DW_FORM_data8";
7368 case DW_FORM_string
:
7369 return "DW_FORM_string";
7371 return "DW_FORM_block";
7372 case DW_FORM_block1
:
7373 return "DW_FORM_block1";
7375 return "DW_FORM_data1";
7377 return "DW_FORM_flag";
7379 return "DW_FORM_sdata";
7381 return "DW_FORM_strp";
7383 return "DW_FORM_udata";
7384 case DW_FORM_ref_addr
:
7385 return "DW_FORM_ref_addr";
7387 return "DW_FORM_ref1";
7389 return "DW_FORM_ref2";
7391 return "DW_FORM_ref4";
7393 return "DW_FORM_ref8";
7394 case DW_FORM_ref_udata
:
7395 return "DW_FORM_ref_udata";
7396 case DW_FORM_indirect
:
7397 return "DW_FORM_indirect";
7399 return "DW_FORM_<unknown>";
7403 /* Convert a DWARF stack opcode into its string name. */
7406 dwarf_stack_op_name (unsigned op
)
7411 return "DW_OP_addr";
7413 return "DW_OP_deref";
7415 return "DW_OP_const1u";
7417 return "DW_OP_const1s";
7419 return "DW_OP_const2u";
7421 return "DW_OP_const2s";
7423 return "DW_OP_const4u";
7425 return "DW_OP_const4s";
7427 return "DW_OP_const8u";
7429 return "DW_OP_const8s";
7431 return "DW_OP_constu";
7433 return "DW_OP_consts";
7437 return "DW_OP_drop";
7439 return "DW_OP_over";
7441 return "DW_OP_pick";
7443 return "DW_OP_swap";
7447 return "DW_OP_xderef";
7455 return "DW_OP_minus";
7467 return "DW_OP_plus";
7468 case DW_OP_plus_uconst
:
7469 return "DW_OP_plus_uconst";
7475 return "DW_OP_shra";
7493 return "DW_OP_skip";
7495 return "DW_OP_lit0";
7497 return "DW_OP_lit1";
7499 return "DW_OP_lit2";
7501 return "DW_OP_lit3";
7503 return "DW_OP_lit4";
7505 return "DW_OP_lit5";
7507 return "DW_OP_lit6";
7509 return "DW_OP_lit7";
7511 return "DW_OP_lit8";
7513 return "DW_OP_lit9";
7515 return "DW_OP_lit10";
7517 return "DW_OP_lit11";
7519 return "DW_OP_lit12";
7521 return "DW_OP_lit13";
7523 return "DW_OP_lit14";
7525 return "DW_OP_lit15";
7527 return "DW_OP_lit16";
7529 return "DW_OP_lit17";
7531 return "DW_OP_lit18";
7533 return "DW_OP_lit19";
7535 return "DW_OP_lit20";
7537 return "DW_OP_lit21";
7539 return "DW_OP_lit22";
7541 return "DW_OP_lit23";
7543 return "DW_OP_lit24";
7545 return "DW_OP_lit25";
7547 return "DW_OP_lit26";
7549 return "DW_OP_lit27";
7551 return "DW_OP_lit28";
7553 return "DW_OP_lit29";
7555 return "DW_OP_lit30";
7557 return "DW_OP_lit31";
7559 return "DW_OP_reg0";
7561 return "DW_OP_reg1";
7563 return "DW_OP_reg2";
7565 return "DW_OP_reg3";
7567 return "DW_OP_reg4";
7569 return "DW_OP_reg5";
7571 return "DW_OP_reg6";
7573 return "DW_OP_reg7";
7575 return "DW_OP_reg8";
7577 return "DW_OP_reg9";
7579 return "DW_OP_reg10";
7581 return "DW_OP_reg11";
7583 return "DW_OP_reg12";
7585 return "DW_OP_reg13";
7587 return "DW_OP_reg14";
7589 return "DW_OP_reg15";
7591 return "DW_OP_reg16";
7593 return "DW_OP_reg17";
7595 return "DW_OP_reg18";
7597 return "DW_OP_reg19";
7599 return "DW_OP_reg20";
7601 return "DW_OP_reg21";
7603 return "DW_OP_reg22";
7605 return "DW_OP_reg23";
7607 return "DW_OP_reg24";
7609 return "DW_OP_reg25";
7611 return "DW_OP_reg26";
7613 return "DW_OP_reg27";
7615 return "DW_OP_reg28";
7617 return "DW_OP_reg29";
7619 return "DW_OP_reg30";
7621 return "DW_OP_reg31";
7623 return "DW_OP_breg0";
7625 return "DW_OP_breg1";
7627 return "DW_OP_breg2";
7629 return "DW_OP_breg3";
7631 return "DW_OP_breg4";
7633 return "DW_OP_breg5";
7635 return "DW_OP_breg6";
7637 return "DW_OP_breg7";
7639 return "DW_OP_breg8";
7641 return "DW_OP_breg9";
7643 return "DW_OP_breg10";
7645 return "DW_OP_breg11";
7647 return "DW_OP_breg12";
7649 return "DW_OP_breg13";
7651 return "DW_OP_breg14";
7653 return "DW_OP_breg15";
7655 return "DW_OP_breg16";
7657 return "DW_OP_breg17";
7659 return "DW_OP_breg18";
7661 return "DW_OP_breg19";
7663 return "DW_OP_breg20";
7665 return "DW_OP_breg21";
7667 return "DW_OP_breg22";
7669 return "DW_OP_breg23";
7671 return "DW_OP_breg24";
7673 return "DW_OP_breg25";
7675 return "DW_OP_breg26";
7677 return "DW_OP_breg27";
7679 return "DW_OP_breg28";
7681 return "DW_OP_breg29";
7683 return "DW_OP_breg30";
7685 return "DW_OP_breg31";
7687 return "DW_OP_regx";
7689 return "DW_OP_fbreg";
7691 return "DW_OP_bregx";
7693 return "DW_OP_piece";
7694 case DW_OP_deref_size
:
7695 return "DW_OP_deref_size";
7696 case DW_OP_xderef_size
:
7697 return "DW_OP_xderef_size";
7700 /* DWARF 3 extensions. */
7701 case DW_OP_push_object_address
:
7702 return "DW_OP_push_object_address";
7704 return "DW_OP_call2";
7706 return "DW_OP_call4";
7707 case DW_OP_call_ref
:
7708 return "DW_OP_call_ref";
7709 /* GNU extensions. */
7710 case DW_OP_GNU_push_tls_address
:
7711 return "DW_OP_GNU_push_tls_address";
7713 return "OP_<unknown>";
7718 dwarf_bool_name (unsigned mybool
)
7726 /* Convert a DWARF type code into its string name. */
7729 dwarf_type_encoding_name (unsigned enc
)
7733 case DW_ATE_address
:
7734 return "DW_ATE_address";
7735 case DW_ATE_boolean
:
7736 return "DW_ATE_boolean";
7737 case DW_ATE_complex_float
:
7738 return "DW_ATE_complex_float";
7740 return "DW_ATE_float";
7742 return "DW_ATE_signed";
7743 case DW_ATE_signed_char
:
7744 return "DW_ATE_signed_char";
7745 case DW_ATE_unsigned
:
7746 return "DW_ATE_unsigned";
7747 case DW_ATE_unsigned_char
:
7748 return "DW_ATE_unsigned_char";
7749 case DW_ATE_imaginary_float
:
7750 return "DW_ATE_imaginary_float";
7752 return "DW_ATE_<unknown>";
7756 /* Convert a DWARF call frame info operation to its string name. */
7760 dwarf_cfi_name (unsigned cfi_opc
)
7764 case DW_CFA_advance_loc
:
7765 return "DW_CFA_advance_loc";
7767 return "DW_CFA_offset";
7768 case DW_CFA_restore
:
7769 return "DW_CFA_restore";
7771 return "DW_CFA_nop";
7772 case DW_CFA_set_loc
:
7773 return "DW_CFA_set_loc";
7774 case DW_CFA_advance_loc1
:
7775 return "DW_CFA_advance_loc1";
7776 case DW_CFA_advance_loc2
:
7777 return "DW_CFA_advance_loc2";
7778 case DW_CFA_advance_loc4
:
7779 return "DW_CFA_advance_loc4";
7780 case DW_CFA_offset_extended
:
7781 return "DW_CFA_offset_extended";
7782 case DW_CFA_restore_extended
:
7783 return "DW_CFA_restore_extended";
7784 case DW_CFA_undefined
:
7785 return "DW_CFA_undefined";
7786 case DW_CFA_same_value
:
7787 return "DW_CFA_same_value";
7788 case DW_CFA_register
:
7789 return "DW_CFA_register";
7790 case DW_CFA_remember_state
:
7791 return "DW_CFA_remember_state";
7792 case DW_CFA_restore_state
:
7793 return "DW_CFA_restore_state";
7794 case DW_CFA_def_cfa
:
7795 return "DW_CFA_def_cfa";
7796 case DW_CFA_def_cfa_register
:
7797 return "DW_CFA_def_cfa_register";
7798 case DW_CFA_def_cfa_offset
:
7799 return "DW_CFA_def_cfa_offset";
7802 case DW_CFA_def_cfa_expression
:
7803 return "DW_CFA_def_cfa_expression";
7804 case DW_CFA_expression
:
7805 return "DW_CFA_expression";
7806 case DW_CFA_offset_extended_sf
:
7807 return "DW_CFA_offset_extended_sf";
7808 case DW_CFA_def_cfa_sf
:
7809 return "DW_CFA_def_cfa_sf";
7810 case DW_CFA_def_cfa_offset_sf
:
7811 return "DW_CFA_def_cfa_offset_sf";
7813 /* SGI/MIPS specific */
7814 case DW_CFA_MIPS_advance_loc8
:
7815 return "DW_CFA_MIPS_advance_loc8";
7817 /* GNU extensions */
7818 case DW_CFA_GNU_window_save
:
7819 return "DW_CFA_GNU_window_save";
7820 case DW_CFA_GNU_args_size
:
7821 return "DW_CFA_GNU_args_size";
7822 case DW_CFA_GNU_negative_offset_extended
:
7823 return "DW_CFA_GNU_negative_offset_extended";
7826 return "DW_CFA_<unknown>";
7832 dump_die (struct die_info
*die
)
7836 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
7837 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
7838 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
7839 dwarf_bool_name (die
->child
!= NULL
));
7841 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
7842 for (i
= 0; i
< die
->num_attrs
; ++i
)
7844 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
7845 dwarf_attr_name (die
->attrs
[i
].name
),
7846 dwarf_form_name (die
->attrs
[i
].form
));
7847 switch (die
->attrs
[i
].form
)
7849 case DW_FORM_ref_addr
:
7851 fprintf_unfiltered (gdb_stderr
, "address: ");
7852 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
7854 case DW_FORM_block2
:
7855 case DW_FORM_block4
:
7857 case DW_FORM_block1
:
7858 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
7869 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
7871 case DW_FORM_string
:
7873 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
7874 DW_STRING (&die
->attrs
[i
])
7875 ? DW_STRING (&die
->attrs
[i
]) : "");
7878 if (DW_UNSND (&die
->attrs
[i
]))
7879 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
7881 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
7883 case DW_FORM_indirect
:
7884 /* the reader will have reduced the indirect form to
7885 the "base form" so this form should not occur */
7886 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
7889 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
7890 die
->attrs
[i
].form
);
7892 fprintf_unfiltered (gdb_stderr
, "\n");
7897 dump_die_list (struct die_info
*die
)
7902 if (die
->child
!= NULL
)
7903 dump_die_list (die
->child
);
7904 if (die
->sibling
!= NULL
)
7905 dump_die_list (die
->sibling
);
7910 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
7913 struct die_info
*old
;
7915 h
= (offset
% REF_HASH_SIZE
);
7916 old
= die_ref_table
[h
];
7917 die
->next_ref
= old
;
7918 die_ref_table
[h
] = die
;
7923 dwarf2_empty_hash_tables (void)
7925 memset (die_ref_table
, 0, sizeof (die_ref_table
));
7929 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
7931 unsigned int result
= 0;
7935 case DW_FORM_ref_addr
:
7936 result
= DW_ADDR (attr
);
7942 case DW_FORM_ref_udata
:
7943 result
= cu
->header
.offset
+ DW_UNSND (attr
);
7946 complaint (&symfile_complaints
,
7947 "unsupported die ref attribute form: '%s'",
7948 dwarf_form_name (attr
->form
));
7953 /* Return the constant value held by the given attribute. Return -1
7954 if the value held by the attribute is not constant. */
7957 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
7959 if (attr
->form
== DW_FORM_sdata
)
7960 return DW_SND (attr
);
7961 else if (attr
->form
== DW_FORM_udata
7962 || attr
->form
== DW_FORM_data1
7963 || attr
->form
== DW_FORM_data2
7964 || attr
->form
== DW_FORM_data4
7965 || attr
->form
== DW_FORM_data8
)
7966 return DW_UNSND (attr
);
7969 complaint (&symfile_complaints
, "Attribute value is not a constant (%s)",
7970 dwarf_form_name (attr
->form
));
7971 return default_value
;
7975 static struct die_info
*
7976 follow_die_ref (unsigned int offset
)
7978 struct die_info
*die
;
7981 h
= (offset
% REF_HASH_SIZE
);
7982 die
= die_ref_table
[h
];
7985 if (die
->offset
== offset
)
7989 die
= die
->next_ref
;
7994 static struct type
*
7995 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid,
7996 struct dwarf2_cu
*cu
)
7998 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
8000 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
8001 typeid, objfile
->name
);
8004 /* Look for this particular type in the fundamental type vector. If
8005 one is not found, create and install one appropriate for the
8006 current language and the current target machine. */
8008 if (cu
->ftypes
[typeid] == NULL
)
8010 cu
->ftypes
[typeid] = cu
->language_defn
->la_fund_type (objfile
, typeid);
8013 return (cu
->ftypes
[typeid]);
8016 /* Decode simple location descriptions.
8017 Given a pointer to a dwarf block that defines a location, compute
8018 the location and return the value.
8020 NOTE drow/2003-11-18: This function is called in two situations
8021 now: for the address of static or global variables (partial symbols
8022 only) and for offsets into structures which are expected to be
8023 (more or less) constant. The partial symbol case should go away,
8024 and only the constant case should remain. That will let this
8025 function complain more accurately. A few special modes are allowed
8026 without complaint for global variables (for instance, global
8027 register values and thread-local values).
8029 A location description containing no operations indicates that the
8030 object is optimized out. The return value is 0 for that case.
8031 FIXME drow/2003-11-16: No callers check for this case any more; soon all
8032 callers will only want a very basic result and this can become a
8035 When the result is a register number, the global isreg flag is set,
8036 otherwise it is cleared.
8038 Note that stack[0] is unused except as a default error return.
8039 Note that stack overflow is not yet handled. */
8042 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
8044 struct objfile
*objfile
= cu
->objfile
;
8045 struct comp_unit_head
*cu_header
= &cu
->header
;
8047 int size
= blk
->size
;
8048 char *data
= blk
->data
;
8049 CORE_ADDR stack
[64];
8051 unsigned int bytes_read
, unsnd
;
8096 stack
[++stacki
] = op
- DW_OP_lit0
;
8132 stack
[++stacki
] = op
- DW_OP_reg0
;
8134 dwarf2_complex_location_expr_complaint ();
8139 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
8141 stack
[++stacki
] = unsnd
;
8143 dwarf2_complex_location_expr_complaint ();
8147 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
8153 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
8158 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
8163 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
8168 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
8173 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
8178 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
8183 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
8189 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
8194 stack
[stacki
+ 1] = stack
[stacki
];
8199 stack
[stacki
- 1] += stack
[stacki
];
8203 case DW_OP_plus_uconst
:
8204 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
8209 stack
[stacki
- 1] -= stack
[stacki
];
8214 /* If we're not the last op, then we definitely can't encode
8215 this using GDB's address_class enum. This is valid for partial
8216 global symbols, although the variable's address will be bogus
8219 dwarf2_complex_location_expr_complaint ();
8222 case DW_OP_GNU_push_tls_address
:
8223 /* The top of the stack has the offset from the beginning
8224 of the thread control block at which the variable is located. */
8225 /* Nothing should follow this operator, so the top of stack would
8227 /* This is valid for partial global symbols, but the variable's
8228 address will be bogus in the psymtab. */
8230 dwarf2_complex_location_expr_complaint ();
8234 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
8235 dwarf_stack_op_name (op
));
8236 return (stack
[stacki
]);
8239 return (stack
[stacki
]);
8242 /* memory allocation interface */
8244 static struct dwarf_block
*
8245 dwarf_alloc_block (struct dwarf2_cu
*cu
)
8247 struct dwarf_block
*blk
;
8249 blk
= (struct dwarf_block
*)
8250 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
8254 static struct abbrev_info
*
8255 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
8257 struct abbrev_info
*abbrev
;
8259 abbrev
= (struct abbrev_info
*)
8260 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
8261 memset (abbrev
, 0, sizeof (struct abbrev_info
));
8265 static struct die_info
*
8266 dwarf_alloc_die (void)
8268 struct die_info
*die
;
8270 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
8271 memset (die
, 0, sizeof (struct die_info
));
8276 /* Macro support. */
8279 /* Return the full name of file number I in *LH's file name table.
8280 Use COMP_DIR as the name of the current directory of the
8281 compilation. The result is allocated using xmalloc; the caller is
8282 responsible for freeing it. */
8284 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
8286 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
8288 if (IS_ABSOLUTE_PATH (fe
->name
))
8289 return xstrdup (fe
->name
);
8297 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8303 dir_len
= strlen (dir
);
8304 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
8305 strcpy (full_name
, dir
);
8306 full_name
[dir_len
] = '/';
8307 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
8311 return xstrdup (fe
->name
);
8316 static struct macro_source_file
*
8317 macro_start_file (int file
, int line
,
8318 struct macro_source_file
*current_file
,
8319 const char *comp_dir
,
8320 struct line_header
*lh
, struct objfile
*objfile
)
8322 /* The full name of this source file. */
8323 char *full_name
= file_full_name (file
, lh
, comp_dir
);
8325 /* We don't create a macro table for this compilation unit
8326 at all until we actually get a filename. */
8327 if (! pending_macros
)
8328 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
8329 objfile
->macro_cache
);
8332 /* If we have no current file, then this must be the start_file
8333 directive for the compilation unit's main source file. */
8334 current_file
= macro_set_main (pending_macros
, full_name
);
8336 current_file
= macro_include (current_file
, line
, full_name
);
8340 return current_file
;
8344 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
8345 followed by a null byte. */
8347 copy_string (const char *buf
, int len
)
8349 char *s
= xmalloc (len
+ 1);
8350 memcpy (s
, buf
, len
);
8358 consume_improper_spaces (const char *p
, const char *body
)
8362 complaint (&symfile_complaints
,
8363 "macro definition contains spaces in formal argument list:\n`%s'",
8375 parse_macro_definition (struct macro_source_file
*file
, int line
,
8380 /* The body string takes one of two forms. For object-like macro
8381 definitions, it should be:
8383 <macro name> " " <definition>
8385 For function-like macro definitions, it should be:
8387 <macro name> "() " <definition>
8389 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
8391 Spaces may appear only where explicitly indicated, and in the
8394 The Dwarf 2 spec says that an object-like macro's name is always
8395 followed by a space, but versions of GCC around March 2002 omit
8396 the space when the macro's definition is the empty string.
8398 The Dwarf 2 spec says that there should be no spaces between the
8399 formal arguments in a function-like macro's formal argument list,
8400 but versions of GCC around March 2002 include spaces after the
8404 /* Find the extent of the macro name. The macro name is terminated
8405 by either a space or null character (for an object-like macro) or
8406 an opening paren (for a function-like macro). */
8407 for (p
= body
; *p
; p
++)
8408 if (*p
== ' ' || *p
== '(')
8411 if (*p
== ' ' || *p
== '\0')
8413 /* It's an object-like macro. */
8414 int name_len
= p
- body
;
8415 char *name
= copy_string (body
, name_len
);
8416 const char *replacement
;
8419 replacement
= body
+ name_len
+ 1;
8422 dwarf2_macro_malformed_definition_complaint (body
);
8423 replacement
= body
+ name_len
;
8426 macro_define_object (file
, line
, name
, replacement
);
8432 /* It's a function-like macro. */
8433 char *name
= copy_string (body
, p
- body
);
8436 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
8440 p
= consume_improper_spaces (p
, body
);
8442 /* Parse the formal argument list. */
8443 while (*p
&& *p
!= ')')
8445 /* Find the extent of the current argument name. */
8446 const char *arg_start
= p
;
8448 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
8451 if (! *p
|| p
== arg_start
)
8452 dwarf2_macro_malformed_definition_complaint (body
);
8455 /* Make sure argv has room for the new argument. */
8456 if (argc
>= argv_size
)
8459 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
8462 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
8465 p
= consume_improper_spaces (p
, body
);
8467 /* Consume the comma, if present. */
8472 p
= consume_improper_spaces (p
, body
);
8481 /* Perfectly formed definition, no complaints. */
8482 macro_define_function (file
, line
, name
,
8483 argc
, (const char **) argv
,
8485 else if (*p
== '\0')
8487 /* Complain, but do define it. */
8488 dwarf2_macro_malformed_definition_complaint (body
);
8489 macro_define_function (file
, line
, name
,
8490 argc
, (const char **) argv
,
8494 /* Just complain. */
8495 dwarf2_macro_malformed_definition_complaint (body
);
8498 /* Just complain. */
8499 dwarf2_macro_malformed_definition_complaint (body
);
8505 for (i
= 0; i
< argc
; i
++)
8511 dwarf2_macro_malformed_definition_complaint (body
);
8516 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
8517 char *comp_dir
, bfd
*abfd
,
8518 struct dwarf2_cu
*cu
)
8520 char *mac_ptr
, *mac_end
;
8521 struct macro_source_file
*current_file
= 0;
8523 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
8525 complaint (&symfile_complaints
, "missing .debug_macinfo section");
8529 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
8530 mac_end
= dwarf2_per_objfile
->macinfo_buffer
8531 + dwarf2_per_objfile
->macinfo_size
;
8535 enum dwarf_macinfo_record_type macinfo_type
;
8537 /* Do we at least have room for a macinfo type byte? */
8538 if (mac_ptr
>= mac_end
)
8540 dwarf2_macros_too_long_complaint ();
8544 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
8547 switch (macinfo_type
)
8549 /* A zero macinfo type indicates the end of the macro
8554 case DW_MACINFO_define
:
8555 case DW_MACINFO_undef
:
8561 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8562 mac_ptr
+= bytes_read
;
8563 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
8564 mac_ptr
+= bytes_read
;
8567 complaint (&symfile_complaints
,
8568 "debug info gives macro %s outside of any file: %s",
8570 DW_MACINFO_define
? "definition" : macinfo_type
==
8571 DW_MACINFO_undef
? "undefinition" :
8572 "something-or-other", body
);
8575 if (macinfo_type
== DW_MACINFO_define
)
8576 parse_macro_definition (current_file
, line
, body
);
8577 else if (macinfo_type
== DW_MACINFO_undef
)
8578 macro_undef (current_file
, line
, body
);
8583 case DW_MACINFO_start_file
:
8588 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8589 mac_ptr
+= bytes_read
;
8590 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8591 mac_ptr
+= bytes_read
;
8593 current_file
= macro_start_file (file
, line
,
8594 current_file
, comp_dir
,
8599 case DW_MACINFO_end_file
:
8601 complaint (&symfile_complaints
,
8602 "macro debug info has an unmatched `close_file' directive");
8605 current_file
= current_file
->included_by
;
8608 enum dwarf_macinfo_record_type next_type
;
8610 /* GCC circa March 2002 doesn't produce the zero
8611 type byte marking the end of the compilation
8612 unit. Complain if it's not there, but exit no
8615 /* Do we at least have room for a macinfo type byte? */
8616 if (mac_ptr
>= mac_end
)
8618 dwarf2_macros_too_long_complaint ();
8622 /* We don't increment mac_ptr here, so this is just
8624 next_type
= read_1_byte (abfd
, mac_ptr
);
8626 complaint (&symfile_complaints
,
8627 "no terminating 0-type entry for macros in `.debug_macinfo' section");
8634 case DW_MACINFO_vendor_ext
:
8640 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8641 mac_ptr
+= bytes_read
;
8642 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
8643 mac_ptr
+= bytes_read
;
8645 /* We don't recognize any vendor extensions. */
8652 /* Check if the attribute's form is a DW_FORM_block*
8653 if so return true else false. */
8655 attr_form_is_block (struct attribute
*attr
)
8657 return (attr
== NULL
? 0 :
8658 attr
->form
== DW_FORM_block1
8659 || attr
->form
== DW_FORM_block2
8660 || attr
->form
== DW_FORM_block4
8661 || attr
->form
== DW_FORM_block
);
8665 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
8666 struct dwarf2_cu
*cu
)
8668 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
8670 struct dwarf2_loclist_baton
*baton
;
8672 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
8673 sizeof (struct dwarf2_loclist_baton
));
8674 baton
->objfile
= cu
->objfile
;
8676 /* We don't know how long the location list is, but make sure we
8677 don't run off the edge of the section. */
8678 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
8679 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
8680 baton
->base_address
= cu
->header
.base_address
;
8681 if (cu
->header
.base_known
== 0)
8682 complaint (&symfile_complaints
,
8683 "Location list used without specifying the CU base address.");
8685 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
8686 SYMBOL_LOCATION_BATON (sym
) = baton
;
8690 struct dwarf2_locexpr_baton
*baton
;
8692 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
8693 sizeof (struct dwarf2_locexpr_baton
));
8694 baton
->objfile
= cu
->objfile
;
8696 if (attr_form_is_block (attr
))
8698 /* Note that we're just copying the block's data pointer
8699 here, not the actual data. We're still pointing into the
8700 info_buffer for SYM's objfile; right now we never release
8701 that buffer, but when we do clean up properly this may
8703 baton
->size
= DW_BLOCK (attr
)->size
;
8704 baton
->data
= DW_BLOCK (attr
)->data
;
8708 dwarf2_invalid_attrib_class_complaint ("location description",
8709 SYMBOL_NATURAL_NAME (sym
));
8714 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
8715 SYMBOL_LOCATION_BATON (sym
) = baton
;
8719 /* This cleanup function is passed the address of a dwarf2_cu on the stack
8720 when we're finished with it. We can't free the pointer itself, but
8721 release any associated storage.
8723 Only used during partial symbol parsing. */
8726 free_stack_comp_unit (void *data
)
8728 struct dwarf2_cu
*cu
= data
;
8730 obstack_free (&cu
->comp_unit_obstack
, NULL
);
8731 cu
->partial_dies
= NULL
;
8734 /* Allocation function for the libiberty hash table which uses an
8738 hashtab_obstack_allocate (void *data
, size_t size
, size_t count
)
8740 unsigned int total
= size
* count
;
8741 void *ptr
= obstack_alloc ((struct obstack
*) data
, total
);
8742 memset (ptr
, 0, total
);
8746 /* Trivial deallocation function for the libiberty splay tree and hash
8747 table - don't deallocate anything. Rely on later deletion of the
8751 dummy_obstack_deallocate (void *object
, void *data
)
8756 /* Trivial hash function for partial_die_info: the hash value of a DIE
8757 is its offset in .debug_info for this objfile. */
8760 partial_die_hash (const void *item
)
8762 const struct partial_die_info
*part_die
= item
;
8763 return part_die
->offset
;
8766 /* Trivial comparison function for partial_die_info structures: two DIEs
8767 are equal if they have the same offset. */
8770 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
8772 const struct partial_die_info
*part_die_lhs
= item_lhs
;
8773 const struct partial_die_info
*part_die_rhs
= item_rhs
;
8774 return part_die_lhs
->offset
== part_die_rhs
->offset
;
8777 void _initialize_dwarf2_read (void);
8780 _initialize_dwarf2_read (void)
8782 dwarf2_objfile_data_key
= register_objfile_data ();