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
;
346 /* The start and end of the statement program following this
347 header. These point into dwarf2_per_objfile->line_buffer. */
348 char *statement_program_start
, *statement_program_end
;
351 /* When we construct a partial symbol table entry we only
352 need this much information. */
353 struct partial_die_info
355 /* Offset of this DIE. */
358 /* DWARF-2 tag for this DIE. */
359 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
361 /* Language code associated with this DIE. This is only used
362 for the compilation unit DIE. */
363 unsigned int language
: 8;
365 /* Assorted flags describing the data found in this DIE. */
366 unsigned int has_children
: 1;
367 unsigned int is_external
: 1;
368 unsigned int is_declaration
: 1;
369 unsigned int has_type
: 1;
370 unsigned int has_specification
: 1;
371 unsigned int has_pc_info
: 1;
373 /* Flag set if the SCOPE field of this structure has been
375 unsigned int scope_set
: 1;
377 /* The name of this DIE. Normally the value of DW_AT_name, but
378 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
382 /* The scope to prepend to our children. This is generally
383 allocated on the comp_unit_obstack, so will disappear
384 when this compilation unit leaves the cache. */
387 /* The location description associated with this DIE, if any. */
388 struct dwarf_block
*locdesc
;
390 /* If HAS_PC_INFO, the PC range associated with this DIE. */
394 /* Pointer into the info_buffer pointing at the target of
395 DW_AT_sibling, if any. */
398 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
399 DW_AT_specification (or DW_AT_abstract_origin or
401 unsigned int spec_offset
;
403 /* Pointers to this DIE's parent, first child, and next sibling,
405 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
408 /* This data structure holds the information of an abbrev. */
411 unsigned int number
; /* number identifying abbrev */
412 enum dwarf_tag tag
; /* dwarf tag */
413 unsigned short has_children
; /* boolean */
414 unsigned short num_attrs
; /* number of attributes */
415 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
416 struct abbrev_info
*next
; /* next in chain */
421 enum dwarf_attribute name
;
422 enum dwarf_form form
;
425 /* This data structure holds a complete die structure. */
428 enum dwarf_tag tag
; /* Tag indicating type of die */
429 unsigned int abbrev
; /* Abbrev number */
430 unsigned int offset
; /* Offset in .debug_info section */
431 unsigned int num_attrs
; /* Number of attributes */
432 struct attribute
*attrs
; /* An array of attributes */
433 struct die_info
*next_ref
; /* Next die in ref hash table */
435 /* The dies in a compilation unit form an n-ary tree. PARENT
436 points to this die's parent; CHILD points to the first child of
437 this node; and all the children of a given node are chained
438 together via their SIBLING fields, terminated by a die whose
440 struct die_info
*child
; /* Its first child, if any. */
441 struct die_info
*sibling
; /* Its next sibling, if any. */
442 struct die_info
*parent
; /* Its parent, if any. */
444 struct type
*type
; /* Cached type information */
447 /* Attributes have a name and a value */
450 enum dwarf_attribute name
;
451 enum dwarf_form form
;
455 struct dwarf_block
*blk
;
463 struct function_range
466 CORE_ADDR lowpc
, highpc
;
468 struct function_range
*next
;
471 /* Get at parts of an attribute structure */
473 #define DW_STRING(attr) ((attr)->u.str)
474 #define DW_UNSND(attr) ((attr)->u.unsnd)
475 #define DW_BLOCK(attr) ((attr)->u.blk)
476 #define DW_SND(attr) ((attr)->u.snd)
477 #define DW_ADDR(attr) ((attr)->u.addr)
479 /* Blocks are a bunch of untyped bytes. */
486 #ifndef ATTR_ALLOC_CHUNK
487 #define ATTR_ALLOC_CHUNK 4
490 /* A hash table of die offsets for following references. */
491 #ifndef REF_HASH_SIZE
492 #define REF_HASH_SIZE 1021
495 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
497 /* Obstack for allocating temporary storage used during symbol reading. */
498 static struct obstack dwarf2_tmp_obstack
;
500 /* Allocate fields for structs, unions and enums in this size. */
501 #ifndef DW_FIELD_ALLOC_CHUNK
502 #define DW_FIELD_ALLOC_CHUNK 4
505 /* A zeroed version of a partial die for initialization purposes. */
506 static struct partial_die_info zeroed_partial_die
;
508 /* FIXME: decode_locdesc sets these variables to describe the location
509 to the caller. These ought to be a structure or something. If
510 none of the flags are set, the object lives at the address returned
511 by decode_locdesc. */
513 static int isreg
; /* Object lives in register.
514 decode_locdesc's return value is
515 the register number. */
517 /* We put a pointer to this structure in the read_symtab_private field
522 /* Offset in .debug_info for this compilation unit. */
524 unsigned long dwarf_info_offset
;
527 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
528 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
530 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
531 but this would require a corresponding change in unpack_field_as_long
533 static int bits_per_byte
= 8;
535 /* The routines that read and process dies for a C struct or C++ class
536 pass lists of data member fields and lists of member function fields
537 in an instance of a field_info structure, as defined below. */
540 /* List of data member and baseclasses fields. */
543 struct nextfield
*next
;
550 /* Number of fields. */
553 /* Number of baseclasses. */
556 /* Set if the accesibility of one of the fields is not public. */
557 int non_public_fields
;
559 /* Member function fields array, entries are allocated in the order they
560 are encountered in the object file. */
563 struct nextfnfield
*next
;
564 struct fn_field fnfield
;
568 /* Member function fieldlist array, contains name of possibly overloaded
569 member function, number of overloaded member functions and a pointer
570 to the head of the member function field chain. */
575 struct nextfnfield
*head
;
579 /* Number of entries in the fnfieldlists array. */
583 /* Various complaints about symbol reading that don't abort the process */
586 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
588 complaint (&symfile_complaints
,
589 "statement list doesn't fit in .debug_line section");
593 dwarf2_complex_location_expr_complaint (void)
595 complaint (&symfile_complaints
, "location expression too complex");
599 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
602 complaint (&symfile_complaints
,
603 "const value length mismatch for '%s', got %d, expected %d", arg1
,
608 dwarf2_macros_too_long_complaint (void)
610 complaint (&symfile_complaints
,
611 "macro info runs off end of `.debug_macinfo' section");
615 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
617 complaint (&symfile_complaints
,
618 "macro debug info contains a malformed macro definition:\n`%s'",
623 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
625 complaint (&symfile_complaints
,
626 "invalid attribute class or form for '%s' in '%s'", arg1
, arg2
);
629 /* local function prototypes */
631 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
634 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
637 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
639 static void scan_partial_symbols (struct partial_die_info
*,
640 CORE_ADDR
*, CORE_ADDR
*,
643 static void add_partial_symbol (struct partial_die_info
*,
646 static int pdi_needs_namespace (enum dwarf_tag tag
);
648 static void add_partial_namespace (struct partial_die_info
*pdi
,
649 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
650 struct dwarf2_cu
*cu
);
652 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
653 struct dwarf2_cu
*cu
);
655 static char *locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
658 struct dwarf2_cu
*cu
);
660 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
662 static void psymtab_to_symtab_1 (struct partial_symtab
*);
664 char *dwarf2_read_section (struct objfile
*, asection
*);
666 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
668 static void dwarf2_free_abbrev_table (void *);
670 static struct abbrev_info
*peek_die_abbrev (char *, int *, struct dwarf2_cu
*);
672 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
675 static struct partial_die_info
*load_partial_dies (bfd
*, char *, int,
678 static char *read_partial_die (struct partial_die_info
*,
679 struct abbrev_info
*abbrev
, unsigned int,
680 bfd
*, char *, struct dwarf2_cu
*);
682 static struct partial_die_info
*find_partial_die (unsigned long,
684 struct dwarf2_cu
**);
686 static void fixup_partial_die (struct partial_die_info
*,
689 static char *read_full_die (struct die_info
**, bfd
*, char *,
690 struct dwarf2_cu
*, int *);
692 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
693 bfd
*, char *, struct dwarf2_cu
*);
695 static char *read_attribute_value (struct attribute
*, unsigned,
696 bfd
*, char *, struct dwarf2_cu
*);
698 static unsigned int read_1_byte (bfd
*, char *);
700 static int read_1_signed_byte (bfd
*, char *);
702 static unsigned int read_2_bytes (bfd
*, char *);
704 static unsigned int read_4_bytes (bfd
*, char *);
706 static unsigned long read_8_bytes (bfd
*, char *);
708 static CORE_ADDR
read_address (bfd
*, char *ptr
, struct dwarf2_cu
*,
711 static LONGEST
read_initial_length (bfd
*, char *,
712 struct comp_unit_head
*, int *bytes_read
);
714 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
717 static char *read_n_bytes (bfd
*, char *, unsigned int);
719 static char *read_string (bfd
*, char *, unsigned int *);
721 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
724 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
726 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
728 static char *skip_leb128 (bfd
*, char *);
730 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
732 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
735 static int dwarf2_attribute_true_p (struct die_info
*die
, unsigned name
,
736 struct dwarf2_cu
*cu
);
738 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
740 static struct die_info
*die_specification (struct die_info
*die
,
743 static void free_line_header (struct line_header
*lh
);
745 static struct line_header
*(dwarf_decode_line_header
746 (unsigned int offset
,
747 bfd
*abfd
, struct dwarf2_cu
*cu
));
749 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
752 static void dwarf2_start_subfile (char *, char *);
754 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
757 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
760 static void dwarf2_const_value_data (struct attribute
*attr
,
764 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
766 static struct type
*die_containing_type (struct die_info
*,
770 static struct type
*type_at_offset (unsigned int, struct objfile
*);
773 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
775 static void read_type_die (struct die_info
*, struct dwarf2_cu
*);
777 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
779 static char *typename_concat (const char *prefix
, const char *suffix
);
781 static void read_typedef (struct die_info
*, struct dwarf2_cu
*);
783 static void read_base_type (struct die_info
*, struct dwarf2_cu
*);
785 static void read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
787 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
789 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
791 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
793 static int dwarf2_get_pc_bounds (struct die_info
*,
794 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
796 static void get_scope_pc_bounds (struct die_info
*,
797 CORE_ADDR
*, CORE_ADDR
*,
800 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
803 static void dwarf2_attach_fields_to_type (struct field_info
*,
804 struct type
*, struct dwarf2_cu
*);
806 static void dwarf2_add_member_fn (struct field_info
*,
807 struct die_info
*, struct type
*,
810 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
811 struct type
*, struct dwarf2_cu
*);
813 static void read_structure_type (struct die_info
*, struct dwarf2_cu
*);
815 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
817 static char *determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
819 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
821 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
823 static const char *namespace_name (struct die_info
*die
,
824 int *is_anonymous
, struct dwarf2_cu
*);
826 static void read_enumeration_type (struct die_info
*, struct dwarf2_cu
*);
828 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
830 static struct type
*dwarf_base_type (int, int, struct dwarf2_cu
*);
832 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
834 static void read_array_type (struct die_info
*, struct dwarf2_cu
*);
836 static void read_tag_pointer_type (struct die_info
*, struct dwarf2_cu
*);
838 static void read_tag_ptr_to_member_type (struct die_info
*,
841 static void read_tag_reference_type (struct die_info
*, struct dwarf2_cu
*);
843 static void read_tag_const_type (struct die_info
*, struct dwarf2_cu
*);
845 static void read_tag_volatile_type (struct die_info
*, struct dwarf2_cu
*);
847 static void read_tag_string_type (struct die_info
*, struct dwarf2_cu
*);
849 static void read_subroutine_type (struct die_info
*, struct dwarf2_cu
*);
851 static struct die_info
*read_comp_unit (char *, bfd
*, struct dwarf2_cu
*);
853 static struct die_info
*read_die_and_children (char *info_ptr
, bfd
*abfd
,
856 struct die_info
*parent
);
858 static struct die_info
*read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
861 struct die_info
*parent
);
863 static void free_die_list (struct die_info
*);
865 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
867 static void process_die (struct die_info
*, struct dwarf2_cu
*);
869 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
871 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
873 static struct die_info
*dwarf2_extension (struct die_info
*die
,
876 static char *dwarf_tag_name (unsigned int);
878 static char *dwarf_attr_name (unsigned int);
880 static char *dwarf_form_name (unsigned int);
882 static char *dwarf_stack_op_name (unsigned int);
884 static char *dwarf_bool_name (unsigned int);
886 static char *dwarf_type_encoding_name (unsigned int);
889 static char *dwarf_cfi_name (unsigned int);
891 struct die_info
*copy_die (struct die_info
*);
894 static struct die_info
*sibling_die (struct die_info
*);
896 static void dump_die (struct die_info
*);
898 static void dump_die_list (struct die_info
*);
900 static void store_in_ref_table (unsigned int, struct die_info
*);
902 static void dwarf2_empty_hash_tables (void);
904 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
907 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
909 static struct die_info
*follow_die_ref (unsigned int);
911 static struct type
*dwarf2_fundamental_type (struct objfile
*, int,
914 /* memory allocation interface */
916 static void dwarf2_free_tmp_obstack (void *);
918 static struct dwarf_block
*dwarf_alloc_block (void);
920 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
922 static struct die_info
*dwarf_alloc_die (void);
924 static void initialize_cu_func_list (struct dwarf2_cu
*);
926 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
929 static void dwarf_decode_macros (struct line_header
*, unsigned int,
930 char *, bfd
*, struct dwarf2_cu
*);
932 static int attr_form_is_block (struct attribute
*);
935 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
936 struct dwarf2_cu
*cu
);
938 static char *skip_one_die (char *info_ptr
, struct abbrev_info
*abbrev
,
939 struct dwarf2_cu
*cu
);
941 static void free_stack_comp_unit (void *);
943 static void *hashtab_obstack_allocate (void *data
, size_t size
, size_t count
);
945 static void dummy_obstack_deallocate (void *object
, void *data
);
947 static hashval_t
partial_die_hash (const void *item
);
949 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
951 /* Try to locate the sections we need for DWARF 2 debugging
952 information and return true if we have enough to do something. */
955 dwarf2_has_info (struct objfile
*objfile
)
957 struct dwarf2_per_objfile
*data
;
959 /* Initialize per-objfile state. */
960 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
961 memset (data
, 0, sizeof (*data
));
962 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
963 dwarf2_per_objfile
= data
;
965 dwarf_info_section
= 0;
966 dwarf_abbrev_section
= 0;
967 dwarf_line_section
= 0;
968 dwarf_str_section
= 0;
969 dwarf_macinfo_section
= 0;
970 dwarf_frame_section
= 0;
971 dwarf_eh_frame_section
= 0;
972 dwarf_ranges_section
= 0;
973 dwarf_loc_section
= 0;
975 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
976 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
979 /* This function is mapped across the sections and remembers the
980 offset and size of each of the debugging sections we are interested
984 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
986 if (strcmp (sectp
->name
, INFO_SECTION
) == 0)
988 dwarf2_per_objfile
->info_size
= bfd_get_section_size_before_reloc (sectp
);
989 dwarf_info_section
= sectp
;
991 else if (strcmp (sectp
->name
, ABBREV_SECTION
) == 0)
993 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
994 dwarf_abbrev_section
= sectp
;
996 else if (strcmp (sectp
->name
, LINE_SECTION
) == 0)
998 dwarf2_per_objfile
->line_size
= bfd_get_section_size_before_reloc (sectp
);
999 dwarf_line_section
= sectp
;
1001 else if (strcmp (sectp
->name
, PUBNAMES_SECTION
) == 0)
1003 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
1004 dwarf_pubnames_section
= sectp
;
1006 else if (strcmp (sectp
->name
, ARANGES_SECTION
) == 0)
1008 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size_before_reloc (sectp
);
1009 dwarf_aranges_section
= sectp
;
1011 else if (strcmp (sectp
->name
, LOC_SECTION
) == 0)
1013 dwarf2_per_objfile
->loc_size
= bfd_get_section_size_before_reloc (sectp
);
1014 dwarf_loc_section
= sectp
;
1016 else if (strcmp (sectp
->name
, MACINFO_SECTION
) == 0)
1018 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
1019 dwarf_macinfo_section
= sectp
;
1021 else if (strcmp (sectp
->name
, STR_SECTION
) == 0)
1023 dwarf2_per_objfile
->str_size
= bfd_get_section_size_before_reloc (sectp
);
1024 dwarf_str_section
= sectp
;
1026 else if (strcmp (sectp
->name
, FRAME_SECTION
) == 0)
1028 dwarf2_per_objfile
->frame_size
= bfd_get_section_size_before_reloc (sectp
);
1029 dwarf_frame_section
= sectp
;
1031 else if (strcmp (sectp
->name
, EH_FRAME_SECTION
) == 0)
1033 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1034 if (aflag
& SEC_HAS_CONTENTS
)
1036 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1037 dwarf_eh_frame_section
= sectp
;
1040 else if (strcmp (sectp
->name
, RANGES_SECTION
) == 0)
1042 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size_before_reloc (sectp
);
1043 dwarf_ranges_section
= sectp
;
1047 /* Build a partial symbol table. */
1050 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1052 /* We definitely need the .debug_info and .debug_abbrev sections */
1054 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1055 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1057 if (dwarf_line_section
)
1058 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1060 dwarf2_per_objfile
->line_buffer
= NULL
;
1062 if (dwarf_str_section
)
1063 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1065 dwarf2_per_objfile
->str_buffer
= NULL
;
1067 if (dwarf_macinfo_section
)
1068 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1069 dwarf_macinfo_section
);
1071 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1073 if (dwarf_ranges_section
)
1074 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1076 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1078 if (dwarf_loc_section
)
1079 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1081 dwarf2_per_objfile
->loc_buffer
= NULL
;
1084 || (objfile
->global_psymbols
.size
== 0
1085 && objfile
->static_psymbols
.size
== 0))
1087 init_psymbol_list (objfile
, 1024);
1091 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1093 /* Things are significantly easier if we have .debug_aranges and
1094 .debug_pubnames sections */
1096 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1100 /* only test this case for now */
1102 /* In this case we have to work a bit harder */
1103 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1108 /* Build the partial symbol table from the information in the
1109 .debug_pubnames and .debug_aranges sections. */
1112 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1114 bfd
*abfd
= objfile
->obfd
;
1115 char *aranges_buffer
, *pubnames_buffer
;
1116 char *aranges_ptr
, *pubnames_ptr
;
1117 unsigned int entry_length
, version
, info_offset
, info_size
;
1119 pubnames_buffer
= dwarf2_read_section (objfile
,
1120 dwarf_pubnames_section
);
1121 pubnames_ptr
= pubnames_buffer
;
1122 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1124 struct comp_unit_head cu_header
;
1127 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1129 pubnames_ptr
+= bytes_read
;
1130 version
= read_1_byte (abfd
, pubnames_ptr
);
1132 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1134 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1138 aranges_buffer
= dwarf2_read_section (objfile
,
1139 dwarf_aranges_section
);
1144 /* Read in the comp unit header information from the debug_info at
1148 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1149 char *info_ptr
, bfd
*abfd
)
1153 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1155 info_ptr
+= bytes_read
;
1156 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1158 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1160 info_ptr
+= bytes_read
;
1161 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1163 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1164 if (signed_addr
< 0)
1165 internal_error (__FILE__
, __LINE__
,
1166 "read_comp_unit_head: dwarf from non elf file");
1167 cu_header
->signed_addr_p
= signed_addr
;
1172 partial_read_comp_unit_head (struct comp_unit_head
*header
, char *info_ptr
,
1175 char *beg_of_comp_unit
= info_ptr
;
1177 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1179 if (header
->version
!= 2)
1180 error ("Dwarf Error: wrong version in compilation unit header "
1181 "(is %d, should be %d) [in module %s]", header
->version
,
1182 2, bfd_get_filename (abfd
));
1184 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1185 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1186 "(offset 0x%lx + 6) [in module %s]",
1187 (long) header
->abbrev_offset
,
1188 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1189 bfd_get_filename (abfd
));
1191 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1192 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1193 error ("Dwarf Error: bad length (0x%lx) in compilation unit header "
1194 "(offset 0x%lx + 0) [in module %s]",
1195 (long) header
->length
,
1196 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1197 bfd_get_filename (abfd
));
1202 /* Build the partial symbol table by doing a quick pass through the
1203 .debug_info and .debug_abbrev sections. */
1206 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1208 /* Instead of reading this into a big buffer, we should probably use
1209 mmap() on architectures that support it. (FIXME) */
1210 bfd
*abfd
= objfile
->obfd
;
1212 char *beg_of_comp_unit
;
1213 struct partial_die_info comp_unit_die
;
1214 struct partial_symtab
*pst
;
1215 struct cleanup
*back_to
;
1216 CORE_ADDR lowpc
, highpc
, baseaddr
;
1218 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1220 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1221 the partial symbol scan, like attribute values.
1223 We could reduce our peak memory consumption during partial symbol
1224 table construction by freeing stuff from this obstack more often
1225 --- say, after processing each compilation unit, or each die ---
1226 but it turns out that this saves almost nothing. For an
1227 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1228 on dwarf2_tmp_obstack. Some investigation showed:
1230 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1231 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1232 all fixed-length values not requiring dynamic allocation.
1234 2) 30% of the attributes used the form DW_FORM_string. For
1235 DW_FORM_string, read_attribute simply hands back a pointer to
1236 the null-terminated string in info_buffer, so no dynamic
1237 allocation is needed there either.
1239 3) The remaining 1% of the attributes all used DW_FORM_block1.
1240 75% of those were DW_AT_frame_base location lists for
1241 functions; the rest were DW_AT_location attributes, probably
1242 for the global variables.
1244 Anyway, what this all means is that the memory the dwarf2
1245 reader uses as temporary space reading partial symbols is about
1246 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1248 obstack_init (&dwarf2_tmp_obstack
);
1249 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1251 /* Since the objects we're extracting from .debug_info vary in
1252 length, only the individual functions to extract them (like
1253 read_comp_unit_head and load_partial_die) can really know whether
1254 the buffer is large enough to hold another complete object.
1256 At the moment, they don't actually check that. If .debug_info
1257 holds just one extra byte after the last compilation unit's dies,
1258 then read_comp_unit_head will happily read off the end of the
1259 buffer. read_partial_die is similarly casual. Those functions
1262 For this loop condition, simply checking whether there's any data
1263 left at all should be sufficient. */
1264 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1265 + dwarf2_per_objfile
->info_size
))
1267 struct cleanup
*back_to_inner
;
1268 struct dwarf2_cu cu
;
1269 struct abbrev_info
*abbrev
;
1270 unsigned int bytes_read
;
1271 struct dwarf2_per_cu_data
*this_cu
;
1273 beg_of_comp_unit
= info_ptr
;
1275 memset (&cu
, 0, sizeof (cu
));
1277 obstack_init (&cu
.comp_unit_obstack
);
1279 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1281 cu
.objfile
= objfile
;
1282 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1284 /* Complete the cu_header */
1285 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1286 cu
.header
.first_die_ptr
= info_ptr
;
1287 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1289 cu
.list_in_scope
= &file_symbols
;
1291 cu
.partial_dies
= NULL
;
1293 /* Read the abbrevs for this compilation unit into a table */
1294 dwarf2_read_abbrevs (abfd
, &cu
);
1295 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1297 /* Read the compilation unit die */
1298 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1299 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1300 abfd
, info_ptr
, &cu
);
1302 /* Set the language we're debugging */
1303 set_cu_language (comp_unit_die
.language
, &cu
);
1305 /* Allocate a new partial symbol table structure */
1306 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1307 comp_unit_die
.name
? comp_unit_die
.name
: "",
1308 comp_unit_die
.lowpc
,
1309 objfile
->global_psymbols
.next
,
1310 objfile
->static_psymbols
.next
);
1312 pst
->read_symtab_private
= (char *)
1313 obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct dwarf2_pinfo
));
1314 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1315 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1317 /* Store the function that reads in the rest of the symbol table */
1318 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1320 /* Check if comp unit has_children.
1321 If so, read the rest of the partial symbols from this comp unit.
1322 If not, there's no more debug_info for this comp unit. */
1323 if (comp_unit_die
.has_children
)
1325 struct partial_die_info
*first_die
;
1327 lowpc
= ((CORE_ADDR
) -1);
1328 highpc
= ((CORE_ADDR
) 0);
1330 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1332 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1334 /* If we didn't find a lowpc, set it to highpc to avoid
1335 complaints from `maint check'. */
1336 if (lowpc
== ((CORE_ADDR
) -1))
1339 /* If the compilation unit didn't have an explicit address range,
1340 then use the information extracted from its child dies. */
1341 if (! comp_unit_die
.has_pc_info
)
1343 comp_unit_die
.lowpc
= lowpc
;
1344 comp_unit_die
.highpc
= highpc
;
1347 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1348 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1350 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1351 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1352 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1353 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1354 sort_pst_symbols (pst
);
1356 /* If there is already a psymtab or symtab for a file of this
1357 name, remove it. (If there is a symtab, more drastic things
1358 also happen.) This happens in VxWorks. */
1359 free_named_symtabs (pst
->filename
);
1361 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1362 + cu
.header
.initial_length_size
;
1364 do_cleanups (back_to_inner
);
1366 do_cleanups (back_to
);
1369 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1370 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1374 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1375 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1377 struct objfile
*objfile
= cu
->objfile
;
1378 bfd
*abfd
= objfile
->obfd
;
1379 struct partial_die_info
*pdi
;
1381 /* Now, march along the PDI's, descending into ones which have
1382 interesting children but skipping the children of the other ones,
1383 until we reach the end of the compilation unit. */
1389 fixup_partial_die (pdi
, cu
);
1391 /* Anonymous namespaces have no name but have interesting
1392 children, so we need to look at them. Ditto for anonymous
1395 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1396 || pdi
->tag
== DW_TAG_enumeration_type
)
1400 case DW_TAG_subprogram
:
1401 if (pdi
->has_pc_info
)
1403 if (pdi
->lowpc
< *lowpc
)
1405 *lowpc
= pdi
->lowpc
;
1407 if (pdi
->highpc
> *highpc
)
1409 *highpc
= pdi
->highpc
;
1411 if (!pdi
->is_declaration
)
1413 add_partial_symbol (pdi
, cu
);
1417 case DW_TAG_variable
:
1418 case DW_TAG_typedef
:
1419 case DW_TAG_union_type
:
1420 if (!pdi
->is_declaration
)
1422 add_partial_symbol (pdi
, cu
);
1425 case DW_TAG_class_type
:
1426 case DW_TAG_structure_type
:
1427 if (!pdi
->is_declaration
)
1429 add_partial_symbol (pdi
, cu
);
1432 case DW_TAG_enumeration_type
:
1433 if (!pdi
->is_declaration
)
1434 add_partial_enumeration (pdi
, cu
);
1436 case DW_TAG_base_type
:
1437 case DW_TAG_subrange_type
:
1438 /* File scope base type definitions are added to the partial
1440 add_partial_symbol (pdi
, cu
);
1442 case DW_TAG_namespace
:
1443 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1450 /* If the die has a sibling, skip to the sibling. */
1452 pdi
= pdi
->die_sibling
;
1456 /* Functions used to compute the fully scoped name of a partial DIE.
1458 Normally, this is simple. For C++, the parent DIE's fully scoped
1459 name is concatenated with "::" and the partial DIE's name.
1460 Enumerators are an exception; they use the scope of their parent
1461 enumeration type, i.e. the name of the enumeration type is not
1462 prepended to the enumerator.
1464 There are two complexities. One is DW_AT_specification; in this
1465 case "parent" means the parent of the target of the specification,
1466 instead of the direct parent of the DIE. The other is compilers
1467 which do not emit DW_TAG_namespace; in this case we try to guess
1468 the fully qualified name of structure types from their members'
1469 linkage names. This must be done using the DIE's children rather
1470 than the children of any DW_AT_specification target. We only need
1471 to do this for structures at the top level, i.e. if the target of
1472 any DW_AT_specification (if any; otherwise the DIE itself) does not
1475 /* Compute the scope prefix associated with PDI's parent, in
1476 compilation unit CU. The result will be allocated on CU's
1477 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1478 field. NULL is returned if no prefix is necessary. */
1480 partial_die_parent_scope (struct partial_die_info
*pdi
,
1481 struct dwarf2_cu
*cu
)
1483 char *grandparent_scope
;
1484 struct partial_die_info
*parent
, *real_pdi
;
1485 struct dwarf2_cu
*spec_cu
;
1487 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1488 then this means the parent of the specification DIE. */
1492 while (real_pdi
->has_specification
)
1493 real_pdi
= find_partial_die (real_pdi
->spec_offset
, spec_cu
, &spec_cu
);
1495 parent
= real_pdi
->die_parent
;
1499 if (parent
->scope_set
)
1500 return parent
->scope
;
1502 fixup_partial_die (parent
, cu
);
1504 grandparent_scope
= partial_die_parent_scope (parent
, spec_cu
);
1506 if (parent
->tag
== DW_TAG_namespace
1507 || parent
->tag
== DW_TAG_structure_type
1508 || parent
->tag
== DW_TAG_class_type
1509 || parent
->tag
== DW_TAG_union_type
)
1511 if (grandparent_scope
== NULL
)
1512 parent
->scope
= parent
->name
;
1514 parent
->scope
= obconcat (&cu
->comp_unit_obstack
, grandparent_scope
,
1515 "::", parent
->name
);
1517 else if (parent
->tag
== DW_TAG_enumeration_type
)
1518 /* Enumerators should not get the name of the enumeration as a prefix. */
1519 parent
->scope
= grandparent_scope
;
1522 /* FIXME drow/2004-04-01: What should we be doing with
1523 function-local names? For partial symbols, we should probably be
1525 complaint (&symfile_complaints
,
1526 "unhandled containing DIE tag %d for DIE at %d",
1527 parent
->tag
, pdi
->offset
);
1528 parent
->scope
= grandparent_scope
;
1531 parent
->scope_set
= 1;
1532 return parent
->scope
;
1535 /* Return the fully scoped name associated with PDI, from compilation unit
1536 CU. The result will be allocated with malloc. */
1538 partial_die_full_name (struct partial_die_info
*pdi
,
1539 struct dwarf2_cu
*cu
)
1543 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1544 if (parent_scope
== NULL
)
1547 return concat (parent_scope
, "::", pdi
->name
, NULL
);
1551 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1553 struct objfile
*objfile
= cu
->objfile
;
1556 const char *my_prefix
;
1557 const struct partial_symbol
*psym
= NULL
;
1559 int built_actual_name
= 0;
1561 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1565 if (pdi_needs_namespace (pdi
->tag
))
1567 actual_name
= partial_die_full_name (pdi
, cu
);
1569 built_actual_name
= 1;
1572 if (actual_name
== NULL
)
1573 actual_name
= pdi
->name
;
1577 case DW_TAG_subprogram
:
1578 if (pdi
->is_external
)
1580 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1581 mst_text, objfile); */
1582 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1583 VAR_DOMAIN
, LOC_BLOCK
,
1584 &objfile
->global_psymbols
,
1585 0, pdi
->lowpc
+ baseaddr
,
1586 cu
->language
, objfile
);
1590 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1591 mst_file_text, objfile); */
1592 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1593 VAR_DOMAIN
, LOC_BLOCK
,
1594 &objfile
->static_psymbols
,
1595 0, pdi
->lowpc
+ baseaddr
,
1596 cu
->language
, objfile
);
1599 case DW_TAG_variable
:
1600 if (pdi
->is_external
)
1603 Don't enter into the minimal symbol tables as there is
1604 a minimal symbol table entry from the ELF symbols already.
1605 Enter into partial symbol table if it has a location
1606 descriptor or a type.
1607 If the location descriptor is missing, new_symbol will create
1608 a LOC_UNRESOLVED symbol, the address of the variable will then
1609 be determined from the minimal symbol table whenever the variable
1611 The address for the partial symbol table entry is not
1612 used by GDB, but it comes in handy for debugging partial symbol
1616 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1617 if (pdi
->locdesc
|| pdi
->has_type
)
1618 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1619 VAR_DOMAIN
, LOC_STATIC
,
1620 &objfile
->global_psymbols
,
1622 cu
->language
, objfile
);
1626 /* Static Variable. Skip symbols without location descriptors. */
1627 if (pdi
->locdesc
== NULL
)
1629 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1630 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1631 mst_file_data, objfile); */
1632 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1633 VAR_DOMAIN
, LOC_STATIC
,
1634 &objfile
->static_psymbols
,
1636 cu
->language
, objfile
);
1639 case DW_TAG_typedef
:
1640 case DW_TAG_base_type
:
1641 case DW_TAG_subrange_type
:
1642 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1643 VAR_DOMAIN
, LOC_TYPEDEF
,
1644 &objfile
->static_psymbols
,
1645 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1647 case DW_TAG_namespace
:
1648 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1649 VAR_DOMAIN
, LOC_TYPEDEF
,
1650 &objfile
->global_psymbols
,
1651 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1653 case DW_TAG_class_type
:
1654 case DW_TAG_structure_type
:
1655 case DW_TAG_union_type
:
1656 case DW_TAG_enumeration_type
:
1657 /* Skip aggregate types without children, these are external
1659 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1660 static vs. global. */
1661 if (pdi
->has_children
== 0)
1663 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1664 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1665 cu
->language
== language_cplus
1666 ? &objfile
->global_psymbols
1667 : &objfile
->static_psymbols
,
1668 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1670 if (cu
->language
== language_cplus
)
1672 /* For C++, these implicitly act as typedefs as well. */
1673 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1674 VAR_DOMAIN
, LOC_TYPEDEF
,
1675 &objfile
->global_psymbols
,
1676 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1679 case DW_TAG_enumerator
:
1680 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1681 VAR_DOMAIN
, LOC_CONST
,
1682 cu
->language
== language_cplus
1683 ? &objfile
->global_psymbols
1684 : &objfile
->static_psymbols
,
1685 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1691 /* Check to see if we should scan the name for possible namespace
1692 info. Only do this if this is C++, if we don't have namespace
1693 debugging info in the file, if the psym is of an appropriate type
1694 (otherwise we'll have psym == NULL), and if we actually had a
1695 mangled name to begin with. */
1697 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
1698 cases which do not set PSYM above? */
1700 if (cu
->language
== language_cplus
1701 && cu
->has_namespace_info
== 0
1703 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
1704 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
1707 if (built_actual_name
)
1708 xfree (actual_name
);
1711 /* Determine whether a die of type TAG living in a C++ class or
1712 namespace needs to have the name of the scope prepended to the
1713 name listed in the die. */
1716 pdi_needs_namespace (enum dwarf_tag tag
)
1720 case DW_TAG_namespace
:
1721 case DW_TAG_typedef
:
1722 case DW_TAG_class_type
:
1723 case DW_TAG_structure_type
:
1724 case DW_TAG_union_type
:
1725 case DW_TAG_enumeration_type
:
1726 case DW_TAG_enumerator
:
1733 /* Read a partial die corresponding to a namespace; also, add a symbol
1734 corresponding to that namespace to the symbol table. NAMESPACE is
1735 the name of the enclosing namespace. */
1738 add_partial_namespace (struct partial_die_info
*pdi
,
1739 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1740 struct dwarf2_cu
*cu
)
1742 struct objfile
*objfile
= cu
->objfile
;
1744 /* Add a symbol for the namespace. */
1746 add_partial_symbol (pdi
, cu
);
1748 /* Now scan partial symbols in that namespace. */
1750 if (pdi
->has_children
)
1751 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
1754 /* See if we can figure out if the class lives in a namespace. We do
1755 this by looking for a member function; its demangled name will
1756 contain namespace info, if there is any. */
1759 guess_structure_name (struct partial_die_info
*struct_pdi
,
1760 struct dwarf2_cu
*cu
)
1762 if (cu
->language
== language_cplus
1763 && cu
->has_namespace_info
== 0
1764 && struct_pdi
->has_children
)
1766 /* NOTE: carlton/2003-10-07: Getting the info this way changes
1767 what template types look like, because the demangler
1768 frequently doesn't give the same name as the debug info. We
1769 could fix this by only using the demangled name to get the
1770 prefix (but see comment in read_structure_type). */
1772 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
1773 struct partial_die_info
*real_pdi
;
1774 struct dwarf2_cu
*spec_cu
;
1776 /* If this DIE (this DIE's specification, if any) has a parent, then
1777 we should not do this. We'll prepend the parent's fully qualified
1778 name when we create the partial symbol. */
1780 real_pdi
= struct_pdi
;
1782 while (real_pdi
->has_specification
)
1783 real_pdi
= find_partial_die (real_pdi
->spec_offset
, spec_cu
, &spec_cu
);
1785 if (real_pdi
->die_parent
!= NULL
)
1788 while (child_pdi
!= NULL
)
1790 if (child_pdi
->tag
== DW_TAG_subprogram
)
1792 char *actual_class_name
1793 = class_name_from_physname (child_pdi
->name
);
1794 if (actual_class_name
!= NULL
)
1797 = obsavestring (actual_class_name
,
1798 strlen (actual_class_name
),
1799 &cu
->comp_unit_obstack
);
1800 xfree (actual_class_name
);
1805 child_pdi
= child_pdi
->die_sibling
;
1810 /* Read a partial die corresponding to an enumeration type. */
1813 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1814 struct dwarf2_cu
*cu
)
1816 struct objfile
*objfile
= cu
->objfile
;
1817 bfd
*abfd
= objfile
->obfd
;
1818 struct partial_die_info
*pdi
;
1820 if (enum_pdi
->name
!= NULL
)
1821 add_partial_symbol (enum_pdi
, cu
);
1823 pdi
= enum_pdi
->die_child
;
1826 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
1827 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
1829 add_partial_symbol (pdi
, cu
);
1830 pdi
= pdi
->die_sibling
;
1834 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
1835 Return the corresponding abbrev, or NULL if the number is zero (indicating
1836 an empty DIE). In either case *BYTES_READ will be set to the length of
1837 the initial number. */
1839 static struct abbrev_info
*
1840 peek_die_abbrev (char *info_ptr
, int *bytes_read
, struct dwarf2_cu
*cu
)
1842 bfd
*abfd
= cu
->objfile
->obfd
;
1843 unsigned int abbrev_number
;
1844 struct abbrev_info
*abbrev
;
1846 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
1848 if (abbrev_number
== 0)
1851 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
1854 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
1855 bfd_get_filename (abfd
));
1861 /* Scan the debug information for CU starting at INFO_PTR. Returns a
1862 pointer to the end of a series of DIEs, terminated by an empty
1863 DIE. Any children of the skipped DIEs will also be skipped. */
1866 skip_children (char *info_ptr
, struct dwarf2_cu
*cu
)
1868 struct abbrev_info
*abbrev
;
1869 unsigned int bytes_read
;
1873 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1875 return info_ptr
+ bytes_read
;
1877 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
1881 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
1882 should point just after the initial uleb128 of a DIE, and the
1883 abbrev corresponding to that skipped uleb128 should be passed in
1884 ABBREV. Returns a pointer to this DIE's sibling, skipping any
1888 skip_one_die (char *info_ptr
, struct abbrev_info
*abbrev
,
1889 struct dwarf2_cu
*cu
)
1891 unsigned int bytes_read
;
1892 struct attribute attr
;
1893 bfd
*abfd
= cu
->objfile
->obfd
;
1894 unsigned int form
, i
;
1896 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
1898 /* The only abbrev we care about is DW_AT_sibling. */
1899 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
1901 read_attribute (&attr
, &abbrev
->attrs
[i
],
1902 abfd
, info_ptr
, cu
);
1903 if (attr
.form
== DW_FORM_ref_addr
)
1904 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
1906 return dwarf2_per_objfile
->info_buffer
1907 + dwarf2_get_ref_die_offset (&attr
, cu
);
1910 /* If it isn't DW_AT_sibling, skip this attribute. */
1911 form
= abbrev
->attrs
[i
].form
;
1916 case DW_FORM_ref_addr
:
1917 info_ptr
+= cu
->header
.addr_size
;
1936 case DW_FORM_string
:
1937 read_string (abfd
, info_ptr
, &bytes_read
);
1938 info_ptr
+= bytes_read
;
1941 info_ptr
+= cu
->header
.offset_size
;
1944 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
1945 info_ptr
+= bytes_read
;
1947 case DW_FORM_block1
:
1948 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
1950 case DW_FORM_block2
:
1951 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
1953 case DW_FORM_block4
:
1954 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
1958 case DW_FORM_ref_udata
:
1959 info_ptr
= skip_leb128 (abfd
, info_ptr
);
1961 case DW_FORM_indirect
:
1962 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
1963 info_ptr
+= bytes_read
;
1964 /* We need to continue parsing from here, so just go back to
1966 goto skip_attribute
;
1969 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
1970 dwarf_form_name (form
),
1971 bfd_get_filename (abfd
));
1975 if (abbrev
->has_children
)
1976 return skip_children (info_ptr
, cu
);
1981 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
1982 the next DIE after ORIG_PDI. */
1985 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, char *info_ptr
,
1986 bfd
*abfd
, struct dwarf2_cu
*cu
)
1988 /* Do we know the sibling already? */
1990 if (orig_pdi
->sibling
)
1991 return orig_pdi
->sibling
;
1993 /* Are there any children to deal with? */
1995 if (!orig_pdi
->has_children
)
1998 /* Skip the children the long way. */
2000 return skip_children (info_ptr
, cu
);
2003 /* Expand this partial symbol table into a full symbol table. */
2006 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2008 /* FIXME: This is barely more than a stub. */
2013 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
2019 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
2020 gdb_flush (gdb_stdout
);
2023 psymtab_to_symtab_1 (pst
);
2025 /* Finish up the debug error message. */
2027 printf_filtered ("done.\n");
2033 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2035 struct objfile
*objfile
= pst
->objfile
;
2036 bfd
*abfd
= objfile
->obfd
;
2037 struct dwarf2_cu cu
;
2038 struct die_info
*dies
;
2039 unsigned long offset
;
2040 CORE_ADDR lowpc
, highpc
;
2041 struct die_info
*child_die
;
2043 struct symtab
*symtab
;
2044 struct cleanup
*back_to
;
2045 struct attribute
*attr
;
2048 dwarf2_per_objfile
= objfile_data (pst
->objfile
, dwarf2_objfile_data_key
);
2050 /* Set local variables from the partial symbol table info. */
2051 offset
= DWARF_INFO_OFFSET (pst
);
2053 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2054 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2056 /* We're in the global namespace. */
2057 processing_current_prefix
= "";
2059 obstack_init (&dwarf2_tmp_obstack
);
2060 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
2063 make_cleanup (really_free_pendings
, NULL
);
2065 cu
.objfile
= objfile
;
2067 /* read in the comp_unit header */
2068 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
2070 /* Read the abbrevs for this compilation unit */
2071 dwarf2_read_abbrevs (abfd
, &cu
);
2072 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2074 cu
.header
.offset
= offset
;
2076 cu
.list_in_scope
= &file_symbols
;
2078 dies
= read_comp_unit (info_ptr
, abfd
, &cu
);
2080 make_cleanup_free_die_list (dies
);
2082 /* Find the base address of the compilation unit for range lists and
2083 location lists. It will normally be specified by DW_AT_low_pc.
2084 In DWARF-3 draft 4, the base address could be overridden by
2085 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2086 compilation units with discontinuous ranges. */
2088 cu
.header
.base_known
= 0;
2089 cu
.header
.base_address
= 0;
2091 attr
= dwarf2_attr (dies
, DW_AT_entry_pc
, &cu
);
2094 cu
.header
.base_address
= DW_ADDR (attr
);
2095 cu
.header
.base_known
= 1;
2099 attr
= dwarf2_attr (dies
, DW_AT_low_pc
, &cu
);
2102 cu
.header
.base_address
= DW_ADDR (attr
);
2103 cu
.header
.base_known
= 1;
2107 /* Do line number decoding in read_file_scope () */
2108 process_die (dies
, &cu
);
2110 /* Some compilers don't define a DW_AT_high_pc attribute for the
2111 compilation unit. If the DW_AT_high_pc is missing, synthesize
2112 it, by scanning the DIE's below the compilation unit. */
2113 get_scope_pc_bounds (dies
, &lowpc
, &highpc
, &cu
);
2115 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2117 /* Set symtab language to language from DW_AT_language.
2118 If the compilation is from a C file generated by language preprocessors,
2119 do not set the language if it was already deduced by start_subfile. */
2121 && !(cu
.language
== language_c
&& symtab
->language
!= language_c
))
2123 symtab
->language
= cu
.language
;
2125 pst
->symtab
= symtab
;
2128 do_cleanups (back_to
);
2131 /* Process a die and its children. */
2134 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2138 case DW_TAG_padding
:
2140 case DW_TAG_compile_unit
:
2141 read_file_scope (die
, cu
);
2143 case DW_TAG_subprogram
:
2144 read_subroutine_type (die
, cu
);
2145 read_func_scope (die
, cu
);
2147 case DW_TAG_inlined_subroutine
:
2148 /* FIXME: These are ignored for now.
2149 They could be used to set breakpoints on all inlined instances
2150 of a function and make GDB `next' properly over inlined functions. */
2152 case DW_TAG_lexical_block
:
2153 case DW_TAG_try_block
:
2154 case DW_TAG_catch_block
:
2155 read_lexical_block_scope (die
, cu
);
2157 case DW_TAG_class_type
:
2158 case DW_TAG_structure_type
:
2159 case DW_TAG_union_type
:
2160 read_structure_type (die
, cu
);
2161 process_structure_scope (die
, cu
);
2163 case DW_TAG_enumeration_type
:
2164 read_enumeration_type (die
, cu
);
2165 process_enumeration_scope (die
, cu
);
2168 /* FIXME drow/2004-03-14: These initialize die->type, but do not create
2169 a symbol or process any children. Therefore it doesn't do anything
2170 that won't be done on-demand by read_type_die. */
2171 case DW_TAG_subroutine_type
:
2172 read_subroutine_type (die
, cu
);
2174 case DW_TAG_array_type
:
2175 read_array_type (die
, cu
);
2177 case DW_TAG_pointer_type
:
2178 read_tag_pointer_type (die
, cu
);
2180 case DW_TAG_ptr_to_member_type
:
2181 read_tag_ptr_to_member_type (die
, cu
);
2183 case DW_TAG_reference_type
:
2184 read_tag_reference_type (die
, cu
);
2186 case DW_TAG_string_type
:
2187 read_tag_string_type (die
, cu
);
2191 case DW_TAG_base_type
:
2192 read_base_type (die
, cu
);
2193 /* Add a typedef symbol for the type definition, if it has a
2195 new_symbol (die
, die
->type
, cu
);
2197 case DW_TAG_subrange_type
:
2198 read_subrange_type (die
, cu
);
2199 /* Add a typedef symbol for the type definition, if it has a
2201 new_symbol (die
, die
->type
, cu
);
2203 case DW_TAG_common_block
:
2204 read_common_block (die
, cu
);
2206 case DW_TAG_common_inclusion
:
2208 case DW_TAG_namespace
:
2209 processing_has_namespace_info
= 1;
2210 read_namespace (die
, cu
);
2212 case DW_TAG_imported_declaration
:
2213 case DW_TAG_imported_module
:
2214 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2215 information contained in these. DW_TAG_imported_declaration
2216 dies shouldn't have children; DW_TAG_imported_module dies
2217 shouldn't in the C++ case, but conceivably could in the
2218 Fortran case, so we'll have to replace this gdb_assert if
2219 Fortran compilers start generating that info. */
2220 processing_has_namespace_info
= 1;
2221 gdb_assert (die
->child
== NULL
);
2224 new_symbol (die
, NULL
, cu
);
2230 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2232 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2236 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2238 struct objfile
*objfile
= cu
->objfile
;
2239 struct comp_unit_head
*cu_header
= &cu
->header
;
2240 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2241 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2242 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2243 struct attribute
*attr
;
2244 char *name
= "<unknown>";
2245 char *comp_dir
= NULL
;
2246 struct die_info
*child_die
;
2247 bfd
*abfd
= objfile
->obfd
;
2248 struct line_header
*line_header
= 0;
2251 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2253 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2255 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2256 from finish_block. */
2257 if (lowpc
== ((CORE_ADDR
) -1))
2262 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2265 name
= DW_STRING (attr
);
2267 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2270 comp_dir
= DW_STRING (attr
);
2273 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2274 directory, get rid of it. */
2275 char *cp
= strchr (comp_dir
, ':');
2277 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2282 if (objfile
->ei
.entry_point
>= lowpc
&&
2283 objfile
->ei
.entry_point
< highpc
)
2285 objfile
->ei
.deprecated_entry_file_lowpc
= lowpc
;
2286 objfile
->ei
.deprecated_entry_file_highpc
= highpc
;
2289 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2292 set_cu_language (DW_UNSND (attr
), cu
);
2295 /* We assume that we're processing GCC output. */
2296 processing_gcc_compilation
= 2;
2298 /* FIXME:Do something here. */
2299 if (dip
->at_producer
!= NULL
)
2301 handle_producer (dip
->at_producer
);
2305 /* The compilation unit may be in a different language or objfile,
2306 zero out all remembered fundamental types. */
2307 memset (cu
->ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
2309 start_symtab (name
, comp_dir
, lowpc
);
2310 record_debugformat ("DWARF 2");
2312 initialize_cu_func_list (cu
);
2314 /* Process all dies in compilation unit. */
2315 if (die
->child
!= NULL
)
2317 child_die
= die
->child
;
2318 while (child_die
&& child_die
->tag
)
2320 process_die (child_die
, cu
);
2321 child_die
= sibling_die (child_die
);
2325 /* Decode line number information if present. */
2326 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2329 unsigned int line_offset
= DW_UNSND (attr
);
2330 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2333 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
2334 (void *) line_header
);
2335 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
);
2339 /* Decode macro information, if present. Dwarf 2 macro information
2340 refers to information in the line number info statement program
2341 header, so we can only read it if we've read the header
2343 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2344 if (attr
&& line_header
)
2346 unsigned int macro_offset
= DW_UNSND (attr
);
2347 dwarf_decode_macros (line_header
, macro_offset
,
2348 comp_dir
, abfd
, cu
);
2350 do_cleanups (back_to
);
2354 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2355 struct dwarf2_cu
*cu
)
2357 struct function_range
*thisfn
;
2359 thisfn
= (struct function_range
*)
2360 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
2361 thisfn
->name
= name
;
2362 thisfn
->lowpc
= lowpc
;
2363 thisfn
->highpc
= highpc
;
2364 thisfn
->seen_line
= 0;
2365 thisfn
->next
= NULL
;
2367 if (cu
->last_fn
== NULL
)
2368 cu
->first_fn
= thisfn
;
2370 cu
->last_fn
->next
= thisfn
;
2372 cu
->last_fn
= thisfn
;
2376 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2378 struct objfile
*objfile
= cu
->objfile
;
2379 struct context_stack
*new;
2382 struct die_info
*child_die
;
2383 struct attribute
*attr
;
2385 const char *previous_prefix
= processing_current_prefix
;
2386 struct cleanup
*back_to
= NULL
;
2389 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2391 name
= dwarf2_linkage_name (die
, cu
);
2393 /* Ignore functions with missing or empty names and functions with
2394 missing or invalid low and high pc attributes. */
2395 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2398 if (cu
->language
== language_cplus
)
2400 struct die_info
*spec_die
= die_specification (die
, cu
);
2402 /* NOTE: carlton/2004-01-23: We have to be careful in the
2403 presence of DW_AT_specification. For example, with GCC 3.4,
2408 // Definition of N::foo.
2412 then we'll have a tree of DIEs like this:
2414 1: DW_TAG_compile_unit
2415 2: DW_TAG_namespace // N
2416 3: DW_TAG_subprogram // declaration of N::foo
2417 4: DW_TAG_subprogram // definition of N::foo
2418 DW_AT_specification // refers to die #3
2420 Thus, when processing die #4, we have to pretend that we're
2421 in the context of its DW_AT_specification, namely the contex
2424 if (spec_die
!= NULL
)
2426 char *specification_prefix
= determine_prefix (spec_die
, cu
);
2427 processing_current_prefix
= specification_prefix
;
2428 back_to
= make_cleanup (xfree
, specification_prefix
);
2435 /* Record the function range for dwarf_decode_lines. */
2436 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
2438 if (objfile
->ei
.entry_point
>= lowpc
&&
2439 objfile
->ei
.entry_point
< highpc
)
2441 objfile
->ei
.entry_func_lowpc
= lowpc
;
2442 objfile
->ei
.entry_func_highpc
= highpc
;
2445 new = push_context (0, lowpc
);
2446 new->name
= new_symbol (die
, die
->type
, cu
);
2448 /* If there is a location expression for DW_AT_frame_base, record
2450 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
2452 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2453 expression is being recorded directly in the function's symbol
2454 and not in a separate frame-base object. I guess this hack is
2455 to avoid adding some sort of frame-base adjunct/annex to the
2456 function's symbol :-(. The problem with doing this is that it
2457 results in a function symbol with a location expression that
2458 has nothing to do with the location of the function, ouch! The
2459 relationship should be: a function's symbol has-a frame base; a
2460 frame-base has-a location expression. */
2461 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
2463 cu
->list_in_scope
= &local_symbols
;
2465 if (die
->child
!= NULL
)
2467 child_die
= die
->child
;
2468 while (child_die
&& child_die
->tag
)
2470 process_die (child_die
, cu
);
2471 child_die
= sibling_die (child_die
);
2475 new = pop_context ();
2476 /* Make a block for the local symbols within. */
2477 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2478 lowpc
, highpc
, objfile
);
2480 /* In C++, we can have functions nested inside functions (e.g., when
2481 a function declares a class that has methods). This means that
2482 when we finish processing a function scope, we may need to go
2483 back to building a containing block's symbol lists. */
2484 local_symbols
= new->locals
;
2485 param_symbols
= new->params
;
2487 /* If we've finished processing a top-level function, subsequent
2488 symbols go in the file symbol list. */
2489 if (outermost_context_p ())
2490 cu
->list_in_scope
= &file_symbols
;
2492 processing_current_prefix
= previous_prefix
;
2493 if (back_to
!= NULL
)
2494 do_cleanups (back_to
);
2497 /* Process all the DIES contained within a lexical block scope. Start
2498 a new scope, process the dies, and then close the scope. */
2501 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2503 struct objfile
*objfile
= cu
->objfile
;
2504 struct context_stack
*new;
2505 CORE_ADDR lowpc
, highpc
;
2506 struct die_info
*child_die
;
2509 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2511 /* Ignore blocks with missing or invalid low and high pc attributes. */
2512 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2513 as multiple lexical blocks? Handling children in a sane way would
2514 be nasty. Might be easier to properly extend generic blocks to
2516 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2521 push_context (0, lowpc
);
2522 if (die
->child
!= NULL
)
2524 child_die
= die
->child
;
2525 while (child_die
&& child_die
->tag
)
2527 process_die (child_die
, cu
);
2528 child_die
= sibling_die (child_die
);
2531 new = pop_context ();
2533 if (local_symbols
!= NULL
)
2535 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2538 local_symbols
= new->locals
;
2541 /* Get low and high pc attributes from a die. Return 1 if the attributes
2542 are present and valid, otherwise, return 0. Return -1 if the range is
2543 discontinuous, i.e. derived from DW_AT_ranges information. */
2545 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2546 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
2548 struct objfile
*objfile
= cu
->objfile
;
2549 struct comp_unit_head
*cu_header
= &cu
->header
;
2550 struct attribute
*attr
;
2551 bfd
*obfd
= objfile
->obfd
;
2556 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
2559 high
= DW_ADDR (attr
);
2560 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
2562 low
= DW_ADDR (attr
);
2564 /* Found high w/o low attribute. */
2567 /* Found consecutive range of addresses. */
2572 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
2575 unsigned int addr_size
= cu_header
->addr_size
;
2576 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2577 /* Value of the DW_AT_ranges attribute is the offset in the
2578 .debug_ranges section. */
2579 unsigned int offset
= DW_UNSND (attr
);
2580 /* Base address selection entry. */
2588 found_base
= cu_header
->base_known
;
2589 base
= cu_header
->base_address
;
2591 if (offset
>= dwarf2_per_objfile
->ranges_size
)
2593 complaint (&symfile_complaints
,
2594 "Offset %d out of bounds for DW_AT_ranges attribute",
2598 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
2600 /* Read in the largest possible address. */
2601 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
2602 if ((marker
& mask
) == mask
)
2604 /* If we found the largest possible address, then
2605 read the base address. */
2606 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2607 buffer
+= 2 * addr_size
;
2608 offset
+= 2 * addr_size
;
2616 CORE_ADDR range_beginning
, range_end
;
2618 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
2619 buffer
+= addr_size
;
2620 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
2621 buffer
+= addr_size
;
2622 offset
+= 2 * addr_size
;
2624 /* An end of list marker is a pair of zero addresses. */
2625 if (range_beginning
== 0 && range_end
== 0)
2626 /* Found the end of list entry. */
2629 /* Each base address selection entry is a pair of 2 values.
2630 The first is the largest possible address, the second is
2631 the base address. Check for a base address here. */
2632 if ((range_beginning
& mask
) == mask
)
2634 /* If we found the largest possible address, then
2635 read the base address. */
2636 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2643 /* We have no valid base address for the ranges
2645 complaint (&symfile_complaints
,
2646 "Invalid .debug_ranges data (no base address)");
2650 range_beginning
+= base
;
2653 /* FIXME: This is recording everything as a low-high
2654 segment of consecutive addresses. We should have a
2655 data structure for discontiguous block ranges
2659 low
= range_beginning
;
2665 if (range_beginning
< low
)
2666 low
= range_beginning
;
2667 if (range_end
> high
)
2673 /* If the first entry is an end-of-list marker, the range
2674 describes an empty scope, i.e. no instructions. */
2684 /* When using the GNU linker, .gnu.linkonce. sections are used to
2685 eliminate duplicate copies of functions and vtables and such.
2686 The linker will arbitrarily choose one and discard the others.
2687 The AT_*_pc values for such functions refer to local labels in
2688 these sections. If the section from that file was discarded, the
2689 labels are not in the output, so the relocs get a value of 0.
2690 If this is a discarded function, mark the pc bounds as invalid,
2691 so that GDB will ignore it. */
2692 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
2700 /* Get the low and high pc's represented by the scope DIE, and store
2701 them in *LOWPC and *HIGHPC. If the correct values can't be
2702 determined, set *LOWPC to -1 and *HIGHPC to 0. */
2705 get_scope_pc_bounds (struct die_info
*die
,
2706 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2707 struct dwarf2_cu
*cu
)
2709 CORE_ADDR best_low
= (CORE_ADDR
) -1;
2710 CORE_ADDR best_high
= (CORE_ADDR
) 0;
2711 CORE_ADDR current_low
, current_high
;
2713 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
2715 best_low
= current_low
;
2716 best_high
= current_high
;
2720 struct die_info
*child
= die
->child
;
2722 while (child
&& child
->tag
)
2724 switch (child
->tag
) {
2725 case DW_TAG_subprogram
:
2726 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
2728 best_low
= min (best_low
, current_low
);
2729 best_high
= max (best_high
, current_high
);
2732 case DW_TAG_namespace
:
2733 /* FIXME: carlton/2004-01-16: Should we do this for
2734 DW_TAG_class_type/DW_TAG_structure_type, too? I think
2735 that current GCC's always emit the DIEs corresponding
2736 to definitions of methods of classes as children of a
2737 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
2738 the DIEs giving the declarations, which could be
2739 anywhere). But I don't see any reason why the
2740 standards says that they have to be there. */
2741 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
2743 if (current_low
!= ((CORE_ADDR
) -1))
2745 best_low
= min (best_low
, current_low
);
2746 best_high
= max (best_high
, current_high
);
2754 child
= sibling_die (child
);
2759 *highpc
= best_high
;
2762 /* Add an aggregate field to the field list. */
2765 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2766 struct dwarf2_cu
*cu
)
2768 struct objfile
*objfile
= cu
->objfile
;
2769 struct nextfield
*new_field
;
2770 struct attribute
*attr
;
2772 char *fieldname
= "";
2774 /* Allocate a new field list entry and link it in. */
2775 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2776 make_cleanup (xfree
, new_field
);
2777 memset (new_field
, 0, sizeof (struct nextfield
));
2778 new_field
->next
= fip
->fields
;
2779 fip
->fields
= new_field
;
2782 /* Handle accessibility and virtuality of field.
2783 The default accessibility for members is public, the default
2784 accessibility for inheritance is private. */
2785 if (die
->tag
!= DW_TAG_inheritance
)
2786 new_field
->accessibility
= DW_ACCESS_public
;
2788 new_field
->accessibility
= DW_ACCESS_private
;
2789 new_field
->virtuality
= DW_VIRTUALITY_none
;
2791 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
2793 new_field
->accessibility
= DW_UNSND (attr
);
2794 if (new_field
->accessibility
!= DW_ACCESS_public
)
2795 fip
->non_public_fields
= 1;
2796 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
2798 new_field
->virtuality
= DW_UNSND (attr
);
2800 fp
= &new_field
->field
;
2802 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
2804 /* Data member other than a C++ static data member. */
2806 /* Get type of field. */
2807 fp
->type
= die_type (die
, cu
);
2809 FIELD_STATIC_KIND (*fp
) = 0;
2811 /* Get bit size of field (zero if none). */
2812 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
2815 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2819 FIELD_BITSIZE (*fp
) = 0;
2822 /* Get bit offset of field. */
2823 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
2826 FIELD_BITPOS (*fp
) =
2827 decode_locdesc (DW_BLOCK (attr
), cu
) * bits_per_byte
;
2830 FIELD_BITPOS (*fp
) = 0;
2831 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
2834 if (BITS_BIG_ENDIAN
)
2836 /* For big endian bits, the DW_AT_bit_offset gives the
2837 additional bit offset from the MSB of the containing
2838 anonymous object to the MSB of the field. We don't
2839 have to do anything special since we don't need to
2840 know the size of the anonymous object. */
2841 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2845 /* For little endian bits, compute the bit offset to the
2846 MSB of the anonymous object, subtract off the number of
2847 bits from the MSB of the field to the MSB of the
2848 object, and then subtract off the number of bits of
2849 the field itself. The result is the bit offset of
2850 the LSB of the field. */
2852 int bit_offset
= DW_UNSND (attr
);
2854 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
2857 /* The size of the anonymous object containing
2858 the bit field is explicit, so use the
2859 indicated size (in bytes). */
2860 anonymous_size
= DW_UNSND (attr
);
2864 /* The size of the anonymous object containing
2865 the bit field must be inferred from the type
2866 attribute of the data member containing the
2868 anonymous_size
= TYPE_LENGTH (fp
->type
);
2870 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2871 - bit_offset
- FIELD_BITSIZE (*fp
);
2875 /* Get name of field. */
2876 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2877 if (attr
&& DW_STRING (attr
))
2878 fieldname
= DW_STRING (attr
);
2880 /* The name is already allocated along with this objfile, so we don't
2881 need to duplicate it for the type. */
2882 fp
->name
= fieldname
;
2884 /* Change accessibility for artificial fields (e.g. virtual table
2885 pointer or virtual base class pointer) to private. */
2886 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
2888 new_field
->accessibility
= DW_ACCESS_private
;
2889 fip
->non_public_fields
= 1;
2892 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
2894 /* C++ static member. */
2896 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2897 is a declaration, but all versions of G++ as of this writing
2898 (so through at least 3.2.1) incorrectly generate
2899 DW_TAG_variable tags. */
2903 /* Get name of field. */
2904 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2905 if (attr
&& DW_STRING (attr
))
2906 fieldname
= DW_STRING (attr
);
2910 /* Get physical name. */
2911 physname
= dwarf2_linkage_name (die
, cu
);
2913 /* The name is already allocated along with this objfile, so we don't
2914 need to duplicate it for the type. */
2915 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
2916 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2917 FIELD_NAME (*fp
) = fieldname
;
2919 else if (die
->tag
== DW_TAG_inheritance
)
2921 /* C++ base class field. */
2922 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
2924 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
2926 FIELD_BITSIZE (*fp
) = 0;
2927 FIELD_STATIC_KIND (*fp
) = 0;
2928 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2929 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2930 fip
->nbaseclasses
++;
2934 /* Create the vector of fields, and attach it to the type. */
2937 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2938 struct dwarf2_cu
*cu
)
2940 int nfields
= fip
->nfields
;
2942 /* Record the field count, allocate space for the array of fields,
2943 and create blank accessibility bitfields if necessary. */
2944 TYPE_NFIELDS (type
) = nfields
;
2945 TYPE_FIELDS (type
) = (struct field
*)
2946 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2947 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2949 if (fip
->non_public_fields
)
2951 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2953 TYPE_FIELD_PRIVATE_BITS (type
) =
2954 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2955 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2957 TYPE_FIELD_PROTECTED_BITS (type
) =
2958 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2959 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2961 TYPE_FIELD_IGNORE_BITS (type
) =
2962 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2963 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2966 /* If the type has baseclasses, allocate and clear a bit vector for
2967 TYPE_FIELD_VIRTUAL_BITS. */
2968 if (fip
->nbaseclasses
)
2970 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2973 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2974 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2975 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2976 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2977 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2980 /* Copy the saved-up fields into the field vector. Start from the head
2981 of the list, adding to the tail of the field array, so that they end
2982 up in the same order in the array in which they were added to the list. */
2983 while (nfields
-- > 0)
2985 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2986 switch (fip
->fields
->accessibility
)
2988 case DW_ACCESS_private
:
2989 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2992 case DW_ACCESS_protected
:
2993 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2996 case DW_ACCESS_public
:
3000 /* Unknown accessibility. Complain and treat it as public. */
3002 complaint (&symfile_complaints
, "unsupported accessibility %d",
3003 fip
->fields
->accessibility
);
3007 if (nfields
< fip
->nbaseclasses
)
3009 switch (fip
->fields
->virtuality
)
3011 case DW_VIRTUALITY_virtual
:
3012 case DW_VIRTUALITY_pure_virtual
:
3013 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3017 fip
->fields
= fip
->fields
->next
;
3021 /* Add a member function to the proper fieldlist. */
3024 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3025 struct type
*type
, struct dwarf2_cu
*cu
)
3027 struct objfile
*objfile
= cu
->objfile
;
3028 struct attribute
*attr
;
3029 struct fnfieldlist
*flp
;
3031 struct fn_field
*fnp
;
3034 struct nextfnfield
*new_fnfield
;
3036 /* Get name of member function. */
3037 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3038 if (attr
&& DW_STRING (attr
))
3039 fieldname
= DW_STRING (attr
);
3043 /* Get the mangled name. */
3044 physname
= dwarf2_linkage_name (die
, cu
);
3046 /* Look up member function name in fieldlist. */
3047 for (i
= 0; i
< fip
->nfnfields
; i
++)
3049 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3053 /* Create new list element if necessary. */
3054 if (i
< fip
->nfnfields
)
3055 flp
= &fip
->fnfieldlists
[i
];
3058 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3060 fip
->fnfieldlists
= (struct fnfieldlist
*)
3061 xrealloc (fip
->fnfieldlists
,
3062 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3063 * sizeof (struct fnfieldlist
));
3064 if (fip
->nfnfields
== 0)
3065 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3067 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3068 flp
->name
= fieldname
;
3074 /* Create a new member function field and chain it to the field list
3076 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3077 make_cleanup (xfree
, new_fnfield
);
3078 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3079 new_fnfield
->next
= flp
->head
;
3080 flp
->head
= new_fnfield
;
3083 /* Fill in the member function field info. */
3084 fnp
= &new_fnfield
->fnfield
;
3085 /* The name is already allocated along with this objfile, so we don't
3086 need to duplicate it for the type. */
3087 fnp
->physname
= physname
? physname
: "";
3088 fnp
->type
= alloc_type (objfile
);
3089 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
3091 int nparams
= TYPE_NFIELDS (die
->type
);
3093 /* TYPE is the domain of this method, and DIE->TYPE is the type
3094 of the method itself (TYPE_CODE_METHOD). */
3095 smash_to_method_type (fnp
->type
, type
,
3096 TYPE_TARGET_TYPE (die
->type
),
3097 TYPE_FIELDS (die
->type
),
3098 TYPE_NFIELDS (die
->type
),
3099 TYPE_VARARGS (die
->type
));
3101 /* Handle static member functions.
3102 Dwarf2 has no clean way to discern C++ static and non-static
3103 member functions. G++ helps GDB by marking the first
3104 parameter for non-static member functions (which is the
3105 this pointer) as artificial. We obtain this information
3106 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3107 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
3108 fnp
->voffset
= VOFFSET_STATIC
;
3111 complaint (&symfile_complaints
, "member function type missing for '%s'",
3114 /* Get fcontext from DW_AT_containing_type if present. */
3115 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3116 fnp
->fcontext
= die_containing_type (die
, cu
);
3118 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3119 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3121 /* Get accessibility. */
3122 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3125 switch (DW_UNSND (attr
))
3127 case DW_ACCESS_private
:
3128 fnp
->is_private
= 1;
3130 case DW_ACCESS_protected
:
3131 fnp
->is_protected
= 1;
3136 /* Check for artificial methods. */
3137 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3138 if (attr
&& DW_UNSND (attr
) != 0)
3139 fnp
->is_artificial
= 1;
3141 /* Get index in virtual function table if it is a virtual member function. */
3142 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3145 /* Support the .debug_loc offsets */
3146 if (attr_form_is_block (attr
))
3148 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3150 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3152 dwarf2_complex_location_expr_complaint ();
3156 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3162 /* Create the vector of member function fields, and attach it to the type. */
3165 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3166 struct dwarf2_cu
*cu
)
3168 struct fnfieldlist
*flp
;
3169 int total_length
= 0;
3172 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3173 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3174 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3176 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3178 struct nextfnfield
*nfp
= flp
->head
;
3179 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3182 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3183 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3184 fn_flp
->fn_fields
= (struct fn_field
*)
3185 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3186 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3187 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3189 total_length
+= flp
->length
;
3192 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3193 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3196 /* Called when we find the DIE that starts a structure or union scope
3197 (definition) to process all dies that define the members of the
3200 NOTE: we need to call struct_type regardless of whether or not the
3201 DIE has an at_name attribute, since it might be an anonymous
3202 structure or union. This gets the type entered into our set of
3205 However, if the structure is incomplete (an opaque struct/union)
3206 then suppress creating a symbol table entry for it since gdb only
3207 wants to find the one with the complete definition. Note that if
3208 it is complete, we just call new_symbol, which does it's own
3209 checking about whether the struct/union is anonymous or not (and
3210 suppresses creating a symbol table entry itself). */
3213 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3215 struct objfile
*objfile
= cu
->objfile
;
3217 struct attribute
*attr
;
3218 const char *previous_prefix
= processing_current_prefix
;
3219 struct cleanup
*back_to
= NULL
;
3224 type
= alloc_type (objfile
);
3226 INIT_CPLUS_SPECIFIC (type
);
3227 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3228 if (attr
&& DW_STRING (attr
))
3230 if (cu
->language
== language_cplus
)
3232 char *new_prefix
= determine_class_name (die
, cu
);
3233 TYPE_TAG_NAME (type
) = obsavestring (new_prefix
,
3234 strlen (new_prefix
),
3235 &objfile
->objfile_obstack
);
3236 back_to
= make_cleanup (xfree
, new_prefix
);
3237 processing_current_prefix
= new_prefix
;
3241 /* The name is already allocated along with this objfile, so
3242 we don't need to duplicate it for the type. */
3243 TYPE_TAG_NAME (type
) = DW_STRING (attr
);
3247 if (die
->tag
== DW_TAG_structure_type
)
3249 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
3251 else if (die
->tag
== DW_TAG_union_type
)
3253 TYPE_CODE (type
) = TYPE_CODE_UNION
;
3257 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
3259 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
3262 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3265 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3269 TYPE_LENGTH (type
) = 0;
3272 if (die_is_declaration (die
, cu
))
3273 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
3275 /* We need to add the type field to the die immediately so we don't
3276 infinitely recurse when dealing with pointers to the structure
3277 type within the structure itself. */
3280 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3282 struct field_info fi
;
3283 struct die_info
*child_die
;
3284 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
3286 memset (&fi
, 0, sizeof (struct field_info
));
3288 child_die
= die
->child
;
3290 while (child_die
&& child_die
->tag
)
3292 if (child_die
->tag
== DW_TAG_member
3293 || child_die
->tag
== DW_TAG_variable
)
3295 /* NOTE: carlton/2002-11-05: A C++ static data member
3296 should be a DW_TAG_member that is a declaration, but
3297 all versions of G++ as of this writing (so through at
3298 least 3.2.1) incorrectly generate DW_TAG_variable
3299 tags for them instead. */
3300 dwarf2_add_field (&fi
, child_die
, cu
);
3302 else if (child_die
->tag
== DW_TAG_subprogram
)
3304 /* C++ member function. */
3305 read_type_die (child_die
, cu
);
3306 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
3308 else if (child_die
->tag
== DW_TAG_inheritance
)
3310 /* C++ base class field. */
3311 dwarf2_add_field (&fi
, child_die
, cu
);
3313 child_die
= sibling_die (child_die
);
3316 /* Attach fields and member functions to the type. */
3318 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
3321 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
3323 /* Get the type which refers to the base class (possibly this
3324 class itself) which contains the vtable pointer for the current
3325 class from the DW_AT_containing_type attribute. */
3327 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3329 struct type
*t
= die_containing_type (die
, cu
);
3331 TYPE_VPTR_BASETYPE (type
) = t
;
3334 static const char vptr_name
[] =
3335 {'_', 'v', 'p', 't', 'r', '\0'};
3338 /* Our own class provides vtbl ptr. */
3339 for (i
= TYPE_NFIELDS (t
) - 1;
3340 i
>= TYPE_N_BASECLASSES (t
);
3343 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
3345 if ((strncmp (fieldname
, vptr_name
,
3346 strlen (vptr_name
) - 1)
3348 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
3350 TYPE_VPTR_FIELDNO (type
) = i
;
3355 /* Complain if virtual function table field not found. */
3356 if (i
< TYPE_N_BASECLASSES (t
))
3357 complaint (&symfile_complaints
,
3358 "virtual function table pointer not found when defining class '%s'",
3359 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
3364 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3369 do_cleanups (back_to
);
3372 processing_current_prefix
= previous_prefix
;
3373 if (back_to
!= NULL
)
3374 do_cleanups (back_to
);
3378 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3380 struct objfile
*objfile
= cu
->objfile
;
3381 const char *previous_prefix
= processing_current_prefix
;
3382 struct die_info
*child_die
= die
->child
;
3384 if (TYPE_TAG_NAME (die
->type
) != NULL
)
3385 processing_current_prefix
= TYPE_TAG_NAME (die
->type
);
3387 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
3388 snapshots) has been known to create a die giving a declaration
3389 for a class that has, as a child, a die giving a definition for a
3390 nested class. So we have to process our children even if the
3391 current die is a declaration. Normally, of course, a declaration
3392 won't have any children at all. */
3394 while (child_die
!= NULL
&& child_die
->tag
)
3396 if (child_die
->tag
== DW_TAG_member
3397 || child_die
->tag
== DW_TAG_variable
3398 || child_die
->tag
== DW_TAG_inheritance
)
3403 process_die (child_die
, cu
);
3405 child_die
= sibling_die (child_die
);
3408 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3409 new_symbol (die
, die
->type
, cu
);
3411 processing_current_prefix
= previous_prefix
;
3414 /* Given a DW_AT_enumeration_type die, set its type. We do not
3415 complete the type's fields yet, or create any symbols. */
3418 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3420 struct objfile
*objfile
= cu
->objfile
;
3422 struct attribute
*attr
;
3427 type
= alloc_type (objfile
);
3429 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3430 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3431 if (attr
&& DW_STRING (attr
))
3433 char *name
= DW_STRING (attr
);
3435 if (processing_has_namespace_info
)
3437 TYPE_TAG_NAME (type
) = obconcat (&objfile
->objfile_obstack
,
3438 processing_current_prefix
,
3439 processing_current_prefix
[0] == '\0'
3445 /* The name is already allocated along with this objfile, so
3446 we don't need to duplicate it for the type. */
3447 TYPE_TAG_NAME (type
) = name
;
3451 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3454 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3458 TYPE_LENGTH (type
) = 0;
3464 /* Determine the name of the type represented by DIE, which should be
3465 a named C++ compound type. Return the name in question; the caller
3466 is responsible for xfree()'ing it. */
3469 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
3471 struct cleanup
*back_to
= NULL
;
3472 struct die_info
*spec_die
= die_specification (die
, cu
);
3473 char *new_prefix
= NULL
;
3475 /* If this is the definition of a class that is declared by another
3476 die, then processing_current_prefix may not be accurate; see
3477 read_func_scope for a similar example. */
3478 if (spec_die
!= NULL
)
3480 char *specification_prefix
= determine_prefix (spec_die
, cu
);
3481 processing_current_prefix
= specification_prefix
;
3482 back_to
= make_cleanup (xfree
, specification_prefix
);
3485 /* If we don't have namespace debug info, guess the name by trying
3486 to demangle the names of members, just like we did in
3487 guess_structure_name. */
3488 if (!processing_has_namespace_info
)
3490 struct die_info
*child
;
3492 for (child
= die
->child
;
3493 child
!= NULL
&& child
->tag
!= 0;
3494 child
= sibling_die (child
))
3496 if (child
->tag
== DW_TAG_subprogram
)
3498 new_prefix
= class_name_from_physname (dwarf2_linkage_name
3501 if (new_prefix
!= NULL
)
3507 if (new_prefix
== NULL
)
3509 const char *name
= dwarf2_name (die
, cu
);
3510 new_prefix
= typename_concat (processing_current_prefix
,
3511 name
? name
: "<<anonymous>>");
3514 if (back_to
!= NULL
)
3515 do_cleanups (back_to
);
3520 /* Given a pointer to a die which begins an enumeration, process all
3521 the dies that define the members of the enumeration, and create the
3522 symbol for the enumeration type.
3524 NOTE: We reverse the order of the element list. */
3527 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3529 struct objfile
*objfile
= cu
->objfile
;
3530 struct die_info
*child_die
;
3531 struct field
*fields
;
3532 struct attribute
*attr
;
3535 int unsigned_enum
= 1;
3539 if (die
->child
!= NULL
)
3541 child_die
= die
->child
;
3542 while (child_die
&& child_die
->tag
)
3544 if (child_die
->tag
!= DW_TAG_enumerator
)
3546 process_die (child_die
, cu
);
3550 attr
= dwarf2_attr (child_die
, DW_AT_name
, cu
);
3553 sym
= new_symbol (child_die
, die
->type
, cu
);
3554 if (SYMBOL_VALUE (sym
) < 0)
3557 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3559 fields
= (struct field
*)
3561 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
3562 * sizeof (struct field
));
3565 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
3566 FIELD_TYPE (fields
[num_fields
]) = NULL
;
3567 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
3568 FIELD_BITSIZE (fields
[num_fields
]) = 0;
3569 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
3575 child_die
= sibling_die (child_die
);
3580 TYPE_NFIELDS (die
->type
) = num_fields
;
3581 TYPE_FIELDS (die
->type
) = (struct field
*)
3582 TYPE_ALLOC (die
->type
, sizeof (struct field
) * num_fields
);
3583 memcpy (TYPE_FIELDS (die
->type
), fields
,
3584 sizeof (struct field
) * num_fields
);
3588 TYPE_FLAGS (die
->type
) |= TYPE_FLAG_UNSIGNED
;
3591 new_symbol (die
, die
->type
, cu
);
3594 /* Extract all information from a DW_TAG_array_type DIE and put it in
3595 the DIE's type field. For now, this only handles one dimensional
3599 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3601 struct objfile
*objfile
= cu
->objfile
;
3602 struct die_info
*child_die
;
3603 struct type
*type
= NULL
;
3604 struct type
*element_type
, *range_type
, *index_type
;
3605 struct type
**range_types
= NULL
;
3606 struct attribute
*attr
;
3608 struct cleanup
*back_to
;
3610 /* Return if we've already decoded this type. */
3616 element_type
= die_type (die
, cu
);
3618 /* Irix 6.2 native cc creates array types without children for
3619 arrays with unspecified length. */
3620 if (die
->child
== NULL
)
3622 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
3623 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3624 die
->type
= create_array_type (NULL
, element_type
, range_type
);
3628 back_to
= make_cleanup (null_cleanup
, NULL
);
3629 child_die
= die
->child
;
3630 while (child_die
&& child_die
->tag
)
3632 if (child_die
->tag
== DW_TAG_subrange_type
)
3634 read_subrange_type (child_die
, cu
);
3636 if (child_die
->type
!= NULL
)
3638 /* The range type was succesfully read. Save it for
3639 the array type creation. */
3640 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3642 range_types
= (struct type
**)
3643 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3644 * sizeof (struct type
*));
3646 make_cleanup (free_current_contents
, &range_types
);
3648 range_types
[ndim
++] = child_die
->type
;
3651 child_die
= sibling_die (child_die
);
3654 /* Dwarf2 dimensions are output from left to right, create the
3655 necessary array types in backwards order. */
3656 type
= element_type
;
3658 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3660 /* Understand Dwarf2 support for vector types (like they occur on
3661 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3662 array type. This is not part of the Dwarf2/3 standard yet, but a
3663 custom vendor extension. The main difference between a regular
3664 array and the vector variant is that vectors are passed by value
3666 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
3668 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3670 do_cleanups (back_to
);
3672 /* Install the type in the die. */
3676 /* First cut: install each common block member as a global variable. */
3679 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
3681 struct die_info
*child_die
;
3682 struct attribute
*attr
;
3684 CORE_ADDR base
= (CORE_ADDR
) 0;
3686 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
3689 /* Support the .debug_loc offsets */
3690 if (attr_form_is_block (attr
))
3692 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
3694 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3696 dwarf2_complex_location_expr_complaint ();
3700 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3701 "common block member");
3704 if (die
->child
!= NULL
)
3706 child_die
= die
->child
;
3707 while (child_die
&& child_die
->tag
)
3709 sym
= new_symbol (child_die
, NULL
, cu
);
3710 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
3713 SYMBOL_VALUE_ADDRESS (sym
) =
3714 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
3715 add_symbol_to_list (sym
, &global_symbols
);
3717 child_die
= sibling_die (child_die
);
3722 /* Read a C++ namespace. */
3725 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3727 struct objfile
*objfile
= cu
->objfile
;
3728 const char *previous_prefix
= processing_current_prefix
;
3731 struct die_info
*current_die
;
3733 name
= namespace_name (die
, &is_anonymous
, cu
);
3735 /* Now build the name of the current namespace. */
3737 if (previous_prefix
[0] == '\0')
3739 processing_current_prefix
= name
;
3743 /* We need temp_name around because processing_current_prefix
3744 is a const char *. */
3745 char *temp_name
= alloca (strlen (previous_prefix
)
3746 + 2 + strlen(name
) + 1);
3747 strcpy (temp_name
, previous_prefix
);
3748 strcat (temp_name
, "::");
3749 strcat (temp_name
, name
);
3751 processing_current_prefix
= temp_name
;
3754 /* Add a symbol associated to this if we haven't seen the namespace
3755 before. Also, add a using directive if it's an anonymous
3758 if (dwarf2_extension (die
, cu
) == NULL
)
3762 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3763 this cast will hopefully become unnecessary. */
3764 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
3765 (char *) processing_current_prefix
,
3767 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
3769 new_symbol (die
, type
, cu
);
3773 cp_add_using_directive (processing_current_prefix
,
3774 strlen (previous_prefix
),
3775 strlen (processing_current_prefix
));
3778 if (die
->child
!= NULL
)
3780 struct die_info
*child_die
= die
->child
;
3782 while (child_die
&& child_die
->tag
)
3784 process_die (child_die
, cu
);
3785 child_die
= sibling_die (child_die
);
3789 processing_current_prefix
= previous_prefix
;
3792 /* Return the name of the namespace represented by DIE. Set
3793 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
3797 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
3799 struct die_info
*current_die
;
3800 const char *name
= NULL
;
3802 /* Loop through the extensions until we find a name. */
3804 for (current_die
= die
;
3805 current_die
!= NULL
;
3806 current_die
= dwarf2_extension (die
, cu
))
3808 name
= dwarf2_name (current_die
, cu
);
3813 /* Is it an anonymous namespace? */
3815 *is_anonymous
= (name
== NULL
);
3817 name
= "(anonymous namespace)";
3822 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3823 the user defined type vector. */
3826 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3828 struct comp_unit_head
*cu_header
= &cu
->header
;
3830 struct attribute
*attr_byte_size
;
3831 struct attribute
*attr_address_class
;
3832 int byte_size
, addr_class
;
3839 type
= lookup_pointer_type (die_type (die
, cu
));
3841 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3843 byte_size
= DW_UNSND (attr_byte_size
);
3845 byte_size
= cu_header
->addr_size
;
3847 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
3848 if (attr_address_class
)
3849 addr_class
= DW_UNSND (attr_address_class
);
3851 addr_class
= DW_ADDR_none
;
3853 /* If the pointer size or address class is different than the
3854 default, create a type variant marked as such and set the
3855 length accordingly. */
3856 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3858 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3862 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3863 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3864 type
= make_type_with_address_space (type
, type_flags
);
3866 else if (TYPE_LENGTH (type
) != byte_size
)
3868 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3871 /* Should we also complain about unhandled address classes? */
3875 TYPE_LENGTH (type
) = byte_size
;
3879 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3880 the user defined type vector. */
3883 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3885 struct objfile
*objfile
= cu
->objfile
;
3887 struct type
*to_type
;
3888 struct type
*domain
;
3895 type
= alloc_type (objfile
);
3896 to_type
= die_type (die
, cu
);
3897 domain
= die_containing_type (die
, cu
);
3898 smash_to_member_type (type
, domain
, to_type
);
3903 /* Extract all information from a DW_TAG_reference_type DIE and add to
3904 the user defined type vector. */
3907 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3909 struct comp_unit_head
*cu_header
= &cu
->header
;
3911 struct attribute
*attr
;
3918 type
= lookup_reference_type (die_type (die
, cu
));
3919 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3922 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3926 TYPE_LENGTH (type
) = cu_header
->addr_size
;
3932 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3934 struct type
*base_type
;
3941 base_type
= die_type (die
, cu
);
3942 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
3946 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3948 struct type
*base_type
;
3955 base_type
= die_type (die
, cu
);
3956 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
3959 /* Extract all information from a DW_TAG_string_type DIE and add to
3960 the user defined type vector. It isn't really a user defined type,
3961 but it behaves like one, with other DIE's using an AT_user_def_type
3962 attribute to reference it. */
3965 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3967 struct objfile
*objfile
= cu
->objfile
;
3968 struct type
*type
, *range_type
, *index_type
, *char_type
;
3969 struct attribute
*attr
;
3970 unsigned int length
;
3977 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
3980 length
= DW_UNSND (attr
);
3984 /* check for the DW_AT_byte_size attribute */
3985 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3988 length
= DW_UNSND (attr
);
3995 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
3996 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3997 if (cu
->language
== language_fortran
)
3999 /* Need to create a unique string type for bounds
4001 type
= create_string_type (0, range_type
);
4005 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
, cu
);
4006 type
= create_string_type (char_type
, range_type
);
4011 /* Handle DIES due to C code like:
4015 int (*funcp)(int a, long l);
4019 ('funcp' generates a DW_TAG_subroutine_type DIE)
4023 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4025 struct type
*type
; /* Type that this function returns */
4026 struct type
*ftype
; /* Function that returns above type */
4027 struct attribute
*attr
;
4029 /* Decode the type that this subroutine returns */
4034 type
= die_type (die
, cu
);
4035 ftype
= lookup_function_type (type
);
4037 /* All functions in C++ have prototypes. */
4038 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4039 if ((attr
&& (DW_UNSND (attr
) != 0))
4040 || cu
->language
== language_cplus
)
4041 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
4043 if (die
->child
!= NULL
)
4045 struct die_info
*child_die
;
4049 /* Count the number of parameters.
4050 FIXME: GDB currently ignores vararg functions, but knows about
4051 vararg member functions. */
4052 child_die
= die
->child
;
4053 while (child_die
&& child_die
->tag
)
4055 if (child_die
->tag
== DW_TAG_formal_parameter
)
4057 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4058 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
4059 child_die
= sibling_die (child_die
);
4062 /* Allocate storage for parameters and fill them in. */
4063 TYPE_NFIELDS (ftype
) = nparams
;
4064 TYPE_FIELDS (ftype
) = (struct field
*)
4065 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
4067 child_die
= die
->child
;
4068 while (child_die
&& child_die
->tag
)
4070 if (child_die
->tag
== DW_TAG_formal_parameter
)
4072 /* Dwarf2 has no clean way to discern C++ static and non-static
4073 member functions. G++ helps GDB by marking the first
4074 parameter for non-static member functions (which is the
4075 this pointer) as artificial. We pass this information
4076 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4077 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4079 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4081 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4082 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4085 child_die
= sibling_die (child_die
);
4093 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4095 struct objfile
*objfile
= cu
->objfile
;
4096 struct attribute
*attr
;
4101 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4102 if (attr
&& DW_STRING (attr
))
4104 name
= DW_STRING (attr
);
4106 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
4107 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
4111 /* Find a representation of a given base type and install
4112 it in the TYPE field of the die. */
4115 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4117 struct objfile
*objfile
= cu
->objfile
;
4119 struct attribute
*attr
;
4120 int encoding
= 0, size
= 0;
4122 /* If we've already decoded this die, this is a no-op. */
4128 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4131 encoding
= DW_UNSND (attr
);
4133 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4136 size
= DW_UNSND (attr
);
4138 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4139 if (attr
&& DW_STRING (attr
))
4141 enum type_code code
= TYPE_CODE_INT
;
4146 case DW_ATE_address
:
4147 /* Turn DW_ATE_address into a void * pointer. */
4148 code
= TYPE_CODE_PTR
;
4149 type_flags
|= TYPE_FLAG_UNSIGNED
;
4151 case DW_ATE_boolean
:
4152 code
= TYPE_CODE_BOOL
;
4153 type_flags
|= TYPE_FLAG_UNSIGNED
;
4155 case DW_ATE_complex_float
:
4156 code
= TYPE_CODE_COMPLEX
;
4159 code
= TYPE_CODE_FLT
;
4162 case DW_ATE_signed_char
:
4164 case DW_ATE_unsigned
:
4165 case DW_ATE_unsigned_char
:
4166 type_flags
|= TYPE_FLAG_UNSIGNED
;
4169 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
4170 dwarf_type_encoding_name (encoding
));
4173 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
4174 if (encoding
== DW_ATE_address
)
4175 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
,
4177 else if (encoding
== DW_ATE_complex_float
)
4180 TYPE_TARGET_TYPE (type
)
4181 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
, cu
);
4182 else if (size
== 16)
4183 TYPE_TARGET_TYPE (type
)
4184 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
4186 TYPE_TARGET_TYPE (type
)
4187 = dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
4192 type
= dwarf_base_type (encoding
, size
, cu
);
4197 /* Read the given DW_AT_subrange DIE. */
4200 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4202 struct type
*base_type
;
4203 struct type
*range_type
;
4204 struct attribute
*attr
;
4208 /* If we have already decoded this die, then nothing more to do. */
4212 base_type
= die_type (die
, cu
);
4213 if (base_type
== NULL
)
4215 complaint (&symfile_complaints
,
4216 "DW_AT_type missing from DW_TAG_subrange_type");
4220 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
4221 base_type
= alloc_type (NULL
);
4223 if (cu
->language
== language_fortran
)
4225 /* FORTRAN implies a lower bound of 1, if not given. */
4229 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
4231 low
= dwarf2_get_attr_constant_value (attr
, 0);
4233 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
4236 if (attr
->form
== DW_FORM_block1
)
4238 /* GCC encodes arrays with unspecified or dynamic length
4239 with a DW_FORM_block1 attribute.
4240 FIXME: GDB does not yet know how to handle dynamic
4241 arrays properly, treat them as arrays with unspecified
4244 FIXME: jimb/2003-09-22: GDB does not really know
4245 how to handle arrays of unspecified length
4246 either; we just represent them as zero-length
4247 arrays. Choose an appropriate upper bound given
4248 the lower bound we've computed above. */
4252 high
= dwarf2_get_attr_constant_value (attr
, 1);
4255 range_type
= create_range_type (NULL
, base_type
, low
, high
);
4257 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4258 if (attr
&& DW_STRING (attr
))
4259 TYPE_NAME (range_type
) = DW_STRING (attr
);
4261 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4263 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
4265 die
->type
= range_type
;
4269 /* Read a whole compilation unit into a linked list of dies. */
4271 static struct die_info
*
4272 read_comp_unit (char *info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
4274 /* Reset die reference table; we are
4275 building new ones now. */
4276 dwarf2_empty_hash_tables ();
4278 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
4281 /* Read a single die and all its descendents. Set the die's sibling
4282 field to NULL; set other fields in the die correctly, and set all
4283 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4284 location of the info_ptr after reading all of those dies. PARENT
4285 is the parent of the die in question. */
4287 static struct die_info
*
4288 read_die_and_children (char *info_ptr
, bfd
*abfd
,
4289 struct dwarf2_cu
*cu
,
4290 char **new_info_ptr
,
4291 struct die_info
*parent
)
4293 struct die_info
*die
;
4297 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
4298 store_in_ref_table (die
->offset
, die
);
4302 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
4308 *new_info_ptr
= cur_ptr
;
4311 die
->sibling
= NULL
;
4312 die
->parent
= parent
;
4316 /* Read a die, all of its descendents, and all of its siblings; set
4317 all of the fields of all of the dies correctly. Arguments are as
4318 in read_die_and_children. */
4320 static struct die_info
*
4321 read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
4322 struct dwarf2_cu
*cu
,
4323 char **new_info_ptr
,
4324 struct die_info
*parent
)
4326 struct die_info
*first_die
, *last_sibling
;
4330 first_die
= last_sibling
= NULL
;
4334 struct die_info
*die
4335 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
4343 last_sibling
->sibling
= die
;
4348 *new_info_ptr
= cur_ptr
;
4358 /* Free a linked list of dies. */
4361 free_die_list (struct die_info
*dies
)
4363 struct die_info
*die
, *next
;
4368 if (die
->child
!= NULL
)
4369 free_die_list (die
->child
);
4370 next
= die
->sibling
;
4378 do_free_die_list_cleanup (void *dies
)
4380 free_die_list (dies
);
4383 static struct cleanup
*
4384 make_cleanup_free_die_list (struct die_info
*dies
)
4386 return make_cleanup (do_free_die_list_cleanup
, dies
);
4390 /* Read the contents of the section at OFFSET and of size SIZE from the
4391 object file specified by OBJFILE into the objfile_obstack and return it. */
4394 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
4396 bfd
*abfd
= objfile
->obfd
;
4398 bfd_size_type size
= bfd_get_section_size_before_reloc (sectp
);
4403 buf
= (char *) obstack_alloc (&objfile
->objfile_obstack
, size
);
4405 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
4409 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
4410 || bfd_bread (buf
, size
, abfd
) != size
)
4411 error ("Dwarf Error: Can't read DWARF data from '%s'",
4412 bfd_get_filename (abfd
));
4417 /* In DWARF version 2, the description of the debugging information is
4418 stored in a separate .debug_abbrev section. Before we read any
4419 dies from a section we read in all abbreviations and install them
4420 in a hash table. This function also sets flags in CU describing
4421 the data found in the abbrev table. */
4424 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
4426 struct comp_unit_head
*cu_header
= &cu
->header
;
4428 struct abbrev_info
*cur_abbrev
;
4429 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
4430 unsigned int abbrev_form
, hash_number
;
4431 struct attr_abbrev
*cur_attrs
;
4432 unsigned int allocated_attrs
;
4434 /* Initialize dwarf2 abbrevs */
4435 obstack_init (&cu
->abbrev_obstack
);
4436 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
4438 * sizeof (struct abbrev_info
*)));
4439 memset (cu
->dwarf2_abbrevs
, 0,
4440 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
4442 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
4443 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4444 abbrev_ptr
+= bytes_read
;
4446 allocated_attrs
= ATTR_ALLOC_CHUNK
;
4447 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
4449 /* loop until we reach an abbrev number of 0 */
4450 while (abbrev_number
)
4452 cur_abbrev
= dwarf_alloc_abbrev (cu
);
4454 /* read in abbrev header */
4455 cur_abbrev
->number
= abbrev_number
;
4456 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4457 abbrev_ptr
+= bytes_read
;
4458 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
4461 if (cur_abbrev
->tag
== DW_TAG_namespace
)
4462 cu
->has_namespace_info
= 1;
4464 /* now read in declarations */
4465 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4466 abbrev_ptr
+= bytes_read
;
4467 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4468 abbrev_ptr
+= bytes_read
;
4471 if (cur_abbrev
->num_attrs
== allocated_attrs
)
4473 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
4475 = xrealloc (cur_attrs
, (allocated_attrs
4476 * sizeof (struct attr_abbrev
)));
4478 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
4479 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
4480 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4481 abbrev_ptr
+= bytes_read
;
4482 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4483 abbrev_ptr
+= bytes_read
;
4486 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
4487 (cur_abbrev
->num_attrs
4488 * sizeof (struct attr_abbrev
)));
4489 memcpy (cur_abbrev
->attrs
, cur_attrs
,
4490 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
4492 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
4493 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
4494 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
4496 /* Get next abbreviation.
4497 Under Irix6 the abbreviations for a compilation unit are not
4498 always properly terminated with an abbrev number of 0.
4499 Exit loop if we encounter an abbreviation which we have
4500 already read (which means we are about to read the abbreviations
4501 for the next compile unit) or if the end of the abbreviation
4502 table is reached. */
4503 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
4504 >= dwarf2_per_objfile
->abbrev_size
)
4506 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4507 abbrev_ptr
+= bytes_read
;
4508 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
4515 /* Release the memory used by the abbrev table for a compilation unit. */
4518 dwarf2_free_abbrev_table (void *ptr_to_cu
)
4520 struct dwarf2_cu
*cu
= ptr_to_cu
;
4522 obstack_free (&cu
->abbrev_obstack
, NULL
);
4523 cu
->dwarf2_abbrevs
= NULL
;
4526 /* Lookup an abbrev_info structure in the abbrev hash table. */
4528 static struct abbrev_info
*
4529 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
4531 unsigned int hash_number
;
4532 struct abbrev_info
*abbrev
;
4534 hash_number
= number
% ABBREV_HASH_SIZE
;
4535 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
4539 if (abbrev
->number
== number
)
4542 abbrev
= abbrev
->next
;
4547 /* Returns nonzero if TAG represents a type that we might generate a partial
4551 is_type_tag_for_partial (int tag
)
4556 /* Some types that would be reasonable to generate partial symbols for,
4557 that we don't at present. */
4558 case DW_TAG_array_type
:
4559 case DW_TAG_file_type
:
4560 case DW_TAG_ptr_to_member_type
:
4561 case DW_TAG_set_type
:
4562 case DW_TAG_string_type
:
4563 case DW_TAG_subroutine_type
:
4565 case DW_TAG_base_type
:
4566 case DW_TAG_class_type
:
4567 case DW_TAG_enumeration_type
:
4568 case DW_TAG_structure_type
:
4569 case DW_TAG_subrange_type
:
4570 case DW_TAG_typedef
:
4571 case DW_TAG_union_type
:
4578 /* Load all DIEs that are interesting for partial symbols into memory. */
4580 static struct partial_die_info
*
4581 load_partial_dies (bfd
*abfd
, char *info_ptr
, int building_psymtab
,
4582 struct dwarf2_cu
*cu
)
4584 struct partial_die_info
*part_die
;
4585 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
4586 struct abbrev_info
*abbrev
;
4587 unsigned int bytes_read
;
4589 int nesting_level
= 1;
4595 = htab_create_alloc_ex (cu
->header
.length
/ 12,
4599 &cu
->comp_unit_obstack
,
4600 hashtab_obstack_allocate
,
4601 dummy_obstack_deallocate
);
4603 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
4604 sizeof (struct partial_die_info
));
4608 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4610 /* A NULL abbrev means the end of a series of children. */
4613 if (--nesting_level
== 0)
4615 /* PART_DIE was probably the last thing allocated on the
4616 comp_unit_obstack, so we could call obstack_free
4617 here. We don't do that because the waste is small,
4618 and will be cleaned up when we're done with this
4619 compilation unit. This way, we're also more robust
4620 against other users of the comp_unit_obstack. */
4623 info_ptr
+= bytes_read
;
4624 last_die
= parent_die
;
4625 parent_die
= parent_die
->die_parent
;
4629 /* Check whether this DIE is interesting enough to save. */
4630 if (!is_type_tag_for_partial (abbrev
->tag
)
4631 && abbrev
->tag
!= DW_TAG_enumerator
4632 && abbrev
->tag
!= DW_TAG_subprogram
4633 && abbrev
->tag
!= DW_TAG_variable
4634 && abbrev
->tag
!= DW_TAG_namespace
)
4636 /* Otherwise we skip to the next sibling, if any. */
4637 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
4641 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
4642 abfd
, info_ptr
, cu
);
4644 /* This two-pass algorithm for processing partial symbols has a
4645 high cost in cache pressure. Thus, handle some simple cases
4646 here which cover the majority of C partial symbols. DIEs
4647 which neither have specification tags in them, nor could have
4648 specification tags elsewhere pointing at them, can simply be
4649 processed and discarded.
4651 This segment is also optional; scan_partial_symbols and
4652 add_partial_symbol will handle these DIEs if we chain
4653 them in normally. When compilers which do not emit large
4654 quantities of duplicate debug information are more common,
4655 this code can probably be removed. */
4657 /* Any complete simple types at the top level (pretty much all
4658 of them, for a language without namespaces), can be processed
4660 if (parent_die
== NULL
4661 && part_die
->has_specification
== 0
4662 && part_die
->is_declaration
== 0
4663 && (part_die
->tag
== DW_TAG_typedef
4664 || part_die
->tag
== DW_TAG_base_type
4665 || part_die
->tag
== DW_TAG_subrange_type
))
4667 if (building_psymtab
&& part_die
->name
!= NULL
)
4668 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
4669 VAR_DOMAIN
, LOC_TYPEDEF
,
4670 &cu
->objfile
->static_psymbols
,
4671 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
4672 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
4676 /* If we're at the second level, and we're an enumerator, and
4677 our parent has no specification (meaning possibly lives in a
4678 namespace elsewhere), then we can add the partial symbol now
4679 instead of queueing it. */
4680 if (part_die
->tag
== DW_TAG_enumerator
4681 && parent_die
!= NULL
4682 && parent_die
->die_parent
== NULL
4683 && parent_die
->tag
== DW_TAG_enumeration_type
4684 && parent_die
->has_specification
== 0)
4686 if (part_die
->name
== NULL
)
4687 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
4688 else if (building_psymtab
)
4689 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
4690 VAR_DOMAIN
, LOC_CONST
,
4691 cu
->language
== language_cplus
4692 ? &cu
->objfile
->global_psymbols
4693 : &cu
->objfile
->static_psymbols
,
4694 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
4696 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
4700 /* We'll save this DIE so link it in. */
4701 part_die
->die_parent
= parent_die
;
4702 part_die
->die_sibling
= NULL
;
4703 part_die
->die_child
= NULL
;
4705 if (last_die
&& last_die
== parent_die
)
4706 last_die
->die_child
= part_die
;
4708 last_die
->die_sibling
= part_die
;
4710 last_die
= part_die
;
4712 if (first_die
== NULL
)
4713 first_die
= part_die
;
4715 /* Maybe add the DIE to the hash table. Not all DIEs that we
4716 find interesting need to be in the hash table, because we
4717 also have the parent/sibling/child chains; only those that we
4718 might refer to by offset later during partial symbol reading.
4720 For now this means things that might have be the target of a
4721 DW_AT_specification, DW_AT_abstract_origin, or
4722 DW_AT_extension. DW_AT_extension will refer only to
4723 namespaces; DW_AT_abstract_origin refers to functions (and
4724 many things under the function DIE, but we do not recurse
4725 into function DIEs during partial symbol reading) and
4726 possibly variables as well; DW_AT_specification refers to
4727 declarations. Declarations ought to have the DW_AT_declaration
4728 flag. It happens that GCC forgets to put it in sometimes, but
4729 only for functions, not for types.
4731 Adding more things than necessary to the hash table is harmless
4732 except for the performance cost. Adding too few will result in
4733 internal errors in find_partial_die. */
4735 if (abbrev
->tag
== DW_TAG_subprogram
4736 || abbrev
->tag
== DW_TAG_variable
4737 || abbrev
->tag
== DW_TAG_namespace
4738 || part_die
->is_declaration
)
4742 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
4743 part_die
->offset
, INSERT
);
4747 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
4748 sizeof (struct partial_die_info
));
4750 /* For some DIEs we want to follow their children (if any). For C
4751 we have no reason to follow the children of structures; for other
4752 languages we have to, both so that we can get at method physnames
4753 to infer fully qualified class names, and for DW_AT_specification. */
4754 if (last_die
->has_children
4755 && (last_die
->tag
== DW_TAG_namespace
4756 || last_die
->tag
== DW_TAG_enumeration_type
4757 || (cu
->language
!= language_c
4758 && (last_die
->tag
== DW_TAG_class_type
4759 || last_die
->tag
== DW_TAG_structure_type
4760 || last_die
->tag
== DW_TAG_union_type
))))
4763 parent_die
= last_die
;
4767 /* Otherwise we skip to the next sibling, if any. */
4768 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
4770 /* Back to the top, do it again. */
4774 /* Read a minimal amount of information into the minimal die structure. */
4777 read_partial_die (struct partial_die_info
*part_die
,
4778 struct abbrev_info
*abbrev
,
4779 unsigned int abbrev_len
, bfd
*abfd
,
4780 char *info_ptr
, struct dwarf2_cu
*cu
)
4782 unsigned int bytes_read
, i
;
4783 struct attribute attr
;
4784 int has_low_pc_attr
= 0;
4785 int has_high_pc_attr
= 0;
4787 memset (part_die
, 0, sizeof (struct partial_die_info
));
4789 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
4791 info_ptr
+= abbrev_len
;
4796 part_die
->tag
= abbrev
->tag
;
4797 part_die
->has_children
= abbrev
->has_children
;
4799 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4801 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
4803 /* Store the data if it is of an attribute we want to keep in a
4804 partial symbol table. */
4809 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
4810 if (part_die
->name
== NULL
)
4811 part_die
->name
= DW_STRING (&attr
);
4813 case DW_AT_MIPS_linkage_name
:
4814 part_die
->name
= DW_STRING (&attr
);
4817 has_low_pc_attr
= 1;
4818 part_die
->lowpc
= DW_ADDR (&attr
);
4821 has_high_pc_attr
= 1;
4822 part_die
->highpc
= DW_ADDR (&attr
);
4824 case DW_AT_location
:
4825 /* Support the .debug_loc offsets */
4826 if (attr_form_is_block (&attr
))
4828 part_die
->locdesc
= DW_BLOCK (&attr
);
4830 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
4832 dwarf2_complex_location_expr_complaint ();
4836 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4837 "partial symbol information");
4840 case DW_AT_language
:
4841 part_die
->language
= DW_UNSND (&attr
);
4843 case DW_AT_external
:
4844 part_die
->is_external
= DW_UNSND (&attr
);
4846 case DW_AT_declaration
:
4847 part_die
->is_declaration
= DW_UNSND (&attr
);
4850 part_die
->has_type
= 1;
4852 case DW_AT_abstract_origin
:
4853 case DW_AT_specification
:
4854 case DW_AT_extension
:
4855 part_die
->has_specification
= 1;
4856 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
4859 /* Ignore absolute siblings, they might point outside of
4860 the current compile unit. */
4861 if (attr
.form
== DW_FORM_ref_addr
)
4862 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
4864 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
4865 + dwarf2_get_ref_die_offset (&attr
, cu
);
4872 /* When using the GNU linker, .gnu.linkonce. sections are used to
4873 eliminate duplicate copies of functions and vtables and such.
4874 The linker will arbitrarily choose one and discard the others.
4875 The AT_*_pc values for such functions refer to local labels in
4876 these sections. If the section from that file was discarded, the
4877 labels are not in the output, so the relocs get a value of 0.
4878 If this is a discarded function, mark the pc bounds as invalid,
4879 so that GDB will ignore it. */
4880 if (has_low_pc_attr
&& has_high_pc_attr
4881 && part_die
->lowpc
< part_die
->highpc
4882 && (part_die
->lowpc
!= 0
4883 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
4884 part_die
->has_pc_info
= 1;
4888 /* Find a cached partial DIE at OFFSET in CU. */
4890 static struct partial_die_info
*
4891 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
4893 struct partial_die_info
*lookup_die
= NULL
;
4894 struct partial_die_info part_die
;
4896 part_die
.offset
= offset
;
4897 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
4899 if (lookup_die
== NULL
)
4900 internal_error (__FILE__
, __LINE__
,
4901 "could not find partial DIE in cache\n");
4906 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
4908 static struct partial_die_info
*
4909 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
,
4910 struct dwarf2_cu
**target_cu
)
4912 struct dwarf2_per_cu_data
*per_cu
;
4914 if (offset
>= cu
->header
.offset
4915 && offset
< cu
->header
.offset
+ cu
->header
.length
)
4918 return find_partial_die_in_comp_unit (offset
, cu
);
4921 internal_error (__FILE__
, __LINE__
,
4922 "unsupported inter-compilation-unit reference");
4925 /* Adjust PART_DIE before generating a symbol for it. This function
4926 may set the is_external flag or change the DIE's name. */
4929 fixup_partial_die (struct partial_die_info
*part_die
,
4930 struct dwarf2_cu
*cu
)
4932 /* If we found a reference attribute and the DIE has no name, try
4933 to find a name in the referred to DIE. */
4935 if (part_die
->name
== NULL
&& part_die
->has_specification
)
4937 struct partial_die_info
*spec_die
;
4938 struct dwarf2_cu
*spec_cu
;
4940 spec_die
= find_partial_die (part_die
->spec_offset
, cu
, &spec_cu
);
4942 fixup_partial_die (spec_die
, spec_cu
);
4946 part_die
->name
= spec_die
->name
;
4948 /* Copy DW_AT_external attribute if it is set. */
4949 if (spec_die
->is_external
)
4950 part_die
->is_external
= spec_die
->is_external
;
4954 /* Set default names for some unnamed DIEs. */
4955 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
4956 || part_die
->tag
== DW_TAG_class_type
))
4957 part_die
->name
= "(anonymous class)";
4959 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
4960 part_die
->name
= "(anonymous namespace)";
4962 if (part_die
->tag
== DW_TAG_structure_type
4963 || part_die
->tag
== DW_TAG_class_type
4964 || part_die
->tag
== DW_TAG_union_type
)
4965 guess_structure_name (part_die
, cu
);
4968 /* Read the die from the .debug_info section buffer. Set DIEP to
4969 point to a newly allocated die with its information, except for its
4970 child, sibling, and parent fields. Set HAS_CHILDREN to tell
4971 whether the die has children or not. */
4974 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
4975 struct dwarf2_cu
*cu
, int *has_children
)
4977 unsigned int abbrev_number
, bytes_read
, i
, offset
;
4978 struct abbrev_info
*abbrev
;
4979 struct die_info
*die
;
4981 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
4982 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4983 info_ptr
+= bytes_read
;
4986 die
= dwarf_alloc_die ();
4988 die
->abbrev
= abbrev_number
;
4995 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4998 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
5000 bfd_get_filename (abfd
));
5002 die
= dwarf_alloc_die ();
5003 die
->offset
= offset
;
5004 die
->tag
= abbrev
->tag
;
5005 die
->abbrev
= abbrev_number
;
5008 die
->num_attrs
= abbrev
->num_attrs
;
5009 die
->attrs
= (struct attribute
*)
5010 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
5012 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5014 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
5015 abfd
, info_ptr
, cu
);
5019 *has_children
= abbrev
->has_children
;
5023 /* Read an attribute value described by an attribute form. */
5026 read_attribute_value (struct attribute
*attr
, unsigned form
,
5027 bfd
*abfd
, char *info_ptr
,
5028 struct dwarf2_cu
*cu
)
5030 struct comp_unit_head
*cu_header
= &cu
->header
;
5031 unsigned int bytes_read
;
5032 struct dwarf_block
*blk
;
5038 case DW_FORM_ref_addr
:
5039 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
5040 info_ptr
+= bytes_read
;
5042 case DW_FORM_block2
:
5043 blk
= dwarf_alloc_block ();
5044 blk
->size
= read_2_bytes (abfd
, info_ptr
);
5046 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5047 info_ptr
+= blk
->size
;
5048 DW_BLOCK (attr
) = blk
;
5050 case DW_FORM_block4
:
5051 blk
= dwarf_alloc_block ();
5052 blk
->size
= read_4_bytes (abfd
, info_ptr
);
5054 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5055 info_ptr
+= blk
->size
;
5056 DW_BLOCK (attr
) = blk
;
5059 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
5063 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
5067 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
5070 case DW_FORM_string
:
5071 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
5072 info_ptr
+= bytes_read
;
5075 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
5077 info_ptr
+= bytes_read
;
5080 blk
= dwarf_alloc_block ();
5081 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5082 info_ptr
+= bytes_read
;
5083 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5084 info_ptr
+= blk
->size
;
5085 DW_BLOCK (attr
) = blk
;
5087 case DW_FORM_block1
:
5088 blk
= dwarf_alloc_block ();
5089 blk
->size
= read_1_byte (abfd
, info_ptr
);
5091 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5092 info_ptr
+= blk
->size
;
5093 DW_BLOCK (attr
) = blk
;
5096 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5100 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5104 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
5105 info_ptr
+= bytes_read
;
5108 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5109 info_ptr
+= bytes_read
;
5112 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5116 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
5120 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
5124 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
5127 case DW_FORM_ref_udata
:
5128 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5129 info_ptr
+= bytes_read
;
5131 case DW_FORM_indirect
:
5132 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5133 info_ptr
+= bytes_read
;
5134 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
5137 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
5138 dwarf_form_name (form
),
5139 bfd_get_filename (abfd
));
5144 /* Read an attribute described by an abbreviated attribute. */
5147 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
5148 bfd
*abfd
, char *info_ptr
, struct dwarf2_cu
*cu
)
5150 attr
->name
= abbrev
->name
;
5151 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
5154 /* read dwarf information from a buffer */
5157 read_1_byte (bfd
*abfd
, char *buf
)
5159 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5163 read_1_signed_byte (bfd
*abfd
, char *buf
)
5165 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
5169 read_2_bytes (bfd
*abfd
, char *buf
)
5171 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
5175 read_2_signed_bytes (bfd
*abfd
, char *buf
)
5177 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
5181 read_4_bytes (bfd
*abfd
, char *buf
)
5183 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5187 read_4_signed_bytes (bfd
*abfd
, char *buf
)
5189 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
5192 static unsigned long
5193 read_8_bytes (bfd
*abfd
, char *buf
)
5195 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5199 read_address (bfd
*abfd
, char *buf
, struct dwarf2_cu
*cu
, int *bytes_read
)
5201 struct comp_unit_head
*cu_header
= &cu
->header
;
5202 CORE_ADDR retval
= 0;
5204 if (cu_header
->signed_addr_p
)
5206 switch (cu_header
->addr_size
)
5209 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
5212 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
5215 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
5218 internal_error (__FILE__
, __LINE__
,
5219 "read_address: bad switch, signed [in module %s]",
5220 bfd_get_filename (abfd
));
5225 switch (cu_header
->addr_size
)
5228 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
5231 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5234 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5237 internal_error (__FILE__
, __LINE__
,
5238 "read_address: bad switch, unsigned [in module %s]",
5239 bfd_get_filename (abfd
));
5243 *bytes_read
= cu_header
->addr_size
;
5247 /* Read the initial length from a section. The (draft) DWARF 3
5248 specification allows the initial length to take up either 4 bytes
5249 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
5250 bytes describe the length and all offsets will be 8 bytes in length
5253 An older, non-standard 64-bit format is also handled by this
5254 function. The older format in question stores the initial length
5255 as an 8-byte quantity without an escape value. Lengths greater
5256 than 2^32 aren't very common which means that the initial 4 bytes
5257 is almost always zero. Since a length value of zero doesn't make
5258 sense for the 32-bit format, this initial zero can be considered to
5259 be an escape value which indicates the presence of the older 64-bit
5260 format. As written, the code can't detect (old format) lengths
5261 greater than 4GB. If it becomes necessary to handle lengths somewhat
5262 larger than 4GB, we could allow other small values (such as the
5263 non-sensical values of 1, 2, and 3) to also be used as escape values
5264 indicating the presence of the old format.
5266 The value returned via bytes_read should be used to increment
5267 the relevant pointer after calling read_initial_length().
5269 As a side effect, this function sets the fields initial_length_size
5270 and offset_size in cu_header to the values appropriate for the
5271 length field. (The format of the initial length field determines
5272 the width of file offsets to be fetched later with fetch_offset().)
5274 [ Note: read_initial_length() and read_offset() are based on the
5275 document entitled "DWARF Debugging Information Format", revision
5276 3, draft 8, dated November 19, 2001. This document was obtained
5279 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
5281 This document is only a draft and is subject to change. (So beware.)
5283 Details regarding the older, non-standard 64-bit format were
5284 determined empirically by examining 64-bit ELF files produced
5285 by the SGI toolchain on an IRIX 6.5 machine.
5287 - Kevin, July 16, 2002
5291 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
5296 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5298 if (retval
== 0xffffffff)
5300 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
5302 if (cu_header
!= NULL
)
5304 cu_header
->initial_length_size
= 12;
5305 cu_header
->offset_size
= 8;
5308 else if (retval
== 0)
5310 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
5312 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5314 if (cu_header
!= NULL
)
5316 cu_header
->initial_length_size
= 8;
5317 cu_header
->offset_size
= 8;
5323 if (cu_header
!= NULL
)
5325 cu_header
->initial_length_size
= 4;
5326 cu_header
->offset_size
= 4;
5333 /* Read an offset from the data stream. The size of the offset is
5334 given by cu_header->offset_size. */
5337 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
5342 switch (cu_header
->offset_size
)
5345 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5349 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5353 internal_error (__FILE__
, __LINE__
,
5354 "read_offset: bad switch [in module %s]",
5355 bfd_get_filename (abfd
));
5362 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
5364 /* If the size of a host char is 8 bits, we can return a pointer
5365 to the buffer, otherwise we have to copy the data to a buffer
5366 allocated on the temporary obstack. */
5367 gdb_assert (HOST_CHAR_BIT
== 8);
5372 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5374 /* If the size of a host char is 8 bits, we can return a pointer
5375 to the string, otherwise we have to copy the string to a buffer
5376 allocated on the temporary obstack. */
5377 gdb_assert (HOST_CHAR_BIT
== 8);
5380 *bytes_read_ptr
= 1;
5383 *bytes_read_ptr
= strlen (buf
) + 1;
5388 read_indirect_string (bfd
*abfd
, char *buf
,
5389 const struct comp_unit_head
*cu_header
,
5390 unsigned int *bytes_read_ptr
)
5392 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
5393 (int *) bytes_read_ptr
);
5395 if (dwarf2_per_objfile
->str_buffer
== NULL
)
5397 error ("DW_FORM_strp used without .debug_str section [in module %s]",
5398 bfd_get_filename (abfd
));
5401 if (str_offset
>= dwarf2_per_objfile
->str_size
)
5403 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
5404 bfd_get_filename (abfd
));
5407 gdb_assert (HOST_CHAR_BIT
== 8);
5408 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
5410 return dwarf2_per_objfile
->str_buffer
+ str_offset
;
5413 static unsigned long
5414 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5416 unsigned long result
;
5417 unsigned int num_read
;
5427 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5430 result
|= ((unsigned long)(byte
& 127) << shift
);
5431 if ((byte
& 128) == 0)
5437 *bytes_read_ptr
= num_read
;
5442 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5445 int i
, shift
, size
, num_read
;
5455 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5458 result
|= ((long)(byte
& 127) << shift
);
5460 if ((byte
& 128) == 0)
5465 if ((shift
< size
) && (byte
& 0x40))
5467 result
|= -(1 << shift
);
5469 *bytes_read_ptr
= num_read
;
5473 /* Return a pointer to just past the end of an LEB128 number in BUF. */
5476 skip_leb128 (bfd
*abfd
, char *buf
)
5482 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5484 if ((byte
& 128) == 0)
5490 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
5496 cu
->language
= language_c
;
5498 case DW_LANG_C_plus_plus
:
5499 cu
->language
= language_cplus
;
5501 case DW_LANG_Fortran77
:
5502 case DW_LANG_Fortran90
:
5503 case DW_LANG_Fortran95
:
5504 cu
->language
= language_fortran
;
5506 case DW_LANG_Mips_Assembler
:
5507 cu
->language
= language_asm
;
5510 cu
->language
= language_java
;
5514 case DW_LANG_Cobol74
:
5515 case DW_LANG_Cobol85
:
5516 case DW_LANG_Pascal83
:
5517 case DW_LANG_Modula2
:
5519 cu
->language
= language_minimal
;
5522 cu
->language_defn
= language_def (cu
->language
);
5525 /* Return the named attribute or NULL if not there. */
5527 static struct attribute
*
5528 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
5531 struct attribute
*spec
= NULL
;
5533 for (i
= 0; i
< die
->num_attrs
; ++i
)
5535 if (die
->attrs
[i
].name
== name
)
5537 return &die
->attrs
[i
];
5539 if (die
->attrs
[i
].name
== DW_AT_specification
5540 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
5541 spec
= &die
->attrs
[i
];
5545 struct die_info
*ref_die
=
5546 follow_die_ref (dwarf2_get_ref_die_offset (spec
, cu
));
5549 return dwarf2_attr (ref_die
, name
, cu
);
5555 /* Return non-zero iff the attribute NAME is defined for the given DIE,
5556 and holds a non-zero value. */
5559 dwarf2_attribute_true_p (struct die_info
*die
, unsigned name
,
5560 struct dwarf2_cu
*cu
)
5562 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
5564 return (attr
&& DW_UNSND (attr
));
5568 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
5570 /* A DIE is a declaration if it has a DW_AT_declaration attribute
5571 which value is non-zero. However, we have to be careful of DIEs
5572 with a DW_AT_specification attribute, because dwarf2_attribute_p()
5573 follows this attribute, and therefore might cause us to find a
5574 DW_AT_declaration attribute, but that belongs to a different DIE. */
5575 return (dwarf2_attribute_true_p (die
, DW_AT_declaration
, cu
)
5576 && ! dwarf2_attribute_true_p (die
, DW_AT_specification
, cu
));
5579 /* Return the die giving the specification for DIE, if there is
5582 static struct die_info
*
5583 die_specification (struct die_info
*die
, struct dwarf2_cu
*cu
)
5585 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
, cu
);
5587 if (spec_attr
== NULL
)
5590 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr
, cu
));
5593 /* Free the line_header structure *LH, and any arrays and strings it
5596 free_line_header (struct line_header
*lh
)
5598 if (lh
->standard_opcode_lengths
)
5599 xfree (lh
->standard_opcode_lengths
);
5601 /* Remember that all the lh->file_names[i].name pointers are
5602 pointers into debug_line_buffer, and don't need to be freed. */
5604 xfree (lh
->file_names
);
5606 /* Similarly for the include directory names. */
5607 if (lh
->include_dirs
)
5608 xfree (lh
->include_dirs
);
5614 /* Add an entry to LH's include directory table. */
5616 add_include_dir (struct line_header
*lh
, char *include_dir
)
5618 /* Grow the array if necessary. */
5619 if (lh
->include_dirs_size
== 0)
5621 lh
->include_dirs_size
= 1; /* for testing */
5622 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
5623 * sizeof (*lh
->include_dirs
));
5625 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
5627 lh
->include_dirs_size
*= 2;
5628 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
5629 (lh
->include_dirs_size
5630 * sizeof (*lh
->include_dirs
)));
5633 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
5637 /* Add an entry to LH's file name table. */
5639 add_file_name (struct line_header
*lh
,
5641 unsigned int dir_index
,
5642 unsigned int mod_time
,
5643 unsigned int length
)
5645 struct file_entry
*fe
;
5647 /* Grow the array if necessary. */
5648 if (lh
->file_names_size
== 0)
5650 lh
->file_names_size
= 1; /* for testing */
5651 lh
->file_names
= xmalloc (lh
->file_names_size
5652 * sizeof (*lh
->file_names
));
5654 else if (lh
->num_file_names
>= lh
->file_names_size
)
5656 lh
->file_names_size
*= 2;
5657 lh
->file_names
= xrealloc (lh
->file_names
,
5658 (lh
->file_names_size
5659 * sizeof (*lh
->file_names
)));
5662 fe
= &lh
->file_names
[lh
->num_file_names
++];
5664 fe
->dir_index
= dir_index
;
5665 fe
->mod_time
= mod_time
;
5666 fe
->length
= length
;
5670 /* Read the statement program header starting at OFFSET in
5671 .debug_line, according to the endianness of ABFD. Return a pointer
5672 to a struct line_header, allocated using xmalloc.
5674 NOTE: the strings in the include directory and file name tables of
5675 the returned object point into debug_line_buffer, and must not be
5677 static struct line_header
*
5678 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
5679 struct dwarf2_cu
*cu
)
5681 struct cleanup
*back_to
;
5682 struct line_header
*lh
;
5686 char *cur_dir
, *cur_file
;
5688 if (dwarf2_per_objfile
->line_buffer
== NULL
)
5690 complaint (&symfile_complaints
, "missing .debug_line section");
5694 /* Make sure that at least there's room for the total_length field. That
5695 could be 12 bytes long, but we're just going to fudge that. */
5696 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
5698 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5702 lh
= xmalloc (sizeof (*lh
));
5703 memset (lh
, 0, sizeof (*lh
));
5704 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
5707 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
5709 /* read in the header */
5710 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
5711 line_ptr
+= bytes_read
;
5712 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
5713 + dwarf2_per_objfile
->line_size
))
5715 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5718 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
5719 lh
->version
= read_2_bytes (abfd
, line_ptr
);
5721 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
5722 line_ptr
+= bytes_read
;
5723 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
5725 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
5727 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
5729 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
5731 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
5733 lh
->standard_opcode_lengths
5734 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
5736 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
5737 for (i
= 1; i
< lh
->opcode_base
; ++i
)
5739 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
5743 /* Read directory table */
5744 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5746 line_ptr
+= bytes_read
;
5747 add_include_dir (lh
, cur_dir
);
5749 line_ptr
+= bytes_read
;
5751 /* Read file name table */
5752 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5754 unsigned int dir_index
, mod_time
, length
;
5756 line_ptr
+= bytes_read
;
5757 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5758 line_ptr
+= bytes_read
;
5759 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5760 line_ptr
+= bytes_read
;
5761 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5762 line_ptr
+= bytes_read
;
5764 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5766 line_ptr
+= bytes_read
;
5767 lh
->statement_program_start
= line_ptr
;
5769 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
5770 + dwarf2_per_objfile
->line_size
))
5771 complaint (&symfile_complaints
,
5772 "line number info header doesn't fit in `.debug_line' section");
5774 discard_cleanups (back_to
);
5778 /* This function exists to work around a bug in certain compilers
5779 (particularly GCC 2.95), in which the first line number marker of a
5780 function does not show up until after the prologue, right before
5781 the second line number marker. This function shifts ADDRESS down
5782 to the beginning of the function if necessary, and is called on
5783 addresses passed to record_line. */
5786 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
5788 struct function_range
*fn
;
5790 /* Find the function_range containing address. */
5795 cu
->cached_fn
= cu
->first_fn
;
5799 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5805 while (fn
&& fn
!= cu
->cached_fn
)
5806 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5816 if (address
!= fn
->lowpc
)
5817 complaint (&symfile_complaints
,
5818 "misplaced first line number at 0x%lx for '%s'",
5819 (unsigned long) address
, fn
->name
);
5824 /* Decode the line number information for the compilation unit whose
5825 line number info is at OFFSET in the .debug_line section.
5826 The compilation directory of the file is passed in COMP_DIR. */
5829 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
5830 struct dwarf2_cu
*cu
)
5834 unsigned int bytes_read
;
5835 unsigned char op_code
, extended_op
, adj_opcode
;
5837 struct objfile
*objfile
= cu
->objfile
;
5839 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5841 line_ptr
= lh
->statement_program_start
;
5842 line_end
= lh
->statement_program_end
;
5844 /* Read the statement sequences until there's nothing left. */
5845 while (line_ptr
< line_end
)
5847 /* state machine registers */
5848 CORE_ADDR address
= 0;
5849 unsigned int file
= 1;
5850 unsigned int line
= 1;
5851 unsigned int column
= 0;
5852 int is_stmt
= lh
->default_is_stmt
;
5853 int basic_block
= 0;
5854 int end_sequence
= 0;
5856 /* Start a subfile for the current file of the state machine. */
5857 if (lh
->num_file_names
>= file
)
5859 /* lh->include_dirs and lh->file_names are 0-based, but the
5860 directory and file name numbers in the statement program
5862 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
5865 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5868 dwarf2_start_subfile (fe
->name
, dir
);
5871 /* Decode the table. */
5872 while (!end_sequence
)
5874 op_code
= read_1_byte (abfd
, line_ptr
);
5877 if (op_code
>= lh
->opcode_base
)
5878 { /* Special operand. */
5879 adj_opcode
= op_code
- lh
->opcode_base
;
5880 address
+= (adj_opcode
/ lh
->line_range
)
5881 * lh
->minimum_instruction_length
;
5882 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
5883 /* append row to matrix using current values */
5884 record_line (current_subfile
, line
,
5885 check_cu_functions (address
, cu
));
5888 else switch (op_code
)
5890 case DW_LNS_extended_op
:
5891 line_ptr
+= 1; /* ignore length */
5892 extended_op
= read_1_byte (abfd
, line_ptr
);
5894 switch (extended_op
)
5896 case DW_LNE_end_sequence
:
5898 record_line (current_subfile
, 0, address
);
5900 case DW_LNE_set_address
:
5901 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
5902 line_ptr
+= bytes_read
;
5903 address
+= baseaddr
;
5905 case DW_LNE_define_file
:
5908 unsigned int dir_index
, mod_time
, length
;
5910 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
5911 line_ptr
+= bytes_read
;
5913 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5914 line_ptr
+= bytes_read
;
5916 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5917 line_ptr
+= bytes_read
;
5919 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5920 line_ptr
+= bytes_read
;
5921 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5925 complaint (&symfile_complaints
,
5926 "mangled .debug_line section");
5931 record_line (current_subfile
, line
,
5932 check_cu_functions (address
, cu
));
5935 case DW_LNS_advance_pc
:
5936 address
+= lh
->minimum_instruction_length
5937 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5938 line_ptr
+= bytes_read
;
5940 case DW_LNS_advance_line
:
5941 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
5942 line_ptr
+= bytes_read
;
5944 case DW_LNS_set_file
:
5946 /* lh->include_dirs and lh->file_names are 0-based,
5947 but the directory and file name numbers in the
5948 statement program are 1-based. */
5949 struct file_entry
*fe
;
5951 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5952 line_ptr
+= bytes_read
;
5953 fe
= &lh
->file_names
[file
- 1];
5955 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5958 dwarf2_start_subfile (fe
->name
, dir
);
5961 case DW_LNS_set_column
:
5962 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5963 line_ptr
+= bytes_read
;
5965 case DW_LNS_negate_stmt
:
5966 is_stmt
= (!is_stmt
);
5968 case DW_LNS_set_basic_block
:
5971 /* Add to the address register of the state machine the
5972 address increment value corresponding to special opcode
5973 255. Ie, this value is scaled by the minimum instruction
5974 length since special opcode 255 would have scaled the
5976 case DW_LNS_const_add_pc
:
5977 address
+= (lh
->minimum_instruction_length
5978 * ((255 - lh
->opcode_base
) / lh
->line_range
));
5980 case DW_LNS_fixed_advance_pc
:
5981 address
+= read_2_bytes (abfd
, line_ptr
);
5985 { /* Unknown standard opcode, ignore it. */
5987 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
5989 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5990 line_ptr
+= bytes_read
;
5998 /* Start a subfile for DWARF. FILENAME is the name of the file and
5999 DIRNAME the name of the source directory which contains FILENAME
6000 or NULL if not known.
6001 This routine tries to keep line numbers from identical absolute and
6002 relative file names in a common subfile.
6004 Using the `list' example from the GDB testsuite, which resides in
6005 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
6006 of /srcdir/list0.c yields the following debugging information for list0.c:
6008 DW_AT_name: /srcdir/list0.c
6009 DW_AT_comp_dir: /compdir
6010 files.files[0].name: list0.h
6011 files.files[0].dir: /srcdir
6012 files.files[1].name: list0.c
6013 files.files[1].dir: /srcdir
6015 The line number information for list0.c has to end up in a single
6016 subfile, so that `break /srcdir/list0.c:1' works as expected. */
6019 dwarf2_start_subfile (char *filename
, char *dirname
)
6021 /* If the filename isn't absolute, try to match an existing subfile
6022 with the full pathname. */
6024 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
6026 struct subfile
*subfile
;
6027 char *fullname
= concat (dirname
, "/", filename
, NULL
);
6029 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
6031 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
6033 current_subfile
= subfile
;
6040 start_subfile (filename
, dirname
);
6044 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
6045 struct dwarf2_cu
*cu
)
6047 struct objfile
*objfile
= cu
->objfile
;
6048 struct comp_unit_head
*cu_header
= &cu
->header
;
6050 /* NOTE drow/2003-01-30: There used to be a comment and some special
6051 code here to turn a symbol with DW_AT_external and a
6052 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
6053 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
6054 with some versions of binutils) where shared libraries could have
6055 relocations against symbols in their debug information - the
6056 minimal symbol would have the right address, but the debug info
6057 would not. It's no longer necessary, because we will explicitly
6058 apply relocations when we read in the debug information now. */
6060 /* A DW_AT_location attribute with no contents indicates that a
6061 variable has been optimized away. */
6062 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
6064 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
6068 /* Handle one degenerate form of location expression specially, to
6069 preserve GDB's previous behavior when section offsets are
6070 specified. If this is just a DW_OP_addr then mark this symbol
6073 if (attr_form_is_block (attr
)
6074 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
6075 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
6079 SYMBOL_VALUE_ADDRESS (sym
) =
6080 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
6081 fixup_symbol_section (sym
, objfile
);
6082 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
6083 SYMBOL_SECTION (sym
));
6084 SYMBOL_CLASS (sym
) = LOC_STATIC
;
6088 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
6089 expression evaluator, and use LOC_COMPUTED only when necessary
6090 (i.e. when the value of a register or memory location is
6091 referenced, or a thread-local block, etc.). Then again, it might
6092 not be worthwhile. I'm assuming that it isn't unless performance
6093 or memory numbers show me otherwise. */
6095 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
6096 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
6099 /* Given a pointer to a DWARF information entry, figure out if we need
6100 to make a symbol table entry for it, and if so, create a new entry
6101 and return a pointer to it.
6102 If TYPE is NULL, determine symbol type from the die, otherwise
6103 used the passed type. */
6105 static struct symbol
*
6106 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
6108 struct objfile
*objfile
= cu
->objfile
;
6109 struct symbol
*sym
= NULL
;
6111 struct attribute
*attr
= NULL
;
6112 struct attribute
*attr2
= NULL
;
6115 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6117 if (die
->tag
!= DW_TAG_namespace
)
6118 name
= dwarf2_linkage_name (die
, cu
);
6120 name
= TYPE_NAME (type
);
6124 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
6125 sizeof (struct symbol
));
6126 OBJSTAT (objfile
, n_syms
++);
6127 memset (sym
, 0, sizeof (struct symbol
));
6129 /* Cache this symbol's name and the name's demangled form (if any). */
6130 SYMBOL_LANGUAGE (sym
) = cu
->language
;
6131 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
6133 /* Default assumptions.
6134 Use the passed type or decode it from the die. */
6135 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6136 SYMBOL_CLASS (sym
) = LOC_STATIC
;
6138 SYMBOL_TYPE (sym
) = type
;
6140 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
6141 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
6144 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
6149 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6152 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
6154 SYMBOL_CLASS (sym
) = LOC_LABEL
;
6156 case DW_TAG_subprogram
:
6157 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
6159 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
6160 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6161 if (attr2
&& (DW_UNSND (attr2
) != 0))
6163 add_symbol_to_list (sym
, &global_symbols
);
6167 add_symbol_to_list (sym
, cu
->list_in_scope
);
6170 case DW_TAG_variable
:
6171 /* Compilation with minimal debug info may result in variables
6172 with missing type entries. Change the misleading `void' type
6173 to something sensible. */
6174 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
6175 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
6176 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
6177 "<variable, no debug info>",
6179 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6182 dwarf2_const_value (attr
, sym
, cu
);
6183 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6184 if (attr2
&& (DW_UNSND (attr2
) != 0))
6185 add_symbol_to_list (sym
, &global_symbols
);
6187 add_symbol_to_list (sym
, cu
->list_in_scope
);
6190 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6193 var_decode_location (attr
, sym
, cu
);
6194 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6195 if (attr2
&& (DW_UNSND (attr2
) != 0))
6196 add_symbol_to_list (sym
, &global_symbols
);
6198 add_symbol_to_list (sym
, cu
->list_in_scope
);
6202 /* We do not know the address of this symbol.
6203 If it is an external symbol and we have type information
6204 for it, enter the symbol as a LOC_UNRESOLVED symbol.
6205 The address of the variable will then be determined from
6206 the minimal symbol table whenever the variable is
6208 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6209 if (attr2
&& (DW_UNSND (attr2
) != 0)
6210 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
6212 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
6213 add_symbol_to_list (sym
, &global_symbols
);
6217 case DW_TAG_formal_parameter
:
6218 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6221 var_decode_location (attr
, sym
, cu
);
6222 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
6223 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
6224 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
6226 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6229 dwarf2_const_value (attr
, sym
, cu
);
6231 add_symbol_to_list (sym
, cu
->list_in_scope
);
6233 case DW_TAG_unspecified_parameters
:
6234 /* From varargs functions; gdb doesn't seem to have any
6235 interest in this information, so just ignore it for now.
6238 case DW_TAG_class_type
:
6239 case DW_TAG_structure_type
:
6240 case DW_TAG_union_type
:
6241 case DW_TAG_enumeration_type
:
6242 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6243 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6245 /* Make sure that the symbol includes appropriate enclosing
6246 classes/namespaces in its name. These are calculated in
6247 read_structure_type, and the correct name is saved in
6250 if (cu
->language
== language_cplus
)
6252 struct type
*type
= SYMBOL_TYPE (sym
);
6254 if (TYPE_TAG_NAME (type
) != NULL
)
6256 /* FIXME: carlton/2003-11-10: Should this use
6257 SYMBOL_SET_NAMES instead? (The same problem also
6258 arises further down in this function.) */
6259 /* The type's name is already allocated along with
6260 this objfile, so we don't need to duplicate it
6262 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
6267 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
6268 really ever be static objects: otherwise, if you try
6269 to, say, break of a class's method and you're in a file
6270 which doesn't mention that class, it won't work unless
6271 the check for all static symbols in lookup_symbol_aux
6272 saves you. See the OtherFileClass tests in
6273 gdb.c++/namespace.exp. */
6275 struct pending
**list_to_add
;
6277 list_to_add
= (cu
->list_in_scope
== &file_symbols
6278 && cu
->language
== language_cplus
6279 ? &global_symbols
: cu
->list_in_scope
);
6281 add_symbol_to_list (sym
, list_to_add
);
6283 /* The semantics of C++ state that "struct foo { ... }" also
6284 defines a typedef for "foo". Synthesize a typedef symbol so
6285 that "ptype foo" works as expected. */
6286 if (cu
->language
== language_cplus
)
6288 struct symbol
*typedef_sym
= (struct symbol
*)
6289 obstack_alloc (&objfile
->objfile_obstack
,
6290 sizeof (struct symbol
));
6291 *typedef_sym
= *sym
;
6292 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
6293 /* The symbol's name is already allocated along with
6294 this objfile, so we don't need to duplicate it for
6296 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
6297 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NATURAL_NAME (sym
);
6298 add_symbol_to_list (typedef_sym
, list_to_add
);
6302 case DW_TAG_typedef
:
6303 if (processing_has_namespace_info
6304 && processing_current_prefix
[0] != '\0')
6306 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->objfile_obstack
,
6307 processing_current_prefix
,
6311 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6312 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6313 add_symbol_to_list (sym
, cu
->list_in_scope
);
6315 case DW_TAG_base_type
:
6316 case DW_TAG_subrange_type
:
6317 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6318 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6319 add_symbol_to_list (sym
, cu
->list_in_scope
);
6321 case DW_TAG_enumerator
:
6322 if (processing_has_namespace_info
6323 && processing_current_prefix
[0] != '\0')
6325 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->objfile_obstack
,
6326 processing_current_prefix
,
6330 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6333 dwarf2_const_value (attr
, sym
, cu
);
6336 /* NOTE: carlton/2003-11-10: See comment above in the
6337 DW_TAG_class_type, etc. block. */
6339 struct pending
**list_to_add
;
6341 list_to_add
= (cu
->list_in_scope
== &file_symbols
6342 && cu
->language
== language_cplus
6343 ? &global_symbols
: cu
->list_in_scope
);
6345 add_symbol_to_list (sym
, list_to_add
);
6348 case DW_TAG_namespace
:
6349 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6350 add_symbol_to_list (sym
, &global_symbols
);
6353 /* Not a tag we recognize. Hopefully we aren't processing
6354 trash data, but since we must specifically ignore things
6355 we don't recognize, there is nothing else we should do at
6357 complaint (&symfile_complaints
, "unsupported tag: '%s'",
6358 dwarf_tag_name (die
->tag
));
6365 /* Copy constant value from an attribute to a symbol. */
6368 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
6369 struct dwarf2_cu
*cu
)
6371 struct objfile
*objfile
= cu
->objfile
;
6372 struct comp_unit_head
*cu_header
= &cu
->header
;
6373 struct dwarf_block
*blk
;
6378 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
6379 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
6380 cu_header
->addr_size
,
6381 TYPE_LENGTH (SYMBOL_TYPE
6383 SYMBOL_VALUE_BYTES (sym
) = (char *)
6384 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
6385 /* NOTE: cagney/2003-05-09: In-lined store_address call with
6386 it's body - store_unsigned_integer. */
6387 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
6389 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6391 case DW_FORM_block1
:
6392 case DW_FORM_block2
:
6393 case DW_FORM_block4
:
6395 blk
= DW_BLOCK (attr
);
6396 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
6397 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
6399 TYPE_LENGTH (SYMBOL_TYPE
6401 SYMBOL_VALUE_BYTES (sym
) = (char *)
6402 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
6403 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
6404 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6407 /* The DW_AT_const_value attributes are supposed to carry the
6408 symbol's value "represented as it would be on the target
6409 architecture." By the time we get here, it's already been
6410 converted to host endianness, so we just need to sign- or
6411 zero-extend it as appropriate. */
6413 dwarf2_const_value_data (attr
, sym
, 8);
6416 dwarf2_const_value_data (attr
, sym
, 16);
6419 dwarf2_const_value_data (attr
, sym
, 32);
6422 dwarf2_const_value_data (attr
, sym
, 64);
6426 SYMBOL_VALUE (sym
) = DW_SND (attr
);
6427 SYMBOL_CLASS (sym
) = LOC_CONST
;
6431 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
6432 SYMBOL_CLASS (sym
) = LOC_CONST
;
6436 complaint (&symfile_complaints
,
6437 "unsupported const value attribute form: '%s'",
6438 dwarf_form_name (attr
->form
));
6439 SYMBOL_VALUE (sym
) = 0;
6440 SYMBOL_CLASS (sym
) = LOC_CONST
;
6446 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
6447 or zero-extend it as appropriate for the symbol's type. */
6449 dwarf2_const_value_data (struct attribute
*attr
,
6453 LONGEST l
= DW_UNSND (attr
);
6455 if (bits
< sizeof (l
) * 8)
6457 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
6458 l
&= ((LONGEST
) 1 << bits
) - 1;
6460 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
6463 SYMBOL_VALUE (sym
) = l
;
6464 SYMBOL_CLASS (sym
) = LOC_CONST
;
6468 /* Return the type of the die in question using its DW_AT_type attribute. */
6470 static struct type
*
6471 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6474 struct attribute
*type_attr
;
6475 struct die_info
*type_die
;
6478 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
6481 /* A missing DW_AT_type represents a void type. */
6482 return dwarf2_fundamental_type (cu
->objfile
, FT_VOID
, cu
);
6486 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6487 type_die
= follow_die_ref (ref
);
6490 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
6491 ref
, cu
->objfile
->name
);
6495 type
= tag_type_to_type (type_die
, cu
);
6498 dump_die (type_die
);
6499 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
6505 /* Return the containing type of the die in question using its
6506 DW_AT_containing_type attribute. */
6508 static struct type
*
6509 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6511 struct type
*type
= NULL
;
6512 struct attribute
*type_attr
;
6513 struct die_info
*type_die
= NULL
;
6516 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
6519 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6520 type_die
= follow_die_ref (ref
);
6523 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
6527 type
= tag_type_to_type (type_die
, cu
);
6532 dump_die (type_die
);
6533 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
6540 static struct type
*
6541 type_at_offset (unsigned int offset
, struct dwarf2_cu
*cu
)
6543 struct die_info
*die
;
6546 die
= follow_die_ref (offset
);
6549 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
6552 type
= tag_type_to_type (die
, cu
);
6557 static struct type
*
6558 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6566 read_type_die (die
, cu
);
6570 error ("Dwarf Error: Cannot find type of die [in module %s]",
6578 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6580 char *prefix
= determine_prefix (die
, cu
);
6581 const char *old_prefix
= processing_current_prefix
;
6582 struct cleanup
*back_to
= make_cleanup (xfree
, prefix
);
6583 processing_current_prefix
= prefix
;
6587 case DW_TAG_class_type
:
6588 case DW_TAG_structure_type
:
6589 case DW_TAG_union_type
:
6590 read_structure_type (die
, cu
);
6592 case DW_TAG_enumeration_type
:
6593 read_enumeration_type (die
, cu
);
6595 case DW_TAG_subprogram
:
6596 case DW_TAG_subroutine_type
:
6597 read_subroutine_type (die
, cu
);
6599 case DW_TAG_array_type
:
6600 read_array_type (die
, cu
);
6602 case DW_TAG_pointer_type
:
6603 read_tag_pointer_type (die
, cu
);
6605 case DW_TAG_ptr_to_member_type
:
6606 read_tag_ptr_to_member_type (die
, cu
);
6608 case DW_TAG_reference_type
:
6609 read_tag_reference_type (die
, cu
);
6611 case DW_TAG_const_type
:
6612 read_tag_const_type (die
, cu
);
6614 case DW_TAG_volatile_type
:
6615 read_tag_volatile_type (die
, cu
);
6617 case DW_TAG_string_type
:
6618 read_tag_string_type (die
, cu
);
6620 case DW_TAG_typedef
:
6621 read_typedef (die
, cu
);
6623 case DW_TAG_subrange_type
:
6624 read_subrange_type (die
, cu
);
6626 case DW_TAG_base_type
:
6627 read_base_type (die
, cu
);
6630 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
6631 dwarf_tag_name (die
->tag
));
6635 processing_current_prefix
= old_prefix
;
6636 do_cleanups (back_to
);
6639 /* Return the name of the namespace/class that DIE is defined within,
6640 or "" if we can't tell. The caller should xfree the result. */
6642 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
6643 therein) for an example of how to use this function to deal with
6644 DW_AT_specification. */
6647 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
6649 struct die_info
*parent
;
6651 if (cu
->language
!= language_cplus
)
6654 parent
= die
->parent
;
6658 return xstrdup ("");
6662 switch (parent
->tag
) {
6663 case DW_TAG_namespace
:
6665 /* FIXME: carlton/2004-03-05: Should I follow extension dies
6666 before doing this check? */
6667 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
6669 return xstrdup (TYPE_TAG_NAME (parent
->type
));
6674 char *parent_prefix
= determine_prefix (parent
, cu
);
6675 char *retval
= typename_concat (parent_prefix
,
6676 namespace_name (parent
, &dummy
,
6678 xfree (parent_prefix
);
6683 case DW_TAG_class_type
:
6684 case DW_TAG_structure_type
:
6686 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
6688 return xstrdup (TYPE_TAG_NAME (parent
->type
));
6692 const char *old_prefix
= processing_current_prefix
;
6693 char *new_prefix
= determine_prefix (parent
, cu
);
6696 processing_current_prefix
= new_prefix
;
6697 retval
= determine_class_name (parent
, cu
);
6698 processing_current_prefix
= old_prefix
;
6705 return determine_prefix (parent
, cu
);
6710 /* Return a newly-allocated string formed by concatenating PREFIX,
6711 "::", and SUFFIX, except that if PREFIX is NULL or the empty
6712 string, just return a copy of SUFFIX. */
6715 typename_concat (const char *prefix
, const char *suffix
)
6717 if (prefix
== NULL
|| prefix
[0] == '\0')
6718 return xstrdup (suffix
);
6721 char *retval
= xmalloc (strlen (prefix
) + 2 + strlen (suffix
) + 1);
6723 strcpy (retval
, prefix
);
6724 strcat (retval
, "::");
6725 strcat (retval
, suffix
);
6731 static struct type
*
6732 dwarf_base_type (int encoding
, int size
, struct dwarf2_cu
*cu
)
6734 struct objfile
*objfile
= cu
->objfile
;
6736 /* FIXME - this should not produce a new (struct type *)
6737 every time. It should cache base types. */
6741 case DW_ATE_address
:
6742 type
= dwarf2_fundamental_type (objfile
, FT_VOID
, cu
);
6744 case DW_ATE_boolean
:
6745 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
, cu
);
6747 case DW_ATE_complex_float
:
6750 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
, cu
);
6754 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
, cu
);
6760 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
6764 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
6771 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6774 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
, cu
);
6778 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6782 case DW_ATE_signed_char
:
6783 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6785 case DW_ATE_unsigned
:
6789 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6792 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
, cu
);
6796 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
, cu
);
6800 case DW_ATE_unsigned_char
:
6801 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6804 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6811 copy_die (struct die_info
*old_die
)
6813 struct die_info
*new_die
;
6816 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6817 memset (new_die
, 0, sizeof (struct die_info
));
6819 new_die
->tag
= old_die
->tag
;
6820 new_die
->has_children
= old_die
->has_children
;
6821 new_die
->abbrev
= old_die
->abbrev
;
6822 new_die
->offset
= old_die
->offset
;
6823 new_die
->type
= NULL
;
6825 num_attrs
= old_die
->num_attrs
;
6826 new_die
->num_attrs
= num_attrs
;
6827 new_die
->attrs
= (struct attribute
*)
6828 xmalloc (num_attrs
* sizeof (struct attribute
));
6830 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
6832 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
6833 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
6834 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
6837 new_die
->next
= NULL
;
6842 /* Return sibling of die, NULL if no sibling. */
6844 static struct die_info
*
6845 sibling_die (struct die_info
*die
)
6847 return die
->sibling
;
6850 /* Get linkage name of a die, return NULL if not found. */
6853 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6855 struct attribute
*attr
;
6857 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6858 if (attr
&& DW_STRING (attr
))
6859 return DW_STRING (attr
);
6860 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6861 if (attr
&& DW_STRING (attr
))
6862 return DW_STRING (attr
);
6866 /* Get name of a die, return NULL if not found. */
6869 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6871 struct attribute
*attr
;
6873 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6874 if (attr
&& DW_STRING (attr
))
6875 return DW_STRING (attr
);
6879 /* Return the die that this die in an extension of, or NULL if there
6882 static struct die_info
*
6883 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
6885 struct attribute
*attr
;
6886 struct die_info
*extension_die
;
6889 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
6893 ref
= dwarf2_get_ref_die_offset (attr
, cu
);
6894 extension_die
= follow_die_ref (ref
);
6897 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
6900 return extension_die
;
6903 /* Convert a DIE tag into its string name. */
6906 dwarf_tag_name (unsigned tag
)
6910 case DW_TAG_padding
:
6911 return "DW_TAG_padding";
6912 case DW_TAG_array_type
:
6913 return "DW_TAG_array_type";
6914 case DW_TAG_class_type
:
6915 return "DW_TAG_class_type";
6916 case DW_TAG_entry_point
:
6917 return "DW_TAG_entry_point";
6918 case DW_TAG_enumeration_type
:
6919 return "DW_TAG_enumeration_type";
6920 case DW_TAG_formal_parameter
:
6921 return "DW_TAG_formal_parameter";
6922 case DW_TAG_imported_declaration
:
6923 return "DW_TAG_imported_declaration";
6925 return "DW_TAG_label";
6926 case DW_TAG_lexical_block
:
6927 return "DW_TAG_lexical_block";
6929 return "DW_TAG_member";
6930 case DW_TAG_pointer_type
:
6931 return "DW_TAG_pointer_type";
6932 case DW_TAG_reference_type
:
6933 return "DW_TAG_reference_type";
6934 case DW_TAG_compile_unit
:
6935 return "DW_TAG_compile_unit";
6936 case DW_TAG_string_type
:
6937 return "DW_TAG_string_type";
6938 case DW_TAG_structure_type
:
6939 return "DW_TAG_structure_type";
6940 case DW_TAG_subroutine_type
:
6941 return "DW_TAG_subroutine_type";
6942 case DW_TAG_typedef
:
6943 return "DW_TAG_typedef";
6944 case DW_TAG_union_type
:
6945 return "DW_TAG_union_type";
6946 case DW_TAG_unspecified_parameters
:
6947 return "DW_TAG_unspecified_parameters";
6948 case DW_TAG_variant
:
6949 return "DW_TAG_variant";
6950 case DW_TAG_common_block
:
6951 return "DW_TAG_common_block";
6952 case DW_TAG_common_inclusion
:
6953 return "DW_TAG_common_inclusion";
6954 case DW_TAG_inheritance
:
6955 return "DW_TAG_inheritance";
6956 case DW_TAG_inlined_subroutine
:
6957 return "DW_TAG_inlined_subroutine";
6959 return "DW_TAG_module";
6960 case DW_TAG_ptr_to_member_type
:
6961 return "DW_TAG_ptr_to_member_type";
6962 case DW_TAG_set_type
:
6963 return "DW_TAG_set_type";
6964 case DW_TAG_subrange_type
:
6965 return "DW_TAG_subrange_type";
6966 case DW_TAG_with_stmt
:
6967 return "DW_TAG_with_stmt";
6968 case DW_TAG_access_declaration
:
6969 return "DW_TAG_access_declaration";
6970 case DW_TAG_base_type
:
6971 return "DW_TAG_base_type";
6972 case DW_TAG_catch_block
:
6973 return "DW_TAG_catch_block";
6974 case DW_TAG_const_type
:
6975 return "DW_TAG_const_type";
6976 case DW_TAG_constant
:
6977 return "DW_TAG_constant";
6978 case DW_TAG_enumerator
:
6979 return "DW_TAG_enumerator";
6980 case DW_TAG_file_type
:
6981 return "DW_TAG_file_type";
6983 return "DW_TAG_friend";
6984 case DW_TAG_namelist
:
6985 return "DW_TAG_namelist";
6986 case DW_TAG_namelist_item
:
6987 return "DW_TAG_namelist_item";
6988 case DW_TAG_packed_type
:
6989 return "DW_TAG_packed_type";
6990 case DW_TAG_subprogram
:
6991 return "DW_TAG_subprogram";
6992 case DW_TAG_template_type_param
:
6993 return "DW_TAG_template_type_param";
6994 case DW_TAG_template_value_param
:
6995 return "DW_TAG_template_value_param";
6996 case DW_TAG_thrown_type
:
6997 return "DW_TAG_thrown_type";
6998 case DW_TAG_try_block
:
6999 return "DW_TAG_try_block";
7000 case DW_TAG_variant_part
:
7001 return "DW_TAG_variant_part";
7002 case DW_TAG_variable
:
7003 return "DW_TAG_variable";
7004 case DW_TAG_volatile_type
:
7005 return "DW_TAG_volatile_type";
7006 case DW_TAG_dwarf_procedure
:
7007 return "DW_TAG_dwarf_procedure";
7008 case DW_TAG_restrict_type
:
7009 return "DW_TAG_restrict_type";
7010 case DW_TAG_interface_type
:
7011 return "DW_TAG_interface_type";
7012 case DW_TAG_namespace
:
7013 return "DW_TAG_namespace";
7014 case DW_TAG_imported_module
:
7015 return "DW_TAG_imported_module";
7016 case DW_TAG_unspecified_type
:
7017 return "DW_TAG_unspecified_type";
7018 case DW_TAG_partial_unit
:
7019 return "DW_TAG_partial_unit";
7020 case DW_TAG_imported_unit
:
7021 return "DW_TAG_imported_unit";
7022 case DW_TAG_MIPS_loop
:
7023 return "DW_TAG_MIPS_loop";
7024 case DW_TAG_format_label
:
7025 return "DW_TAG_format_label";
7026 case DW_TAG_function_template
:
7027 return "DW_TAG_function_template";
7028 case DW_TAG_class_template
:
7029 return "DW_TAG_class_template";
7031 return "DW_TAG_<unknown>";
7035 /* Convert a DWARF attribute code into its string name. */
7038 dwarf_attr_name (unsigned attr
)
7043 return "DW_AT_sibling";
7044 case DW_AT_location
:
7045 return "DW_AT_location";
7047 return "DW_AT_name";
7048 case DW_AT_ordering
:
7049 return "DW_AT_ordering";
7050 case DW_AT_subscr_data
:
7051 return "DW_AT_subscr_data";
7052 case DW_AT_byte_size
:
7053 return "DW_AT_byte_size";
7054 case DW_AT_bit_offset
:
7055 return "DW_AT_bit_offset";
7056 case DW_AT_bit_size
:
7057 return "DW_AT_bit_size";
7058 case DW_AT_element_list
:
7059 return "DW_AT_element_list";
7060 case DW_AT_stmt_list
:
7061 return "DW_AT_stmt_list";
7063 return "DW_AT_low_pc";
7065 return "DW_AT_high_pc";
7066 case DW_AT_language
:
7067 return "DW_AT_language";
7069 return "DW_AT_member";
7071 return "DW_AT_discr";
7072 case DW_AT_discr_value
:
7073 return "DW_AT_discr_value";
7074 case DW_AT_visibility
:
7075 return "DW_AT_visibility";
7077 return "DW_AT_import";
7078 case DW_AT_string_length
:
7079 return "DW_AT_string_length";
7080 case DW_AT_common_reference
:
7081 return "DW_AT_common_reference";
7082 case DW_AT_comp_dir
:
7083 return "DW_AT_comp_dir";
7084 case DW_AT_const_value
:
7085 return "DW_AT_const_value";
7086 case DW_AT_containing_type
:
7087 return "DW_AT_containing_type";
7088 case DW_AT_default_value
:
7089 return "DW_AT_default_value";
7091 return "DW_AT_inline";
7092 case DW_AT_is_optional
:
7093 return "DW_AT_is_optional";
7094 case DW_AT_lower_bound
:
7095 return "DW_AT_lower_bound";
7096 case DW_AT_producer
:
7097 return "DW_AT_producer";
7098 case DW_AT_prototyped
:
7099 return "DW_AT_prototyped";
7100 case DW_AT_return_addr
:
7101 return "DW_AT_return_addr";
7102 case DW_AT_start_scope
:
7103 return "DW_AT_start_scope";
7104 case DW_AT_stride_size
:
7105 return "DW_AT_stride_size";
7106 case DW_AT_upper_bound
:
7107 return "DW_AT_upper_bound";
7108 case DW_AT_abstract_origin
:
7109 return "DW_AT_abstract_origin";
7110 case DW_AT_accessibility
:
7111 return "DW_AT_accessibility";
7112 case DW_AT_address_class
:
7113 return "DW_AT_address_class";
7114 case DW_AT_artificial
:
7115 return "DW_AT_artificial";
7116 case DW_AT_base_types
:
7117 return "DW_AT_base_types";
7118 case DW_AT_calling_convention
:
7119 return "DW_AT_calling_convention";
7121 return "DW_AT_count";
7122 case DW_AT_data_member_location
:
7123 return "DW_AT_data_member_location";
7124 case DW_AT_decl_column
:
7125 return "DW_AT_decl_column";
7126 case DW_AT_decl_file
:
7127 return "DW_AT_decl_file";
7128 case DW_AT_decl_line
:
7129 return "DW_AT_decl_line";
7130 case DW_AT_declaration
:
7131 return "DW_AT_declaration";
7132 case DW_AT_discr_list
:
7133 return "DW_AT_discr_list";
7134 case DW_AT_encoding
:
7135 return "DW_AT_encoding";
7136 case DW_AT_external
:
7137 return "DW_AT_external";
7138 case DW_AT_frame_base
:
7139 return "DW_AT_frame_base";
7141 return "DW_AT_friend";
7142 case DW_AT_identifier_case
:
7143 return "DW_AT_identifier_case";
7144 case DW_AT_macro_info
:
7145 return "DW_AT_macro_info";
7146 case DW_AT_namelist_items
:
7147 return "DW_AT_namelist_items";
7148 case DW_AT_priority
:
7149 return "DW_AT_priority";
7151 return "DW_AT_segment";
7152 case DW_AT_specification
:
7153 return "DW_AT_specification";
7154 case DW_AT_static_link
:
7155 return "DW_AT_static_link";
7157 return "DW_AT_type";
7158 case DW_AT_use_location
:
7159 return "DW_AT_use_location";
7160 case DW_AT_variable_parameter
:
7161 return "DW_AT_variable_parameter";
7162 case DW_AT_virtuality
:
7163 return "DW_AT_virtuality";
7164 case DW_AT_vtable_elem_location
:
7165 return "DW_AT_vtable_elem_location";
7166 case DW_AT_allocated
:
7167 return "DW_AT_allocated";
7168 case DW_AT_associated
:
7169 return "DW_AT_associated";
7170 case DW_AT_data_location
:
7171 return "DW_AT_data_location";
7173 return "DW_AT_stride";
7174 case DW_AT_entry_pc
:
7175 return "DW_AT_entry_pc";
7176 case DW_AT_use_UTF8
:
7177 return "DW_AT_use_UTF8";
7178 case DW_AT_extension
:
7179 return "DW_AT_extension";
7181 return "DW_AT_ranges";
7182 case DW_AT_trampoline
:
7183 return "DW_AT_trampoline";
7184 case DW_AT_call_column
:
7185 return "DW_AT_call_column";
7186 case DW_AT_call_file
:
7187 return "DW_AT_call_file";
7188 case DW_AT_call_line
:
7189 return "DW_AT_call_line";
7191 case DW_AT_MIPS_fde
:
7192 return "DW_AT_MIPS_fde";
7193 case DW_AT_MIPS_loop_begin
:
7194 return "DW_AT_MIPS_loop_begin";
7195 case DW_AT_MIPS_tail_loop_begin
:
7196 return "DW_AT_MIPS_tail_loop_begin";
7197 case DW_AT_MIPS_epilog_begin
:
7198 return "DW_AT_MIPS_epilog_begin";
7199 case DW_AT_MIPS_loop_unroll_factor
:
7200 return "DW_AT_MIPS_loop_unroll_factor";
7201 case DW_AT_MIPS_software_pipeline_depth
:
7202 return "DW_AT_MIPS_software_pipeline_depth";
7204 case DW_AT_MIPS_linkage_name
:
7205 return "DW_AT_MIPS_linkage_name";
7207 case DW_AT_sf_names
:
7208 return "DW_AT_sf_names";
7209 case DW_AT_src_info
:
7210 return "DW_AT_src_info";
7211 case DW_AT_mac_info
:
7212 return "DW_AT_mac_info";
7213 case DW_AT_src_coords
:
7214 return "DW_AT_src_coords";
7215 case DW_AT_body_begin
:
7216 return "DW_AT_body_begin";
7217 case DW_AT_body_end
:
7218 return "DW_AT_body_end";
7219 case DW_AT_GNU_vector
:
7220 return "DW_AT_GNU_vector";
7222 return "DW_AT_<unknown>";
7226 /* Convert a DWARF value form code into its string name. */
7229 dwarf_form_name (unsigned form
)
7234 return "DW_FORM_addr";
7235 case DW_FORM_block2
:
7236 return "DW_FORM_block2";
7237 case DW_FORM_block4
:
7238 return "DW_FORM_block4";
7240 return "DW_FORM_data2";
7242 return "DW_FORM_data4";
7244 return "DW_FORM_data8";
7245 case DW_FORM_string
:
7246 return "DW_FORM_string";
7248 return "DW_FORM_block";
7249 case DW_FORM_block1
:
7250 return "DW_FORM_block1";
7252 return "DW_FORM_data1";
7254 return "DW_FORM_flag";
7256 return "DW_FORM_sdata";
7258 return "DW_FORM_strp";
7260 return "DW_FORM_udata";
7261 case DW_FORM_ref_addr
:
7262 return "DW_FORM_ref_addr";
7264 return "DW_FORM_ref1";
7266 return "DW_FORM_ref2";
7268 return "DW_FORM_ref4";
7270 return "DW_FORM_ref8";
7271 case DW_FORM_ref_udata
:
7272 return "DW_FORM_ref_udata";
7273 case DW_FORM_indirect
:
7274 return "DW_FORM_indirect";
7276 return "DW_FORM_<unknown>";
7280 /* Convert a DWARF stack opcode into its string name. */
7283 dwarf_stack_op_name (unsigned op
)
7288 return "DW_OP_addr";
7290 return "DW_OP_deref";
7292 return "DW_OP_const1u";
7294 return "DW_OP_const1s";
7296 return "DW_OP_const2u";
7298 return "DW_OP_const2s";
7300 return "DW_OP_const4u";
7302 return "DW_OP_const4s";
7304 return "DW_OP_const8u";
7306 return "DW_OP_const8s";
7308 return "DW_OP_constu";
7310 return "DW_OP_consts";
7314 return "DW_OP_drop";
7316 return "DW_OP_over";
7318 return "DW_OP_pick";
7320 return "DW_OP_swap";
7324 return "DW_OP_xderef";
7332 return "DW_OP_minus";
7344 return "DW_OP_plus";
7345 case DW_OP_plus_uconst
:
7346 return "DW_OP_plus_uconst";
7352 return "DW_OP_shra";
7370 return "DW_OP_skip";
7372 return "DW_OP_lit0";
7374 return "DW_OP_lit1";
7376 return "DW_OP_lit2";
7378 return "DW_OP_lit3";
7380 return "DW_OP_lit4";
7382 return "DW_OP_lit5";
7384 return "DW_OP_lit6";
7386 return "DW_OP_lit7";
7388 return "DW_OP_lit8";
7390 return "DW_OP_lit9";
7392 return "DW_OP_lit10";
7394 return "DW_OP_lit11";
7396 return "DW_OP_lit12";
7398 return "DW_OP_lit13";
7400 return "DW_OP_lit14";
7402 return "DW_OP_lit15";
7404 return "DW_OP_lit16";
7406 return "DW_OP_lit17";
7408 return "DW_OP_lit18";
7410 return "DW_OP_lit19";
7412 return "DW_OP_lit20";
7414 return "DW_OP_lit21";
7416 return "DW_OP_lit22";
7418 return "DW_OP_lit23";
7420 return "DW_OP_lit24";
7422 return "DW_OP_lit25";
7424 return "DW_OP_lit26";
7426 return "DW_OP_lit27";
7428 return "DW_OP_lit28";
7430 return "DW_OP_lit29";
7432 return "DW_OP_lit30";
7434 return "DW_OP_lit31";
7436 return "DW_OP_reg0";
7438 return "DW_OP_reg1";
7440 return "DW_OP_reg2";
7442 return "DW_OP_reg3";
7444 return "DW_OP_reg4";
7446 return "DW_OP_reg5";
7448 return "DW_OP_reg6";
7450 return "DW_OP_reg7";
7452 return "DW_OP_reg8";
7454 return "DW_OP_reg9";
7456 return "DW_OP_reg10";
7458 return "DW_OP_reg11";
7460 return "DW_OP_reg12";
7462 return "DW_OP_reg13";
7464 return "DW_OP_reg14";
7466 return "DW_OP_reg15";
7468 return "DW_OP_reg16";
7470 return "DW_OP_reg17";
7472 return "DW_OP_reg18";
7474 return "DW_OP_reg19";
7476 return "DW_OP_reg20";
7478 return "DW_OP_reg21";
7480 return "DW_OP_reg22";
7482 return "DW_OP_reg23";
7484 return "DW_OP_reg24";
7486 return "DW_OP_reg25";
7488 return "DW_OP_reg26";
7490 return "DW_OP_reg27";
7492 return "DW_OP_reg28";
7494 return "DW_OP_reg29";
7496 return "DW_OP_reg30";
7498 return "DW_OP_reg31";
7500 return "DW_OP_breg0";
7502 return "DW_OP_breg1";
7504 return "DW_OP_breg2";
7506 return "DW_OP_breg3";
7508 return "DW_OP_breg4";
7510 return "DW_OP_breg5";
7512 return "DW_OP_breg6";
7514 return "DW_OP_breg7";
7516 return "DW_OP_breg8";
7518 return "DW_OP_breg9";
7520 return "DW_OP_breg10";
7522 return "DW_OP_breg11";
7524 return "DW_OP_breg12";
7526 return "DW_OP_breg13";
7528 return "DW_OP_breg14";
7530 return "DW_OP_breg15";
7532 return "DW_OP_breg16";
7534 return "DW_OP_breg17";
7536 return "DW_OP_breg18";
7538 return "DW_OP_breg19";
7540 return "DW_OP_breg20";
7542 return "DW_OP_breg21";
7544 return "DW_OP_breg22";
7546 return "DW_OP_breg23";
7548 return "DW_OP_breg24";
7550 return "DW_OP_breg25";
7552 return "DW_OP_breg26";
7554 return "DW_OP_breg27";
7556 return "DW_OP_breg28";
7558 return "DW_OP_breg29";
7560 return "DW_OP_breg30";
7562 return "DW_OP_breg31";
7564 return "DW_OP_regx";
7566 return "DW_OP_fbreg";
7568 return "DW_OP_bregx";
7570 return "DW_OP_piece";
7571 case DW_OP_deref_size
:
7572 return "DW_OP_deref_size";
7573 case DW_OP_xderef_size
:
7574 return "DW_OP_xderef_size";
7577 /* DWARF 3 extensions. */
7578 case DW_OP_push_object_address
:
7579 return "DW_OP_push_object_address";
7581 return "DW_OP_call2";
7583 return "DW_OP_call4";
7584 case DW_OP_call_ref
:
7585 return "DW_OP_call_ref";
7586 /* GNU extensions. */
7587 case DW_OP_GNU_push_tls_address
:
7588 return "DW_OP_GNU_push_tls_address";
7590 return "OP_<unknown>";
7595 dwarf_bool_name (unsigned mybool
)
7603 /* Convert a DWARF type code into its string name. */
7606 dwarf_type_encoding_name (unsigned enc
)
7610 case DW_ATE_address
:
7611 return "DW_ATE_address";
7612 case DW_ATE_boolean
:
7613 return "DW_ATE_boolean";
7614 case DW_ATE_complex_float
:
7615 return "DW_ATE_complex_float";
7617 return "DW_ATE_float";
7619 return "DW_ATE_signed";
7620 case DW_ATE_signed_char
:
7621 return "DW_ATE_signed_char";
7622 case DW_ATE_unsigned
:
7623 return "DW_ATE_unsigned";
7624 case DW_ATE_unsigned_char
:
7625 return "DW_ATE_unsigned_char";
7626 case DW_ATE_imaginary_float
:
7627 return "DW_ATE_imaginary_float";
7629 return "DW_ATE_<unknown>";
7633 /* Convert a DWARF call frame info operation to its string name. */
7637 dwarf_cfi_name (unsigned cfi_opc
)
7641 case DW_CFA_advance_loc
:
7642 return "DW_CFA_advance_loc";
7644 return "DW_CFA_offset";
7645 case DW_CFA_restore
:
7646 return "DW_CFA_restore";
7648 return "DW_CFA_nop";
7649 case DW_CFA_set_loc
:
7650 return "DW_CFA_set_loc";
7651 case DW_CFA_advance_loc1
:
7652 return "DW_CFA_advance_loc1";
7653 case DW_CFA_advance_loc2
:
7654 return "DW_CFA_advance_loc2";
7655 case DW_CFA_advance_loc4
:
7656 return "DW_CFA_advance_loc4";
7657 case DW_CFA_offset_extended
:
7658 return "DW_CFA_offset_extended";
7659 case DW_CFA_restore_extended
:
7660 return "DW_CFA_restore_extended";
7661 case DW_CFA_undefined
:
7662 return "DW_CFA_undefined";
7663 case DW_CFA_same_value
:
7664 return "DW_CFA_same_value";
7665 case DW_CFA_register
:
7666 return "DW_CFA_register";
7667 case DW_CFA_remember_state
:
7668 return "DW_CFA_remember_state";
7669 case DW_CFA_restore_state
:
7670 return "DW_CFA_restore_state";
7671 case DW_CFA_def_cfa
:
7672 return "DW_CFA_def_cfa";
7673 case DW_CFA_def_cfa_register
:
7674 return "DW_CFA_def_cfa_register";
7675 case DW_CFA_def_cfa_offset
:
7676 return "DW_CFA_def_cfa_offset";
7679 case DW_CFA_def_cfa_expression
:
7680 return "DW_CFA_def_cfa_expression";
7681 case DW_CFA_expression
:
7682 return "DW_CFA_expression";
7683 case DW_CFA_offset_extended_sf
:
7684 return "DW_CFA_offset_extended_sf";
7685 case DW_CFA_def_cfa_sf
:
7686 return "DW_CFA_def_cfa_sf";
7687 case DW_CFA_def_cfa_offset_sf
:
7688 return "DW_CFA_def_cfa_offset_sf";
7690 /* SGI/MIPS specific */
7691 case DW_CFA_MIPS_advance_loc8
:
7692 return "DW_CFA_MIPS_advance_loc8";
7694 /* GNU extensions */
7695 case DW_CFA_GNU_window_save
:
7696 return "DW_CFA_GNU_window_save";
7697 case DW_CFA_GNU_args_size
:
7698 return "DW_CFA_GNU_args_size";
7699 case DW_CFA_GNU_negative_offset_extended
:
7700 return "DW_CFA_GNU_negative_offset_extended";
7703 return "DW_CFA_<unknown>";
7709 dump_die (struct die_info
*die
)
7713 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
7714 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
7715 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
7716 dwarf_bool_name (die
->child
!= NULL
));
7718 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
7719 for (i
= 0; i
< die
->num_attrs
; ++i
)
7721 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
7722 dwarf_attr_name (die
->attrs
[i
].name
),
7723 dwarf_form_name (die
->attrs
[i
].form
));
7724 switch (die
->attrs
[i
].form
)
7726 case DW_FORM_ref_addr
:
7728 fprintf_unfiltered (gdb_stderr
, "address: ");
7729 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
7731 case DW_FORM_block2
:
7732 case DW_FORM_block4
:
7734 case DW_FORM_block1
:
7735 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
7746 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
7748 case DW_FORM_string
:
7750 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
7751 DW_STRING (&die
->attrs
[i
])
7752 ? DW_STRING (&die
->attrs
[i
]) : "");
7755 if (DW_UNSND (&die
->attrs
[i
]))
7756 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
7758 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
7760 case DW_FORM_indirect
:
7761 /* the reader will have reduced the indirect form to
7762 the "base form" so this form should not occur */
7763 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
7766 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
7767 die
->attrs
[i
].form
);
7769 fprintf_unfiltered (gdb_stderr
, "\n");
7774 dump_die_list (struct die_info
*die
)
7779 if (die
->child
!= NULL
)
7780 dump_die_list (die
->child
);
7781 if (die
->sibling
!= NULL
)
7782 dump_die_list (die
->sibling
);
7787 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
7790 struct die_info
*old
;
7792 h
= (offset
% REF_HASH_SIZE
);
7793 old
= die_ref_table
[h
];
7794 die
->next_ref
= old
;
7795 die_ref_table
[h
] = die
;
7800 dwarf2_empty_hash_tables (void)
7802 memset (die_ref_table
, 0, sizeof (die_ref_table
));
7806 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
7808 unsigned int result
= 0;
7812 case DW_FORM_ref_addr
:
7813 result
= DW_ADDR (attr
);
7819 case DW_FORM_ref_udata
:
7820 result
= cu
->header
.offset
+ DW_UNSND (attr
);
7823 complaint (&symfile_complaints
,
7824 "unsupported die ref attribute form: '%s'",
7825 dwarf_form_name (attr
->form
));
7830 /* Return the constant value held by the given attribute. Return -1
7831 if the value held by the attribute is not constant. */
7834 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
7836 if (attr
->form
== DW_FORM_sdata
)
7837 return DW_SND (attr
);
7838 else if (attr
->form
== DW_FORM_udata
7839 || attr
->form
== DW_FORM_data1
7840 || attr
->form
== DW_FORM_data2
7841 || attr
->form
== DW_FORM_data4
7842 || attr
->form
== DW_FORM_data8
)
7843 return DW_UNSND (attr
);
7846 complaint (&symfile_complaints
, "Attribute value is not a constant (%s)",
7847 dwarf_form_name (attr
->form
));
7848 return default_value
;
7852 static struct die_info
*
7853 follow_die_ref (unsigned int offset
)
7855 struct die_info
*die
;
7858 h
= (offset
% REF_HASH_SIZE
);
7859 die
= die_ref_table
[h
];
7862 if (die
->offset
== offset
)
7866 die
= die
->next_ref
;
7871 static struct type
*
7872 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid,
7873 struct dwarf2_cu
*cu
)
7875 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
7877 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
7878 typeid, objfile
->name
);
7881 /* Look for this particular type in the fundamental type vector. If
7882 one is not found, create and install one appropriate for the
7883 current language and the current target machine. */
7885 if (cu
->ftypes
[typeid] == NULL
)
7887 cu
->ftypes
[typeid] = cu
->language_defn
->la_fund_type (objfile
, typeid);
7890 return (cu
->ftypes
[typeid]);
7893 /* Decode simple location descriptions.
7894 Given a pointer to a dwarf block that defines a location, compute
7895 the location and return the value.
7897 NOTE drow/2003-11-18: This function is called in two situations
7898 now: for the address of static or global variables (partial symbols
7899 only) and for offsets into structures which are expected to be
7900 (more or less) constant. The partial symbol case should go away,
7901 and only the constant case should remain. That will let this
7902 function complain more accurately. A few special modes are allowed
7903 without complaint for global variables (for instance, global
7904 register values and thread-local values).
7906 A location description containing no operations indicates that the
7907 object is optimized out. The return value is 0 for that case.
7908 FIXME drow/2003-11-16: No callers check for this case any more; soon all
7909 callers will only want a very basic result and this can become a
7912 When the result is a register number, the global isreg flag is set,
7913 otherwise it is cleared.
7915 Note that stack[0] is unused except as a default error return.
7916 Note that stack overflow is not yet handled. */
7919 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
7921 struct objfile
*objfile
= cu
->objfile
;
7922 struct comp_unit_head
*cu_header
= &cu
->header
;
7924 int size
= blk
->size
;
7925 char *data
= blk
->data
;
7926 CORE_ADDR stack
[64];
7928 unsigned int bytes_read
, unsnd
;
7973 stack
[++stacki
] = op
- DW_OP_lit0
;
8009 stack
[++stacki
] = op
- DW_OP_reg0
;
8011 dwarf2_complex_location_expr_complaint ();
8016 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
8018 stack
[++stacki
] = unsnd
;
8020 dwarf2_complex_location_expr_complaint ();
8024 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
8030 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
8035 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
8040 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
8045 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
8050 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
8055 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
8060 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
8066 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
8071 stack
[stacki
+ 1] = stack
[stacki
];
8076 stack
[stacki
- 1] += stack
[stacki
];
8080 case DW_OP_plus_uconst
:
8081 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
8086 stack
[stacki
- 1] -= stack
[stacki
];
8091 /* If we're not the last op, then we definitely can't encode
8092 this using GDB's address_class enum. This is valid for partial
8093 global symbols, although the variable's address will be bogus
8096 dwarf2_complex_location_expr_complaint ();
8099 case DW_OP_GNU_push_tls_address
:
8100 /* The top of the stack has the offset from the beginning
8101 of the thread control block at which the variable is located. */
8102 /* Nothing should follow this operator, so the top of stack would
8104 /* This is valid for partial global symbols, but the variable's
8105 address will be bogus in the psymtab. */
8107 dwarf2_complex_location_expr_complaint ();
8111 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
8112 dwarf_stack_op_name (op
));
8113 return (stack
[stacki
]);
8116 return (stack
[stacki
]);
8119 /* memory allocation interface */
8122 dwarf2_free_tmp_obstack (void *ignore
)
8124 obstack_free (&dwarf2_tmp_obstack
, NULL
);
8127 static struct dwarf_block
*
8128 dwarf_alloc_block (void)
8130 struct dwarf_block
*blk
;
8132 blk
= (struct dwarf_block
*)
8133 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
8137 static struct abbrev_info
*
8138 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
8140 struct abbrev_info
*abbrev
;
8142 abbrev
= (struct abbrev_info
*)
8143 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
8144 memset (abbrev
, 0, sizeof (struct abbrev_info
));
8148 static struct die_info
*
8149 dwarf_alloc_die (void)
8151 struct die_info
*die
;
8153 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
8154 memset (die
, 0, sizeof (struct die_info
));
8159 /* Macro support. */
8162 /* Return the full name of file number I in *LH's file name table.
8163 Use COMP_DIR as the name of the current directory of the
8164 compilation. The result is allocated using xmalloc; the caller is
8165 responsible for freeing it. */
8167 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
8169 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
8171 if (IS_ABSOLUTE_PATH (fe
->name
))
8172 return xstrdup (fe
->name
);
8180 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8186 dir_len
= strlen (dir
);
8187 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
8188 strcpy (full_name
, dir
);
8189 full_name
[dir_len
] = '/';
8190 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
8194 return xstrdup (fe
->name
);
8199 static struct macro_source_file
*
8200 macro_start_file (int file
, int line
,
8201 struct macro_source_file
*current_file
,
8202 const char *comp_dir
,
8203 struct line_header
*lh
, struct objfile
*objfile
)
8205 /* The full name of this source file. */
8206 char *full_name
= file_full_name (file
, lh
, comp_dir
);
8208 /* We don't create a macro table for this compilation unit
8209 at all until we actually get a filename. */
8210 if (! pending_macros
)
8211 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
8212 objfile
->macro_cache
);
8215 /* If we have no current file, then this must be the start_file
8216 directive for the compilation unit's main source file. */
8217 current_file
= macro_set_main (pending_macros
, full_name
);
8219 current_file
= macro_include (current_file
, line
, full_name
);
8223 return current_file
;
8227 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
8228 followed by a null byte. */
8230 copy_string (const char *buf
, int len
)
8232 char *s
= xmalloc (len
+ 1);
8233 memcpy (s
, buf
, len
);
8241 consume_improper_spaces (const char *p
, const char *body
)
8245 complaint (&symfile_complaints
,
8246 "macro definition contains spaces in formal argument list:\n`%s'",
8258 parse_macro_definition (struct macro_source_file
*file
, int line
,
8263 /* The body string takes one of two forms. For object-like macro
8264 definitions, it should be:
8266 <macro name> " " <definition>
8268 For function-like macro definitions, it should be:
8270 <macro name> "() " <definition>
8272 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
8274 Spaces may appear only where explicitly indicated, and in the
8277 The Dwarf 2 spec says that an object-like macro's name is always
8278 followed by a space, but versions of GCC around March 2002 omit
8279 the space when the macro's definition is the empty string.
8281 The Dwarf 2 spec says that there should be no spaces between the
8282 formal arguments in a function-like macro's formal argument list,
8283 but versions of GCC around March 2002 include spaces after the
8287 /* Find the extent of the macro name. The macro name is terminated
8288 by either a space or null character (for an object-like macro) or
8289 an opening paren (for a function-like macro). */
8290 for (p
= body
; *p
; p
++)
8291 if (*p
== ' ' || *p
== '(')
8294 if (*p
== ' ' || *p
== '\0')
8296 /* It's an object-like macro. */
8297 int name_len
= p
- body
;
8298 char *name
= copy_string (body
, name_len
);
8299 const char *replacement
;
8302 replacement
= body
+ name_len
+ 1;
8305 dwarf2_macro_malformed_definition_complaint (body
);
8306 replacement
= body
+ name_len
;
8309 macro_define_object (file
, line
, name
, replacement
);
8315 /* It's a function-like macro. */
8316 char *name
= copy_string (body
, p
- body
);
8319 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
8323 p
= consume_improper_spaces (p
, body
);
8325 /* Parse the formal argument list. */
8326 while (*p
&& *p
!= ')')
8328 /* Find the extent of the current argument name. */
8329 const char *arg_start
= p
;
8331 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
8334 if (! *p
|| p
== arg_start
)
8335 dwarf2_macro_malformed_definition_complaint (body
);
8338 /* Make sure argv has room for the new argument. */
8339 if (argc
>= argv_size
)
8342 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
8345 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
8348 p
= consume_improper_spaces (p
, body
);
8350 /* Consume the comma, if present. */
8355 p
= consume_improper_spaces (p
, body
);
8364 /* Perfectly formed definition, no complaints. */
8365 macro_define_function (file
, line
, name
,
8366 argc
, (const char **) argv
,
8368 else if (*p
== '\0')
8370 /* Complain, but do define it. */
8371 dwarf2_macro_malformed_definition_complaint (body
);
8372 macro_define_function (file
, line
, name
,
8373 argc
, (const char **) argv
,
8377 /* Just complain. */
8378 dwarf2_macro_malformed_definition_complaint (body
);
8381 /* Just complain. */
8382 dwarf2_macro_malformed_definition_complaint (body
);
8388 for (i
= 0; i
< argc
; i
++)
8394 dwarf2_macro_malformed_definition_complaint (body
);
8399 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
8400 char *comp_dir
, bfd
*abfd
,
8401 struct dwarf2_cu
*cu
)
8403 char *mac_ptr
, *mac_end
;
8404 struct macro_source_file
*current_file
= 0;
8406 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
8408 complaint (&symfile_complaints
, "missing .debug_macinfo section");
8412 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
8413 mac_end
= dwarf2_per_objfile
->macinfo_buffer
8414 + dwarf2_per_objfile
->macinfo_size
;
8418 enum dwarf_macinfo_record_type macinfo_type
;
8420 /* Do we at least have room for a macinfo type byte? */
8421 if (mac_ptr
>= mac_end
)
8423 dwarf2_macros_too_long_complaint ();
8427 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
8430 switch (macinfo_type
)
8432 /* A zero macinfo type indicates the end of the macro
8437 case DW_MACINFO_define
:
8438 case DW_MACINFO_undef
:
8444 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8445 mac_ptr
+= bytes_read
;
8446 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
8447 mac_ptr
+= bytes_read
;
8450 complaint (&symfile_complaints
,
8451 "debug info gives macro %s outside of any file: %s",
8453 DW_MACINFO_define
? "definition" : macinfo_type
==
8454 DW_MACINFO_undef
? "undefinition" :
8455 "something-or-other", body
);
8458 if (macinfo_type
== DW_MACINFO_define
)
8459 parse_macro_definition (current_file
, line
, body
);
8460 else if (macinfo_type
== DW_MACINFO_undef
)
8461 macro_undef (current_file
, line
, body
);
8466 case DW_MACINFO_start_file
:
8471 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8472 mac_ptr
+= bytes_read
;
8473 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8474 mac_ptr
+= bytes_read
;
8476 current_file
= macro_start_file (file
, line
,
8477 current_file
, comp_dir
,
8482 case DW_MACINFO_end_file
:
8484 complaint (&symfile_complaints
,
8485 "macro debug info has an unmatched `close_file' directive");
8488 current_file
= current_file
->included_by
;
8491 enum dwarf_macinfo_record_type next_type
;
8493 /* GCC circa March 2002 doesn't produce the zero
8494 type byte marking the end of the compilation
8495 unit. Complain if it's not there, but exit no
8498 /* Do we at least have room for a macinfo type byte? */
8499 if (mac_ptr
>= mac_end
)
8501 dwarf2_macros_too_long_complaint ();
8505 /* We don't increment mac_ptr here, so this is just
8507 next_type
= read_1_byte (abfd
, mac_ptr
);
8509 complaint (&symfile_complaints
,
8510 "no terminating 0-type entry for macros in `.debug_macinfo' section");
8517 case DW_MACINFO_vendor_ext
:
8523 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8524 mac_ptr
+= bytes_read
;
8525 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
8526 mac_ptr
+= bytes_read
;
8528 /* We don't recognize any vendor extensions. */
8535 /* Check if the attribute's form is a DW_FORM_block*
8536 if so return true else false. */
8538 attr_form_is_block (struct attribute
*attr
)
8540 return (attr
== NULL
? 0 :
8541 attr
->form
== DW_FORM_block1
8542 || attr
->form
== DW_FORM_block2
8543 || attr
->form
== DW_FORM_block4
8544 || attr
->form
== DW_FORM_block
);
8548 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
8549 struct dwarf2_cu
*cu
)
8551 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
8553 struct dwarf2_loclist_baton
*baton
;
8555 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
8556 sizeof (struct dwarf2_loclist_baton
));
8557 baton
->objfile
= cu
->objfile
;
8559 /* We don't know how long the location list is, but make sure we
8560 don't run off the edge of the section. */
8561 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
8562 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
8563 baton
->base_address
= cu
->header
.base_address
;
8564 if (cu
->header
.base_known
== 0)
8565 complaint (&symfile_complaints
,
8566 "Location list used without specifying the CU base address.");
8568 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
8569 SYMBOL_LOCATION_BATON (sym
) = baton
;
8573 struct dwarf2_locexpr_baton
*baton
;
8575 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
8576 sizeof (struct dwarf2_locexpr_baton
));
8577 baton
->objfile
= cu
->objfile
;
8579 if (attr_form_is_block (attr
))
8581 /* Note that we're just copying the block's data pointer
8582 here, not the actual data. We're still pointing into the
8583 info_buffer for SYM's objfile; right now we never release
8584 that buffer, but when we do clean up properly this may
8586 baton
->size
= DW_BLOCK (attr
)->size
;
8587 baton
->data
= DW_BLOCK (attr
)->data
;
8591 dwarf2_invalid_attrib_class_complaint ("location description",
8592 SYMBOL_NATURAL_NAME (sym
));
8597 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
8598 SYMBOL_LOCATION_BATON (sym
) = baton
;
8602 /* This cleanup function is passed the address of a dwarf2_cu on the stack
8603 when we're finished with it. We can't free the pointer itself, but
8604 release any associated storage.
8606 Only used during partial symbol parsing. */
8609 free_stack_comp_unit (void *data
)
8611 struct dwarf2_cu
*cu
= data
;
8613 obstack_free (&cu
->comp_unit_obstack
, NULL
);
8614 cu
->partial_dies
= NULL
;
8617 /* Allocation function for the libiberty hash table which uses an
8621 hashtab_obstack_allocate (void *data
, size_t size
, size_t count
)
8623 unsigned int total
= size
* count
;
8624 void *ptr
= obstack_alloc ((struct obstack
*) data
, total
);
8625 memset (ptr
, 0, total
);
8629 /* Trivial deallocation function for the libiberty splay tree and hash
8630 table - don't deallocate anything. Rely on later deletion of the
8634 dummy_obstack_deallocate (void *object
, void *data
)
8639 /* Trivial hash function for partial_die_info: the hash value of a DIE
8640 is its offset in .debug_info for this objfile. */
8643 partial_die_hash (const void *item
)
8645 const struct partial_die_info
*part_die
= item
;
8646 return part_die
->offset
;
8649 /* Trivial comparison function for partial_die_info structures: two DIEs
8650 are equal if they have the same offset. */
8653 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
8655 const struct partial_die_info
*part_die_lhs
= item_lhs
;
8656 const struct partial_die_info
*part_die_rhs
= item_rhs
;
8657 return part_die_lhs
->offset
== part_die_rhs
->offset
;
8660 void _initialize_dwarf2_read (void);
8663 _initialize_dwarf2_read (void)
8665 dwarf2_objfile_data_key
= register_objfile_data ();