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 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2357 set_cu_language (DW_UNSND (attr
), cu
);
2360 /* We assume that we're processing GCC output. */
2361 processing_gcc_compilation
= 2;
2363 /* FIXME:Do something here. */
2364 if (dip
->at_producer
!= NULL
)
2366 handle_producer (dip
->at_producer
);
2370 /* The compilation unit may be in a different language or objfile,
2371 zero out all remembered fundamental types. */
2372 memset (cu
->ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
2374 start_symtab (name
, comp_dir
, lowpc
);
2375 record_debugformat ("DWARF 2");
2377 initialize_cu_func_list (cu
);
2379 /* Process all dies in compilation unit. */
2380 if (die
->child
!= NULL
)
2382 child_die
= die
->child
;
2383 while (child_die
&& child_die
->tag
)
2385 process_die (child_die
, cu
);
2386 child_die
= sibling_die (child_die
);
2390 /* Decode line number information if present. */
2391 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2394 unsigned int line_offset
= DW_UNSND (attr
);
2395 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2398 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
2399 (void *) line_header
);
2400 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2404 /* Decode macro information, if present. Dwarf 2 macro information
2405 refers to information in the line number info statement program
2406 header, so we can only read it if we've read the header
2408 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2409 if (attr
&& line_header
)
2411 unsigned int macro_offset
= DW_UNSND (attr
);
2412 dwarf_decode_macros (line_header
, macro_offset
,
2413 comp_dir
, abfd
, cu
);
2415 do_cleanups (back_to
);
2419 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2420 struct dwarf2_cu
*cu
)
2422 struct function_range
*thisfn
;
2424 thisfn
= (struct function_range
*)
2425 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
2426 thisfn
->name
= name
;
2427 thisfn
->lowpc
= lowpc
;
2428 thisfn
->highpc
= highpc
;
2429 thisfn
->seen_line
= 0;
2430 thisfn
->next
= NULL
;
2432 if (cu
->last_fn
== NULL
)
2433 cu
->first_fn
= thisfn
;
2435 cu
->last_fn
->next
= thisfn
;
2437 cu
->last_fn
= thisfn
;
2441 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2443 struct objfile
*objfile
= cu
->objfile
;
2444 struct context_stack
*new;
2447 struct die_info
*child_die
;
2448 struct attribute
*attr
;
2450 const char *previous_prefix
= processing_current_prefix
;
2451 struct cleanup
*back_to
= NULL
;
2454 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2456 name
= dwarf2_linkage_name (die
, cu
);
2458 /* Ignore functions with missing or empty names and functions with
2459 missing or invalid low and high pc attributes. */
2460 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2463 if (cu
->language
== language_cplus
)
2465 struct die_info
*spec_die
= die_specification (die
, cu
);
2467 /* NOTE: carlton/2004-01-23: We have to be careful in the
2468 presence of DW_AT_specification. For example, with GCC 3.4,
2473 // Definition of N::foo.
2477 then we'll have a tree of DIEs like this:
2479 1: DW_TAG_compile_unit
2480 2: DW_TAG_namespace // N
2481 3: DW_TAG_subprogram // declaration of N::foo
2482 4: DW_TAG_subprogram // definition of N::foo
2483 DW_AT_specification // refers to die #3
2485 Thus, when processing die #4, we have to pretend that we're
2486 in the context of its DW_AT_specification, namely the contex
2489 if (spec_die
!= NULL
)
2491 char *specification_prefix
= determine_prefix (spec_die
, cu
);
2492 processing_current_prefix
= specification_prefix
;
2493 back_to
= make_cleanup (xfree
, specification_prefix
);
2500 /* Record the function range for dwarf_decode_lines. */
2501 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
2503 if (objfile
->ei
.entry_point
>= lowpc
&&
2504 objfile
->ei
.entry_point
< highpc
)
2506 objfile
->ei
.entry_func_lowpc
= lowpc
;
2507 objfile
->ei
.entry_func_highpc
= highpc
;
2510 new = push_context (0, lowpc
);
2511 new->name
= new_symbol (die
, die
->type
, cu
);
2513 /* If there is a location expression for DW_AT_frame_base, record
2515 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
2517 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2518 expression is being recorded directly in the function's symbol
2519 and not in a separate frame-base object. I guess this hack is
2520 to avoid adding some sort of frame-base adjunct/annex to the
2521 function's symbol :-(. The problem with doing this is that it
2522 results in a function symbol with a location expression that
2523 has nothing to do with the location of the function, ouch! The
2524 relationship should be: a function's symbol has-a frame base; a
2525 frame-base has-a location expression. */
2526 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
2528 cu
->list_in_scope
= &local_symbols
;
2530 if (die
->child
!= NULL
)
2532 child_die
= die
->child
;
2533 while (child_die
&& child_die
->tag
)
2535 process_die (child_die
, cu
);
2536 child_die
= sibling_die (child_die
);
2540 new = pop_context ();
2541 /* Make a block for the local symbols within. */
2542 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2543 lowpc
, highpc
, objfile
);
2545 /* In C++, we can have functions nested inside functions (e.g., when
2546 a function declares a class that has methods). This means that
2547 when we finish processing a function scope, we may need to go
2548 back to building a containing block's symbol lists. */
2549 local_symbols
= new->locals
;
2550 param_symbols
= new->params
;
2552 /* If we've finished processing a top-level function, subsequent
2553 symbols go in the file symbol list. */
2554 if (outermost_context_p ())
2555 cu
->list_in_scope
= &file_symbols
;
2557 processing_current_prefix
= previous_prefix
;
2558 if (back_to
!= NULL
)
2559 do_cleanups (back_to
);
2562 /* Process all the DIES contained within a lexical block scope. Start
2563 a new scope, process the dies, and then close the scope. */
2566 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2568 struct objfile
*objfile
= cu
->objfile
;
2569 struct context_stack
*new;
2570 CORE_ADDR lowpc
, highpc
;
2571 struct die_info
*child_die
;
2574 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2576 /* Ignore blocks with missing or invalid low and high pc attributes. */
2577 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2578 as multiple lexical blocks? Handling children in a sane way would
2579 be nasty. Might be easier to properly extend generic blocks to
2581 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2586 push_context (0, lowpc
);
2587 if (die
->child
!= NULL
)
2589 child_die
= die
->child
;
2590 while (child_die
&& child_die
->tag
)
2592 process_die (child_die
, cu
);
2593 child_die
= sibling_die (child_die
);
2596 new = pop_context ();
2598 if (local_symbols
!= NULL
)
2600 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2603 local_symbols
= new->locals
;
2606 /* Get low and high pc attributes from a die. Return 1 if the attributes
2607 are present and valid, otherwise, return 0. Return -1 if the range is
2608 discontinuous, i.e. derived from DW_AT_ranges information. */
2610 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2611 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
2613 struct objfile
*objfile
= cu
->objfile
;
2614 struct comp_unit_head
*cu_header
= &cu
->header
;
2615 struct attribute
*attr
;
2616 bfd
*obfd
= objfile
->obfd
;
2621 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
2624 high
= DW_ADDR (attr
);
2625 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
2627 low
= DW_ADDR (attr
);
2629 /* Found high w/o low attribute. */
2632 /* Found consecutive range of addresses. */
2637 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
2640 unsigned int addr_size
= cu_header
->addr_size
;
2641 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2642 /* Value of the DW_AT_ranges attribute is the offset in the
2643 .debug_ranges section. */
2644 unsigned int offset
= DW_UNSND (attr
);
2645 /* Base address selection entry. */
2653 found_base
= cu_header
->base_known
;
2654 base
= cu_header
->base_address
;
2656 if (offset
>= dwarf2_per_objfile
->ranges_size
)
2658 complaint (&symfile_complaints
,
2659 "Offset %d out of bounds for DW_AT_ranges attribute",
2663 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
2665 /* Read in the largest possible address. */
2666 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
2667 if ((marker
& mask
) == mask
)
2669 /* If we found the largest possible address, then
2670 read the base address. */
2671 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2672 buffer
+= 2 * addr_size
;
2673 offset
+= 2 * addr_size
;
2681 CORE_ADDR range_beginning
, range_end
;
2683 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
2684 buffer
+= addr_size
;
2685 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
2686 buffer
+= addr_size
;
2687 offset
+= 2 * addr_size
;
2689 /* An end of list marker is a pair of zero addresses. */
2690 if (range_beginning
== 0 && range_end
== 0)
2691 /* Found the end of list entry. */
2694 /* Each base address selection entry is a pair of 2 values.
2695 The first is the largest possible address, the second is
2696 the base address. Check for a base address here. */
2697 if ((range_beginning
& mask
) == mask
)
2699 /* If we found the largest possible address, then
2700 read the base address. */
2701 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2708 /* We have no valid base address for the ranges
2710 complaint (&symfile_complaints
,
2711 "Invalid .debug_ranges data (no base address)");
2715 range_beginning
+= base
;
2718 /* FIXME: This is recording everything as a low-high
2719 segment of consecutive addresses. We should have a
2720 data structure for discontiguous block ranges
2724 low
= range_beginning
;
2730 if (range_beginning
< low
)
2731 low
= range_beginning
;
2732 if (range_end
> high
)
2738 /* If the first entry is an end-of-list marker, the range
2739 describes an empty scope, i.e. no instructions. */
2749 /* When using the GNU linker, .gnu.linkonce. sections are used to
2750 eliminate duplicate copies of functions and vtables and such.
2751 The linker will arbitrarily choose one and discard the others.
2752 The AT_*_pc values for such functions refer to local labels in
2753 these sections. If the section from that file was discarded, the
2754 labels are not in the output, so the relocs get a value of 0.
2755 If this is a discarded function, mark the pc bounds as invalid,
2756 so that GDB will ignore it. */
2757 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
2765 /* Get the low and high pc's represented by the scope DIE, and store
2766 them in *LOWPC and *HIGHPC. If the correct values can't be
2767 determined, set *LOWPC to -1 and *HIGHPC to 0. */
2770 get_scope_pc_bounds (struct die_info
*die
,
2771 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2772 struct dwarf2_cu
*cu
)
2774 CORE_ADDR best_low
= (CORE_ADDR
) -1;
2775 CORE_ADDR best_high
= (CORE_ADDR
) 0;
2776 CORE_ADDR current_low
, current_high
;
2778 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
2780 best_low
= current_low
;
2781 best_high
= current_high
;
2785 struct die_info
*child
= die
->child
;
2787 while (child
&& child
->tag
)
2789 switch (child
->tag
) {
2790 case DW_TAG_subprogram
:
2791 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
2793 best_low
= min (best_low
, current_low
);
2794 best_high
= max (best_high
, current_high
);
2797 case DW_TAG_namespace
:
2798 /* FIXME: carlton/2004-01-16: Should we do this for
2799 DW_TAG_class_type/DW_TAG_structure_type, too? I think
2800 that current GCC's always emit the DIEs corresponding
2801 to definitions of methods of classes as children of a
2802 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
2803 the DIEs giving the declarations, which could be
2804 anywhere). But I don't see any reason why the
2805 standards says that they have to be there. */
2806 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
2808 if (current_low
!= ((CORE_ADDR
) -1))
2810 best_low
= min (best_low
, current_low
);
2811 best_high
= max (best_high
, current_high
);
2819 child
= sibling_die (child
);
2824 *highpc
= best_high
;
2827 /* Add an aggregate field to the field list. */
2830 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2831 struct dwarf2_cu
*cu
)
2833 struct objfile
*objfile
= cu
->objfile
;
2834 struct nextfield
*new_field
;
2835 struct attribute
*attr
;
2837 char *fieldname
= "";
2839 /* Allocate a new field list entry and link it in. */
2840 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2841 make_cleanup (xfree
, new_field
);
2842 memset (new_field
, 0, sizeof (struct nextfield
));
2843 new_field
->next
= fip
->fields
;
2844 fip
->fields
= new_field
;
2847 /* Handle accessibility and virtuality of field.
2848 The default accessibility for members is public, the default
2849 accessibility for inheritance is private. */
2850 if (die
->tag
!= DW_TAG_inheritance
)
2851 new_field
->accessibility
= DW_ACCESS_public
;
2853 new_field
->accessibility
= DW_ACCESS_private
;
2854 new_field
->virtuality
= DW_VIRTUALITY_none
;
2856 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
2858 new_field
->accessibility
= DW_UNSND (attr
);
2859 if (new_field
->accessibility
!= DW_ACCESS_public
)
2860 fip
->non_public_fields
= 1;
2861 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
2863 new_field
->virtuality
= DW_UNSND (attr
);
2865 fp
= &new_field
->field
;
2867 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
2869 /* Data member other than a C++ static data member. */
2871 /* Get type of field. */
2872 fp
->type
= die_type (die
, cu
);
2874 FIELD_STATIC_KIND (*fp
) = 0;
2876 /* Get bit size of field (zero if none). */
2877 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
2880 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2884 FIELD_BITSIZE (*fp
) = 0;
2887 /* Get bit offset of field. */
2888 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
2891 FIELD_BITPOS (*fp
) =
2892 decode_locdesc (DW_BLOCK (attr
), cu
) * bits_per_byte
;
2895 FIELD_BITPOS (*fp
) = 0;
2896 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
2899 if (BITS_BIG_ENDIAN
)
2901 /* For big endian bits, the DW_AT_bit_offset gives the
2902 additional bit offset from the MSB of the containing
2903 anonymous object to the MSB of the field. We don't
2904 have to do anything special since we don't need to
2905 know the size of the anonymous object. */
2906 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2910 /* For little endian bits, compute the bit offset to the
2911 MSB of the anonymous object, subtract off the number of
2912 bits from the MSB of the field to the MSB of the
2913 object, and then subtract off the number of bits of
2914 the field itself. The result is the bit offset of
2915 the LSB of the field. */
2917 int bit_offset
= DW_UNSND (attr
);
2919 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
2922 /* The size of the anonymous object containing
2923 the bit field is explicit, so use the
2924 indicated size (in bytes). */
2925 anonymous_size
= DW_UNSND (attr
);
2929 /* The size of the anonymous object containing
2930 the bit field must be inferred from the type
2931 attribute of the data member containing the
2933 anonymous_size
= TYPE_LENGTH (fp
->type
);
2935 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2936 - bit_offset
- FIELD_BITSIZE (*fp
);
2940 /* Get name of field. */
2941 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2942 if (attr
&& DW_STRING (attr
))
2943 fieldname
= DW_STRING (attr
);
2945 /* The name is already allocated along with this objfile, so we don't
2946 need to duplicate it for the type. */
2947 fp
->name
= fieldname
;
2949 /* Change accessibility for artificial fields (e.g. virtual table
2950 pointer or virtual base class pointer) to private. */
2951 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
2953 new_field
->accessibility
= DW_ACCESS_private
;
2954 fip
->non_public_fields
= 1;
2957 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
2959 /* C++ static member. */
2961 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2962 is a declaration, but all versions of G++ as of this writing
2963 (so through at least 3.2.1) incorrectly generate
2964 DW_TAG_variable tags. */
2968 /* Get name of field. */
2969 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2970 if (attr
&& DW_STRING (attr
))
2971 fieldname
= DW_STRING (attr
);
2975 /* Get physical name. */
2976 physname
= dwarf2_linkage_name (die
, cu
);
2978 /* The name is already allocated along with this objfile, so we don't
2979 need to duplicate it for the type. */
2980 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
2981 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2982 FIELD_NAME (*fp
) = fieldname
;
2984 else if (die
->tag
== DW_TAG_inheritance
)
2986 /* C++ base class field. */
2987 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
2989 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
2991 FIELD_BITSIZE (*fp
) = 0;
2992 FIELD_STATIC_KIND (*fp
) = 0;
2993 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2994 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2995 fip
->nbaseclasses
++;
2999 /* Create the vector of fields, and attach it to the type. */
3002 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3003 struct dwarf2_cu
*cu
)
3005 int nfields
= fip
->nfields
;
3007 /* Record the field count, allocate space for the array of fields,
3008 and create blank accessibility bitfields if necessary. */
3009 TYPE_NFIELDS (type
) = nfields
;
3010 TYPE_FIELDS (type
) = (struct field
*)
3011 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3012 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3014 if (fip
->non_public_fields
)
3016 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3018 TYPE_FIELD_PRIVATE_BITS (type
) =
3019 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3020 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3022 TYPE_FIELD_PROTECTED_BITS (type
) =
3023 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3024 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3026 TYPE_FIELD_IGNORE_BITS (type
) =
3027 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3028 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3031 /* If the type has baseclasses, allocate and clear a bit vector for
3032 TYPE_FIELD_VIRTUAL_BITS. */
3033 if (fip
->nbaseclasses
)
3035 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3038 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3039 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
3040 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
3041 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3042 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3045 /* Copy the saved-up fields into the field vector. Start from the head
3046 of the list, adding to the tail of the field array, so that they end
3047 up in the same order in the array in which they were added to the list. */
3048 while (nfields
-- > 0)
3050 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3051 switch (fip
->fields
->accessibility
)
3053 case DW_ACCESS_private
:
3054 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3057 case DW_ACCESS_protected
:
3058 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3061 case DW_ACCESS_public
:
3065 /* Unknown accessibility. Complain and treat it as public. */
3067 complaint (&symfile_complaints
, "unsupported accessibility %d",
3068 fip
->fields
->accessibility
);
3072 if (nfields
< fip
->nbaseclasses
)
3074 switch (fip
->fields
->virtuality
)
3076 case DW_VIRTUALITY_virtual
:
3077 case DW_VIRTUALITY_pure_virtual
:
3078 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3082 fip
->fields
= fip
->fields
->next
;
3086 /* Add a member function to the proper fieldlist. */
3089 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3090 struct type
*type
, struct dwarf2_cu
*cu
)
3092 struct objfile
*objfile
= cu
->objfile
;
3093 struct attribute
*attr
;
3094 struct fnfieldlist
*flp
;
3096 struct fn_field
*fnp
;
3099 struct nextfnfield
*new_fnfield
;
3101 /* Get name of member function. */
3102 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3103 if (attr
&& DW_STRING (attr
))
3104 fieldname
= DW_STRING (attr
);
3108 /* Get the mangled name. */
3109 physname
= dwarf2_linkage_name (die
, cu
);
3111 /* Look up member function name in fieldlist. */
3112 for (i
= 0; i
< fip
->nfnfields
; i
++)
3114 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3118 /* Create new list element if necessary. */
3119 if (i
< fip
->nfnfields
)
3120 flp
= &fip
->fnfieldlists
[i
];
3123 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3125 fip
->fnfieldlists
= (struct fnfieldlist
*)
3126 xrealloc (fip
->fnfieldlists
,
3127 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3128 * sizeof (struct fnfieldlist
));
3129 if (fip
->nfnfields
== 0)
3130 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3132 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3133 flp
->name
= fieldname
;
3139 /* Create a new member function field and chain it to the field list
3141 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3142 make_cleanup (xfree
, new_fnfield
);
3143 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3144 new_fnfield
->next
= flp
->head
;
3145 flp
->head
= new_fnfield
;
3148 /* Fill in the member function field info. */
3149 fnp
= &new_fnfield
->fnfield
;
3150 /* The name is already allocated along with this objfile, so we don't
3151 need to duplicate it for the type. */
3152 fnp
->physname
= physname
? physname
: "";
3153 fnp
->type
= alloc_type (objfile
);
3154 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
3156 int nparams
= TYPE_NFIELDS (die
->type
);
3158 /* TYPE is the domain of this method, and DIE->TYPE is the type
3159 of the method itself (TYPE_CODE_METHOD). */
3160 smash_to_method_type (fnp
->type
, type
,
3161 TYPE_TARGET_TYPE (die
->type
),
3162 TYPE_FIELDS (die
->type
),
3163 TYPE_NFIELDS (die
->type
),
3164 TYPE_VARARGS (die
->type
));
3166 /* Handle static member functions.
3167 Dwarf2 has no clean way to discern C++ static and non-static
3168 member functions. G++ helps GDB by marking the first
3169 parameter for non-static member functions (which is the
3170 this pointer) as artificial. We obtain this information
3171 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3172 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
3173 fnp
->voffset
= VOFFSET_STATIC
;
3176 complaint (&symfile_complaints
, "member function type missing for '%s'",
3179 /* Get fcontext from DW_AT_containing_type if present. */
3180 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3181 fnp
->fcontext
= die_containing_type (die
, cu
);
3183 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3184 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3186 /* Get accessibility. */
3187 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3190 switch (DW_UNSND (attr
))
3192 case DW_ACCESS_private
:
3193 fnp
->is_private
= 1;
3195 case DW_ACCESS_protected
:
3196 fnp
->is_protected
= 1;
3201 /* Check for artificial methods. */
3202 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3203 if (attr
&& DW_UNSND (attr
) != 0)
3204 fnp
->is_artificial
= 1;
3206 /* Get index in virtual function table if it is a virtual member function. */
3207 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3210 /* Support the .debug_loc offsets */
3211 if (attr_form_is_block (attr
))
3213 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3215 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3217 dwarf2_complex_location_expr_complaint ();
3221 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3227 /* Create the vector of member function fields, and attach it to the type. */
3230 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3231 struct dwarf2_cu
*cu
)
3233 struct fnfieldlist
*flp
;
3234 int total_length
= 0;
3237 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3238 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3239 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3241 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3243 struct nextfnfield
*nfp
= flp
->head
;
3244 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3247 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3248 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3249 fn_flp
->fn_fields
= (struct fn_field
*)
3250 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3251 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3252 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3254 total_length
+= flp
->length
;
3257 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3258 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3261 /* Called when we find the DIE that starts a structure or union scope
3262 (definition) to process all dies that define the members of the
3265 NOTE: we need to call struct_type regardless of whether or not the
3266 DIE has an at_name attribute, since it might be an anonymous
3267 structure or union. This gets the type entered into our set of
3270 However, if the structure is incomplete (an opaque struct/union)
3271 then suppress creating a symbol table entry for it since gdb only
3272 wants to find the one with the complete definition. Note that if
3273 it is complete, we just call new_symbol, which does it's own
3274 checking about whether the struct/union is anonymous or not (and
3275 suppresses creating a symbol table entry itself). */
3278 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3280 struct objfile
*objfile
= cu
->objfile
;
3282 struct attribute
*attr
;
3283 const char *previous_prefix
= processing_current_prefix
;
3284 struct cleanup
*back_to
= NULL
;
3289 type
= alloc_type (objfile
);
3291 INIT_CPLUS_SPECIFIC (type
);
3292 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3293 if (attr
&& DW_STRING (attr
))
3295 if (cu
->language
== language_cplus
)
3297 char *new_prefix
= determine_class_name (die
, cu
);
3298 TYPE_TAG_NAME (type
) = obsavestring (new_prefix
,
3299 strlen (new_prefix
),
3300 &objfile
->objfile_obstack
);
3301 back_to
= make_cleanup (xfree
, new_prefix
);
3302 processing_current_prefix
= new_prefix
;
3306 /* The name is already allocated along with this objfile, so
3307 we don't need to duplicate it for the type. */
3308 TYPE_TAG_NAME (type
) = DW_STRING (attr
);
3312 if (die
->tag
== DW_TAG_structure_type
)
3314 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
3316 else if (die
->tag
== DW_TAG_union_type
)
3318 TYPE_CODE (type
) = TYPE_CODE_UNION
;
3322 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
3324 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
3327 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3330 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3334 TYPE_LENGTH (type
) = 0;
3337 if (die_is_declaration (die
, cu
))
3338 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
3340 /* We need to add the type field to the die immediately so we don't
3341 infinitely recurse when dealing with pointers to the structure
3342 type within the structure itself. */
3345 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3347 struct field_info fi
;
3348 struct die_info
*child_die
;
3349 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
3351 memset (&fi
, 0, sizeof (struct field_info
));
3353 child_die
= die
->child
;
3355 while (child_die
&& child_die
->tag
)
3357 if (child_die
->tag
== DW_TAG_member
3358 || child_die
->tag
== DW_TAG_variable
)
3360 /* NOTE: carlton/2002-11-05: A C++ static data member
3361 should be a DW_TAG_member that is a declaration, but
3362 all versions of G++ as of this writing (so through at
3363 least 3.2.1) incorrectly generate DW_TAG_variable
3364 tags for them instead. */
3365 dwarf2_add_field (&fi
, child_die
, cu
);
3367 else if (child_die
->tag
== DW_TAG_subprogram
)
3369 /* C++ member function. */
3370 read_type_die (child_die
, cu
);
3371 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
3373 else if (child_die
->tag
== DW_TAG_inheritance
)
3375 /* C++ base class field. */
3376 dwarf2_add_field (&fi
, child_die
, cu
);
3378 child_die
= sibling_die (child_die
);
3381 /* Attach fields and member functions to the type. */
3383 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
3386 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
3388 /* Get the type which refers to the base class (possibly this
3389 class itself) which contains the vtable pointer for the current
3390 class from the DW_AT_containing_type attribute. */
3392 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3394 struct type
*t
= die_containing_type (die
, cu
);
3396 TYPE_VPTR_BASETYPE (type
) = t
;
3399 static const char vptr_name
[] =
3400 {'_', 'v', 'p', 't', 'r', '\0'};
3403 /* Our own class provides vtbl ptr. */
3404 for (i
= TYPE_NFIELDS (t
) - 1;
3405 i
>= TYPE_N_BASECLASSES (t
);
3408 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
3410 if ((strncmp (fieldname
, vptr_name
,
3411 strlen (vptr_name
) - 1)
3413 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
3415 TYPE_VPTR_FIELDNO (type
) = i
;
3420 /* Complain if virtual function table field not found. */
3421 if (i
< TYPE_N_BASECLASSES (t
))
3422 complaint (&symfile_complaints
,
3423 "virtual function table pointer not found when defining class '%s'",
3424 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
3429 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3434 do_cleanups (back_to
);
3437 processing_current_prefix
= previous_prefix
;
3438 if (back_to
!= NULL
)
3439 do_cleanups (back_to
);
3443 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3445 struct objfile
*objfile
= cu
->objfile
;
3446 const char *previous_prefix
= processing_current_prefix
;
3447 struct die_info
*child_die
= die
->child
;
3449 if (TYPE_TAG_NAME (die
->type
) != NULL
)
3450 processing_current_prefix
= TYPE_TAG_NAME (die
->type
);
3452 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
3453 snapshots) has been known to create a die giving a declaration
3454 for a class that has, as a child, a die giving a definition for a
3455 nested class. So we have to process our children even if the
3456 current die is a declaration. Normally, of course, a declaration
3457 won't have any children at all. */
3459 while (child_die
!= NULL
&& child_die
->tag
)
3461 if (child_die
->tag
== DW_TAG_member
3462 || child_die
->tag
== DW_TAG_variable
3463 || child_die
->tag
== DW_TAG_inheritance
)
3468 process_die (child_die
, cu
);
3470 child_die
= sibling_die (child_die
);
3473 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3474 new_symbol (die
, die
->type
, cu
);
3476 processing_current_prefix
= previous_prefix
;
3479 /* Given a DW_AT_enumeration_type die, set its type. We do not
3480 complete the type's fields yet, or create any symbols. */
3483 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3485 struct objfile
*objfile
= cu
->objfile
;
3487 struct attribute
*attr
;
3492 type
= alloc_type (objfile
);
3494 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3495 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3496 if (attr
&& DW_STRING (attr
))
3498 char *name
= DW_STRING (attr
);
3500 if (processing_has_namespace_info
)
3502 TYPE_TAG_NAME (type
) = obconcat (&objfile
->objfile_obstack
,
3503 processing_current_prefix
,
3504 processing_current_prefix
[0] == '\0'
3510 /* The name is already allocated along with this objfile, so
3511 we don't need to duplicate it for the type. */
3512 TYPE_TAG_NAME (type
) = name
;
3516 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3519 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3523 TYPE_LENGTH (type
) = 0;
3529 /* Determine the name of the type represented by DIE, which should be
3530 a named C++ compound type. Return the name in question; the caller
3531 is responsible for xfree()'ing it. */
3534 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
3536 struct cleanup
*back_to
= NULL
;
3537 struct die_info
*spec_die
= die_specification (die
, cu
);
3538 char *new_prefix
= NULL
;
3540 /* If this is the definition of a class that is declared by another
3541 die, then processing_current_prefix may not be accurate; see
3542 read_func_scope for a similar example. */
3543 if (spec_die
!= NULL
)
3545 char *specification_prefix
= determine_prefix (spec_die
, cu
);
3546 processing_current_prefix
= specification_prefix
;
3547 back_to
= make_cleanup (xfree
, specification_prefix
);
3550 /* If we don't have namespace debug info, guess the name by trying
3551 to demangle the names of members, just like we did in
3552 guess_structure_name. */
3553 if (!processing_has_namespace_info
)
3555 struct die_info
*child
;
3557 for (child
= die
->child
;
3558 child
!= NULL
&& child
->tag
!= 0;
3559 child
= sibling_die (child
))
3561 if (child
->tag
== DW_TAG_subprogram
)
3563 new_prefix
= class_name_from_physname (dwarf2_linkage_name
3566 if (new_prefix
!= NULL
)
3572 if (new_prefix
== NULL
)
3574 const char *name
= dwarf2_name (die
, cu
);
3575 new_prefix
= typename_concat (processing_current_prefix
,
3576 name
? name
: "<<anonymous>>");
3579 if (back_to
!= NULL
)
3580 do_cleanups (back_to
);
3585 /* Given a pointer to a die which begins an enumeration, process all
3586 the dies that define the members of the enumeration, and create the
3587 symbol for the enumeration type.
3589 NOTE: We reverse the order of the element list. */
3592 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3594 struct objfile
*objfile
= cu
->objfile
;
3595 struct die_info
*child_die
;
3596 struct field
*fields
;
3597 struct attribute
*attr
;
3600 int unsigned_enum
= 1;
3604 if (die
->child
!= NULL
)
3606 child_die
= die
->child
;
3607 while (child_die
&& child_die
->tag
)
3609 if (child_die
->tag
!= DW_TAG_enumerator
)
3611 process_die (child_die
, cu
);
3615 attr
= dwarf2_attr (child_die
, DW_AT_name
, cu
);
3618 sym
= new_symbol (child_die
, die
->type
, cu
);
3619 if (SYMBOL_VALUE (sym
) < 0)
3622 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3624 fields
= (struct field
*)
3626 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
3627 * sizeof (struct field
));
3630 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
3631 FIELD_TYPE (fields
[num_fields
]) = NULL
;
3632 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
3633 FIELD_BITSIZE (fields
[num_fields
]) = 0;
3634 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
3640 child_die
= sibling_die (child_die
);
3645 TYPE_NFIELDS (die
->type
) = num_fields
;
3646 TYPE_FIELDS (die
->type
) = (struct field
*)
3647 TYPE_ALLOC (die
->type
, sizeof (struct field
) * num_fields
);
3648 memcpy (TYPE_FIELDS (die
->type
), fields
,
3649 sizeof (struct field
) * num_fields
);
3653 TYPE_FLAGS (die
->type
) |= TYPE_FLAG_UNSIGNED
;
3656 new_symbol (die
, die
->type
, cu
);
3659 /* Extract all information from a DW_TAG_array_type DIE and put it in
3660 the DIE's type field. For now, this only handles one dimensional
3664 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3666 struct objfile
*objfile
= cu
->objfile
;
3667 struct die_info
*child_die
;
3668 struct type
*type
= NULL
;
3669 struct type
*element_type
, *range_type
, *index_type
;
3670 struct type
**range_types
= NULL
;
3671 struct attribute
*attr
;
3673 struct cleanup
*back_to
;
3675 /* Return if we've already decoded this type. */
3681 element_type
= die_type (die
, cu
);
3683 /* Irix 6.2 native cc creates array types without children for
3684 arrays with unspecified length. */
3685 if (die
->child
== NULL
)
3687 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
3688 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3689 die
->type
= create_array_type (NULL
, element_type
, range_type
);
3693 back_to
= make_cleanup (null_cleanup
, NULL
);
3694 child_die
= die
->child
;
3695 while (child_die
&& child_die
->tag
)
3697 if (child_die
->tag
== DW_TAG_subrange_type
)
3699 read_subrange_type (child_die
, cu
);
3701 if (child_die
->type
!= NULL
)
3703 /* The range type was succesfully read. Save it for
3704 the array type creation. */
3705 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3707 range_types
= (struct type
**)
3708 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3709 * sizeof (struct type
*));
3711 make_cleanup (free_current_contents
, &range_types
);
3713 range_types
[ndim
++] = child_die
->type
;
3716 child_die
= sibling_die (child_die
);
3719 /* Dwarf2 dimensions are output from left to right, create the
3720 necessary array types in backwards order. */
3721 type
= element_type
;
3723 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3725 /* Understand Dwarf2 support for vector types (like they occur on
3726 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3727 array type. This is not part of the Dwarf2/3 standard yet, but a
3728 custom vendor extension. The main difference between a regular
3729 array and the vector variant is that vectors are passed by value
3731 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
3733 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3735 do_cleanups (back_to
);
3737 /* Install the type in the die. */
3741 /* First cut: install each common block member as a global variable. */
3744 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
3746 struct die_info
*child_die
;
3747 struct attribute
*attr
;
3749 CORE_ADDR base
= (CORE_ADDR
) 0;
3751 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
3754 /* Support the .debug_loc offsets */
3755 if (attr_form_is_block (attr
))
3757 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
3759 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3761 dwarf2_complex_location_expr_complaint ();
3765 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3766 "common block member");
3769 if (die
->child
!= NULL
)
3771 child_die
= die
->child
;
3772 while (child_die
&& child_die
->tag
)
3774 sym
= new_symbol (child_die
, NULL
, cu
);
3775 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
3778 SYMBOL_VALUE_ADDRESS (sym
) =
3779 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
3780 add_symbol_to_list (sym
, &global_symbols
);
3782 child_die
= sibling_die (child_die
);
3787 /* Read a C++ namespace. */
3790 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3792 struct objfile
*objfile
= cu
->objfile
;
3793 const char *previous_prefix
= processing_current_prefix
;
3796 struct die_info
*current_die
;
3798 name
= namespace_name (die
, &is_anonymous
, cu
);
3800 /* Now build the name of the current namespace. */
3802 if (previous_prefix
[0] == '\0')
3804 processing_current_prefix
= name
;
3808 /* We need temp_name around because processing_current_prefix
3809 is a const char *. */
3810 char *temp_name
= alloca (strlen (previous_prefix
)
3811 + 2 + strlen(name
) + 1);
3812 strcpy (temp_name
, previous_prefix
);
3813 strcat (temp_name
, "::");
3814 strcat (temp_name
, name
);
3816 processing_current_prefix
= temp_name
;
3819 /* Add a symbol associated to this if we haven't seen the namespace
3820 before. Also, add a using directive if it's an anonymous
3823 if (dwarf2_extension (die
, cu
) == NULL
)
3827 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3828 this cast will hopefully become unnecessary. */
3829 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
3830 (char *) processing_current_prefix
,
3832 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
3834 new_symbol (die
, type
, cu
);
3838 cp_add_using_directive (processing_current_prefix
,
3839 strlen (previous_prefix
),
3840 strlen (processing_current_prefix
));
3843 if (die
->child
!= NULL
)
3845 struct die_info
*child_die
= die
->child
;
3847 while (child_die
&& child_die
->tag
)
3849 process_die (child_die
, cu
);
3850 child_die
= sibling_die (child_die
);
3854 processing_current_prefix
= previous_prefix
;
3857 /* Return the name of the namespace represented by DIE. Set
3858 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
3862 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
3864 struct die_info
*current_die
;
3865 const char *name
= NULL
;
3867 /* Loop through the extensions until we find a name. */
3869 for (current_die
= die
;
3870 current_die
!= NULL
;
3871 current_die
= dwarf2_extension (die
, cu
))
3873 name
= dwarf2_name (current_die
, cu
);
3878 /* Is it an anonymous namespace? */
3880 *is_anonymous
= (name
== NULL
);
3882 name
= "(anonymous namespace)";
3887 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3888 the user defined type vector. */
3891 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3893 struct comp_unit_head
*cu_header
= &cu
->header
;
3895 struct attribute
*attr_byte_size
;
3896 struct attribute
*attr_address_class
;
3897 int byte_size
, addr_class
;
3904 type
= lookup_pointer_type (die_type (die
, cu
));
3906 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3908 byte_size
= DW_UNSND (attr_byte_size
);
3910 byte_size
= cu_header
->addr_size
;
3912 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
3913 if (attr_address_class
)
3914 addr_class
= DW_UNSND (attr_address_class
);
3916 addr_class
= DW_ADDR_none
;
3918 /* If the pointer size or address class is different than the
3919 default, create a type variant marked as such and set the
3920 length accordingly. */
3921 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3923 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3927 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3928 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3929 type
= make_type_with_address_space (type
, type_flags
);
3931 else if (TYPE_LENGTH (type
) != byte_size
)
3933 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3936 /* Should we also complain about unhandled address classes? */
3940 TYPE_LENGTH (type
) = byte_size
;
3944 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3945 the user defined type vector. */
3948 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3950 struct objfile
*objfile
= cu
->objfile
;
3952 struct type
*to_type
;
3953 struct type
*domain
;
3960 type
= alloc_type (objfile
);
3961 to_type
= die_type (die
, cu
);
3962 domain
= die_containing_type (die
, cu
);
3963 smash_to_member_type (type
, domain
, to_type
);
3968 /* Extract all information from a DW_TAG_reference_type DIE and add to
3969 the user defined type vector. */
3972 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3974 struct comp_unit_head
*cu_header
= &cu
->header
;
3976 struct attribute
*attr
;
3983 type
= lookup_reference_type (die_type (die
, cu
));
3984 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3987 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3991 TYPE_LENGTH (type
) = cu_header
->addr_size
;
3997 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3999 struct type
*base_type
;
4006 base_type
= die_type (die
, cu
);
4007 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
4011 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4013 struct type
*base_type
;
4020 base_type
= die_type (die
, cu
);
4021 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
4024 /* Extract all information from a DW_TAG_string_type DIE and add to
4025 the user defined type vector. It isn't really a user defined type,
4026 but it behaves like one, with other DIE's using an AT_user_def_type
4027 attribute to reference it. */
4030 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4032 struct objfile
*objfile
= cu
->objfile
;
4033 struct type
*type
, *range_type
, *index_type
, *char_type
;
4034 struct attribute
*attr
;
4035 unsigned int length
;
4042 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4045 length
= DW_UNSND (attr
);
4049 /* check for the DW_AT_byte_size attribute */
4050 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4053 length
= DW_UNSND (attr
);
4060 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
4061 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4062 if (cu
->language
== language_fortran
)
4064 /* Need to create a unique string type for bounds
4066 type
= create_string_type (0, range_type
);
4070 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
, cu
);
4071 type
= create_string_type (char_type
, range_type
);
4076 /* Handle DIES due to C code like:
4080 int (*funcp)(int a, long l);
4084 ('funcp' generates a DW_TAG_subroutine_type DIE)
4088 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4090 struct type
*type
; /* Type that this function returns */
4091 struct type
*ftype
; /* Function that returns above type */
4092 struct attribute
*attr
;
4094 /* Decode the type that this subroutine returns */
4099 type
= die_type (die
, cu
);
4100 ftype
= lookup_function_type (type
);
4102 /* All functions in C++ have prototypes. */
4103 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4104 if ((attr
&& (DW_UNSND (attr
) != 0))
4105 || cu
->language
== language_cplus
)
4106 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
4108 if (die
->child
!= NULL
)
4110 struct die_info
*child_die
;
4114 /* Count the number of parameters.
4115 FIXME: GDB currently ignores vararg functions, but knows about
4116 vararg member functions. */
4117 child_die
= die
->child
;
4118 while (child_die
&& child_die
->tag
)
4120 if (child_die
->tag
== DW_TAG_formal_parameter
)
4122 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4123 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
4124 child_die
= sibling_die (child_die
);
4127 /* Allocate storage for parameters and fill them in. */
4128 TYPE_NFIELDS (ftype
) = nparams
;
4129 TYPE_FIELDS (ftype
) = (struct field
*)
4130 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
4132 child_die
= die
->child
;
4133 while (child_die
&& child_die
->tag
)
4135 if (child_die
->tag
== DW_TAG_formal_parameter
)
4137 /* Dwarf2 has no clean way to discern C++ static and non-static
4138 member functions. G++ helps GDB by marking the first
4139 parameter for non-static member functions (which is the
4140 this pointer) as artificial. We pass this information
4141 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4142 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4144 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4146 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4147 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4150 child_die
= sibling_die (child_die
);
4158 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4160 struct objfile
*objfile
= cu
->objfile
;
4161 struct attribute
*attr
;
4166 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4167 if (attr
&& DW_STRING (attr
))
4169 name
= DW_STRING (attr
);
4171 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
4172 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
4176 /* Find a representation of a given base type and install
4177 it in the TYPE field of the die. */
4180 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4182 struct objfile
*objfile
= cu
->objfile
;
4184 struct attribute
*attr
;
4185 int encoding
= 0, size
= 0;
4187 /* If we've already decoded this die, this is a no-op. */
4193 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4196 encoding
= DW_UNSND (attr
);
4198 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4201 size
= DW_UNSND (attr
);
4203 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4204 if (attr
&& DW_STRING (attr
))
4206 enum type_code code
= TYPE_CODE_INT
;
4211 case DW_ATE_address
:
4212 /* Turn DW_ATE_address into a void * pointer. */
4213 code
= TYPE_CODE_PTR
;
4214 type_flags
|= TYPE_FLAG_UNSIGNED
;
4216 case DW_ATE_boolean
:
4217 code
= TYPE_CODE_BOOL
;
4218 type_flags
|= TYPE_FLAG_UNSIGNED
;
4220 case DW_ATE_complex_float
:
4221 code
= TYPE_CODE_COMPLEX
;
4224 code
= TYPE_CODE_FLT
;
4227 case DW_ATE_signed_char
:
4229 case DW_ATE_unsigned
:
4230 case DW_ATE_unsigned_char
:
4231 type_flags
|= TYPE_FLAG_UNSIGNED
;
4234 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
4235 dwarf_type_encoding_name (encoding
));
4238 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
4239 if (encoding
== DW_ATE_address
)
4240 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
,
4242 else if (encoding
== DW_ATE_complex_float
)
4245 TYPE_TARGET_TYPE (type
)
4246 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
, cu
);
4247 else if (size
== 16)
4248 TYPE_TARGET_TYPE (type
)
4249 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
4251 TYPE_TARGET_TYPE (type
)
4252 = dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
4257 type
= dwarf_base_type (encoding
, size
, cu
);
4262 /* Read the given DW_AT_subrange DIE. */
4265 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4267 struct type
*base_type
;
4268 struct type
*range_type
;
4269 struct attribute
*attr
;
4273 /* If we have already decoded this die, then nothing more to do. */
4277 base_type
= die_type (die
, cu
);
4278 if (base_type
== NULL
)
4280 complaint (&symfile_complaints
,
4281 "DW_AT_type missing from DW_TAG_subrange_type");
4285 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
4286 base_type
= alloc_type (NULL
);
4288 if (cu
->language
== language_fortran
)
4290 /* FORTRAN implies a lower bound of 1, if not given. */
4294 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
4296 low
= dwarf2_get_attr_constant_value (attr
, 0);
4298 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
4301 if (attr
->form
== DW_FORM_block1
)
4303 /* GCC encodes arrays with unspecified or dynamic length
4304 with a DW_FORM_block1 attribute.
4305 FIXME: GDB does not yet know how to handle dynamic
4306 arrays properly, treat them as arrays with unspecified
4309 FIXME: jimb/2003-09-22: GDB does not really know
4310 how to handle arrays of unspecified length
4311 either; we just represent them as zero-length
4312 arrays. Choose an appropriate upper bound given
4313 the lower bound we've computed above. */
4317 high
= dwarf2_get_attr_constant_value (attr
, 1);
4320 range_type
= create_range_type (NULL
, base_type
, low
, high
);
4322 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4323 if (attr
&& DW_STRING (attr
))
4324 TYPE_NAME (range_type
) = DW_STRING (attr
);
4326 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4328 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
4330 die
->type
= range_type
;
4334 /* Read a whole compilation unit into a linked list of dies. */
4336 static struct die_info
*
4337 read_comp_unit (char *info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
4339 /* Reset die reference table; we are
4340 building new ones now. */
4341 dwarf2_empty_hash_tables ();
4343 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
4346 /* Read a single die and all its descendents. Set the die's sibling
4347 field to NULL; set other fields in the die correctly, and set all
4348 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4349 location of the info_ptr after reading all of those dies. PARENT
4350 is the parent of the die in question. */
4352 static struct die_info
*
4353 read_die_and_children (char *info_ptr
, bfd
*abfd
,
4354 struct dwarf2_cu
*cu
,
4355 char **new_info_ptr
,
4356 struct die_info
*parent
)
4358 struct die_info
*die
;
4362 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
4363 store_in_ref_table (die
->offset
, die
);
4367 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
4373 *new_info_ptr
= cur_ptr
;
4376 die
->sibling
= NULL
;
4377 die
->parent
= parent
;
4381 /* Read a die, all of its descendents, and all of its siblings; set
4382 all of the fields of all of the dies correctly. Arguments are as
4383 in read_die_and_children. */
4385 static struct die_info
*
4386 read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
4387 struct dwarf2_cu
*cu
,
4388 char **new_info_ptr
,
4389 struct die_info
*parent
)
4391 struct die_info
*first_die
, *last_sibling
;
4395 first_die
= last_sibling
= NULL
;
4399 struct die_info
*die
4400 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
4408 last_sibling
->sibling
= die
;
4413 *new_info_ptr
= cur_ptr
;
4423 /* Free a linked list of dies. */
4426 free_die_list (struct die_info
*dies
)
4428 struct die_info
*die
, *next
;
4433 if (die
->child
!= NULL
)
4434 free_die_list (die
->child
);
4435 next
= die
->sibling
;
4443 do_free_die_list_cleanup (void *dies
)
4445 free_die_list (dies
);
4448 static struct cleanup
*
4449 make_cleanup_free_die_list (struct die_info
*dies
)
4451 return make_cleanup (do_free_die_list_cleanup
, dies
);
4455 /* Read the contents of the section at OFFSET and of size SIZE from the
4456 object file specified by OBJFILE into the objfile_obstack and return it. */
4459 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
4461 bfd
*abfd
= objfile
->obfd
;
4463 bfd_size_type size
= bfd_get_section_size_before_reloc (sectp
);
4468 buf
= (char *) obstack_alloc (&objfile
->objfile_obstack
, size
);
4470 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
4474 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
4475 || bfd_bread (buf
, size
, abfd
) != size
)
4476 error ("Dwarf Error: Can't read DWARF data from '%s'",
4477 bfd_get_filename (abfd
));
4482 /* In DWARF version 2, the description of the debugging information is
4483 stored in a separate .debug_abbrev section. Before we read any
4484 dies from a section we read in all abbreviations and install them
4485 in a hash table. This function also sets flags in CU describing
4486 the data found in the abbrev table. */
4489 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
4491 struct comp_unit_head
*cu_header
= &cu
->header
;
4493 struct abbrev_info
*cur_abbrev
;
4494 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
4495 unsigned int abbrev_form
, hash_number
;
4496 struct attr_abbrev
*cur_attrs
;
4497 unsigned int allocated_attrs
;
4499 /* Initialize dwarf2 abbrevs */
4500 obstack_init (&cu
->abbrev_obstack
);
4501 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
4503 * sizeof (struct abbrev_info
*)));
4504 memset (cu
->dwarf2_abbrevs
, 0,
4505 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
4507 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
4508 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4509 abbrev_ptr
+= bytes_read
;
4511 allocated_attrs
= ATTR_ALLOC_CHUNK
;
4512 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
4514 /* loop until we reach an abbrev number of 0 */
4515 while (abbrev_number
)
4517 cur_abbrev
= dwarf_alloc_abbrev (cu
);
4519 /* read in abbrev header */
4520 cur_abbrev
->number
= abbrev_number
;
4521 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4522 abbrev_ptr
+= bytes_read
;
4523 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
4526 if (cur_abbrev
->tag
== DW_TAG_namespace
)
4527 cu
->has_namespace_info
= 1;
4529 /* now read in declarations */
4530 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4531 abbrev_ptr
+= bytes_read
;
4532 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4533 abbrev_ptr
+= bytes_read
;
4536 if (cur_abbrev
->num_attrs
== allocated_attrs
)
4538 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
4540 = xrealloc (cur_attrs
, (allocated_attrs
4541 * sizeof (struct attr_abbrev
)));
4543 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
4544 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
4545 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4546 abbrev_ptr
+= bytes_read
;
4547 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4548 abbrev_ptr
+= bytes_read
;
4551 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
4552 (cur_abbrev
->num_attrs
4553 * sizeof (struct attr_abbrev
)));
4554 memcpy (cur_abbrev
->attrs
, cur_attrs
,
4555 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
4557 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
4558 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
4559 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
4561 /* Get next abbreviation.
4562 Under Irix6 the abbreviations for a compilation unit are not
4563 always properly terminated with an abbrev number of 0.
4564 Exit loop if we encounter an abbreviation which we have
4565 already read (which means we are about to read the abbreviations
4566 for the next compile unit) or if the end of the abbreviation
4567 table is reached. */
4568 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
4569 >= dwarf2_per_objfile
->abbrev_size
)
4571 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4572 abbrev_ptr
+= bytes_read
;
4573 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
4580 /* Release the memory used by the abbrev table for a compilation unit. */
4583 dwarf2_free_abbrev_table (void *ptr_to_cu
)
4585 struct dwarf2_cu
*cu
= ptr_to_cu
;
4587 obstack_free (&cu
->abbrev_obstack
, NULL
);
4588 cu
->dwarf2_abbrevs
= NULL
;
4591 /* Lookup an abbrev_info structure in the abbrev hash table. */
4593 static struct abbrev_info
*
4594 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
4596 unsigned int hash_number
;
4597 struct abbrev_info
*abbrev
;
4599 hash_number
= number
% ABBREV_HASH_SIZE
;
4600 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
4604 if (abbrev
->number
== number
)
4607 abbrev
= abbrev
->next
;
4612 /* Returns nonzero if TAG represents a type that we might generate a partial
4616 is_type_tag_for_partial (int tag
)
4621 /* Some types that would be reasonable to generate partial symbols for,
4622 that we don't at present. */
4623 case DW_TAG_array_type
:
4624 case DW_TAG_file_type
:
4625 case DW_TAG_ptr_to_member_type
:
4626 case DW_TAG_set_type
:
4627 case DW_TAG_string_type
:
4628 case DW_TAG_subroutine_type
:
4630 case DW_TAG_base_type
:
4631 case DW_TAG_class_type
:
4632 case DW_TAG_enumeration_type
:
4633 case DW_TAG_structure_type
:
4634 case DW_TAG_subrange_type
:
4635 case DW_TAG_typedef
:
4636 case DW_TAG_union_type
:
4643 /* Load all DIEs that are interesting for partial symbols into memory. */
4645 static struct partial_die_info
*
4646 load_partial_dies (bfd
*abfd
, char *info_ptr
, int building_psymtab
,
4647 struct dwarf2_cu
*cu
)
4649 struct partial_die_info
*part_die
;
4650 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
4651 struct abbrev_info
*abbrev
;
4652 unsigned int bytes_read
;
4654 int nesting_level
= 1;
4660 = htab_create_alloc_ex (cu
->header
.length
/ 12,
4664 &cu
->comp_unit_obstack
,
4665 hashtab_obstack_allocate
,
4666 dummy_obstack_deallocate
);
4668 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
4669 sizeof (struct partial_die_info
));
4673 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4675 /* A NULL abbrev means the end of a series of children. */
4678 if (--nesting_level
== 0)
4680 /* PART_DIE was probably the last thing allocated on the
4681 comp_unit_obstack, so we could call obstack_free
4682 here. We don't do that because the waste is small,
4683 and will be cleaned up when we're done with this
4684 compilation unit. This way, we're also more robust
4685 against other users of the comp_unit_obstack. */
4688 info_ptr
+= bytes_read
;
4689 last_die
= parent_die
;
4690 parent_die
= parent_die
->die_parent
;
4694 /* Check whether this DIE is interesting enough to save. */
4695 if (!is_type_tag_for_partial (abbrev
->tag
)
4696 && abbrev
->tag
!= DW_TAG_enumerator
4697 && abbrev
->tag
!= DW_TAG_subprogram
4698 && abbrev
->tag
!= DW_TAG_variable
4699 && abbrev
->tag
!= DW_TAG_namespace
)
4701 /* Otherwise we skip to the next sibling, if any. */
4702 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
4706 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
4707 abfd
, info_ptr
, cu
);
4709 /* This two-pass algorithm for processing partial symbols has a
4710 high cost in cache pressure. Thus, handle some simple cases
4711 here which cover the majority of C partial symbols. DIEs
4712 which neither have specification tags in them, nor could have
4713 specification tags elsewhere pointing at them, can simply be
4714 processed and discarded.
4716 This segment is also optional; scan_partial_symbols and
4717 add_partial_symbol will handle these DIEs if we chain
4718 them in normally. When compilers which do not emit large
4719 quantities of duplicate debug information are more common,
4720 this code can probably be removed. */
4722 /* Any complete simple types at the top level (pretty much all
4723 of them, for a language without namespaces), can be processed
4725 if (parent_die
== NULL
4726 && part_die
->has_specification
== 0
4727 && part_die
->is_declaration
== 0
4728 && (part_die
->tag
== DW_TAG_typedef
4729 || part_die
->tag
== DW_TAG_base_type
4730 || part_die
->tag
== DW_TAG_subrange_type
))
4732 if (building_psymtab
&& part_die
->name
!= NULL
)
4733 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
4734 VAR_DOMAIN
, LOC_TYPEDEF
,
4735 &cu
->objfile
->static_psymbols
,
4736 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
4737 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
4741 /* If we're at the second level, and we're an enumerator, and
4742 our parent has no specification (meaning possibly lives in a
4743 namespace elsewhere), then we can add the partial symbol now
4744 instead of queueing it. */
4745 if (part_die
->tag
== DW_TAG_enumerator
4746 && parent_die
!= NULL
4747 && parent_die
->die_parent
== NULL
4748 && parent_die
->tag
== DW_TAG_enumeration_type
4749 && parent_die
->has_specification
== 0)
4751 if (part_die
->name
== NULL
)
4752 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
4753 else if (building_psymtab
)
4754 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
4755 VAR_DOMAIN
, LOC_CONST
,
4756 cu
->language
== language_cplus
4757 ? &cu
->objfile
->global_psymbols
4758 : &cu
->objfile
->static_psymbols
,
4759 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
4761 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
4765 /* We'll save this DIE so link it in. */
4766 part_die
->die_parent
= parent_die
;
4767 part_die
->die_sibling
= NULL
;
4768 part_die
->die_child
= NULL
;
4770 if (last_die
&& last_die
== parent_die
)
4771 last_die
->die_child
= part_die
;
4773 last_die
->die_sibling
= part_die
;
4775 last_die
= part_die
;
4777 if (first_die
== NULL
)
4778 first_die
= part_die
;
4780 /* Maybe add the DIE to the hash table. Not all DIEs that we
4781 find interesting need to be in the hash table, because we
4782 also have the parent/sibling/child chains; only those that we
4783 might refer to by offset later during partial symbol reading.
4785 For now this means things that might have be the target of a
4786 DW_AT_specification, DW_AT_abstract_origin, or
4787 DW_AT_extension. DW_AT_extension will refer only to
4788 namespaces; DW_AT_abstract_origin refers to functions (and
4789 many things under the function DIE, but we do not recurse
4790 into function DIEs during partial symbol reading) and
4791 possibly variables as well; DW_AT_specification refers to
4792 declarations. Declarations ought to have the DW_AT_declaration
4793 flag. It happens that GCC forgets to put it in sometimes, but
4794 only for functions, not for types.
4796 Adding more things than necessary to the hash table is harmless
4797 except for the performance cost. Adding too few will result in
4798 internal errors in find_partial_die. */
4800 if (abbrev
->tag
== DW_TAG_subprogram
4801 || abbrev
->tag
== DW_TAG_variable
4802 || abbrev
->tag
== DW_TAG_namespace
4803 || part_die
->is_declaration
)
4807 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
4808 part_die
->offset
, INSERT
);
4812 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
4813 sizeof (struct partial_die_info
));
4815 /* For some DIEs we want to follow their children (if any). For C
4816 we have no reason to follow the children of structures; for other
4817 languages we have to, both so that we can get at method physnames
4818 to infer fully qualified class names, and for DW_AT_specification. */
4819 if (last_die
->has_children
4820 && (last_die
->tag
== DW_TAG_namespace
4821 || last_die
->tag
== DW_TAG_enumeration_type
4822 || (cu
->language
!= language_c
4823 && (last_die
->tag
== DW_TAG_class_type
4824 || last_die
->tag
== DW_TAG_structure_type
4825 || last_die
->tag
== DW_TAG_union_type
))))
4828 parent_die
= last_die
;
4832 /* Otherwise we skip to the next sibling, if any. */
4833 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
4835 /* Back to the top, do it again. */
4839 /* Read a minimal amount of information into the minimal die structure. */
4842 read_partial_die (struct partial_die_info
*part_die
,
4843 struct abbrev_info
*abbrev
,
4844 unsigned int abbrev_len
, bfd
*abfd
,
4845 char *info_ptr
, struct dwarf2_cu
*cu
)
4847 unsigned int bytes_read
, i
;
4848 struct attribute attr
;
4849 int has_low_pc_attr
= 0;
4850 int has_high_pc_attr
= 0;
4852 memset (part_die
, 0, sizeof (struct partial_die_info
));
4854 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
4856 info_ptr
+= abbrev_len
;
4861 part_die
->tag
= abbrev
->tag
;
4862 part_die
->has_children
= abbrev
->has_children
;
4864 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4866 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
4868 /* Store the data if it is of an attribute we want to keep in a
4869 partial symbol table. */
4874 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
4875 if (part_die
->name
== NULL
)
4876 part_die
->name
= DW_STRING (&attr
);
4878 case DW_AT_MIPS_linkage_name
:
4879 part_die
->name
= DW_STRING (&attr
);
4882 has_low_pc_attr
= 1;
4883 part_die
->lowpc
= DW_ADDR (&attr
);
4886 has_high_pc_attr
= 1;
4887 part_die
->highpc
= DW_ADDR (&attr
);
4889 case DW_AT_location
:
4890 /* Support the .debug_loc offsets */
4891 if (attr_form_is_block (&attr
))
4893 part_die
->locdesc
= DW_BLOCK (&attr
);
4895 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
4897 dwarf2_complex_location_expr_complaint ();
4901 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4902 "partial symbol information");
4905 case DW_AT_language
:
4906 part_die
->language
= DW_UNSND (&attr
);
4908 case DW_AT_external
:
4909 part_die
->is_external
= DW_UNSND (&attr
);
4911 case DW_AT_declaration
:
4912 part_die
->is_declaration
= DW_UNSND (&attr
);
4915 part_die
->has_type
= 1;
4917 case DW_AT_abstract_origin
:
4918 case DW_AT_specification
:
4919 case DW_AT_extension
:
4920 part_die
->has_specification
= 1;
4921 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
4924 /* Ignore absolute siblings, they might point outside of
4925 the current compile unit. */
4926 if (attr
.form
== DW_FORM_ref_addr
)
4927 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
4929 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
4930 + dwarf2_get_ref_die_offset (&attr
, cu
);
4932 case DW_AT_stmt_list
:
4933 part_die
->has_stmt_list
= 1;
4934 part_die
->line_offset
= DW_UNSND (&attr
);
4941 /* When using the GNU linker, .gnu.linkonce. sections are used to
4942 eliminate duplicate copies of functions and vtables and such.
4943 The linker will arbitrarily choose one and discard the others.
4944 The AT_*_pc values for such functions refer to local labels in
4945 these sections. If the section from that file was discarded, the
4946 labels are not in the output, so the relocs get a value of 0.
4947 If this is a discarded function, mark the pc bounds as invalid,
4948 so that GDB will ignore it. */
4949 if (has_low_pc_attr
&& has_high_pc_attr
4950 && part_die
->lowpc
< part_die
->highpc
4951 && (part_die
->lowpc
!= 0
4952 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
4953 part_die
->has_pc_info
= 1;
4957 /* Find a cached partial DIE at OFFSET in CU. */
4959 static struct partial_die_info
*
4960 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
4962 struct partial_die_info
*lookup_die
= NULL
;
4963 struct partial_die_info part_die
;
4965 part_die
.offset
= offset
;
4966 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
4968 if (lookup_die
== NULL
)
4969 internal_error (__FILE__
, __LINE__
,
4970 "could not find partial DIE in cache\n");
4975 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
4977 static struct partial_die_info
*
4978 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
,
4979 struct dwarf2_cu
**target_cu
)
4981 struct dwarf2_per_cu_data
*per_cu
;
4983 if (offset
>= cu
->header
.offset
4984 && offset
< cu
->header
.offset
+ cu
->header
.length
)
4987 return find_partial_die_in_comp_unit (offset
, cu
);
4990 internal_error (__FILE__
, __LINE__
,
4991 "unsupported inter-compilation-unit reference");
4994 /* Adjust PART_DIE before generating a symbol for it. This function
4995 may set the is_external flag or change the DIE's name. */
4998 fixup_partial_die (struct partial_die_info
*part_die
,
4999 struct dwarf2_cu
*cu
)
5001 /* If we found a reference attribute and the DIE has no name, try
5002 to find a name in the referred to DIE. */
5004 if (part_die
->name
== NULL
&& part_die
->has_specification
)
5006 struct partial_die_info
*spec_die
;
5007 struct dwarf2_cu
*spec_cu
;
5009 spec_die
= find_partial_die (part_die
->spec_offset
, cu
, &spec_cu
);
5011 fixup_partial_die (spec_die
, spec_cu
);
5015 part_die
->name
= spec_die
->name
;
5017 /* Copy DW_AT_external attribute if it is set. */
5018 if (spec_die
->is_external
)
5019 part_die
->is_external
= spec_die
->is_external
;
5023 /* Set default names for some unnamed DIEs. */
5024 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
5025 || part_die
->tag
== DW_TAG_class_type
))
5026 part_die
->name
= "(anonymous class)";
5028 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
5029 part_die
->name
= "(anonymous namespace)";
5031 if (part_die
->tag
== DW_TAG_structure_type
5032 || part_die
->tag
== DW_TAG_class_type
5033 || part_die
->tag
== DW_TAG_union_type
)
5034 guess_structure_name (part_die
, cu
);
5037 /* Read the die from the .debug_info section buffer. Set DIEP to
5038 point to a newly allocated die with its information, except for its
5039 child, sibling, and parent fields. Set HAS_CHILDREN to tell
5040 whether the die has children or not. */
5043 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
5044 struct dwarf2_cu
*cu
, int *has_children
)
5046 unsigned int abbrev_number
, bytes_read
, i
, offset
;
5047 struct abbrev_info
*abbrev
;
5048 struct die_info
*die
;
5050 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5051 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5052 info_ptr
+= bytes_read
;
5055 die
= dwarf_alloc_die ();
5057 die
->abbrev
= abbrev_number
;
5064 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
5067 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
5069 bfd_get_filename (abfd
));
5071 die
= dwarf_alloc_die ();
5072 die
->offset
= offset
;
5073 die
->tag
= abbrev
->tag
;
5074 die
->abbrev
= abbrev_number
;
5077 die
->num_attrs
= abbrev
->num_attrs
;
5078 die
->attrs
= (struct attribute
*)
5079 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
5081 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5083 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
5084 abfd
, info_ptr
, cu
);
5088 *has_children
= abbrev
->has_children
;
5092 /* Read an attribute value described by an attribute form. */
5095 read_attribute_value (struct attribute
*attr
, unsigned form
,
5096 bfd
*abfd
, char *info_ptr
,
5097 struct dwarf2_cu
*cu
)
5099 struct comp_unit_head
*cu_header
= &cu
->header
;
5100 unsigned int bytes_read
;
5101 struct dwarf_block
*blk
;
5107 case DW_FORM_ref_addr
:
5108 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
5109 info_ptr
+= bytes_read
;
5111 case DW_FORM_block2
:
5112 blk
= dwarf_alloc_block (cu
);
5113 blk
->size
= read_2_bytes (abfd
, info_ptr
);
5115 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5116 info_ptr
+= blk
->size
;
5117 DW_BLOCK (attr
) = blk
;
5119 case DW_FORM_block4
:
5120 blk
= dwarf_alloc_block (cu
);
5121 blk
->size
= read_4_bytes (abfd
, info_ptr
);
5123 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5124 info_ptr
+= blk
->size
;
5125 DW_BLOCK (attr
) = blk
;
5128 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
5132 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
5136 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
5139 case DW_FORM_string
:
5140 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
5141 info_ptr
+= bytes_read
;
5144 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
5146 info_ptr
+= bytes_read
;
5149 blk
= dwarf_alloc_block (cu
);
5150 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5151 info_ptr
+= bytes_read
;
5152 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5153 info_ptr
+= blk
->size
;
5154 DW_BLOCK (attr
) = blk
;
5156 case DW_FORM_block1
:
5157 blk
= dwarf_alloc_block (cu
);
5158 blk
->size
= read_1_byte (abfd
, info_ptr
);
5160 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5161 info_ptr
+= blk
->size
;
5162 DW_BLOCK (attr
) = blk
;
5165 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5169 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5173 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
5174 info_ptr
+= bytes_read
;
5177 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5178 info_ptr
+= bytes_read
;
5181 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5185 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
5189 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
5193 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
5196 case DW_FORM_ref_udata
:
5197 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5198 info_ptr
+= bytes_read
;
5200 case DW_FORM_indirect
:
5201 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5202 info_ptr
+= bytes_read
;
5203 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
5206 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
5207 dwarf_form_name (form
),
5208 bfd_get_filename (abfd
));
5213 /* Read an attribute described by an abbreviated attribute. */
5216 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
5217 bfd
*abfd
, char *info_ptr
, struct dwarf2_cu
*cu
)
5219 attr
->name
= abbrev
->name
;
5220 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
5223 /* read dwarf information from a buffer */
5226 read_1_byte (bfd
*abfd
, char *buf
)
5228 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5232 read_1_signed_byte (bfd
*abfd
, char *buf
)
5234 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
5238 read_2_bytes (bfd
*abfd
, char *buf
)
5240 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
5244 read_2_signed_bytes (bfd
*abfd
, char *buf
)
5246 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
5250 read_4_bytes (bfd
*abfd
, char *buf
)
5252 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5256 read_4_signed_bytes (bfd
*abfd
, char *buf
)
5258 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
5261 static unsigned long
5262 read_8_bytes (bfd
*abfd
, char *buf
)
5264 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5268 read_address (bfd
*abfd
, char *buf
, struct dwarf2_cu
*cu
, int *bytes_read
)
5270 struct comp_unit_head
*cu_header
= &cu
->header
;
5271 CORE_ADDR retval
= 0;
5273 if (cu_header
->signed_addr_p
)
5275 switch (cu_header
->addr_size
)
5278 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
5281 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
5284 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
5287 internal_error (__FILE__
, __LINE__
,
5288 "read_address: bad switch, signed [in module %s]",
5289 bfd_get_filename (abfd
));
5294 switch (cu_header
->addr_size
)
5297 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
5300 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5303 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5306 internal_error (__FILE__
, __LINE__
,
5307 "read_address: bad switch, unsigned [in module %s]",
5308 bfd_get_filename (abfd
));
5312 *bytes_read
= cu_header
->addr_size
;
5316 /* Read the initial length from a section. The (draft) DWARF 3
5317 specification allows the initial length to take up either 4 bytes
5318 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
5319 bytes describe the length and all offsets will be 8 bytes in length
5322 An older, non-standard 64-bit format is also handled by this
5323 function. The older format in question stores the initial length
5324 as an 8-byte quantity without an escape value. Lengths greater
5325 than 2^32 aren't very common which means that the initial 4 bytes
5326 is almost always zero. Since a length value of zero doesn't make
5327 sense for the 32-bit format, this initial zero can be considered to
5328 be an escape value which indicates the presence of the older 64-bit
5329 format. As written, the code can't detect (old format) lengths
5330 greater than 4GB. If it becomes necessary to handle lengths somewhat
5331 larger than 4GB, we could allow other small values (such as the
5332 non-sensical values of 1, 2, and 3) to also be used as escape values
5333 indicating the presence of the old format.
5335 The value returned via bytes_read should be used to increment
5336 the relevant pointer after calling read_initial_length().
5338 As a side effect, this function sets the fields initial_length_size
5339 and offset_size in cu_header to the values appropriate for the
5340 length field. (The format of the initial length field determines
5341 the width of file offsets to be fetched later with fetch_offset().)
5343 [ Note: read_initial_length() and read_offset() are based on the
5344 document entitled "DWARF Debugging Information Format", revision
5345 3, draft 8, dated November 19, 2001. This document was obtained
5348 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
5350 This document is only a draft and is subject to change. (So beware.)
5352 Details regarding the older, non-standard 64-bit format were
5353 determined empirically by examining 64-bit ELF files produced
5354 by the SGI toolchain on an IRIX 6.5 machine.
5356 - Kevin, July 16, 2002
5360 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
5365 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5367 if (retval
== 0xffffffff)
5369 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
5371 if (cu_header
!= NULL
)
5373 cu_header
->initial_length_size
= 12;
5374 cu_header
->offset_size
= 8;
5377 else if (retval
== 0)
5379 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
5381 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5383 if (cu_header
!= NULL
)
5385 cu_header
->initial_length_size
= 8;
5386 cu_header
->offset_size
= 8;
5392 if (cu_header
!= NULL
)
5394 cu_header
->initial_length_size
= 4;
5395 cu_header
->offset_size
= 4;
5402 /* Read an offset from the data stream. The size of the offset is
5403 given by cu_header->offset_size. */
5406 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
5411 switch (cu_header
->offset_size
)
5414 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5418 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5422 internal_error (__FILE__
, __LINE__
,
5423 "read_offset: bad switch [in module %s]",
5424 bfd_get_filename (abfd
));
5431 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
5433 /* If the size of a host char is 8 bits, we can return a pointer
5434 to the buffer, otherwise we have to copy the data to a buffer
5435 allocated on the temporary obstack. */
5436 gdb_assert (HOST_CHAR_BIT
== 8);
5441 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5443 /* If the size of a host char is 8 bits, we can return a pointer
5444 to the string, otherwise we have to copy the string to a buffer
5445 allocated on the temporary obstack. */
5446 gdb_assert (HOST_CHAR_BIT
== 8);
5449 *bytes_read_ptr
= 1;
5452 *bytes_read_ptr
= strlen (buf
) + 1;
5457 read_indirect_string (bfd
*abfd
, char *buf
,
5458 const struct comp_unit_head
*cu_header
,
5459 unsigned int *bytes_read_ptr
)
5461 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
5462 (int *) bytes_read_ptr
);
5464 if (dwarf2_per_objfile
->str_buffer
== NULL
)
5466 error ("DW_FORM_strp used without .debug_str section [in module %s]",
5467 bfd_get_filename (abfd
));
5470 if (str_offset
>= dwarf2_per_objfile
->str_size
)
5472 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
5473 bfd_get_filename (abfd
));
5476 gdb_assert (HOST_CHAR_BIT
== 8);
5477 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
5479 return dwarf2_per_objfile
->str_buffer
+ str_offset
;
5482 static unsigned long
5483 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5485 unsigned long result
;
5486 unsigned int num_read
;
5496 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5499 result
|= ((unsigned long)(byte
& 127) << shift
);
5500 if ((byte
& 128) == 0)
5506 *bytes_read_ptr
= num_read
;
5511 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5514 int i
, shift
, size
, num_read
;
5524 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5527 result
|= ((long)(byte
& 127) << shift
);
5529 if ((byte
& 128) == 0)
5534 if ((shift
< size
) && (byte
& 0x40))
5536 result
|= -(1 << shift
);
5538 *bytes_read_ptr
= num_read
;
5542 /* Return a pointer to just past the end of an LEB128 number in BUF. */
5545 skip_leb128 (bfd
*abfd
, char *buf
)
5551 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5553 if ((byte
& 128) == 0)
5559 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
5565 cu
->language
= language_c
;
5567 case DW_LANG_C_plus_plus
:
5568 cu
->language
= language_cplus
;
5570 case DW_LANG_Fortran77
:
5571 case DW_LANG_Fortran90
:
5572 case DW_LANG_Fortran95
:
5573 cu
->language
= language_fortran
;
5575 case DW_LANG_Mips_Assembler
:
5576 cu
->language
= language_asm
;
5579 cu
->language
= language_java
;
5583 case DW_LANG_Cobol74
:
5584 case DW_LANG_Cobol85
:
5585 case DW_LANG_Pascal83
:
5586 case DW_LANG_Modula2
:
5588 cu
->language
= language_minimal
;
5591 cu
->language_defn
= language_def (cu
->language
);
5594 /* Return the named attribute or NULL if not there. */
5596 static struct attribute
*
5597 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
5600 struct attribute
*spec
= NULL
;
5602 for (i
= 0; i
< die
->num_attrs
; ++i
)
5604 if (die
->attrs
[i
].name
== name
)
5606 return &die
->attrs
[i
];
5608 if (die
->attrs
[i
].name
== DW_AT_specification
5609 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
5610 spec
= &die
->attrs
[i
];
5614 struct die_info
*ref_die
=
5615 follow_die_ref (dwarf2_get_ref_die_offset (spec
, cu
));
5618 return dwarf2_attr (ref_die
, name
, cu
);
5624 /* Return non-zero iff the attribute NAME is defined for the given DIE,
5625 and holds a non-zero value. This function should only be used for
5626 DW_FORM_flag attributes. */
5629 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
5631 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
5633 return (attr
&& DW_UNSND (attr
));
5637 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
5639 /* A DIE is a declaration if it has a DW_AT_declaration attribute
5640 which value is non-zero. However, we have to be careful with
5641 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
5642 (via dwarf2_flag_true_p) follows this attribute. So we may
5643 end up accidently finding a declaration attribute that belongs
5644 to a different DIE referenced by the specification attribute,
5645 even though the given DIE does not have a declaration attribute. */
5646 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
5647 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
5650 /* Return the die giving the specification for DIE, if there is
5653 static struct die_info
*
5654 die_specification (struct die_info
*die
, struct dwarf2_cu
*cu
)
5656 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
, cu
);
5658 if (spec_attr
== NULL
)
5661 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr
, cu
));
5664 /* Free the line_header structure *LH, and any arrays and strings it
5667 free_line_header (struct line_header
*lh
)
5669 if (lh
->standard_opcode_lengths
)
5670 xfree (lh
->standard_opcode_lengths
);
5672 /* Remember that all the lh->file_names[i].name pointers are
5673 pointers into debug_line_buffer, and don't need to be freed. */
5675 xfree (lh
->file_names
);
5677 /* Similarly for the include directory names. */
5678 if (lh
->include_dirs
)
5679 xfree (lh
->include_dirs
);
5685 /* Add an entry to LH's include directory table. */
5687 add_include_dir (struct line_header
*lh
, char *include_dir
)
5689 /* Grow the array if necessary. */
5690 if (lh
->include_dirs_size
== 0)
5692 lh
->include_dirs_size
= 1; /* for testing */
5693 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
5694 * sizeof (*lh
->include_dirs
));
5696 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
5698 lh
->include_dirs_size
*= 2;
5699 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
5700 (lh
->include_dirs_size
5701 * sizeof (*lh
->include_dirs
)));
5704 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
5708 /* Add an entry to LH's file name table. */
5710 add_file_name (struct line_header
*lh
,
5712 unsigned int dir_index
,
5713 unsigned int mod_time
,
5714 unsigned int length
)
5716 struct file_entry
*fe
;
5718 /* Grow the array if necessary. */
5719 if (lh
->file_names_size
== 0)
5721 lh
->file_names_size
= 1; /* for testing */
5722 lh
->file_names
= xmalloc (lh
->file_names_size
5723 * sizeof (*lh
->file_names
));
5725 else if (lh
->num_file_names
>= lh
->file_names_size
)
5727 lh
->file_names_size
*= 2;
5728 lh
->file_names
= xrealloc (lh
->file_names
,
5729 (lh
->file_names_size
5730 * sizeof (*lh
->file_names
)));
5733 fe
= &lh
->file_names
[lh
->num_file_names
++];
5735 fe
->dir_index
= dir_index
;
5736 fe
->mod_time
= mod_time
;
5737 fe
->length
= length
;
5742 /* Read the statement program header starting at OFFSET in
5743 .debug_line, according to the endianness of ABFD. Return a pointer
5744 to a struct line_header, allocated using xmalloc.
5746 NOTE: the strings in the include directory and file name tables of
5747 the returned object point into debug_line_buffer, and must not be
5749 static struct line_header
*
5750 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
5751 struct dwarf2_cu
*cu
)
5753 struct cleanup
*back_to
;
5754 struct line_header
*lh
;
5758 char *cur_dir
, *cur_file
;
5760 if (dwarf2_per_objfile
->line_buffer
== NULL
)
5762 complaint (&symfile_complaints
, "missing .debug_line section");
5766 /* Make sure that at least there's room for the total_length field. That
5767 could be 12 bytes long, but we're just going to fudge that. */
5768 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
5770 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5774 lh
= xmalloc (sizeof (*lh
));
5775 memset (lh
, 0, sizeof (*lh
));
5776 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
5779 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
5781 /* read in the header */
5782 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
5783 line_ptr
+= bytes_read
;
5784 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
5785 + dwarf2_per_objfile
->line_size
))
5787 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5790 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
5791 lh
->version
= read_2_bytes (abfd
, line_ptr
);
5793 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
5794 line_ptr
+= bytes_read
;
5795 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
5797 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
5799 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
5801 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
5803 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
5805 lh
->standard_opcode_lengths
5806 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
5808 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
5809 for (i
= 1; i
< lh
->opcode_base
; ++i
)
5811 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
5815 /* Read directory table */
5816 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5818 line_ptr
+= bytes_read
;
5819 add_include_dir (lh
, cur_dir
);
5821 line_ptr
+= bytes_read
;
5823 /* Read file name table */
5824 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5826 unsigned int dir_index
, mod_time
, length
;
5828 line_ptr
+= bytes_read
;
5829 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5830 line_ptr
+= bytes_read
;
5831 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5832 line_ptr
+= bytes_read
;
5833 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5834 line_ptr
+= bytes_read
;
5836 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5838 line_ptr
+= bytes_read
;
5839 lh
->statement_program_start
= line_ptr
;
5841 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
5842 + dwarf2_per_objfile
->line_size
))
5843 complaint (&symfile_complaints
,
5844 "line number info header doesn't fit in `.debug_line' section");
5846 discard_cleanups (back_to
);
5850 /* This function exists to work around a bug in certain compilers
5851 (particularly GCC 2.95), in which the first line number marker of a
5852 function does not show up until after the prologue, right before
5853 the second line number marker. This function shifts ADDRESS down
5854 to the beginning of the function if necessary, and is called on
5855 addresses passed to record_line. */
5858 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
5860 struct function_range
*fn
;
5862 /* Find the function_range containing address. */
5867 cu
->cached_fn
= cu
->first_fn
;
5871 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5877 while (fn
&& fn
!= cu
->cached_fn
)
5878 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5888 if (address
!= fn
->lowpc
)
5889 complaint (&symfile_complaints
,
5890 "misplaced first line number at 0x%lx for '%s'",
5891 (unsigned long) address
, fn
->name
);
5896 /* Decode the Line Number Program (LNP) for the given line_header
5897 structure and CU. The actual information extracted and the type
5898 of structures created from the LNP depends on the value of PST.
5900 1. If PST is NULL, then this procedure uses the data from the program
5901 to create all necessary symbol tables, and their linetables.
5902 The compilation directory of the file is passed in COMP_DIR,
5903 and must not be NULL.
5905 2. If PST is not NULL, this procedure reads the program to determine
5906 the list of files included by the unit represented by PST, and
5907 builds all the associated partial symbol tables. In this case,
5908 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
5909 is not used to compute the full name of the symtab, and therefore
5910 omitting it when building the partial symtab does not introduce
5911 the potential for inconsistency - a partial symtab and its associated
5912 symbtab having a different fullname -). */
5915 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
5916 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
5920 unsigned int bytes_read
;
5921 unsigned char op_code
, extended_op
, adj_opcode
;
5923 struct objfile
*objfile
= cu
->objfile
;
5924 const int decode_for_pst_p
= (pst
!= NULL
);
5926 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5928 line_ptr
= lh
->statement_program_start
;
5929 line_end
= lh
->statement_program_end
;
5931 /* Read the statement sequences until there's nothing left. */
5932 while (line_ptr
< line_end
)
5934 /* state machine registers */
5935 CORE_ADDR address
= 0;
5936 unsigned int file
= 1;
5937 unsigned int line
= 1;
5938 unsigned int column
= 0;
5939 int is_stmt
= lh
->default_is_stmt
;
5940 int basic_block
= 0;
5941 int end_sequence
= 0;
5943 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
5945 /* Start a subfile for the current file of the state machine. */
5946 /* lh->include_dirs and lh->file_names are 0-based, but the
5947 directory and file name numbers in the statement program
5949 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
5952 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5955 dwarf2_start_subfile (fe
->name
, dir
);
5958 /* Decode the table. */
5959 while (!end_sequence
)
5961 op_code
= read_1_byte (abfd
, line_ptr
);
5964 if (op_code
>= lh
->opcode_base
)
5965 { /* Special operand. */
5966 adj_opcode
= op_code
- lh
->opcode_base
;
5967 address
+= (adj_opcode
/ lh
->line_range
)
5968 * lh
->minimum_instruction_length
;
5969 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
5970 if (!decode_for_pst_p
)
5972 /* append row to matrix using current values */
5973 record_line (current_subfile
, line
,
5974 check_cu_functions (address
, cu
));
5978 else switch (op_code
)
5980 case DW_LNS_extended_op
:
5981 line_ptr
+= 1; /* ignore length */
5982 extended_op
= read_1_byte (abfd
, line_ptr
);
5984 switch (extended_op
)
5986 case DW_LNE_end_sequence
:
5988 if (!decode_for_pst_p
)
5989 record_line (current_subfile
, 0, address
);
5991 case DW_LNE_set_address
:
5992 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
5993 line_ptr
+= bytes_read
;
5994 address
+= baseaddr
;
5996 case DW_LNE_define_file
:
5999 unsigned int dir_index
, mod_time
, length
;
6001 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
6002 line_ptr
+= bytes_read
;
6004 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6005 line_ptr
+= bytes_read
;
6007 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6008 line_ptr
+= bytes_read
;
6010 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6011 line_ptr
+= bytes_read
;
6012 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6016 complaint (&symfile_complaints
,
6017 "mangled .debug_line section");
6022 if (!decode_for_pst_p
)
6023 record_line (current_subfile
, line
,
6024 check_cu_functions (address
, cu
));
6027 case DW_LNS_advance_pc
:
6028 address
+= lh
->minimum_instruction_length
6029 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6030 line_ptr
+= bytes_read
;
6032 case DW_LNS_advance_line
:
6033 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
6034 line_ptr
+= bytes_read
;
6036 case DW_LNS_set_file
:
6038 /* lh->include_dirs and lh->file_names are 0-based,
6039 but the directory and file name numbers in the
6040 statement program are 1-based. */
6041 struct file_entry
*fe
;
6043 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6044 line_ptr
+= bytes_read
;
6045 fe
= &lh
->file_names
[file
- 1];
6048 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6051 if (!decode_for_pst_p
)
6052 dwarf2_start_subfile (fe
->name
, dir
);
6055 case DW_LNS_set_column
:
6056 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6057 line_ptr
+= bytes_read
;
6059 case DW_LNS_negate_stmt
:
6060 is_stmt
= (!is_stmt
);
6062 case DW_LNS_set_basic_block
:
6065 /* Add to the address register of the state machine the
6066 address increment value corresponding to special opcode
6067 255. Ie, this value is scaled by the minimum instruction
6068 length since special opcode 255 would have scaled the
6070 case DW_LNS_const_add_pc
:
6071 address
+= (lh
->minimum_instruction_length
6072 * ((255 - lh
->opcode_base
) / lh
->line_range
));
6074 case DW_LNS_fixed_advance_pc
:
6075 address
+= read_2_bytes (abfd
, line_ptr
);
6079 { /* Unknown standard opcode, ignore it. */
6081 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
6083 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6084 line_ptr
+= bytes_read
;
6091 if (decode_for_pst_p
)
6095 /* Now that we're done scanning the Line Header Program, we can
6096 create the psymtab of each included file. */
6097 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
6098 if (lh
->file_names
[file_index
].included_p
== 1)
6100 char *include_name
= lh
->file_names
[file_index
].name
;
6102 if (strcmp (include_name
, pst
->filename
) != 0)
6103 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
6108 /* Start a subfile for DWARF. FILENAME is the name of the file and
6109 DIRNAME the name of the source directory which contains FILENAME
6110 or NULL if not known.
6111 This routine tries to keep line numbers from identical absolute and
6112 relative file names in a common subfile.
6114 Using the `list' example from the GDB testsuite, which resides in
6115 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
6116 of /srcdir/list0.c yields the following debugging information for list0.c:
6118 DW_AT_name: /srcdir/list0.c
6119 DW_AT_comp_dir: /compdir
6120 files.files[0].name: list0.h
6121 files.files[0].dir: /srcdir
6122 files.files[1].name: list0.c
6123 files.files[1].dir: /srcdir
6125 The line number information for list0.c has to end up in a single
6126 subfile, so that `break /srcdir/list0.c:1' works as expected. */
6129 dwarf2_start_subfile (char *filename
, char *dirname
)
6131 /* If the filename isn't absolute, try to match an existing subfile
6132 with the full pathname. */
6134 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
6136 struct subfile
*subfile
;
6137 char *fullname
= concat (dirname
, "/", filename
, NULL
);
6139 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
6141 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
6143 current_subfile
= subfile
;
6150 start_subfile (filename
, dirname
);
6154 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
6155 struct dwarf2_cu
*cu
)
6157 struct objfile
*objfile
= cu
->objfile
;
6158 struct comp_unit_head
*cu_header
= &cu
->header
;
6160 /* NOTE drow/2003-01-30: There used to be a comment and some special
6161 code here to turn a symbol with DW_AT_external and a
6162 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
6163 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
6164 with some versions of binutils) where shared libraries could have
6165 relocations against symbols in their debug information - the
6166 minimal symbol would have the right address, but the debug info
6167 would not. It's no longer necessary, because we will explicitly
6168 apply relocations when we read in the debug information now. */
6170 /* A DW_AT_location attribute with no contents indicates that a
6171 variable has been optimized away. */
6172 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
6174 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
6178 /* Handle one degenerate form of location expression specially, to
6179 preserve GDB's previous behavior when section offsets are
6180 specified. If this is just a DW_OP_addr then mark this symbol
6183 if (attr_form_is_block (attr
)
6184 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
6185 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
6189 SYMBOL_VALUE_ADDRESS (sym
) =
6190 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
6191 fixup_symbol_section (sym
, objfile
);
6192 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
6193 SYMBOL_SECTION (sym
));
6194 SYMBOL_CLASS (sym
) = LOC_STATIC
;
6198 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
6199 expression evaluator, and use LOC_COMPUTED only when necessary
6200 (i.e. when the value of a register or memory location is
6201 referenced, or a thread-local block, etc.). Then again, it might
6202 not be worthwhile. I'm assuming that it isn't unless performance
6203 or memory numbers show me otherwise. */
6205 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
6206 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
6209 /* Given a pointer to a DWARF information entry, figure out if we need
6210 to make a symbol table entry for it, and if so, create a new entry
6211 and return a pointer to it.
6212 If TYPE is NULL, determine symbol type from the die, otherwise
6213 used the passed type. */
6215 static struct symbol
*
6216 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
6218 struct objfile
*objfile
= cu
->objfile
;
6219 struct symbol
*sym
= NULL
;
6221 struct attribute
*attr
= NULL
;
6222 struct attribute
*attr2
= NULL
;
6225 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6227 if (die
->tag
!= DW_TAG_namespace
)
6228 name
= dwarf2_linkage_name (die
, cu
);
6230 name
= TYPE_NAME (type
);
6234 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
6235 sizeof (struct symbol
));
6236 OBJSTAT (objfile
, n_syms
++);
6237 memset (sym
, 0, sizeof (struct symbol
));
6239 /* Cache this symbol's name and the name's demangled form (if any). */
6240 SYMBOL_LANGUAGE (sym
) = cu
->language
;
6241 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
6243 /* Default assumptions.
6244 Use the passed type or decode it from the die. */
6245 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6246 SYMBOL_CLASS (sym
) = LOC_STATIC
;
6248 SYMBOL_TYPE (sym
) = type
;
6250 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
6251 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
6254 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
6259 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6262 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
6264 SYMBOL_CLASS (sym
) = LOC_LABEL
;
6266 case DW_TAG_subprogram
:
6267 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
6269 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
6270 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6271 if (attr2
&& (DW_UNSND (attr2
) != 0))
6273 add_symbol_to_list (sym
, &global_symbols
);
6277 add_symbol_to_list (sym
, cu
->list_in_scope
);
6280 case DW_TAG_variable
:
6281 /* Compilation with minimal debug info may result in variables
6282 with missing type entries. Change the misleading `void' type
6283 to something sensible. */
6284 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
6285 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
6286 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
6287 "<variable, no debug info>",
6289 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6292 dwarf2_const_value (attr
, sym
, cu
);
6293 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6294 if (attr2
&& (DW_UNSND (attr2
) != 0))
6295 add_symbol_to_list (sym
, &global_symbols
);
6297 add_symbol_to_list (sym
, cu
->list_in_scope
);
6300 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6303 var_decode_location (attr
, sym
, cu
);
6304 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6305 if (attr2
&& (DW_UNSND (attr2
) != 0))
6306 add_symbol_to_list (sym
, &global_symbols
);
6308 add_symbol_to_list (sym
, cu
->list_in_scope
);
6312 /* We do not know the address of this symbol.
6313 If it is an external symbol and we have type information
6314 for it, enter the symbol as a LOC_UNRESOLVED symbol.
6315 The address of the variable will then be determined from
6316 the minimal symbol table whenever the variable is
6318 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6319 if (attr2
&& (DW_UNSND (attr2
) != 0)
6320 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
6322 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
6323 add_symbol_to_list (sym
, &global_symbols
);
6327 case DW_TAG_formal_parameter
:
6328 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6331 var_decode_location (attr
, sym
, cu
);
6332 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
6333 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
6334 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
6336 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6339 dwarf2_const_value (attr
, sym
, cu
);
6341 add_symbol_to_list (sym
, cu
->list_in_scope
);
6343 case DW_TAG_unspecified_parameters
:
6344 /* From varargs functions; gdb doesn't seem to have any
6345 interest in this information, so just ignore it for now.
6348 case DW_TAG_class_type
:
6349 case DW_TAG_structure_type
:
6350 case DW_TAG_union_type
:
6351 case DW_TAG_enumeration_type
:
6352 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6353 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6355 /* Make sure that the symbol includes appropriate enclosing
6356 classes/namespaces in its name. These are calculated in
6357 read_structure_type, and the correct name is saved in
6360 if (cu
->language
== language_cplus
)
6362 struct type
*type
= SYMBOL_TYPE (sym
);
6364 if (TYPE_TAG_NAME (type
) != NULL
)
6366 /* FIXME: carlton/2003-11-10: Should this use
6367 SYMBOL_SET_NAMES instead? (The same problem also
6368 arises further down in this function.) */
6369 /* The type's name is already allocated along with
6370 this objfile, so we don't need to duplicate it
6372 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
6377 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
6378 really ever be static objects: otherwise, if you try
6379 to, say, break of a class's method and you're in a file
6380 which doesn't mention that class, it won't work unless
6381 the check for all static symbols in lookup_symbol_aux
6382 saves you. See the OtherFileClass tests in
6383 gdb.c++/namespace.exp. */
6385 struct pending
**list_to_add
;
6387 list_to_add
= (cu
->list_in_scope
== &file_symbols
6388 && cu
->language
== language_cplus
6389 ? &global_symbols
: cu
->list_in_scope
);
6391 add_symbol_to_list (sym
, list_to_add
);
6393 /* The semantics of C++ state that "struct foo { ... }" also
6394 defines a typedef for "foo". Synthesize a typedef symbol so
6395 that "ptype foo" works as expected. */
6396 if (cu
->language
== language_cplus
)
6398 struct symbol
*typedef_sym
= (struct symbol
*)
6399 obstack_alloc (&objfile
->objfile_obstack
,
6400 sizeof (struct symbol
));
6401 *typedef_sym
= *sym
;
6402 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
6403 /* The symbol's name is already allocated along with
6404 this objfile, so we don't need to duplicate it for
6406 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
6407 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NATURAL_NAME (sym
);
6408 add_symbol_to_list (typedef_sym
, list_to_add
);
6412 case DW_TAG_typedef
:
6413 if (processing_has_namespace_info
6414 && processing_current_prefix
[0] != '\0')
6416 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->objfile_obstack
,
6417 processing_current_prefix
,
6421 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6422 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6423 add_symbol_to_list (sym
, cu
->list_in_scope
);
6425 case DW_TAG_base_type
:
6426 case DW_TAG_subrange_type
:
6427 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6428 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6429 add_symbol_to_list (sym
, cu
->list_in_scope
);
6431 case DW_TAG_enumerator
:
6432 if (processing_has_namespace_info
6433 && processing_current_prefix
[0] != '\0')
6435 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->objfile_obstack
,
6436 processing_current_prefix
,
6440 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6443 dwarf2_const_value (attr
, sym
, cu
);
6446 /* NOTE: carlton/2003-11-10: See comment above in the
6447 DW_TAG_class_type, etc. block. */
6449 struct pending
**list_to_add
;
6451 list_to_add
= (cu
->list_in_scope
== &file_symbols
6452 && cu
->language
== language_cplus
6453 ? &global_symbols
: cu
->list_in_scope
);
6455 add_symbol_to_list (sym
, list_to_add
);
6458 case DW_TAG_namespace
:
6459 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6460 add_symbol_to_list (sym
, &global_symbols
);
6463 /* Not a tag we recognize. Hopefully we aren't processing
6464 trash data, but since we must specifically ignore things
6465 we don't recognize, there is nothing else we should do at
6467 complaint (&symfile_complaints
, "unsupported tag: '%s'",
6468 dwarf_tag_name (die
->tag
));
6475 /* Copy constant value from an attribute to a symbol. */
6478 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
6479 struct dwarf2_cu
*cu
)
6481 struct objfile
*objfile
= cu
->objfile
;
6482 struct comp_unit_head
*cu_header
= &cu
->header
;
6483 struct dwarf_block
*blk
;
6488 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
6489 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
6490 cu_header
->addr_size
,
6491 TYPE_LENGTH (SYMBOL_TYPE
6493 SYMBOL_VALUE_BYTES (sym
) = (char *)
6494 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
6495 /* NOTE: cagney/2003-05-09: In-lined store_address call with
6496 it's body - store_unsigned_integer. */
6497 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
6499 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6501 case DW_FORM_block1
:
6502 case DW_FORM_block2
:
6503 case DW_FORM_block4
:
6505 blk
= DW_BLOCK (attr
);
6506 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
6507 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
6509 TYPE_LENGTH (SYMBOL_TYPE
6511 SYMBOL_VALUE_BYTES (sym
) = (char *)
6512 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
6513 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
6514 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6517 /* The DW_AT_const_value attributes are supposed to carry the
6518 symbol's value "represented as it would be on the target
6519 architecture." By the time we get here, it's already been
6520 converted to host endianness, so we just need to sign- or
6521 zero-extend it as appropriate. */
6523 dwarf2_const_value_data (attr
, sym
, 8);
6526 dwarf2_const_value_data (attr
, sym
, 16);
6529 dwarf2_const_value_data (attr
, sym
, 32);
6532 dwarf2_const_value_data (attr
, sym
, 64);
6536 SYMBOL_VALUE (sym
) = DW_SND (attr
);
6537 SYMBOL_CLASS (sym
) = LOC_CONST
;
6541 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
6542 SYMBOL_CLASS (sym
) = LOC_CONST
;
6546 complaint (&symfile_complaints
,
6547 "unsupported const value attribute form: '%s'",
6548 dwarf_form_name (attr
->form
));
6549 SYMBOL_VALUE (sym
) = 0;
6550 SYMBOL_CLASS (sym
) = LOC_CONST
;
6556 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
6557 or zero-extend it as appropriate for the symbol's type. */
6559 dwarf2_const_value_data (struct attribute
*attr
,
6563 LONGEST l
= DW_UNSND (attr
);
6565 if (bits
< sizeof (l
) * 8)
6567 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
6568 l
&= ((LONGEST
) 1 << bits
) - 1;
6570 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
6573 SYMBOL_VALUE (sym
) = l
;
6574 SYMBOL_CLASS (sym
) = LOC_CONST
;
6578 /* Return the type of the die in question using its DW_AT_type attribute. */
6580 static struct type
*
6581 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6584 struct attribute
*type_attr
;
6585 struct die_info
*type_die
;
6588 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
6591 /* A missing DW_AT_type represents a void type. */
6592 return dwarf2_fundamental_type (cu
->objfile
, FT_VOID
, cu
);
6596 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6597 type_die
= follow_die_ref (ref
);
6600 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
6601 ref
, cu
->objfile
->name
);
6605 type
= tag_type_to_type (type_die
, cu
);
6608 dump_die (type_die
);
6609 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
6615 /* Return the containing type of the die in question using its
6616 DW_AT_containing_type attribute. */
6618 static struct type
*
6619 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6621 struct type
*type
= NULL
;
6622 struct attribute
*type_attr
;
6623 struct die_info
*type_die
= NULL
;
6626 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
6629 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6630 type_die
= follow_die_ref (ref
);
6633 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
6637 type
= tag_type_to_type (type_die
, cu
);
6642 dump_die (type_die
);
6643 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
6650 static struct type
*
6651 type_at_offset (unsigned int offset
, struct dwarf2_cu
*cu
)
6653 struct die_info
*die
;
6656 die
= follow_die_ref (offset
);
6659 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
6662 type
= tag_type_to_type (die
, cu
);
6667 static struct type
*
6668 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6676 read_type_die (die
, cu
);
6680 error ("Dwarf Error: Cannot find type of die [in module %s]",
6688 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6690 char *prefix
= determine_prefix (die
, cu
);
6691 const char *old_prefix
= processing_current_prefix
;
6692 struct cleanup
*back_to
= make_cleanup (xfree
, prefix
);
6693 processing_current_prefix
= prefix
;
6697 case DW_TAG_class_type
:
6698 case DW_TAG_structure_type
:
6699 case DW_TAG_union_type
:
6700 read_structure_type (die
, cu
);
6702 case DW_TAG_enumeration_type
:
6703 read_enumeration_type (die
, cu
);
6705 case DW_TAG_subprogram
:
6706 case DW_TAG_subroutine_type
:
6707 read_subroutine_type (die
, cu
);
6709 case DW_TAG_array_type
:
6710 read_array_type (die
, cu
);
6712 case DW_TAG_pointer_type
:
6713 read_tag_pointer_type (die
, cu
);
6715 case DW_TAG_ptr_to_member_type
:
6716 read_tag_ptr_to_member_type (die
, cu
);
6718 case DW_TAG_reference_type
:
6719 read_tag_reference_type (die
, cu
);
6721 case DW_TAG_const_type
:
6722 read_tag_const_type (die
, cu
);
6724 case DW_TAG_volatile_type
:
6725 read_tag_volatile_type (die
, cu
);
6727 case DW_TAG_string_type
:
6728 read_tag_string_type (die
, cu
);
6730 case DW_TAG_typedef
:
6731 read_typedef (die
, cu
);
6733 case DW_TAG_subrange_type
:
6734 read_subrange_type (die
, cu
);
6736 case DW_TAG_base_type
:
6737 read_base_type (die
, cu
);
6740 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
6741 dwarf_tag_name (die
->tag
));
6745 processing_current_prefix
= old_prefix
;
6746 do_cleanups (back_to
);
6749 /* Return the name of the namespace/class that DIE is defined within,
6750 or "" if we can't tell. The caller should xfree the result. */
6752 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
6753 therein) for an example of how to use this function to deal with
6754 DW_AT_specification. */
6757 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
6759 struct die_info
*parent
;
6761 if (cu
->language
!= language_cplus
)
6764 parent
= die
->parent
;
6768 return xstrdup ("");
6772 switch (parent
->tag
) {
6773 case DW_TAG_namespace
:
6775 /* FIXME: carlton/2004-03-05: Should I follow extension dies
6776 before doing this check? */
6777 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
6779 return xstrdup (TYPE_TAG_NAME (parent
->type
));
6784 char *parent_prefix
= determine_prefix (parent
, cu
);
6785 char *retval
= typename_concat (parent_prefix
,
6786 namespace_name (parent
, &dummy
,
6788 xfree (parent_prefix
);
6793 case DW_TAG_class_type
:
6794 case DW_TAG_structure_type
:
6796 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
6798 return xstrdup (TYPE_TAG_NAME (parent
->type
));
6802 const char *old_prefix
= processing_current_prefix
;
6803 char *new_prefix
= determine_prefix (parent
, cu
);
6806 processing_current_prefix
= new_prefix
;
6807 retval
= determine_class_name (parent
, cu
);
6808 processing_current_prefix
= old_prefix
;
6815 return determine_prefix (parent
, cu
);
6820 /* Return a newly-allocated string formed by concatenating PREFIX,
6821 "::", and SUFFIX, except that if PREFIX is NULL or the empty
6822 string, just return a copy of SUFFIX. */
6825 typename_concat (const char *prefix
, const char *suffix
)
6827 if (prefix
== NULL
|| prefix
[0] == '\0')
6828 return xstrdup (suffix
);
6831 char *retval
= xmalloc (strlen (prefix
) + 2 + strlen (suffix
) + 1);
6833 strcpy (retval
, prefix
);
6834 strcat (retval
, "::");
6835 strcat (retval
, suffix
);
6841 static struct type
*
6842 dwarf_base_type (int encoding
, int size
, struct dwarf2_cu
*cu
)
6844 struct objfile
*objfile
= cu
->objfile
;
6846 /* FIXME - this should not produce a new (struct type *)
6847 every time. It should cache base types. */
6851 case DW_ATE_address
:
6852 type
= dwarf2_fundamental_type (objfile
, FT_VOID
, cu
);
6854 case DW_ATE_boolean
:
6855 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
, cu
);
6857 case DW_ATE_complex_float
:
6860 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
, cu
);
6864 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
, cu
);
6870 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
6874 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
6881 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6884 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
, cu
);
6888 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6892 case DW_ATE_signed_char
:
6893 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6895 case DW_ATE_unsigned
:
6899 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6902 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
, cu
);
6906 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
, cu
);
6910 case DW_ATE_unsigned_char
:
6911 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6914 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6921 copy_die (struct die_info
*old_die
)
6923 struct die_info
*new_die
;
6926 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6927 memset (new_die
, 0, sizeof (struct die_info
));
6929 new_die
->tag
= old_die
->tag
;
6930 new_die
->has_children
= old_die
->has_children
;
6931 new_die
->abbrev
= old_die
->abbrev
;
6932 new_die
->offset
= old_die
->offset
;
6933 new_die
->type
= NULL
;
6935 num_attrs
= old_die
->num_attrs
;
6936 new_die
->num_attrs
= num_attrs
;
6937 new_die
->attrs
= (struct attribute
*)
6938 xmalloc (num_attrs
* sizeof (struct attribute
));
6940 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
6942 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
6943 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
6944 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
6947 new_die
->next
= NULL
;
6952 /* Return sibling of die, NULL if no sibling. */
6954 static struct die_info
*
6955 sibling_die (struct die_info
*die
)
6957 return die
->sibling
;
6960 /* Get linkage name of a die, return NULL if not found. */
6963 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6965 struct attribute
*attr
;
6967 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6968 if (attr
&& DW_STRING (attr
))
6969 return DW_STRING (attr
);
6970 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6971 if (attr
&& DW_STRING (attr
))
6972 return DW_STRING (attr
);
6976 /* Get name of a die, return NULL if not found. */
6979 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6981 struct attribute
*attr
;
6983 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6984 if (attr
&& DW_STRING (attr
))
6985 return DW_STRING (attr
);
6989 /* Return the die that this die in an extension of, or NULL if there
6992 static struct die_info
*
6993 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
6995 struct attribute
*attr
;
6996 struct die_info
*extension_die
;
6999 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
7003 ref
= dwarf2_get_ref_die_offset (attr
, cu
);
7004 extension_die
= follow_die_ref (ref
);
7007 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
7010 return extension_die
;
7013 /* Convert a DIE tag into its string name. */
7016 dwarf_tag_name (unsigned tag
)
7020 case DW_TAG_padding
:
7021 return "DW_TAG_padding";
7022 case DW_TAG_array_type
:
7023 return "DW_TAG_array_type";
7024 case DW_TAG_class_type
:
7025 return "DW_TAG_class_type";
7026 case DW_TAG_entry_point
:
7027 return "DW_TAG_entry_point";
7028 case DW_TAG_enumeration_type
:
7029 return "DW_TAG_enumeration_type";
7030 case DW_TAG_formal_parameter
:
7031 return "DW_TAG_formal_parameter";
7032 case DW_TAG_imported_declaration
:
7033 return "DW_TAG_imported_declaration";
7035 return "DW_TAG_label";
7036 case DW_TAG_lexical_block
:
7037 return "DW_TAG_lexical_block";
7039 return "DW_TAG_member";
7040 case DW_TAG_pointer_type
:
7041 return "DW_TAG_pointer_type";
7042 case DW_TAG_reference_type
:
7043 return "DW_TAG_reference_type";
7044 case DW_TAG_compile_unit
:
7045 return "DW_TAG_compile_unit";
7046 case DW_TAG_string_type
:
7047 return "DW_TAG_string_type";
7048 case DW_TAG_structure_type
:
7049 return "DW_TAG_structure_type";
7050 case DW_TAG_subroutine_type
:
7051 return "DW_TAG_subroutine_type";
7052 case DW_TAG_typedef
:
7053 return "DW_TAG_typedef";
7054 case DW_TAG_union_type
:
7055 return "DW_TAG_union_type";
7056 case DW_TAG_unspecified_parameters
:
7057 return "DW_TAG_unspecified_parameters";
7058 case DW_TAG_variant
:
7059 return "DW_TAG_variant";
7060 case DW_TAG_common_block
:
7061 return "DW_TAG_common_block";
7062 case DW_TAG_common_inclusion
:
7063 return "DW_TAG_common_inclusion";
7064 case DW_TAG_inheritance
:
7065 return "DW_TAG_inheritance";
7066 case DW_TAG_inlined_subroutine
:
7067 return "DW_TAG_inlined_subroutine";
7069 return "DW_TAG_module";
7070 case DW_TAG_ptr_to_member_type
:
7071 return "DW_TAG_ptr_to_member_type";
7072 case DW_TAG_set_type
:
7073 return "DW_TAG_set_type";
7074 case DW_TAG_subrange_type
:
7075 return "DW_TAG_subrange_type";
7076 case DW_TAG_with_stmt
:
7077 return "DW_TAG_with_stmt";
7078 case DW_TAG_access_declaration
:
7079 return "DW_TAG_access_declaration";
7080 case DW_TAG_base_type
:
7081 return "DW_TAG_base_type";
7082 case DW_TAG_catch_block
:
7083 return "DW_TAG_catch_block";
7084 case DW_TAG_const_type
:
7085 return "DW_TAG_const_type";
7086 case DW_TAG_constant
:
7087 return "DW_TAG_constant";
7088 case DW_TAG_enumerator
:
7089 return "DW_TAG_enumerator";
7090 case DW_TAG_file_type
:
7091 return "DW_TAG_file_type";
7093 return "DW_TAG_friend";
7094 case DW_TAG_namelist
:
7095 return "DW_TAG_namelist";
7096 case DW_TAG_namelist_item
:
7097 return "DW_TAG_namelist_item";
7098 case DW_TAG_packed_type
:
7099 return "DW_TAG_packed_type";
7100 case DW_TAG_subprogram
:
7101 return "DW_TAG_subprogram";
7102 case DW_TAG_template_type_param
:
7103 return "DW_TAG_template_type_param";
7104 case DW_TAG_template_value_param
:
7105 return "DW_TAG_template_value_param";
7106 case DW_TAG_thrown_type
:
7107 return "DW_TAG_thrown_type";
7108 case DW_TAG_try_block
:
7109 return "DW_TAG_try_block";
7110 case DW_TAG_variant_part
:
7111 return "DW_TAG_variant_part";
7112 case DW_TAG_variable
:
7113 return "DW_TAG_variable";
7114 case DW_TAG_volatile_type
:
7115 return "DW_TAG_volatile_type";
7116 case DW_TAG_dwarf_procedure
:
7117 return "DW_TAG_dwarf_procedure";
7118 case DW_TAG_restrict_type
:
7119 return "DW_TAG_restrict_type";
7120 case DW_TAG_interface_type
:
7121 return "DW_TAG_interface_type";
7122 case DW_TAG_namespace
:
7123 return "DW_TAG_namespace";
7124 case DW_TAG_imported_module
:
7125 return "DW_TAG_imported_module";
7126 case DW_TAG_unspecified_type
:
7127 return "DW_TAG_unspecified_type";
7128 case DW_TAG_partial_unit
:
7129 return "DW_TAG_partial_unit";
7130 case DW_TAG_imported_unit
:
7131 return "DW_TAG_imported_unit";
7132 case DW_TAG_MIPS_loop
:
7133 return "DW_TAG_MIPS_loop";
7134 case DW_TAG_format_label
:
7135 return "DW_TAG_format_label";
7136 case DW_TAG_function_template
:
7137 return "DW_TAG_function_template";
7138 case DW_TAG_class_template
:
7139 return "DW_TAG_class_template";
7141 return "DW_TAG_<unknown>";
7145 /* Convert a DWARF attribute code into its string name. */
7148 dwarf_attr_name (unsigned attr
)
7153 return "DW_AT_sibling";
7154 case DW_AT_location
:
7155 return "DW_AT_location";
7157 return "DW_AT_name";
7158 case DW_AT_ordering
:
7159 return "DW_AT_ordering";
7160 case DW_AT_subscr_data
:
7161 return "DW_AT_subscr_data";
7162 case DW_AT_byte_size
:
7163 return "DW_AT_byte_size";
7164 case DW_AT_bit_offset
:
7165 return "DW_AT_bit_offset";
7166 case DW_AT_bit_size
:
7167 return "DW_AT_bit_size";
7168 case DW_AT_element_list
:
7169 return "DW_AT_element_list";
7170 case DW_AT_stmt_list
:
7171 return "DW_AT_stmt_list";
7173 return "DW_AT_low_pc";
7175 return "DW_AT_high_pc";
7176 case DW_AT_language
:
7177 return "DW_AT_language";
7179 return "DW_AT_member";
7181 return "DW_AT_discr";
7182 case DW_AT_discr_value
:
7183 return "DW_AT_discr_value";
7184 case DW_AT_visibility
:
7185 return "DW_AT_visibility";
7187 return "DW_AT_import";
7188 case DW_AT_string_length
:
7189 return "DW_AT_string_length";
7190 case DW_AT_common_reference
:
7191 return "DW_AT_common_reference";
7192 case DW_AT_comp_dir
:
7193 return "DW_AT_comp_dir";
7194 case DW_AT_const_value
:
7195 return "DW_AT_const_value";
7196 case DW_AT_containing_type
:
7197 return "DW_AT_containing_type";
7198 case DW_AT_default_value
:
7199 return "DW_AT_default_value";
7201 return "DW_AT_inline";
7202 case DW_AT_is_optional
:
7203 return "DW_AT_is_optional";
7204 case DW_AT_lower_bound
:
7205 return "DW_AT_lower_bound";
7206 case DW_AT_producer
:
7207 return "DW_AT_producer";
7208 case DW_AT_prototyped
:
7209 return "DW_AT_prototyped";
7210 case DW_AT_return_addr
:
7211 return "DW_AT_return_addr";
7212 case DW_AT_start_scope
:
7213 return "DW_AT_start_scope";
7214 case DW_AT_stride_size
:
7215 return "DW_AT_stride_size";
7216 case DW_AT_upper_bound
:
7217 return "DW_AT_upper_bound";
7218 case DW_AT_abstract_origin
:
7219 return "DW_AT_abstract_origin";
7220 case DW_AT_accessibility
:
7221 return "DW_AT_accessibility";
7222 case DW_AT_address_class
:
7223 return "DW_AT_address_class";
7224 case DW_AT_artificial
:
7225 return "DW_AT_artificial";
7226 case DW_AT_base_types
:
7227 return "DW_AT_base_types";
7228 case DW_AT_calling_convention
:
7229 return "DW_AT_calling_convention";
7231 return "DW_AT_count";
7232 case DW_AT_data_member_location
:
7233 return "DW_AT_data_member_location";
7234 case DW_AT_decl_column
:
7235 return "DW_AT_decl_column";
7236 case DW_AT_decl_file
:
7237 return "DW_AT_decl_file";
7238 case DW_AT_decl_line
:
7239 return "DW_AT_decl_line";
7240 case DW_AT_declaration
:
7241 return "DW_AT_declaration";
7242 case DW_AT_discr_list
:
7243 return "DW_AT_discr_list";
7244 case DW_AT_encoding
:
7245 return "DW_AT_encoding";
7246 case DW_AT_external
:
7247 return "DW_AT_external";
7248 case DW_AT_frame_base
:
7249 return "DW_AT_frame_base";
7251 return "DW_AT_friend";
7252 case DW_AT_identifier_case
:
7253 return "DW_AT_identifier_case";
7254 case DW_AT_macro_info
:
7255 return "DW_AT_macro_info";
7256 case DW_AT_namelist_items
:
7257 return "DW_AT_namelist_items";
7258 case DW_AT_priority
:
7259 return "DW_AT_priority";
7261 return "DW_AT_segment";
7262 case DW_AT_specification
:
7263 return "DW_AT_specification";
7264 case DW_AT_static_link
:
7265 return "DW_AT_static_link";
7267 return "DW_AT_type";
7268 case DW_AT_use_location
:
7269 return "DW_AT_use_location";
7270 case DW_AT_variable_parameter
:
7271 return "DW_AT_variable_parameter";
7272 case DW_AT_virtuality
:
7273 return "DW_AT_virtuality";
7274 case DW_AT_vtable_elem_location
:
7275 return "DW_AT_vtable_elem_location";
7276 case DW_AT_allocated
:
7277 return "DW_AT_allocated";
7278 case DW_AT_associated
:
7279 return "DW_AT_associated";
7280 case DW_AT_data_location
:
7281 return "DW_AT_data_location";
7283 return "DW_AT_stride";
7284 case DW_AT_entry_pc
:
7285 return "DW_AT_entry_pc";
7286 case DW_AT_use_UTF8
:
7287 return "DW_AT_use_UTF8";
7288 case DW_AT_extension
:
7289 return "DW_AT_extension";
7291 return "DW_AT_ranges";
7292 case DW_AT_trampoline
:
7293 return "DW_AT_trampoline";
7294 case DW_AT_call_column
:
7295 return "DW_AT_call_column";
7296 case DW_AT_call_file
:
7297 return "DW_AT_call_file";
7298 case DW_AT_call_line
:
7299 return "DW_AT_call_line";
7301 case DW_AT_MIPS_fde
:
7302 return "DW_AT_MIPS_fde";
7303 case DW_AT_MIPS_loop_begin
:
7304 return "DW_AT_MIPS_loop_begin";
7305 case DW_AT_MIPS_tail_loop_begin
:
7306 return "DW_AT_MIPS_tail_loop_begin";
7307 case DW_AT_MIPS_epilog_begin
:
7308 return "DW_AT_MIPS_epilog_begin";
7309 case DW_AT_MIPS_loop_unroll_factor
:
7310 return "DW_AT_MIPS_loop_unroll_factor";
7311 case DW_AT_MIPS_software_pipeline_depth
:
7312 return "DW_AT_MIPS_software_pipeline_depth";
7314 case DW_AT_MIPS_linkage_name
:
7315 return "DW_AT_MIPS_linkage_name";
7317 case DW_AT_sf_names
:
7318 return "DW_AT_sf_names";
7319 case DW_AT_src_info
:
7320 return "DW_AT_src_info";
7321 case DW_AT_mac_info
:
7322 return "DW_AT_mac_info";
7323 case DW_AT_src_coords
:
7324 return "DW_AT_src_coords";
7325 case DW_AT_body_begin
:
7326 return "DW_AT_body_begin";
7327 case DW_AT_body_end
:
7328 return "DW_AT_body_end";
7329 case DW_AT_GNU_vector
:
7330 return "DW_AT_GNU_vector";
7332 return "DW_AT_<unknown>";
7336 /* Convert a DWARF value form code into its string name. */
7339 dwarf_form_name (unsigned form
)
7344 return "DW_FORM_addr";
7345 case DW_FORM_block2
:
7346 return "DW_FORM_block2";
7347 case DW_FORM_block4
:
7348 return "DW_FORM_block4";
7350 return "DW_FORM_data2";
7352 return "DW_FORM_data4";
7354 return "DW_FORM_data8";
7355 case DW_FORM_string
:
7356 return "DW_FORM_string";
7358 return "DW_FORM_block";
7359 case DW_FORM_block1
:
7360 return "DW_FORM_block1";
7362 return "DW_FORM_data1";
7364 return "DW_FORM_flag";
7366 return "DW_FORM_sdata";
7368 return "DW_FORM_strp";
7370 return "DW_FORM_udata";
7371 case DW_FORM_ref_addr
:
7372 return "DW_FORM_ref_addr";
7374 return "DW_FORM_ref1";
7376 return "DW_FORM_ref2";
7378 return "DW_FORM_ref4";
7380 return "DW_FORM_ref8";
7381 case DW_FORM_ref_udata
:
7382 return "DW_FORM_ref_udata";
7383 case DW_FORM_indirect
:
7384 return "DW_FORM_indirect";
7386 return "DW_FORM_<unknown>";
7390 /* Convert a DWARF stack opcode into its string name. */
7393 dwarf_stack_op_name (unsigned op
)
7398 return "DW_OP_addr";
7400 return "DW_OP_deref";
7402 return "DW_OP_const1u";
7404 return "DW_OP_const1s";
7406 return "DW_OP_const2u";
7408 return "DW_OP_const2s";
7410 return "DW_OP_const4u";
7412 return "DW_OP_const4s";
7414 return "DW_OP_const8u";
7416 return "DW_OP_const8s";
7418 return "DW_OP_constu";
7420 return "DW_OP_consts";
7424 return "DW_OP_drop";
7426 return "DW_OP_over";
7428 return "DW_OP_pick";
7430 return "DW_OP_swap";
7434 return "DW_OP_xderef";
7442 return "DW_OP_minus";
7454 return "DW_OP_plus";
7455 case DW_OP_plus_uconst
:
7456 return "DW_OP_plus_uconst";
7462 return "DW_OP_shra";
7480 return "DW_OP_skip";
7482 return "DW_OP_lit0";
7484 return "DW_OP_lit1";
7486 return "DW_OP_lit2";
7488 return "DW_OP_lit3";
7490 return "DW_OP_lit4";
7492 return "DW_OP_lit5";
7494 return "DW_OP_lit6";
7496 return "DW_OP_lit7";
7498 return "DW_OP_lit8";
7500 return "DW_OP_lit9";
7502 return "DW_OP_lit10";
7504 return "DW_OP_lit11";
7506 return "DW_OP_lit12";
7508 return "DW_OP_lit13";
7510 return "DW_OP_lit14";
7512 return "DW_OP_lit15";
7514 return "DW_OP_lit16";
7516 return "DW_OP_lit17";
7518 return "DW_OP_lit18";
7520 return "DW_OP_lit19";
7522 return "DW_OP_lit20";
7524 return "DW_OP_lit21";
7526 return "DW_OP_lit22";
7528 return "DW_OP_lit23";
7530 return "DW_OP_lit24";
7532 return "DW_OP_lit25";
7534 return "DW_OP_lit26";
7536 return "DW_OP_lit27";
7538 return "DW_OP_lit28";
7540 return "DW_OP_lit29";
7542 return "DW_OP_lit30";
7544 return "DW_OP_lit31";
7546 return "DW_OP_reg0";
7548 return "DW_OP_reg1";
7550 return "DW_OP_reg2";
7552 return "DW_OP_reg3";
7554 return "DW_OP_reg4";
7556 return "DW_OP_reg5";
7558 return "DW_OP_reg6";
7560 return "DW_OP_reg7";
7562 return "DW_OP_reg8";
7564 return "DW_OP_reg9";
7566 return "DW_OP_reg10";
7568 return "DW_OP_reg11";
7570 return "DW_OP_reg12";
7572 return "DW_OP_reg13";
7574 return "DW_OP_reg14";
7576 return "DW_OP_reg15";
7578 return "DW_OP_reg16";
7580 return "DW_OP_reg17";
7582 return "DW_OP_reg18";
7584 return "DW_OP_reg19";
7586 return "DW_OP_reg20";
7588 return "DW_OP_reg21";
7590 return "DW_OP_reg22";
7592 return "DW_OP_reg23";
7594 return "DW_OP_reg24";
7596 return "DW_OP_reg25";
7598 return "DW_OP_reg26";
7600 return "DW_OP_reg27";
7602 return "DW_OP_reg28";
7604 return "DW_OP_reg29";
7606 return "DW_OP_reg30";
7608 return "DW_OP_reg31";
7610 return "DW_OP_breg0";
7612 return "DW_OP_breg1";
7614 return "DW_OP_breg2";
7616 return "DW_OP_breg3";
7618 return "DW_OP_breg4";
7620 return "DW_OP_breg5";
7622 return "DW_OP_breg6";
7624 return "DW_OP_breg7";
7626 return "DW_OP_breg8";
7628 return "DW_OP_breg9";
7630 return "DW_OP_breg10";
7632 return "DW_OP_breg11";
7634 return "DW_OP_breg12";
7636 return "DW_OP_breg13";
7638 return "DW_OP_breg14";
7640 return "DW_OP_breg15";
7642 return "DW_OP_breg16";
7644 return "DW_OP_breg17";
7646 return "DW_OP_breg18";
7648 return "DW_OP_breg19";
7650 return "DW_OP_breg20";
7652 return "DW_OP_breg21";
7654 return "DW_OP_breg22";
7656 return "DW_OP_breg23";
7658 return "DW_OP_breg24";
7660 return "DW_OP_breg25";
7662 return "DW_OP_breg26";
7664 return "DW_OP_breg27";
7666 return "DW_OP_breg28";
7668 return "DW_OP_breg29";
7670 return "DW_OP_breg30";
7672 return "DW_OP_breg31";
7674 return "DW_OP_regx";
7676 return "DW_OP_fbreg";
7678 return "DW_OP_bregx";
7680 return "DW_OP_piece";
7681 case DW_OP_deref_size
:
7682 return "DW_OP_deref_size";
7683 case DW_OP_xderef_size
:
7684 return "DW_OP_xderef_size";
7687 /* DWARF 3 extensions. */
7688 case DW_OP_push_object_address
:
7689 return "DW_OP_push_object_address";
7691 return "DW_OP_call2";
7693 return "DW_OP_call4";
7694 case DW_OP_call_ref
:
7695 return "DW_OP_call_ref";
7696 /* GNU extensions. */
7697 case DW_OP_GNU_push_tls_address
:
7698 return "DW_OP_GNU_push_tls_address";
7700 return "OP_<unknown>";
7705 dwarf_bool_name (unsigned mybool
)
7713 /* Convert a DWARF type code into its string name. */
7716 dwarf_type_encoding_name (unsigned enc
)
7720 case DW_ATE_address
:
7721 return "DW_ATE_address";
7722 case DW_ATE_boolean
:
7723 return "DW_ATE_boolean";
7724 case DW_ATE_complex_float
:
7725 return "DW_ATE_complex_float";
7727 return "DW_ATE_float";
7729 return "DW_ATE_signed";
7730 case DW_ATE_signed_char
:
7731 return "DW_ATE_signed_char";
7732 case DW_ATE_unsigned
:
7733 return "DW_ATE_unsigned";
7734 case DW_ATE_unsigned_char
:
7735 return "DW_ATE_unsigned_char";
7736 case DW_ATE_imaginary_float
:
7737 return "DW_ATE_imaginary_float";
7739 return "DW_ATE_<unknown>";
7743 /* Convert a DWARF call frame info operation to its string name. */
7747 dwarf_cfi_name (unsigned cfi_opc
)
7751 case DW_CFA_advance_loc
:
7752 return "DW_CFA_advance_loc";
7754 return "DW_CFA_offset";
7755 case DW_CFA_restore
:
7756 return "DW_CFA_restore";
7758 return "DW_CFA_nop";
7759 case DW_CFA_set_loc
:
7760 return "DW_CFA_set_loc";
7761 case DW_CFA_advance_loc1
:
7762 return "DW_CFA_advance_loc1";
7763 case DW_CFA_advance_loc2
:
7764 return "DW_CFA_advance_loc2";
7765 case DW_CFA_advance_loc4
:
7766 return "DW_CFA_advance_loc4";
7767 case DW_CFA_offset_extended
:
7768 return "DW_CFA_offset_extended";
7769 case DW_CFA_restore_extended
:
7770 return "DW_CFA_restore_extended";
7771 case DW_CFA_undefined
:
7772 return "DW_CFA_undefined";
7773 case DW_CFA_same_value
:
7774 return "DW_CFA_same_value";
7775 case DW_CFA_register
:
7776 return "DW_CFA_register";
7777 case DW_CFA_remember_state
:
7778 return "DW_CFA_remember_state";
7779 case DW_CFA_restore_state
:
7780 return "DW_CFA_restore_state";
7781 case DW_CFA_def_cfa
:
7782 return "DW_CFA_def_cfa";
7783 case DW_CFA_def_cfa_register
:
7784 return "DW_CFA_def_cfa_register";
7785 case DW_CFA_def_cfa_offset
:
7786 return "DW_CFA_def_cfa_offset";
7789 case DW_CFA_def_cfa_expression
:
7790 return "DW_CFA_def_cfa_expression";
7791 case DW_CFA_expression
:
7792 return "DW_CFA_expression";
7793 case DW_CFA_offset_extended_sf
:
7794 return "DW_CFA_offset_extended_sf";
7795 case DW_CFA_def_cfa_sf
:
7796 return "DW_CFA_def_cfa_sf";
7797 case DW_CFA_def_cfa_offset_sf
:
7798 return "DW_CFA_def_cfa_offset_sf";
7800 /* SGI/MIPS specific */
7801 case DW_CFA_MIPS_advance_loc8
:
7802 return "DW_CFA_MIPS_advance_loc8";
7804 /* GNU extensions */
7805 case DW_CFA_GNU_window_save
:
7806 return "DW_CFA_GNU_window_save";
7807 case DW_CFA_GNU_args_size
:
7808 return "DW_CFA_GNU_args_size";
7809 case DW_CFA_GNU_negative_offset_extended
:
7810 return "DW_CFA_GNU_negative_offset_extended";
7813 return "DW_CFA_<unknown>";
7819 dump_die (struct die_info
*die
)
7823 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
7824 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
7825 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
7826 dwarf_bool_name (die
->child
!= NULL
));
7828 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
7829 for (i
= 0; i
< die
->num_attrs
; ++i
)
7831 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
7832 dwarf_attr_name (die
->attrs
[i
].name
),
7833 dwarf_form_name (die
->attrs
[i
].form
));
7834 switch (die
->attrs
[i
].form
)
7836 case DW_FORM_ref_addr
:
7838 fprintf_unfiltered (gdb_stderr
, "address: ");
7839 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
7841 case DW_FORM_block2
:
7842 case DW_FORM_block4
:
7844 case DW_FORM_block1
:
7845 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
7856 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
7858 case DW_FORM_string
:
7860 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
7861 DW_STRING (&die
->attrs
[i
])
7862 ? DW_STRING (&die
->attrs
[i
]) : "");
7865 if (DW_UNSND (&die
->attrs
[i
]))
7866 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
7868 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
7870 case DW_FORM_indirect
:
7871 /* the reader will have reduced the indirect form to
7872 the "base form" so this form should not occur */
7873 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
7876 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
7877 die
->attrs
[i
].form
);
7879 fprintf_unfiltered (gdb_stderr
, "\n");
7884 dump_die_list (struct die_info
*die
)
7889 if (die
->child
!= NULL
)
7890 dump_die_list (die
->child
);
7891 if (die
->sibling
!= NULL
)
7892 dump_die_list (die
->sibling
);
7897 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
7900 struct die_info
*old
;
7902 h
= (offset
% REF_HASH_SIZE
);
7903 old
= die_ref_table
[h
];
7904 die
->next_ref
= old
;
7905 die_ref_table
[h
] = die
;
7910 dwarf2_empty_hash_tables (void)
7912 memset (die_ref_table
, 0, sizeof (die_ref_table
));
7916 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
7918 unsigned int result
= 0;
7922 case DW_FORM_ref_addr
:
7923 result
= DW_ADDR (attr
);
7929 case DW_FORM_ref_udata
:
7930 result
= cu
->header
.offset
+ DW_UNSND (attr
);
7933 complaint (&symfile_complaints
,
7934 "unsupported die ref attribute form: '%s'",
7935 dwarf_form_name (attr
->form
));
7940 /* Return the constant value held by the given attribute. Return -1
7941 if the value held by the attribute is not constant. */
7944 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
7946 if (attr
->form
== DW_FORM_sdata
)
7947 return DW_SND (attr
);
7948 else if (attr
->form
== DW_FORM_udata
7949 || attr
->form
== DW_FORM_data1
7950 || attr
->form
== DW_FORM_data2
7951 || attr
->form
== DW_FORM_data4
7952 || attr
->form
== DW_FORM_data8
)
7953 return DW_UNSND (attr
);
7956 complaint (&symfile_complaints
, "Attribute value is not a constant (%s)",
7957 dwarf_form_name (attr
->form
));
7958 return default_value
;
7962 static struct die_info
*
7963 follow_die_ref (unsigned int offset
)
7965 struct die_info
*die
;
7968 h
= (offset
% REF_HASH_SIZE
);
7969 die
= die_ref_table
[h
];
7972 if (die
->offset
== offset
)
7976 die
= die
->next_ref
;
7981 static struct type
*
7982 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid,
7983 struct dwarf2_cu
*cu
)
7985 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
7987 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
7988 typeid, objfile
->name
);
7991 /* Look for this particular type in the fundamental type vector. If
7992 one is not found, create and install one appropriate for the
7993 current language and the current target machine. */
7995 if (cu
->ftypes
[typeid] == NULL
)
7997 cu
->ftypes
[typeid] = cu
->language_defn
->la_fund_type (objfile
, typeid);
8000 return (cu
->ftypes
[typeid]);
8003 /* Decode simple location descriptions.
8004 Given a pointer to a dwarf block that defines a location, compute
8005 the location and return the value.
8007 NOTE drow/2003-11-18: This function is called in two situations
8008 now: for the address of static or global variables (partial symbols
8009 only) and for offsets into structures which are expected to be
8010 (more or less) constant. The partial symbol case should go away,
8011 and only the constant case should remain. That will let this
8012 function complain more accurately. A few special modes are allowed
8013 without complaint for global variables (for instance, global
8014 register values and thread-local values).
8016 A location description containing no operations indicates that the
8017 object is optimized out. The return value is 0 for that case.
8018 FIXME drow/2003-11-16: No callers check for this case any more; soon all
8019 callers will only want a very basic result and this can become a
8022 When the result is a register number, the global isreg flag is set,
8023 otherwise it is cleared.
8025 Note that stack[0] is unused except as a default error return.
8026 Note that stack overflow is not yet handled. */
8029 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
8031 struct objfile
*objfile
= cu
->objfile
;
8032 struct comp_unit_head
*cu_header
= &cu
->header
;
8034 int size
= blk
->size
;
8035 char *data
= blk
->data
;
8036 CORE_ADDR stack
[64];
8038 unsigned int bytes_read
, unsnd
;
8083 stack
[++stacki
] = op
- DW_OP_lit0
;
8119 stack
[++stacki
] = op
- DW_OP_reg0
;
8121 dwarf2_complex_location_expr_complaint ();
8126 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
8128 stack
[++stacki
] = unsnd
;
8130 dwarf2_complex_location_expr_complaint ();
8134 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
8140 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
8145 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
8150 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
8155 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
8160 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
8165 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
8170 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
8176 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
8181 stack
[stacki
+ 1] = stack
[stacki
];
8186 stack
[stacki
- 1] += stack
[stacki
];
8190 case DW_OP_plus_uconst
:
8191 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
8196 stack
[stacki
- 1] -= stack
[stacki
];
8201 /* If we're not the last op, then we definitely can't encode
8202 this using GDB's address_class enum. This is valid for partial
8203 global symbols, although the variable's address will be bogus
8206 dwarf2_complex_location_expr_complaint ();
8209 case DW_OP_GNU_push_tls_address
:
8210 /* The top of the stack has the offset from the beginning
8211 of the thread control block at which the variable is located. */
8212 /* Nothing should follow this operator, so the top of stack would
8214 /* This is valid for partial global symbols, but the variable's
8215 address will be bogus in the psymtab. */
8217 dwarf2_complex_location_expr_complaint ();
8221 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
8222 dwarf_stack_op_name (op
));
8223 return (stack
[stacki
]);
8226 return (stack
[stacki
]);
8229 /* memory allocation interface */
8231 static struct dwarf_block
*
8232 dwarf_alloc_block (struct dwarf2_cu
*cu
)
8234 struct dwarf_block
*blk
;
8236 blk
= (struct dwarf_block
*)
8237 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
8241 static struct abbrev_info
*
8242 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
8244 struct abbrev_info
*abbrev
;
8246 abbrev
= (struct abbrev_info
*)
8247 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
8248 memset (abbrev
, 0, sizeof (struct abbrev_info
));
8252 static struct die_info
*
8253 dwarf_alloc_die (void)
8255 struct die_info
*die
;
8257 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
8258 memset (die
, 0, sizeof (struct die_info
));
8263 /* Macro support. */
8266 /* Return the full name of file number I in *LH's file name table.
8267 Use COMP_DIR as the name of the current directory of the
8268 compilation. The result is allocated using xmalloc; the caller is
8269 responsible for freeing it. */
8271 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
8273 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
8275 if (IS_ABSOLUTE_PATH (fe
->name
))
8276 return xstrdup (fe
->name
);
8284 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8290 dir_len
= strlen (dir
);
8291 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
8292 strcpy (full_name
, dir
);
8293 full_name
[dir_len
] = '/';
8294 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
8298 return xstrdup (fe
->name
);
8303 static struct macro_source_file
*
8304 macro_start_file (int file
, int line
,
8305 struct macro_source_file
*current_file
,
8306 const char *comp_dir
,
8307 struct line_header
*lh
, struct objfile
*objfile
)
8309 /* The full name of this source file. */
8310 char *full_name
= file_full_name (file
, lh
, comp_dir
);
8312 /* We don't create a macro table for this compilation unit
8313 at all until we actually get a filename. */
8314 if (! pending_macros
)
8315 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
8316 objfile
->macro_cache
);
8319 /* If we have no current file, then this must be the start_file
8320 directive for the compilation unit's main source file. */
8321 current_file
= macro_set_main (pending_macros
, full_name
);
8323 current_file
= macro_include (current_file
, line
, full_name
);
8327 return current_file
;
8331 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
8332 followed by a null byte. */
8334 copy_string (const char *buf
, int len
)
8336 char *s
= xmalloc (len
+ 1);
8337 memcpy (s
, buf
, len
);
8345 consume_improper_spaces (const char *p
, const char *body
)
8349 complaint (&symfile_complaints
,
8350 "macro definition contains spaces in formal argument list:\n`%s'",
8362 parse_macro_definition (struct macro_source_file
*file
, int line
,
8367 /* The body string takes one of two forms. For object-like macro
8368 definitions, it should be:
8370 <macro name> " " <definition>
8372 For function-like macro definitions, it should be:
8374 <macro name> "() " <definition>
8376 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
8378 Spaces may appear only where explicitly indicated, and in the
8381 The Dwarf 2 spec says that an object-like macro's name is always
8382 followed by a space, but versions of GCC around March 2002 omit
8383 the space when the macro's definition is the empty string.
8385 The Dwarf 2 spec says that there should be no spaces between the
8386 formal arguments in a function-like macro's formal argument list,
8387 but versions of GCC around March 2002 include spaces after the
8391 /* Find the extent of the macro name. The macro name is terminated
8392 by either a space or null character (for an object-like macro) or
8393 an opening paren (for a function-like macro). */
8394 for (p
= body
; *p
; p
++)
8395 if (*p
== ' ' || *p
== '(')
8398 if (*p
== ' ' || *p
== '\0')
8400 /* It's an object-like macro. */
8401 int name_len
= p
- body
;
8402 char *name
= copy_string (body
, name_len
);
8403 const char *replacement
;
8406 replacement
= body
+ name_len
+ 1;
8409 dwarf2_macro_malformed_definition_complaint (body
);
8410 replacement
= body
+ name_len
;
8413 macro_define_object (file
, line
, name
, replacement
);
8419 /* It's a function-like macro. */
8420 char *name
= copy_string (body
, p
- body
);
8423 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
8427 p
= consume_improper_spaces (p
, body
);
8429 /* Parse the formal argument list. */
8430 while (*p
&& *p
!= ')')
8432 /* Find the extent of the current argument name. */
8433 const char *arg_start
= p
;
8435 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
8438 if (! *p
|| p
== arg_start
)
8439 dwarf2_macro_malformed_definition_complaint (body
);
8442 /* Make sure argv has room for the new argument. */
8443 if (argc
>= argv_size
)
8446 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
8449 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
8452 p
= consume_improper_spaces (p
, body
);
8454 /* Consume the comma, if present. */
8459 p
= consume_improper_spaces (p
, body
);
8468 /* Perfectly formed definition, no complaints. */
8469 macro_define_function (file
, line
, name
,
8470 argc
, (const char **) argv
,
8472 else if (*p
== '\0')
8474 /* Complain, but do define it. */
8475 dwarf2_macro_malformed_definition_complaint (body
);
8476 macro_define_function (file
, line
, name
,
8477 argc
, (const char **) argv
,
8481 /* Just complain. */
8482 dwarf2_macro_malformed_definition_complaint (body
);
8485 /* Just complain. */
8486 dwarf2_macro_malformed_definition_complaint (body
);
8492 for (i
= 0; i
< argc
; i
++)
8498 dwarf2_macro_malformed_definition_complaint (body
);
8503 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
8504 char *comp_dir
, bfd
*abfd
,
8505 struct dwarf2_cu
*cu
)
8507 char *mac_ptr
, *mac_end
;
8508 struct macro_source_file
*current_file
= 0;
8510 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
8512 complaint (&symfile_complaints
, "missing .debug_macinfo section");
8516 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
8517 mac_end
= dwarf2_per_objfile
->macinfo_buffer
8518 + dwarf2_per_objfile
->macinfo_size
;
8522 enum dwarf_macinfo_record_type macinfo_type
;
8524 /* Do we at least have room for a macinfo type byte? */
8525 if (mac_ptr
>= mac_end
)
8527 dwarf2_macros_too_long_complaint ();
8531 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
8534 switch (macinfo_type
)
8536 /* A zero macinfo type indicates the end of the macro
8541 case DW_MACINFO_define
:
8542 case DW_MACINFO_undef
:
8548 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8549 mac_ptr
+= bytes_read
;
8550 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
8551 mac_ptr
+= bytes_read
;
8554 complaint (&symfile_complaints
,
8555 "debug info gives macro %s outside of any file: %s",
8557 DW_MACINFO_define
? "definition" : macinfo_type
==
8558 DW_MACINFO_undef
? "undefinition" :
8559 "something-or-other", body
);
8562 if (macinfo_type
== DW_MACINFO_define
)
8563 parse_macro_definition (current_file
, line
, body
);
8564 else if (macinfo_type
== DW_MACINFO_undef
)
8565 macro_undef (current_file
, line
, body
);
8570 case DW_MACINFO_start_file
:
8575 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8576 mac_ptr
+= bytes_read
;
8577 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8578 mac_ptr
+= bytes_read
;
8580 current_file
= macro_start_file (file
, line
,
8581 current_file
, comp_dir
,
8586 case DW_MACINFO_end_file
:
8588 complaint (&symfile_complaints
,
8589 "macro debug info has an unmatched `close_file' directive");
8592 current_file
= current_file
->included_by
;
8595 enum dwarf_macinfo_record_type next_type
;
8597 /* GCC circa March 2002 doesn't produce the zero
8598 type byte marking the end of the compilation
8599 unit. Complain if it's not there, but exit no
8602 /* Do we at least have room for a macinfo type byte? */
8603 if (mac_ptr
>= mac_end
)
8605 dwarf2_macros_too_long_complaint ();
8609 /* We don't increment mac_ptr here, so this is just
8611 next_type
= read_1_byte (abfd
, mac_ptr
);
8613 complaint (&symfile_complaints
,
8614 "no terminating 0-type entry for macros in `.debug_macinfo' section");
8621 case DW_MACINFO_vendor_ext
:
8627 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8628 mac_ptr
+= bytes_read
;
8629 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
8630 mac_ptr
+= bytes_read
;
8632 /* We don't recognize any vendor extensions. */
8639 /* Check if the attribute's form is a DW_FORM_block*
8640 if so return true else false. */
8642 attr_form_is_block (struct attribute
*attr
)
8644 return (attr
== NULL
? 0 :
8645 attr
->form
== DW_FORM_block1
8646 || attr
->form
== DW_FORM_block2
8647 || attr
->form
== DW_FORM_block4
8648 || attr
->form
== DW_FORM_block
);
8652 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
8653 struct dwarf2_cu
*cu
)
8655 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
8657 struct dwarf2_loclist_baton
*baton
;
8659 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
8660 sizeof (struct dwarf2_loclist_baton
));
8661 baton
->objfile
= cu
->objfile
;
8663 /* We don't know how long the location list is, but make sure we
8664 don't run off the edge of the section. */
8665 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
8666 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
8667 baton
->base_address
= cu
->header
.base_address
;
8668 if (cu
->header
.base_known
== 0)
8669 complaint (&symfile_complaints
,
8670 "Location list used without specifying the CU base address.");
8672 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
8673 SYMBOL_LOCATION_BATON (sym
) = baton
;
8677 struct dwarf2_locexpr_baton
*baton
;
8679 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
8680 sizeof (struct dwarf2_locexpr_baton
));
8681 baton
->objfile
= cu
->objfile
;
8683 if (attr_form_is_block (attr
))
8685 /* Note that we're just copying the block's data pointer
8686 here, not the actual data. We're still pointing into the
8687 info_buffer for SYM's objfile; right now we never release
8688 that buffer, but when we do clean up properly this may
8690 baton
->size
= DW_BLOCK (attr
)->size
;
8691 baton
->data
= DW_BLOCK (attr
)->data
;
8695 dwarf2_invalid_attrib_class_complaint ("location description",
8696 SYMBOL_NATURAL_NAME (sym
));
8701 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
8702 SYMBOL_LOCATION_BATON (sym
) = baton
;
8706 /* This cleanup function is passed the address of a dwarf2_cu on the stack
8707 when we're finished with it. We can't free the pointer itself, but
8708 release any associated storage.
8710 Only used during partial symbol parsing. */
8713 free_stack_comp_unit (void *data
)
8715 struct dwarf2_cu
*cu
= data
;
8717 obstack_free (&cu
->comp_unit_obstack
, NULL
);
8718 cu
->partial_dies
= NULL
;
8721 /* Allocation function for the libiberty hash table which uses an
8725 hashtab_obstack_allocate (void *data
, size_t size
, size_t count
)
8727 unsigned int total
= size
* count
;
8728 void *ptr
= obstack_alloc ((struct obstack
*) data
, total
);
8729 memset (ptr
, 0, total
);
8733 /* Trivial deallocation function for the libiberty splay tree and hash
8734 table - don't deallocate anything. Rely on later deletion of the
8738 dummy_obstack_deallocate (void *object
, void *data
)
8743 /* Trivial hash function for partial_die_info: the hash value of a DIE
8744 is its offset in .debug_info for this objfile. */
8747 partial_die_hash (const void *item
)
8749 const struct partial_die_info
*part_die
= item
;
8750 return part_die
->offset
;
8753 /* Trivial comparison function for partial_die_info structures: two DIEs
8754 are equal if they have the same offset. */
8757 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
8759 const struct partial_die_info
*part_die_lhs
= item_lhs
;
8760 const struct partial_die_info
*part_die_rhs
= item_rhs
;
8761 return part_die_lhs
->offset
== part_die_rhs
->offset
;
8764 void _initialize_dwarf2_read (void);
8767 _initialize_dwarf2_read (void)
8769 dwarf2_objfile_data_key
= register_objfile_data ();