1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 Free Software Foundation, Inc.
6 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
7 Inc. with support from Florida State University (under contract
8 with the Ada Joint Program Office), and Silicon Graphics, Inc.
9 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
10 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
11 support in dwarfread.c
13 This file is part of GDB.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or (at
18 your option) any later version.
20 This program is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. */
35 #include "elf/dwarf2.h"
38 #include "expression.h"
39 #include "filenames.h" /* for DOSish file names */
42 #include "complaints.h"
44 #include "dwarf2expr.h"
45 #include "dwarf2loc.h"
46 #include "cp-support.h"
50 #include "gdb_string.h"
51 #include "gdb_assert.h"
52 #include <sys/types.h>
54 /* A note on memory usage for this file.
56 At the present time, this code reads the debug info sections into
57 the objfile's objfile_obstack. A definite improvement for startup
58 time, on platforms which do not emit relocations for debug
59 sections, would be to use mmap instead. The object's complete
60 debug information is loaded into memory, partly to simplify
61 absolute DIE references.
63 Whether using obstacks or mmap, the sections should remain loaded
64 until the objfile is released, and pointers into the section data
65 can be used for any other data associated to the objfile (symbol
66 names, type names, location expressions to name a few). */
68 #ifndef DWARF2_REG_TO_REGNUM
69 #define DWARF2_REG_TO_REGNUM(REG) (REG)
73 /* .debug_info header for a compilation unit
74 Because of alignment constraints, this structure has padding and cannot
75 be mapped directly onto the beginning of the .debug_info section. */
76 typedef struct comp_unit_header
78 unsigned int length
; /* length of the .debug_info
80 unsigned short version
; /* version number -- 2 for DWARF
82 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
83 unsigned char addr_size
; /* byte size of an address -- 4 */
86 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
89 /* .debug_pubnames header
90 Because of alignment constraints, this structure has padding and cannot
91 be mapped directly onto the beginning of the .debug_info section. */
92 typedef struct pubnames_header
94 unsigned int length
; /* length of the .debug_pubnames
96 unsigned char version
; /* version number -- 2 for DWARF
98 unsigned int info_offset
; /* offset into .debug_info section */
99 unsigned int info_size
; /* byte size of .debug_info section
103 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
105 /* .debug_pubnames header
106 Because of alignment constraints, this structure has padding and cannot
107 be mapped directly onto the beginning of the .debug_info section. */
108 typedef struct aranges_header
110 unsigned int length
; /* byte len of the .debug_aranges
112 unsigned short version
; /* version number -- 2 for DWARF
114 unsigned int info_offset
; /* offset into .debug_info section */
115 unsigned char addr_size
; /* byte size of an address */
116 unsigned char seg_size
; /* byte size of segment descriptor */
119 #define _ACTUAL_ARANGES_HEADER_SIZE 12
121 /* .debug_line statement program prologue
122 Because of alignment constraints, this structure has padding and cannot
123 be mapped directly onto the beginning of the .debug_info section. */
124 typedef struct statement_prologue
126 unsigned int total_length
; /* byte length of the statement
128 unsigned short version
; /* version number -- 2 for DWARF
130 unsigned int prologue_length
; /* # bytes between prologue &
132 unsigned char minimum_instruction_length
; /* byte size of
134 unsigned char default_is_stmt
; /* initial value of is_stmt
137 unsigned char line_range
;
138 unsigned char opcode_base
; /* number assigned to first special
140 unsigned char *standard_opcode_lengths
;
144 static const struct objfile_data
*dwarf2_objfile_data_key
;
146 struct dwarf2_per_objfile
148 /* Sizes of debugging sections. */
149 unsigned int info_size
;
150 unsigned int abbrev_size
;
151 unsigned int line_size
;
152 unsigned int pubnames_size
;
153 unsigned int aranges_size
;
154 unsigned int loc_size
;
155 unsigned int macinfo_size
;
156 unsigned int str_size
;
157 unsigned int ranges_size
;
158 unsigned int frame_size
;
159 unsigned int eh_frame_size
;
161 /* Loaded data from the sections. */
166 char *macinfo_buffer
;
171 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
173 static asection
*dwarf_info_section
;
174 static asection
*dwarf_abbrev_section
;
175 static asection
*dwarf_line_section
;
176 static asection
*dwarf_pubnames_section
;
177 static asection
*dwarf_aranges_section
;
178 static asection
*dwarf_loc_section
;
179 static asection
*dwarf_macinfo_section
;
180 static asection
*dwarf_str_section
;
181 static asection
*dwarf_ranges_section
;
182 asection
*dwarf_frame_section
;
183 asection
*dwarf_eh_frame_section
;
185 /* names of the debugging sections */
187 #define INFO_SECTION ".debug_info"
188 #define ABBREV_SECTION ".debug_abbrev"
189 #define LINE_SECTION ".debug_line"
190 #define PUBNAMES_SECTION ".debug_pubnames"
191 #define ARANGES_SECTION ".debug_aranges"
192 #define LOC_SECTION ".debug_loc"
193 #define MACINFO_SECTION ".debug_macinfo"
194 #define STR_SECTION ".debug_str"
195 #define RANGES_SECTION ".debug_ranges"
196 #define FRAME_SECTION ".debug_frame"
197 #define EH_FRAME_SECTION ".eh_frame"
199 /* local data types */
201 /* We hold several abbreviation tables in memory at the same time. */
202 #ifndef ABBREV_HASH_SIZE
203 #define ABBREV_HASH_SIZE 121
206 /* The data in a compilation unit header, after target2host
207 translation, looks like this. */
208 struct comp_unit_head
210 unsigned long length
;
212 unsigned int abbrev_offset
;
213 unsigned char addr_size
;
214 unsigned char signed_addr_p
;
215 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
216 unsigned int initial_length_size
; /* size of the length field; either
219 /* Offset to the first byte of this compilation unit header in the
220 * .debug_info section, for resolving relative reference dies. */
224 /* Pointer to this compilation unit header in the .debug_info
229 /* Pointer to the first die of this compilatio unit. This will
230 * be the first byte following the compilation unit header. */
234 /* Pointer to the next compilation unit header in the program. */
236 struct comp_unit_head
*next
;
238 /* Base address of this compilation unit. */
240 CORE_ADDR base_address
;
242 /* Non-zero if base_address has been set. */
247 /* Internal state when decoding a particular compilation unit. */
250 /* The objfile containing this compilation unit. */
251 struct objfile
*objfile
;
253 /* The header of the compilation unit.
255 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
256 should logically be moved to the dwarf2_cu structure. */
257 struct comp_unit_head header
;
259 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
261 /* The language we are debugging. */
262 enum language language
;
263 const struct language_defn
*language_defn
;
265 /* The generic symbol table building routines have separate lists for
266 file scope symbols and all all other scopes (local scopes). So
267 we need to select the right one to pass to add_symbol_to_list().
268 We do it by keeping a pointer to the correct list in list_in_scope.
270 FIXME: The original dwarf code just treated the file scope as the
271 first local scope, and all other local scopes as nested local
272 scopes, and worked fine. Check to see if we really need to
273 distinguish these in buildsym.c. */
274 struct pending
**list_in_scope
;
276 /* Maintain an array of referenced fundamental types for the current
277 compilation unit being read. For DWARF version 1, we have to construct
278 the fundamental types on the fly, since no information about the
279 fundamental types is supplied. Each such fundamental type is created by
280 calling a language dependent routine to create the type, and then a
281 pointer to that type is then placed in the array at the index specified
282 by it's FT_<TYPENAME> value. The array has a fixed size set by the
283 FT_NUM_MEMBERS compile time constant, which is the number of predefined
284 fundamental types gdb knows how to construct. */
285 struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
287 /* DWARF abbreviation table associated with this compilation unit. */
288 struct abbrev_info
**dwarf2_abbrevs
;
290 /* Storage for the abbrev table. */
291 struct obstack abbrev_obstack
;
293 /* Hash table holding all the loaded partial DIEs. */
296 /* Storage for things with the same lifetime as this read-in compilation
297 unit, including partial DIEs. */
298 struct obstack comp_unit_obstack
;
300 /* This flag will be set if this compilation unit includes any
301 DW_TAG_namespace DIEs. If we know that there are explicit
302 DIEs for namespaces, we don't need to try to infer them
303 from mangled names. */
304 unsigned int has_namespace_info
: 1;
307 /* The line number information for a compilation unit (found in the
308 .debug_line section) begins with a "statement program header",
309 which contains the following information. */
312 unsigned int total_length
;
313 unsigned short version
;
314 unsigned int header_length
;
315 unsigned char minimum_instruction_length
;
316 unsigned char default_is_stmt
;
318 unsigned char line_range
;
319 unsigned char opcode_base
;
321 /* standard_opcode_lengths[i] is the number of operands for the
322 standard opcode whose value is i. This means that
323 standard_opcode_lengths[0] is unused, and the last meaningful
324 element is standard_opcode_lengths[opcode_base - 1]. */
325 unsigned char *standard_opcode_lengths
;
327 /* The include_directories table. NOTE! These strings are not
328 allocated with xmalloc; instead, they are pointers into
329 debug_line_buffer. If you try to free them, `free' will get
331 unsigned int num_include_dirs
, include_dirs_size
;
334 /* The file_names table. NOTE! These strings are not allocated
335 with xmalloc; instead, they are pointers into debug_line_buffer.
336 Don't try to free them directly. */
337 unsigned int num_file_names
, file_names_size
;
341 unsigned int dir_index
;
342 unsigned int mod_time
;
344 int included_p
; /* Non-zero if referenced by the Line Number Program. */
347 /* The start and end of the statement program following this
348 header. These point into dwarf2_per_objfile->line_buffer. */
349 char *statement_program_start
, *statement_program_end
;
352 /* When we construct a partial symbol table entry we only
353 need this much information. */
354 struct partial_die_info
356 /* Offset of this DIE. */
359 /* DWARF-2 tag for this DIE. */
360 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
362 /* Language code associated with this DIE. This is only used
363 for the compilation unit DIE. */
364 unsigned int language
: 8;
366 /* Assorted flags describing the data found in this DIE. */
367 unsigned int has_children
: 1;
368 unsigned int is_external
: 1;
369 unsigned int is_declaration
: 1;
370 unsigned int has_type
: 1;
371 unsigned int has_specification
: 1;
372 unsigned int has_stmt_list
: 1;
373 unsigned int has_pc_info
: 1;
375 /* Flag set if the SCOPE field of this structure has been
377 unsigned int scope_set
: 1;
379 /* The name of this DIE. Normally the value of DW_AT_name, but
380 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
384 /* The scope to prepend to our children. This is generally
385 allocated on the comp_unit_obstack, so will disappear
386 when this compilation unit leaves the cache. */
389 /* The location description associated with this DIE, if any. */
390 struct dwarf_block
*locdesc
;
392 /* If HAS_PC_INFO, the PC range associated with this DIE. */
396 /* Pointer into the info_buffer pointing at the target of
397 DW_AT_sibling, if any. */
400 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
401 DW_AT_specification (or DW_AT_abstract_origin or
403 unsigned int spec_offset
;
405 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
406 unsigned int line_offset
;
408 /* Pointers to this DIE's parent, first child, and next sibling,
410 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
413 /* This data structure holds the information of an abbrev. */
416 unsigned int number
; /* number identifying abbrev */
417 enum dwarf_tag tag
; /* dwarf tag */
418 unsigned short has_children
; /* boolean */
419 unsigned short num_attrs
; /* number of attributes */
420 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
421 struct abbrev_info
*next
; /* next in chain */
426 enum dwarf_attribute name
;
427 enum dwarf_form form
;
430 /* This data structure holds a complete die structure. */
433 enum dwarf_tag tag
; /* Tag indicating type of die */
434 unsigned int abbrev
; /* Abbrev number */
435 unsigned int offset
; /* Offset in .debug_info section */
436 unsigned int num_attrs
; /* Number of attributes */
437 struct attribute
*attrs
; /* An array of attributes */
438 struct die_info
*next_ref
; /* Next die in ref hash table */
440 /* The dies in a compilation unit form an n-ary tree. PARENT
441 points to this die's parent; CHILD points to the first child of
442 this node; and all the children of a given node are chained
443 together via their SIBLING fields, terminated by a die whose
445 struct die_info
*child
; /* Its first child, if any. */
446 struct die_info
*sibling
; /* Its next sibling, if any. */
447 struct die_info
*parent
; /* Its parent, if any. */
449 struct type
*type
; /* Cached type information */
452 /* Attributes have a name and a value */
455 enum dwarf_attribute name
;
456 enum dwarf_form form
;
460 struct dwarf_block
*blk
;
468 struct function_range
471 CORE_ADDR lowpc
, highpc
;
473 struct function_range
*next
;
476 /* Get at parts of an attribute structure */
478 #define DW_STRING(attr) ((attr)->u.str)
479 #define DW_UNSND(attr) ((attr)->u.unsnd)
480 #define DW_BLOCK(attr) ((attr)->u.blk)
481 #define DW_SND(attr) ((attr)->u.snd)
482 #define DW_ADDR(attr) ((attr)->u.addr)
484 /* Blocks are a bunch of untyped bytes. */
491 #ifndef ATTR_ALLOC_CHUNK
492 #define ATTR_ALLOC_CHUNK 4
495 /* A hash table of die offsets for following references. */
496 #ifndef REF_HASH_SIZE
497 #define REF_HASH_SIZE 1021
500 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
502 /* Allocate fields for structs, unions and enums in this size. */
503 #ifndef DW_FIELD_ALLOC_CHUNK
504 #define DW_FIELD_ALLOC_CHUNK 4
507 /* A zeroed version of a partial die for initialization purposes. */
508 static struct partial_die_info zeroed_partial_die
;
510 /* FIXME: decode_locdesc sets these variables to describe the location
511 to the caller. These ought to be a structure or something. If
512 none of the flags are set, the object lives at the address returned
513 by decode_locdesc. */
515 static int isreg
; /* Object lives in register.
516 decode_locdesc's return value is
517 the register number. */
519 /* We put a pointer to this structure in the read_symtab_private field
524 /* Offset in .debug_info for this compilation unit. */
526 unsigned long dwarf_info_offset
;
529 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
530 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
532 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
533 but this would require a corresponding change in unpack_field_as_long
535 static int bits_per_byte
= 8;
537 /* The routines that read and process dies for a C struct or C++ class
538 pass lists of data member fields and lists of member function fields
539 in an instance of a field_info structure, as defined below. */
542 /* List of data member and baseclasses fields. */
545 struct nextfield
*next
;
552 /* Number of fields. */
555 /* Number of baseclasses. */
558 /* Set if the accesibility of one of the fields is not public. */
559 int non_public_fields
;
561 /* Member function fields array, entries are allocated in the order they
562 are encountered in the object file. */
565 struct nextfnfield
*next
;
566 struct fn_field fnfield
;
570 /* Member function fieldlist array, contains name of possibly overloaded
571 member function, number of overloaded member functions and a pointer
572 to the head of the member function field chain. */
577 struct nextfnfield
*head
;
581 /* Number of entries in the fnfieldlists array. */
585 /* Various complaints about symbol reading that don't abort the process */
588 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
590 complaint (&symfile_complaints
,
591 "statement list doesn't fit in .debug_line section");
595 dwarf2_complex_location_expr_complaint (void)
597 complaint (&symfile_complaints
, "location expression too complex");
601 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
604 complaint (&symfile_complaints
,
605 "const value length mismatch for '%s', got %d, expected %d", arg1
,
610 dwarf2_macros_too_long_complaint (void)
612 complaint (&symfile_complaints
,
613 "macro info runs off end of `.debug_macinfo' section");
617 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
619 complaint (&symfile_complaints
,
620 "macro debug info contains a malformed macro definition:\n`%s'",
625 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
627 complaint (&symfile_complaints
,
628 "invalid attribute class or form for '%s' in '%s'", arg1
, arg2
);
631 /* local function prototypes */
633 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
636 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
639 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
642 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
643 struct partial_die_info
*,
644 struct partial_symtab
*);
646 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
648 static void scan_partial_symbols (struct partial_die_info
*,
649 CORE_ADDR
*, CORE_ADDR
*,
652 static void add_partial_symbol (struct partial_die_info
*,
655 static int pdi_needs_namespace (enum dwarf_tag tag
);
657 static void add_partial_namespace (struct partial_die_info
*pdi
,
658 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
659 struct dwarf2_cu
*cu
);
661 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
662 struct dwarf2_cu
*cu
);
664 static char *locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
667 struct dwarf2_cu
*cu
);
669 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
671 static void psymtab_to_symtab_1 (struct partial_symtab
*);
673 char *dwarf2_read_section (struct objfile
*, asection
*);
675 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
677 static void dwarf2_free_abbrev_table (void *);
679 static struct abbrev_info
*peek_die_abbrev (char *, int *, struct dwarf2_cu
*);
681 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
684 static struct partial_die_info
*load_partial_dies (bfd
*, char *, int,
687 static char *read_partial_die (struct partial_die_info
*,
688 struct abbrev_info
*abbrev
, unsigned int,
689 bfd
*, char *, struct dwarf2_cu
*);
691 static struct partial_die_info
*find_partial_die (unsigned long,
693 struct dwarf2_cu
**);
695 static void fixup_partial_die (struct partial_die_info
*,
698 static char *read_full_die (struct die_info
**, bfd
*, char *,
699 struct dwarf2_cu
*, int *);
701 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
702 bfd
*, char *, struct dwarf2_cu
*);
704 static char *read_attribute_value (struct attribute
*, unsigned,
705 bfd
*, char *, struct dwarf2_cu
*);
707 static unsigned int read_1_byte (bfd
*, char *);
709 static int read_1_signed_byte (bfd
*, char *);
711 static unsigned int read_2_bytes (bfd
*, char *);
713 static unsigned int read_4_bytes (bfd
*, char *);
715 static unsigned long read_8_bytes (bfd
*, char *);
717 static CORE_ADDR
read_address (bfd
*, char *ptr
, struct dwarf2_cu
*,
720 static LONGEST
read_initial_length (bfd
*, char *,
721 struct comp_unit_head
*, int *bytes_read
);
723 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
726 static char *read_n_bytes (bfd
*, char *, unsigned int);
728 static char *read_string (bfd
*, char *, unsigned int *);
730 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
733 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
735 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
737 static char *skip_leb128 (bfd
*, char *);
739 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
741 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
744 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
745 struct dwarf2_cu
*cu
);
747 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
749 static struct die_info
*die_specification (struct die_info
*die
,
752 static void free_line_header (struct line_header
*lh
);
754 static void add_file_name (struct line_header
*, char *, unsigned int,
755 unsigned int, unsigned int);
757 static struct line_header
*(dwarf_decode_line_header
758 (unsigned int offset
,
759 bfd
*abfd
, struct dwarf2_cu
*cu
));
761 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
762 struct dwarf2_cu
*, struct partial_symtab
*);
764 static void dwarf2_start_subfile (char *, char *);
766 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
769 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
772 static void dwarf2_const_value_data (struct attribute
*attr
,
776 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
778 static struct type
*die_containing_type (struct die_info
*,
782 static struct type
*type_at_offset (unsigned int, struct objfile
*);
785 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
787 static void read_type_die (struct die_info
*, struct dwarf2_cu
*);
789 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
791 static char *typename_concat (const char *prefix
, const char *suffix
);
793 static void read_typedef (struct die_info
*, struct dwarf2_cu
*);
795 static void read_base_type (struct die_info
*, struct dwarf2_cu
*);
797 static void read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
799 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
801 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
803 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
805 static int dwarf2_get_pc_bounds (struct die_info
*,
806 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
808 static void get_scope_pc_bounds (struct die_info
*,
809 CORE_ADDR
*, CORE_ADDR
*,
812 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
815 static void dwarf2_attach_fields_to_type (struct field_info
*,
816 struct type
*, struct dwarf2_cu
*);
818 static void dwarf2_add_member_fn (struct field_info
*,
819 struct die_info
*, struct type
*,
822 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
823 struct type
*, struct dwarf2_cu
*);
825 static void read_structure_type (struct die_info
*, struct dwarf2_cu
*);
827 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
829 static char *determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
831 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
833 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
835 static const char *namespace_name (struct die_info
*die
,
836 int *is_anonymous
, struct dwarf2_cu
*);
838 static void read_enumeration_type (struct die_info
*, struct dwarf2_cu
*);
840 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
842 static struct type
*dwarf_base_type (int, int, struct dwarf2_cu
*);
844 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
846 static void read_array_type (struct die_info
*, struct dwarf2_cu
*);
848 static void read_tag_pointer_type (struct die_info
*, struct dwarf2_cu
*);
850 static void read_tag_ptr_to_member_type (struct die_info
*,
853 static void read_tag_reference_type (struct die_info
*, struct dwarf2_cu
*);
855 static void read_tag_const_type (struct die_info
*, struct dwarf2_cu
*);
857 static void read_tag_volatile_type (struct die_info
*, struct dwarf2_cu
*);
859 static void read_tag_string_type (struct die_info
*, struct dwarf2_cu
*);
861 static void read_subroutine_type (struct die_info
*, struct dwarf2_cu
*);
863 static struct die_info
*read_comp_unit (char *, bfd
*, struct dwarf2_cu
*);
865 static struct die_info
*read_die_and_children (char *info_ptr
, bfd
*abfd
,
868 struct die_info
*parent
);
870 static struct die_info
*read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
873 struct die_info
*parent
);
875 static void free_die_list (struct die_info
*);
877 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
879 static void process_die (struct die_info
*, struct dwarf2_cu
*);
881 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
883 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
885 static struct die_info
*dwarf2_extension (struct die_info
*die
,
888 static char *dwarf_tag_name (unsigned int);
890 static char *dwarf_attr_name (unsigned int);
892 static char *dwarf_form_name (unsigned int);
894 static char *dwarf_stack_op_name (unsigned int);
896 static char *dwarf_bool_name (unsigned int);
898 static char *dwarf_type_encoding_name (unsigned int);
901 static char *dwarf_cfi_name (unsigned int);
903 struct die_info
*copy_die (struct die_info
*);
906 static struct die_info
*sibling_die (struct die_info
*);
908 static void dump_die (struct die_info
*);
910 static void dump_die_list (struct die_info
*);
912 static void store_in_ref_table (unsigned int, struct die_info
*);
914 static void dwarf2_empty_hash_tables (void);
916 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
919 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
921 static struct die_info
*follow_die_ref (unsigned int);
923 static struct type
*dwarf2_fundamental_type (struct objfile
*, int,
926 /* memory allocation interface */
928 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
930 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
932 static struct die_info
*dwarf_alloc_die (void);
934 static void initialize_cu_func_list (struct dwarf2_cu
*);
936 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
939 static void dwarf_decode_macros (struct line_header
*, unsigned int,
940 char *, bfd
*, struct dwarf2_cu
*);
942 static int attr_form_is_block (struct attribute
*);
945 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
946 struct dwarf2_cu
*cu
);
948 static char *skip_one_die (char *info_ptr
, struct abbrev_info
*abbrev
,
949 struct dwarf2_cu
*cu
);
951 static void free_stack_comp_unit (void *);
953 static void *hashtab_obstack_allocate (void *data
, size_t size
, size_t count
);
955 static void dummy_obstack_deallocate (void *object
, void *data
);
957 static hashval_t
partial_die_hash (const void *item
);
959 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
961 /* Try to locate the sections we need for DWARF 2 debugging
962 information and return true if we have enough to do something. */
965 dwarf2_has_info (struct objfile
*objfile
)
967 struct dwarf2_per_objfile
*data
;
969 /* Initialize per-objfile state. */
970 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
971 memset (data
, 0, sizeof (*data
));
972 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
973 dwarf2_per_objfile
= data
;
975 dwarf_info_section
= 0;
976 dwarf_abbrev_section
= 0;
977 dwarf_line_section
= 0;
978 dwarf_str_section
= 0;
979 dwarf_macinfo_section
= 0;
980 dwarf_frame_section
= 0;
981 dwarf_eh_frame_section
= 0;
982 dwarf_ranges_section
= 0;
983 dwarf_loc_section
= 0;
985 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
986 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
989 /* This function is mapped across the sections and remembers the
990 offset and size of each of the debugging sections we are interested
994 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
996 if (strcmp (sectp
->name
, INFO_SECTION
) == 0)
998 dwarf2_per_objfile
->info_size
= bfd_get_section_size_before_reloc (sectp
);
999 dwarf_info_section
= sectp
;
1001 else if (strcmp (sectp
->name
, ABBREV_SECTION
) == 0)
1003 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
1004 dwarf_abbrev_section
= sectp
;
1006 else if (strcmp (sectp
->name
, LINE_SECTION
) == 0)
1008 dwarf2_per_objfile
->line_size
= bfd_get_section_size_before_reloc (sectp
);
1009 dwarf_line_section
= sectp
;
1011 else if (strcmp (sectp
->name
, PUBNAMES_SECTION
) == 0)
1013 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
1014 dwarf_pubnames_section
= sectp
;
1016 else if (strcmp (sectp
->name
, ARANGES_SECTION
) == 0)
1018 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size_before_reloc (sectp
);
1019 dwarf_aranges_section
= sectp
;
1021 else if (strcmp (sectp
->name
, LOC_SECTION
) == 0)
1023 dwarf2_per_objfile
->loc_size
= bfd_get_section_size_before_reloc (sectp
);
1024 dwarf_loc_section
= sectp
;
1026 else if (strcmp (sectp
->name
, MACINFO_SECTION
) == 0)
1028 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
1029 dwarf_macinfo_section
= sectp
;
1031 else if (strcmp (sectp
->name
, STR_SECTION
) == 0)
1033 dwarf2_per_objfile
->str_size
= bfd_get_section_size_before_reloc (sectp
);
1034 dwarf_str_section
= sectp
;
1036 else if (strcmp (sectp
->name
, FRAME_SECTION
) == 0)
1038 dwarf2_per_objfile
->frame_size
= bfd_get_section_size_before_reloc (sectp
);
1039 dwarf_frame_section
= sectp
;
1041 else if (strcmp (sectp
->name
, EH_FRAME_SECTION
) == 0)
1043 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1044 if (aflag
& SEC_HAS_CONTENTS
)
1046 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1047 dwarf_eh_frame_section
= sectp
;
1050 else if (strcmp (sectp
->name
, RANGES_SECTION
) == 0)
1052 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size_before_reloc (sectp
);
1053 dwarf_ranges_section
= sectp
;
1057 /* Build a partial symbol table. */
1060 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1062 /* We definitely need the .debug_info and .debug_abbrev sections */
1064 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1065 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1067 if (dwarf_line_section
)
1068 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1070 dwarf2_per_objfile
->line_buffer
= NULL
;
1072 if (dwarf_str_section
)
1073 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1075 dwarf2_per_objfile
->str_buffer
= NULL
;
1077 if (dwarf_macinfo_section
)
1078 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1079 dwarf_macinfo_section
);
1081 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1083 if (dwarf_ranges_section
)
1084 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1086 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1088 if (dwarf_loc_section
)
1089 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1091 dwarf2_per_objfile
->loc_buffer
= NULL
;
1094 || (objfile
->global_psymbols
.size
== 0
1095 && objfile
->static_psymbols
.size
== 0))
1097 init_psymbol_list (objfile
, 1024);
1101 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1103 /* Things are significantly easier if we have .debug_aranges and
1104 .debug_pubnames sections */
1106 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1110 /* only test this case for now */
1112 /* In this case we have to work a bit harder */
1113 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1118 /* Build the partial symbol table from the information in the
1119 .debug_pubnames and .debug_aranges sections. */
1122 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1124 bfd
*abfd
= objfile
->obfd
;
1125 char *aranges_buffer
, *pubnames_buffer
;
1126 char *aranges_ptr
, *pubnames_ptr
;
1127 unsigned int entry_length
, version
, info_offset
, info_size
;
1129 pubnames_buffer
= dwarf2_read_section (objfile
,
1130 dwarf_pubnames_section
);
1131 pubnames_ptr
= pubnames_buffer
;
1132 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1134 struct comp_unit_head cu_header
;
1137 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1139 pubnames_ptr
+= bytes_read
;
1140 version
= read_1_byte (abfd
, pubnames_ptr
);
1142 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1144 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1148 aranges_buffer
= dwarf2_read_section (objfile
,
1149 dwarf_aranges_section
);
1154 /* Read in the comp unit header information from the debug_info at
1158 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1159 char *info_ptr
, bfd
*abfd
)
1163 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1165 info_ptr
+= bytes_read
;
1166 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1168 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1170 info_ptr
+= bytes_read
;
1171 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1173 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1174 if (signed_addr
< 0)
1175 internal_error (__FILE__
, __LINE__
,
1176 "read_comp_unit_head: dwarf from non elf file");
1177 cu_header
->signed_addr_p
= signed_addr
;
1182 partial_read_comp_unit_head (struct comp_unit_head
*header
, char *info_ptr
,
1185 char *beg_of_comp_unit
= info_ptr
;
1187 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1189 if (header
->version
!= 2)
1190 error ("Dwarf Error: wrong version in compilation unit header "
1191 "(is %d, should be %d) [in module %s]", header
->version
,
1192 2, bfd_get_filename (abfd
));
1194 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1195 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1196 "(offset 0x%lx + 6) [in module %s]",
1197 (long) header
->abbrev_offset
,
1198 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1199 bfd_get_filename (abfd
));
1201 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1202 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1203 error ("Dwarf Error: bad length (0x%lx) in compilation unit header "
1204 "(offset 0x%lx + 0) [in module %s]",
1205 (long) header
->length
,
1206 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1207 bfd_get_filename (abfd
));
1212 /* Allocate a new partial symtab for file named NAME and mark this new
1213 partial symtab as being an include of PST. */
1216 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1217 struct objfile
*objfile
)
1219 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1221 subpst
->section_offsets
= pst
->section_offsets
;
1222 subpst
->textlow
= 0;
1223 subpst
->texthigh
= 0;
1225 subpst
->dependencies
= (struct partial_symtab
**)
1226 obstack_alloc (&objfile
->objfile_obstack
,
1227 sizeof (struct partial_symtab
*));
1228 subpst
->dependencies
[0] = pst
;
1229 subpst
->number_of_dependencies
= 1;
1231 subpst
->globals_offset
= 0;
1232 subpst
->n_global_syms
= 0;
1233 subpst
->statics_offset
= 0;
1234 subpst
->n_static_syms
= 0;
1235 subpst
->symtab
= NULL
;
1236 subpst
->read_symtab
= pst
->read_symtab
;
1239 /* No private part is necessary for include psymtabs. This property
1240 can be used to differentiate between such include psymtabs and
1241 the regular ones. If it ever happens that a regular psymtab can
1242 legitimally have a NULL private part, then we'll have to add a
1243 dedicated field for that in the dwarf2_pinfo structure. */
1244 subpst
->read_symtab_private
= NULL
;
1247 /* Read the Line Number Program data and extract the list of files
1248 included by the source file represented by PST. Build an include
1249 partial symtab for each of these included files.
1251 This procedure assumes that there *is* a Line Number Program in
1252 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1253 before calling this procedure. */
1256 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1257 struct partial_die_info
*pdi
,
1258 struct partial_symtab
*pst
)
1260 struct objfile
*objfile
= cu
->objfile
;
1261 bfd
*abfd
= objfile
->obfd
;
1262 struct line_header
*lh
;
1264 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1266 return; /* No linetable, so no includes. */
1268 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1270 free_line_header (lh
);
1274 /* Build the partial symbol table by doing a quick pass through the
1275 .debug_info and .debug_abbrev sections. */
1278 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1280 /* Instead of reading this into a big buffer, we should probably use
1281 mmap() on architectures that support it. (FIXME) */
1282 bfd
*abfd
= objfile
->obfd
;
1284 char *beg_of_comp_unit
;
1285 struct partial_die_info comp_unit_die
;
1286 struct partial_symtab
*pst
;
1287 CORE_ADDR lowpc
, highpc
, baseaddr
;
1289 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1291 /* Since the objects we're extracting from .debug_info vary in
1292 length, only the individual functions to extract them (like
1293 read_comp_unit_head and load_partial_die) can really know whether
1294 the buffer is large enough to hold another complete object.
1296 At the moment, they don't actually check that. If .debug_info
1297 holds just one extra byte after the last compilation unit's dies,
1298 then read_comp_unit_head will happily read off the end of the
1299 buffer. read_partial_die is similarly casual. Those functions
1302 For this loop condition, simply checking whether there's any data
1303 left at all should be sufficient. */
1304 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1305 + dwarf2_per_objfile
->info_size
))
1307 struct cleanup
*back_to_inner
;
1308 struct dwarf2_cu cu
;
1309 struct abbrev_info
*abbrev
;
1310 unsigned int bytes_read
;
1311 struct dwarf2_per_cu_data
*this_cu
;
1313 beg_of_comp_unit
= info_ptr
;
1315 memset (&cu
, 0, sizeof (cu
));
1317 obstack_init (&cu
.comp_unit_obstack
);
1319 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1321 cu
.objfile
= objfile
;
1322 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1324 /* Complete the cu_header */
1325 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1326 cu
.header
.first_die_ptr
= info_ptr
;
1327 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1329 cu
.list_in_scope
= &file_symbols
;
1331 cu
.partial_dies
= NULL
;
1333 /* Read the abbrevs for this compilation unit into a table */
1334 dwarf2_read_abbrevs (abfd
, &cu
);
1335 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1337 /* Read the compilation unit die */
1338 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1339 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1340 abfd
, info_ptr
, &cu
);
1342 /* Set the language we're debugging */
1343 set_cu_language (comp_unit_die
.language
, &cu
);
1345 /* Allocate a new partial symbol table structure */
1346 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1347 comp_unit_die
.name
? comp_unit_die
.name
: "",
1348 comp_unit_die
.lowpc
,
1349 objfile
->global_psymbols
.next
,
1350 objfile
->static_psymbols
.next
);
1352 pst
->read_symtab_private
= (char *)
1353 obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct dwarf2_pinfo
));
1354 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1355 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1357 /* Store the function that reads in the rest of the symbol table */
1358 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1360 /* Check if comp unit has_children.
1361 If so, read the rest of the partial symbols from this comp unit.
1362 If not, there's no more debug_info for this comp unit. */
1363 if (comp_unit_die
.has_children
)
1365 struct partial_die_info
*first_die
;
1367 lowpc
= ((CORE_ADDR
) -1);
1368 highpc
= ((CORE_ADDR
) 0);
1370 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1372 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1374 /* If we didn't find a lowpc, set it to highpc to avoid
1375 complaints from `maint check'. */
1376 if (lowpc
== ((CORE_ADDR
) -1))
1379 /* If the compilation unit didn't have an explicit address range,
1380 then use the information extracted from its child dies. */
1381 if (! comp_unit_die
.has_pc_info
)
1383 comp_unit_die
.lowpc
= lowpc
;
1384 comp_unit_die
.highpc
= highpc
;
1387 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1388 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1390 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1391 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1392 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1393 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1394 sort_pst_symbols (pst
);
1396 /* If there is already a psymtab or symtab for a file of this
1397 name, remove it. (If there is a symtab, more drastic things
1398 also happen.) This happens in VxWorks. */
1399 free_named_symtabs (pst
->filename
);
1401 if (comp_unit_die
.has_stmt_list
)
1403 /* Get the list of files included in the current compilation unit,
1404 and build a psymtab for each of them. */
1405 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1408 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1409 + cu
.header
.initial_length_size
;
1411 do_cleanups (back_to_inner
);
1415 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1416 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1420 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1421 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1423 struct objfile
*objfile
= cu
->objfile
;
1424 bfd
*abfd
= objfile
->obfd
;
1425 struct partial_die_info
*pdi
;
1427 /* Now, march along the PDI's, descending into ones which have
1428 interesting children but skipping the children of the other ones,
1429 until we reach the end of the compilation unit. */
1435 fixup_partial_die (pdi
, cu
);
1437 /* Anonymous namespaces have no name but have interesting
1438 children, so we need to look at them. Ditto for anonymous
1441 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1442 || pdi
->tag
== DW_TAG_enumeration_type
)
1446 case DW_TAG_subprogram
:
1447 if (pdi
->has_pc_info
)
1449 if (pdi
->lowpc
< *lowpc
)
1451 *lowpc
= pdi
->lowpc
;
1453 if (pdi
->highpc
> *highpc
)
1455 *highpc
= pdi
->highpc
;
1457 if (!pdi
->is_declaration
)
1459 add_partial_symbol (pdi
, cu
);
1463 case DW_TAG_variable
:
1464 case DW_TAG_typedef
:
1465 case DW_TAG_union_type
:
1466 if (!pdi
->is_declaration
)
1468 add_partial_symbol (pdi
, cu
);
1471 case DW_TAG_class_type
:
1472 case DW_TAG_structure_type
:
1473 if (!pdi
->is_declaration
)
1475 add_partial_symbol (pdi
, cu
);
1478 case DW_TAG_enumeration_type
:
1479 if (!pdi
->is_declaration
)
1480 add_partial_enumeration (pdi
, cu
);
1482 case DW_TAG_base_type
:
1483 case DW_TAG_subrange_type
:
1484 /* File scope base type definitions are added to the partial
1486 add_partial_symbol (pdi
, cu
);
1488 case DW_TAG_namespace
:
1489 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1496 /* If the die has a sibling, skip to the sibling. */
1498 pdi
= pdi
->die_sibling
;
1502 /* Functions used to compute the fully scoped name of a partial DIE.
1504 Normally, this is simple. For C++, the parent DIE's fully scoped
1505 name is concatenated with "::" and the partial DIE's name.
1506 Enumerators are an exception; they use the scope of their parent
1507 enumeration type, i.e. the name of the enumeration type is not
1508 prepended to the enumerator.
1510 There are two complexities. One is DW_AT_specification; in this
1511 case "parent" means the parent of the target of the specification,
1512 instead of the direct parent of the DIE. The other is compilers
1513 which do not emit DW_TAG_namespace; in this case we try to guess
1514 the fully qualified name of structure types from their members'
1515 linkage names. This must be done using the DIE's children rather
1516 than the children of any DW_AT_specification target. We only need
1517 to do this for structures at the top level, i.e. if the target of
1518 any DW_AT_specification (if any; otherwise the DIE itself) does not
1521 /* Compute the scope prefix associated with PDI's parent, in
1522 compilation unit CU. The result will be allocated on CU's
1523 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1524 field. NULL is returned if no prefix is necessary. */
1526 partial_die_parent_scope (struct partial_die_info
*pdi
,
1527 struct dwarf2_cu
*cu
)
1529 char *grandparent_scope
;
1530 struct partial_die_info
*parent
, *real_pdi
;
1531 struct dwarf2_cu
*spec_cu
;
1533 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1534 then this means the parent of the specification DIE. */
1538 while (real_pdi
->has_specification
)
1539 real_pdi
= find_partial_die (real_pdi
->spec_offset
, spec_cu
, &spec_cu
);
1541 parent
= real_pdi
->die_parent
;
1545 if (parent
->scope_set
)
1546 return parent
->scope
;
1548 fixup_partial_die (parent
, cu
);
1550 grandparent_scope
= partial_die_parent_scope (parent
, spec_cu
);
1552 if (parent
->tag
== DW_TAG_namespace
1553 || parent
->tag
== DW_TAG_structure_type
1554 || parent
->tag
== DW_TAG_class_type
1555 || parent
->tag
== DW_TAG_union_type
)
1557 if (grandparent_scope
== NULL
)
1558 parent
->scope
= parent
->name
;
1560 parent
->scope
= obconcat (&cu
->comp_unit_obstack
, grandparent_scope
,
1561 "::", parent
->name
);
1563 else if (parent
->tag
== DW_TAG_enumeration_type
)
1564 /* Enumerators should not get the name of the enumeration as a prefix. */
1565 parent
->scope
= grandparent_scope
;
1568 /* FIXME drow/2004-04-01: What should we be doing with
1569 function-local names? For partial symbols, we should probably be
1571 complaint (&symfile_complaints
,
1572 "unhandled containing DIE tag %d for DIE at %d",
1573 parent
->tag
, pdi
->offset
);
1574 parent
->scope
= grandparent_scope
;
1577 parent
->scope_set
= 1;
1578 return parent
->scope
;
1581 /* Return the fully scoped name associated with PDI, from compilation unit
1582 CU. The result will be allocated with malloc. */
1584 partial_die_full_name (struct partial_die_info
*pdi
,
1585 struct dwarf2_cu
*cu
)
1589 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1590 if (parent_scope
== NULL
)
1593 return concat (parent_scope
, "::", pdi
->name
, NULL
);
1597 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1599 struct objfile
*objfile
= cu
->objfile
;
1602 const char *my_prefix
;
1603 const struct partial_symbol
*psym
= NULL
;
1605 int built_actual_name
= 0;
1607 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1611 if (pdi_needs_namespace (pdi
->tag
))
1613 actual_name
= partial_die_full_name (pdi
, cu
);
1615 built_actual_name
= 1;
1618 if (actual_name
== NULL
)
1619 actual_name
= pdi
->name
;
1623 case DW_TAG_subprogram
:
1624 if (pdi
->is_external
)
1626 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1627 mst_text, objfile); */
1628 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1629 VAR_DOMAIN
, LOC_BLOCK
,
1630 &objfile
->global_psymbols
,
1631 0, pdi
->lowpc
+ baseaddr
,
1632 cu
->language
, objfile
);
1636 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1637 mst_file_text, objfile); */
1638 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1639 VAR_DOMAIN
, LOC_BLOCK
,
1640 &objfile
->static_psymbols
,
1641 0, pdi
->lowpc
+ baseaddr
,
1642 cu
->language
, objfile
);
1645 case DW_TAG_variable
:
1646 if (pdi
->is_external
)
1649 Don't enter into the minimal symbol tables as there is
1650 a minimal symbol table entry from the ELF symbols already.
1651 Enter into partial symbol table if it has a location
1652 descriptor or a type.
1653 If the location descriptor is missing, new_symbol will create
1654 a LOC_UNRESOLVED symbol, the address of the variable will then
1655 be determined from the minimal symbol table whenever the variable
1657 The address for the partial symbol table entry is not
1658 used by GDB, but it comes in handy for debugging partial symbol
1662 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1663 if (pdi
->locdesc
|| pdi
->has_type
)
1664 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1665 VAR_DOMAIN
, LOC_STATIC
,
1666 &objfile
->global_psymbols
,
1668 cu
->language
, objfile
);
1672 /* Static Variable. Skip symbols without location descriptors. */
1673 if (pdi
->locdesc
== NULL
)
1675 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1676 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1677 mst_file_data, objfile); */
1678 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1679 VAR_DOMAIN
, LOC_STATIC
,
1680 &objfile
->static_psymbols
,
1682 cu
->language
, objfile
);
1685 case DW_TAG_typedef
:
1686 case DW_TAG_base_type
:
1687 case DW_TAG_subrange_type
:
1688 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1689 VAR_DOMAIN
, LOC_TYPEDEF
,
1690 &objfile
->static_psymbols
,
1691 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1693 case DW_TAG_namespace
:
1694 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1695 VAR_DOMAIN
, LOC_TYPEDEF
,
1696 &objfile
->global_psymbols
,
1697 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1699 case DW_TAG_class_type
:
1700 case DW_TAG_structure_type
:
1701 case DW_TAG_union_type
:
1702 case DW_TAG_enumeration_type
:
1703 /* Skip aggregate types without children, these are external
1705 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1706 static vs. global. */
1707 if (pdi
->has_children
== 0)
1709 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1710 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1711 cu
->language
== language_cplus
1712 ? &objfile
->global_psymbols
1713 : &objfile
->static_psymbols
,
1714 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1716 if (cu
->language
== language_cplus
)
1718 /* For C++, these implicitly act as typedefs as well. */
1719 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1720 VAR_DOMAIN
, LOC_TYPEDEF
,
1721 &objfile
->global_psymbols
,
1722 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1725 case DW_TAG_enumerator
:
1726 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1727 VAR_DOMAIN
, LOC_CONST
,
1728 cu
->language
== language_cplus
1729 ? &objfile
->global_psymbols
1730 : &objfile
->static_psymbols
,
1731 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1737 /* Check to see if we should scan the name for possible namespace
1738 info. Only do this if this is C++, if we don't have namespace
1739 debugging info in the file, if the psym is of an appropriate type
1740 (otherwise we'll have psym == NULL), and if we actually had a
1741 mangled name to begin with. */
1743 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
1744 cases which do not set PSYM above? */
1746 if (cu
->language
== language_cplus
1747 && cu
->has_namespace_info
== 0
1749 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
1750 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
1753 if (built_actual_name
)
1754 xfree (actual_name
);
1757 /* Determine whether a die of type TAG living in a C++ class or
1758 namespace needs to have the name of the scope prepended to the
1759 name listed in the die. */
1762 pdi_needs_namespace (enum dwarf_tag tag
)
1766 case DW_TAG_namespace
:
1767 case DW_TAG_typedef
:
1768 case DW_TAG_class_type
:
1769 case DW_TAG_structure_type
:
1770 case DW_TAG_union_type
:
1771 case DW_TAG_enumeration_type
:
1772 case DW_TAG_enumerator
:
1779 /* Read a partial die corresponding to a namespace; also, add a symbol
1780 corresponding to that namespace to the symbol table. NAMESPACE is
1781 the name of the enclosing namespace. */
1784 add_partial_namespace (struct partial_die_info
*pdi
,
1785 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1786 struct dwarf2_cu
*cu
)
1788 struct objfile
*objfile
= cu
->objfile
;
1790 /* Add a symbol for the namespace. */
1792 add_partial_symbol (pdi
, cu
);
1794 /* Now scan partial symbols in that namespace. */
1796 if (pdi
->has_children
)
1797 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
1800 /* See if we can figure out if the class lives in a namespace. We do
1801 this by looking for a member function; its demangled name will
1802 contain namespace info, if there is any. */
1805 guess_structure_name (struct partial_die_info
*struct_pdi
,
1806 struct dwarf2_cu
*cu
)
1808 if (cu
->language
== language_cplus
1809 && cu
->has_namespace_info
== 0
1810 && struct_pdi
->has_children
)
1812 /* NOTE: carlton/2003-10-07: Getting the info this way changes
1813 what template types look like, because the demangler
1814 frequently doesn't give the same name as the debug info. We
1815 could fix this by only using the demangled name to get the
1816 prefix (but see comment in read_structure_type). */
1818 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
1819 struct partial_die_info
*real_pdi
;
1820 struct dwarf2_cu
*spec_cu
;
1822 /* If this DIE (this DIE's specification, if any) has a parent, then
1823 we should not do this. We'll prepend the parent's fully qualified
1824 name when we create the partial symbol. */
1826 real_pdi
= struct_pdi
;
1828 while (real_pdi
->has_specification
)
1829 real_pdi
= find_partial_die (real_pdi
->spec_offset
, spec_cu
, &spec_cu
);
1831 if (real_pdi
->die_parent
!= NULL
)
1834 while (child_pdi
!= NULL
)
1836 if (child_pdi
->tag
== DW_TAG_subprogram
)
1838 char *actual_class_name
1839 = class_name_from_physname (child_pdi
->name
);
1840 if (actual_class_name
!= NULL
)
1843 = obsavestring (actual_class_name
,
1844 strlen (actual_class_name
),
1845 &cu
->comp_unit_obstack
);
1846 xfree (actual_class_name
);
1851 child_pdi
= child_pdi
->die_sibling
;
1856 /* Read a partial die corresponding to an enumeration type. */
1859 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1860 struct dwarf2_cu
*cu
)
1862 struct objfile
*objfile
= cu
->objfile
;
1863 bfd
*abfd
= objfile
->obfd
;
1864 struct partial_die_info
*pdi
;
1866 if (enum_pdi
->name
!= NULL
)
1867 add_partial_symbol (enum_pdi
, cu
);
1869 pdi
= enum_pdi
->die_child
;
1872 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
1873 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
1875 add_partial_symbol (pdi
, cu
);
1876 pdi
= pdi
->die_sibling
;
1880 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
1881 Return the corresponding abbrev, or NULL if the number is zero (indicating
1882 an empty DIE). In either case *BYTES_READ will be set to the length of
1883 the initial number. */
1885 static struct abbrev_info
*
1886 peek_die_abbrev (char *info_ptr
, int *bytes_read
, struct dwarf2_cu
*cu
)
1888 bfd
*abfd
= cu
->objfile
->obfd
;
1889 unsigned int abbrev_number
;
1890 struct abbrev_info
*abbrev
;
1892 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
1894 if (abbrev_number
== 0)
1897 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
1900 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
1901 bfd_get_filename (abfd
));
1907 /* Scan the debug information for CU starting at INFO_PTR. Returns a
1908 pointer to the end of a series of DIEs, terminated by an empty
1909 DIE. Any children of the skipped DIEs will also be skipped. */
1912 skip_children (char *info_ptr
, struct dwarf2_cu
*cu
)
1914 struct abbrev_info
*abbrev
;
1915 unsigned int bytes_read
;
1919 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1921 return info_ptr
+ bytes_read
;
1923 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
1927 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
1928 should point just after the initial uleb128 of a DIE, and the
1929 abbrev corresponding to that skipped uleb128 should be passed in
1930 ABBREV. Returns a pointer to this DIE's sibling, skipping any
1934 skip_one_die (char *info_ptr
, struct abbrev_info
*abbrev
,
1935 struct dwarf2_cu
*cu
)
1937 unsigned int bytes_read
;
1938 struct attribute attr
;
1939 bfd
*abfd
= cu
->objfile
->obfd
;
1940 unsigned int form
, i
;
1942 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
1944 /* The only abbrev we care about is DW_AT_sibling. */
1945 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
1947 read_attribute (&attr
, &abbrev
->attrs
[i
],
1948 abfd
, info_ptr
, cu
);
1949 if (attr
.form
== DW_FORM_ref_addr
)
1950 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
1952 return dwarf2_per_objfile
->info_buffer
1953 + dwarf2_get_ref_die_offset (&attr
, cu
);
1956 /* If it isn't DW_AT_sibling, skip this attribute. */
1957 form
= abbrev
->attrs
[i
].form
;
1962 case DW_FORM_ref_addr
:
1963 info_ptr
+= cu
->header
.addr_size
;
1982 case DW_FORM_string
:
1983 read_string (abfd
, info_ptr
, &bytes_read
);
1984 info_ptr
+= bytes_read
;
1987 info_ptr
+= cu
->header
.offset_size
;
1990 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
1991 info_ptr
+= bytes_read
;
1993 case DW_FORM_block1
:
1994 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
1996 case DW_FORM_block2
:
1997 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
1999 case DW_FORM_block4
:
2000 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2004 case DW_FORM_ref_udata
:
2005 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2007 case DW_FORM_indirect
:
2008 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2009 info_ptr
+= bytes_read
;
2010 /* We need to continue parsing from here, so just go back to
2012 goto skip_attribute
;
2015 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
2016 dwarf_form_name (form
),
2017 bfd_get_filename (abfd
));
2021 if (abbrev
->has_children
)
2022 return skip_children (info_ptr
, cu
);
2027 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2028 the next DIE after ORIG_PDI. */
2031 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, char *info_ptr
,
2032 bfd
*abfd
, struct dwarf2_cu
*cu
)
2034 /* Do we know the sibling already? */
2036 if (orig_pdi
->sibling
)
2037 return orig_pdi
->sibling
;
2039 /* Are there any children to deal with? */
2041 if (!orig_pdi
->has_children
)
2044 /* Skip the children the long way. */
2046 return skip_children (info_ptr
, cu
);
2049 /* Expand this partial symbol table into a full symbol table. */
2052 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2054 /* FIXME: This is barely more than a stub. */
2059 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
2065 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
2066 gdb_flush (gdb_stdout
);
2069 psymtab_to_symtab_1 (pst
);
2071 /* Finish up the debug error message. */
2073 printf_filtered ("done.\n");
2079 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2081 struct objfile
*objfile
= pst
->objfile
;
2082 bfd
*abfd
= objfile
->obfd
;
2083 struct dwarf2_cu cu
;
2084 struct die_info
*dies
;
2085 unsigned long offset
;
2086 CORE_ADDR lowpc
, highpc
;
2087 struct die_info
*child_die
;
2089 struct symtab
*symtab
;
2090 struct cleanup
*back_to
;
2091 struct attribute
*attr
;
2095 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2096 if (!pst
->dependencies
[i
]->readin
)
2098 /* Inform about additional files that need to be read in. */
2101 fputs_filtered (" ", gdb_stdout
);
2103 fputs_filtered ("and ", gdb_stdout
);
2105 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2106 wrap_here (""); /* Flush output */
2107 gdb_flush (gdb_stdout
);
2109 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2112 if (pst
->read_symtab_private
== NULL
)
2114 /* It's an include file, no symbols to read for it.
2115 Everything is in the parent symtab. */
2120 dwarf2_per_objfile
= objfile_data (pst
->objfile
, dwarf2_objfile_data_key
);
2122 /* Set local variables from the partial symbol table info. */
2123 offset
= DWARF_INFO_OFFSET (pst
);
2125 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2126 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2128 /* We're in the global namespace. */
2129 processing_current_prefix
= "";
2131 obstack_init (&cu
.comp_unit_obstack
);
2132 back_to
= make_cleanup (free_stack_comp_unit
, &cu
);
2135 make_cleanup (really_free_pendings
, NULL
);
2137 cu
.objfile
= objfile
;
2139 /* read in the comp_unit header */
2140 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
2142 /* Read the abbrevs for this compilation unit */
2143 dwarf2_read_abbrevs (abfd
, &cu
);
2144 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2146 cu
.header
.offset
= offset
;
2148 cu
.list_in_scope
= &file_symbols
;
2150 dies
= read_comp_unit (info_ptr
, abfd
, &cu
);
2152 make_cleanup_free_die_list (dies
);
2154 /* Find the base address of the compilation unit for range lists and
2155 location lists. It will normally be specified by DW_AT_low_pc.
2156 In DWARF-3 draft 4, the base address could be overridden by
2157 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2158 compilation units with discontinuous ranges. */
2160 cu
.header
.base_known
= 0;
2161 cu
.header
.base_address
= 0;
2163 attr
= dwarf2_attr (dies
, DW_AT_entry_pc
, &cu
);
2166 cu
.header
.base_address
= DW_ADDR (attr
);
2167 cu
.header
.base_known
= 1;
2171 attr
= dwarf2_attr (dies
, DW_AT_low_pc
, &cu
);
2174 cu
.header
.base_address
= DW_ADDR (attr
);
2175 cu
.header
.base_known
= 1;
2179 /* Do line number decoding in read_file_scope () */
2180 process_die (dies
, &cu
);
2182 /* Some compilers don't define a DW_AT_high_pc attribute for the
2183 compilation unit. If the DW_AT_high_pc is missing, synthesize
2184 it, by scanning the DIE's below the compilation unit. */
2185 get_scope_pc_bounds (dies
, &lowpc
, &highpc
, &cu
);
2187 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2189 /* Set symtab language to language from DW_AT_language.
2190 If the compilation is from a C file generated by language preprocessors,
2191 do not set the language if it was already deduced by start_subfile. */
2193 && !(cu
.language
== language_c
&& symtab
->language
!= language_c
))
2195 symtab
->language
= cu
.language
;
2197 pst
->symtab
= symtab
;
2200 do_cleanups (back_to
);
2203 /* Process a die and its children. */
2206 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2210 case DW_TAG_padding
:
2212 case DW_TAG_compile_unit
:
2213 read_file_scope (die
, cu
);
2215 case DW_TAG_subprogram
:
2216 read_subroutine_type (die
, cu
);
2217 read_func_scope (die
, cu
);
2219 case DW_TAG_inlined_subroutine
:
2220 /* FIXME: These are ignored for now.
2221 They could be used to set breakpoints on all inlined instances
2222 of a function and make GDB `next' properly over inlined functions. */
2224 case DW_TAG_lexical_block
:
2225 case DW_TAG_try_block
:
2226 case DW_TAG_catch_block
:
2227 read_lexical_block_scope (die
, cu
);
2229 case DW_TAG_class_type
:
2230 case DW_TAG_structure_type
:
2231 case DW_TAG_union_type
:
2232 read_structure_type (die
, cu
);
2233 process_structure_scope (die
, cu
);
2235 case DW_TAG_enumeration_type
:
2236 read_enumeration_type (die
, cu
);
2237 process_enumeration_scope (die
, cu
);
2240 /* FIXME drow/2004-03-14: These initialize die->type, but do not create
2241 a symbol or process any children. Therefore it doesn't do anything
2242 that won't be done on-demand by read_type_die. */
2243 case DW_TAG_subroutine_type
:
2244 read_subroutine_type (die
, cu
);
2246 case DW_TAG_array_type
:
2247 read_array_type (die
, cu
);
2249 case DW_TAG_pointer_type
:
2250 read_tag_pointer_type (die
, cu
);
2252 case DW_TAG_ptr_to_member_type
:
2253 read_tag_ptr_to_member_type (die
, cu
);
2255 case DW_TAG_reference_type
:
2256 read_tag_reference_type (die
, cu
);
2258 case DW_TAG_string_type
:
2259 read_tag_string_type (die
, cu
);
2263 case DW_TAG_base_type
:
2264 read_base_type (die
, cu
);
2265 /* Add a typedef symbol for the type definition, if it has a
2267 new_symbol (die
, die
->type
, cu
);
2269 case DW_TAG_subrange_type
:
2270 read_subrange_type (die
, cu
);
2271 /* Add a typedef symbol for the type definition, if it has a
2273 new_symbol (die
, die
->type
, cu
);
2275 case DW_TAG_common_block
:
2276 read_common_block (die
, cu
);
2278 case DW_TAG_common_inclusion
:
2280 case DW_TAG_namespace
:
2281 processing_has_namespace_info
= 1;
2282 read_namespace (die
, cu
);
2284 case DW_TAG_imported_declaration
:
2285 case DW_TAG_imported_module
:
2286 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2287 information contained in these. DW_TAG_imported_declaration
2288 dies shouldn't have children; DW_TAG_imported_module dies
2289 shouldn't in the C++ case, but conceivably could in the
2290 Fortran case, so we'll have to replace this gdb_assert if
2291 Fortran compilers start generating that info. */
2292 processing_has_namespace_info
= 1;
2293 gdb_assert (die
->child
== NULL
);
2296 new_symbol (die
, NULL
, cu
);
2302 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2304 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2308 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2310 struct objfile
*objfile
= cu
->objfile
;
2311 struct comp_unit_head
*cu_header
= &cu
->header
;
2312 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2313 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2314 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2315 struct attribute
*attr
;
2316 char *name
= "<unknown>";
2317 char *comp_dir
= NULL
;
2318 struct die_info
*child_die
;
2319 bfd
*abfd
= objfile
->obfd
;
2320 struct line_header
*line_header
= 0;
2323 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2325 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2327 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2328 from finish_block. */
2329 if (lowpc
== ((CORE_ADDR
) -1))
2334 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2337 name
= DW_STRING (attr
);
2339 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2342 comp_dir
= DW_STRING (attr
);
2345 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2346 directory, get rid of it. */
2347 char *cp
= strchr (comp_dir
, ':');
2349 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2354 if (objfile
->ei
.entry_point
>= lowpc
&&
2355 objfile
->ei
.entry_point
< highpc
)
2357 objfile
->ei
.deprecated_entry_file_lowpc
= lowpc
;
2358 objfile
->ei
.deprecated_entry_file_highpc
= highpc
;
2361 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2364 set_cu_language (DW_UNSND (attr
), cu
);
2367 /* We assume that we're processing GCC output. */
2368 processing_gcc_compilation
= 2;
2370 /* FIXME:Do something here. */
2371 if (dip
->at_producer
!= NULL
)
2373 handle_producer (dip
->at_producer
);
2377 /* The compilation unit may be in a different language or objfile,
2378 zero out all remembered fundamental types. */
2379 memset (cu
->ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
2381 start_symtab (name
, comp_dir
, lowpc
);
2382 record_debugformat ("DWARF 2");
2384 initialize_cu_func_list (cu
);
2386 /* Process all dies in compilation unit. */
2387 if (die
->child
!= NULL
)
2389 child_die
= die
->child
;
2390 while (child_die
&& child_die
->tag
)
2392 process_die (child_die
, cu
);
2393 child_die
= sibling_die (child_die
);
2397 /* Decode line number information if present. */
2398 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2401 unsigned int line_offset
= DW_UNSND (attr
);
2402 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2405 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
2406 (void *) line_header
);
2407 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2411 /* Decode macro information, if present. Dwarf 2 macro information
2412 refers to information in the line number info statement program
2413 header, so we can only read it if we've read the header
2415 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2416 if (attr
&& line_header
)
2418 unsigned int macro_offset
= DW_UNSND (attr
);
2419 dwarf_decode_macros (line_header
, macro_offset
,
2420 comp_dir
, abfd
, cu
);
2422 do_cleanups (back_to
);
2426 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2427 struct dwarf2_cu
*cu
)
2429 struct function_range
*thisfn
;
2431 thisfn
= (struct function_range
*)
2432 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
2433 thisfn
->name
= name
;
2434 thisfn
->lowpc
= lowpc
;
2435 thisfn
->highpc
= highpc
;
2436 thisfn
->seen_line
= 0;
2437 thisfn
->next
= NULL
;
2439 if (cu
->last_fn
== NULL
)
2440 cu
->first_fn
= thisfn
;
2442 cu
->last_fn
->next
= thisfn
;
2444 cu
->last_fn
= thisfn
;
2448 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2450 struct objfile
*objfile
= cu
->objfile
;
2451 struct context_stack
*new;
2454 struct die_info
*child_die
;
2455 struct attribute
*attr
;
2457 const char *previous_prefix
= processing_current_prefix
;
2458 struct cleanup
*back_to
= NULL
;
2461 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2463 name
= dwarf2_linkage_name (die
, cu
);
2465 /* Ignore functions with missing or empty names and functions with
2466 missing or invalid low and high pc attributes. */
2467 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2470 if (cu
->language
== language_cplus
)
2472 struct die_info
*spec_die
= die_specification (die
, cu
);
2474 /* NOTE: carlton/2004-01-23: We have to be careful in the
2475 presence of DW_AT_specification. For example, with GCC 3.4,
2480 // Definition of N::foo.
2484 then we'll have a tree of DIEs like this:
2486 1: DW_TAG_compile_unit
2487 2: DW_TAG_namespace // N
2488 3: DW_TAG_subprogram // declaration of N::foo
2489 4: DW_TAG_subprogram // definition of N::foo
2490 DW_AT_specification // refers to die #3
2492 Thus, when processing die #4, we have to pretend that we're
2493 in the context of its DW_AT_specification, namely the contex
2496 if (spec_die
!= NULL
)
2498 char *specification_prefix
= determine_prefix (spec_die
, cu
);
2499 processing_current_prefix
= specification_prefix
;
2500 back_to
= make_cleanup (xfree
, specification_prefix
);
2507 /* Record the function range for dwarf_decode_lines. */
2508 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
2510 if (objfile
->ei
.entry_point
>= lowpc
&&
2511 objfile
->ei
.entry_point
< highpc
)
2513 objfile
->ei
.entry_func_lowpc
= lowpc
;
2514 objfile
->ei
.entry_func_highpc
= highpc
;
2517 new = push_context (0, lowpc
);
2518 new->name
= new_symbol (die
, die
->type
, cu
);
2520 /* If there is a location expression for DW_AT_frame_base, record
2522 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
2524 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2525 expression is being recorded directly in the function's symbol
2526 and not in a separate frame-base object. I guess this hack is
2527 to avoid adding some sort of frame-base adjunct/annex to the
2528 function's symbol :-(. The problem with doing this is that it
2529 results in a function symbol with a location expression that
2530 has nothing to do with the location of the function, ouch! The
2531 relationship should be: a function's symbol has-a frame base; a
2532 frame-base has-a location expression. */
2533 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
2535 cu
->list_in_scope
= &local_symbols
;
2537 if (die
->child
!= NULL
)
2539 child_die
= die
->child
;
2540 while (child_die
&& child_die
->tag
)
2542 process_die (child_die
, cu
);
2543 child_die
= sibling_die (child_die
);
2547 new = pop_context ();
2548 /* Make a block for the local symbols within. */
2549 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2550 lowpc
, highpc
, objfile
);
2552 /* In C++, we can have functions nested inside functions (e.g., when
2553 a function declares a class that has methods). This means that
2554 when we finish processing a function scope, we may need to go
2555 back to building a containing block's symbol lists. */
2556 local_symbols
= new->locals
;
2557 param_symbols
= new->params
;
2559 /* If we've finished processing a top-level function, subsequent
2560 symbols go in the file symbol list. */
2561 if (outermost_context_p ())
2562 cu
->list_in_scope
= &file_symbols
;
2564 processing_current_prefix
= previous_prefix
;
2565 if (back_to
!= NULL
)
2566 do_cleanups (back_to
);
2569 /* Process all the DIES contained within a lexical block scope. Start
2570 a new scope, process the dies, and then close the scope. */
2573 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2575 struct objfile
*objfile
= cu
->objfile
;
2576 struct context_stack
*new;
2577 CORE_ADDR lowpc
, highpc
;
2578 struct die_info
*child_die
;
2581 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2583 /* Ignore blocks with missing or invalid low and high pc attributes. */
2584 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2585 as multiple lexical blocks? Handling children in a sane way would
2586 be nasty. Might be easier to properly extend generic blocks to
2588 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2593 push_context (0, lowpc
);
2594 if (die
->child
!= NULL
)
2596 child_die
= die
->child
;
2597 while (child_die
&& child_die
->tag
)
2599 process_die (child_die
, cu
);
2600 child_die
= sibling_die (child_die
);
2603 new = pop_context ();
2605 if (local_symbols
!= NULL
)
2607 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2610 local_symbols
= new->locals
;
2613 /* Get low and high pc attributes from a die. Return 1 if the attributes
2614 are present and valid, otherwise, return 0. Return -1 if the range is
2615 discontinuous, i.e. derived from DW_AT_ranges information. */
2617 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2618 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
2620 struct objfile
*objfile
= cu
->objfile
;
2621 struct comp_unit_head
*cu_header
= &cu
->header
;
2622 struct attribute
*attr
;
2623 bfd
*obfd
= objfile
->obfd
;
2628 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
2631 high
= DW_ADDR (attr
);
2632 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
2634 low
= DW_ADDR (attr
);
2636 /* Found high w/o low attribute. */
2639 /* Found consecutive range of addresses. */
2644 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
2647 unsigned int addr_size
= cu_header
->addr_size
;
2648 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2649 /* Value of the DW_AT_ranges attribute is the offset in the
2650 .debug_ranges section. */
2651 unsigned int offset
= DW_UNSND (attr
);
2652 /* Base address selection entry. */
2660 found_base
= cu_header
->base_known
;
2661 base
= cu_header
->base_address
;
2663 if (offset
>= dwarf2_per_objfile
->ranges_size
)
2665 complaint (&symfile_complaints
,
2666 "Offset %d out of bounds for DW_AT_ranges attribute",
2670 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
2672 /* Read in the largest possible address. */
2673 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
2674 if ((marker
& mask
) == mask
)
2676 /* If we found the largest possible address, then
2677 read the base address. */
2678 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2679 buffer
+= 2 * addr_size
;
2680 offset
+= 2 * addr_size
;
2688 CORE_ADDR range_beginning
, range_end
;
2690 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
2691 buffer
+= addr_size
;
2692 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
2693 buffer
+= addr_size
;
2694 offset
+= 2 * addr_size
;
2696 /* An end of list marker is a pair of zero addresses. */
2697 if (range_beginning
== 0 && range_end
== 0)
2698 /* Found the end of list entry. */
2701 /* Each base address selection entry is a pair of 2 values.
2702 The first is the largest possible address, the second is
2703 the base address. Check for a base address here. */
2704 if ((range_beginning
& mask
) == mask
)
2706 /* If we found the largest possible address, then
2707 read the base address. */
2708 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2715 /* We have no valid base address for the ranges
2717 complaint (&symfile_complaints
,
2718 "Invalid .debug_ranges data (no base address)");
2722 range_beginning
+= base
;
2725 /* FIXME: This is recording everything as a low-high
2726 segment of consecutive addresses. We should have a
2727 data structure for discontiguous block ranges
2731 low
= range_beginning
;
2737 if (range_beginning
< low
)
2738 low
= range_beginning
;
2739 if (range_end
> high
)
2745 /* If the first entry is an end-of-list marker, the range
2746 describes an empty scope, i.e. no instructions. */
2756 /* When using the GNU linker, .gnu.linkonce. sections are used to
2757 eliminate duplicate copies of functions and vtables and such.
2758 The linker will arbitrarily choose one and discard the others.
2759 The AT_*_pc values for such functions refer to local labels in
2760 these sections. If the section from that file was discarded, the
2761 labels are not in the output, so the relocs get a value of 0.
2762 If this is a discarded function, mark the pc bounds as invalid,
2763 so that GDB will ignore it. */
2764 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
2772 /* Get the low and high pc's represented by the scope DIE, and store
2773 them in *LOWPC and *HIGHPC. If the correct values can't be
2774 determined, set *LOWPC to -1 and *HIGHPC to 0. */
2777 get_scope_pc_bounds (struct die_info
*die
,
2778 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2779 struct dwarf2_cu
*cu
)
2781 CORE_ADDR best_low
= (CORE_ADDR
) -1;
2782 CORE_ADDR best_high
= (CORE_ADDR
) 0;
2783 CORE_ADDR current_low
, current_high
;
2785 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
2787 best_low
= current_low
;
2788 best_high
= current_high
;
2792 struct die_info
*child
= die
->child
;
2794 while (child
&& child
->tag
)
2796 switch (child
->tag
) {
2797 case DW_TAG_subprogram
:
2798 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
2800 best_low
= min (best_low
, current_low
);
2801 best_high
= max (best_high
, current_high
);
2804 case DW_TAG_namespace
:
2805 /* FIXME: carlton/2004-01-16: Should we do this for
2806 DW_TAG_class_type/DW_TAG_structure_type, too? I think
2807 that current GCC's always emit the DIEs corresponding
2808 to definitions of methods of classes as children of a
2809 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
2810 the DIEs giving the declarations, which could be
2811 anywhere). But I don't see any reason why the
2812 standards says that they have to be there. */
2813 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
2815 if (current_low
!= ((CORE_ADDR
) -1))
2817 best_low
= min (best_low
, current_low
);
2818 best_high
= max (best_high
, current_high
);
2826 child
= sibling_die (child
);
2831 *highpc
= best_high
;
2834 /* Add an aggregate field to the field list. */
2837 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2838 struct dwarf2_cu
*cu
)
2840 struct objfile
*objfile
= cu
->objfile
;
2841 struct nextfield
*new_field
;
2842 struct attribute
*attr
;
2844 char *fieldname
= "";
2846 /* Allocate a new field list entry and link it in. */
2847 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2848 make_cleanup (xfree
, new_field
);
2849 memset (new_field
, 0, sizeof (struct nextfield
));
2850 new_field
->next
= fip
->fields
;
2851 fip
->fields
= new_field
;
2854 /* Handle accessibility and virtuality of field.
2855 The default accessibility for members is public, the default
2856 accessibility for inheritance is private. */
2857 if (die
->tag
!= DW_TAG_inheritance
)
2858 new_field
->accessibility
= DW_ACCESS_public
;
2860 new_field
->accessibility
= DW_ACCESS_private
;
2861 new_field
->virtuality
= DW_VIRTUALITY_none
;
2863 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
2865 new_field
->accessibility
= DW_UNSND (attr
);
2866 if (new_field
->accessibility
!= DW_ACCESS_public
)
2867 fip
->non_public_fields
= 1;
2868 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
2870 new_field
->virtuality
= DW_UNSND (attr
);
2872 fp
= &new_field
->field
;
2874 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
2876 /* Data member other than a C++ static data member. */
2878 /* Get type of field. */
2879 fp
->type
= die_type (die
, cu
);
2881 FIELD_STATIC_KIND (*fp
) = 0;
2883 /* Get bit size of field (zero if none). */
2884 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
2887 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2891 FIELD_BITSIZE (*fp
) = 0;
2894 /* Get bit offset of field. */
2895 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
2898 FIELD_BITPOS (*fp
) =
2899 decode_locdesc (DW_BLOCK (attr
), cu
) * bits_per_byte
;
2902 FIELD_BITPOS (*fp
) = 0;
2903 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
2906 if (BITS_BIG_ENDIAN
)
2908 /* For big endian bits, the DW_AT_bit_offset gives the
2909 additional bit offset from the MSB of the containing
2910 anonymous object to the MSB of the field. We don't
2911 have to do anything special since we don't need to
2912 know the size of the anonymous object. */
2913 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2917 /* For little endian bits, compute the bit offset to the
2918 MSB of the anonymous object, subtract off the number of
2919 bits from the MSB of the field to the MSB of the
2920 object, and then subtract off the number of bits of
2921 the field itself. The result is the bit offset of
2922 the LSB of the field. */
2924 int bit_offset
= DW_UNSND (attr
);
2926 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
2929 /* The size of the anonymous object containing
2930 the bit field is explicit, so use the
2931 indicated size (in bytes). */
2932 anonymous_size
= DW_UNSND (attr
);
2936 /* The size of the anonymous object containing
2937 the bit field must be inferred from the type
2938 attribute of the data member containing the
2940 anonymous_size
= TYPE_LENGTH (fp
->type
);
2942 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2943 - bit_offset
- FIELD_BITSIZE (*fp
);
2947 /* Get name of field. */
2948 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2949 if (attr
&& DW_STRING (attr
))
2950 fieldname
= DW_STRING (attr
);
2952 /* The name is already allocated along with this objfile, so we don't
2953 need to duplicate it for the type. */
2954 fp
->name
= fieldname
;
2956 /* Change accessibility for artificial fields (e.g. virtual table
2957 pointer or virtual base class pointer) to private. */
2958 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
2960 new_field
->accessibility
= DW_ACCESS_private
;
2961 fip
->non_public_fields
= 1;
2964 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
2966 /* C++ static member. */
2968 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2969 is a declaration, but all versions of G++ as of this writing
2970 (so through at least 3.2.1) incorrectly generate
2971 DW_TAG_variable tags. */
2975 /* Get name of field. */
2976 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2977 if (attr
&& DW_STRING (attr
))
2978 fieldname
= DW_STRING (attr
);
2982 /* Get physical name. */
2983 physname
= dwarf2_linkage_name (die
, cu
);
2985 /* The name is already allocated along with this objfile, so we don't
2986 need to duplicate it for the type. */
2987 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
2988 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2989 FIELD_NAME (*fp
) = fieldname
;
2991 else if (die
->tag
== DW_TAG_inheritance
)
2993 /* C++ base class field. */
2994 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
2996 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
2998 FIELD_BITSIZE (*fp
) = 0;
2999 FIELD_STATIC_KIND (*fp
) = 0;
3000 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3001 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3002 fip
->nbaseclasses
++;
3006 /* Create the vector of fields, and attach it to the type. */
3009 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3010 struct dwarf2_cu
*cu
)
3012 int nfields
= fip
->nfields
;
3014 /* Record the field count, allocate space for the array of fields,
3015 and create blank accessibility bitfields if necessary. */
3016 TYPE_NFIELDS (type
) = nfields
;
3017 TYPE_FIELDS (type
) = (struct field
*)
3018 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3019 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3021 if (fip
->non_public_fields
)
3023 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3025 TYPE_FIELD_PRIVATE_BITS (type
) =
3026 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3027 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3029 TYPE_FIELD_PROTECTED_BITS (type
) =
3030 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3031 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3033 TYPE_FIELD_IGNORE_BITS (type
) =
3034 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3035 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3038 /* If the type has baseclasses, allocate and clear a bit vector for
3039 TYPE_FIELD_VIRTUAL_BITS. */
3040 if (fip
->nbaseclasses
)
3042 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3045 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3046 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
3047 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
3048 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3049 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3052 /* Copy the saved-up fields into the field vector. Start from the head
3053 of the list, adding to the tail of the field array, so that they end
3054 up in the same order in the array in which they were added to the list. */
3055 while (nfields
-- > 0)
3057 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3058 switch (fip
->fields
->accessibility
)
3060 case DW_ACCESS_private
:
3061 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3064 case DW_ACCESS_protected
:
3065 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3068 case DW_ACCESS_public
:
3072 /* Unknown accessibility. Complain and treat it as public. */
3074 complaint (&symfile_complaints
, "unsupported accessibility %d",
3075 fip
->fields
->accessibility
);
3079 if (nfields
< fip
->nbaseclasses
)
3081 switch (fip
->fields
->virtuality
)
3083 case DW_VIRTUALITY_virtual
:
3084 case DW_VIRTUALITY_pure_virtual
:
3085 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3089 fip
->fields
= fip
->fields
->next
;
3093 /* Add a member function to the proper fieldlist. */
3096 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3097 struct type
*type
, struct dwarf2_cu
*cu
)
3099 struct objfile
*objfile
= cu
->objfile
;
3100 struct attribute
*attr
;
3101 struct fnfieldlist
*flp
;
3103 struct fn_field
*fnp
;
3106 struct nextfnfield
*new_fnfield
;
3108 /* Get name of member function. */
3109 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3110 if (attr
&& DW_STRING (attr
))
3111 fieldname
= DW_STRING (attr
);
3115 /* Get the mangled name. */
3116 physname
= dwarf2_linkage_name (die
, cu
);
3118 /* Look up member function name in fieldlist. */
3119 for (i
= 0; i
< fip
->nfnfields
; i
++)
3121 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3125 /* Create new list element if necessary. */
3126 if (i
< fip
->nfnfields
)
3127 flp
= &fip
->fnfieldlists
[i
];
3130 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3132 fip
->fnfieldlists
= (struct fnfieldlist
*)
3133 xrealloc (fip
->fnfieldlists
,
3134 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3135 * sizeof (struct fnfieldlist
));
3136 if (fip
->nfnfields
== 0)
3137 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3139 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3140 flp
->name
= fieldname
;
3146 /* Create a new member function field and chain it to the field list
3148 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3149 make_cleanup (xfree
, new_fnfield
);
3150 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3151 new_fnfield
->next
= flp
->head
;
3152 flp
->head
= new_fnfield
;
3155 /* Fill in the member function field info. */
3156 fnp
= &new_fnfield
->fnfield
;
3157 /* The name is already allocated along with this objfile, so we don't
3158 need to duplicate it for the type. */
3159 fnp
->physname
= physname
? physname
: "";
3160 fnp
->type
= alloc_type (objfile
);
3161 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
3163 int nparams
= TYPE_NFIELDS (die
->type
);
3165 /* TYPE is the domain of this method, and DIE->TYPE is the type
3166 of the method itself (TYPE_CODE_METHOD). */
3167 smash_to_method_type (fnp
->type
, type
,
3168 TYPE_TARGET_TYPE (die
->type
),
3169 TYPE_FIELDS (die
->type
),
3170 TYPE_NFIELDS (die
->type
),
3171 TYPE_VARARGS (die
->type
));
3173 /* Handle static member functions.
3174 Dwarf2 has no clean way to discern C++ static and non-static
3175 member functions. G++ helps GDB by marking the first
3176 parameter for non-static member functions (which is the
3177 this pointer) as artificial. We obtain this information
3178 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3179 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
3180 fnp
->voffset
= VOFFSET_STATIC
;
3183 complaint (&symfile_complaints
, "member function type missing for '%s'",
3186 /* Get fcontext from DW_AT_containing_type if present. */
3187 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3188 fnp
->fcontext
= die_containing_type (die
, cu
);
3190 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3191 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3193 /* Get accessibility. */
3194 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3197 switch (DW_UNSND (attr
))
3199 case DW_ACCESS_private
:
3200 fnp
->is_private
= 1;
3202 case DW_ACCESS_protected
:
3203 fnp
->is_protected
= 1;
3208 /* Check for artificial methods. */
3209 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3210 if (attr
&& DW_UNSND (attr
) != 0)
3211 fnp
->is_artificial
= 1;
3213 /* Get index in virtual function table if it is a virtual member function. */
3214 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3217 /* Support the .debug_loc offsets */
3218 if (attr_form_is_block (attr
))
3220 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3222 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3224 dwarf2_complex_location_expr_complaint ();
3228 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3234 /* Create the vector of member function fields, and attach it to the type. */
3237 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3238 struct dwarf2_cu
*cu
)
3240 struct fnfieldlist
*flp
;
3241 int total_length
= 0;
3244 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3245 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3246 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3248 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3250 struct nextfnfield
*nfp
= flp
->head
;
3251 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3254 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3255 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3256 fn_flp
->fn_fields
= (struct fn_field
*)
3257 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3258 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3259 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3261 total_length
+= flp
->length
;
3264 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3265 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3268 /* Called when we find the DIE that starts a structure or union scope
3269 (definition) to process all dies that define the members of the
3272 NOTE: we need to call struct_type regardless of whether or not the
3273 DIE has an at_name attribute, since it might be an anonymous
3274 structure or union. This gets the type entered into our set of
3277 However, if the structure is incomplete (an opaque struct/union)
3278 then suppress creating a symbol table entry for it since gdb only
3279 wants to find the one with the complete definition. Note that if
3280 it is complete, we just call new_symbol, which does it's own
3281 checking about whether the struct/union is anonymous or not (and
3282 suppresses creating a symbol table entry itself). */
3285 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3287 struct objfile
*objfile
= cu
->objfile
;
3289 struct attribute
*attr
;
3290 const char *previous_prefix
= processing_current_prefix
;
3291 struct cleanup
*back_to
= NULL
;
3296 type
= alloc_type (objfile
);
3298 INIT_CPLUS_SPECIFIC (type
);
3299 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3300 if (attr
&& DW_STRING (attr
))
3302 if (cu
->language
== language_cplus
)
3304 char *new_prefix
= determine_class_name (die
, cu
);
3305 TYPE_TAG_NAME (type
) = obsavestring (new_prefix
,
3306 strlen (new_prefix
),
3307 &objfile
->objfile_obstack
);
3308 back_to
= make_cleanup (xfree
, new_prefix
);
3309 processing_current_prefix
= new_prefix
;
3313 /* The name is already allocated along with this objfile, so
3314 we don't need to duplicate it for the type. */
3315 TYPE_TAG_NAME (type
) = DW_STRING (attr
);
3319 if (die
->tag
== DW_TAG_structure_type
)
3321 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
3323 else if (die
->tag
== DW_TAG_union_type
)
3325 TYPE_CODE (type
) = TYPE_CODE_UNION
;
3329 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
3331 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
3334 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3337 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3341 TYPE_LENGTH (type
) = 0;
3344 if (die_is_declaration (die
, cu
))
3345 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
3347 /* We need to add the type field to the die immediately so we don't
3348 infinitely recurse when dealing with pointers to the structure
3349 type within the structure itself. */
3352 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3354 struct field_info fi
;
3355 struct die_info
*child_die
;
3356 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
3358 memset (&fi
, 0, sizeof (struct field_info
));
3360 child_die
= die
->child
;
3362 while (child_die
&& child_die
->tag
)
3364 if (child_die
->tag
== DW_TAG_member
3365 || child_die
->tag
== DW_TAG_variable
)
3367 /* NOTE: carlton/2002-11-05: A C++ static data member
3368 should be a DW_TAG_member that is a declaration, but
3369 all versions of G++ as of this writing (so through at
3370 least 3.2.1) incorrectly generate DW_TAG_variable
3371 tags for them instead. */
3372 dwarf2_add_field (&fi
, child_die
, cu
);
3374 else if (child_die
->tag
== DW_TAG_subprogram
)
3376 /* C++ member function. */
3377 read_type_die (child_die
, cu
);
3378 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
3380 else if (child_die
->tag
== DW_TAG_inheritance
)
3382 /* C++ base class field. */
3383 dwarf2_add_field (&fi
, child_die
, cu
);
3385 child_die
= sibling_die (child_die
);
3388 /* Attach fields and member functions to the type. */
3390 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
3393 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
3395 /* Get the type which refers to the base class (possibly this
3396 class itself) which contains the vtable pointer for the current
3397 class from the DW_AT_containing_type attribute. */
3399 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3401 struct type
*t
= die_containing_type (die
, cu
);
3403 TYPE_VPTR_BASETYPE (type
) = t
;
3406 static const char vptr_name
[] =
3407 {'_', 'v', 'p', 't', 'r', '\0'};
3410 /* Our own class provides vtbl ptr. */
3411 for (i
= TYPE_NFIELDS (t
) - 1;
3412 i
>= TYPE_N_BASECLASSES (t
);
3415 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
3417 if ((strncmp (fieldname
, vptr_name
,
3418 strlen (vptr_name
) - 1)
3420 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
3422 TYPE_VPTR_FIELDNO (type
) = i
;
3427 /* Complain if virtual function table field not found. */
3428 if (i
< TYPE_N_BASECLASSES (t
))
3429 complaint (&symfile_complaints
,
3430 "virtual function table pointer not found when defining class '%s'",
3431 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
3436 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3441 do_cleanups (back_to
);
3444 processing_current_prefix
= previous_prefix
;
3445 if (back_to
!= NULL
)
3446 do_cleanups (back_to
);
3450 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3452 struct objfile
*objfile
= cu
->objfile
;
3453 const char *previous_prefix
= processing_current_prefix
;
3454 struct die_info
*child_die
= die
->child
;
3456 if (TYPE_TAG_NAME (die
->type
) != NULL
)
3457 processing_current_prefix
= TYPE_TAG_NAME (die
->type
);
3459 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
3460 snapshots) has been known to create a die giving a declaration
3461 for a class that has, as a child, a die giving a definition for a
3462 nested class. So we have to process our children even if the
3463 current die is a declaration. Normally, of course, a declaration
3464 won't have any children at all. */
3466 while (child_die
!= NULL
&& child_die
->tag
)
3468 if (child_die
->tag
== DW_TAG_member
3469 || child_die
->tag
== DW_TAG_variable
3470 || child_die
->tag
== DW_TAG_inheritance
)
3475 process_die (child_die
, cu
);
3477 child_die
= sibling_die (child_die
);
3480 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3481 new_symbol (die
, die
->type
, cu
);
3483 processing_current_prefix
= previous_prefix
;
3486 /* Given a DW_AT_enumeration_type die, set its type. We do not
3487 complete the type's fields yet, or create any symbols. */
3490 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3492 struct objfile
*objfile
= cu
->objfile
;
3494 struct attribute
*attr
;
3499 type
= alloc_type (objfile
);
3501 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3502 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3503 if (attr
&& DW_STRING (attr
))
3505 char *name
= DW_STRING (attr
);
3507 if (processing_has_namespace_info
)
3509 TYPE_TAG_NAME (type
) = obconcat (&objfile
->objfile_obstack
,
3510 processing_current_prefix
,
3511 processing_current_prefix
[0] == '\0'
3517 /* The name is already allocated along with this objfile, so
3518 we don't need to duplicate it for the type. */
3519 TYPE_TAG_NAME (type
) = name
;
3523 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3526 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3530 TYPE_LENGTH (type
) = 0;
3536 /* Determine the name of the type represented by DIE, which should be
3537 a named C++ compound type. Return the name in question; the caller
3538 is responsible for xfree()'ing it. */
3541 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
3543 struct cleanup
*back_to
= NULL
;
3544 struct die_info
*spec_die
= die_specification (die
, cu
);
3545 char *new_prefix
= NULL
;
3547 /* If this is the definition of a class that is declared by another
3548 die, then processing_current_prefix may not be accurate; see
3549 read_func_scope for a similar example. */
3550 if (spec_die
!= NULL
)
3552 char *specification_prefix
= determine_prefix (spec_die
, cu
);
3553 processing_current_prefix
= specification_prefix
;
3554 back_to
= make_cleanup (xfree
, specification_prefix
);
3557 /* If we don't have namespace debug info, guess the name by trying
3558 to demangle the names of members, just like we did in
3559 guess_structure_name. */
3560 if (!processing_has_namespace_info
)
3562 struct die_info
*child
;
3564 for (child
= die
->child
;
3565 child
!= NULL
&& child
->tag
!= 0;
3566 child
= sibling_die (child
))
3568 if (child
->tag
== DW_TAG_subprogram
)
3570 new_prefix
= class_name_from_physname (dwarf2_linkage_name
3573 if (new_prefix
!= NULL
)
3579 if (new_prefix
== NULL
)
3581 const char *name
= dwarf2_name (die
, cu
);
3582 new_prefix
= typename_concat (processing_current_prefix
,
3583 name
? name
: "<<anonymous>>");
3586 if (back_to
!= NULL
)
3587 do_cleanups (back_to
);
3592 /* Given a pointer to a die which begins an enumeration, process all
3593 the dies that define the members of the enumeration, and create the
3594 symbol for the enumeration type.
3596 NOTE: We reverse the order of the element list. */
3599 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3601 struct objfile
*objfile
= cu
->objfile
;
3602 struct die_info
*child_die
;
3603 struct field
*fields
;
3604 struct attribute
*attr
;
3607 int unsigned_enum
= 1;
3611 if (die
->child
!= NULL
)
3613 child_die
= die
->child
;
3614 while (child_die
&& child_die
->tag
)
3616 if (child_die
->tag
!= DW_TAG_enumerator
)
3618 process_die (child_die
, cu
);
3622 attr
= dwarf2_attr (child_die
, DW_AT_name
, cu
);
3625 sym
= new_symbol (child_die
, die
->type
, cu
);
3626 if (SYMBOL_VALUE (sym
) < 0)
3629 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3631 fields
= (struct field
*)
3633 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
3634 * sizeof (struct field
));
3637 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
3638 FIELD_TYPE (fields
[num_fields
]) = NULL
;
3639 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
3640 FIELD_BITSIZE (fields
[num_fields
]) = 0;
3641 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
3647 child_die
= sibling_die (child_die
);
3652 TYPE_NFIELDS (die
->type
) = num_fields
;
3653 TYPE_FIELDS (die
->type
) = (struct field
*)
3654 TYPE_ALLOC (die
->type
, sizeof (struct field
) * num_fields
);
3655 memcpy (TYPE_FIELDS (die
->type
), fields
,
3656 sizeof (struct field
) * num_fields
);
3660 TYPE_FLAGS (die
->type
) |= TYPE_FLAG_UNSIGNED
;
3663 new_symbol (die
, die
->type
, cu
);
3666 /* Extract all information from a DW_TAG_array_type DIE and put it in
3667 the DIE's type field. For now, this only handles one dimensional
3671 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3673 struct objfile
*objfile
= cu
->objfile
;
3674 struct die_info
*child_die
;
3675 struct type
*type
= NULL
;
3676 struct type
*element_type
, *range_type
, *index_type
;
3677 struct type
**range_types
= NULL
;
3678 struct attribute
*attr
;
3680 struct cleanup
*back_to
;
3682 /* Return if we've already decoded this type. */
3688 element_type
= die_type (die
, cu
);
3690 /* Irix 6.2 native cc creates array types without children for
3691 arrays with unspecified length. */
3692 if (die
->child
== NULL
)
3694 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
3695 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3696 die
->type
= create_array_type (NULL
, element_type
, range_type
);
3700 back_to
= make_cleanup (null_cleanup
, NULL
);
3701 child_die
= die
->child
;
3702 while (child_die
&& child_die
->tag
)
3704 if (child_die
->tag
== DW_TAG_subrange_type
)
3706 read_subrange_type (child_die
, cu
);
3708 if (child_die
->type
!= NULL
)
3710 /* The range type was succesfully read. Save it for
3711 the array type creation. */
3712 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3714 range_types
= (struct type
**)
3715 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3716 * sizeof (struct type
*));
3718 make_cleanup (free_current_contents
, &range_types
);
3720 range_types
[ndim
++] = child_die
->type
;
3723 child_die
= sibling_die (child_die
);
3726 /* Dwarf2 dimensions are output from left to right, create the
3727 necessary array types in backwards order. */
3728 type
= element_type
;
3730 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3732 /* Understand Dwarf2 support for vector types (like they occur on
3733 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3734 array type. This is not part of the Dwarf2/3 standard yet, but a
3735 custom vendor extension. The main difference between a regular
3736 array and the vector variant is that vectors are passed by value
3738 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
3740 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3742 do_cleanups (back_to
);
3744 /* Install the type in the die. */
3748 /* First cut: install each common block member as a global variable. */
3751 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
3753 struct die_info
*child_die
;
3754 struct attribute
*attr
;
3756 CORE_ADDR base
= (CORE_ADDR
) 0;
3758 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
3761 /* Support the .debug_loc offsets */
3762 if (attr_form_is_block (attr
))
3764 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
3766 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3768 dwarf2_complex_location_expr_complaint ();
3772 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3773 "common block member");
3776 if (die
->child
!= NULL
)
3778 child_die
= die
->child
;
3779 while (child_die
&& child_die
->tag
)
3781 sym
= new_symbol (child_die
, NULL
, cu
);
3782 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
3785 SYMBOL_VALUE_ADDRESS (sym
) =
3786 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
3787 add_symbol_to_list (sym
, &global_symbols
);
3789 child_die
= sibling_die (child_die
);
3794 /* Read a C++ namespace. */
3797 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3799 struct objfile
*objfile
= cu
->objfile
;
3800 const char *previous_prefix
= processing_current_prefix
;
3803 struct die_info
*current_die
;
3805 name
= namespace_name (die
, &is_anonymous
, cu
);
3807 /* Now build the name of the current namespace. */
3809 if (previous_prefix
[0] == '\0')
3811 processing_current_prefix
= name
;
3815 /* We need temp_name around because processing_current_prefix
3816 is a const char *. */
3817 char *temp_name
= alloca (strlen (previous_prefix
)
3818 + 2 + strlen(name
) + 1);
3819 strcpy (temp_name
, previous_prefix
);
3820 strcat (temp_name
, "::");
3821 strcat (temp_name
, name
);
3823 processing_current_prefix
= temp_name
;
3826 /* Add a symbol associated to this if we haven't seen the namespace
3827 before. Also, add a using directive if it's an anonymous
3830 if (dwarf2_extension (die
, cu
) == NULL
)
3834 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3835 this cast will hopefully become unnecessary. */
3836 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
3837 (char *) processing_current_prefix
,
3839 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
3841 new_symbol (die
, type
, cu
);
3845 cp_add_using_directive (processing_current_prefix
,
3846 strlen (previous_prefix
),
3847 strlen (processing_current_prefix
));
3850 if (die
->child
!= NULL
)
3852 struct die_info
*child_die
= die
->child
;
3854 while (child_die
&& child_die
->tag
)
3856 process_die (child_die
, cu
);
3857 child_die
= sibling_die (child_die
);
3861 processing_current_prefix
= previous_prefix
;
3864 /* Return the name of the namespace represented by DIE. Set
3865 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
3869 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
3871 struct die_info
*current_die
;
3872 const char *name
= NULL
;
3874 /* Loop through the extensions until we find a name. */
3876 for (current_die
= die
;
3877 current_die
!= NULL
;
3878 current_die
= dwarf2_extension (die
, cu
))
3880 name
= dwarf2_name (current_die
, cu
);
3885 /* Is it an anonymous namespace? */
3887 *is_anonymous
= (name
== NULL
);
3889 name
= "(anonymous namespace)";
3894 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3895 the user defined type vector. */
3898 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3900 struct comp_unit_head
*cu_header
= &cu
->header
;
3902 struct attribute
*attr_byte_size
;
3903 struct attribute
*attr_address_class
;
3904 int byte_size
, addr_class
;
3911 type
= lookup_pointer_type (die_type (die
, cu
));
3913 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3915 byte_size
= DW_UNSND (attr_byte_size
);
3917 byte_size
= cu_header
->addr_size
;
3919 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
3920 if (attr_address_class
)
3921 addr_class
= DW_UNSND (attr_address_class
);
3923 addr_class
= DW_ADDR_none
;
3925 /* If the pointer size or address class is different than the
3926 default, create a type variant marked as such and set the
3927 length accordingly. */
3928 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3930 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3934 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3935 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3936 type
= make_type_with_address_space (type
, type_flags
);
3938 else if (TYPE_LENGTH (type
) != byte_size
)
3940 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3943 /* Should we also complain about unhandled address classes? */
3947 TYPE_LENGTH (type
) = byte_size
;
3951 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3952 the user defined type vector. */
3955 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3957 struct objfile
*objfile
= cu
->objfile
;
3959 struct type
*to_type
;
3960 struct type
*domain
;
3967 type
= alloc_type (objfile
);
3968 to_type
= die_type (die
, cu
);
3969 domain
= die_containing_type (die
, cu
);
3970 smash_to_member_type (type
, domain
, to_type
);
3975 /* Extract all information from a DW_TAG_reference_type DIE and add to
3976 the user defined type vector. */
3979 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3981 struct comp_unit_head
*cu_header
= &cu
->header
;
3983 struct attribute
*attr
;
3990 type
= lookup_reference_type (die_type (die
, cu
));
3991 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3994 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3998 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4004 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4006 struct type
*base_type
;
4013 base_type
= die_type (die
, cu
);
4014 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
4018 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4020 struct type
*base_type
;
4027 base_type
= die_type (die
, cu
);
4028 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
4031 /* Extract all information from a DW_TAG_string_type DIE and add to
4032 the user defined type vector. It isn't really a user defined type,
4033 but it behaves like one, with other DIE's using an AT_user_def_type
4034 attribute to reference it. */
4037 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4039 struct objfile
*objfile
= cu
->objfile
;
4040 struct type
*type
, *range_type
, *index_type
, *char_type
;
4041 struct attribute
*attr
;
4042 unsigned int length
;
4049 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4052 length
= DW_UNSND (attr
);
4056 /* check for the DW_AT_byte_size attribute */
4057 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4060 length
= DW_UNSND (attr
);
4067 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
4068 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4069 if (cu
->language
== language_fortran
)
4071 /* Need to create a unique string type for bounds
4073 type
= create_string_type (0, range_type
);
4077 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
, cu
);
4078 type
= create_string_type (char_type
, range_type
);
4083 /* Handle DIES due to C code like:
4087 int (*funcp)(int a, long l);
4091 ('funcp' generates a DW_TAG_subroutine_type DIE)
4095 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4097 struct type
*type
; /* Type that this function returns */
4098 struct type
*ftype
; /* Function that returns above type */
4099 struct attribute
*attr
;
4101 /* Decode the type that this subroutine returns */
4106 type
= die_type (die
, cu
);
4107 ftype
= lookup_function_type (type
);
4109 /* All functions in C++ have prototypes. */
4110 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4111 if ((attr
&& (DW_UNSND (attr
) != 0))
4112 || cu
->language
== language_cplus
)
4113 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
4115 if (die
->child
!= NULL
)
4117 struct die_info
*child_die
;
4121 /* Count the number of parameters.
4122 FIXME: GDB currently ignores vararg functions, but knows about
4123 vararg member functions. */
4124 child_die
= die
->child
;
4125 while (child_die
&& child_die
->tag
)
4127 if (child_die
->tag
== DW_TAG_formal_parameter
)
4129 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4130 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
4131 child_die
= sibling_die (child_die
);
4134 /* Allocate storage for parameters and fill them in. */
4135 TYPE_NFIELDS (ftype
) = nparams
;
4136 TYPE_FIELDS (ftype
) = (struct field
*)
4137 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
4139 child_die
= die
->child
;
4140 while (child_die
&& child_die
->tag
)
4142 if (child_die
->tag
== DW_TAG_formal_parameter
)
4144 /* Dwarf2 has no clean way to discern C++ static and non-static
4145 member functions. G++ helps GDB by marking the first
4146 parameter for non-static member functions (which is the
4147 this pointer) as artificial. We pass this information
4148 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4149 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4151 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4153 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4154 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4157 child_die
= sibling_die (child_die
);
4165 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4167 struct objfile
*objfile
= cu
->objfile
;
4168 struct attribute
*attr
;
4173 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4174 if (attr
&& DW_STRING (attr
))
4176 name
= DW_STRING (attr
);
4178 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
4179 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
4183 /* Find a representation of a given base type and install
4184 it in the TYPE field of the die. */
4187 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4189 struct objfile
*objfile
= cu
->objfile
;
4191 struct attribute
*attr
;
4192 int encoding
= 0, size
= 0;
4194 /* If we've already decoded this die, this is a no-op. */
4200 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4203 encoding
= DW_UNSND (attr
);
4205 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4208 size
= DW_UNSND (attr
);
4210 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4211 if (attr
&& DW_STRING (attr
))
4213 enum type_code code
= TYPE_CODE_INT
;
4218 case DW_ATE_address
:
4219 /* Turn DW_ATE_address into a void * pointer. */
4220 code
= TYPE_CODE_PTR
;
4221 type_flags
|= TYPE_FLAG_UNSIGNED
;
4223 case DW_ATE_boolean
:
4224 code
= TYPE_CODE_BOOL
;
4225 type_flags
|= TYPE_FLAG_UNSIGNED
;
4227 case DW_ATE_complex_float
:
4228 code
= TYPE_CODE_COMPLEX
;
4231 code
= TYPE_CODE_FLT
;
4234 case DW_ATE_signed_char
:
4236 case DW_ATE_unsigned
:
4237 case DW_ATE_unsigned_char
:
4238 type_flags
|= TYPE_FLAG_UNSIGNED
;
4241 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
4242 dwarf_type_encoding_name (encoding
));
4245 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
4246 if (encoding
== DW_ATE_address
)
4247 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
,
4249 else if (encoding
== DW_ATE_complex_float
)
4252 TYPE_TARGET_TYPE (type
)
4253 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
, cu
);
4254 else if (size
== 16)
4255 TYPE_TARGET_TYPE (type
)
4256 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
4258 TYPE_TARGET_TYPE (type
)
4259 = dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
4264 type
= dwarf_base_type (encoding
, size
, cu
);
4269 /* Read the given DW_AT_subrange DIE. */
4272 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4274 struct type
*base_type
;
4275 struct type
*range_type
;
4276 struct attribute
*attr
;
4280 /* If we have already decoded this die, then nothing more to do. */
4284 base_type
= die_type (die
, cu
);
4285 if (base_type
== NULL
)
4287 complaint (&symfile_complaints
,
4288 "DW_AT_type missing from DW_TAG_subrange_type");
4292 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
4293 base_type
= alloc_type (NULL
);
4295 if (cu
->language
== language_fortran
)
4297 /* FORTRAN implies a lower bound of 1, if not given. */
4301 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
4303 low
= dwarf2_get_attr_constant_value (attr
, 0);
4305 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
4308 if (attr
->form
== DW_FORM_block1
)
4310 /* GCC encodes arrays with unspecified or dynamic length
4311 with a DW_FORM_block1 attribute.
4312 FIXME: GDB does not yet know how to handle dynamic
4313 arrays properly, treat them as arrays with unspecified
4316 FIXME: jimb/2003-09-22: GDB does not really know
4317 how to handle arrays of unspecified length
4318 either; we just represent them as zero-length
4319 arrays. Choose an appropriate upper bound given
4320 the lower bound we've computed above. */
4324 high
= dwarf2_get_attr_constant_value (attr
, 1);
4327 range_type
= create_range_type (NULL
, base_type
, low
, high
);
4329 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4330 if (attr
&& DW_STRING (attr
))
4331 TYPE_NAME (range_type
) = DW_STRING (attr
);
4333 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4335 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
4337 die
->type
= range_type
;
4341 /* Read a whole compilation unit into a linked list of dies. */
4343 static struct die_info
*
4344 read_comp_unit (char *info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
4346 /* Reset die reference table; we are
4347 building new ones now. */
4348 dwarf2_empty_hash_tables ();
4350 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
4353 /* Read a single die and all its descendents. Set the die's sibling
4354 field to NULL; set other fields in the die correctly, and set all
4355 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4356 location of the info_ptr after reading all of those dies. PARENT
4357 is the parent of the die in question. */
4359 static struct die_info
*
4360 read_die_and_children (char *info_ptr
, bfd
*abfd
,
4361 struct dwarf2_cu
*cu
,
4362 char **new_info_ptr
,
4363 struct die_info
*parent
)
4365 struct die_info
*die
;
4369 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
4370 store_in_ref_table (die
->offset
, die
);
4374 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
4380 *new_info_ptr
= cur_ptr
;
4383 die
->sibling
= NULL
;
4384 die
->parent
= parent
;
4388 /* Read a die, all of its descendents, and all of its siblings; set
4389 all of the fields of all of the dies correctly. Arguments are as
4390 in read_die_and_children. */
4392 static struct die_info
*
4393 read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
4394 struct dwarf2_cu
*cu
,
4395 char **new_info_ptr
,
4396 struct die_info
*parent
)
4398 struct die_info
*first_die
, *last_sibling
;
4402 first_die
= last_sibling
= NULL
;
4406 struct die_info
*die
4407 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
4415 last_sibling
->sibling
= die
;
4420 *new_info_ptr
= cur_ptr
;
4430 /* Free a linked list of dies. */
4433 free_die_list (struct die_info
*dies
)
4435 struct die_info
*die
, *next
;
4440 if (die
->child
!= NULL
)
4441 free_die_list (die
->child
);
4442 next
= die
->sibling
;
4450 do_free_die_list_cleanup (void *dies
)
4452 free_die_list (dies
);
4455 static struct cleanup
*
4456 make_cleanup_free_die_list (struct die_info
*dies
)
4458 return make_cleanup (do_free_die_list_cleanup
, dies
);
4462 /* Read the contents of the section at OFFSET and of size SIZE from the
4463 object file specified by OBJFILE into the objfile_obstack and return it. */
4466 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
4468 bfd
*abfd
= objfile
->obfd
;
4470 bfd_size_type size
= bfd_get_section_size_before_reloc (sectp
);
4475 buf
= (char *) obstack_alloc (&objfile
->objfile_obstack
, size
);
4477 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
4481 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
4482 || bfd_bread (buf
, size
, abfd
) != size
)
4483 error ("Dwarf Error: Can't read DWARF data from '%s'",
4484 bfd_get_filename (abfd
));
4489 /* In DWARF version 2, the description of the debugging information is
4490 stored in a separate .debug_abbrev section. Before we read any
4491 dies from a section we read in all abbreviations and install them
4492 in a hash table. This function also sets flags in CU describing
4493 the data found in the abbrev table. */
4496 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
4498 struct comp_unit_head
*cu_header
= &cu
->header
;
4500 struct abbrev_info
*cur_abbrev
;
4501 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
4502 unsigned int abbrev_form
, hash_number
;
4503 struct attr_abbrev
*cur_attrs
;
4504 unsigned int allocated_attrs
;
4506 /* Initialize dwarf2 abbrevs */
4507 obstack_init (&cu
->abbrev_obstack
);
4508 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
4510 * sizeof (struct abbrev_info
*)));
4511 memset (cu
->dwarf2_abbrevs
, 0,
4512 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
4514 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
4515 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4516 abbrev_ptr
+= bytes_read
;
4518 allocated_attrs
= ATTR_ALLOC_CHUNK
;
4519 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
4521 /* loop until we reach an abbrev number of 0 */
4522 while (abbrev_number
)
4524 cur_abbrev
= dwarf_alloc_abbrev (cu
);
4526 /* read in abbrev header */
4527 cur_abbrev
->number
= abbrev_number
;
4528 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4529 abbrev_ptr
+= bytes_read
;
4530 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
4533 if (cur_abbrev
->tag
== DW_TAG_namespace
)
4534 cu
->has_namespace_info
= 1;
4536 /* now read in declarations */
4537 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4538 abbrev_ptr
+= bytes_read
;
4539 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4540 abbrev_ptr
+= bytes_read
;
4543 if (cur_abbrev
->num_attrs
== allocated_attrs
)
4545 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
4547 = xrealloc (cur_attrs
, (allocated_attrs
4548 * sizeof (struct attr_abbrev
)));
4550 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
4551 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
4552 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4553 abbrev_ptr
+= bytes_read
;
4554 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4555 abbrev_ptr
+= bytes_read
;
4558 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
4559 (cur_abbrev
->num_attrs
4560 * sizeof (struct attr_abbrev
)));
4561 memcpy (cur_abbrev
->attrs
, cur_attrs
,
4562 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
4564 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
4565 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
4566 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
4568 /* Get next abbreviation.
4569 Under Irix6 the abbreviations for a compilation unit are not
4570 always properly terminated with an abbrev number of 0.
4571 Exit loop if we encounter an abbreviation which we have
4572 already read (which means we are about to read the abbreviations
4573 for the next compile unit) or if the end of the abbreviation
4574 table is reached. */
4575 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
4576 >= dwarf2_per_objfile
->abbrev_size
)
4578 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4579 abbrev_ptr
+= bytes_read
;
4580 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
4587 /* Release the memory used by the abbrev table for a compilation unit. */
4590 dwarf2_free_abbrev_table (void *ptr_to_cu
)
4592 struct dwarf2_cu
*cu
= ptr_to_cu
;
4594 obstack_free (&cu
->abbrev_obstack
, NULL
);
4595 cu
->dwarf2_abbrevs
= NULL
;
4598 /* Lookup an abbrev_info structure in the abbrev hash table. */
4600 static struct abbrev_info
*
4601 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
4603 unsigned int hash_number
;
4604 struct abbrev_info
*abbrev
;
4606 hash_number
= number
% ABBREV_HASH_SIZE
;
4607 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
4611 if (abbrev
->number
== number
)
4614 abbrev
= abbrev
->next
;
4619 /* Returns nonzero if TAG represents a type that we might generate a partial
4623 is_type_tag_for_partial (int tag
)
4628 /* Some types that would be reasonable to generate partial symbols for,
4629 that we don't at present. */
4630 case DW_TAG_array_type
:
4631 case DW_TAG_file_type
:
4632 case DW_TAG_ptr_to_member_type
:
4633 case DW_TAG_set_type
:
4634 case DW_TAG_string_type
:
4635 case DW_TAG_subroutine_type
:
4637 case DW_TAG_base_type
:
4638 case DW_TAG_class_type
:
4639 case DW_TAG_enumeration_type
:
4640 case DW_TAG_structure_type
:
4641 case DW_TAG_subrange_type
:
4642 case DW_TAG_typedef
:
4643 case DW_TAG_union_type
:
4650 /* Load all DIEs that are interesting for partial symbols into memory. */
4652 static struct partial_die_info
*
4653 load_partial_dies (bfd
*abfd
, char *info_ptr
, int building_psymtab
,
4654 struct dwarf2_cu
*cu
)
4656 struct partial_die_info
*part_die
;
4657 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
4658 struct abbrev_info
*abbrev
;
4659 unsigned int bytes_read
;
4661 int nesting_level
= 1;
4667 = htab_create_alloc_ex (cu
->header
.length
/ 12,
4671 &cu
->comp_unit_obstack
,
4672 hashtab_obstack_allocate
,
4673 dummy_obstack_deallocate
);
4675 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
4676 sizeof (struct partial_die_info
));
4680 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4682 /* A NULL abbrev means the end of a series of children. */
4685 if (--nesting_level
== 0)
4687 /* PART_DIE was probably the last thing allocated on the
4688 comp_unit_obstack, so we could call obstack_free
4689 here. We don't do that because the waste is small,
4690 and will be cleaned up when we're done with this
4691 compilation unit. This way, we're also more robust
4692 against other users of the comp_unit_obstack. */
4695 info_ptr
+= bytes_read
;
4696 last_die
= parent_die
;
4697 parent_die
= parent_die
->die_parent
;
4701 /* Check whether this DIE is interesting enough to save. */
4702 if (!is_type_tag_for_partial (abbrev
->tag
)
4703 && abbrev
->tag
!= DW_TAG_enumerator
4704 && abbrev
->tag
!= DW_TAG_subprogram
4705 && abbrev
->tag
!= DW_TAG_variable
4706 && abbrev
->tag
!= DW_TAG_namespace
)
4708 /* Otherwise we skip to the next sibling, if any. */
4709 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
4713 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
4714 abfd
, info_ptr
, cu
);
4716 /* This two-pass algorithm for processing partial symbols has a
4717 high cost in cache pressure. Thus, handle some simple cases
4718 here which cover the majority of C partial symbols. DIEs
4719 which neither have specification tags in them, nor could have
4720 specification tags elsewhere pointing at them, can simply be
4721 processed and discarded.
4723 This segment is also optional; scan_partial_symbols and
4724 add_partial_symbol will handle these DIEs if we chain
4725 them in normally. When compilers which do not emit large
4726 quantities of duplicate debug information are more common,
4727 this code can probably be removed. */
4729 /* Any complete simple types at the top level (pretty much all
4730 of them, for a language without namespaces), can be processed
4732 if (parent_die
== NULL
4733 && part_die
->has_specification
== 0
4734 && part_die
->is_declaration
== 0
4735 && (part_die
->tag
== DW_TAG_typedef
4736 || part_die
->tag
== DW_TAG_base_type
4737 || part_die
->tag
== DW_TAG_subrange_type
))
4739 if (building_psymtab
&& part_die
->name
!= NULL
)
4740 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
4741 VAR_DOMAIN
, LOC_TYPEDEF
,
4742 &cu
->objfile
->static_psymbols
,
4743 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
4744 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
4748 /* If we're at the second level, and we're an enumerator, and
4749 our parent has no specification (meaning possibly lives in a
4750 namespace elsewhere), then we can add the partial symbol now
4751 instead of queueing it. */
4752 if (part_die
->tag
== DW_TAG_enumerator
4753 && parent_die
!= NULL
4754 && parent_die
->die_parent
== NULL
4755 && parent_die
->tag
== DW_TAG_enumeration_type
4756 && parent_die
->has_specification
== 0)
4758 if (part_die
->name
== NULL
)
4759 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
4760 else if (building_psymtab
)
4761 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
4762 VAR_DOMAIN
, LOC_CONST
,
4763 cu
->language
== language_cplus
4764 ? &cu
->objfile
->global_psymbols
4765 : &cu
->objfile
->static_psymbols
,
4766 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
4768 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
4772 /* We'll save this DIE so link it in. */
4773 part_die
->die_parent
= parent_die
;
4774 part_die
->die_sibling
= NULL
;
4775 part_die
->die_child
= NULL
;
4777 if (last_die
&& last_die
== parent_die
)
4778 last_die
->die_child
= part_die
;
4780 last_die
->die_sibling
= part_die
;
4782 last_die
= part_die
;
4784 if (first_die
== NULL
)
4785 first_die
= part_die
;
4787 /* Maybe add the DIE to the hash table. Not all DIEs that we
4788 find interesting need to be in the hash table, because we
4789 also have the parent/sibling/child chains; only those that we
4790 might refer to by offset later during partial symbol reading.
4792 For now this means things that might have be the target of a
4793 DW_AT_specification, DW_AT_abstract_origin, or
4794 DW_AT_extension. DW_AT_extension will refer only to
4795 namespaces; DW_AT_abstract_origin refers to functions (and
4796 many things under the function DIE, but we do not recurse
4797 into function DIEs during partial symbol reading) and
4798 possibly variables as well; DW_AT_specification refers to
4799 declarations. Declarations ought to have the DW_AT_declaration
4800 flag. It happens that GCC forgets to put it in sometimes, but
4801 only for functions, not for types.
4803 Adding more things than necessary to the hash table is harmless
4804 except for the performance cost. Adding too few will result in
4805 internal errors in find_partial_die. */
4807 if (abbrev
->tag
== DW_TAG_subprogram
4808 || abbrev
->tag
== DW_TAG_variable
4809 || abbrev
->tag
== DW_TAG_namespace
4810 || part_die
->is_declaration
)
4814 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
4815 part_die
->offset
, INSERT
);
4819 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
4820 sizeof (struct partial_die_info
));
4822 /* For some DIEs we want to follow their children (if any). For C
4823 we have no reason to follow the children of structures; for other
4824 languages we have to, both so that we can get at method physnames
4825 to infer fully qualified class names, and for DW_AT_specification. */
4826 if (last_die
->has_children
4827 && (last_die
->tag
== DW_TAG_namespace
4828 || last_die
->tag
== DW_TAG_enumeration_type
4829 || (cu
->language
!= language_c
4830 && (last_die
->tag
== DW_TAG_class_type
4831 || last_die
->tag
== DW_TAG_structure_type
4832 || last_die
->tag
== DW_TAG_union_type
))))
4835 parent_die
= last_die
;
4839 /* Otherwise we skip to the next sibling, if any. */
4840 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
4842 /* Back to the top, do it again. */
4846 /* Read a minimal amount of information into the minimal die structure. */
4849 read_partial_die (struct partial_die_info
*part_die
,
4850 struct abbrev_info
*abbrev
,
4851 unsigned int abbrev_len
, bfd
*abfd
,
4852 char *info_ptr
, struct dwarf2_cu
*cu
)
4854 unsigned int bytes_read
, i
;
4855 struct attribute attr
;
4856 int has_low_pc_attr
= 0;
4857 int has_high_pc_attr
= 0;
4859 memset (part_die
, 0, sizeof (struct partial_die_info
));
4861 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
4863 info_ptr
+= abbrev_len
;
4868 part_die
->tag
= abbrev
->tag
;
4869 part_die
->has_children
= abbrev
->has_children
;
4871 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4873 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
4875 /* Store the data if it is of an attribute we want to keep in a
4876 partial symbol table. */
4881 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
4882 if (part_die
->name
== NULL
)
4883 part_die
->name
= DW_STRING (&attr
);
4885 case DW_AT_MIPS_linkage_name
:
4886 part_die
->name
= DW_STRING (&attr
);
4889 has_low_pc_attr
= 1;
4890 part_die
->lowpc
= DW_ADDR (&attr
);
4893 has_high_pc_attr
= 1;
4894 part_die
->highpc
= DW_ADDR (&attr
);
4896 case DW_AT_location
:
4897 /* Support the .debug_loc offsets */
4898 if (attr_form_is_block (&attr
))
4900 part_die
->locdesc
= DW_BLOCK (&attr
);
4902 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
4904 dwarf2_complex_location_expr_complaint ();
4908 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4909 "partial symbol information");
4912 case DW_AT_language
:
4913 part_die
->language
= DW_UNSND (&attr
);
4915 case DW_AT_external
:
4916 part_die
->is_external
= DW_UNSND (&attr
);
4918 case DW_AT_declaration
:
4919 part_die
->is_declaration
= DW_UNSND (&attr
);
4922 part_die
->has_type
= 1;
4924 case DW_AT_abstract_origin
:
4925 case DW_AT_specification
:
4926 case DW_AT_extension
:
4927 part_die
->has_specification
= 1;
4928 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
4931 /* Ignore absolute siblings, they might point outside of
4932 the current compile unit. */
4933 if (attr
.form
== DW_FORM_ref_addr
)
4934 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
4936 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
4937 + dwarf2_get_ref_die_offset (&attr
, cu
);
4939 case DW_AT_stmt_list
:
4940 part_die
->has_stmt_list
= 1;
4941 part_die
->line_offset
= DW_UNSND (&attr
);
4948 /* When using the GNU linker, .gnu.linkonce. sections are used to
4949 eliminate duplicate copies of functions and vtables and such.
4950 The linker will arbitrarily choose one and discard the others.
4951 The AT_*_pc values for such functions refer to local labels in
4952 these sections. If the section from that file was discarded, the
4953 labels are not in the output, so the relocs get a value of 0.
4954 If this is a discarded function, mark the pc bounds as invalid,
4955 so that GDB will ignore it. */
4956 if (has_low_pc_attr
&& has_high_pc_attr
4957 && part_die
->lowpc
< part_die
->highpc
4958 && (part_die
->lowpc
!= 0
4959 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
4960 part_die
->has_pc_info
= 1;
4964 /* Find a cached partial DIE at OFFSET in CU. */
4966 static struct partial_die_info
*
4967 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
4969 struct partial_die_info
*lookup_die
= NULL
;
4970 struct partial_die_info part_die
;
4972 part_die
.offset
= offset
;
4973 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
4975 if (lookup_die
== NULL
)
4976 internal_error (__FILE__
, __LINE__
,
4977 "could not find partial DIE in cache\n");
4982 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
4984 static struct partial_die_info
*
4985 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
,
4986 struct dwarf2_cu
**target_cu
)
4988 struct dwarf2_per_cu_data
*per_cu
;
4990 if (offset
>= cu
->header
.offset
4991 && offset
< cu
->header
.offset
+ cu
->header
.length
)
4994 return find_partial_die_in_comp_unit (offset
, cu
);
4997 internal_error (__FILE__
, __LINE__
,
4998 "unsupported inter-compilation-unit reference");
5001 /* Adjust PART_DIE before generating a symbol for it. This function
5002 may set the is_external flag or change the DIE's name. */
5005 fixup_partial_die (struct partial_die_info
*part_die
,
5006 struct dwarf2_cu
*cu
)
5008 /* If we found a reference attribute and the DIE has no name, try
5009 to find a name in the referred to DIE. */
5011 if (part_die
->name
== NULL
&& part_die
->has_specification
)
5013 struct partial_die_info
*spec_die
;
5014 struct dwarf2_cu
*spec_cu
;
5016 spec_die
= find_partial_die (part_die
->spec_offset
, cu
, &spec_cu
);
5018 fixup_partial_die (spec_die
, spec_cu
);
5022 part_die
->name
= spec_die
->name
;
5024 /* Copy DW_AT_external attribute if it is set. */
5025 if (spec_die
->is_external
)
5026 part_die
->is_external
= spec_die
->is_external
;
5030 /* Set default names for some unnamed DIEs. */
5031 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
5032 || part_die
->tag
== DW_TAG_class_type
))
5033 part_die
->name
= "(anonymous class)";
5035 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
5036 part_die
->name
= "(anonymous namespace)";
5038 if (part_die
->tag
== DW_TAG_structure_type
5039 || part_die
->tag
== DW_TAG_class_type
5040 || part_die
->tag
== DW_TAG_union_type
)
5041 guess_structure_name (part_die
, cu
);
5044 /* Read the die from the .debug_info section buffer. Set DIEP to
5045 point to a newly allocated die with its information, except for its
5046 child, sibling, and parent fields. Set HAS_CHILDREN to tell
5047 whether the die has children or not. */
5050 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
5051 struct dwarf2_cu
*cu
, int *has_children
)
5053 unsigned int abbrev_number
, bytes_read
, i
, offset
;
5054 struct abbrev_info
*abbrev
;
5055 struct die_info
*die
;
5057 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5058 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5059 info_ptr
+= bytes_read
;
5062 die
= dwarf_alloc_die ();
5064 die
->abbrev
= abbrev_number
;
5071 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
5074 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
5076 bfd_get_filename (abfd
));
5078 die
= dwarf_alloc_die ();
5079 die
->offset
= offset
;
5080 die
->tag
= abbrev
->tag
;
5081 die
->abbrev
= abbrev_number
;
5084 die
->num_attrs
= abbrev
->num_attrs
;
5085 die
->attrs
= (struct attribute
*)
5086 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
5088 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5090 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
5091 abfd
, info_ptr
, cu
);
5095 *has_children
= abbrev
->has_children
;
5099 /* Read an attribute value described by an attribute form. */
5102 read_attribute_value (struct attribute
*attr
, unsigned form
,
5103 bfd
*abfd
, char *info_ptr
,
5104 struct dwarf2_cu
*cu
)
5106 struct comp_unit_head
*cu_header
= &cu
->header
;
5107 unsigned int bytes_read
;
5108 struct dwarf_block
*blk
;
5114 case DW_FORM_ref_addr
:
5115 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
5116 info_ptr
+= bytes_read
;
5118 case DW_FORM_block2
:
5119 blk
= dwarf_alloc_block (cu
);
5120 blk
->size
= read_2_bytes (abfd
, info_ptr
);
5122 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5123 info_ptr
+= blk
->size
;
5124 DW_BLOCK (attr
) = blk
;
5126 case DW_FORM_block4
:
5127 blk
= dwarf_alloc_block (cu
);
5128 blk
->size
= read_4_bytes (abfd
, info_ptr
);
5130 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5131 info_ptr
+= blk
->size
;
5132 DW_BLOCK (attr
) = blk
;
5135 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
5139 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
5143 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
5146 case DW_FORM_string
:
5147 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
5148 info_ptr
+= bytes_read
;
5151 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
5153 info_ptr
+= bytes_read
;
5156 blk
= dwarf_alloc_block (cu
);
5157 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5158 info_ptr
+= bytes_read
;
5159 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5160 info_ptr
+= blk
->size
;
5161 DW_BLOCK (attr
) = blk
;
5163 case DW_FORM_block1
:
5164 blk
= dwarf_alloc_block (cu
);
5165 blk
->size
= read_1_byte (abfd
, info_ptr
);
5167 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5168 info_ptr
+= blk
->size
;
5169 DW_BLOCK (attr
) = blk
;
5172 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5176 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5180 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
5181 info_ptr
+= bytes_read
;
5184 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5185 info_ptr
+= bytes_read
;
5188 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5192 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
5196 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
5200 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
5203 case DW_FORM_ref_udata
:
5204 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5205 info_ptr
+= bytes_read
;
5207 case DW_FORM_indirect
:
5208 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5209 info_ptr
+= bytes_read
;
5210 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
5213 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
5214 dwarf_form_name (form
),
5215 bfd_get_filename (abfd
));
5220 /* Read an attribute described by an abbreviated attribute. */
5223 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
5224 bfd
*abfd
, char *info_ptr
, struct dwarf2_cu
*cu
)
5226 attr
->name
= abbrev
->name
;
5227 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
5230 /* read dwarf information from a buffer */
5233 read_1_byte (bfd
*abfd
, char *buf
)
5235 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5239 read_1_signed_byte (bfd
*abfd
, char *buf
)
5241 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
5245 read_2_bytes (bfd
*abfd
, char *buf
)
5247 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
5251 read_2_signed_bytes (bfd
*abfd
, char *buf
)
5253 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
5257 read_4_bytes (bfd
*abfd
, char *buf
)
5259 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5263 read_4_signed_bytes (bfd
*abfd
, char *buf
)
5265 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
5268 static unsigned long
5269 read_8_bytes (bfd
*abfd
, char *buf
)
5271 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5275 read_address (bfd
*abfd
, char *buf
, struct dwarf2_cu
*cu
, int *bytes_read
)
5277 struct comp_unit_head
*cu_header
= &cu
->header
;
5278 CORE_ADDR retval
= 0;
5280 if (cu_header
->signed_addr_p
)
5282 switch (cu_header
->addr_size
)
5285 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
5288 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
5291 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
5294 internal_error (__FILE__
, __LINE__
,
5295 "read_address: bad switch, signed [in module %s]",
5296 bfd_get_filename (abfd
));
5301 switch (cu_header
->addr_size
)
5304 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
5307 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5310 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5313 internal_error (__FILE__
, __LINE__
,
5314 "read_address: bad switch, unsigned [in module %s]",
5315 bfd_get_filename (abfd
));
5319 *bytes_read
= cu_header
->addr_size
;
5323 /* Read the initial length from a section. The (draft) DWARF 3
5324 specification allows the initial length to take up either 4 bytes
5325 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
5326 bytes describe the length and all offsets will be 8 bytes in length
5329 An older, non-standard 64-bit format is also handled by this
5330 function. The older format in question stores the initial length
5331 as an 8-byte quantity without an escape value. Lengths greater
5332 than 2^32 aren't very common which means that the initial 4 bytes
5333 is almost always zero. Since a length value of zero doesn't make
5334 sense for the 32-bit format, this initial zero can be considered to
5335 be an escape value which indicates the presence of the older 64-bit
5336 format. As written, the code can't detect (old format) lengths
5337 greater than 4GB. If it becomes necessary to handle lengths somewhat
5338 larger than 4GB, we could allow other small values (such as the
5339 non-sensical values of 1, 2, and 3) to also be used as escape values
5340 indicating the presence of the old format.
5342 The value returned via bytes_read should be used to increment
5343 the relevant pointer after calling read_initial_length().
5345 As a side effect, this function sets the fields initial_length_size
5346 and offset_size in cu_header to the values appropriate for the
5347 length field. (The format of the initial length field determines
5348 the width of file offsets to be fetched later with fetch_offset().)
5350 [ Note: read_initial_length() and read_offset() are based on the
5351 document entitled "DWARF Debugging Information Format", revision
5352 3, draft 8, dated November 19, 2001. This document was obtained
5355 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
5357 This document is only a draft and is subject to change. (So beware.)
5359 Details regarding the older, non-standard 64-bit format were
5360 determined empirically by examining 64-bit ELF files produced
5361 by the SGI toolchain on an IRIX 6.5 machine.
5363 - Kevin, July 16, 2002
5367 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
5372 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5374 if (retval
== 0xffffffff)
5376 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
5378 if (cu_header
!= NULL
)
5380 cu_header
->initial_length_size
= 12;
5381 cu_header
->offset_size
= 8;
5384 else if (retval
== 0)
5386 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
5388 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5390 if (cu_header
!= NULL
)
5392 cu_header
->initial_length_size
= 8;
5393 cu_header
->offset_size
= 8;
5399 if (cu_header
!= NULL
)
5401 cu_header
->initial_length_size
= 4;
5402 cu_header
->offset_size
= 4;
5409 /* Read an offset from the data stream. The size of the offset is
5410 given by cu_header->offset_size. */
5413 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
5418 switch (cu_header
->offset_size
)
5421 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5425 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5429 internal_error (__FILE__
, __LINE__
,
5430 "read_offset: bad switch [in module %s]",
5431 bfd_get_filename (abfd
));
5438 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
5440 /* If the size of a host char is 8 bits, we can return a pointer
5441 to the buffer, otherwise we have to copy the data to a buffer
5442 allocated on the temporary obstack. */
5443 gdb_assert (HOST_CHAR_BIT
== 8);
5448 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5450 /* If the size of a host char is 8 bits, we can return a pointer
5451 to the string, otherwise we have to copy the string to a buffer
5452 allocated on the temporary obstack. */
5453 gdb_assert (HOST_CHAR_BIT
== 8);
5456 *bytes_read_ptr
= 1;
5459 *bytes_read_ptr
= strlen (buf
) + 1;
5464 read_indirect_string (bfd
*abfd
, char *buf
,
5465 const struct comp_unit_head
*cu_header
,
5466 unsigned int *bytes_read_ptr
)
5468 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
5469 (int *) bytes_read_ptr
);
5471 if (dwarf2_per_objfile
->str_buffer
== NULL
)
5473 error ("DW_FORM_strp used without .debug_str section [in module %s]",
5474 bfd_get_filename (abfd
));
5477 if (str_offset
>= dwarf2_per_objfile
->str_size
)
5479 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
5480 bfd_get_filename (abfd
));
5483 gdb_assert (HOST_CHAR_BIT
== 8);
5484 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
5486 return dwarf2_per_objfile
->str_buffer
+ str_offset
;
5489 static unsigned long
5490 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5492 unsigned long result
;
5493 unsigned int num_read
;
5503 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5506 result
|= ((unsigned long)(byte
& 127) << shift
);
5507 if ((byte
& 128) == 0)
5513 *bytes_read_ptr
= num_read
;
5518 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5521 int i
, shift
, size
, num_read
;
5531 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5534 result
|= ((long)(byte
& 127) << shift
);
5536 if ((byte
& 128) == 0)
5541 if ((shift
< size
) && (byte
& 0x40))
5543 result
|= -(1 << shift
);
5545 *bytes_read_ptr
= num_read
;
5549 /* Return a pointer to just past the end of an LEB128 number in BUF. */
5552 skip_leb128 (bfd
*abfd
, char *buf
)
5558 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5560 if ((byte
& 128) == 0)
5566 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
5572 cu
->language
= language_c
;
5574 case DW_LANG_C_plus_plus
:
5575 cu
->language
= language_cplus
;
5577 case DW_LANG_Fortran77
:
5578 case DW_LANG_Fortran90
:
5579 case DW_LANG_Fortran95
:
5580 cu
->language
= language_fortran
;
5582 case DW_LANG_Mips_Assembler
:
5583 cu
->language
= language_asm
;
5586 cu
->language
= language_java
;
5590 case DW_LANG_Cobol74
:
5591 case DW_LANG_Cobol85
:
5592 case DW_LANG_Pascal83
:
5593 case DW_LANG_Modula2
:
5595 cu
->language
= language_minimal
;
5598 cu
->language_defn
= language_def (cu
->language
);
5601 /* Return the named attribute or NULL if not there. */
5603 static struct attribute
*
5604 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
5607 struct attribute
*spec
= NULL
;
5609 for (i
= 0; i
< die
->num_attrs
; ++i
)
5611 if (die
->attrs
[i
].name
== name
)
5613 return &die
->attrs
[i
];
5615 if (die
->attrs
[i
].name
== DW_AT_specification
5616 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
5617 spec
= &die
->attrs
[i
];
5621 struct die_info
*ref_die
=
5622 follow_die_ref (dwarf2_get_ref_die_offset (spec
, cu
));
5625 return dwarf2_attr (ref_die
, name
, cu
);
5631 /* Return non-zero iff the attribute NAME is defined for the given DIE,
5632 and holds a non-zero value. This function should only be used for
5633 DW_FORM_flag attributes. */
5636 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
5638 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
5640 return (attr
&& DW_UNSND (attr
));
5644 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
5646 /* A DIE is a declaration if it has a DW_AT_declaration attribute
5647 which value is non-zero. However, we have to be careful with
5648 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
5649 (via dwarf2_flag_true_p) follows this attribute. So we may
5650 end up accidently finding a declaration attribute that belongs
5651 to a different DIE referenced by the specification attribute,
5652 even though the given DIE does not have a declaration attribute. */
5653 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
5654 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
5657 /* Return the die giving the specification for DIE, if there is
5660 static struct die_info
*
5661 die_specification (struct die_info
*die
, struct dwarf2_cu
*cu
)
5663 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
, cu
);
5665 if (spec_attr
== NULL
)
5668 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr
, cu
));
5671 /* Free the line_header structure *LH, and any arrays and strings it
5674 free_line_header (struct line_header
*lh
)
5676 if (lh
->standard_opcode_lengths
)
5677 xfree (lh
->standard_opcode_lengths
);
5679 /* Remember that all the lh->file_names[i].name pointers are
5680 pointers into debug_line_buffer, and don't need to be freed. */
5682 xfree (lh
->file_names
);
5684 /* Similarly for the include directory names. */
5685 if (lh
->include_dirs
)
5686 xfree (lh
->include_dirs
);
5692 /* Add an entry to LH's include directory table. */
5694 add_include_dir (struct line_header
*lh
, char *include_dir
)
5696 /* Grow the array if necessary. */
5697 if (lh
->include_dirs_size
== 0)
5699 lh
->include_dirs_size
= 1; /* for testing */
5700 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
5701 * sizeof (*lh
->include_dirs
));
5703 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
5705 lh
->include_dirs_size
*= 2;
5706 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
5707 (lh
->include_dirs_size
5708 * sizeof (*lh
->include_dirs
)));
5711 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
5715 /* Add an entry to LH's file name table. */
5717 add_file_name (struct line_header
*lh
,
5719 unsigned int dir_index
,
5720 unsigned int mod_time
,
5721 unsigned int length
)
5723 struct file_entry
*fe
;
5725 /* Grow the array if necessary. */
5726 if (lh
->file_names_size
== 0)
5728 lh
->file_names_size
= 1; /* for testing */
5729 lh
->file_names
= xmalloc (lh
->file_names_size
5730 * sizeof (*lh
->file_names
));
5732 else if (lh
->num_file_names
>= lh
->file_names_size
)
5734 lh
->file_names_size
*= 2;
5735 lh
->file_names
= xrealloc (lh
->file_names
,
5736 (lh
->file_names_size
5737 * sizeof (*lh
->file_names
)));
5740 fe
= &lh
->file_names
[lh
->num_file_names
++];
5742 fe
->dir_index
= dir_index
;
5743 fe
->mod_time
= mod_time
;
5744 fe
->length
= length
;
5749 /* Read the statement program header starting at OFFSET in
5750 .debug_line, according to the endianness of ABFD. Return a pointer
5751 to a struct line_header, allocated using xmalloc.
5753 NOTE: the strings in the include directory and file name tables of
5754 the returned object point into debug_line_buffer, and must not be
5756 static struct line_header
*
5757 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
5758 struct dwarf2_cu
*cu
)
5760 struct cleanup
*back_to
;
5761 struct line_header
*lh
;
5765 char *cur_dir
, *cur_file
;
5767 if (dwarf2_per_objfile
->line_buffer
== NULL
)
5769 complaint (&symfile_complaints
, "missing .debug_line section");
5773 /* Make sure that at least there's room for the total_length field. That
5774 could be 12 bytes long, but we're just going to fudge that. */
5775 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
5777 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5781 lh
= xmalloc (sizeof (*lh
));
5782 memset (lh
, 0, sizeof (*lh
));
5783 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
5786 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
5788 /* read in the header */
5789 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
5790 line_ptr
+= bytes_read
;
5791 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
5792 + dwarf2_per_objfile
->line_size
))
5794 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5797 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
5798 lh
->version
= read_2_bytes (abfd
, line_ptr
);
5800 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
5801 line_ptr
+= bytes_read
;
5802 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
5804 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
5806 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
5808 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
5810 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
5812 lh
->standard_opcode_lengths
5813 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
5815 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
5816 for (i
= 1; i
< lh
->opcode_base
; ++i
)
5818 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
5822 /* Read directory table */
5823 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5825 line_ptr
+= bytes_read
;
5826 add_include_dir (lh
, cur_dir
);
5828 line_ptr
+= bytes_read
;
5830 /* Read file name table */
5831 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5833 unsigned int dir_index
, mod_time
, length
;
5835 line_ptr
+= bytes_read
;
5836 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5837 line_ptr
+= bytes_read
;
5838 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5839 line_ptr
+= bytes_read
;
5840 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5841 line_ptr
+= bytes_read
;
5843 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5845 line_ptr
+= bytes_read
;
5846 lh
->statement_program_start
= line_ptr
;
5848 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
5849 + dwarf2_per_objfile
->line_size
))
5850 complaint (&symfile_complaints
,
5851 "line number info header doesn't fit in `.debug_line' section");
5853 discard_cleanups (back_to
);
5857 /* This function exists to work around a bug in certain compilers
5858 (particularly GCC 2.95), in which the first line number marker of a
5859 function does not show up until after the prologue, right before
5860 the second line number marker. This function shifts ADDRESS down
5861 to the beginning of the function if necessary, and is called on
5862 addresses passed to record_line. */
5865 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
5867 struct function_range
*fn
;
5869 /* Find the function_range containing address. */
5874 cu
->cached_fn
= cu
->first_fn
;
5878 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5884 while (fn
&& fn
!= cu
->cached_fn
)
5885 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5895 if (address
!= fn
->lowpc
)
5896 complaint (&symfile_complaints
,
5897 "misplaced first line number at 0x%lx for '%s'",
5898 (unsigned long) address
, fn
->name
);
5903 /* Decode the Line Number Program (LNP) for the given line_header
5904 structure and CU. The actual information extracted and the type
5905 of structures created from the LNP depends on the value of PST.
5907 1. If PST is NULL, then this procedure uses the data from the program
5908 to create all necessary symbol tables, and their linetables.
5909 The compilation directory of the file is passed in COMP_DIR,
5910 and must not be NULL.
5912 2. If PST is not NULL, this procedure reads the program to determine
5913 the list of files included by the unit represented by PST, and
5914 builds all the associated partial symbol tables. In this case,
5915 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
5916 is not used to compute the full name of the symtab, and therefore
5917 omitting it when building the partial symtab does not introduce
5918 the potential for inconsistency - a partial symtab and its associated
5919 symbtab having a different fullname -). */
5922 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
5923 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
5927 unsigned int bytes_read
;
5928 unsigned char op_code
, extended_op
, adj_opcode
;
5930 struct objfile
*objfile
= cu
->objfile
;
5931 const int decode_for_pst_p
= (pst
!= NULL
);
5933 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5935 line_ptr
= lh
->statement_program_start
;
5936 line_end
= lh
->statement_program_end
;
5938 /* Read the statement sequences until there's nothing left. */
5939 while (line_ptr
< line_end
)
5941 /* state machine registers */
5942 CORE_ADDR address
= 0;
5943 unsigned int file
= 1;
5944 unsigned int line
= 1;
5945 unsigned int column
= 0;
5946 int is_stmt
= lh
->default_is_stmt
;
5947 int basic_block
= 0;
5948 int end_sequence
= 0;
5950 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
5952 /* Start a subfile for the current file of the state machine. */
5953 /* lh->include_dirs and lh->file_names are 0-based, but the
5954 directory and file name numbers in the statement program
5956 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
5959 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5962 dwarf2_start_subfile (fe
->name
, dir
);
5965 /* Decode the table. */
5966 while (!end_sequence
)
5968 op_code
= read_1_byte (abfd
, line_ptr
);
5971 if (op_code
>= lh
->opcode_base
)
5972 { /* Special operand. */
5973 adj_opcode
= op_code
- lh
->opcode_base
;
5974 address
+= (adj_opcode
/ lh
->line_range
)
5975 * lh
->minimum_instruction_length
;
5976 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
5977 if (!decode_for_pst_p
)
5979 /* append row to matrix using current values */
5980 record_line (current_subfile
, line
,
5981 check_cu_functions (address
, cu
));
5985 else switch (op_code
)
5987 case DW_LNS_extended_op
:
5988 line_ptr
+= 1; /* ignore length */
5989 extended_op
= read_1_byte (abfd
, line_ptr
);
5991 switch (extended_op
)
5993 case DW_LNE_end_sequence
:
5995 if (!decode_for_pst_p
)
5996 record_line (current_subfile
, 0, address
);
5998 case DW_LNE_set_address
:
5999 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
6000 line_ptr
+= bytes_read
;
6001 address
+= baseaddr
;
6003 case DW_LNE_define_file
:
6006 unsigned int dir_index
, mod_time
, length
;
6008 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
6009 line_ptr
+= bytes_read
;
6011 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6012 line_ptr
+= bytes_read
;
6014 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6015 line_ptr
+= bytes_read
;
6017 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6018 line_ptr
+= bytes_read
;
6019 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6023 complaint (&symfile_complaints
,
6024 "mangled .debug_line section");
6029 if (!decode_for_pst_p
)
6030 record_line (current_subfile
, line
,
6031 check_cu_functions (address
, cu
));
6034 case DW_LNS_advance_pc
:
6035 address
+= lh
->minimum_instruction_length
6036 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6037 line_ptr
+= bytes_read
;
6039 case DW_LNS_advance_line
:
6040 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
6041 line_ptr
+= bytes_read
;
6043 case DW_LNS_set_file
:
6045 /* lh->include_dirs and lh->file_names are 0-based,
6046 but the directory and file name numbers in the
6047 statement program are 1-based. */
6048 struct file_entry
*fe
;
6050 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6051 line_ptr
+= bytes_read
;
6052 fe
= &lh
->file_names
[file
- 1];
6055 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6058 if (!decode_for_pst_p
)
6059 dwarf2_start_subfile (fe
->name
, dir
);
6062 case DW_LNS_set_column
:
6063 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6064 line_ptr
+= bytes_read
;
6066 case DW_LNS_negate_stmt
:
6067 is_stmt
= (!is_stmt
);
6069 case DW_LNS_set_basic_block
:
6072 /* Add to the address register of the state machine the
6073 address increment value corresponding to special opcode
6074 255. Ie, this value is scaled by the minimum instruction
6075 length since special opcode 255 would have scaled the
6077 case DW_LNS_const_add_pc
:
6078 address
+= (lh
->minimum_instruction_length
6079 * ((255 - lh
->opcode_base
) / lh
->line_range
));
6081 case DW_LNS_fixed_advance_pc
:
6082 address
+= read_2_bytes (abfd
, line_ptr
);
6086 { /* Unknown standard opcode, ignore it. */
6088 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
6090 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6091 line_ptr
+= bytes_read
;
6098 if (decode_for_pst_p
)
6102 /* Now that we're done scanning the Line Header Program, we can
6103 create the psymtab of each included file. */
6104 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
6105 if (lh
->file_names
[file_index
].included_p
== 1)
6107 char *include_name
= lh
->file_names
[file_index
].name
;
6109 if (strcmp (include_name
, pst
->filename
) != 0)
6110 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
6115 /* Start a subfile for DWARF. FILENAME is the name of the file and
6116 DIRNAME the name of the source directory which contains FILENAME
6117 or NULL if not known.
6118 This routine tries to keep line numbers from identical absolute and
6119 relative file names in a common subfile.
6121 Using the `list' example from the GDB testsuite, which resides in
6122 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
6123 of /srcdir/list0.c yields the following debugging information for list0.c:
6125 DW_AT_name: /srcdir/list0.c
6126 DW_AT_comp_dir: /compdir
6127 files.files[0].name: list0.h
6128 files.files[0].dir: /srcdir
6129 files.files[1].name: list0.c
6130 files.files[1].dir: /srcdir
6132 The line number information for list0.c has to end up in a single
6133 subfile, so that `break /srcdir/list0.c:1' works as expected. */
6136 dwarf2_start_subfile (char *filename
, char *dirname
)
6138 /* If the filename isn't absolute, try to match an existing subfile
6139 with the full pathname. */
6141 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
6143 struct subfile
*subfile
;
6144 char *fullname
= concat (dirname
, "/", filename
, NULL
);
6146 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
6148 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
6150 current_subfile
= subfile
;
6157 start_subfile (filename
, dirname
);
6161 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
6162 struct dwarf2_cu
*cu
)
6164 struct objfile
*objfile
= cu
->objfile
;
6165 struct comp_unit_head
*cu_header
= &cu
->header
;
6167 /* NOTE drow/2003-01-30: There used to be a comment and some special
6168 code here to turn a symbol with DW_AT_external and a
6169 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
6170 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
6171 with some versions of binutils) where shared libraries could have
6172 relocations against symbols in their debug information - the
6173 minimal symbol would have the right address, but the debug info
6174 would not. It's no longer necessary, because we will explicitly
6175 apply relocations when we read in the debug information now. */
6177 /* A DW_AT_location attribute with no contents indicates that a
6178 variable has been optimized away. */
6179 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
6181 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
6185 /* Handle one degenerate form of location expression specially, to
6186 preserve GDB's previous behavior when section offsets are
6187 specified. If this is just a DW_OP_addr then mark this symbol
6190 if (attr_form_is_block (attr
)
6191 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
6192 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
6196 SYMBOL_VALUE_ADDRESS (sym
) =
6197 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
6198 fixup_symbol_section (sym
, objfile
);
6199 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
6200 SYMBOL_SECTION (sym
));
6201 SYMBOL_CLASS (sym
) = LOC_STATIC
;
6205 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
6206 expression evaluator, and use LOC_COMPUTED only when necessary
6207 (i.e. when the value of a register or memory location is
6208 referenced, or a thread-local block, etc.). Then again, it might
6209 not be worthwhile. I'm assuming that it isn't unless performance
6210 or memory numbers show me otherwise. */
6212 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
6213 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
6216 /* Given a pointer to a DWARF information entry, figure out if we need
6217 to make a symbol table entry for it, and if so, create a new entry
6218 and return a pointer to it.
6219 If TYPE is NULL, determine symbol type from the die, otherwise
6220 used the passed type. */
6222 static struct symbol
*
6223 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
6225 struct objfile
*objfile
= cu
->objfile
;
6226 struct symbol
*sym
= NULL
;
6228 struct attribute
*attr
= NULL
;
6229 struct attribute
*attr2
= NULL
;
6232 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6234 if (die
->tag
!= DW_TAG_namespace
)
6235 name
= dwarf2_linkage_name (die
, cu
);
6237 name
= TYPE_NAME (type
);
6241 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
6242 sizeof (struct symbol
));
6243 OBJSTAT (objfile
, n_syms
++);
6244 memset (sym
, 0, sizeof (struct symbol
));
6246 /* Cache this symbol's name and the name's demangled form (if any). */
6247 SYMBOL_LANGUAGE (sym
) = cu
->language
;
6248 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
6250 /* Default assumptions.
6251 Use the passed type or decode it from the die. */
6252 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6253 SYMBOL_CLASS (sym
) = LOC_STATIC
;
6255 SYMBOL_TYPE (sym
) = type
;
6257 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
6258 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
6261 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
6266 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6269 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
6271 SYMBOL_CLASS (sym
) = LOC_LABEL
;
6273 case DW_TAG_subprogram
:
6274 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
6276 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
6277 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6278 if (attr2
&& (DW_UNSND (attr2
) != 0))
6280 add_symbol_to_list (sym
, &global_symbols
);
6284 add_symbol_to_list (sym
, cu
->list_in_scope
);
6287 case DW_TAG_variable
:
6288 /* Compilation with minimal debug info may result in variables
6289 with missing type entries. Change the misleading `void' type
6290 to something sensible. */
6291 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
6292 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
6293 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
6294 "<variable, no debug info>",
6296 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6299 dwarf2_const_value (attr
, sym
, cu
);
6300 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6301 if (attr2
&& (DW_UNSND (attr2
) != 0))
6302 add_symbol_to_list (sym
, &global_symbols
);
6304 add_symbol_to_list (sym
, cu
->list_in_scope
);
6307 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6310 var_decode_location (attr
, sym
, cu
);
6311 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6312 if (attr2
&& (DW_UNSND (attr2
) != 0))
6313 add_symbol_to_list (sym
, &global_symbols
);
6315 add_symbol_to_list (sym
, cu
->list_in_scope
);
6319 /* We do not know the address of this symbol.
6320 If it is an external symbol and we have type information
6321 for it, enter the symbol as a LOC_UNRESOLVED symbol.
6322 The address of the variable will then be determined from
6323 the minimal symbol table whenever the variable is
6325 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6326 if (attr2
&& (DW_UNSND (attr2
) != 0)
6327 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
6329 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
6330 add_symbol_to_list (sym
, &global_symbols
);
6334 case DW_TAG_formal_parameter
:
6335 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6338 var_decode_location (attr
, sym
, cu
);
6339 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
6340 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
6341 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
6343 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6346 dwarf2_const_value (attr
, sym
, cu
);
6348 add_symbol_to_list (sym
, cu
->list_in_scope
);
6350 case DW_TAG_unspecified_parameters
:
6351 /* From varargs functions; gdb doesn't seem to have any
6352 interest in this information, so just ignore it for now.
6355 case DW_TAG_class_type
:
6356 case DW_TAG_structure_type
:
6357 case DW_TAG_union_type
:
6358 case DW_TAG_enumeration_type
:
6359 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6360 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6362 /* Make sure that the symbol includes appropriate enclosing
6363 classes/namespaces in its name. These are calculated in
6364 read_structure_type, and the correct name is saved in
6367 if (cu
->language
== language_cplus
)
6369 struct type
*type
= SYMBOL_TYPE (sym
);
6371 if (TYPE_TAG_NAME (type
) != NULL
)
6373 /* FIXME: carlton/2003-11-10: Should this use
6374 SYMBOL_SET_NAMES instead? (The same problem also
6375 arises further down in this function.) */
6376 /* The type's name is already allocated along with
6377 this objfile, so we don't need to duplicate it
6379 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
6384 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
6385 really ever be static objects: otherwise, if you try
6386 to, say, break of a class's method and you're in a file
6387 which doesn't mention that class, it won't work unless
6388 the check for all static symbols in lookup_symbol_aux
6389 saves you. See the OtherFileClass tests in
6390 gdb.c++/namespace.exp. */
6392 struct pending
**list_to_add
;
6394 list_to_add
= (cu
->list_in_scope
== &file_symbols
6395 && cu
->language
== language_cplus
6396 ? &global_symbols
: cu
->list_in_scope
);
6398 add_symbol_to_list (sym
, list_to_add
);
6400 /* The semantics of C++ state that "struct foo { ... }" also
6401 defines a typedef for "foo". Synthesize a typedef symbol so
6402 that "ptype foo" works as expected. */
6403 if (cu
->language
== language_cplus
)
6405 struct symbol
*typedef_sym
= (struct symbol
*)
6406 obstack_alloc (&objfile
->objfile_obstack
,
6407 sizeof (struct symbol
));
6408 *typedef_sym
= *sym
;
6409 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
6410 /* The symbol's name is already allocated along with
6411 this objfile, so we don't need to duplicate it for
6413 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
6414 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NATURAL_NAME (sym
);
6415 add_symbol_to_list (typedef_sym
, list_to_add
);
6419 case DW_TAG_typedef
:
6420 if (processing_has_namespace_info
6421 && processing_current_prefix
[0] != '\0')
6423 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->objfile_obstack
,
6424 processing_current_prefix
,
6428 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6429 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6430 add_symbol_to_list (sym
, cu
->list_in_scope
);
6432 case DW_TAG_base_type
:
6433 case DW_TAG_subrange_type
:
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_enumerator
:
6439 if (processing_has_namespace_info
6440 && processing_current_prefix
[0] != '\0')
6442 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->objfile_obstack
,
6443 processing_current_prefix
,
6447 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6450 dwarf2_const_value (attr
, sym
, cu
);
6453 /* NOTE: carlton/2003-11-10: See comment above in the
6454 DW_TAG_class_type, etc. block. */
6456 struct pending
**list_to_add
;
6458 list_to_add
= (cu
->list_in_scope
== &file_symbols
6459 && cu
->language
== language_cplus
6460 ? &global_symbols
: cu
->list_in_scope
);
6462 add_symbol_to_list (sym
, list_to_add
);
6465 case DW_TAG_namespace
:
6466 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6467 add_symbol_to_list (sym
, &global_symbols
);
6470 /* Not a tag we recognize. Hopefully we aren't processing
6471 trash data, but since we must specifically ignore things
6472 we don't recognize, there is nothing else we should do at
6474 complaint (&symfile_complaints
, "unsupported tag: '%s'",
6475 dwarf_tag_name (die
->tag
));
6482 /* Copy constant value from an attribute to a symbol. */
6485 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
6486 struct dwarf2_cu
*cu
)
6488 struct objfile
*objfile
= cu
->objfile
;
6489 struct comp_unit_head
*cu_header
= &cu
->header
;
6490 struct dwarf_block
*blk
;
6495 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
6496 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
6497 cu_header
->addr_size
,
6498 TYPE_LENGTH (SYMBOL_TYPE
6500 SYMBOL_VALUE_BYTES (sym
) = (char *)
6501 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
6502 /* NOTE: cagney/2003-05-09: In-lined store_address call with
6503 it's body - store_unsigned_integer. */
6504 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
6506 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6508 case DW_FORM_block1
:
6509 case DW_FORM_block2
:
6510 case DW_FORM_block4
:
6512 blk
= DW_BLOCK (attr
);
6513 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
6514 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
6516 TYPE_LENGTH (SYMBOL_TYPE
6518 SYMBOL_VALUE_BYTES (sym
) = (char *)
6519 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
6520 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
6521 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6524 /* The DW_AT_const_value attributes are supposed to carry the
6525 symbol's value "represented as it would be on the target
6526 architecture." By the time we get here, it's already been
6527 converted to host endianness, so we just need to sign- or
6528 zero-extend it as appropriate. */
6530 dwarf2_const_value_data (attr
, sym
, 8);
6533 dwarf2_const_value_data (attr
, sym
, 16);
6536 dwarf2_const_value_data (attr
, sym
, 32);
6539 dwarf2_const_value_data (attr
, sym
, 64);
6543 SYMBOL_VALUE (sym
) = DW_SND (attr
);
6544 SYMBOL_CLASS (sym
) = LOC_CONST
;
6548 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
6549 SYMBOL_CLASS (sym
) = LOC_CONST
;
6553 complaint (&symfile_complaints
,
6554 "unsupported const value attribute form: '%s'",
6555 dwarf_form_name (attr
->form
));
6556 SYMBOL_VALUE (sym
) = 0;
6557 SYMBOL_CLASS (sym
) = LOC_CONST
;
6563 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
6564 or zero-extend it as appropriate for the symbol's type. */
6566 dwarf2_const_value_data (struct attribute
*attr
,
6570 LONGEST l
= DW_UNSND (attr
);
6572 if (bits
< sizeof (l
) * 8)
6574 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
6575 l
&= ((LONGEST
) 1 << bits
) - 1;
6577 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
6580 SYMBOL_VALUE (sym
) = l
;
6581 SYMBOL_CLASS (sym
) = LOC_CONST
;
6585 /* Return the type of the die in question using its DW_AT_type attribute. */
6587 static struct type
*
6588 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6591 struct attribute
*type_attr
;
6592 struct die_info
*type_die
;
6595 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
6598 /* A missing DW_AT_type represents a void type. */
6599 return dwarf2_fundamental_type (cu
->objfile
, FT_VOID
, cu
);
6603 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6604 type_die
= follow_die_ref (ref
);
6607 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
6608 ref
, cu
->objfile
->name
);
6612 type
= tag_type_to_type (type_die
, cu
);
6615 dump_die (type_die
);
6616 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
6622 /* Return the containing type of the die in question using its
6623 DW_AT_containing_type attribute. */
6625 static struct type
*
6626 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6628 struct type
*type
= NULL
;
6629 struct attribute
*type_attr
;
6630 struct die_info
*type_die
= NULL
;
6633 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
6636 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6637 type_die
= follow_die_ref (ref
);
6640 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
6644 type
= tag_type_to_type (type_die
, cu
);
6649 dump_die (type_die
);
6650 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
6657 static struct type
*
6658 type_at_offset (unsigned int offset
, struct dwarf2_cu
*cu
)
6660 struct die_info
*die
;
6663 die
= follow_die_ref (offset
);
6666 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
6669 type
= tag_type_to_type (die
, cu
);
6674 static struct type
*
6675 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6683 read_type_die (die
, cu
);
6687 error ("Dwarf Error: Cannot find type of die [in module %s]",
6695 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6697 char *prefix
= determine_prefix (die
, cu
);
6698 const char *old_prefix
= processing_current_prefix
;
6699 struct cleanup
*back_to
= make_cleanup (xfree
, prefix
);
6700 processing_current_prefix
= prefix
;
6704 case DW_TAG_class_type
:
6705 case DW_TAG_structure_type
:
6706 case DW_TAG_union_type
:
6707 read_structure_type (die
, cu
);
6709 case DW_TAG_enumeration_type
:
6710 read_enumeration_type (die
, cu
);
6712 case DW_TAG_subprogram
:
6713 case DW_TAG_subroutine_type
:
6714 read_subroutine_type (die
, cu
);
6716 case DW_TAG_array_type
:
6717 read_array_type (die
, cu
);
6719 case DW_TAG_pointer_type
:
6720 read_tag_pointer_type (die
, cu
);
6722 case DW_TAG_ptr_to_member_type
:
6723 read_tag_ptr_to_member_type (die
, cu
);
6725 case DW_TAG_reference_type
:
6726 read_tag_reference_type (die
, cu
);
6728 case DW_TAG_const_type
:
6729 read_tag_const_type (die
, cu
);
6731 case DW_TAG_volatile_type
:
6732 read_tag_volatile_type (die
, cu
);
6734 case DW_TAG_string_type
:
6735 read_tag_string_type (die
, cu
);
6737 case DW_TAG_typedef
:
6738 read_typedef (die
, cu
);
6740 case DW_TAG_subrange_type
:
6741 read_subrange_type (die
, cu
);
6743 case DW_TAG_base_type
:
6744 read_base_type (die
, cu
);
6747 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
6748 dwarf_tag_name (die
->tag
));
6752 processing_current_prefix
= old_prefix
;
6753 do_cleanups (back_to
);
6756 /* Return the name of the namespace/class that DIE is defined within,
6757 or "" if we can't tell. The caller should xfree the result. */
6759 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
6760 therein) for an example of how to use this function to deal with
6761 DW_AT_specification. */
6764 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
6766 struct die_info
*parent
;
6768 if (cu
->language
!= language_cplus
)
6771 parent
= die
->parent
;
6775 return xstrdup ("");
6779 switch (parent
->tag
) {
6780 case DW_TAG_namespace
:
6782 /* FIXME: carlton/2004-03-05: Should I follow extension dies
6783 before doing this check? */
6784 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
6786 return xstrdup (TYPE_TAG_NAME (parent
->type
));
6791 char *parent_prefix
= determine_prefix (parent
, cu
);
6792 char *retval
= typename_concat (parent_prefix
,
6793 namespace_name (parent
, &dummy
,
6795 xfree (parent_prefix
);
6800 case DW_TAG_class_type
:
6801 case DW_TAG_structure_type
:
6803 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
6805 return xstrdup (TYPE_TAG_NAME (parent
->type
));
6809 const char *old_prefix
= processing_current_prefix
;
6810 char *new_prefix
= determine_prefix (parent
, cu
);
6813 processing_current_prefix
= new_prefix
;
6814 retval
= determine_class_name (parent
, cu
);
6815 processing_current_prefix
= old_prefix
;
6822 return determine_prefix (parent
, cu
);
6827 /* Return a newly-allocated string formed by concatenating PREFIX,
6828 "::", and SUFFIX, except that if PREFIX is NULL or the empty
6829 string, just return a copy of SUFFIX. */
6832 typename_concat (const char *prefix
, const char *suffix
)
6834 if (prefix
== NULL
|| prefix
[0] == '\0')
6835 return xstrdup (suffix
);
6838 char *retval
= xmalloc (strlen (prefix
) + 2 + strlen (suffix
) + 1);
6840 strcpy (retval
, prefix
);
6841 strcat (retval
, "::");
6842 strcat (retval
, suffix
);
6848 static struct type
*
6849 dwarf_base_type (int encoding
, int size
, struct dwarf2_cu
*cu
)
6851 struct objfile
*objfile
= cu
->objfile
;
6853 /* FIXME - this should not produce a new (struct type *)
6854 every time. It should cache base types. */
6858 case DW_ATE_address
:
6859 type
= dwarf2_fundamental_type (objfile
, FT_VOID
, cu
);
6861 case DW_ATE_boolean
:
6862 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
, cu
);
6864 case DW_ATE_complex_float
:
6867 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
, cu
);
6871 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
, cu
);
6877 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
6881 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
6888 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6891 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
, cu
);
6895 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6899 case DW_ATE_signed_char
:
6900 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6902 case DW_ATE_unsigned
:
6906 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6909 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
, cu
);
6913 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
, cu
);
6917 case DW_ATE_unsigned_char
:
6918 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6921 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6928 copy_die (struct die_info
*old_die
)
6930 struct die_info
*new_die
;
6933 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6934 memset (new_die
, 0, sizeof (struct die_info
));
6936 new_die
->tag
= old_die
->tag
;
6937 new_die
->has_children
= old_die
->has_children
;
6938 new_die
->abbrev
= old_die
->abbrev
;
6939 new_die
->offset
= old_die
->offset
;
6940 new_die
->type
= NULL
;
6942 num_attrs
= old_die
->num_attrs
;
6943 new_die
->num_attrs
= num_attrs
;
6944 new_die
->attrs
= (struct attribute
*)
6945 xmalloc (num_attrs
* sizeof (struct attribute
));
6947 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
6949 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
6950 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
6951 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
6954 new_die
->next
= NULL
;
6959 /* Return sibling of die, NULL if no sibling. */
6961 static struct die_info
*
6962 sibling_die (struct die_info
*die
)
6964 return die
->sibling
;
6967 /* Get linkage name of a die, return NULL if not found. */
6970 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6972 struct attribute
*attr
;
6974 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6975 if (attr
&& DW_STRING (attr
))
6976 return DW_STRING (attr
);
6977 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6978 if (attr
&& DW_STRING (attr
))
6979 return DW_STRING (attr
);
6983 /* Get name of a die, return NULL if not found. */
6986 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6988 struct attribute
*attr
;
6990 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6991 if (attr
&& DW_STRING (attr
))
6992 return DW_STRING (attr
);
6996 /* Return the die that this die in an extension of, or NULL if there
6999 static struct die_info
*
7000 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
7002 struct attribute
*attr
;
7003 struct die_info
*extension_die
;
7006 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
7010 ref
= dwarf2_get_ref_die_offset (attr
, cu
);
7011 extension_die
= follow_die_ref (ref
);
7014 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
7017 return extension_die
;
7020 /* Convert a DIE tag into its string name. */
7023 dwarf_tag_name (unsigned tag
)
7027 case DW_TAG_padding
:
7028 return "DW_TAG_padding";
7029 case DW_TAG_array_type
:
7030 return "DW_TAG_array_type";
7031 case DW_TAG_class_type
:
7032 return "DW_TAG_class_type";
7033 case DW_TAG_entry_point
:
7034 return "DW_TAG_entry_point";
7035 case DW_TAG_enumeration_type
:
7036 return "DW_TAG_enumeration_type";
7037 case DW_TAG_formal_parameter
:
7038 return "DW_TAG_formal_parameter";
7039 case DW_TAG_imported_declaration
:
7040 return "DW_TAG_imported_declaration";
7042 return "DW_TAG_label";
7043 case DW_TAG_lexical_block
:
7044 return "DW_TAG_lexical_block";
7046 return "DW_TAG_member";
7047 case DW_TAG_pointer_type
:
7048 return "DW_TAG_pointer_type";
7049 case DW_TAG_reference_type
:
7050 return "DW_TAG_reference_type";
7051 case DW_TAG_compile_unit
:
7052 return "DW_TAG_compile_unit";
7053 case DW_TAG_string_type
:
7054 return "DW_TAG_string_type";
7055 case DW_TAG_structure_type
:
7056 return "DW_TAG_structure_type";
7057 case DW_TAG_subroutine_type
:
7058 return "DW_TAG_subroutine_type";
7059 case DW_TAG_typedef
:
7060 return "DW_TAG_typedef";
7061 case DW_TAG_union_type
:
7062 return "DW_TAG_union_type";
7063 case DW_TAG_unspecified_parameters
:
7064 return "DW_TAG_unspecified_parameters";
7065 case DW_TAG_variant
:
7066 return "DW_TAG_variant";
7067 case DW_TAG_common_block
:
7068 return "DW_TAG_common_block";
7069 case DW_TAG_common_inclusion
:
7070 return "DW_TAG_common_inclusion";
7071 case DW_TAG_inheritance
:
7072 return "DW_TAG_inheritance";
7073 case DW_TAG_inlined_subroutine
:
7074 return "DW_TAG_inlined_subroutine";
7076 return "DW_TAG_module";
7077 case DW_TAG_ptr_to_member_type
:
7078 return "DW_TAG_ptr_to_member_type";
7079 case DW_TAG_set_type
:
7080 return "DW_TAG_set_type";
7081 case DW_TAG_subrange_type
:
7082 return "DW_TAG_subrange_type";
7083 case DW_TAG_with_stmt
:
7084 return "DW_TAG_with_stmt";
7085 case DW_TAG_access_declaration
:
7086 return "DW_TAG_access_declaration";
7087 case DW_TAG_base_type
:
7088 return "DW_TAG_base_type";
7089 case DW_TAG_catch_block
:
7090 return "DW_TAG_catch_block";
7091 case DW_TAG_const_type
:
7092 return "DW_TAG_const_type";
7093 case DW_TAG_constant
:
7094 return "DW_TAG_constant";
7095 case DW_TAG_enumerator
:
7096 return "DW_TAG_enumerator";
7097 case DW_TAG_file_type
:
7098 return "DW_TAG_file_type";
7100 return "DW_TAG_friend";
7101 case DW_TAG_namelist
:
7102 return "DW_TAG_namelist";
7103 case DW_TAG_namelist_item
:
7104 return "DW_TAG_namelist_item";
7105 case DW_TAG_packed_type
:
7106 return "DW_TAG_packed_type";
7107 case DW_TAG_subprogram
:
7108 return "DW_TAG_subprogram";
7109 case DW_TAG_template_type_param
:
7110 return "DW_TAG_template_type_param";
7111 case DW_TAG_template_value_param
:
7112 return "DW_TAG_template_value_param";
7113 case DW_TAG_thrown_type
:
7114 return "DW_TAG_thrown_type";
7115 case DW_TAG_try_block
:
7116 return "DW_TAG_try_block";
7117 case DW_TAG_variant_part
:
7118 return "DW_TAG_variant_part";
7119 case DW_TAG_variable
:
7120 return "DW_TAG_variable";
7121 case DW_TAG_volatile_type
:
7122 return "DW_TAG_volatile_type";
7123 case DW_TAG_dwarf_procedure
:
7124 return "DW_TAG_dwarf_procedure";
7125 case DW_TAG_restrict_type
:
7126 return "DW_TAG_restrict_type";
7127 case DW_TAG_interface_type
:
7128 return "DW_TAG_interface_type";
7129 case DW_TAG_namespace
:
7130 return "DW_TAG_namespace";
7131 case DW_TAG_imported_module
:
7132 return "DW_TAG_imported_module";
7133 case DW_TAG_unspecified_type
:
7134 return "DW_TAG_unspecified_type";
7135 case DW_TAG_partial_unit
:
7136 return "DW_TAG_partial_unit";
7137 case DW_TAG_imported_unit
:
7138 return "DW_TAG_imported_unit";
7139 case DW_TAG_MIPS_loop
:
7140 return "DW_TAG_MIPS_loop";
7141 case DW_TAG_format_label
:
7142 return "DW_TAG_format_label";
7143 case DW_TAG_function_template
:
7144 return "DW_TAG_function_template";
7145 case DW_TAG_class_template
:
7146 return "DW_TAG_class_template";
7148 return "DW_TAG_<unknown>";
7152 /* Convert a DWARF attribute code into its string name. */
7155 dwarf_attr_name (unsigned attr
)
7160 return "DW_AT_sibling";
7161 case DW_AT_location
:
7162 return "DW_AT_location";
7164 return "DW_AT_name";
7165 case DW_AT_ordering
:
7166 return "DW_AT_ordering";
7167 case DW_AT_subscr_data
:
7168 return "DW_AT_subscr_data";
7169 case DW_AT_byte_size
:
7170 return "DW_AT_byte_size";
7171 case DW_AT_bit_offset
:
7172 return "DW_AT_bit_offset";
7173 case DW_AT_bit_size
:
7174 return "DW_AT_bit_size";
7175 case DW_AT_element_list
:
7176 return "DW_AT_element_list";
7177 case DW_AT_stmt_list
:
7178 return "DW_AT_stmt_list";
7180 return "DW_AT_low_pc";
7182 return "DW_AT_high_pc";
7183 case DW_AT_language
:
7184 return "DW_AT_language";
7186 return "DW_AT_member";
7188 return "DW_AT_discr";
7189 case DW_AT_discr_value
:
7190 return "DW_AT_discr_value";
7191 case DW_AT_visibility
:
7192 return "DW_AT_visibility";
7194 return "DW_AT_import";
7195 case DW_AT_string_length
:
7196 return "DW_AT_string_length";
7197 case DW_AT_common_reference
:
7198 return "DW_AT_common_reference";
7199 case DW_AT_comp_dir
:
7200 return "DW_AT_comp_dir";
7201 case DW_AT_const_value
:
7202 return "DW_AT_const_value";
7203 case DW_AT_containing_type
:
7204 return "DW_AT_containing_type";
7205 case DW_AT_default_value
:
7206 return "DW_AT_default_value";
7208 return "DW_AT_inline";
7209 case DW_AT_is_optional
:
7210 return "DW_AT_is_optional";
7211 case DW_AT_lower_bound
:
7212 return "DW_AT_lower_bound";
7213 case DW_AT_producer
:
7214 return "DW_AT_producer";
7215 case DW_AT_prototyped
:
7216 return "DW_AT_prototyped";
7217 case DW_AT_return_addr
:
7218 return "DW_AT_return_addr";
7219 case DW_AT_start_scope
:
7220 return "DW_AT_start_scope";
7221 case DW_AT_stride_size
:
7222 return "DW_AT_stride_size";
7223 case DW_AT_upper_bound
:
7224 return "DW_AT_upper_bound";
7225 case DW_AT_abstract_origin
:
7226 return "DW_AT_abstract_origin";
7227 case DW_AT_accessibility
:
7228 return "DW_AT_accessibility";
7229 case DW_AT_address_class
:
7230 return "DW_AT_address_class";
7231 case DW_AT_artificial
:
7232 return "DW_AT_artificial";
7233 case DW_AT_base_types
:
7234 return "DW_AT_base_types";
7235 case DW_AT_calling_convention
:
7236 return "DW_AT_calling_convention";
7238 return "DW_AT_count";
7239 case DW_AT_data_member_location
:
7240 return "DW_AT_data_member_location";
7241 case DW_AT_decl_column
:
7242 return "DW_AT_decl_column";
7243 case DW_AT_decl_file
:
7244 return "DW_AT_decl_file";
7245 case DW_AT_decl_line
:
7246 return "DW_AT_decl_line";
7247 case DW_AT_declaration
:
7248 return "DW_AT_declaration";
7249 case DW_AT_discr_list
:
7250 return "DW_AT_discr_list";
7251 case DW_AT_encoding
:
7252 return "DW_AT_encoding";
7253 case DW_AT_external
:
7254 return "DW_AT_external";
7255 case DW_AT_frame_base
:
7256 return "DW_AT_frame_base";
7258 return "DW_AT_friend";
7259 case DW_AT_identifier_case
:
7260 return "DW_AT_identifier_case";
7261 case DW_AT_macro_info
:
7262 return "DW_AT_macro_info";
7263 case DW_AT_namelist_items
:
7264 return "DW_AT_namelist_items";
7265 case DW_AT_priority
:
7266 return "DW_AT_priority";
7268 return "DW_AT_segment";
7269 case DW_AT_specification
:
7270 return "DW_AT_specification";
7271 case DW_AT_static_link
:
7272 return "DW_AT_static_link";
7274 return "DW_AT_type";
7275 case DW_AT_use_location
:
7276 return "DW_AT_use_location";
7277 case DW_AT_variable_parameter
:
7278 return "DW_AT_variable_parameter";
7279 case DW_AT_virtuality
:
7280 return "DW_AT_virtuality";
7281 case DW_AT_vtable_elem_location
:
7282 return "DW_AT_vtable_elem_location";
7283 case DW_AT_allocated
:
7284 return "DW_AT_allocated";
7285 case DW_AT_associated
:
7286 return "DW_AT_associated";
7287 case DW_AT_data_location
:
7288 return "DW_AT_data_location";
7290 return "DW_AT_stride";
7291 case DW_AT_entry_pc
:
7292 return "DW_AT_entry_pc";
7293 case DW_AT_use_UTF8
:
7294 return "DW_AT_use_UTF8";
7295 case DW_AT_extension
:
7296 return "DW_AT_extension";
7298 return "DW_AT_ranges";
7299 case DW_AT_trampoline
:
7300 return "DW_AT_trampoline";
7301 case DW_AT_call_column
:
7302 return "DW_AT_call_column";
7303 case DW_AT_call_file
:
7304 return "DW_AT_call_file";
7305 case DW_AT_call_line
:
7306 return "DW_AT_call_line";
7308 case DW_AT_MIPS_fde
:
7309 return "DW_AT_MIPS_fde";
7310 case DW_AT_MIPS_loop_begin
:
7311 return "DW_AT_MIPS_loop_begin";
7312 case DW_AT_MIPS_tail_loop_begin
:
7313 return "DW_AT_MIPS_tail_loop_begin";
7314 case DW_AT_MIPS_epilog_begin
:
7315 return "DW_AT_MIPS_epilog_begin";
7316 case DW_AT_MIPS_loop_unroll_factor
:
7317 return "DW_AT_MIPS_loop_unroll_factor";
7318 case DW_AT_MIPS_software_pipeline_depth
:
7319 return "DW_AT_MIPS_software_pipeline_depth";
7321 case DW_AT_MIPS_linkage_name
:
7322 return "DW_AT_MIPS_linkage_name";
7324 case DW_AT_sf_names
:
7325 return "DW_AT_sf_names";
7326 case DW_AT_src_info
:
7327 return "DW_AT_src_info";
7328 case DW_AT_mac_info
:
7329 return "DW_AT_mac_info";
7330 case DW_AT_src_coords
:
7331 return "DW_AT_src_coords";
7332 case DW_AT_body_begin
:
7333 return "DW_AT_body_begin";
7334 case DW_AT_body_end
:
7335 return "DW_AT_body_end";
7336 case DW_AT_GNU_vector
:
7337 return "DW_AT_GNU_vector";
7339 return "DW_AT_<unknown>";
7343 /* Convert a DWARF value form code into its string name. */
7346 dwarf_form_name (unsigned form
)
7351 return "DW_FORM_addr";
7352 case DW_FORM_block2
:
7353 return "DW_FORM_block2";
7354 case DW_FORM_block4
:
7355 return "DW_FORM_block4";
7357 return "DW_FORM_data2";
7359 return "DW_FORM_data4";
7361 return "DW_FORM_data8";
7362 case DW_FORM_string
:
7363 return "DW_FORM_string";
7365 return "DW_FORM_block";
7366 case DW_FORM_block1
:
7367 return "DW_FORM_block1";
7369 return "DW_FORM_data1";
7371 return "DW_FORM_flag";
7373 return "DW_FORM_sdata";
7375 return "DW_FORM_strp";
7377 return "DW_FORM_udata";
7378 case DW_FORM_ref_addr
:
7379 return "DW_FORM_ref_addr";
7381 return "DW_FORM_ref1";
7383 return "DW_FORM_ref2";
7385 return "DW_FORM_ref4";
7387 return "DW_FORM_ref8";
7388 case DW_FORM_ref_udata
:
7389 return "DW_FORM_ref_udata";
7390 case DW_FORM_indirect
:
7391 return "DW_FORM_indirect";
7393 return "DW_FORM_<unknown>";
7397 /* Convert a DWARF stack opcode into its string name. */
7400 dwarf_stack_op_name (unsigned op
)
7405 return "DW_OP_addr";
7407 return "DW_OP_deref";
7409 return "DW_OP_const1u";
7411 return "DW_OP_const1s";
7413 return "DW_OP_const2u";
7415 return "DW_OP_const2s";
7417 return "DW_OP_const4u";
7419 return "DW_OP_const4s";
7421 return "DW_OP_const8u";
7423 return "DW_OP_const8s";
7425 return "DW_OP_constu";
7427 return "DW_OP_consts";
7431 return "DW_OP_drop";
7433 return "DW_OP_over";
7435 return "DW_OP_pick";
7437 return "DW_OP_swap";
7441 return "DW_OP_xderef";
7449 return "DW_OP_minus";
7461 return "DW_OP_plus";
7462 case DW_OP_plus_uconst
:
7463 return "DW_OP_plus_uconst";
7469 return "DW_OP_shra";
7487 return "DW_OP_skip";
7489 return "DW_OP_lit0";
7491 return "DW_OP_lit1";
7493 return "DW_OP_lit2";
7495 return "DW_OP_lit3";
7497 return "DW_OP_lit4";
7499 return "DW_OP_lit5";
7501 return "DW_OP_lit6";
7503 return "DW_OP_lit7";
7505 return "DW_OP_lit8";
7507 return "DW_OP_lit9";
7509 return "DW_OP_lit10";
7511 return "DW_OP_lit11";
7513 return "DW_OP_lit12";
7515 return "DW_OP_lit13";
7517 return "DW_OP_lit14";
7519 return "DW_OP_lit15";
7521 return "DW_OP_lit16";
7523 return "DW_OP_lit17";
7525 return "DW_OP_lit18";
7527 return "DW_OP_lit19";
7529 return "DW_OP_lit20";
7531 return "DW_OP_lit21";
7533 return "DW_OP_lit22";
7535 return "DW_OP_lit23";
7537 return "DW_OP_lit24";
7539 return "DW_OP_lit25";
7541 return "DW_OP_lit26";
7543 return "DW_OP_lit27";
7545 return "DW_OP_lit28";
7547 return "DW_OP_lit29";
7549 return "DW_OP_lit30";
7551 return "DW_OP_lit31";
7553 return "DW_OP_reg0";
7555 return "DW_OP_reg1";
7557 return "DW_OP_reg2";
7559 return "DW_OP_reg3";
7561 return "DW_OP_reg4";
7563 return "DW_OP_reg5";
7565 return "DW_OP_reg6";
7567 return "DW_OP_reg7";
7569 return "DW_OP_reg8";
7571 return "DW_OP_reg9";
7573 return "DW_OP_reg10";
7575 return "DW_OP_reg11";
7577 return "DW_OP_reg12";
7579 return "DW_OP_reg13";
7581 return "DW_OP_reg14";
7583 return "DW_OP_reg15";
7585 return "DW_OP_reg16";
7587 return "DW_OP_reg17";
7589 return "DW_OP_reg18";
7591 return "DW_OP_reg19";
7593 return "DW_OP_reg20";
7595 return "DW_OP_reg21";
7597 return "DW_OP_reg22";
7599 return "DW_OP_reg23";
7601 return "DW_OP_reg24";
7603 return "DW_OP_reg25";
7605 return "DW_OP_reg26";
7607 return "DW_OP_reg27";
7609 return "DW_OP_reg28";
7611 return "DW_OP_reg29";
7613 return "DW_OP_reg30";
7615 return "DW_OP_reg31";
7617 return "DW_OP_breg0";
7619 return "DW_OP_breg1";
7621 return "DW_OP_breg2";
7623 return "DW_OP_breg3";
7625 return "DW_OP_breg4";
7627 return "DW_OP_breg5";
7629 return "DW_OP_breg6";
7631 return "DW_OP_breg7";
7633 return "DW_OP_breg8";
7635 return "DW_OP_breg9";
7637 return "DW_OP_breg10";
7639 return "DW_OP_breg11";
7641 return "DW_OP_breg12";
7643 return "DW_OP_breg13";
7645 return "DW_OP_breg14";
7647 return "DW_OP_breg15";
7649 return "DW_OP_breg16";
7651 return "DW_OP_breg17";
7653 return "DW_OP_breg18";
7655 return "DW_OP_breg19";
7657 return "DW_OP_breg20";
7659 return "DW_OP_breg21";
7661 return "DW_OP_breg22";
7663 return "DW_OP_breg23";
7665 return "DW_OP_breg24";
7667 return "DW_OP_breg25";
7669 return "DW_OP_breg26";
7671 return "DW_OP_breg27";
7673 return "DW_OP_breg28";
7675 return "DW_OP_breg29";
7677 return "DW_OP_breg30";
7679 return "DW_OP_breg31";
7681 return "DW_OP_regx";
7683 return "DW_OP_fbreg";
7685 return "DW_OP_bregx";
7687 return "DW_OP_piece";
7688 case DW_OP_deref_size
:
7689 return "DW_OP_deref_size";
7690 case DW_OP_xderef_size
:
7691 return "DW_OP_xderef_size";
7694 /* DWARF 3 extensions. */
7695 case DW_OP_push_object_address
:
7696 return "DW_OP_push_object_address";
7698 return "DW_OP_call2";
7700 return "DW_OP_call4";
7701 case DW_OP_call_ref
:
7702 return "DW_OP_call_ref";
7703 /* GNU extensions. */
7704 case DW_OP_GNU_push_tls_address
:
7705 return "DW_OP_GNU_push_tls_address";
7707 return "OP_<unknown>";
7712 dwarf_bool_name (unsigned mybool
)
7720 /* Convert a DWARF type code into its string name. */
7723 dwarf_type_encoding_name (unsigned enc
)
7727 case DW_ATE_address
:
7728 return "DW_ATE_address";
7729 case DW_ATE_boolean
:
7730 return "DW_ATE_boolean";
7731 case DW_ATE_complex_float
:
7732 return "DW_ATE_complex_float";
7734 return "DW_ATE_float";
7736 return "DW_ATE_signed";
7737 case DW_ATE_signed_char
:
7738 return "DW_ATE_signed_char";
7739 case DW_ATE_unsigned
:
7740 return "DW_ATE_unsigned";
7741 case DW_ATE_unsigned_char
:
7742 return "DW_ATE_unsigned_char";
7743 case DW_ATE_imaginary_float
:
7744 return "DW_ATE_imaginary_float";
7746 return "DW_ATE_<unknown>";
7750 /* Convert a DWARF call frame info operation to its string name. */
7754 dwarf_cfi_name (unsigned cfi_opc
)
7758 case DW_CFA_advance_loc
:
7759 return "DW_CFA_advance_loc";
7761 return "DW_CFA_offset";
7762 case DW_CFA_restore
:
7763 return "DW_CFA_restore";
7765 return "DW_CFA_nop";
7766 case DW_CFA_set_loc
:
7767 return "DW_CFA_set_loc";
7768 case DW_CFA_advance_loc1
:
7769 return "DW_CFA_advance_loc1";
7770 case DW_CFA_advance_loc2
:
7771 return "DW_CFA_advance_loc2";
7772 case DW_CFA_advance_loc4
:
7773 return "DW_CFA_advance_loc4";
7774 case DW_CFA_offset_extended
:
7775 return "DW_CFA_offset_extended";
7776 case DW_CFA_restore_extended
:
7777 return "DW_CFA_restore_extended";
7778 case DW_CFA_undefined
:
7779 return "DW_CFA_undefined";
7780 case DW_CFA_same_value
:
7781 return "DW_CFA_same_value";
7782 case DW_CFA_register
:
7783 return "DW_CFA_register";
7784 case DW_CFA_remember_state
:
7785 return "DW_CFA_remember_state";
7786 case DW_CFA_restore_state
:
7787 return "DW_CFA_restore_state";
7788 case DW_CFA_def_cfa
:
7789 return "DW_CFA_def_cfa";
7790 case DW_CFA_def_cfa_register
:
7791 return "DW_CFA_def_cfa_register";
7792 case DW_CFA_def_cfa_offset
:
7793 return "DW_CFA_def_cfa_offset";
7796 case DW_CFA_def_cfa_expression
:
7797 return "DW_CFA_def_cfa_expression";
7798 case DW_CFA_expression
:
7799 return "DW_CFA_expression";
7800 case DW_CFA_offset_extended_sf
:
7801 return "DW_CFA_offset_extended_sf";
7802 case DW_CFA_def_cfa_sf
:
7803 return "DW_CFA_def_cfa_sf";
7804 case DW_CFA_def_cfa_offset_sf
:
7805 return "DW_CFA_def_cfa_offset_sf";
7807 /* SGI/MIPS specific */
7808 case DW_CFA_MIPS_advance_loc8
:
7809 return "DW_CFA_MIPS_advance_loc8";
7811 /* GNU extensions */
7812 case DW_CFA_GNU_window_save
:
7813 return "DW_CFA_GNU_window_save";
7814 case DW_CFA_GNU_args_size
:
7815 return "DW_CFA_GNU_args_size";
7816 case DW_CFA_GNU_negative_offset_extended
:
7817 return "DW_CFA_GNU_negative_offset_extended";
7820 return "DW_CFA_<unknown>";
7826 dump_die (struct die_info
*die
)
7830 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
7831 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
7832 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
7833 dwarf_bool_name (die
->child
!= NULL
));
7835 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
7836 for (i
= 0; i
< die
->num_attrs
; ++i
)
7838 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
7839 dwarf_attr_name (die
->attrs
[i
].name
),
7840 dwarf_form_name (die
->attrs
[i
].form
));
7841 switch (die
->attrs
[i
].form
)
7843 case DW_FORM_ref_addr
:
7845 fprintf_unfiltered (gdb_stderr
, "address: ");
7846 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
7848 case DW_FORM_block2
:
7849 case DW_FORM_block4
:
7851 case DW_FORM_block1
:
7852 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
7863 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
7865 case DW_FORM_string
:
7867 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
7868 DW_STRING (&die
->attrs
[i
])
7869 ? DW_STRING (&die
->attrs
[i
]) : "");
7872 if (DW_UNSND (&die
->attrs
[i
]))
7873 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
7875 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
7877 case DW_FORM_indirect
:
7878 /* the reader will have reduced the indirect form to
7879 the "base form" so this form should not occur */
7880 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
7883 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
7884 die
->attrs
[i
].form
);
7886 fprintf_unfiltered (gdb_stderr
, "\n");
7891 dump_die_list (struct die_info
*die
)
7896 if (die
->child
!= NULL
)
7897 dump_die_list (die
->child
);
7898 if (die
->sibling
!= NULL
)
7899 dump_die_list (die
->sibling
);
7904 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
7907 struct die_info
*old
;
7909 h
= (offset
% REF_HASH_SIZE
);
7910 old
= die_ref_table
[h
];
7911 die
->next_ref
= old
;
7912 die_ref_table
[h
] = die
;
7917 dwarf2_empty_hash_tables (void)
7919 memset (die_ref_table
, 0, sizeof (die_ref_table
));
7923 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
7925 unsigned int result
= 0;
7929 case DW_FORM_ref_addr
:
7930 result
= DW_ADDR (attr
);
7936 case DW_FORM_ref_udata
:
7937 result
= cu
->header
.offset
+ DW_UNSND (attr
);
7940 complaint (&symfile_complaints
,
7941 "unsupported die ref attribute form: '%s'",
7942 dwarf_form_name (attr
->form
));
7947 /* Return the constant value held by the given attribute. Return -1
7948 if the value held by the attribute is not constant. */
7951 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
7953 if (attr
->form
== DW_FORM_sdata
)
7954 return DW_SND (attr
);
7955 else if (attr
->form
== DW_FORM_udata
7956 || attr
->form
== DW_FORM_data1
7957 || attr
->form
== DW_FORM_data2
7958 || attr
->form
== DW_FORM_data4
7959 || attr
->form
== DW_FORM_data8
)
7960 return DW_UNSND (attr
);
7963 complaint (&symfile_complaints
, "Attribute value is not a constant (%s)",
7964 dwarf_form_name (attr
->form
));
7965 return default_value
;
7969 static struct die_info
*
7970 follow_die_ref (unsigned int offset
)
7972 struct die_info
*die
;
7975 h
= (offset
% REF_HASH_SIZE
);
7976 die
= die_ref_table
[h
];
7979 if (die
->offset
== offset
)
7983 die
= die
->next_ref
;
7988 static struct type
*
7989 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid,
7990 struct dwarf2_cu
*cu
)
7992 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
7994 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
7995 typeid, objfile
->name
);
7998 /* Look for this particular type in the fundamental type vector. If
7999 one is not found, create and install one appropriate for the
8000 current language and the current target machine. */
8002 if (cu
->ftypes
[typeid] == NULL
)
8004 cu
->ftypes
[typeid] = cu
->language_defn
->la_fund_type (objfile
, typeid);
8007 return (cu
->ftypes
[typeid]);
8010 /* Decode simple location descriptions.
8011 Given a pointer to a dwarf block that defines a location, compute
8012 the location and return the value.
8014 NOTE drow/2003-11-18: This function is called in two situations
8015 now: for the address of static or global variables (partial symbols
8016 only) and for offsets into structures which are expected to be
8017 (more or less) constant. The partial symbol case should go away,
8018 and only the constant case should remain. That will let this
8019 function complain more accurately. A few special modes are allowed
8020 without complaint for global variables (for instance, global
8021 register values and thread-local values).
8023 A location description containing no operations indicates that the
8024 object is optimized out. The return value is 0 for that case.
8025 FIXME drow/2003-11-16: No callers check for this case any more; soon all
8026 callers will only want a very basic result and this can become a
8029 When the result is a register number, the global isreg flag is set,
8030 otherwise it is cleared.
8032 Note that stack[0] is unused except as a default error return.
8033 Note that stack overflow is not yet handled. */
8036 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
8038 struct objfile
*objfile
= cu
->objfile
;
8039 struct comp_unit_head
*cu_header
= &cu
->header
;
8041 int size
= blk
->size
;
8042 char *data
= blk
->data
;
8043 CORE_ADDR stack
[64];
8045 unsigned int bytes_read
, unsnd
;
8090 stack
[++stacki
] = op
- DW_OP_lit0
;
8126 stack
[++stacki
] = op
- DW_OP_reg0
;
8128 dwarf2_complex_location_expr_complaint ();
8133 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
8135 stack
[++stacki
] = unsnd
;
8137 dwarf2_complex_location_expr_complaint ();
8141 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
8147 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
8152 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
8157 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
8162 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
8167 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
8172 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
8177 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
8183 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
8188 stack
[stacki
+ 1] = stack
[stacki
];
8193 stack
[stacki
- 1] += stack
[stacki
];
8197 case DW_OP_plus_uconst
:
8198 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
8203 stack
[stacki
- 1] -= stack
[stacki
];
8208 /* If we're not the last op, then we definitely can't encode
8209 this using GDB's address_class enum. This is valid for partial
8210 global symbols, although the variable's address will be bogus
8213 dwarf2_complex_location_expr_complaint ();
8216 case DW_OP_GNU_push_tls_address
:
8217 /* The top of the stack has the offset from the beginning
8218 of the thread control block at which the variable is located. */
8219 /* Nothing should follow this operator, so the top of stack would
8221 /* This is valid for partial global symbols, but the variable's
8222 address will be bogus in the psymtab. */
8224 dwarf2_complex_location_expr_complaint ();
8228 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
8229 dwarf_stack_op_name (op
));
8230 return (stack
[stacki
]);
8233 return (stack
[stacki
]);
8236 /* memory allocation interface */
8238 static struct dwarf_block
*
8239 dwarf_alloc_block (struct dwarf2_cu
*cu
)
8241 struct dwarf_block
*blk
;
8243 blk
= (struct dwarf_block
*)
8244 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
8248 static struct abbrev_info
*
8249 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
8251 struct abbrev_info
*abbrev
;
8253 abbrev
= (struct abbrev_info
*)
8254 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
8255 memset (abbrev
, 0, sizeof (struct abbrev_info
));
8259 static struct die_info
*
8260 dwarf_alloc_die (void)
8262 struct die_info
*die
;
8264 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
8265 memset (die
, 0, sizeof (struct die_info
));
8270 /* Macro support. */
8273 /* Return the full name of file number I in *LH's file name table.
8274 Use COMP_DIR as the name of the current directory of the
8275 compilation. The result is allocated using xmalloc; the caller is
8276 responsible for freeing it. */
8278 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
8280 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
8282 if (IS_ABSOLUTE_PATH (fe
->name
))
8283 return xstrdup (fe
->name
);
8291 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8297 dir_len
= strlen (dir
);
8298 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
8299 strcpy (full_name
, dir
);
8300 full_name
[dir_len
] = '/';
8301 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
8305 return xstrdup (fe
->name
);
8310 static struct macro_source_file
*
8311 macro_start_file (int file
, int line
,
8312 struct macro_source_file
*current_file
,
8313 const char *comp_dir
,
8314 struct line_header
*lh
, struct objfile
*objfile
)
8316 /* The full name of this source file. */
8317 char *full_name
= file_full_name (file
, lh
, comp_dir
);
8319 /* We don't create a macro table for this compilation unit
8320 at all until we actually get a filename. */
8321 if (! pending_macros
)
8322 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
8323 objfile
->macro_cache
);
8326 /* If we have no current file, then this must be the start_file
8327 directive for the compilation unit's main source file. */
8328 current_file
= macro_set_main (pending_macros
, full_name
);
8330 current_file
= macro_include (current_file
, line
, full_name
);
8334 return current_file
;
8338 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
8339 followed by a null byte. */
8341 copy_string (const char *buf
, int len
)
8343 char *s
= xmalloc (len
+ 1);
8344 memcpy (s
, buf
, len
);
8352 consume_improper_spaces (const char *p
, const char *body
)
8356 complaint (&symfile_complaints
,
8357 "macro definition contains spaces in formal argument list:\n`%s'",
8369 parse_macro_definition (struct macro_source_file
*file
, int line
,
8374 /* The body string takes one of two forms. For object-like macro
8375 definitions, it should be:
8377 <macro name> " " <definition>
8379 For function-like macro definitions, it should be:
8381 <macro name> "() " <definition>
8383 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
8385 Spaces may appear only where explicitly indicated, and in the
8388 The Dwarf 2 spec says that an object-like macro's name is always
8389 followed by a space, but versions of GCC around March 2002 omit
8390 the space when the macro's definition is the empty string.
8392 The Dwarf 2 spec says that there should be no spaces between the
8393 formal arguments in a function-like macro's formal argument list,
8394 but versions of GCC around March 2002 include spaces after the
8398 /* Find the extent of the macro name. The macro name is terminated
8399 by either a space or null character (for an object-like macro) or
8400 an opening paren (for a function-like macro). */
8401 for (p
= body
; *p
; p
++)
8402 if (*p
== ' ' || *p
== '(')
8405 if (*p
== ' ' || *p
== '\0')
8407 /* It's an object-like macro. */
8408 int name_len
= p
- body
;
8409 char *name
= copy_string (body
, name_len
);
8410 const char *replacement
;
8413 replacement
= body
+ name_len
+ 1;
8416 dwarf2_macro_malformed_definition_complaint (body
);
8417 replacement
= body
+ name_len
;
8420 macro_define_object (file
, line
, name
, replacement
);
8426 /* It's a function-like macro. */
8427 char *name
= copy_string (body
, p
- body
);
8430 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
8434 p
= consume_improper_spaces (p
, body
);
8436 /* Parse the formal argument list. */
8437 while (*p
&& *p
!= ')')
8439 /* Find the extent of the current argument name. */
8440 const char *arg_start
= p
;
8442 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
8445 if (! *p
|| p
== arg_start
)
8446 dwarf2_macro_malformed_definition_complaint (body
);
8449 /* Make sure argv has room for the new argument. */
8450 if (argc
>= argv_size
)
8453 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
8456 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
8459 p
= consume_improper_spaces (p
, body
);
8461 /* Consume the comma, if present. */
8466 p
= consume_improper_spaces (p
, body
);
8475 /* Perfectly formed definition, no complaints. */
8476 macro_define_function (file
, line
, name
,
8477 argc
, (const char **) argv
,
8479 else if (*p
== '\0')
8481 /* Complain, but do define it. */
8482 dwarf2_macro_malformed_definition_complaint (body
);
8483 macro_define_function (file
, line
, name
,
8484 argc
, (const char **) argv
,
8488 /* Just complain. */
8489 dwarf2_macro_malformed_definition_complaint (body
);
8492 /* Just complain. */
8493 dwarf2_macro_malformed_definition_complaint (body
);
8499 for (i
= 0; i
< argc
; i
++)
8505 dwarf2_macro_malformed_definition_complaint (body
);
8510 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
8511 char *comp_dir
, bfd
*abfd
,
8512 struct dwarf2_cu
*cu
)
8514 char *mac_ptr
, *mac_end
;
8515 struct macro_source_file
*current_file
= 0;
8517 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
8519 complaint (&symfile_complaints
, "missing .debug_macinfo section");
8523 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
8524 mac_end
= dwarf2_per_objfile
->macinfo_buffer
8525 + dwarf2_per_objfile
->macinfo_size
;
8529 enum dwarf_macinfo_record_type macinfo_type
;
8531 /* Do we at least have room for a macinfo type byte? */
8532 if (mac_ptr
>= mac_end
)
8534 dwarf2_macros_too_long_complaint ();
8538 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
8541 switch (macinfo_type
)
8543 /* A zero macinfo type indicates the end of the macro
8548 case DW_MACINFO_define
:
8549 case DW_MACINFO_undef
:
8555 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8556 mac_ptr
+= bytes_read
;
8557 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
8558 mac_ptr
+= bytes_read
;
8561 complaint (&symfile_complaints
,
8562 "debug info gives macro %s outside of any file: %s",
8564 DW_MACINFO_define
? "definition" : macinfo_type
==
8565 DW_MACINFO_undef
? "undefinition" :
8566 "something-or-other", body
);
8569 if (macinfo_type
== DW_MACINFO_define
)
8570 parse_macro_definition (current_file
, line
, body
);
8571 else if (macinfo_type
== DW_MACINFO_undef
)
8572 macro_undef (current_file
, line
, body
);
8577 case DW_MACINFO_start_file
:
8582 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8583 mac_ptr
+= bytes_read
;
8584 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8585 mac_ptr
+= bytes_read
;
8587 current_file
= macro_start_file (file
, line
,
8588 current_file
, comp_dir
,
8593 case DW_MACINFO_end_file
:
8595 complaint (&symfile_complaints
,
8596 "macro debug info has an unmatched `close_file' directive");
8599 current_file
= current_file
->included_by
;
8602 enum dwarf_macinfo_record_type next_type
;
8604 /* GCC circa March 2002 doesn't produce the zero
8605 type byte marking the end of the compilation
8606 unit. Complain if it's not there, but exit no
8609 /* Do we at least have room for a macinfo type byte? */
8610 if (mac_ptr
>= mac_end
)
8612 dwarf2_macros_too_long_complaint ();
8616 /* We don't increment mac_ptr here, so this is just
8618 next_type
= read_1_byte (abfd
, mac_ptr
);
8620 complaint (&symfile_complaints
,
8621 "no terminating 0-type entry for macros in `.debug_macinfo' section");
8628 case DW_MACINFO_vendor_ext
:
8634 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8635 mac_ptr
+= bytes_read
;
8636 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
8637 mac_ptr
+= bytes_read
;
8639 /* We don't recognize any vendor extensions. */
8646 /* Check if the attribute's form is a DW_FORM_block*
8647 if so return true else false. */
8649 attr_form_is_block (struct attribute
*attr
)
8651 return (attr
== NULL
? 0 :
8652 attr
->form
== DW_FORM_block1
8653 || attr
->form
== DW_FORM_block2
8654 || attr
->form
== DW_FORM_block4
8655 || attr
->form
== DW_FORM_block
);
8659 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
8660 struct dwarf2_cu
*cu
)
8662 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
8664 struct dwarf2_loclist_baton
*baton
;
8666 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
8667 sizeof (struct dwarf2_loclist_baton
));
8668 baton
->objfile
= cu
->objfile
;
8670 /* We don't know how long the location list is, but make sure we
8671 don't run off the edge of the section. */
8672 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
8673 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
8674 baton
->base_address
= cu
->header
.base_address
;
8675 if (cu
->header
.base_known
== 0)
8676 complaint (&symfile_complaints
,
8677 "Location list used without specifying the CU base address.");
8679 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
8680 SYMBOL_LOCATION_BATON (sym
) = baton
;
8684 struct dwarf2_locexpr_baton
*baton
;
8686 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
8687 sizeof (struct dwarf2_locexpr_baton
));
8688 baton
->objfile
= cu
->objfile
;
8690 if (attr_form_is_block (attr
))
8692 /* Note that we're just copying the block's data pointer
8693 here, not the actual data. We're still pointing into the
8694 info_buffer for SYM's objfile; right now we never release
8695 that buffer, but when we do clean up properly this may
8697 baton
->size
= DW_BLOCK (attr
)->size
;
8698 baton
->data
= DW_BLOCK (attr
)->data
;
8702 dwarf2_invalid_attrib_class_complaint ("location description",
8703 SYMBOL_NATURAL_NAME (sym
));
8708 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
8709 SYMBOL_LOCATION_BATON (sym
) = baton
;
8713 /* This cleanup function is passed the address of a dwarf2_cu on the stack
8714 when we're finished with it. We can't free the pointer itself, but
8715 release any associated storage.
8717 Only used during partial symbol parsing. */
8720 free_stack_comp_unit (void *data
)
8722 struct dwarf2_cu
*cu
= data
;
8724 obstack_free (&cu
->comp_unit_obstack
, NULL
);
8725 cu
->partial_dies
= NULL
;
8728 /* Allocation function for the libiberty hash table which uses an
8732 hashtab_obstack_allocate (void *data
, size_t size
, size_t count
)
8734 unsigned int total
= size
* count
;
8735 void *ptr
= obstack_alloc ((struct obstack
*) data
, total
);
8736 memset (ptr
, 0, total
);
8740 /* Trivial deallocation function for the libiberty splay tree and hash
8741 table - don't deallocate anything. Rely on later deletion of the
8745 dummy_obstack_deallocate (void *object
, void *data
)
8750 /* Trivial hash function for partial_die_info: the hash value of a DIE
8751 is its offset in .debug_info for this objfile. */
8754 partial_die_hash (const void *item
)
8756 const struct partial_die_info
*part_die
= item
;
8757 return part_die
->offset
;
8760 /* Trivial comparison function for partial_die_info structures: two DIEs
8761 are equal if they have the same offset. */
8764 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
8766 const struct partial_die_info
*part_die_lhs
= item_lhs
;
8767 const struct partial_die_info
*part_die_rhs
= item_rhs
;
8768 return part_die_lhs
->offset
== part_die_rhs
->offset
;
8771 void _initialize_dwarf2_read (void);
8774 _initialize_dwarf2_read (void)
8776 dwarf2_objfile_data_key
= register_objfile_data ();