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 /* Allocate fields for structs, unions and enums in this size. */
498 #ifndef DW_FIELD_ALLOC_CHUNK
499 #define DW_FIELD_ALLOC_CHUNK 4
502 /* A zeroed version of a partial die for initialization purposes. */
503 static struct partial_die_info zeroed_partial_die
;
505 /* FIXME: decode_locdesc sets these variables to describe the location
506 to the caller. These ought to be a structure or something. If
507 none of the flags are set, the object lives at the address returned
508 by decode_locdesc. */
510 static int isreg
; /* Object lives in register.
511 decode_locdesc's return value is
512 the register number. */
514 /* We put a pointer to this structure in the read_symtab_private field
519 /* Offset in .debug_info for this compilation unit. */
521 unsigned long dwarf_info_offset
;
524 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
525 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
527 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
528 but this would require a corresponding change in unpack_field_as_long
530 static int bits_per_byte
= 8;
532 /* The routines that read and process dies for a C struct or C++ class
533 pass lists of data member fields and lists of member function fields
534 in an instance of a field_info structure, as defined below. */
537 /* List of data member and baseclasses fields. */
540 struct nextfield
*next
;
547 /* Number of fields. */
550 /* Number of baseclasses. */
553 /* Set if the accesibility of one of the fields is not public. */
554 int non_public_fields
;
556 /* Member function fields array, entries are allocated in the order they
557 are encountered in the object file. */
560 struct nextfnfield
*next
;
561 struct fn_field fnfield
;
565 /* Member function fieldlist array, contains name of possibly overloaded
566 member function, number of overloaded member functions and a pointer
567 to the head of the member function field chain. */
572 struct nextfnfield
*head
;
576 /* Number of entries in the fnfieldlists array. */
580 /* Various complaints about symbol reading that don't abort the process */
583 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
585 complaint (&symfile_complaints
,
586 "statement list doesn't fit in .debug_line section");
590 dwarf2_complex_location_expr_complaint (void)
592 complaint (&symfile_complaints
, "location expression too complex");
596 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
599 complaint (&symfile_complaints
,
600 "const value length mismatch for '%s', got %d, expected %d", arg1
,
605 dwarf2_macros_too_long_complaint (void)
607 complaint (&symfile_complaints
,
608 "macro info runs off end of `.debug_macinfo' section");
612 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
614 complaint (&symfile_complaints
,
615 "macro debug info contains a malformed macro definition:\n`%s'",
620 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
622 complaint (&symfile_complaints
,
623 "invalid attribute class or form for '%s' in '%s'", arg1
, arg2
);
626 /* local function prototypes */
628 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
631 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
634 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
636 static void scan_partial_symbols (struct partial_die_info
*,
637 CORE_ADDR
*, CORE_ADDR
*,
640 static void add_partial_symbol (struct partial_die_info
*,
643 static int pdi_needs_namespace (enum dwarf_tag tag
);
645 static void add_partial_namespace (struct partial_die_info
*pdi
,
646 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
647 struct dwarf2_cu
*cu
);
649 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
650 struct dwarf2_cu
*cu
);
652 static char *locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
655 struct dwarf2_cu
*cu
);
657 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
659 static void psymtab_to_symtab_1 (struct partial_symtab
*);
661 char *dwarf2_read_section (struct objfile
*, asection
*);
663 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
665 static void dwarf2_free_abbrev_table (void *);
667 static struct abbrev_info
*peek_die_abbrev (char *, int *, struct dwarf2_cu
*);
669 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
672 static struct partial_die_info
*load_partial_dies (bfd
*, char *, int,
675 static char *read_partial_die (struct partial_die_info
*,
676 struct abbrev_info
*abbrev
, unsigned int,
677 bfd
*, char *, struct dwarf2_cu
*);
679 static struct partial_die_info
*find_partial_die (unsigned long,
681 struct dwarf2_cu
**);
683 static void fixup_partial_die (struct partial_die_info
*,
686 static char *read_full_die (struct die_info
**, bfd
*, char *,
687 struct dwarf2_cu
*, int *);
689 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
690 bfd
*, char *, struct dwarf2_cu
*);
692 static char *read_attribute_value (struct attribute
*, unsigned,
693 bfd
*, char *, struct dwarf2_cu
*);
695 static unsigned int read_1_byte (bfd
*, char *);
697 static int read_1_signed_byte (bfd
*, char *);
699 static unsigned int read_2_bytes (bfd
*, char *);
701 static unsigned int read_4_bytes (bfd
*, char *);
703 static unsigned long read_8_bytes (bfd
*, char *);
705 static CORE_ADDR
read_address (bfd
*, char *ptr
, struct dwarf2_cu
*,
708 static LONGEST
read_initial_length (bfd
*, char *,
709 struct comp_unit_head
*, int *bytes_read
);
711 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
714 static char *read_n_bytes (bfd
*, char *, unsigned int);
716 static char *read_string (bfd
*, char *, unsigned int *);
718 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
721 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
723 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
725 static char *skip_leb128 (bfd
*, char *);
727 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
729 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
732 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
733 struct dwarf2_cu
*cu
);
735 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
737 static struct die_info
*die_specification (struct die_info
*die
,
740 static void free_line_header (struct line_header
*lh
);
742 static struct line_header
*(dwarf_decode_line_header
743 (unsigned int offset
,
744 bfd
*abfd
, struct dwarf2_cu
*cu
));
746 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
749 static void dwarf2_start_subfile (char *, char *);
751 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
754 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
757 static void dwarf2_const_value_data (struct attribute
*attr
,
761 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
763 static struct type
*die_containing_type (struct die_info
*,
767 static struct type
*type_at_offset (unsigned int, struct objfile
*);
770 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
772 static void read_type_die (struct die_info
*, struct dwarf2_cu
*);
774 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
776 static char *typename_concat (const char *prefix
, const char *suffix
);
778 static void read_typedef (struct die_info
*, struct dwarf2_cu
*);
780 static void read_base_type (struct die_info
*, struct dwarf2_cu
*);
782 static void read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
784 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
786 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
788 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
790 static int dwarf2_get_pc_bounds (struct die_info
*,
791 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
793 static void get_scope_pc_bounds (struct die_info
*,
794 CORE_ADDR
*, CORE_ADDR
*,
797 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
800 static void dwarf2_attach_fields_to_type (struct field_info
*,
801 struct type
*, struct dwarf2_cu
*);
803 static void dwarf2_add_member_fn (struct field_info
*,
804 struct die_info
*, struct type
*,
807 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
808 struct type
*, struct dwarf2_cu
*);
810 static void read_structure_type (struct die_info
*, struct dwarf2_cu
*);
812 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
814 static char *determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
816 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
818 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
820 static const char *namespace_name (struct die_info
*die
,
821 int *is_anonymous
, struct dwarf2_cu
*);
823 static void read_enumeration_type (struct die_info
*, struct dwarf2_cu
*);
825 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
827 static struct type
*dwarf_base_type (int, int, struct dwarf2_cu
*);
829 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
831 static void read_array_type (struct die_info
*, struct dwarf2_cu
*);
833 static void read_tag_pointer_type (struct die_info
*, struct dwarf2_cu
*);
835 static void read_tag_ptr_to_member_type (struct die_info
*,
838 static void read_tag_reference_type (struct die_info
*, struct dwarf2_cu
*);
840 static void read_tag_const_type (struct die_info
*, struct dwarf2_cu
*);
842 static void read_tag_volatile_type (struct die_info
*, struct dwarf2_cu
*);
844 static void read_tag_string_type (struct die_info
*, struct dwarf2_cu
*);
846 static void read_subroutine_type (struct die_info
*, struct dwarf2_cu
*);
848 static struct die_info
*read_comp_unit (char *, bfd
*, struct dwarf2_cu
*);
850 static struct die_info
*read_die_and_children (char *info_ptr
, bfd
*abfd
,
853 struct die_info
*parent
);
855 static struct die_info
*read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
858 struct die_info
*parent
);
860 static void free_die_list (struct die_info
*);
862 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
864 static void process_die (struct die_info
*, struct dwarf2_cu
*);
866 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
868 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
870 static struct die_info
*dwarf2_extension (struct die_info
*die
,
873 static char *dwarf_tag_name (unsigned int);
875 static char *dwarf_attr_name (unsigned int);
877 static char *dwarf_form_name (unsigned int);
879 static char *dwarf_stack_op_name (unsigned int);
881 static char *dwarf_bool_name (unsigned int);
883 static char *dwarf_type_encoding_name (unsigned int);
886 static char *dwarf_cfi_name (unsigned int);
888 struct die_info
*copy_die (struct die_info
*);
891 static struct die_info
*sibling_die (struct die_info
*);
893 static void dump_die (struct die_info
*);
895 static void dump_die_list (struct die_info
*);
897 static void store_in_ref_table (unsigned int, struct die_info
*);
899 static void dwarf2_empty_hash_tables (void);
901 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
904 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
906 static struct die_info
*follow_die_ref (unsigned int);
908 static struct type
*dwarf2_fundamental_type (struct objfile
*, int,
911 /* memory allocation interface */
913 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
915 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
917 static struct die_info
*dwarf_alloc_die (void);
919 static void initialize_cu_func_list (struct dwarf2_cu
*);
921 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
924 static void dwarf_decode_macros (struct line_header
*, unsigned int,
925 char *, bfd
*, struct dwarf2_cu
*);
927 static int attr_form_is_block (struct attribute
*);
930 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
931 struct dwarf2_cu
*cu
);
933 static char *skip_one_die (char *info_ptr
, struct abbrev_info
*abbrev
,
934 struct dwarf2_cu
*cu
);
936 static void free_stack_comp_unit (void *);
938 static void *hashtab_obstack_allocate (void *data
, size_t size
, size_t count
);
940 static void dummy_obstack_deallocate (void *object
, void *data
);
942 static hashval_t
partial_die_hash (const void *item
);
944 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
946 /* Try to locate the sections we need for DWARF 2 debugging
947 information and return true if we have enough to do something. */
950 dwarf2_has_info (struct objfile
*objfile
)
952 struct dwarf2_per_objfile
*data
;
954 /* Initialize per-objfile state. */
955 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
956 memset (data
, 0, sizeof (*data
));
957 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
958 dwarf2_per_objfile
= data
;
960 dwarf_info_section
= 0;
961 dwarf_abbrev_section
= 0;
962 dwarf_line_section
= 0;
963 dwarf_str_section
= 0;
964 dwarf_macinfo_section
= 0;
965 dwarf_frame_section
= 0;
966 dwarf_eh_frame_section
= 0;
967 dwarf_ranges_section
= 0;
968 dwarf_loc_section
= 0;
970 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
971 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
974 /* This function is mapped across the sections and remembers the
975 offset and size of each of the debugging sections we are interested
979 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
981 if (strcmp (sectp
->name
, INFO_SECTION
) == 0)
983 dwarf2_per_objfile
->info_size
= bfd_get_section_size_before_reloc (sectp
);
984 dwarf_info_section
= sectp
;
986 else if (strcmp (sectp
->name
, ABBREV_SECTION
) == 0)
988 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
989 dwarf_abbrev_section
= sectp
;
991 else if (strcmp (sectp
->name
, LINE_SECTION
) == 0)
993 dwarf2_per_objfile
->line_size
= bfd_get_section_size_before_reloc (sectp
);
994 dwarf_line_section
= sectp
;
996 else if (strcmp (sectp
->name
, PUBNAMES_SECTION
) == 0)
998 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
999 dwarf_pubnames_section
= sectp
;
1001 else if (strcmp (sectp
->name
, ARANGES_SECTION
) == 0)
1003 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size_before_reloc (sectp
);
1004 dwarf_aranges_section
= sectp
;
1006 else if (strcmp (sectp
->name
, LOC_SECTION
) == 0)
1008 dwarf2_per_objfile
->loc_size
= bfd_get_section_size_before_reloc (sectp
);
1009 dwarf_loc_section
= sectp
;
1011 else if (strcmp (sectp
->name
, MACINFO_SECTION
) == 0)
1013 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
1014 dwarf_macinfo_section
= sectp
;
1016 else if (strcmp (sectp
->name
, STR_SECTION
) == 0)
1018 dwarf2_per_objfile
->str_size
= bfd_get_section_size_before_reloc (sectp
);
1019 dwarf_str_section
= sectp
;
1021 else if (strcmp (sectp
->name
, FRAME_SECTION
) == 0)
1023 dwarf2_per_objfile
->frame_size
= bfd_get_section_size_before_reloc (sectp
);
1024 dwarf_frame_section
= sectp
;
1026 else if (strcmp (sectp
->name
, EH_FRAME_SECTION
) == 0)
1028 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1029 if (aflag
& SEC_HAS_CONTENTS
)
1031 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1032 dwarf_eh_frame_section
= sectp
;
1035 else if (strcmp (sectp
->name
, RANGES_SECTION
) == 0)
1037 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size_before_reloc (sectp
);
1038 dwarf_ranges_section
= sectp
;
1042 /* Build a partial symbol table. */
1045 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1047 /* We definitely need the .debug_info and .debug_abbrev sections */
1049 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1050 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1052 if (dwarf_line_section
)
1053 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1055 dwarf2_per_objfile
->line_buffer
= NULL
;
1057 if (dwarf_str_section
)
1058 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1060 dwarf2_per_objfile
->str_buffer
= NULL
;
1062 if (dwarf_macinfo_section
)
1063 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1064 dwarf_macinfo_section
);
1066 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1068 if (dwarf_ranges_section
)
1069 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1071 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1073 if (dwarf_loc_section
)
1074 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1076 dwarf2_per_objfile
->loc_buffer
= NULL
;
1079 || (objfile
->global_psymbols
.size
== 0
1080 && objfile
->static_psymbols
.size
== 0))
1082 init_psymbol_list (objfile
, 1024);
1086 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1088 /* Things are significantly easier if we have .debug_aranges and
1089 .debug_pubnames sections */
1091 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1095 /* only test this case for now */
1097 /* In this case we have to work a bit harder */
1098 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1103 /* Build the partial symbol table from the information in the
1104 .debug_pubnames and .debug_aranges sections. */
1107 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1109 bfd
*abfd
= objfile
->obfd
;
1110 char *aranges_buffer
, *pubnames_buffer
;
1111 char *aranges_ptr
, *pubnames_ptr
;
1112 unsigned int entry_length
, version
, info_offset
, info_size
;
1114 pubnames_buffer
= dwarf2_read_section (objfile
,
1115 dwarf_pubnames_section
);
1116 pubnames_ptr
= pubnames_buffer
;
1117 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1119 struct comp_unit_head cu_header
;
1122 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1124 pubnames_ptr
+= bytes_read
;
1125 version
= read_1_byte (abfd
, pubnames_ptr
);
1127 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1129 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1133 aranges_buffer
= dwarf2_read_section (objfile
,
1134 dwarf_aranges_section
);
1139 /* Read in the comp unit header information from the debug_info at
1143 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1144 char *info_ptr
, bfd
*abfd
)
1148 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1150 info_ptr
+= bytes_read
;
1151 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1153 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1155 info_ptr
+= bytes_read
;
1156 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1158 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1159 if (signed_addr
< 0)
1160 internal_error (__FILE__
, __LINE__
,
1161 "read_comp_unit_head: dwarf from non elf file");
1162 cu_header
->signed_addr_p
= signed_addr
;
1167 partial_read_comp_unit_head (struct comp_unit_head
*header
, char *info_ptr
,
1170 char *beg_of_comp_unit
= info_ptr
;
1172 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1174 if (header
->version
!= 2)
1175 error ("Dwarf Error: wrong version in compilation unit header "
1176 "(is %d, should be %d) [in module %s]", header
->version
,
1177 2, bfd_get_filename (abfd
));
1179 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1180 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1181 "(offset 0x%lx + 6) [in module %s]",
1182 (long) header
->abbrev_offset
,
1183 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1184 bfd_get_filename (abfd
));
1186 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1187 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1188 error ("Dwarf Error: bad length (0x%lx) in compilation unit header "
1189 "(offset 0x%lx + 0) [in module %s]",
1190 (long) header
->length
,
1191 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1192 bfd_get_filename (abfd
));
1197 /* Build the partial symbol table by doing a quick pass through the
1198 .debug_info and .debug_abbrev sections. */
1201 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1203 /* Instead of reading this into a big buffer, we should probably use
1204 mmap() on architectures that support it. (FIXME) */
1205 bfd
*abfd
= objfile
->obfd
;
1207 char *beg_of_comp_unit
;
1208 struct partial_die_info comp_unit_die
;
1209 struct partial_symtab
*pst
;
1210 CORE_ADDR lowpc
, highpc
, baseaddr
;
1212 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1214 /* Since the objects we're extracting from .debug_info vary in
1215 length, only the individual functions to extract them (like
1216 read_comp_unit_head and load_partial_die) can really know whether
1217 the buffer is large enough to hold another complete object.
1219 At the moment, they don't actually check that. If .debug_info
1220 holds just one extra byte after the last compilation unit's dies,
1221 then read_comp_unit_head will happily read off the end of the
1222 buffer. read_partial_die is similarly casual. Those functions
1225 For this loop condition, simply checking whether there's any data
1226 left at all should be sufficient. */
1227 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1228 + dwarf2_per_objfile
->info_size
))
1230 struct cleanup
*back_to_inner
;
1231 struct dwarf2_cu cu
;
1232 struct abbrev_info
*abbrev
;
1233 unsigned int bytes_read
;
1234 struct dwarf2_per_cu_data
*this_cu
;
1236 beg_of_comp_unit
= info_ptr
;
1238 memset (&cu
, 0, sizeof (cu
));
1240 obstack_init (&cu
.comp_unit_obstack
);
1242 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1244 cu
.objfile
= objfile
;
1245 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1247 /* Complete the cu_header */
1248 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1249 cu
.header
.first_die_ptr
= info_ptr
;
1250 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1252 cu
.list_in_scope
= &file_symbols
;
1254 cu
.partial_dies
= NULL
;
1256 /* Read the abbrevs for this compilation unit into a table */
1257 dwarf2_read_abbrevs (abfd
, &cu
);
1258 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1260 /* Read the compilation unit die */
1261 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1262 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1263 abfd
, info_ptr
, &cu
);
1265 /* Set the language we're debugging */
1266 set_cu_language (comp_unit_die
.language
, &cu
);
1268 /* Allocate a new partial symbol table structure */
1269 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1270 comp_unit_die
.name
? comp_unit_die
.name
: "",
1271 comp_unit_die
.lowpc
,
1272 objfile
->global_psymbols
.next
,
1273 objfile
->static_psymbols
.next
);
1275 pst
->read_symtab_private
= (char *)
1276 obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct dwarf2_pinfo
));
1277 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1278 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1280 /* Store the function that reads in the rest of the symbol table */
1281 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1283 /* Check if comp unit has_children.
1284 If so, read the rest of the partial symbols from this comp unit.
1285 If not, there's no more debug_info for this comp unit. */
1286 if (comp_unit_die
.has_children
)
1288 struct partial_die_info
*first_die
;
1290 lowpc
= ((CORE_ADDR
) -1);
1291 highpc
= ((CORE_ADDR
) 0);
1293 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1295 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1297 /* If we didn't find a lowpc, set it to highpc to avoid
1298 complaints from `maint check'. */
1299 if (lowpc
== ((CORE_ADDR
) -1))
1302 /* If the compilation unit didn't have an explicit address range,
1303 then use the information extracted from its child dies. */
1304 if (! comp_unit_die
.has_pc_info
)
1306 comp_unit_die
.lowpc
= lowpc
;
1307 comp_unit_die
.highpc
= highpc
;
1310 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1311 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1313 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1314 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1315 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1316 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1317 sort_pst_symbols (pst
);
1319 /* If there is already a psymtab or symtab for a file of this
1320 name, remove it. (If there is a symtab, more drastic things
1321 also happen.) This happens in VxWorks. */
1322 free_named_symtabs (pst
->filename
);
1324 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1325 + cu
.header
.initial_length_size
;
1327 do_cleanups (back_to_inner
);
1331 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1332 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1336 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1337 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1339 struct objfile
*objfile
= cu
->objfile
;
1340 bfd
*abfd
= objfile
->obfd
;
1341 struct partial_die_info
*pdi
;
1343 /* Now, march along the PDI's, descending into ones which have
1344 interesting children but skipping the children of the other ones,
1345 until we reach the end of the compilation unit. */
1351 fixup_partial_die (pdi
, cu
);
1353 /* Anonymous namespaces have no name but have interesting
1354 children, so we need to look at them. Ditto for anonymous
1357 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1358 || pdi
->tag
== DW_TAG_enumeration_type
)
1362 case DW_TAG_subprogram
:
1363 if (pdi
->has_pc_info
)
1365 if (pdi
->lowpc
< *lowpc
)
1367 *lowpc
= pdi
->lowpc
;
1369 if (pdi
->highpc
> *highpc
)
1371 *highpc
= pdi
->highpc
;
1373 if (!pdi
->is_declaration
)
1375 add_partial_symbol (pdi
, cu
);
1379 case DW_TAG_variable
:
1380 case DW_TAG_typedef
:
1381 case DW_TAG_union_type
:
1382 if (!pdi
->is_declaration
)
1384 add_partial_symbol (pdi
, cu
);
1387 case DW_TAG_class_type
:
1388 case DW_TAG_structure_type
:
1389 if (!pdi
->is_declaration
)
1391 add_partial_symbol (pdi
, cu
);
1394 case DW_TAG_enumeration_type
:
1395 if (!pdi
->is_declaration
)
1396 add_partial_enumeration (pdi
, cu
);
1398 case DW_TAG_base_type
:
1399 case DW_TAG_subrange_type
:
1400 /* File scope base type definitions are added to the partial
1402 add_partial_symbol (pdi
, cu
);
1404 case DW_TAG_namespace
:
1405 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1412 /* If the die has a sibling, skip to the sibling. */
1414 pdi
= pdi
->die_sibling
;
1418 /* Functions used to compute the fully scoped name of a partial DIE.
1420 Normally, this is simple. For C++, the parent DIE's fully scoped
1421 name is concatenated with "::" and the partial DIE's name.
1422 Enumerators are an exception; they use the scope of their parent
1423 enumeration type, i.e. the name of the enumeration type is not
1424 prepended to the enumerator.
1426 There are two complexities. One is DW_AT_specification; in this
1427 case "parent" means the parent of the target of the specification,
1428 instead of the direct parent of the DIE. The other is compilers
1429 which do not emit DW_TAG_namespace; in this case we try to guess
1430 the fully qualified name of structure types from their members'
1431 linkage names. This must be done using the DIE's children rather
1432 than the children of any DW_AT_specification target. We only need
1433 to do this for structures at the top level, i.e. if the target of
1434 any DW_AT_specification (if any; otherwise the DIE itself) does not
1437 /* Compute the scope prefix associated with PDI's parent, in
1438 compilation unit CU. The result will be allocated on CU's
1439 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1440 field. NULL is returned if no prefix is necessary. */
1442 partial_die_parent_scope (struct partial_die_info
*pdi
,
1443 struct dwarf2_cu
*cu
)
1445 char *grandparent_scope
;
1446 struct partial_die_info
*parent
, *real_pdi
;
1447 struct dwarf2_cu
*spec_cu
;
1449 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1450 then this means the parent of the specification DIE. */
1454 while (real_pdi
->has_specification
)
1455 real_pdi
= find_partial_die (real_pdi
->spec_offset
, spec_cu
, &spec_cu
);
1457 parent
= real_pdi
->die_parent
;
1461 if (parent
->scope_set
)
1462 return parent
->scope
;
1464 fixup_partial_die (parent
, cu
);
1466 grandparent_scope
= partial_die_parent_scope (parent
, spec_cu
);
1468 if (parent
->tag
== DW_TAG_namespace
1469 || parent
->tag
== DW_TAG_structure_type
1470 || parent
->tag
== DW_TAG_class_type
1471 || parent
->tag
== DW_TAG_union_type
)
1473 if (grandparent_scope
== NULL
)
1474 parent
->scope
= parent
->name
;
1476 parent
->scope
= obconcat (&cu
->comp_unit_obstack
, grandparent_scope
,
1477 "::", parent
->name
);
1479 else if (parent
->tag
== DW_TAG_enumeration_type
)
1480 /* Enumerators should not get the name of the enumeration as a prefix. */
1481 parent
->scope
= grandparent_scope
;
1484 /* FIXME drow/2004-04-01: What should we be doing with
1485 function-local names? For partial symbols, we should probably be
1487 complaint (&symfile_complaints
,
1488 "unhandled containing DIE tag %d for DIE at %d",
1489 parent
->tag
, pdi
->offset
);
1490 parent
->scope
= grandparent_scope
;
1493 parent
->scope_set
= 1;
1494 return parent
->scope
;
1497 /* Return the fully scoped name associated with PDI, from compilation unit
1498 CU. The result will be allocated with malloc. */
1500 partial_die_full_name (struct partial_die_info
*pdi
,
1501 struct dwarf2_cu
*cu
)
1505 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1506 if (parent_scope
== NULL
)
1509 return concat (parent_scope
, "::", pdi
->name
, NULL
);
1513 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1515 struct objfile
*objfile
= cu
->objfile
;
1518 const char *my_prefix
;
1519 const struct partial_symbol
*psym
= NULL
;
1521 int built_actual_name
= 0;
1523 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1527 if (pdi_needs_namespace (pdi
->tag
))
1529 actual_name
= partial_die_full_name (pdi
, cu
);
1531 built_actual_name
= 1;
1534 if (actual_name
== NULL
)
1535 actual_name
= pdi
->name
;
1539 case DW_TAG_subprogram
:
1540 if (pdi
->is_external
)
1542 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1543 mst_text, objfile); */
1544 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1545 VAR_DOMAIN
, LOC_BLOCK
,
1546 &objfile
->global_psymbols
,
1547 0, pdi
->lowpc
+ baseaddr
,
1548 cu
->language
, objfile
);
1552 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1553 mst_file_text, objfile); */
1554 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1555 VAR_DOMAIN
, LOC_BLOCK
,
1556 &objfile
->static_psymbols
,
1557 0, pdi
->lowpc
+ baseaddr
,
1558 cu
->language
, objfile
);
1561 case DW_TAG_variable
:
1562 if (pdi
->is_external
)
1565 Don't enter into the minimal symbol tables as there is
1566 a minimal symbol table entry from the ELF symbols already.
1567 Enter into partial symbol table if it has a location
1568 descriptor or a type.
1569 If the location descriptor is missing, new_symbol will create
1570 a LOC_UNRESOLVED symbol, the address of the variable will then
1571 be determined from the minimal symbol table whenever the variable
1573 The address for the partial symbol table entry is not
1574 used by GDB, but it comes in handy for debugging partial symbol
1578 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1579 if (pdi
->locdesc
|| pdi
->has_type
)
1580 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1581 VAR_DOMAIN
, LOC_STATIC
,
1582 &objfile
->global_psymbols
,
1584 cu
->language
, objfile
);
1588 /* Static Variable. Skip symbols without location descriptors. */
1589 if (pdi
->locdesc
== NULL
)
1591 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1592 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1593 mst_file_data, objfile); */
1594 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1595 VAR_DOMAIN
, LOC_STATIC
,
1596 &objfile
->static_psymbols
,
1598 cu
->language
, objfile
);
1601 case DW_TAG_typedef
:
1602 case DW_TAG_base_type
:
1603 case DW_TAG_subrange_type
:
1604 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1605 VAR_DOMAIN
, LOC_TYPEDEF
,
1606 &objfile
->static_psymbols
,
1607 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1609 case DW_TAG_namespace
:
1610 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1611 VAR_DOMAIN
, LOC_TYPEDEF
,
1612 &objfile
->global_psymbols
,
1613 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1615 case DW_TAG_class_type
:
1616 case DW_TAG_structure_type
:
1617 case DW_TAG_union_type
:
1618 case DW_TAG_enumeration_type
:
1619 /* Skip aggregate types without children, these are external
1621 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1622 static vs. global. */
1623 if (pdi
->has_children
== 0)
1625 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1626 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1627 cu
->language
== language_cplus
1628 ? &objfile
->global_psymbols
1629 : &objfile
->static_psymbols
,
1630 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1632 if (cu
->language
== language_cplus
)
1634 /* For C++, these implicitly act as typedefs as well. */
1635 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1636 VAR_DOMAIN
, LOC_TYPEDEF
,
1637 &objfile
->global_psymbols
,
1638 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1641 case DW_TAG_enumerator
:
1642 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1643 VAR_DOMAIN
, LOC_CONST
,
1644 cu
->language
== language_cplus
1645 ? &objfile
->global_psymbols
1646 : &objfile
->static_psymbols
,
1647 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1653 /* Check to see if we should scan the name for possible namespace
1654 info. Only do this if this is C++, if we don't have namespace
1655 debugging info in the file, if the psym is of an appropriate type
1656 (otherwise we'll have psym == NULL), and if we actually had a
1657 mangled name to begin with. */
1659 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
1660 cases which do not set PSYM above? */
1662 if (cu
->language
== language_cplus
1663 && cu
->has_namespace_info
== 0
1665 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
1666 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
1669 if (built_actual_name
)
1670 xfree (actual_name
);
1673 /* Determine whether a die of type TAG living in a C++ class or
1674 namespace needs to have the name of the scope prepended to the
1675 name listed in the die. */
1678 pdi_needs_namespace (enum dwarf_tag tag
)
1682 case DW_TAG_namespace
:
1683 case DW_TAG_typedef
:
1684 case DW_TAG_class_type
:
1685 case DW_TAG_structure_type
:
1686 case DW_TAG_union_type
:
1687 case DW_TAG_enumeration_type
:
1688 case DW_TAG_enumerator
:
1695 /* Read a partial die corresponding to a namespace; also, add a symbol
1696 corresponding to that namespace to the symbol table. NAMESPACE is
1697 the name of the enclosing namespace. */
1700 add_partial_namespace (struct partial_die_info
*pdi
,
1701 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1702 struct dwarf2_cu
*cu
)
1704 struct objfile
*objfile
= cu
->objfile
;
1706 /* Add a symbol for the namespace. */
1708 add_partial_symbol (pdi
, cu
);
1710 /* Now scan partial symbols in that namespace. */
1712 if (pdi
->has_children
)
1713 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
1716 /* See if we can figure out if the class lives in a namespace. We do
1717 this by looking for a member function; its demangled name will
1718 contain namespace info, if there is any. */
1721 guess_structure_name (struct partial_die_info
*struct_pdi
,
1722 struct dwarf2_cu
*cu
)
1724 if (cu
->language
== language_cplus
1725 && cu
->has_namespace_info
== 0
1726 && struct_pdi
->has_children
)
1728 /* NOTE: carlton/2003-10-07: Getting the info this way changes
1729 what template types look like, because the demangler
1730 frequently doesn't give the same name as the debug info. We
1731 could fix this by only using the demangled name to get the
1732 prefix (but see comment in read_structure_type). */
1734 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
1735 struct partial_die_info
*real_pdi
;
1736 struct dwarf2_cu
*spec_cu
;
1738 /* If this DIE (this DIE's specification, if any) has a parent, then
1739 we should not do this. We'll prepend the parent's fully qualified
1740 name when we create the partial symbol. */
1742 real_pdi
= struct_pdi
;
1744 while (real_pdi
->has_specification
)
1745 real_pdi
= find_partial_die (real_pdi
->spec_offset
, spec_cu
, &spec_cu
);
1747 if (real_pdi
->die_parent
!= NULL
)
1750 while (child_pdi
!= NULL
)
1752 if (child_pdi
->tag
== DW_TAG_subprogram
)
1754 char *actual_class_name
1755 = class_name_from_physname (child_pdi
->name
);
1756 if (actual_class_name
!= NULL
)
1759 = obsavestring (actual_class_name
,
1760 strlen (actual_class_name
),
1761 &cu
->comp_unit_obstack
);
1762 xfree (actual_class_name
);
1767 child_pdi
= child_pdi
->die_sibling
;
1772 /* Read a partial die corresponding to an enumeration type. */
1775 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1776 struct dwarf2_cu
*cu
)
1778 struct objfile
*objfile
= cu
->objfile
;
1779 bfd
*abfd
= objfile
->obfd
;
1780 struct partial_die_info
*pdi
;
1782 if (enum_pdi
->name
!= NULL
)
1783 add_partial_symbol (enum_pdi
, cu
);
1785 pdi
= enum_pdi
->die_child
;
1788 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
1789 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
1791 add_partial_symbol (pdi
, cu
);
1792 pdi
= pdi
->die_sibling
;
1796 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
1797 Return the corresponding abbrev, or NULL if the number is zero (indicating
1798 an empty DIE). In either case *BYTES_READ will be set to the length of
1799 the initial number. */
1801 static struct abbrev_info
*
1802 peek_die_abbrev (char *info_ptr
, int *bytes_read
, struct dwarf2_cu
*cu
)
1804 bfd
*abfd
= cu
->objfile
->obfd
;
1805 unsigned int abbrev_number
;
1806 struct abbrev_info
*abbrev
;
1808 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
1810 if (abbrev_number
== 0)
1813 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
1816 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
1817 bfd_get_filename (abfd
));
1823 /* Scan the debug information for CU starting at INFO_PTR. Returns a
1824 pointer to the end of a series of DIEs, terminated by an empty
1825 DIE. Any children of the skipped DIEs will also be skipped. */
1828 skip_children (char *info_ptr
, struct dwarf2_cu
*cu
)
1830 struct abbrev_info
*abbrev
;
1831 unsigned int bytes_read
;
1835 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1837 return info_ptr
+ bytes_read
;
1839 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
1843 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
1844 should point just after the initial uleb128 of a DIE, and the
1845 abbrev corresponding to that skipped uleb128 should be passed in
1846 ABBREV. Returns a pointer to this DIE's sibling, skipping any
1850 skip_one_die (char *info_ptr
, struct abbrev_info
*abbrev
,
1851 struct dwarf2_cu
*cu
)
1853 unsigned int bytes_read
;
1854 struct attribute attr
;
1855 bfd
*abfd
= cu
->objfile
->obfd
;
1856 unsigned int form
, i
;
1858 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
1860 /* The only abbrev we care about is DW_AT_sibling. */
1861 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
1863 read_attribute (&attr
, &abbrev
->attrs
[i
],
1864 abfd
, info_ptr
, cu
);
1865 if (attr
.form
== DW_FORM_ref_addr
)
1866 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
1868 return dwarf2_per_objfile
->info_buffer
1869 + dwarf2_get_ref_die_offset (&attr
, cu
);
1872 /* If it isn't DW_AT_sibling, skip this attribute. */
1873 form
= abbrev
->attrs
[i
].form
;
1878 case DW_FORM_ref_addr
:
1879 info_ptr
+= cu
->header
.addr_size
;
1898 case DW_FORM_string
:
1899 read_string (abfd
, info_ptr
, &bytes_read
);
1900 info_ptr
+= bytes_read
;
1903 info_ptr
+= cu
->header
.offset_size
;
1906 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
1907 info_ptr
+= bytes_read
;
1909 case DW_FORM_block1
:
1910 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
1912 case DW_FORM_block2
:
1913 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
1915 case DW_FORM_block4
:
1916 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
1920 case DW_FORM_ref_udata
:
1921 info_ptr
= skip_leb128 (abfd
, info_ptr
);
1923 case DW_FORM_indirect
:
1924 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
1925 info_ptr
+= bytes_read
;
1926 /* We need to continue parsing from here, so just go back to
1928 goto skip_attribute
;
1931 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
1932 dwarf_form_name (form
),
1933 bfd_get_filename (abfd
));
1937 if (abbrev
->has_children
)
1938 return skip_children (info_ptr
, cu
);
1943 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
1944 the next DIE after ORIG_PDI. */
1947 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, char *info_ptr
,
1948 bfd
*abfd
, struct dwarf2_cu
*cu
)
1950 /* Do we know the sibling already? */
1952 if (orig_pdi
->sibling
)
1953 return orig_pdi
->sibling
;
1955 /* Are there any children to deal with? */
1957 if (!orig_pdi
->has_children
)
1960 /* Skip the children the long way. */
1962 return skip_children (info_ptr
, cu
);
1965 /* Expand this partial symbol table into a full symbol table. */
1968 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1970 /* FIXME: This is barely more than a stub. */
1975 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1981 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1982 gdb_flush (gdb_stdout
);
1985 psymtab_to_symtab_1 (pst
);
1987 /* Finish up the debug error message. */
1989 printf_filtered ("done.\n");
1995 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1997 struct objfile
*objfile
= pst
->objfile
;
1998 bfd
*abfd
= objfile
->obfd
;
1999 struct dwarf2_cu cu
;
2000 struct die_info
*dies
;
2001 unsigned long offset
;
2002 CORE_ADDR lowpc
, highpc
;
2003 struct die_info
*child_die
;
2005 struct symtab
*symtab
;
2006 struct cleanup
*back_to
;
2007 struct attribute
*attr
;
2010 dwarf2_per_objfile
= objfile_data (pst
->objfile
, dwarf2_objfile_data_key
);
2012 /* Set local variables from the partial symbol table info. */
2013 offset
= DWARF_INFO_OFFSET (pst
);
2015 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2016 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2018 /* We're in the global namespace. */
2019 processing_current_prefix
= "";
2021 obstack_init (&cu
.comp_unit_obstack
);
2022 back_to
= make_cleanup (free_stack_comp_unit
, &cu
);
2025 make_cleanup (really_free_pendings
, NULL
);
2027 cu
.objfile
= objfile
;
2029 /* read in the comp_unit header */
2030 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
2032 /* Read the abbrevs for this compilation unit */
2033 dwarf2_read_abbrevs (abfd
, &cu
);
2034 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2036 cu
.header
.offset
= offset
;
2038 cu
.list_in_scope
= &file_symbols
;
2040 dies
= read_comp_unit (info_ptr
, abfd
, &cu
);
2042 make_cleanup_free_die_list (dies
);
2044 /* Find the base address of the compilation unit for range lists and
2045 location lists. It will normally be specified by DW_AT_low_pc.
2046 In DWARF-3 draft 4, the base address could be overridden by
2047 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2048 compilation units with discontinuous ranges. */
2050 cu
.header
.base_known
= 0;
2051 cu
.header
.base_address
= 0;
2053 attr
= dwarf2_attr (dies
, DW_AT_entry_pc
, &cu
);
2056 cu
.header
.base_address
= DW_ADDR (attr
);
2057 cu
.header
.base_known
= 1;
2061 attr
= dwarf2_attr (dies
, DW_AT_low_pc
, &cu
);
2064 cu
.header
.base_address
= DW_ADDR (attr
);
2065 cu
.header
.base_known
= 1;
2069 /* Do line number decoding in read_file_scope () */
2070 process_die (dies
, &cu
);
2072 /* Some compilers don't define a DW_AT_high_pc attribute for the
2073 compilation unit. If the DW_AT_high_pc is missing, synthesize
2074 it, by scanning the DIE's below the compilation unit. */
2075 get_scope_pc_bounds (dies
, &lowpc
, &highpc
, &cu
);
2077 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2079 /* Set symtab language to language from DW_AT_language.
2080 If the compilation is from a C file generated by language preprocessors,
2081 do not set the language if it was already deduced by start_subfile. */
2083 && !(cu
.language
== language_c
&& symtab
->language
!= language_c
))
2085 symtab
->language
= cu
.language
;
2087 pst
->symtab
= symtab
;
2090 do_cleanups (back_to
);
2093 /* Process a die and its children. */
2096 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2100 case DW_TAG_padding
:
2102 case DW_TAG_compile_unit
:
2103 read_file_scope (die
, cu
);
2105 case DW_TAG_subprogram
:
2106 read_subroutine_type (die
, cu
);
2107 read_func_scope (die
, cu
);
2109 case DW_TAG_inlined_subroutine
:
2110 /* FIXME: These are ignored for now.
2111 They could be used to set breakpoints on all inlined instances
2112 of a function and make GDB `next' properly over inlined functions. */
2114 case DW_TAG_lexical_block
:
2115 case DW_TAG_try_block
:
2116 case DW_TAG_catch_block
:
2117 read_lexical_block_scope (die
, cu
);
2119 case DW_TAG_class_type
:
2120 case DW_TAG_structure_type
:
2121 case DW_TAG_union_type
:
2122 read_structure_type (die
, cu
);
2123 process_structure_scope (die
, cu
);
2125 case DW_TAG_enumeration_type
:
2126 read_enumeration_type (die
, cu
);
2127 process_enumeration_scope (die
, cu
);
2130 /* FIXME drow/2004-03-14: These initialize die->type, but do not create
2131 a symbol or process any children. Therefore it doesn't do anything
2132 that won't be done on-demand by read_type_die. */
2133 case DW_TAG_subroutine_type
:
2134 read_subroutine_type (die
, cu
);
2136 case DW_TAG_array_type
:
2137 read_array_type (die
, cu
);
2139 case DW_TAG_pointer_type
:
2140 read_tag_pointer_type (die
, cu
);
2142 case DW_TAG_ptr_to_member_type
:
2143 read_tag_ptr_to_member_type (die
, cu
);
2145 case DW_TAG_reference_type
:
2146 read_tag_reference_type (die
, cu
);
2148 case DW_TAG_string_type
:
2149 read_tag_string_type (die
, cu
);
2153 case DW_TAG_base_type
:
2154 read_base_type (die
, cu
);
2155 /* Add a typedef symbol for the type definition, if it has a
2157 new_symbol (die
, die
->type
, cu
);
2159 case DW_TAG_subrange_type
:
2160 read_subrange_type (die
, cu
);
2161 /* Add a typedef symbol for the type definition, if it has a
2163 new_symbol (die
, die
->type
, cu
);
2165 case DW_TAG_common_block
:
2166 read_common_block (die
, cu
);
2168 case DW_TAG_common_inclusion
:
2170 case DW_TAG_namespace
:
2171 processing_has_namespace_info
= 1;
2172 read_namespace (die
, cu
);
2174 case DW_TAG_imported_declaration
:
2175 case DW_TAG_imported_module
:
2176 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2177 information contained in these. DW_TAG_imported_declaration
2178 dies shouldn't have children; DW_TAG_imported_module dies
2179 shouldn't in the C++ case, but conceivably could in the
2180 Fortran case, so we'll have to replace this gdb_assert if
2181 Fortran compilers start generating that info. */
2182 processing_has_namespace_info
= 1;
2183 gdb_assert (die
->child
== NULL
);
2186 new_symbol (die
, NULL
, cu
);
2192 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2194 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2198 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2200 struct objfile
*objfile
= cu
->objfile
;
2201 struct comp_unit_head
*cu_header
= &cu
->header
;
2202 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2203 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2204 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2205 struct attribute
*attr
;
2206 char *name
= "<unknown>";
2207 char *comp_dir
= NULL
;
2208 struct die_info
*child_die
;
2209 bfd
*abfd
= objfile
->obfd
;
2210 struct line_header
*line_header
= 0;
2213 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2215 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2217 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2218 from finish_block. */
2219 if (lowpc
== ((CORE_ADDR
) -1))
2224 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2227 name
= DW_STRING (attr
);
2229 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2232 comp_dir
= DW_STRING (attr
);
2235 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2236 directory, get rid of it. */
2237 char *cp
= strchr (comp_dir
, ':');
2239 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2244 if (objfile
->ei
.entry_point
>= lowpc
&&
2245 objfile
->ei
.entry_point
< highpc
)
2247 objfile
->ei
.deprecated_entry_file_lowpc
= lowpc
;
2248 objfile
->ei
.deprecated_entry_file_highpc
= highpc
;
2251 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2254 set_cu_language (DW_UNSND (attr
), cu
);
2257 /* We assume that we're processing GCC output. */
2258 processing_gcc_compilation
= 2;
2260 /* FIXME:Do something here. */
2261 if (dip
->at_producer
!= NULL
)
2263 handle_producer (dip
->at_producer
);
2267 /* The compilation unit may be in a different language or objfile,
2268 zero out all remembered fundamental types. */
2269 memset (cu
->ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
2271 start_symtab (name
, comp_dir
, lowpc
);
2272 record_debugformat ("DWARF 2");
2274 initialize_cu_func_list (cu
);
2276 /* Process all dies in compilation unit. */
2277 if (die
->child
!= NULL
)
2279 child_die
= die
->child
;
2280 while (child_die
&& child_die
->tag
)
2282 process_die (child_die
, cu
);
2283 child_die
= sibling_die (child_die
);
2287 /* Decode line number information if present. */
2288 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2291 unsigned int line_offset
= DW_UNSND (attr
);
2292 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2295 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
2296 (void *) line_header
);
2297 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
);
2301 /* Decode macro information, if present. Dwarf 2 macro information
2302 refers to information in the line number info statement program
2303 header, so we can only read it if we've read the header
2305 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2306 if (attr
&& line_header
)
2308 unsigned int macro_offset
= DW_UNSND (attr
);
2309 dwarf_decode_macros (line_header
, macro_offset
,
2310 comp_dir
, abfd
, cu
);
2312 do_cleanups (back_to
);
2316 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2317 struct dwarf2_cu
*cu
)
2319 struct function_range
*thisfn
;
2321 thisfn
= (struct function_range
*)
2322 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
2323 thisfn
->name
= name
;
2324 thisfn
->lowpc
= lowpc
;
2325 thisfn
->highpc
= highpc
;
2326 thisfn
->seen_line
= 0;
2327 thisfn
->next
= NULL
;
2329 if (cu
->last_fn
== NULL
)
2330 cu
->first_fn
= thisfn
;
2332 cu
->last_fn
->next
= thisfn
;
2334 cu
->last_fn
= thisfn
;
2338 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2340 struct objfile
*objfile
= cu
->objfile
;
2341 struct context_stack
*new;
2344 struct die_info
*child_die
;
2345 struct attribute
*attr
;
2347 const char *previous_prefix
= processing_current_prefix
;
2348 struct cleanup
*back_to
= NULL
;
2351 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2353 name
= dwarf2_linkage_name (die
, cu
);
2355 /* Ignore functions with missing or empty names and functions with
2356 missing or invalid low and high pc attributes. */
2357 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2360 if (cu
->language
== language_cplus
)
2362 struct die_info
*spec_die
= die_specification (die
, cu
);
2364 /* NOTE: carlton/2004-01-23: We have to be careful in the
2365 presence of DW_AT_specification. For example, with GCC 3.4,
2370 // Definition of N::foo.
2374 then we'll have a tree of DIEs like this:
2376 1: DW_TAG_compile_unit
2377 2: DW_TAG_namespace // N
2378 3: DW_TAG_subprogram // declaration of N::foo
2379 4: DW_TAG_subprogram // definition of N::foo
2380 DW_AT_specification // refers to die #3
2382 Thus, when processing die #4, we have to pretend that we're
2383 in the context of its DW_AT_specification, namely the contex
2386 if (spec_die
!= NULL
)
2388 char *specification_prefix
= determine_prefix (spec_die
, cu
);
2389 processing_current_prefix
= specification_prefix
;
2390 back_to
= make_cleanup (xfree
, specification_prefix
);
2397 /* Record the function range for dwarf_decode_lines. */
2398 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
2400 if (objfile
->ei
.entry_point
>= lowpc
&&
2401 objfile
->ei
.entry_point
< highpc
)
2403 objfile
->ei
.entry_func_lowpc
= lowpc
;
2404 objfile
->ei
.entry_func_highpc
= highpc
;
2407 new = push_context (0, lowpc
);
2408 new->name
= new_symbol (die
, die
->type
, cu
);
2410 /* If there is a location expression for DW_AT_frame_base, record
2412 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
2414 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2415 expression is being recorded directly in the function's symbol
2416 and not in a separate frame-base object. I guess this hack is
2417 to avoid adding some sort of frame-base adjunct/annex to the
2418 function's symbol :-(. The problem with doing this is that it
2419 results in a function symbol with a location expression that
2420 has nothing to do with the location of the function, ouch! The
2421 relationship should be: a function's symbol has-a frame base; a
2422 frame-base has-a location expression. */
2423 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
2425 cu
->list_in_scope
= &local_symbols
;
2427 if (die
->child
!= NULL
)
2429 child_die
= die
->child
;
2430 while (child_die
&& child_die
->tag
)
2432 process_die (child_die
, cu
);
2433 child_die
= sibling_die (child_die
);
2437 new = pop_context ();
2438 /* Make a block for the local symbols within. */
2439 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2440 lowpc
, highpc
, objfile
);
2442 /* In C++, we can have functions nested inside functions (e.g., when
2443 a function declares a class that has methods). This means that
2444 when we finish processing a function scope, we may need to go
2445 back to building a containing block's symbol lists. */
2446 local_symbols
= new->locals
;
2447 param_symbols
= new->params
;
2449 /* If we've finished processing a top-level function, subsequent
2450 symbols go in the file symbol list. */
2451 if (outermost_context_p ())
2452 cu
->list_in_scope
= &file_symbols
;
2454 processing_current_prefix
= previous_prefix
;
2455 if (back_to
!= NULL
)
2456 do_cleanups (back_to
);
2459 /* Process all the DIES contained within a lexical block scope. Start
2460 a new scope, process the dies, and then close the scope. */
2463 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2465 struct objfile
*objfile
= cu
->objfile
;
2466 struct context_stack
*new;
2467 CORE_ADDR lowpc
, highpc
;
2468 struct die_info
*child_die
;
2471 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2473 /* Ignore blocks with missing or invalid low and high pc attributes. */
2474 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2475 as multiple lexical blocks? Handling children in a sane way would
2476 be nasty. Might be easier to properly extend generic blocks to
2478 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2483 push_context (0, lowpc
);
2484 if (die
->child
!= NULL
)
2486 child_die
= die
->child
;
2487 while (child_die
&& child_die
->tag
)
2489 process_die (child_die
, cu
);
2490 child_die
= sibling_die (child_die
);
2493 new = pop_context ();
2495 if (local_symbols
!= NULL
)
2497 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2500 local_symbols
= new->locals
;
2503 /* Get low and high pc attributes from a die. Return 1 if the attributes
2504 are present and valid, otherwise, return 0. Return -1 if the range is
2505 discontinuous, i.e. derived from DW_AT_ranges information. */
2507 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2508 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
2510 struct objfile
*objfile
= cu
->objfile
;
2511 struct comp_unit_head
*cu_header
= &cu
->header
;
2512 struct attribute
*attr
;
2513 bfd
*obfd
= objfile
->obfd
;
2518 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
2521 high
= DW_ADDR (attr
);
2522 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
2524 low
= DW_ADDR (attr
);
2526 /* Found high w/o low attribute. */
2529 /* Found consecutive range of addresses. */
2534 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
2537 unsigned int addr_size
= cu_header
->addr_size
;
2538 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2539 /* Value of the DW_AT_ranges attribute is the offset in the
2540 .debug_ranges section. */
2541 unsigned int offset
= DW_UNSND (attr
);
2542 /* Base address selection entry. */
2550 found_base
= cu_header
->base_known
;
2551 base
= cu_header
->base_address
;
2553 if (offset
>= dwarf2_per_objfile
->ranges_size
)
2555 complaint (&symfile_complaints
,
2556 "Offset %d out of bounds for DW_AT_ranges attribute",
2560 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
2562 /* Read in the largest possible address. */
2563 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
2564 if ((marker
& mask
) == mask
)
2566 /* If we found the largest possible address, then
2567 read the base address. */
2568 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2569 buffer
+= 2 * addr_size
;
2570 offset
+= 2 * addr_size
;
2578 CORE_ADDR range_beginning
, range_end
;
2580 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
2581 buffer
+= addr_size
;
2582 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
2583 buffer
+= addr_size
;
2584 offset
+= 2 * addr_size
;
2586 /* An end of list marker is a pair of zero addresses. */
2587 if (range_beginning
== 0 && range_end
== 0)
2588 /* Found the end of list entry. */
2591 /* Each base address selection entry is a pair of 2 values.
2592 The first is the largest possible address, the second is
2593 the base address. Check for a base address here. */
2594 if ((range_beginning
& mask
) == mask
)
2596 /* If we found the largest possible address, then
2597 read the base address. */
2598 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2605 /* We have no valid base address for the ranges
2607 complaint (&symfile_complaints
,
2608 "Invalid .debug_ranges data (no base address)");
2612 range_beginning
+= base
;
2615 /* FIXME: This is recording everything as a low-high
2616 segment of consecutive addresses. We should have a
2617 data structure for discontiguous block ranges
2621 low
= range_beginning
;
2627 if (range_beginning
< low
)
2628 low
= range_beginning
;
2629 if (range_end
> high
)
2635 /* If the first entry is an end-of-list marker, the range
2636 describes an empty scope, i.e. no instructions. */
2646 /* When using the GNU linker, .gnu.linkonce. sections are used to
2647 eliminate duplicate copies of functions and vtables and such.
2648 The linker will arbitrarily choose one and discard the others.
2649 The AT_*_pc values for such functions refer to local labels in
2650 these sections. If the section from that file was discarded, the
2651 labels are not in the output, so the relocs get a value of 0.
2652 If this is a discarded function, mark the pc bounds as invalid,
2653 so that GDB will ignore it. */
2654 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
2662 /* Get the low and high pc's represented by the scope DIE, and store
2663 them in *LOWPC and *HIGHPC. If the correct values can't be
2664 determined, set *LOWPC to -1 and *HIGHPC to 0. */
2667 get_scope_pc_bounds (struct die_info
*die
,
2668 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2669 struct dwarf2_cu
*cu
)
2671 CORE_ADDR best_low
= (CORE_ADDR
) -1;
2672 CORE_ADDR best_high
= (CORE_ADDR
) 0;
2673 CORE_ADDR current_low
, current_high
;
2675 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
2677 best_low
= current_low
;
2678 best_high
= current_high
;
2682 struct die_info
*child
= die
->child
;
2684 while (child
&& child
->tag
)
2686 switch (child
->tag
) {
2687 case DW_TAG_subprogram
:
2688 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
2690 best_low
= min (best_low
, current_low
);
2691 best_high
= max (best_high
, current_high
);
2694 case DW_TAG_namespace
:
2695 /* FIXME: carlton/2004-01-16: Should we do this for
2696 DW_TAG_class_type/DW_TAG_structure_type, too? I think
2697 that current GCC's always emit the DIEs corresponding
2698 to definitions of methods of classes as children of a
2699 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
2700 the DIEs giving the declarations, which could be
2701 anywhere). But I don't see any reason why the
2702 standards says that they have to be there. */
2703 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
2705 if (current_low
!= ((CORE_ADDR
) -1))
2707 best_low
= min (best_low
, current_low
);
2708 best_high
= max (best_high
, current_high
);
2716 child
= sibling_die (child
);
2721 *highpc
= best_high
;
2724 /* Add an aggregate field to the field list. */
2727 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2728 struct dwarf2_cu
*cu
)
2730 struct objfile
*objfile
= cu
->objfile
;
2731 struct nextfield
*new_field
;
2732 struct attribute
*attr
;
2734 char *fieldname
= "";
2736 /* Allocate a new field list entry and link it in. */
2737 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2738 make_cleanup (xfree
, new_field
);
2739 memset (new_field
, 0, sizeof (struct nextfield
));
2740 new_field
->next
= fip
->fields
;
2741 fip
->fields
= new_field
;
2744 /* Handle accessibility and virtuality of field.
2745 The default accessibility for members is public, the default
2746 accessibility for inheritance is private. */
2747 if (die
->tag
!= DW_TAG_inheritance
)
2748 new_field
->accessibility
= DW_ACCESS_public
;
2750 new_field
->accessibility
= DW_ACCESS_private
;
2751 new_field
->virtuality
= DW_VIRTUALITY_none
;
2753 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
2755 new_field
->accessibility
= DW_UNSND (attr
);
2756 if (new_field
->accessibility
!= DW_ACCESS_public
)
2757 fip
->non_public_fields
= 1;
2758 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
2760 new_field
->virtuality
= DW_UNSND (attr
);
2762 fp
= &new_field
->field
;
2764 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
2766 /* Data member other than a C++ static data member. */
2768 /* Get type of field. */
2769 fp
->type
= die_type (die
, cu
);
2771 FIELD_STATIC_KIND (*fp
) = 0;
2773 /* Get bit size of field (zero if none). */
2774 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
2777 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2781 FIELD_BITSIZE (*fp
) = 0;
2784 /* Get bit offset of field. */
2785 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
2788 FIELD_BITPOS (*fp
) =
2789 decode_locdesc (DW_BLOCK (attr
), cu
) * bits_per_byte
;
2792 FIELD_BITPOS (*fp
) = 0;
2793 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
2796 if (BITS_BIG_ENDIAN
)
2798 /* For big endian bits, the DW_AT_bit_offset gives the
2799 additional bit offset from the MSB of the containing
2800 anonymous object to the MSB of the field. We don't
2801 have to do anything special since we don't need to
2802 know the size of the anonymous object. */
2803 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2807 /* For little endian bits, compute the bit offset to the
2808 MSB of the anonymous object, subtract off the number of
2809 bits from the MSB of the field to the MSB of the
2810 object, and then subtract off the number of bits of
2811 the field itself. The result is the bit offset of
2812 the LSB of the field. */
2814 int bit_offset
= DW_UNSND (attr
);
2816 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
2819 /* The size of the anonymous object containing
2820 the bit field is explicit, so use the
2821 indicated size (in bytes). */
2822 anonymous_size
= DW_UNSND (attr
);
2826 /* The size of the anonymous object containing
2827 the bit field must be inferred from the type
2828 attribute of the data member containing the
2830 anonymous_size
= TYPE_LENGTH (fp
->type
);
2832 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2833 - bit_offset
- FIELD_BITSIZE (*fp
);
2837 /* Get name of field. */
2838 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2839 if (attr
&& DW_STRING (attr
))
2840 fieldname
= DW_STRING (attr
);
2842 /* The name is already allocated along with this objfile, so we don't
2843 need to duplicate it for the type. */
2844 fp
->name
= fieldname
;
2846 /* Change accessibility for artificial fields (e.g. virtual table
2847 pointer or virtual base class pointer) to private. */
2848 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
2850 new_field
->accessibility
= DW_ACCESS_private
;
2851 fip
->non_public_fields
= 1;
2854 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
2856 /* C++ static member. */
2858 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2859 is a declaration, but all versions of G++ as of this writing
2860 (so through at least 3.2.1) incorrectly generate
2861 DW_TAG_variable tags. */
2865 /* Get name of field. */
2866 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2867 if (attr
&& DW_STRING (attr
))
2868 fieldname
= DW_STRING (attr
);
2872 /* Get physical name. */
2873 physname
= dwarf2_linkage_name (die
, cu
);
2875 /* The name is already allocated along with this objfile, so we don't
2876 need to duplicate it for the type. */
2877 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
2878 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2879 FIELD_NAME (*fp
) = fieldname
;
2881 else if (die
->tag
== DW_TAG_inheritance
)
2883 /* C++ base class field. */
2884 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
2886 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
2888 FIELD_BITSIZE (*fp
) = 0;
2889 FIELD_STATIC_KIND (*fp
) = 0;
2890 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2891 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2892 fip
->nbaseclasses
++;
2896 /* Create the vector of fields, and attach it to the type. */
2899 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2900 struct dwarf2_cu
*cu
)
2902 int nfields
= fip
->nfields
;
2904 /* Record the field count, allocate space for the array of fields,
2905 and create blank accessibility bitfields if necessary. */
2906 TYPE_NFIELDS (type
) = nfields
;
2907 TYPE_FIELDS (type
) = (struct field
*)
2908 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2909 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2911 if (fip
->non_public_fields
)
2913 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2915 TYPE_FIELD_PRIVATE_BITS (type
) =
2916 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2917 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2919 TYPE_FIELD_PROTECTED_BITS (type
) =
2920 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2921 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2923 TYPE_FIELD_IGNORE_BITS (type
) =
2924 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2925 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2928 /* If the type has baseclasses, allocate and clear a bit vector for
2929 TYPE_FIELD_VIRTUAL_BITS. */
2930 if (fip
->nbaseclasses
)
2932 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2935 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2936 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2937 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2938 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2939 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2942 /* Copy the saved-up fields into the field vector. Start from the head
2943 of the list, adding to the tail of the field array, so that they end
2944 up in the same order in the array in which they were added to the list. */
2945 while (nfields
-- > 0)
2947 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2948 switch (fip
->fields
->accessibility
)
2950 case DW_ACCESS_private
:
2951 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2954 case DW_ACCESS_protected
:
2955 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2958 case DW_ACCESS_public
:
2962 /* Unknown accessibility. Complain and treat it as public. */
2964 complaint (&symfile_complaints
, "unsupported accessibility %d",
2965 fip
->fields
->accessibility
);
2969 if (nfields
< fip
->nbaseclasses
)
2971 switch (fip
->fields
->virtuality
)
2973 case DW_VIRTUALITY_virtual
:
2974 case DW_VIRTUALITY_pure_virtual
:
2975 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2979 fip
->fields
= fip
->fields
->next
;
2983 /* Add a member function to the proper fieldlist. */
2986 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2987 struct type
*type
, struct dwarf2_cu
*cu
)
2989 struct objfile
*objfile
= cu
->objfile
;
2990 struct attribute
*attr
;
2991 struct fnfieldlist
*flp
;
2993 struct fn_field
*fnp
;
2996 struct nextfnfield
*new_fnfield
;
2998 /* Get name of member function. */
2999 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3000 if (attr
&& DW_STRING (attr
))
3001 fieldname
= DW_STRING (attr
);
3005 /* Get the mangled name. */
3006 physname
= dwarf2_linkage_name (die
, cu
);
3008 /* Look up member function name in fieldlist. */
3009 for (i
= 0; i
< fip
->nfnfields
; i
++)
3011 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3015 /* Create new list element if necessary. */
3016 if (i
< fip
->nfnfields
)
3017 flp
= &fip
->fnfieldlists
[i
];
3020 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3022 fip
->fnfieldlists
= (struct fnfieldlist
*)
3023 xrealloc (fip
->fnfieldlists
,
3024 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3025 * sizeof (struct fnfieldlist
));
3026 if (fip
->nfnfields
== 0)
3027 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3029 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3030 flp
->name
= fieldname
;
3036 /* Create a new member function field and chain it to the field list
3038 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3039 make_cleanup (xfree
, new_fnfield
);
3040 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3041 new_fnfield
->next
= flp
->head
;
3042 flp
->head
= new_fnfield
;
3045 /* Fill in the member function field info. */
3046 fnp
= &new_fnfield
->fnfield
;
3047 /* The name is already allocated along with this objfile, so we don't
3048 need to duplicate it for the type. */
3049 fnp
->physname
= physname
? physname
: "";
3050 fnp
->type
= alloc_type (objfile
);
3051 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
3053 int nparams
= TYPE_NFIELDS (die
->type
);
3055 /* TYPE is the domain of this method, and DIE->TYPE is the type
3056 of the method itself (TYPE_CODE_METHOD). */
3057 smash_to_method_type (fnp
->type
, type
,
3058 TYPE_TARGET_TYPE (die
->type
),
3059 TYPE_FIELDS (die
->type
),
3060 TYPE_NFIELDS (die
->type
),
3061 TYPE_VARARGS (die
->type
));
3063 /* Handle static member functions.
3064 Dwarf2 has no clean way to discern C++ static and non-static
3065 member functions. G++ helps GDB by marking the first
3066 parameter for non-static member functions (which is the
3067 this pointer) as artificial. We obtain this information
3068 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3069 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
3070 fnp
->voffset
= VOFFSET_STATIC
;
3073 complaint (&symfile_complaints
, "member function type missing for '%s'",
3076 /* Get fcontext from DW_AT_containing_type if present. */
3077 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3078 fnp
->fcontext
= die_containing_type (die
, cu
);
3080 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3081 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3083 /* Get accessibility. */
3084 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3087 switch (DW_UNSND (attr
))
3089 case DW_ACCESS_private
:
3090 fnp
->is_private
= 1;
3092 case DW_ACCESS_protected
:
3093 fnp
->is_protected
= 1;
3098 /* Check for artificial methods. */
3099 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3100 if (attr
&& DW_UNSND (attr
) != 0)
3101 fnp
->is_artificial
= 1;
3103 /* Get index in virtual function table if it is a virtual member function. */
3104 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3107 /* Support the .debug_loc offsets */
3108 if (attr_form_is_block (attr
))
3110 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3112 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3114 dwarf2_complex_location_expr_complaint ();
3118 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3124 /* Create the vector of member function fields, and attach it to the type. */
3127 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3128 struct dwarf2_cu
*cu
)
3130 struct fnfieldlist
*flp
;
3131 int total_length
= 0;
3134 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3135 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3136 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3138 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3140 struct nextfnfield
*nfp
= flp
->head
;
3141 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3144 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3145 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3146 fn_flp
->fn_fields
= (struct fn_field
*)
3147 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3148 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3149 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3151 total_length
+= flp
->length
;
3154 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3155 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3158 /* Called when we find the DIE that starts a structure or union scope
3159 (definition) to process all dies that define the members of the
3162 NOTE: we need to call struct_type regardless of whether or not the
3163 DIE has an at_name attribute, since it might be an anonymous
3164 structure or union. This gets the type entered into our set of
3167 However, if the structure is incomplete (an opaque struct/union)
3168 then suppress creating a symbol table entry for it since gdb only
3169 wants to find the one with the complete definition. Note that if
3170 it is complete, we just call new_symbol, which does it's own
3171 checking about whether the struct/union is anonymous or not (and
3172 suppresses creating a symbol table entry itself). */
3175 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3177 struct objfile
*objfile
= cu
->objfile
;
3179 struct attribute
*attr
;
3180 const char *previous_prefix
= processing_current_prefix
;
3181 struct cleanup
*back_to
= NULL
;
3186 type
= alloc_type (objfile
);
3188 INIT_CPLUS_SPECIFIC (type
);
3189 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3190 if (attr
&& DW_STRING (attr
))
3192 if (cu
->language
== language_cplus
)
3194 char *new_prefix
= determine_class_name (die
, cu
);
3195 TYPE_TAG_NAME (type
) = obsavestring (new_prefix
,
3196 strlen (new_prefix
),
3197 &objfile
->objfile_obstack
);
3198 back_to
= make_cleanup (xfree
, new_prefix
);
3199 processing_current_prefix
= new_prefix
;
3203 /* The name is already allocated along with this objfile, so
3204 we don't need to duplicate it for the type. */
3205 TYPE_TAG_NAME (type
) = DW_STRING (attr
);
3209 if (die
->tag
== DW_TAG_structure_type
)
3211 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
3213 else if (die
->tag
== DW_TAG_union_type
)
3215 TYPE_CODE (type
) = TYPE_CODE_UNION
;
3219 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
3221 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
3224 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3227 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3231 TYPE_LENGTH (type
) = 0;
3234 if (die_is_declaration (die
, cu
))
3235 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
3237 /* We need to add the type field to the die immediately so we don't
3238 infinitely recurse when dealing with pointers to the structure
3239 type within the structure itself. */
3242 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3244 struct field_info fi
;
3245 struct die_info
*child_die
;
3246 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
3248 memset (&fi
, 0, sizeof (struct field_info
));
3250 child_die
= die
->child
;
3252 while (child_die
&& child_die
->tag
)
3254 if (child_die
->tag
== DW_TAG_member
3255 || child_die
->tag
== DW_TAG_variable
)
3257 /* NOTE: carlton/2002-11-05: A C++ static data member
3258 should be a DW_TAG_member that is a declaration, but
3259 all versions of G++ as of this writing (so through at
3260 least 3.2.1) incorrectly generate DW_TAG_variable
3261 tags for them instead. */
3262 dwarf2_add_field (&fi
, child_die
, cu
);
3264 else if (child_die
->tag
== DW_TAG_subprogram
)
3266 /* C++ member function. */
3267 read_type_die (child_die
, cu
);
3268 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
3270 else if (child_die
->tag
== DW_TAG_inheritance
)
3272 /* C++ base class field. */
3273 dwarf2_add_field (&fi
, child_die
, cu
);
3275 child_die
= sibling_die (child_die
);
3278 /* Attach fields and member functions to the type. */
3280 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
3283 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
3285 /* Get the type which refers to the base class (possibly this
3286 class itself) which contains the vtable pointer for the current
3287 class from the DW_AT_containing_type attribute. */
3289 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3291 struct type
*t
= die_containing_type (die
, cu
);
3293 TYPE_VPTR_BASETYPE (type
) = t
;
3296 static const char vptr_name
[] =
3297 {'_', 'v', 'p', 't', 'r', '\0'};
3300 /* Our own class provides vtbl ptr. */
3301 for (i
= TYPE_NFIELDS (t
) - 1;
3302 i
>= TYPE_N_BASECLASSES (t
);
3305 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
3307 if ((strncmp (fieldname
, vptr_name
,
3308 strlen (vptr_name
) - 1)
3310 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
3312 TYPE_VPTR_FIELDNO (type
) = i
;
3317 /* Complain if virtual function table field not found. */
3318 if (i
< TYPE_N_BASECLASSES (t
))
3319 complaint (&symfile_complaints
,
3320 "virtual function table pointer not found when defining class '%s'",
3321 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
3326 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3331 do_cleanups (back_to
);
3334 processing_current_prefix
= previous_prefix
;
3335 if (back_to
!= NULL
)
3336 do_cleanups (back_to
);
3340 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3342 struct objfile
*objfile
= cu
->objfile
;
3343 const char *previous_prefix
= processing_current_prefix
;
3344 struct die_info
*child_die
= die
->child
;
3346 if (TYPE_TAG_NAME (die
->type
) != NULL
)
3347 processing_current_prefix
= TYPE_TAG_NAME (die
->type
);
3349 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
3350 snapshots) has been known to create a die giving a declaration
3351 for a class that has, as a child, a die giving a definition for a
3352 nested class. So we have to process our children even if the
3353 current die is a declaration. Normally, of course, a declaration
3354 won't have any children at all. */
3356 while (child_die
!= NULL
&& child_die
->tag
)
3358 if (child_die
->tag
== DW_TAG_member
3359 || child_die
->tag
== DW_TAG_variable
3360 || child_die
->tag
== DW_TAG_inheritance
)
3365 process_die (child_die
, cu
);
3367 child_die
= sibling_die (child_die
);
3370 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3371 new_symbol (die
, die
->type
, cu
);
3373 processing_current_prefix
= previous_prefix
;
3376 /* Given a DW_AT_enumeration_type die, set its type. We do not
3377 complete the type's fields yet, or create any symbols. */
3380 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3382 struct objfile
*objfile
= cu
->objfile
;
3384 struct attribute
*attr
;
3389 type
= alloc_type (objfile
);
3391 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3392 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3393 if (attr
&& DW_STRING (attr
))
3395 char *name
= DW_STRING (attr
);
3397 if (processing_has_namespace_info
)
3399 TYPE_TAG_NAME (type
) = obconcat (&objfile
->objfile_obstack
,
3400 processing_current_prefix
,
3401 processing_current_prefix
[0] == '\0'
3407 /* The name is already allocated along with this objfile, so
3408 we don't need to duplicate it for the type. */
3409 TYPE_TAG_NAME (type
) = name
;
3413 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3416 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3420 TYPE_LENGTH (type
) = 0;
3426 /* Determine the name of the type represented by DIE, which should be
3427 a named C++ compound type. Return the name in question; the caller
3428 is responsible for xfree()'ing it. */
3431 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
3433 struct cleanup
*back_to
= NULL
;
3434 struct die_info
*spec_die
= die_specification (die
, cu
);
3435 char *new_prefix
= NULL
;
3437 /* If this is the definition of a class that is declared by another
3438 die, then processing_current_prefix may not be accurate; see
3439 read_func_scope for a similar example. */
3440 if (spec_die
!= NULL
)
3442 char *specification_prefix
= determine_prefix (spec_die
, cu
);
3443 processing_current_prefix
= specification_prefix
;
3444 back_to
= make_cleanup (xfree
, specification_prefix
);
3447 /* If we don't have namespace debug info, guess the name by trying
3448 to demangle the names of members, just like we did in
3449 guess_structure_name. */
3450 if (!processing_has_namespace_info
)
3452 struct die_info
*child
;
3454 for (child
= die
->child
;
3455 child
!= NULL
&& child
->tag
!= 0;
3456 child
= sibling_die (child
))
3458 if (child
->tag
== DW_TAG_subprogram
)
3460 new_prefix
= class_name_from_physname (dwarf2_linkage_name
3463 if (new_prefix
!= NULL
)
3469 if (new_prefix
== NULL
)
3471 const char *name
= dwarf2_name (die
, cu
);
3472 new_prefix
= typename_concat (processing_current_prefix
,
3473 name
? name
: "<<anonymous>>");
3476 if (back_to
!= NULL
)
3477 do_cleanups (back_to
);
3482 /* Given a pointer to a die which begins an enumeration, process all
3483 the dies that define the members of the enumeration, and create the
3484 symbol for the enumeration type.
3486 NOTE: We reverse the order of the element list. */
3489 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3491 struct objfile
*objfile
= cu
->objfile
;
3492 struct die_info
*child_die
;
3493 struct field
*fields
;
3494 struct attribute
*attr
;
3497 int unsigned_enum
= 1;
3501 if (die
->child
!= NULL
)
3503 child_die
= die
->child
;
3504 while (child_die
&& child_die
->tag
)
3506 if (child_die
->tag
!= DW_TAG_enumerator
)
3508 process_die (child_die
, cu
);
3512 attr
= dwarf2_attr (child_die
, DW_AT_name
, cu
);
3515 sym
= new_symbol (child_die
, die
->type
, cu
);
3516 if (SYMBOL_VALUE (sym
) < 0)
3519 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3521 fields
= (struct field
*)
3523 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
3524 * sizeof (struct field
));
3527 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
3528 FIELD_TYPE (fields
[num_fields
]) = NULL
;
3529 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
3530 FIELD_BITSIZE (fields
[num_fields
]) = 0;
3531 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
3537 child_die
= sibling_die (child_die
);
3542 TYPE_NFIELDS (die
->type
) = num_fields
;
3543 TYPE_FIELDS (die
->type
) = (struct field
*)
3544 TYPE_ALLOC (die
->type
, sizeof (struct field
) * num_fields
);
3545 memcpy (TYPE_FIELDS (die
->type
), fields
,
3546 sizeof (struct field
) * num_fields
);
3550 TYPE_FLAGS (die
->type
) |= TYPE_FLAG_UNSIGNED
;
3553 new_symbol (die
, die
->type
, cu
);
3556 /* Extract all information from a DW_TAG_array_type DIE and put it in
3557 the DIE's type field. For now, this only handles one dimensional
3561 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3563 struct objfile
*objfile
= cu
->objfile
;
3564 struct die_info
*child_die
;
3565 struct type
*type
= NULL
;
3566 struct type
*element_type
, *range_type
, *index_type
;
3567 struct type
**range_types
= NULL
;
3568 struct attribute
*attr
;
3570 struct cleanup
*back_to
;
3572 /* Return if we've already decoded this type. */
3578 element_type
= die_type (die
, cu
);
3580 /* Irix 6.2 native cc creates array types without children for
3581 arrays with unspecified length. */
3582 if (die
->child
== NULL
)
3584 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
3585 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3586 die
->type
= create_array_type (NULL
, element_type
, range_type
);
3590 back_to
= make_cleanup (null_cleanup
, NULL
);
3591 child_die
= die
->child
;
3592 while (child_die
&& child_die
->tag
)
3594 if (child_die
->tag
== DW_TAG_subrange_type
)
3596 read_subrange_type (child_die
, cu
);
3598 if (child_die
->type
!= NULL
)
3600 /* The range type was succesfully read. Save it for
3601 the array type creation. */
3602 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3604 range_types
= (struct type
**)
3605 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3606 * sizeof (struct type
*));
3608 make_cleanup (free_current_contents
, &range_types
);
3610 range_types
[ndim
++] = child_die
->type
;
3613 child_die
= sibling_die (child_die
);
3616 /* Dwarf2 dimensions are output from left to right, create the
3617 necessary array types in backwards order. */
3618 type
= element_type
;
3620 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3622 /* Understand Dwarf2 support for vector types (like they occur on
3623 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3624 array type. This is not part of the Dwarf2/3 standard yet, but a
3625 custom vendor extension. The main difference between a regular
3626 array and the vector variant is that vectors are passed by value
3628 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
3630 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3632 do_cleanups (back_to
);
3634 /* Install the type in the die. */
3638 /* First cut: install each common block member as a global variable. */
3641 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
3643 struct die_info
*child_die
;
3644 struct attribute
*attr
;
3646 CORE_ADDR base
= (CORE_ADDR
) 0;
3648 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
3651 /* Support the .debug_loc offsets */
3652 if (attr_form_is_block (attr
))
3654 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
3656 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3658 dwarf2_complex_location_expr_complaint ();
3662 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3663 "common block member");
3666 if (die
->child
!= NULL
)
3668 child_die
= die
->child
;
3669 while (child_die
&& child_die
->tag
)
3671 sym
= new_symbol (child_die
, NULL
, cu
);
3672 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
3675 SYMBOL_VALUE_ADDRESS (sym
) =
3676 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
3677 add_symbol_to_list (sym
, &global_symbols
);
3679 child_die
= sibling_die (child_die
);
3684 /* Read a C++ namespace. */
3687 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3689 struct objfile
*objfile
= cu
->objfile
;
3690 const char *previous_prefix
= processing_current_prefix
;
3693 struct die_info
*current_die
;
3695 name
= namespace_name (die
, &is_anonymous
, cu
);
3697 /* Now build the name of the current namespace. */
3699 if (previous_prefix
[0] == '\0')
3701 processing_current_prefix
= name
;
3705 /* We need temp_name around because processing_current_prefix
3706 is a const char *. */
3707 char *temp_name
= alloca (strlen (previous_prefix
)
3708 + 2 + strlen(name
) + 1);
3709 strcpy (temp_name
, previous_prefix
);
3710 strcat (temp_name
, "::");
3711 strcat (temp_name
, name
);
3713 processing_current_prefix
= temp_name
;
3716 /* Add a symbol associated to this if we haven't seen the namespace
3717 before. Also, add a using directive if it's an anonymous
3720 if (dwarf2_extension (die
, cu
) == NULL
)
3724 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3725 this cast will hopefully become unnecessary. */
3726 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
3727 (char *) processing_current_prefix
,
3729 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
3731 new_symbol (die
, type
, cu
);
3735 cp_add_using_directive (processing_current_prefix
,
3736 strlen (previous_prefix
),
3737 strlen (processing_current_prefix
));
3740 if (die
->child
!= NULL
)
3742 struct die_info
*child_die
= die
->child
;
3744 while (child_die
&& child_die
->tag
)
3746 process_die (child_die
, cu
);
3747 child_die
= sibling_die (child_die
);
3751 processing_current_prefix
= previous_prefix
;
3754 /* Return the name of the namespace represented by DIE. Set
3755 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
3759 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
3761 struct die_info
*current_die
;
3762 const char *name
= NULL
;
3764 /* Loop through the extensions until we find a name. */
3766 for (current_die
= die
;
3767 current_die
!= NULL
;
3768 current_die
= dwarf2_extension (die
, cu
))
3770 name
= dwarf2_name (current_die
, cu
);
3775 /* Is it an anonymous namespace? */
3777 *is_anonymous
= (name
== NULL
);
3779 name
= "(anonymous namespace)";
3784 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3785 the user defined type vector. */
3788 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3790 struct comp_unit_head
*cu_header
= &cu
->header
;
3792 struct attribute
*attr_byte_size
;
3793 struct attribute
*attr_address_class
;
3794 int byte_size
, addr_class
;
3801 type
= lookup_pointer_type (die_type (die
, cu
));
3803 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3805 byte_size
= DW_UNSND (attr_byte_size
);
3807 byte_size
= cu_header
->addr_size
;
3809 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
3810 if (attr_address_class
)
3811 addr_class
= DW_UNSND (attr_address_class
);
3813 addr_class
= DW_ADDR_none
;
3815 /* If the pointer size or address class is different than the
3816 default, create a type variant marked as such and set the
3817 length accordingly. */
3818 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3820 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3824 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3825 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3826 type
= make_type_with_address_space (type
, type_flags
);
3828 else if (TYPE_LENGTH (type
) != byte_size
)
3830 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3833 /* Should we also complain about unhandled address classes? */
3837 TYPE_LENGTH (type
) = byte_size
;
3841 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3842 the user defined type vector. */
3845 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3847 struct objfile
*objfile
= cu
->objfile
;
3849 struct type
*to_type
;
3850 struct type
*domain
;
3857 type
= alloc_type (objfile
);
3858 to_type
= die_type (die
, cu
);
3859 domain
= die_containing_type (die
, cu
);
3860 smash_to_member_type (type
, domain
, to_type
);
3865 /* Extract all information from a DW_TAG_reference_type DIE and add to
3866 the user defined type vector. */
3869 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3871 struct comp_unit_head
*cu_header
= &cu
->header
;
3873 struct attribute
*attr
;
3880 type
= lookup_reference_type (die_type (die
, cu
));
3881 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3884 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3888 TYPE_LENGTH (type
) = cu_header
->addr_size
;
3894 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3896 struct type
*base_type
;
3903 base_type
= die_type (die
, cu
);
3904 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
3908 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3910 struct type
*base_type
;
3917 base_type
= die_type (die
, cu
);
3918 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
3921 /* Extract all information from a DW_TAG_string_type DIE and add to
3922 the user defined type vector. It isn't really a user defined type,
3923 but it behaves like one, with other DIE's using an AT_user_def_type
3924 attribute to reference it. */
3927 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3929 struct objfile
*objfile
= cu
->objfile
;
3930 struct type
*type
, *range_type
, *index_type
, *char_type
;
3931 struct attribute
*attr
;
3932 unsigned int length
;
3939 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
3942 length
= DW_UNSND (attr
);
3946 /* check for the DW_AT_byte_size attribute */
3947 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3950 length
= DW_UNSND (attr
);
3957 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
3958 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3959 if (cu
->language
== language_fortran
)
3961 /* Need to create a unique string type for bounds
3963 type
= create_string_type (0, range_type
);
3967 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
, cu
);
3968 type
= create_string_type (char_type
, range_type
);
3973 /* Handle DIES due to C code like:
3977 int (*funcp)(int a, long l);
3981 ('funcp' generates a DW_TAG_subroutine_type DIE)
3985 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3987 struct type
*type
; /* Type that this function returns */
3988 struct type
*ftype
; /* Function that returns above type */
3989 struct attribute
*attr
;
3991 /* Decode the type that this subroutine returns */
3996 type
= die_type (die
, cu
);
3997 ftype
= lookup_function_type (type
);
3999 /* All functions in C++ have prototypes. */
4000 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4001 if ((attr
&& (DW_UNSND (attr
) != 0))
4002 || cu
->language
== language_cplus
)
4003 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
4005 if (die
->child
!= NULL
)
4007 struct die_info
*child_die
;
4011 /* Count the number of parameters.
4012 FIXME: GDB currently ignores vararg functions, but knows about
4013 vararg member functions. */
4014 child_die
= die
->child
;
4015 while (child_die
&& child_die
->tag
)
4017 if (child_die
->tag
== DW_TAG_formal_parameter
)
4019 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4020 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
4021 child_die
= sibling_die (child_die
);
4024 /* Allocate storage for parameters and fill them in. */
4025 TYPE_NFIELDS (ftype
) = nparams
;
4026 TYPE_FIELDS (ftype
) = (struct field
*)
4027 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
4029 child_die
= die
->child
;
4030 while (child_die
&& child_die
->tag
)
4032 if (child_die
->tag
== DW_TAG_formal_parameter
)
4034 /* Dwarf2 has no clean way to discern C++ static and non-static
4035 member functions. G++ helps GDB by marking the first
4036 parameter for non-static member functions (which is the
4037 this pointer) as artificial. We pass this information
4038 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4039 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4041 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4043 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4044 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4047 child_die
= sibling_die (child_die
);
4055 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4057 struct objfile
*objfile
= cu
->objfile
;
4058 struct attribute
*attr
;
4063 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4064 if (attr
&& DW_STRING (attr
))
4066 name
= DW_STRING (attr
);
4068 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
4069 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
4073 /* Find a representation of a given base type and install
4074 it in the TYPE field of the die. */
4077 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4079 struct objfile
*objfile
= cu
->objfile
;
4081 struct attribute
*attr
;
4082 int encoding
= 0, size
= 0;
4084 /* If we've already decoded this die, this is a no-op. */
4090 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4093 encoding
= DW_UNSND (attr
);
4095 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4098 size
= DW_UNSND (attr
);
4100 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4101 if (attr
&& DW_STRING (attr
))
4103 enum type_code code
= TYPE_CODE_INT
;
4108 case DW_ATE_address
:
4109 /* Turn DW_ATE_address into a void * pointer. */
4110 code
= TYPE_CODE_PTR
;
4111 type_flags
|= TYPE_FLAG_UNSIGNED
;
4113 case DW_ATE_boolean
:
4114 code
= TYPE_CODE_BOOL
;
4115 type_flags
|= TYPE_FLAG_UNSIGNED
;
4117 case DW_ATE_complex_float
:
4118 code
= TYPE_CODE_COMPLEX
;
4121 code
= TYPE_CODE_FLT
;
4124 case DW_ATE_signed_char
:
4126 case DW_ATE_unsigned
:
4127 case DW_ATE_unsigned_char
:
4128 type_flags
|= TYPE_FLAG_UNSIGNED
;
4131 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
4132 dwarf_type_encoding_name (encoding
));
4135 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
4136 if (encoding
== DW_ATE_address
)
4137 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
,
4139 else if (encoding
== DW_ATE_complex_float
)
4142 TYPE_TARGET_TYPE (type
)
4143 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
, cu
);
4144 else if (size
== 16)
4145 TYPE_TARGET_TYPE (type
)
4146 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
4148 TYPE_TARGET_TYPE (type
)
4149 = dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
4154 type
= dwarf_base_type (encoding
, size
, cu
);
4159 /* Read the given DW_AT_subrange DIE. */
4162 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4164 struct type
*base_type
;
4165 struct type
*range_type
;
4166 struct attribute
*attr
;
4170 /* If we have already decoded this die, then nothing more to do. */
4174 base_type
= die_type (die
, cu
);
4175 if (base_type
== NULL
)
4177 complaint (&symfile_complaints
,
4178 "DW_AT_type missing from DW_TAG_subrange_type");
4182 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
4183 base_type
= alloc_type (NULL
);
4185 if (cu
->language
== language_fortran
)
4187 /* FORTRAN implies a lower bound of 1, if not given. */
4191 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
4193 low
= dwarf2_get_attr_constant_value (attr
, 0);
4195 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
4198 if (attr
->form
== DW_FORM_block1
)
4200 /* GCC encodes arrays with unspecified or dynamic length
4201 with a DW_FORM_block1 attribute.
4202 FIXME: GDB does not yet know how to handle dynamic
4203 arrays properly, treat them as arrays with unspecified
4206 FIXME: jimb/2003-09-22: GDB does not really know
4207 how to handle arrays of unspecified length
4208 either; we just represent them as zero-length
4209 arrays. Choose an appropriate upper bound given
4210 the lower bound we've computed above. */
4214 high
= dwarf2_get_attr_constant_value (attr
, 1);
4217 range_type
= create_range_type (NULL
, base_type
, low
, high
);
4219 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4220 if (attr
&& DW_STRING (attr
))
4221 TYPE_NAME (range_type
) = DW_STRING (attr
);
4223 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4225 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
4227 die
->type
= range_type
;
4231 /* Read a whole compilation unit into a linked list of dies. */
4233 static struct die_info
*
4234 read_comp_unit (char *info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
4236 /* Reset die reference table; we are
4237 building new ones now. */
4238 dwarf2_empty_hash_tables ();
4240 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
4243 /* Read a single die and all its descendents. Set the die's sibling
4244 field to NULL; set other fields in the die correctly, and set all
4245 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4246 location of the info_ptr after reading all of those dies. PARENT
4247 is the parent of the die in question. */
4249 static struct die_info
*
4250 read_die_and_children (char *info_ptr
, bfd
*abfd
,
4251 struct dwarf2_cu
*cu
,
4252 char **new_info_ptr
,
4253 struct die_info
*parent
)
4255 struct die_info
*die
;
4259 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
4260 store_in_ref_table (die
->offset
, die
);
4264 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
4270 *new_info_ptr
= cur_ptr
;
4273 die
->sibling
= NULL
;
4274 die
->parent
= parent
;
4278 /* Read a die, all of its descendents, and all of its siblings; set
4279 all of the fields of all of the dies correctly. Arguments are as
4280 in read_die_and_children. */
4282 static struct die_info
*
4283 read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
4284 struct dwarf2_cu
*cu
,
4285 char **new_info_ptr
,
4286 struct die_info
*parent
)
4288 struct die_info
*first_die
, *last_sibling
;
4292 first_die
= last_sibling
= NULL
;
4296 struct die_info
*die
4297 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
4305 last_sibling
->sibling
= die
;
4310 *new_info_ptr
= cur_ptr
;
4320 /* Free a linked list of dies. */
4323 free_die_list (struct die_info
*dies
)
4325 struct die_info
*die
, *next
;
4330 if (die
->child
!= NULL
)
4331 free_die_list (die
->child
);
4332 next
= die
->sibling
;
4340 do_free_die_list_cleanup (void *dies
)
4342 free_die_list (dies
);
4345 static struct cleanup
*
4346 make_cleanup_free_die_list (struct die_info
*dies
)
4348 return make_cleanup (do_free_die_list_cleanup
, dies
);
4352 /* Read the contents of the section at OFFSET and of size SIZE from the
4353 object file specified by OBJFILE into the objfile_obstack and return it. */
4356 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
4358 bfd
*abfd
= objfile
->obfd
;
4360 bfd_size_type size
= bfd_get_section_size_before_reloc (sectp
);
4365 buf
= (char *) obstack_alloc (&objfile
->objfile_obstack
, size
);
4367 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
4371 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
4372 || bfd_bread (buf
, size
, abfd
) != size
)
4373 error ("Dwarf Error: Can't read DWARF data from '%s'",
4374 bfd_get_filename (abfd
));
4379 /* In DWARF version 2, the description of the debugging information is
4380 stored in a separate .debug_abbrev section. Before we read any
4381 dies from a section we read in all abbreviations and install them
4382 in a hash table. This function also sets flags in CU describing
4383 the data found in the abbrev table. */
4386 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
4388 struct comp_unit_head
*cu_header
= &cu
->header
;
4390 struct abbrev_info
*cur_abbrev
;
4391 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
4392 unsigned int abbrev_form
, hash_number
;
4393 struct attr_abbrev
*cur_attrs
;
4394 unsigned int allocated_attrs
;
4396 /* Initialize dwarf2 abbrevs */
4397 obstack_init (&cu
->abbrev_obstack
);
4398 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
4400 * sizeof (struct abbrev_info
*)));
4401 memset (cu
->dwarf2_abbrevs
, 0,
4402 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
4404 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
4405 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4406 abbrev_ptr
+= bytes_read
;
4408 allocated_attrs
= ATTR_ALLOC_CHUNK
;
4409 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
4411 /* loop until we reach an abbrev number of 0 */
4412 while (abbrev_number
)
4414 cur_abbrev
= dwarf_alloc_abbrev (cu
);
4416 /* read in abbrev header */
4417 cur_abbrev
->number
= abbrev_number
;
4418 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4419 abbrev_ptr
+= bytes_read
;
4420 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
4423 if (cur_abbrev
->tag
== DW_TAG_namespace
)
4424 cu
->has_namespace_info
= 1;
4426 /* now read in declarations */
4427 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4428 abbrev_ptr
+= bytes_read
;
4429 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4430 abbrev_ptr
+= bytes_read
;
4433 if (cur_abbrev
->num_attrs
== allocated_attrs
)
4435 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
4437 = xrealloc (cur_attrs
, (allocated_attrs
4438 * sizeof (struct attr_abbrev
)));
4440 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
4441 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
4442 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4443 abbrev_ptr
+= bytes_read
;
4444 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4445 abbrev_ptr
+= bytes_read
;
4448 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
4449 (cur_abbrev
->num_attrs
4450 * sizeof (struct attr_abbrev
)));
4451 memcpy (cur_abbrev
->attrs
, cur_attrs
,
4452 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
4454 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
4455 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
4456 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
4458 /* Get next abbreviation.
4459 Under Irix6 the abbreviations for a compilation unit are not
4460 always properly terminated with an abbrev number of 0.
4461 Exit loop if we encounter an abbreviation which we have
4462 already read (which means we are about to read the abbreviations
4463 for the next compile unit) or if the end of the abbreviation
4464 table is reached. */
4465 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
4466 >= dwarf2_per_objfile
->abbrev_size
)
4468 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4469 abbrev_ptr
+= bytes_read
;
4470 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
4477 /* Release the memory used by the abbrev table for a compilation unit. */
4480 dwarf2_free_abbrev_table (void *ptr_to_cu
)
4482 struct dwarf2_cu
*cu
= ptr_to_cu
;
4484 obstack_free (&cu
->abbrev_obstack
, NULL
);
4485 cu
->dwarf2_abbrevs
= NULL
;
4488 /* Lookup an abbrev_info structure in the abbrev hash table. */
4490 static struct abbrev_info
*
4491 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
4493 unsigned int hash_number
;
4494 struct abbrev_info
*abbrev
;
4496 hash_number
= number
% ABBREV_HASH_SIZE
;
4497 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
4501 if (abbrev
->number
== number
)
4504 abbrev
= abbrev
->next
;
4509 /* Returns nonzero if TAG represents a type that we might generate a partial
4513 is_type_tag_for_partial (int tag
)
4518 /* Some types that would be reasonable to generate partial symbols for,
4519 that we don't at present. */
4520 case DW_TAG_array_type
:
4521 case DW_TAG_file_type
:
4522 case DW_TAG_ptr_to_member_type
:
4523 case DW_TAG_set_type
:
4524 case DW_TAG_string_type
:
4525 case DW_TAG_subroutine_type
:
4527 case DW_TAG_base_type
:
4528 case DW_TAG_class_type
:
4529 case DW_TAG_enumeration_type
:
4530 case DW_TAG_structure_type
:
4531 case DW_TAG_subrange_type
:
4532 case DW_TAG_typedef
:
4533 case DW_TAG_union_type
:
4540 /* Load all DIEs that are interesting for partial symbols into memory. */
4542 static struct partial_die_info
*
4543 load_partial_dies (bfd
*abfd
, char *info_ptr
, int building_psymtab
,
4544 struct dwarf2_cu
*cu
)
4546 struct partial_die_info
*part_die
;
4547 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
4548 struct abbrev_info
*abbrev
;
4549 unsigned int bytes_read
;
4551 int nesting_level
= 1;
4557 = htab_create_alloc_ex (cu
->header
.length
/ 12,
4561 &cu
->comp_unit_obstack
,
4562 hashtab_obstack_allocate
,
4563 dummy_obstack_deallocate
);
4565 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
4566 sizeof (struct partial_die_info
));
4570 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4572 /* A NULL abbrev means the end of a series of children. */
4575 if (--nesting_level
== 0)
4577 /* PART_DIE was probably the last thing allocated on the
4578 comp_unit_obstack, so we could call obstack_free
4579 here. We don't do that because the waste is small,
4580 and will be cleaned up when we're done with this
4581 compilation unit. This way, we're also more robust
4582 against other users of the comp_unit_obstack. */
4585 info_ptr
+= bytes_read
;
4586 last_die
= parent_die
;
4587 parent_die
= parent_die
->die_parent
;
4591 /* Check whether this DIE is interesting enough to save. */
4592 if (!is_type_tag_for_partial (abbrev
->tag
)
4593 && abbrev
->tag
!= DW_TAG_enumerator
4594 && abbrev
->tag
!= DW_TAG_subprogram
4595 && abbrev
->tag
!= DW_TAG_variable
4596 && abbrev
->tag
!= DW_TAG_namespace
)
4598 /* Otherwise we skip to the next sibling, if any. */
4599 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
4603 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
4604 abfd
, info_ptr
, cu
);
4606 /* This two-pass algorithm for processing partial symbols has a
4607 high cost in cache pressure. Thus, handle some simple cases
4608 here which cover the majority of C partial symbols. DIEs
4609 which neither have specification tags in them, nor could have
4610 specification tags elsewhere pointing at them, can simply be
4611 processed and discarded.
4613 This segment is also optional; scan_partial_symbols and
4614 add_partial_symbol will handle these DIEs if we chain
4615 them in normally. When compilers which do not emit large
4616 quantities of duplicate debug information are more common,
4617 this code can probably be removed. */
4619 /* Any complete simple types at the top level (pretty much all
4620 of them, for a language without namespaces), can be processed
4622 if (parent_die
== NULL
4623 && part_die
->has_specification
== 0
4624 && part_die
->is_declaration
== 0
4625 && (part_die
->tag
== DW_TAG_typedef
4626 || part_die
->tag
== DW_TAG_base_type
4627 || part_die
->tag
== DW_TAG_subrange_type
))
4629 if (building_psymtab
&& part_die
->name
!= NULL
)
4630 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
4631 VAR_DOMAIN
, LOC_TYPEDEF
,
4632 &cu
->objfile
->static_psymbols
,
4633 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
4634 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
4638 /* If we're at the second level, and we're an enumerator, and
4639 our parent has no specification (meaning possibly lives in a
4640 namespace elsewhere), then we can add the partial symbol now
4641 instead of queueing it. */
4642 if (part_die
->tag
== DW_TAG_enumerator
4643 && parent_die
!= NULL
4644 && parent_die
->die_parent
== NULL
4645 && parent_die
->tag
== DW_TAG_enumeration_type
4646 && parent_die
->has_specification
== 0)
4648 if (part_die
->name
== NULL
)
4649 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
4650 else if (building_psymtab
)
4651 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
4652 VAR_DOMAIN
, LOC_CONST
,
4653 cu
->language
== language_cplus
4654 ? &cu
->objfile
->global_psymbols
4655 : &cu
->objfile
->static_psymbols
,
4656 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
4658 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
4662 /* We'll save this DIE so link it in. */
4663 part_die
->die_parent
= parent_die
;
4664 part_die
->die_sibling
= NULL
;
4665 part_die
->die_child
= NULL
;
4667 if (last_die
&& last_die
== parent_die
)
4668 last_die
->die_child
= part_die
;
4670 last_die
->die_sibling
= part_die
;
4672 last_die
= part_die
;
4674 if (first_die
== NULL
)
4675 first_die
= part_die
;
4677 /* Maybe add the DIE to the hash table. Not all DIEs that we
4678 find interesting need to be in the hash table, because we
4679 also have the parent/sibling/child chains; only those that we
4680 might refer to by offset later during partial symbol reading.
4682 For now this means things that might have be the target of a
4683 DW_AT_specification, DW_AT_abstract_origin, or
4684 DW_AT_extension. DW_AT_extension will refer only to
4685 namespaces; DW_AT_abstract_origin refers to functions (and
4686 many things under the function DIE, but we do not recurse
4687 into function DIEs during partial symbol reading) and
4688 possibly variables as well; DW_AT_specification refers to
4689 declarations. Declarations ought to have the DW_AT_declaration
4690 flag. It happens that GCC forgets to put it in sometimes, but
4691 only for functions, not for types.
4693 Adding more things than necessary to the hash table is harmless
4694 except for the performance cost. Adding too few will result in
4695 internal errors in find_partial_die. */
4697 if (abbrev
->tag
== DW_TAG_subprogram
4698 || abbrev
->tag
== DW_TAG_variable
4699 || abbrev
->tag
== DW_TAG_namespace
4700 || part_die
->is_declaration
)
4704 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
4705 part_die
->offset
, INSERT
);
4709 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
4710 sizeof (struct partial_die_info
));
4712 /* For some DIEs we want to follow their children (if any). For C
4713 we have no reason to follow the children of structures; for other
4714 languages we have to, both so that we can get at method physnames
4715 to infer fully qualified class names, and for DW_AT_specification. */
4716 if (last_die
->has_children
4717 && (last_die
->tag
== DW_TAG_namespace
4718 || last_die
->tag
== DW_TAG_enumeration_type
4719 || (cu
->language
!= language_c
4720 && (last_die
->tag
== DW_TAG_class_type
4721 || last_die
->tag
== DW_TAG_structure_type
4722 || last_die
->tag
== DW_TAG_union_type
))))
4725 parent_die
= last_die
;
4729 /* Otherwise we skip to the next sibling, if any. */
4730 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
4732 /* Back to the top, do it again. */
4736 /* Read a minimal amount of information into the minimal die structure. */
4739 read_partial_die (struct partial_die_info
*part_die
,
4740 struct abbrev_info
*abbrev
,
4741 unsigned int abbrev_len
, bfd
*abfd
,
4742 char *info_ptr
, struct dwarf2_cu
*cu
)
4744 unsigned int bytes_read
, i
;
4745 struct attribute attr
;
4746 int has_low_pc_attr
= 0;
4747 int has_high_pc_attr
= 0;
4749 memset (part_die
, 0, sizeof (struct partial_die_info
));
4751 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
4753 info_ptr
+= abbrev_len
;
4758 part_die
->tag
= abbrev
->tag
;
4759 part_die
->has_children
= abbrev
->has_children
;
4761 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4763 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
4765 /* Store the data if it is of an attribute we want to keep in a
4766 partial symbol table. */
4771 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
4772 if (part_die
->name
== NULL
)
4773 part_die
->name
= DW_STRING (&attr
);
4775 case DW_AT_MIPS_linkage_name
:
4776 part_die
->name
= DW_STRING (&attr
);
4779 has_low_pc_attr
= 1;
4780 part_die
->lowpc
= DW_ADDR (&attr
);
4783 has_high_pc_attr
= 1;
4784 part_die
->highpc
= DW_ADDR (&attr
);
4786 case DW_AT_location
:
4787 /* Support the .debug_loc offsets */
4788 if (attr_form_is_block (&attr
))
4790 part_die
->locdesc
= DW_BLOCK (&attr
);
4792 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
4794 dwarf2_complex_location_expr_complaint ();
4798 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4799 "partial symbol information");
4802 case DW_AT_language
:
4803 part_die
->language
= DW_UNSND (&attr
);
4805 case DW_AT_external
:
4806 part_die
->is_external
= DW_UNSND (&attr
);
4808 case DW_AT_declaration
:
4809 part_die
->is_declaration
= DW_UNSND (&attr
);
4812 part_die
->has_type
= 1;
4814 case DW_AT_abstract_origin
:
4815 case DW_AT_specification
:
4816 case DW_AT_extension
:
4817 part_die
->has_specification
= 1;
4818 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
4821 /* Ignore absolute siblings, they might point outside of
4822 the current compile unit. */
4823 if (attr
.form
== DW_FORM_ref_addr
)
4824 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
4826 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
4827 + dwarf2_get_ref_die_offset (&attr
, cu
);
4834 /* When using the GNU linker, .gnu.linkonce. sections are used to
4835 eliminate duplicate copies of functions and vtables and such.
4836 The linker will arbitrarily choose one and discard the others.
4837 The AT_*_pc values for such functions refer to local labels in
4838 these sections. If the section from that file was discarded, the
4839 labels are not in the output, so the relocs get a value of 0.
4840 If this is a discarded function, mark the pc bounds as invalid,
4841 so that GDB will ignore it. */
4842 if (has_low_pc_attr
&& has_high_pc_attr
4843 && part_die
->lowpc
< part_die
->highpc
4844 && (part_die
->lowpc
!= 0
4845 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
4846 part_die
->has_pc_info
= 1;
4850 /* Find a cached partial DIE at OFFSET in CU. */
4852 static struct partial_die_info
*
4853 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
4855 struct partial_die_info
*lookup_die
= NULL
;
4856 struct partial_die_info part_die
;
4858 part_die
.offset
= offset
;
4859 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
4861 if (lookup_die
== NULL
)
4862 internal_error (__FILE__
, __LINE__
,
4863 "could not find partial DIE in cache\n");
4868 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
4870 static struct partial_die_info
*
4871 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
,
4872 struct dwarf2_cu
**target_cu
)
4874 struct dwarf2_per_cu_data
*per_cu
;
4876 if (offset
>= cu
->header
.offset
4877 && offset
< cu
->header
.offset
+ cu
->header
.length
)
4880 return find_partial_die_in_comp_unit (offset
, cu
);
4883 internal_error (__FILE__
, __LINE__
,
4884 "unsupported inter-compilation-unit reference");
4887 /* Adjust PART_DIE before generating a symbol for it. This function
4888 may set the is_external flag or change the DIE's name. */
4891 fixup_partial_die (struct partial_die_info
*part_die
,
4892 struct dwarf2_cu
*cu
)
4894 /* If we found a reference attribute and the DIE has no name, try
4895 to find a name in the referred to DIE. */
4897 if (part_die
->name
== NULL
&& part_die
->has_specification
)
4899 struct partial_die_info
*spec_die
;
4900 struct dwarf2_cu
*spec_cu
;
4902 spec_die
= find_partial_die (part_die
->spec_offset
, cu
, &spec_cu
);
4904 fixup_partial_die (spec_die
, spec_cu
);
4908 part_die
->name
= spec_die
->name
;
4910 /* Copy DW_AT_external attribute if it is set. */
4911 if (spec_die
->is_external
)
4912 part_die
->is_external
= spec_die
->is_external
;
4916 /* Set default names for some unnamed DIEs. */
4917 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
4918 || part_die
->tag
== DW_TAG_class_type
))
4919 part_die
->name
= "(anonymous class)";
4921 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
4922 part_die
->name
= "(anonymous namespace)";
4924 if (part_die
->tag
== DW_TAG_structure_type
4925 || part_die
->tag
== DW_TAG_class_type
4926 || part_die
->tag
== DW_TAG_union_type
)
4927 guess_structure_name (part_die
, cu
);
4930 /* Read the die from the .debug_info section buffer. Set DIEP to
4931 point to a newly allocated die with its information, except for its
4932 child, sibling, and parent fields. Set HAS_CHILDREN to tell
4933 whether the die has children or not. */
4936 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
4937 struct dwarf2_cu
*cu
, int *has_children
)
4939 unsigned int abbrev_number
, bytes_read
, i
, offset
;
4940 struct abbrev_info
*abbrev
;
4941 struct die_info
*die
;
4943 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
4944 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4945 info_ptr
+= bytes_read
;
4948 die
= dwarf_alloc_die ();
4950 die
->abbrev
= abbrev_number
;
4957 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4960 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
4962 bfd_get_filename (abfd
));
4964 die
= dwarf_alloc_die ();
4965 die
->offset
= offset
;
4966 die
->tag
= abbrev
->tag
;
4967 die
->abbrev
= abbrev_number
;
4970 die
->num_attrs
= abbrev
->num_attrs
;
4971 die
->attrs
= (struct attribute
*)
4972 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
4974 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4976 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
4977 abfd
, info_ptr
, cu
);
4981 *has_children
= abbrev
->has_children
;
4985 /* Read an attribute value described by an attribute form. */
4988 read_attribute_value (struct attribute
*attr
, unsigned form
,
4989 bfd
*abfd
, char *info_ptr
,
4990 struct dwarf2_cu
*cu
)
4992 struct comp_unit_head
*cu_header
= &cu
->header
;
4993 unsigned int bytes_read
;
4994 struct dwarf_block
*blk
;
5000 case DW_FORM_ref_addr
:
5001 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
5002 info_ptr
+= bytes_read
;
5004 case DW_FORM_block2
:
5005 blk
= dwarf_alloc_block (cu
);
5006 blk
->size
= read_2_bytes (abfd
, info_ptr
);
5008 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5009 info_ptr
+= blk
->size
;
5010 DW_BLOCK (attr
) = blk
;
5012 case DW_FORM_block4
:
5013 blk
= dwarf_alloc_block (cu
);
5014 blk
->size
= read_4_bytes (abfd
, info_ptr
);
5016 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5017 info_ptr
+= blk
->size
;
5018 DW_BLOCK (attr
) = blk
;
5021 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
5025 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
5029 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
5032 case DW_FORM_string
:
5033 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
5034 info_ptr
+= bytes_read
;
5037 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
5039 info_ptr
+= bytes_read
;
5042 blk
= dwarf_alloc_block (cu
);
5043 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5044 info_ptr
+= bytes_read
;
5045 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5046 info_ptr
+= blk
->size
;
5047 DW_BLOCK (attr
) = blk
;
5049 case DW_FORM_block1
:
5050 blk
= dwarf_alloc_block (cu
);
5051 blk
->size
= read_1_byte (abfd
, info_ptr
);
5053 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5054 info_ptr
+= blk
->size
;
5055 DW_BLOCK (attr
) = blk
;
5058 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5062 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5066 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
5067 info_ptr
+= bytes_read
;
5070 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5071 info_ptr
+= bytes_read
;
5074 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5078 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
5082 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
5086 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
5089 case DW_FORM_ref_udata
:
5090 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5091 info_ptr
+= bytes_read
;
5093 case DW_FORM_indirect
:
5094 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5095 info_ptr
+= bytes_read
;
5096 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
5099 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
5100 dwarf_form_name (form
),
5101 bfd_get_filename (abfd
));
5106 /* Read an attribute described by an abbreviated attribute. */
5109 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
5110 bfd
*abfd
, char *info_ptr
, struct dwarf2_cu
*cu
)
5112 attr
->name
= abbrev
->name
;
5113 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
5116 /* read dwarf information from a buffer */
5119 read_1_byte (bfd
*abfd
, char *buf
)
5121 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5125 read_1_signed_byte (bfd
*abfd
, char *buf
)
5127 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
5131 read_2_bytes (bfd
*abfd
, char *buf
)
5133 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
5137 read_2_signed_bytes (bfd
*abfd
, char *buf
)
5139 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
5143 read_4_bytes (bfd
*abfd
, char *buf
)
5145 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5149 read_4_signed_bytes (bfd
*abfd
, char *buf
)
5151 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
5154 static unsigned long
5155 read_8_bytes (bfd
*abfd
, char *buf
)
5157 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5161 read_address (bfd
*abfd
, char *buf
, struct dwarf2_cu
*cu
, int *bytes_read
)
5163 struct comp_unit_head
*cu_header
= &cu
->header
;
5164 CORE_ADDR retval
= 0;
5166 if (cu_header
->signed_addr_p
)
5168 switch (cu_header
->addr_size
)
5171 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
5174 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
5177 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
5180 internal_error (__FILE__
, __LINE__
,
5181 "read_address: bad switch, signed [in module %s]",
5182 bfd_get_filename (abfd
));
5187 switch (cu_header
->addr_size
)
5190 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
5193 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5196 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5199 internal_error (__FILE__
, __LINE__
,
5200 "read_address: bad switch, unsigned [in module %s]",
5201 bfd_get_filename (abfd
));
5205 *bytes_read
= cu_header
->addr_size
;
5209 /* Read the initial length from a section. The (draft) DWARF 3
5210 specification allows the initial length to take up either 4 bytes
5211 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
5212 bytes describe the length and all offsets will be 8 bytes in length
5215 An older, non-standard 64-bit format is also handled by this
5216 function. The older format in question stores the initial length
5217 as an 8-byte quantity without an escape value. Lengths greater
5218 than 2^32 aren't very common which means that the initial 4 bytes
5219 is almost always zero. Since a length value of zero doesn't make
5220 sense for the 32-bit format, this initial zero can be considered to
5221 be an escape value which indicates the presence of the older 64-bit
5222 format. As written, the code can't detect (old format) lengths
5223 greater than 4GB. If it becomes necessary to handle lengths somewhat
5224 larger than 4GB, we could allow other small values (such as the
5225 non-sensical values of 1, 2, and 3) to also be used as escape values
5226 indicating the presence of the old format.
5228 The value returned via bytes_read should be used to increment
5229 the relevant pointer after calling read_initial_length().
5231 As a side effect, this function sets the fields initial_length_size
5232 and offset_size in cu_header to the values appropriate for the
5233 length field. (The format of the initial length field determines
5234 the width of file offsets to be fetched later with fetch_offset().)
5236 [ Note: read_initial_length() and read_offset() are based on the
5237 document entitled "DWARF Debugging Information Format", revision
5238 3, draft 8, dated November 19, 2001. This document was obtained
5241 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
5243 This document is only a draft and is subject to change. (So beware.)
5245 Details regarding the older, non-standard 64-bit format were
5246 determined empirically by examining 64-bit ELF files produced
5247 by the SGI toolchain on an IRIX 6.5 machine.
5249 - Kevin, July 16, 2002
5253 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
5258 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5260 if (retval
== 0xffffffff)
5262 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
5264 if (cu_header
!= NULL
)
5266 cu_header
->initial_length_size
= 12;
5267 cu_header
->offset_size
= 8;
5270 else if (retval
== 0)
5272 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
5274 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5276 if (cu_header
!= NULL
)
5278 cu_header
->initial_length_size
= 8;
5279 cu_header
->offset_size
= 8;
5285 if (cu_header
!= NULL
)
5287 cu_header
->initial_length_size
= 4;
5288 cu_header
->offset_size
= 4;
5295 /* Read an offset from the data stream. The size of the offset is
5296 given by cu_header->offset_size. */
5299 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
5304 switch (cu_header
->offset_size
)
5307 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5311 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5315 internal_error (__FILE__
, __LINE__
,
5316 "read_offset: bad switch [in module %s]",
5317 bfd_get_filename (abfd
));
5324 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
5326 /* If the size of a host char is 8 bits, we can return a pointer
5327 to the buffer, otherwise we have to copy the data to a buffer
5328 allocated on the temporary obstack. */
5329 gdb_assert (HOST_CHAR_BIT
== 8);
5334 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5336 /* If the size of a host char is 8 bits, we can return a pointer
5337 to the string, otherwise we have to copy the string to a buffer
5338 allocated on the temporary obstack. */
5339 gdb_assert (HOST_CHAR_BIT
== 8);
5342 *bytes_read_ptr
= 1;
5345 *bytes_read_ptr
= strlen (buf
) + 1;
5350 read_indirect_string (bfd
*abfd
, char *buf
,
5351 const struct comp_unit_head
*cu_header
,
5352 unsigned int *bytes_read_ptr
)
5354 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
5355 (int *) bytes_read_ptr
);
5357 if (dwarf2_per_objfile
->str_buffer
== NULL
)
5359 error ("DW_FORM_strp used without .debug_str section [in module %s]",
5360 bfd_get_filename (abfd
));
5363 if (str_offset
>= dwarf2_per_objfile
->str_size
)
5365 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
5366 bfd_get_filename (abfd
));
5369 gdb_assert (HOST_CHAR_BIT
== 8);
5370 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
5372 return dwarf2_per_objfile
->str_buffer
+ str_offset
;
5375 static unsigned long
5376 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5378 unsigned long result
;
5379 unsigned int num_read
;
5389 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5392 result
|= ((unsigned long)(byte
& 127) << shift
);
5393 if ((byte
& 128) == 0)
5399 *bytes_read_ptr
= num_read
;
5404 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5407 int i
, shift
, size
, num_read
;
5417 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5420 result
|= ((long)(byte
& 127) << shift
);
5422 if ((byte
& 128) == 0)
5427 if ((shift
< size
) && (byte
& 0x40))
5429 result
|= -(1 << shift
);
5431 *bytes_read_ptr
= num_read
;
5435 /* Return a pointer to just past the end of an LEB128 number in BUF. */
5438 skip_leb128 (bfd
*abfd
, char *buf
)
5444 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5446 if ((byte
& 128) == 0)
5452 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
5458 cu
->language
= language_c
;
5460 case DW_LANG_C_plus_plus
:
5461 cu
->language
= language_cplus
;
5463 case DW_LANG_Fortran77
:
5464 case DW_LANG_Fortran90
:
5465 case DW_LANG_Fortran95
:
5466 cu
->language
= language_fortran
;
5468 case DW_LANG_Mips_Assembler
:
5469 cu
->language
= language_asm
;
5472 cu
->language
= language_java
;
5476 case DW_LANG_Cobol74
:
5477 case DW_LANG_Cobol85
:
5478 case DW_LANG_Pascal83
:
5479 case DW_LANG_Modula2
:
5481 cu
->language
= language_minimal
;
5484 cu
->language_defn
= language_def (cu
->language
);
5487 /* Return the named attribute or NULL if not there. */
5489 static struct attribute
*
5490 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
5493 struct attribute
*spec
= NULL
;
5495 for (i
= 0; i
< die
->num_attrs
; ++i
)
5497 if (die
->attrs
[i
].name
== name
)
5499 return &die
->attrs
[i
];
5501 if (die
->attrs
[i
].name
== DW_AT_specification
5502 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
5503 spec
= &die
->attrs
[i
];
5507 struct die_info
*ref_die
=
5508 follow_die_ref (dwarf2_get_ref_die_offset (spec
, cu
));
5511 return dwarf2_attr (ref_die
, name
, cu
);
5517 /* Return non-zero iff the attribute NAME is defined for the given DIE,
5518 and holds a non-zero value. This function should only be used for
5519 DW_FORM_flag attributes. */
5522 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
5524 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
5526 return (attr
&& DW_UNSND (attr
));
5530 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
5532 /* A DIE is a declaration if it has a DW_AT_declaration attribute
5533 which value is non-zero. However, we have to be careful with
5534 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
5535 (via dwarf2_flag_true_p) follows this attribute. So we may
5536 end up accidently finding a declaration attribute that belongs
5537 to a different DIE referenced by the specification attribute,
5538 even though the given DIE does not have a declaration attribute. */
5539 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
5540 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
5543 /* Return the die giving the specification for DIE, if there is
5546 static struct die_info
*
5547 die_specification (struct die_info
*die
, struct dwarf2_cu
*cu
)
5549 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
, cu
);
5551 if (spec_attr
== NULL
)
5554 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr
, cu
));
5557 /* Free the line_header structure *LH, and any arrays and strings it
5560 free_line_header (struct line_header
*lh
)
5562 if (lh
->standard_opcode_lengths
)
5563 xfree (lh
->standard_opcode_lengths
);
5565 /* Remember that all the lh->file_names[i].name pointers are
5566 pointers into debug_line_buffer, and don't need to be freed. */
5568 xfree (lh
->file_names
);
5570 /* Similarly for the include directory names. */
5571 if (lh
->include_dirs
)
5572 xfree (lh
->include_dirs
);
5578 /* Add an entry to LH's include directory table. */
5580 add_include_dir (struct line_header
*lh
, char *include_dir
)
5582 /* Grow the array if necessary. */
5583 if (lh
->include_dirs_size
== 0)
5585 lh
->include_dirs_size
= 1; /* for testing */
5586 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
5587 * sizeof (*lh
->include_dirs
));
5589 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
5591 lh
->include_dirs_size
*= 2;
5592 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
5593 (lh
->include_dirs_size
5594 * sizeof (*lh
->include_dirs
)));
5597 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
5601 /* Add an entry to LH's file name table. */
5603 add_file_name (struct line_header
*lh
,
5605 unsigned int dir_index
,
5606 unsigned int mod_time
,
5607 unsigned int length
)
5609 struct file_entry
*fe
;
5611 /* Grow the array if necessary. */
5612 if (lh
->file_names_size
== 0)
5614 lh
->file_names_size
= 1; /* for testing */
5615 lh
->file_names
= xmalloc (lh
->file_names_size
5616 * sizeof (*lh
->file_names
));
5618 else if (lh
->num_file_names
>= lh
->file_names_size
)
5620 lh
->file_names_size
*= 2;
5621 lh
->file_names
= xrealloc (lh
->file_names
,
5622 (lh
->file_names_size
5623 * sizeof (*lh
->file_names
)));
5626 fe
= &lh
->file_names
[lh
->num_file_names
++];
5628 fe
->dir_index
= dir_index
;
5629 fe
->mod_time
= mod_time
;
5630 fe
->length
= length
;
5634 /* Read the statement program header starting at OFFSET in
5635 .debug_line, according to the endianness of ABFD. Return a pointer
5636 to a struct line_header, allocated using xmalloc.
5638 NOTE: the strings in the include directory and file name tables of
5639 the returned object point into debug_line_buffer, and must not be
5641 static struct line_header
*
5642 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
5643 struct dwarf2_cu
*cu
)
5645 struct cleanup
*back_to
;
5646 struct line_header
*lh
;
5650 char *cur_dir
, *cur_file
;
5652 if (dwarf2_per_objfile
->line_buffer
== NULL
)
5654 complaint (&symfile_complaints
, "missing .debug_line section");
5658 /* Make sure that at least there's room for the total_length field. That
5659 could be 12 bytes long, but we're just going to fudge that. */
5660 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
5662 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5666 lh
= xmalloc (sizeof (*lh
));
5667 memset (lh
, 0, sizeof (*lh
));
5668 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
5671 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
5673 /* read in the header */
5674 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
5675 line_ptr
+= bytes_read
;
5676 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
5677 + dwarf2_per_objfile
->line_size
))
5679 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5682 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
5683 lh
->version
= read_2_bytes (abfd
, line_ptr
);
5685 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
5686 line_ptr
+= bytes_read
;
5687 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
5689 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
5691 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
5693 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
5695 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
5697 lh
->standard_opcode_lengths
5698 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
5700 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
5701 for (i
= 1; i
< lh
->opcode_base
; ++i
)
5703 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
5707 /* Read directory table */
5708 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5710 line_ptr
+= bytes_read
;
5711 add_include_dir (lh
, cur_dir
);
5713 line_ptr
+= bytes_read
;
5715 /* Read file name table */
5716 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5718 unsigned int dir_index
, mod_time
, length
;
5720 line_ptr
+= bytes_read
;
5721 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5722 line_ptr
+= bytes_read
;
5723 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5724 line_ptr
+= bytes_read
;
5725 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5726 line_ptr
+= bytes_read
;
5728 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5730 line_ptr
+= bytes_read
;
5731 lh
->statement_program_start
= line_ptr
;
5733 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
5734 + dwarf2_per_objfile
->line_size
))
5735 complaint (&symfile_complaints
,
5736 "line number info header doesn't fit in `.debug_line' section");
5738 discard_cleanups (back_to
);
5742 /* This function exists to work around a bug in certain compilers
5743 (particularly GCC 2.95), in which the first line number marker of a
5744 function does not show up until after the prologue, right before
5745 the second line number marker. This function shifts ADDRESS down
5746 to the beginning of the function if necessary, and is called on
5747 addresses passed to record_line. */
5750 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
5752 struct function_range
*fn
;
5754 /* Find the function_range containing address. */
5759 cu
->cached_fn
= cu
->first_fn
;
5763 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5769 while (fn
&& fn
!= cu
->cached_fn
)
5770 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5780 if (address
!= fn
->lowpc
)
5781 complaint (&symfile_complaints
,
5782 "misplaced first line number at 0x%lx for '%s'",
5783 (unsigned long) address
, fn
->name
);
5788 /* Decode the line number information for the compilation unit whose
5789 line number info is at OFFSET in the .debug_line section.
5790 The compilation directory of the file is passed in COMP_DIR. */
5793 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
5794 struct dwarf2_cu
*cu
)
5798 unsigned int bytes_read
;
5799 unsigned char op_code
, extended_op
, adj_opcode
;
5801 struct objfile
*objfile
= cu
->objfile
;
5803 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5805 line_ptr
= lh
->statement_program_start
;
5806 line_end
= lh
->statement_program_end
;
5808 /* Read the statement sequences until there's nothing left. */
5809 while (line_ptr
< line_end
)
5811 /* state machine registers */
5812 CORE_ADDR address
= 0;
5813 unsigned int file
= 1;
5814 unsigned int line
= 1;
5815 unsigned int column
= 0;
5816 int is_stmt
= lh
->default_is_stmt
;
5817 int basic_block
= 0;
5818 int end_sequence
= 0;
5820 /* Start a subfile for the current file of the state machine. */
5821 if (lh
->num_file_names
>= file
)
5823 /* lh->include_dirs and lh->file_names are 0-based, but the
5824 directory and file name numbers in the statement program
5826 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
5829 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5832 dwarf2_start_subfile (fe
->name
, dir
);
5835 /* Decode the table. */
5836 while (!end_sequence
)
5838 op_code
= read_1_byte (abfd
, line_ptr
);
5841 if (op_code
>= lh
->opcode_base
)
5842 { /* Special operand. */
5843 adj_opcode
= op_code
- lh
->opcode_base
;
5844 address
+= (adj_opcode
/ lh
->line_range
)
5845 * lh
->minimum_instruction_length
;
5846 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
5847 /* append row to matrix using current values */
5848 record_line (current_subfile
, line
,
5849 check_cu_functions (address
, cu
));
5852 else switch (op_code
)
5854 case DW_LNS_extended_op
:
5855 line_ptr
+= 1; /* ignore length */
5856 extended_op
= read_1_byte (abfd
, line_ptr
);
5858 switch (extended_op
)
5860 case DW_LNE_end_sequence
:
5862 record_line (current_subfile
, 0, address
);
5864 case DW_LNE_set_address
:
5865 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
5866 line_ptr
+= bytes_read
;
5867 address
+= baseaddr
;
5869 case DW_LNE_define_file
:
5872 unsigned int dir_index
, mod_time
, length
;
5874 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
5875 line_ptr
+= bytes_read
;
5877 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5878 line_ptr
+= bytes_read
;
5880 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5881 line_ptr
+= bytes_read
;
5883 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5884 line_ptr
+= bytes_read
;
5885 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5889 complaint (&symfile_complaints
,
5890 "mangled .debug_line section");
5895 record_line (current_subfile
, line
,
5896 check_cu_functions (address
, cu
));
5899 case DW_LNS_advance_pc
:
5900 address
+= lh
->minimum_instruction_length
5901 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5902 line_ptr
+= bytes_read
;
5904 case DW_LNS_advance_line
:
5905 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
5906 line_ptr
+= bytes_read
;
5908 case DW_LNS_set_file
:
5910 /* lh->include_dirs and lh->file_names are 0-based,
5911 but the directory and file name numbers in the
5912 statement program are 1-based. */
5913 struct file_entry
*fe
;
5915 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5916 line_ptr
+= bytes_read
;
5917 fe
= &lh
->file_names
[file
- 1];
5919 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5922 dwarf2_start_subfile (fe
->name
, dir
);
5925 case DW_LNS_set_column
:
5926 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5927 line_ptr
+= bytes_read
;
5929 case DW_LNS_negate_stmt
:
5930 is_stmt
= (!is_stmt
);
5932 case DW_LNS_set_basic_block
:
5935 /* Add to the address register of the state machine the
5936 address increment value corresponding to special opcode
5937 255. Ie, this value is scaled by the minimum instruction
5938 length since special opcode 255 would have scaled the
5940 case DW_LNS_const_add_pc
:
5941 address
+= (lh
->minimum_instruction_length
5942 * ((255 - lh
->opcode_base
) / lh
->line_range
));
5944 case DW_LNS_fixed_advance_pc
:
5945 address
+= read_2_bytes (abfd
, line_ptr
);
5949 { /* Unknown standard opcode, ignore it. */
5951 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
5953 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5954 line_ptr
+= bytes_read
;
5962 /* Start a subfile for DWARF. FILENAME is the name of the file and
5963 DIRNAME the name of the source directory which contains FILENAME
5964 or NULL if not known.
5965 This routine tries to keep line numbers from identical absolute and
5966 relative file names in a common subfile.
5968 Using the `list' example from the GDB testsuite, which resides in
5969 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
5970 of /srcdir/list0.c yields the following debugging information for list0.c:
5972 DW_AT_name: /srcdir/list0.c
5973 DW_AT_comp_dir: /compdir
5974 files.files[0].name: list0.h
5975 files.files[0].dir: /srcdir
5976 files.files[1].name: list0.c
5977 files.files[1].dir: /srcdir
5979 The line number information for list0.c has to end up in a single
5980 subfile, so that `break /srcdir/list0.c:1' works as expected. */
5983 dwarf2_start_subfile (char *filename
, char *dirname
)
5985 /* If the filename isn't absolute, try to match an existing subfile
5986 with the full pathname. */
5988 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
5990 struct subfile
*subfile
;
5991 char *fullname
= concat (dirname
, "/", filename
, NULL
);
5993 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
5995 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
5997 current_subfile
= subfile
;
6004 start_subfile (filename
, dirname
);
6008 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
6009 struct dwarf2_cu
*cu
)
6011 struct objfile
*objfile
= cu
->objfile
;
6012 struct comp_unit_head
*cu_header
= &cu
->header
;
6014 /* NOTE drow/2003-01-30: There used to be a comment and some special
6015 code here to turn a symbol with DW_AT_external and a
6016 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
6017 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
6018 with some versions of binutils) where shared libraries could have
6019 relocations against symbols in their debug information - the
6020 minimal symbol would have the right address, but the debug info
6021 would not. It's no longer necessary, because we will explicitly
6022 apply relocations when we read in the debug information now. */
6024 /* A DW_AT_location attribute with no contents indicates that a
6025 variable has been optimized away. */
6026 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
6028 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
6032 /* Handle one degenerate form of location expression specially, to
6033 preserve GDB's previous behavior when section offsets are
6034 specified. If this is just a DW_OP_addr then mark this symbol
6037 if (attr_form_is_block (attr
)
6038 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
6039 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
6043 SYMBOL_VALUE_ADDRESS (sym
) =
6044 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
6045 fixup_symbol_section (sym
, objfile
);
6046 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
6047 SYMBOL_SECTION (sym
));
6048 SYMBOL_CLASS (sym
) = LOC_STATIC
;
6052 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
6053 expression evaluator, and use LOC_COMPUTED only when necessary
6054 (i.e. when the value of a register or memory location is
6055 referenced, or a thread-local block, etc.). Then again, it might
6056 not be worthwhile. I'm assuming that it isn't unless performance
6057 or memory numbers show me otherwise. */
6059 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
6060 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
6063 /* Given a pointer to a DWARF information entry, figure out if we need
6064 to make a symbol table entry for it, and if so, create a new entry
6065 and return a pointer to it.
6066 If TYPE is NULL, determine symbol type from the die, otherwise
6067 used the passed type. */
6069 static struct symbol
*
6070 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
6072 struct objfile
*objfile
= cu
->objfile
;
6073 struct symbol
*sym
= NULL
;
6075 struct attribute
*attr
= NULL
;
6076 struct attribute
*attr2
= NULL
;
6079 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6081 if (die
->tag
!= DW_TAG_namespace
)
6082 name
= dwarf2_linkage_name (die
, cu
);
6084 name
= TYPE_NAME (type
);
6088 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
6089 sizeof (struct symbol
));
6090 OBJSTAT (objfile
, n_syms
++);
6091 memset (sym
, 0, sizeof (struct symbol
));
6093 /* Cache this symbol's name and the name's demangled form (if any). */
6094 SYMBOL_LANGUAGE (sym
) = cu
->language
;
6095 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
6097 /* Default assumptions.
6098 Use the passed type or decode it from the die. */
6099 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6100 SYMBOL_CLASS (sym
) = LOC_STATIC
;
6102 SYMBOL_TYPE (sym
) = type
;
6104 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
6105 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
6108 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
6113 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6116 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
6118 SYMBOL_CLASS (sym
) = LOC_LABEL
;
6120 case DW_TAG_subprogram
:
6121 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
6123 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
6124 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6125 if (attr2
&& (DW_UNSND (attr2
) != 0))
6127 add_symbol_to_list (sym
, &global_symbols
);
6131 add_symbol_to_list (sym
, cu
->list_in_scope
);
6134 case DW_TAG_variable
:
6135 /* Compilation with minimal debug info may result in variables
6136 with missing type entries. Change the misleading `void' type
6137 to something sensible. */
6138 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
6139 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
6140 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
6141 "<variable, no debug info>",
6143 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6146 dwarf2_const_value (attr
, sym
, cu
);
6147 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6148 if (attr2
&& (DW_UNSND (attr2
) != 0))
6149 add_symbol_to_list (sym
, &global_symbols
);
6151 add_symbol_to_list (sym
, cu
->list_in_scope
);
6154 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6157 var_decode_location (attr
, sym
, cu
);
6158 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6159 if (attr2
&& (DW_UNSND (attr2
) != 0))
6160 add_symbol_to_list (sym
, &global_symbols
);
6162 add_symbol_to_list (sym
, cu
->list_in_scope
);
6166 /* We do not know the address of this symbol.
6167 If it is an external symbol and we have type information
6168 for it, enter the symbol as a LOC_UNRESOLVED symbol.
6169 The address of the variable will then be determined from
6170 the minimal symbol table whenever the variable is
6172 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6173 if (attr2
&& (DW_UNSND (attr2
) != 0)
6174 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
6176 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
6177 add_symbol_to_list (sym
, &global_symbols
);
6181 case DW_TAG_formal_parameter
:
6182 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6185 var_decode_location (attr
, sym
, cu
);
6186 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
6187 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
6188 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
6190 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6193 dwarf2_const_value (attr
, sym
, cu
);
6195 add_symbol_to_list (sym
, cu
->list_in_scope
);
6197 case DW_TAG_unspecified_parameters
:
6198 /* From varargs functions; gdb doesn't seem to have any
6199 interest in this information, so just ignore it for now.
6202 case DW_TAG_class_type
:
6203 case DW_TAG_structure_type
:
6204 case DW_TAG_union_type
:
6205 case DW_TAG_enumeration_type
:
6206 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6207 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6209 /* Make sure that the symbol includes appropriate enclosing
6210 classes/namespaces in its name. These are calculated in
6211 read_structure_type, and the correct name is saved in
6214 if (cu
->language
== language_cplus
)
6216 struct type
*type
= SYMBOL_TYPE (sym
);
6218 if (TYPE_TAG_NAME (type
) != NULL
)
6220 /* FIXME: carlton/2003-11-10: Should this use
6221 SYMBOL_SET_NAMES instead? (The same problem also
6222 arises further down in this function.) */
6223 /* The type's name is already allocated along with
6224 this objfile, so we don't need to duplicate it
6226 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
6231 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
6232 really ever be static objects: otherwise, if you try
6233 to, say, break of a class's method and you're in a file
6234 which doesn't mention that class, it won't work unless
6235 the check for all static symbols in lookup_symbol_aux
6236 saves you. See the OtherFileClass tests in
6237 gdb.c++/namespace.exp. */
6239 struct pending
**list_to_add
;
6241 list_to_add
= (cu
->list_in_scope
== &file_symbols
6242 && cu
->language
== language_cplus
6243 ? &global_symbols
: cu
->list_in_scope
);
6245 add_symbol_to_list (sym
, list_to_add
);
6247 /* The semantics of C++ state that "struct foo { ... }" also
6248 defines a typedef for "foo". Synthesize a typedef symbol so
6249 that "ptype foo" works as expected. */
6250 if (cu
->language
== language_cplus
)
6252 struct symbol
*typedef_sym
= (struct symbol
*)
6253 obstack_alloc (&objfile
->objfile_obstack
,
6254 sizeof (struct symbol
));
6255 *typedef_sym
= *sym
;
6256 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
6257 /* The symbol's name is already allocated along with
6258 this objfile, so we don't need to duplicate it for
6260 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
6261 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NATURAL_NAME (sym
);
6262 add_symbol_to_list (typedef_sym
, list_to_add
);
6266 case DW_TAG_typedef
:
6267 if (processing_has_namespace_info
6268 && processing_current_prefix
[0] != '\0')
6270 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->objfile_obstack
,
6271 processing_current_prefix
,
6275 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6276 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6277 add_symbol_to_list (sym
, cu
->list_in_scope
);
6279 case DW_TAG_base_type
:
6280 case DW_TAG_subrange_type
:
6281 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6282 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6283 add_symbol_to_list (sym
, cu
->list_in_scope
);
6285 case DW_TAG_enumerator
:
6286 if (processing_has_namespace_info
6287 && processing_current_prefix
[0] != '\0')
6289 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->objfile_obstack
,
6290 processing_current_prefix
,
6294 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6297 dwarf2_const_value (attr
, sym
, cu
);
6300 /* NOTE: carlton/2003-11-10: See comment above in the
6301 DW_TAG_class_type, etc. block. */
6303 struct pending
**list_to_add
;
6305 list_to_add
= (cu
->list_in_scope
== &file_symbols
6306 && cu
->language
== language_cplus
6307 ? &global_symbols
: cu
->list_in_scope
);
6309 add_symbol_to_list (sym
, list_to_add
);
6312 case DW_TAG_namespace
:
6313 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6314 add_symbol_to_list (sym
, &global_symbols
);
6317 /* Not a tag we recognize. Hopefully we aren't processing
6318 trash data, but since we must specifically ignore things
6319 we don't recognize, there is nothing else we should do at
6321 complaint (&symfile_complaints
, "unsupported tag: '%s'",
6322 dwarf_tag_name (die
->tag
));
6329 /* Copy constant value from an attribute to a symbol. */
6332 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
6333 struct dwarf2_cu
*cu
)
6335 struct objfile
*objfile
= cu
->objfile
;
6336 struct comp_unit_head
*cu_header
= &cu
->header
;
6337 struct dwarf_block
*blk
;
6342 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
6343 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
6344 cu_header
->addr_size
,
6345 TYPE_LENGTH (SYMBOL_TYPE
6347 SYMBOL_VALUE_BYTES (sym
) = (char *)
6348 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
6349 /* NOTE: cagney/2003-05-09: In-lined store_address call with
6350 it's body - store_unsigned_integer. */
6351 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
6353 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6355 case DW_FORM_block1
:
6356 case DW_FORM_block2
:
6357 case DW_FORM_block4
:
6359 blk
= DW_BLOCK (attr
);
6360 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
6361 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
6363 TYPE_LENGTH (SYMBOL_TYPE
6365 SYMBOL_VALUE_BYTES (sym
) = (char *)
6366 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
6367 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
6368 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6371 /* The DW_AT_const_value attributes are supposed to carry the
6372 symbol's value "represented as it would be on the target
6373 architecture." By the time we get here, it's already been
6374 converted to host endianness, so we just need to sign- or
6375 zero-extend it as appropriate. */
6377 dwarf2_const_value_data (attr
, sym
, 8);
6380 dwarf2_const_value_data (attr
, sym
, 16);
6383 dwarf2_const_value_data (attr
, sym
, 32);
6386 dwarf2_const_value_data (attr
, sym
, 64);
6390 SYMBOL_VALUE (sym
) = DW_SND (attr
);
6391 SYMBOL_CLASS (sym
) = LOC_CONST
;
6395 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
6396 SYMBOL_CLASS (sym
) = LOC_CONST
;
6400 complaint (&symfile_complaints
,
6401 "unsupported const value attribute form: '%s'",
6402 dwarf_form_name (attr
->form
));
6403 SYMBOL_VALUE (sym
) = 0;
6404 SYMBOL_CLASS (sym
) = LOC_CONST
;
6410 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
6411 or zero-extend it as appropriate for the symbol's type. */
6413 dwarf2_const_value_data (struct attribute
*attr
,
6417 LONGEST l
= DW_UNSND (attr
);
6419 if (bits
< sizeof (l
) * 8)
6421 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
6422 l
&= ((LONGEST
) 1 << bits
) - 1;
6424 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
6427 SYMBOL_VALUE (sym
) = l
;
6428 SYMBOL_CLASS (sym
) = LOC_CONST
;
6432 /* Return the type of the die in question using its DW_AT_type attribute. */
6434 static struct type
*
6435 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6438 struct attribute
*type_attr
;
6439 struct die_info
*type_die
;
6442 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
6445 /* A missing DW_AT_type represents a void type. */
6446 return dwarf2_fundamental_type (cu
->objfile
, FT_VOID
, cu
);
6450 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6451 type_die
= follow_die_ref (ref
);
6454 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
6455 ref
, cu
->objfile
->name
);
6459 type
= tag_type_to_type (type_die
, cu
);
6462 dump_die (type_die
);
6463 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
6469 /* Return the containing type of the die in question using its
6470 DW_AT_containing_type attribute. */
6472 static struct type
*
6473 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6475 struct type
*type
= NULL
;
6476 struct attribute
*type_attr
;
6477 struct die_info
*type_die
= NULL
;
6480 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
6483 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6484 type_die
= follow_die_ref (ref
);
6487 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
6491 type
= tag_type_to_type (type_die
, cu
);
6496 dump_die (type_die
);
6497 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
6504 static struct type
*
6505 type_at_offset (unsigned int offset
, struct dwarf2_cu
*cu
)
6507 struct die_info
*die
;
6510 die
= follow_die_ref (offset
);
6513 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
6516 type
= tag_type_to_type (die
, cu
);
6521 static struct type
*
6522 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6530 read_type_die (die
, cu
);
6534 error ("Dwarf Error: Cannot find type of die [in module %s]",
6542 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6544 char *prefix
= determine_prefix (die
, cu
);
6545 const char *old_prefix
= processing_current_prefix
;
6546 struct cleanup
*back_to
= make_cleanup (xfree
, prefix
);
6547 processing_current_prefix
= prefix
;
6551 case DW_TAG_class_type
:
6552 case DW_TAG_structure_type
:
6553 case DW_TAG_union_type
:
6554 read_structure_type (die
, cu
);
6556 case DW_TAG_enumeration_type
:
6557 read_enumeration_type (die
, cu
);
6559 case DW_TAG_subprogram
:
6560 case DW_TAG_subroutine_type
:
6561 read_subroutine_type (die
, cu
);
6563 case DW_TAG_array_type
:
6564 read_array_type (die
, cu
);
6566 case DW_TAG_pointer_type
:
6567 read_tag_pointer_type (die
, cu
);
6569 case DW_TAG_ptr_to_member_type
:
6570 read_tag_ptr_to_member_type (die
, cu
);
6572 case DW_TAG_reference_type
:
6573 read_tag_reference_type (die
, cu
);
6575 case DW_TAG_const_type
:
6576 read_tag_const_type (die
, cu
);
6578 case DW_TAG_volatile_type
:
6579 read_tag_volatile_type (die
, cu
);
6581 case DW_TAG_string_type
:
6582 read_tag_string_type (die
, cu
);
6584 case DW_TAG_typedef
:
6585 read_typedef (die
, cu
);
6587 case DW_TAG_subrange_type
:
6588 read_subrange_type (die
, cu
);
6590 case DW_TAG_base_type
:
6591 read_base_type (die
, cu
);
6594 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
6595 dwarf_tag_name (die
->tag
));
6599 processing_current_prefix
= old_prefix
;
6600 do_cleanups (back_to
);
6603 /* Return the name of the namespace/class that DIE is defined within,
6604 or "" if we can't tell. The caller should xfree the result. */
6606 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
6607 therein) for an example of how to use this function to deal with
6608 DW_AT_specification. */
6611 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
6613 struct die_info
*parent
;
6615 if (cu
->language
!= language_cplus
)
6618 parent
= die
->parent
;
6622 return xstrdup ("");
6626 switch (parent
->tag
) {
6627 case DW_TAG_namespace
:
6629 /* FIXME: carlton/2004-03-05: Should I follow extension dies
6630 before doing this check? */
6631 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
6633 return xstrdup (TYPE_TAG_NAME (parent
->type
));
6638 char *parent_prefix
= determine_prefix (parent
, cu
);
6639 char *retval
= typename_concat (parent_prefix
,
6640 namespace_name (parent
, &dummy
,
6642 xfree (parent_prefix
);
6647 case DW_TAG_class_type
:
6648 case DW_TAG_structure_type
:
6650 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
6652 return xstrdup (TYPE_TAG_NAME (parent
->type
));
6656 const char *old_prefix
= processing_current_prefix
;
6657 char *new_prefix
= determine_prefix (parent
, cu
);
6660 processing_current_prefix
= new_prefix
;
6661 retval
= determine_class_name (parent
, cu
);
6662 processing_current_prefix
= old_prefix
;
6669 return determine_prefix (parent
, cu
);
6674 /* Return a newly-allocated string formed by concatenating PREFIX,
6675 "::", and SUFFIX, except that if PREFIX is NULL or the empty
6676 string, just return a copy of SUFFIX. */
6679 typename_concat (const char *prefix
, const char *suffix
)
6681 if (prefix
== NULL
|| prefix
[0] == '\0')
6682 return xstrdup (suffix
);
6685 char *retval
= xmalloc (strlen (prefix
) + 2 + strlen (suffix
) + 1);
6687 strcpy (retval
, prefix
);
6688 strcat (retval
, "::");
6689 strcat (retval
, suffix
);
6695 static struct type
*
6696 dwarf_base_type (int encoding
, int size
, struct dwarf2_cu
*cu
)
6698 struct objfile
*objfile
= cu
->objfile
;
6700 /* FIXME - this should not produce a new (struct type *)
6701 every time. It should cache base types. */
6705 case DW_ATE_address
:
6706 type
= dwarf2_fundamental_type (objfile
, FT_VOID
, cu
);
6708 case DW_ATE_boolean
:
6709 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
, cu
);
6711 case DW_ATE_complex_float
:
6714 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
, cu
);
6718 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
, cu
);
6724 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
6728 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
6735 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6738 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
, cu
);
6742 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6746 case DW_ATE_signed_char
:
6747 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6749 case DW_ATE_unsigned
:
6753 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6756 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
, cu
);
6760 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
, cu
);
6764 case DW_ATE_unsigned_char
:
6765 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6768 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6775 copy_die (struct die_info
*old_die
)
6777 struct die_info
*new_die
;
6780 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6781 memset (new_die
, 0, sizeof (struct die_info
));
6783 new_die
->tag
= old_die
->tag
;
6784 new_die
->has_children
= old_die
->has_children
;
6785 new_die
->abbrev
= old_die
->abbrev
;
6786 new_die
->offset
= old_die
->offset
;
6787 new_die
->type
= NULL
;
6789 num_attrs
= old_die
->num_attrs
;
6790 new_die
->num_attrs
= num_attrs
;
6791 new_die
->attrs
= (struct attribute
*)
6792 xmalloc (num_attrs
* sizeof (struct attribute
));
6794 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
6796 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
6797 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
6798 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
6801 new_die
->next
= NULL
;
6806 /* Return sibling of die, NULL if no sibling. */
6808 static struct die_info
*
6809 sibling_die (struct die_info
*die
)
6811 return die
->sibling
;
6814 /* Get linkage name of a die, return NULL if not found. */
6817 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6819 struct attribute
*attr
;
6821 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6822 if (attr
&& DW_STRING (attr
))
6823 return DW_STRING (attr
);
6824 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6825 if (attr
&& DW_STRING (attr
))
6826 return DW_STRING (attr
);
6830 /* Get name of a die, return NULL if not found. */
6833 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6835 struct attribute
*attr
;
6837 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6838 if (attr
&& DW_STRING (attr
))
6839 return DW_STRING (attr
);
6843 /* Return the die that this die in an extension of, or NULL if there
6846 static struct die_info
*
6847 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
6849 struct attribute
*attr
;
6850 struct die_info
*extension_die
;
6853 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
6857 ref
= dwarf2_get_ref_die_offset (attr
, cu
);
6858 extension_die
= follow_die_ref (ref
);
6861 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
6864 return extension_die
;
6867 /* Convert a DIE tag into its string name. */
6870 dwarf_tag_name (unsigned tag
)
6874 case DW_TAG_padding
:
6875 return "DW_TAG_padding";
6876 case DW_TAG_array_type
:
6877 return "DW_TAG_array_type";
6878 case DW_TAG_class_type
:
6879 return "DW_TAG_class_type";
6880 case DW_TAG_entry_point
:
6881 return "DW_TAG_entry_point";
6882 case DW_TAG_enumeration_type
:
6883 return "DW_TAG_enumeration_type";
6884 case DW_TAG_formal_parameter
:
6885 return "DW_TAG_formal_parameter";
6886 case DW_TAG_imported_declaration
:
6887 return "DW_TAG_imported_declaration";
6889 return "DW_TAG_label";
6890 case DW_TAG_lexical_block
:
6891 return "DW_TAG_lexical_block";
6893 return "DW_TAG_member";
6894 case DW_TAG_pointer_type
:
6895 return "DW_TAG_pointer_type";
6896 case DW_TAG_reference_type
:
6897 return "DW_TAG_reference_type";
6898 case DW_TAG_compile_unit
:
6899 return "DW_TAG_compile_unit";
6900 case DW_TAG_string_type
:
6901 return "DW_TAG_string_type";
6902 case DW_TAG_structure_type
:
6903 return "DW_TAG_structure_type";
6904 case DW_TAG_subroutine_type
:
6905 return "DW_TAG_subroutine_type";
6906 case DW_TAG_typedef
:
6907 return "DW_TAG_typedef";
6908 case DW_TAG_union_type
:
6909 return "DW_TAG_union_type";
6910 case DW_TAG_unspecified_parameters
:
6911 return "DW_TAG_unspecified_parameters";
6912 case DW_TAG_variant
:
6913 return "DW_TAG_variant";
6914 case DW_TAG_common_block
:
6915 return "DW_TAG_common_block";
6916 case DW_TAG_common_inclusion
:
6917 return "DW_TAG_common_inclusion";
6918 case DW_TAG_inheritance
:
6919 return "DW_TAG_inheritance";
6920 case DW_TAG_inlined_subroutine
:
6921 return "DW_TAG_inlined_subroutine";
6923 return "DW_TAG_module";
6924 case DW_TAG_ptr_to_member_type
:
6925 return "DW_TAG_ptr_to_member_type";
6926 case DW_TAG_set_type
:
6927 return "DW_TAG_set_type";
6928 case DW_TAG_subrange_type
:
6929 return "DW_TAG_subrange_type";
6930 case DW_TAG_with_stmt
:
6931 return "DW_TAG_with_stmt";
6932 case DW_TAG_access_declaration
:
6933 return "DW_TAG_access_declaration";
6934 case DW_TAG_base_type
:
6935 return "DW_TAG_base_type";
6936 case DW_TAG_catch_block
:
6937 return "DW_TAG_catch_block";
6938 case DW_TAG_const_type
:
6939 return "DW_TAG_const_type";
6940 case DW_TAG_constant
:
6941 return "DW_TAG_constant";
6942 case DW_TAG_enumerator
:
6943 return "DW_TAG_enumerator";
6944 case DW_TAG_file_type
:
6945 return "DW_TAG_file_type";
6947 return "DW_TAG_friend";
6948 case DW_TAG_namelist
:
6949 return "DW_TAG_namelist";
6950 case DW_TAG_namelist_item
:
6951 return "DW_TAG_namelist_item";
6952 case DW_TAG_packed_type
:
6953 return "DW_TAG_packed_type";
6954 case DW_TAG_subprogram
:
6955 return "DW_TAG_subprogram";
6956 case DW_TAG_template_type_param
:
6957 return "DW_TAG_template_type_param";
6958 case DW_TAG_template_value_param
:
6959 return "DW_TAG_template_value_param";
6960 case DW_TAG_thrown_type
:
6961 return "DW_TAG_thrown_type";
6962 case DW_TAG_try_block
:
6963 return "DW_TAG_try_block";
6964 case DW_TAG_variant_part
:
6965 return "DW_TAG_variant_part";
6966 case DW_TAG_variable
:
6967 return "DW_TAG_variable";
6968 case DW_TAG_volatile_type
:
6969 return "DW_TAG_volatile_type";
6970 case DW_TAG_dwarf_procedure
:
6971 return "DW_TAG_dwarf_procedure";
6972 case DW_TAG_restrict_type
:
6973 return "DW_TAG_restrict_type";
6974 case DW_TAG_interface_type
:
6975 return "DW_TAG_interface_type";
6976 case DW_TAG_namespace
:
6977 return "DW_TAG_namespace";
6978 case DW_TAG_imported_module
:
6979 return "DW_TAG_imported_module";
6980 case DW_TAG_unspecified_type
:
6981 return "DW_TAG_unspecified_type";
6982 case DW_TAG_partial_unit
:
6983 return "DW_TAG_partial_unit";
6984 case DW_TAG_imported_unit
:
6985 return "DW_TAG_imported_unit";
6986 case DW_TAG_MIPS_loop
:
6987 return "DW_TAG_MIPS_loop";
6988 case DW_TAG_format_label
:
6989 return "DW_TAG_format_label";
6990 case DW_TAG_function_template
:
6991 return "DW_TAG_function_template";
6992 case DW_TAG_class_template
:
6993 return "DW_TAG_class_template";
6995 return "DW_TAG_<unknown>";
6999 /* Convert a DWARF attribute code into its string name. */
7002 dwarf_attr_name (unsigned attr
)
7007 return "DW_AT_sibling";
7008 case DW_AT_location
:
7009 return "DW_AT_location";
7011 return "DW_AT_name";
7012 case DW_AT_ordering
:
7013 return "DW_AT_ordering";
7014 case DW_AT_subscr_data
:
7015 return "DW_AT_subscr_data";
7016 case DW_AT_byte_size
:
7017 return "DW_AT_byte_size";
7018 case DW_AT_bit_offset
:
7019 return "DW_AT_bit_offset";
7020 case DW_AT_bit_size
:
7021 return "DW_AT_bit_size";
7022 case DW_AT_element_list
:
7023 return "DW_AT_element_list";
7024 case DW_AT_stmt_list
:
7025 return "DW_AT_stmt_list";
7027 return "DW_AT_low_pc";
7029 return "DW_AT_high_pc";
7030 case DW_AT_language
:
7031 return "DW_AT_language";
7033 return "DW_AT_member";
7035 return "DW_AT_discr";
7036 case DW_AT_discr_value
:
7037 return "DW_AT_discr_value";
7038 case DW_AT_visibility
:
7039 return "DW_AT_visibility";
7041 return "DW_AT_import";
7042 case DW_AT_string_length
:
7043 return "DW_AT_string_length";
7044 case DW_AT_common_reference
:
7045 return "DW_AT_common_reference";
7046 case DW_AT_comp_dir
:
7047 return "DW_AT_comp_dir";
7048 case DW_AT_const_value
:
7049 return "DW_AT_const_value";
7050 case DW_AT_containing_type
:
7051 return "DW_AT_containing_type";
7052 case DW_AT_default_value
:
7053 return "DW_AT_default_value";
7055 return "DW_AT_inline";
7056 case DW_AT_is_optional
:
7057 return "DW_AT_is_optional";
7058 case DW_AT_lower_bound
:
7059 return "DW_AT_lower_bound";
7060 case DW_AT_producer
:
7061 return "DW_AT_producer";
7062 case DW_AT_prototyped
:
7063 return "DW_AT_prototyped";
7064 case DW_AT_return_addr
:
7065 return "DW_AT_return_addr";
7066 case DW_AT_start_scope
:
7067 return "DW_AT_start_scope";
7068 case DW_AT_stride_size
:
7069 return "DW_AT_stride_size";
7070 case DW_AT_upper_bound
:
7071 return "DW_AT_upper_bound";
7072 case DW_AT_abstract_origin
:
7073 return "DW_AT_abstract_origin";
7074 case DW_AT_accessibility
:
7075 return "DW_AT_accessibility";
7076 case DW_AT_address_class
:
7077 return "DW_AT_address_class";
7078 case DW_AT_artificial
:
7079 return "DW_AT_artificial";
7080 case DW_AT_base_types
:
7081 return "DW_AT_base_types";
7082 case DW_AT_calling_convention
:
7083 return "DW_AT_calling_convention";
7085 return "DW_AT_count";
7086 case DW_AT_data_member_location
:
7087 return "DW_AT_data_member_location";
7088 case DW_AT_decl_column
:
7089 return "DW_AT_decl_column";
7090 case DW_AT_decl_file
:
7091 return "DW_AT_decl_file";
7092 case DW_AT_decl_line
:
7093 return "DW_AT_decl_line";
7094 case DW_AT_declaration
:
7095 return "DW_AT_declaration";
7096 case DW_AT_discr_list
:
7097 return "DW_AT_discr_list";
7098 case DW_AT_encoding
:
7099 return "DW_AT_encoding";
7100 case DW_AT_external
:
7101 return "DW_AT_external";
7102 case DW_AT_frame_base
:
7103 return "DW_AT_frame_base";
7105 return "DW_AT_friend";
7106 case DW_AT_identifier_case
:
7107 return "DW_AT_identifier_case";
7108 case DW_AT_macro_info
:
7109 return "DW_AT_macro_info";
7110 case DW_AT_namelist_items
:
7111 return "DW_AT_namelist_items";
7112 case DW_AT_priority
:
7113 return "DW_AT_priority";
7115 return "DW_AT_segment";
7116 case DW_AT_specification
:
7117 return "DW_AT_specification";
7118 case DW_AT_static_link
:
7119 return "DW_AT_static_link";
7121 return "DW_AT_type";
7122 case DW_AT_use_location
:
7123 return "DW_AT_use_location";
7124 case DW_AT_variable_parameter
:
7125 return "DW_AT_variable_parameter";
7126 case DW_AT_virtuality
:
7127 return "DW_AT_virtuality";
7128 case DW_AT_vtable_elem_location
:
7129 return "DW_AT_vtable_elem_location";
7130 case DW_AT_allocated
:
7131 return "DW_AT_allocated";
7132 case DW_AT_associated
:
7133 return "DW_AT_associated";
7134 case DW_AT_data_location
:
7135 return "DW_AT_data_location";
7137 return "DW_AT_stride";
7138 case DW_AT_entry_pc
:
7139 return "DW_AT_entry_pc";
7140 case DW_AT_use_UTF8
:
7141 return "DW_AT_use_UTF8";
7142 case DW_AT_extension
:
7143 return "DW_AT_extension";
7145 return "DW_AT_ranges";
7146 case DW_AT_trampoline
:
7147 return "DW_AT_trampoline";
7148 case DW_AT_call_column
:
7149 return "DW_AT_call_column";
7150 case DW_AT_call_file
:
7151 return "DW_AT_call_file";
7152 case DW_AT_call_line
:
7153 return "DW_AT_call_line";
7155 case DW_AT_MIPS_fde
:
7156 return "DW_AT_MIPS_fde";
7157 case DW_AT_MIPS_loop_begin
:
7158 return "DW_AT_MIPS_loop_begin";
7159 case DW_AT_MIPS_tail_loop_begin
:
7160 return "DW_AT_MIPS_tail_loop_begin";
7161 case DW_AT_MIPS_epilog_begin
:
7162 return "DW_AT_MIPS_epilog_begin";
7163 case DW_AT_MIPS_loop_unroll_factor
:
7164 return "DW_AT_MIPS_loop_unroll_factor";
7165 case DW_AT_MIPS_software_pipeline_depth
:
7166 return "DW_AT_MIPS_software_pipeline_depth";
7168 case DW_AT_MIPS_linkage_name
:
7169 return "DW_AT_MIPS_linkage_name";
7171 case DW_AT_sf_names
:
7172 return "DW_AT_sf_names";
7173 case DW_AT_src_info
:
7174 return "DW_AT_src_info";
7175 case DW_AT_mac_info
:
7176 return "DW_AT_mac_info";
7177 case DW_AT_src_coords
:
7178 return "DW_AT_src_coords";
7179 case DW_AT_body_begin
:
7180 return "DW_AT_body_begin";
7181 case DW_AT_body_end
:
7182 return "DW_AT_body_end";
7183 case DW_AT_GNU_vector
:
7184 return "DW_AT_GNU_vector";
7186 return "DW_AT_<unknown>";
7190 /* Convert a DWARF value form code into its string name. */
7193 dwarf_form_name (unsigned form
)
7198 return "DW_FORM_addr";
7199 case DW_FORM_block2
:
7200 return "DW_FORM_block2";
7201 case DW_FORM_block4
:
7202 return "DW_FORM_block4";
7204 return "DW_FORM_data2";
7206 return "DW_FORM_data4";
7208 return "DW_FORM_data8";
7209 case DW_FORM_string
:
7210 return "DW_FORM_string";
7212 return "DW_FORM_block";
7213 case DW_FORM_block1
:
7214 return "DW_FORM_block1";
7216 return "DW_FORM_data1";
7218 return "DW_FORM_flag";
7220 return "DW_FORM_sdata";
7222 return "DW_FORM_strp";
7224 return "DW_FORM_udata";
7225 case DW_FORM_ref_addr
:
7226 return "DW_FORM_ref_addr";
7228 return "DW_FORM_ref1";
7230 return "DW_FORM_ref2";
7232 return "DW_FORM_ref4";
7234 return "DW_FORM_ref8";
7235 case DW_FORM_ref_udata
:
7236 return "DW_FORM_ref_udata";
7237 case DW_FORM_indirect
:
7238 return "DW_FORM_indirect";
7240 return "DW_FORM_<unknown>";
7244 /* Convert a DWARF stack opcode into its string name. */
7247 dwarf_stack_op_name (unsigned op
)
7252 return "DW_OP_addr";
7254 return "DW_OP_deref";
7256 return "DW_OP_const1u";
7258 return "DW_OP_const1s";
7260 return "DW_OP_const2u";
7262 return "DW_OP_const2s";
7264 return "DW_OP_const4u";
7266 return "DW_OP_const4s";
7268 return "DW_OP_const8u";
7270 return "DW_OP_const8s";
7272 return "DW_OP_constu";
7274 return "DW_OP_consts";
7278 return "DW_OP_drop";
7280 return "DW_OP_over";
7282 return "DW_OP_pick";
7284 return "DW_OP_swap";
7288 return "DW_OP_xderef";
7296 return "DW_OP_minus";
7308 return "DW_OP_plus";
7309 case DW_OP_plus_uconst
:
7310 return "DW_OP_plus_uconst";
7316 return "DW_OP_shra";
7334 return "DW_OP_skip";
7336 return "DW_OP_lit0";
7338 return "DW_OP_lit1";
7340 return "DW_OP_lit2";
7342 return "DW_OP_lit3";
7344 return "DW_OP_lit4";
7346 return "DW_OP_lit5";
7348 return "DW_OP_lit6";
7350 return "DW_OP_lit7";
7352 return "DW_OP_lit8";
7354 return "DW_OP_lit9";
7356 return "DW_OP_lit10";
7358 return "DW_OP_lit11";
7360 return "DW_OP_lit12";
7362 return "DW_OP_lit13";
7364 return "DW_OP_lit14";
7366 return "DW_OP_lit15";
7368 return "DW_OP_lit16";
7370 return "DW_OP_lit17";
7372 return "DW_OP_lit18";
7374 return "DW_OP_lit19";
7376 return "DW_OP_lit20";
7378 return "DW_OP_lit21";
7380 return "DW_OP_lit22";
7382 return "DW_OP_lit23";
7384 return "DW_OP_lit24";
7386 return "DW_OP_lit25";
7388 return "DW_OP_lit26";
7390 return "DW_OP_lit27";
7392 return "DW_OP_lit28";
7394 return "DW_OP_lit29";
7396 return "DW_OP_lit30";
7398 return "DW_OP_lit31";
7400 return "DW_OP_reg0";
7402 return "DW_OP_reg1";
7404 return "DW_OP_reg2";
7406 return "DW_OP_reg3";
7408 return "DW_OP_reg4";
7410 return "DW_OP_reg5";
7412 return "DW_OP_reg6";
7414 return "DW_OP_reg7";
7416 return "DW_OP_reg8";
7418 return "DW_OP_reg9";
7420 return "DW_OP_reg10";
7422 return "DW_OP_reg11";
7424 return "DW_OP_reg12";
7426 return "DW_OP_reg13";
7428 return "DW_OP_reg14";
7430 return "DW_OP_reg15";
7432 return "DW_OP_reg16";
7434 return "DW_OP_reg17";
7436 return "DW_OP_reg18";
7438 return "DW_OP_reg19";
7440 return "DW_OP_reg20";
7442 return "DW_OP_reg21";
7444 return "DW_OP_reg22";
7446 return "DW_OP_reg23";
7448 return "DW_OP_reg24";
7450 return "DW_OP_reg25";
7452 return "DW_OP_reg26";
7454 return "DW_OP_reg27";
7456 return "DW_OP_reg28";
7458 return "DW_OP_reg29";
7460 return "DW_OP_reg30";
7462 return "DW_OP_reg31";
7464 return "DW_OP_breg0";
7466 return "DW_OP_breg1";
7468 return "DW_OP_breg2";
7470 return "DW_OP_breg3";
7472 return "DW_OP_breg4";
7474 return "DW_OP_breg5";
7476 return "DW_OP_breg6";
7478 return "DW_OP_breg7";
7480 return "DW_OP_breg8";
7482 return "DW_OP_breg9";
7484 return "DW_OP_breg10";
7486 return "DW_OP_breg11";
7488 return "DW_OP_breg12";
7490 return "DW_OP_breg13";
7492 return "DW_OP_breg14";
7494 return "DW_OP_breg15";
7496 return "DW_OP_breg16";
7498 return "DW_OP_breg17";
7500 return "DW_OP_breg18";
7502 return "DW_OP_breg19";
7504 return "DW_OP_breg20";
7506 return "DW_OP_breg21";
7508 return "DW_OP_breg22";
7510 return "DW_OP_breg23";
7512 return "DW_OP_breg24";
7514 return "DW_OP_breg25";
7516 return "DW_OP_breg26";
7518 return "DW_OP_breg27";
7520 return "DW_OP_breg28";
7522 return "DW_OP_breg29";
7524 return "DW_OP_breg30";
7526 return "DW_OP_breg31";
7528 return "DW_OP_regx";
7530 return "DW_OP_fbreg";
7532 return "DW_OP_bregx";
7534 return "DW_OP_piece";
7535 case DW_OP_deref_size
:
7536 return "DW_OP_deref_size";
7537 case DW_OP_xderef_size
:
7538 return "DW_OP_xderef_size";
7541 /* DWARF 3 extensions. */
7542 case DW_OP_push_object_address
:
7543 return "DW_OP_push_object_address";
7545 return "DW_OP_call2";
7547 return "DW_OP_call4";
7548 case DW_OP_call_ref
:
7549 return "DW_OP_call_ref";
7550 /* GNU extensions. */
7551 case DW_OP_GNU_push_tls_address
:
7552 return "DW_OP_GNU_push_tls_address";
7554 return "OP_<unknown>";
7559 dwarf_bool_name (unsigned mybool
)
7567 /* Convert a DWARF type code into its string name. */
7570 dwarf_type_encoding_name (unsigned enc
)
7574 case DW_ATE_address
:
7575 return "DW_ATE_address";
7576 case DW_ATE_boolean
:
7577 return "DW_ATE_boolean";
7578 case DW_ATE_complex_float
:
7579 return "DW_ATE_complex_float";
7581 return "DW_ATE_float";
7583 return "DW_ATE_signed";
7584 case DW_ATE_signed_char
:
7585 return "DW_ATE_signed_char";
7586 case DW_ATE_unsigned
:
7587 return "DW_ATE_unsigned";
7588 case DW_ATE_unsigned_char
:
7589 return "DW_ATE_unsigned_char";
7590 case DW_ATE_imaginary_float
:
7591 return "DW_ATE_imaginary_float";
7593 return "DW_ATE_<unknown>";
7597 /* Convert a DWARF call frame info operation to its string name. */
7601 dwarf_cfi_name (unsigned cfi_opc
)
7605 case DW_CFA_advance_loc
:
7606 return "DW_CFA_advance_loc";
7608 return "DW_CFA_offset";
7609 case DW_CFA_restore
:
7610 return "DW_CFA_restore";
7612 return "DW_CFA_nop";
7613 case DW_CFA_set_loc
:
7614 return "DW_CFA_set_loc";
7615 case DW_CFA_advance_loc1
:
7616 return "DW_CFA_advance_loc1";
7617 case DW_CFA_advance_loc2
:
7618 return "DW_CFA_advance_loc2";
7619 case DW_CFA_advance_loc4
:
7620 return "DW_CFA_advance_loc4";
7621 case DW_CFA_offset_extended
:
7622 return "DW_CFA_offset_extended";
7623 case DW_CFA_restore_extended
:
7624 return "DW_CFA_restore_extended";
7625 case DW_CFA_undefined
:
7626 return "DW_CFA_undefined";
7627 case DW_CFA_same_value
:
7628 return "DW_CFA_same_value";
7629 case DW_CFA_register
:
7630 return "DW_CFA_register";
7631 case DW_CFA_remember_state
:
7632 return "DW_CFA_remember_state";
7633 case DW_CFA_restore_state
:
7634 return "DW_CFA_restore_state";
7635 case DW_CFA_def_cfa
:
7636 return "DW_CFA_def_cfa";
7637 case DW_CFA_def_cfa_register
:
7638 return "DW_CFA_def_cfa_register";
7639 case DW_CFA_def_cfa_offset
:
7640 return "DW_CFA_def_cfa_offset";
7643 case DW_CFA_def_cfa_expression
:
7644 return "DW_CFA_def_cfa_expression";
7645 case DW_CFA_expression
:
7646 return "DW_CFA_expression";
7647 case DW_CFA_offset_extended_sf
:
7648 return "DW_CFA_offset_extended_sf";
7649 case DW_CFA_def_cfa_sf
:
7650 return "DW_CFA_def_cfa_sf";
7651 case DW_CFA_def_cfa_offset_sf
:
7652 return "DW_CFA_def_cfa_offset_sf";
7654 /* SGI/MIPS specific */
7655 case DW_CFA_MIPS_advance_loc8
:
7656 return "DW_CFA_MIPS_advance_loc8";
7658 /* GNU extensions */
7659 case DW_CFA_GNU_window_save
:
7660 return "DW_CFA_GNU_window_save";
7661 case DW_CFA_GNU_args_size
:
7662 return "DW_CFA_GNU_args_size";
7663 case DW_CFA_GNU_negative_offset_extended
:
7664 return "DW_CFA_GNU_negative_offset_extended";
7667 return "DW_CFA_<unknown>";
7673 dump_die (struct die_info
*die
)
7677 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
7678 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
7679 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
7680 dwarf_bool_name (die
->child
!= NULL
));
7682 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
7683 for (i
= 0; i
< die
->num_attrs
; ++i
)
7685 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
7686 dwarf_attr_name (die
->attrs
[i
].name
),
7687 dwarf_form_name (die
->attrs
[i
].form
));
7688 switch (die
->attrs
[i
].form
)
7690 case DW_FORM_ref_addr
:
7692 fprintf_unfiltered (gdb_stderr
, "address: ");
7693 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
7695 case DW_FORM_block2
:
7696 case DW_FORM_block4
:
7698 case DW_FORM_block1
:
7699 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
7710 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
7712 case DW_FORM_string
:
7714 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
7715 DW_STRING (&die
->attrs
[i
])
7716 ? DW_STRING (&die
->attrs
[i
]) : "");
7719 if (DW_UNSND (&die
->attrs
[i
]))
7720 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
7722 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
7724 case DW_FORM_indirect
:
7725 /* the reader will have reduced the indirect form to
7726 the "base form" so this form should not occur */
7727 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
7730 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
7731 die
->attrs
[i
].form
);
7733 fprintf_unfiltered (gdb_stderr
, "\n");
7738 dump_die_list (struct die_info
*die
)
7743 if (die
->child
!= NULL
)
7744 dump_die_list (die
->child
);
7745 if (die
->sibling
!= NULL
)
7746 dump_die_list (die
->sibling
);
7751 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
7754 struct die_info
*old
;
7756 h
= (offset
% REF_HASH_SIZE
);
7757 old
= die_ref_table
[h
];
7758 die
->next_ref
= old
;
7759 die_ref_table
[h
] = die
;
7764 dwarf2_empty_hash_tables (void)
7766 memset (die_ref_table
, 0, sizeof (die_ref_table
));
7770 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
7772 unsigned int result
= 0;
7776 case DW_FORM_ref_addr
:
7777 result
= DW_ADDR (attr
);
7783 case DW_FORM_ref_udata
:
7784 result
= cu
->header
.offset
+ DW_UNSND (attr
);
7787 complaint (&symfile_complaints
,
7788 "unsupported die ref attribute form: '%s'",
7789 dwarf_form_name (attr
->form
));
7794 /* Return the constant value held by the given attribute. Return -1
7795 if the value held by the attribute is not constant. */
7798 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
7800 if (attr
->form
== DW_FORM_sdata
)
7801 return DW_SND (attr
);
7802 else if (attr
->form
== DW_FORM_udata
7803 || attr
->form
== DW_FORM_data1
7804 || attr
->form
== DW_FORM_data2
7805 || attr
->form
== DW_FORM_data4
7806 || attr
->form
== DW_FORM_data8
)
7807 return DW_UNSND (attr
);
7810 complaint (&symfile_complaints
, "Attribute value is not a constant (%s)",
7811 dwarf_form_name (attr
->form
));
7812 return default_value
;
7816 static struct die_info
*
7817 follow_die_ref (unsigned int offset
)
7819 struct die_info
*die
;
7822 h
= (offset
% REF_HASH_SIZE
);
7823 die
= die_ref_table
[h
];
7826 if (die
->offset
== offset
)
7830 die
= die
->next_ref
;
7835 static struct type
*
7836 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid,
7837 struct dwarf2_cu
*cu
)
7839 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
7841 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
7842 typeid, objfile
->name
);
7845 /* Look for this particular type in the fundamental type vector. If
7846 one is not found, create and install one appropriate for the
7847 current language and the current target machine. */
7849 if (cu
->ftypes
[typeid] == NULL
)
7851 cu
->ftypes
[typeid] = cu
->language_defn
->la_fund_type (objfile
, typeid);
7854 return (cu
->ftypes
[typeid]);
7857 /* Decode simple location descriptions.
7858 Given a pointer to a dwarf block that defines a location, compute
7859 the location and return the value.
7861 NOTE drow/2003-11-18: This function is called in two situations
7862 now: for the address of static or global variables (partial symbols
7863 only) and for offsets into structures which are expected to be
7864 (more or less) constant. The partial symbol case should go away,
7865 and only the constant case should remain. That will let this
7866 function complain more accurately. A few special modes are allowed
7867 without complaint for global variables (for instance, global
7868 register values and thread-local values).
7870 A location description containing no operations indicates that the
7871 object is optimized out. The return value is 0 for that case.
7872 FIXME drow/2003-11-16: No callers check for this case any more; soon all
7873 callers will only want a very basic result and this can become a
7876 When the result is a register number, the global isreg flag is set,
7877 otherwise it is cleared.
7879 Note that stack[0] is unused except as a default error return.
7880 Note that stack overflow is not yet handled. */
7883 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
7885 struct objfile
*objfile
= cu
->objfile
;
7886 struct comp_unit_head
*cu_header
= &cu
->header
;
7888 int size
= blk
->size
;
7889 char *data
= blk
->data
;
7890 CORE_ADDR stack
[64];
7892 unsigned int bytes_read
, unsnd
;
7937 stack
[++stacki
] = op
- DW_OP_lit0
;
7973 stack
[++stacki
] = op
- DW_OP_reg0
;
7975 dwarf2_complex_location_expr_complaint ();
7980 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
7982 stack
[++stacki
] = unsnd
;
7984 dwarf2_complex_location_expr_complaint ();
7988 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
7994 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
7999 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
8004 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
8009 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
8014 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
8019 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
8024 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
8030 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
8035 stack
[stacki
+ 1] = stack
[stacki
];
8040 stack
[stacki
- 1] += stack
[stacki
];
8044 case DW_OP_plus_uconst
:
8045 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
8050 stack
[stacki
- 1] -= stack
[stacki
];
8055 /* If we're not the last op, then we definitely can't encode
8056 this using GDB's address_class enum. This is valid for partial
8057 global symbols, although the variable's address will be bogus
8060 dwarf2_complex_location_expr_complaint ();
8063 case DW_OP_GNU_push_tls_address
:
8064 /* The top of the stack has the offset from the beginning
8065 of the thread control block at which the variable is located. */
8066 /* Nothing should follow this operator, so the top of stack would
8068 /* This is valid for partial global symbols, but the variable's
8069 address will be bogus in the psymtab. */
8071 dwarf2_complex_location_expr_complaint ();
8075 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
8076 dwarf_stack_op_name (op
));
8077 return (stack
[stacki
]);
8080 return (stack
[stacki
]);
8083 /* memory allocation interface */
8085 static struct dwarf_block
*
8086 dwarf_alloc_block (struct dwarf2_cu
*cu
)
8088 struct dwarf_block
*blk
;
8090 blk
= (struct dwarf_block
*)
8091 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
8095 static struct abbrev_info
*
8096 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
8098 struct abbrev_info
*abbrev
;
8100 abbrev
= (struct abbrev_info
*)
8101 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
8102 memset (abbrev
, 0, sizeof (struct abbrev_info
));
8106 static struct die_info
*
8107 dwarf_alloc_die (void)
8109 struct die_info
*die
;
8111 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
8112 memset (die
, 0, sizeof (struct die_info
));
8117 /* Macro support. */
8120 /* Return the full name of file number I in *LH's file name table.
8121 Use COMP_DIR as the name of the current directory of the
8122 compilation. The result is allocated using xmalloc; the caller is
8123 responsible for freeing it. */
8125 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
8127 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
8129 if (IS_ABSOLUTE_PATH (fe
->name
))
8130 return xstrdup (fe
->name
);
8138 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8144 dir_len
= strlen (dir
);
8145 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
8146 strcpy (full_name
, dir
);
8147 full_name
[dir_len
] = '/';
8148 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
8152 return xstrdup (fe
->name
);
8157 static struct macro_source_file
*
8158 macro_start_file (int file
, int line
,
8159 struct macro_source_file
*current_file
,
8160 const char *comp_dir
,
8161 struct line_header
*lh
, struct objfile
*objfile
)
8163 /* The full name of this source file. */
8164 char *full_name
= file_full_name (file
, lh
, comp_dir
);
8166 /* We don't create a macro table for this compilation unit
8167 at all until we actually get a filename. */
8168 if (! pending_macros
)
8169 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
8170 objfile
->macro_cache
);
8173 /* If we have no current file, then this must be the start_file
8174 directive for the compilation unit's main source file. */
8175 current_file
= macro_set_main (pending_macros
, full_name
);
8177 current_file
= macro_include (current_file
, line
, full_name
);
8181 return current_file
;
8185 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
8186 followed by a null byte. */
8188 copy_string (const char *buf
, int len
)
8190 char *s
= xmalloc (len
+ 1);
8191 memcpy (s
, buf
, len
);
8199 consume_improper_spaces (const char *p
, const char *body
)
8203 complaint (&symfile_complaints
,
8204 "macro definition contains spaces in formal argument list:\n`%s'",
8216 parse_macro_definition (struct macro_source_file
*file
, int line
,
8221 /* The body string takes one of two forms. For object-like macro
8222 definitions, it should be:
8224 <macro name> " " <definition>
8226 For function-like macro definitions, it should be:
8228 <macro name> "() " <definition>
8230 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
8232 Spaces may appear only where explicitly indicated, and in the
8235 The Dwarf 2 spec says that an object-like macro's name is always
8236 followed by a space, but versions of GCC around March 2002 omit
8237 the space when the macro's definition is the empty string.
8239 The Dwarf 2 spec says that there should be no spaces between the
8240 formal arguments in a function-like macro's formal argument list,
8241 but versions of GCC around March 2002 include spaces after the
8245 /* Find the extent of the macro name. The macro name is terminated
8246 by either a space or null character (for an object-like macro) or
8247 an opening paren (for a function-like macro). */
8248 for (p
= body
; *p
; p
++)
8249 if (*p
== ' ' || *p
== '(')
8252 if (*p
== ' ' || *p
== '\0')
8254 /* It's an object-like macro. */
8255 int name_len
= p
- body
;
8256 char *name
= copy_string (body
, name_len
);
8257 const char *replacement
;
8260 replacement
= body
+ name_len
+ 1;
8263 dwarf2_macro_malformed_definition_complaint (body
);
8264 replacement
= body
+ name_len
;
8267 macro_define_object (file
, line
, name
, replacement
);
8273 /* It's a function-like macro. */
8274 char *name
= copy_string (body
, p
- body
);
8277 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
8281 p
= consume_improper_spaces (p
, body
);
8283 /* Parse the formal argument list. */
8284 while (*p
&& *p
!= ')')
8286 /* Find the extent of the current argument name. */
8287 const char *arg_start
= p
;
8289 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
8292 if (! *p
|| p
== arg_start
)
8293 dwarf2_macro_malformed_definition_complaint (body
);
8296 /* Make sure argv has room for the new argument. */
8297 if (argc
>= argv_size
)
8300 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
8303 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
8306 p
= consume_improper_spaces (p
, body
);
8308 /* Consume the comma, if present. */
8313 p
= consume_improper_spaces (p
, body
);
8322 /* Perfectly formed definition, no complaints. */
8323 macro_define_function (file
, line
, name
,
8324 argc
, (const char **) argv
,
8326 else if (*p
== '\0')
8328 /* Complain, but do define it. */
8329 dwarf2_macro_malformed_definition_complaint (body
);
8330 macro_define_function (file
, line
, name
,
8331 argc
, (const char **) argv
,
8335 /* Just complain. */
8336 dwarf2_macro_malformed_definition_complaint (body
);
8339 /* Just complain. */
8340 dwarf2_macro_malformed_definition_complaint (body
);
8346 for (i
= 0; i
< argc
; i
++)
8352 dwarf2_macro_malformed_definition_complaint (body
);
8357 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
8358 char *comp_dir
, bfd
*abfd
,
8359 struct dwarf2_cu
*cu
)
8361 char *mac_ptr
, *mac_end
;
8362 struct macro_source_file
*current_file
= 0;
8364 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
8366 complaint (&symfile_complaints
, "missing .debug_macinfo section");
8370 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
8371 mac_end
= dwarf2_per_objfile
->macinfo_buffer
8372 + dwarf2_per_objfile
->macinfo_size
;
8376 enum dwarf_macinfo_record_type macinfo_type
;
8378 /* Do we at least have room for a macinfo type byte? */
8379 if (mac_ptr
>= mac_end
)
8381 dwarf2_macros_too_long_complaint ();
8385 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
8388 switch (macinfo_type
)
8390 /* A zero macinfo type indicates the end of the macro
8395 case DW_MACINFO_define
:
8396 case DW_MACINFO_undef
:
8402 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8403 mac_ptr
+= bytes_read
;
8404 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
8405 mac_ptr
+= bytes_read
;
8408 complaint (&symfile_complaints
,
8409 "debug info gives macro %s outside of any file: %s",
8411 DW_MACINFO_define
? "definition" : macinfo_type
==
8412 DW_MACINFO_undef
? "undefinition" :
8413 "something-or-other", body
);
8416 if (macinfo_type
== DW_MACINFO_define
)
8417 parse_macro_definition (current_file
, line
, body
);
8418 else if (macinfo_type
== DW_MACINFO_undef
)
8419 macro_undef (current_file
, line
, body
);
8424 case DW_MACINFO_start_file
:
8429 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8430 mac_ptr
+= bytes_read
;
8431 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8432 mac_ptr
+= bytes_read
;
8434 current_file
= macro_start_file (file
, line
,
8435 current_file
, comp_dir
,
8440 case DW_MACINFO_end_file
:
8442 complaint (&symfile_complaints
,
8443 "macro debug info has an unmatched `close_file' directive");
8446 current_file
= current_file
->included_by
;
8449 enum dwarf_macinfo_record_type next_type
;
8451 /* GCC circa March 2002 doesn't produce the zero
8452 type byte marking the end of the compilation
8453 unit. Complain if it's not there, but exit no
8456 /* Do we at least have room for a macinfo type byte? */
8457 if (mac_ptr
>= mac_end
)
8459 dwarf2_macros_too_long_complaint ();
8463 /* We don't increment mac_ptr here, so this is just
8465 next_type
= read_1_byte (abfd
, mac_ptr
);
8467 complaint (&symfile_complaints
,
8468 "no terminating 0-type entry for macros in `.debug_macinfo' section");
8475 case DW_MACINFO_vendor_ext
:
8481 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8482 mac_ptr
+= bytes_read
;
8483 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
8484 mac_ptr
+= bytes_read
;
8486 /* We don't recognize any vendor extensions. */
8493 /* Check if the attribute's form is a DW_FORM_block*
8494 if so return true else false. */
8496 attr_form_is_block (struct attribute
*attr
)
8498 return (attr
== NULL
? 0 :
8499 attr
->form
== DW_FORM_block1
8500 || attr
->form
== DW_FORM_block2
8501 || attr
->form
== DW_FORM_block4
8502 || attr
->form
== DW_FORM_block
);
8506 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
8507 struct dwarf2_cu
*cu
)
8509 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
8511 struct dwarf2_loclist_baton
*baton
;
8513 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
8514 sizeof (struct dwarf2_loclist_baton
));
8515 baton
->objfile
= cu
->objfile
;
8517 /* We don't know how long the location list is, but make sure we
8518 don't run off the edge of the section. */
8519 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
8520 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
8521 baton
->base_address
= cu
->header
.base_address
;
8522 if (cu
->header
.base_known
== 0)
8523 complaint (&symfile_complaints
,
8524 "Location list used without specifying the CU base address.");
8526 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
8527 SYMBOL_LOCATION_BATON (sym
) = baton
;
8531 struct dwarf2_locexpr_baton
*baton
;
8533 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
8534 sizeof (struct dwarf2_locexpr_baton
));
8535 baton
->objfile
= cu
->objfile
;
8537 if (attr_form_is_block (attr
))
8539 /* Note that we're just copying the block's data pointer
8540 here, not the actual data. We're still pointing into the
8541 info_buffer for SYM's objfile; right now we never release
8542 that buffer, but when we do clean up properly this may
8544 baton
->size
= DW_BLOCK (attr
)->size
;
8545 baton
->data
= DW_BLOCK (attr
)->data
;
8549 dwarf2_invalid_attrib_class_complaint ("location description",
8550 SYMBOL_NATURAL_NAME (sym
));
8555 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
8556 SYMBOL_LOCATION_BATON (sym
) = baton
;
8560 /* This cleanup function is passed the address of a dwarf2_cu on the stack
8561 when we're finished with it. We can't free the pointer itself, but
8562 release any associated storage.
8564 Only used during partial symbol parsing. */
8567 free_stack_comp_unit (void *data
)
8569 struct dwarf2_cu
*cu
= data
;
8571 obstack_free (&cu
->comp_unit_obstack
, NULL
);
8572 cu
->partial_dies
= NULL
;
8575 /* Allocation function for the libiberty hash table which uses an
8579 hashtab_obstack_allocate (void *data
, size_t size
, size_t count
)
8581 unsigned int total
= size
* count
;
8582 void *ptr
= obstack_alloc ((struct obstack
*) data
, total
);
8583 memset (ptr
, 0, total
);
8587 /* Trivial deallocation function for the libiberty splay tree and hash
8588 table - don't deallocate anything. Rely on later deletion of the
8592 dummy_obstack_deallocate (void *object
, void *data
)
8597 /* Trivial hash function for partial_die_info: the hash value of a DIE
8598 is its offset in .debug_info for this objfile. */
8601 partial_die_hash (const void *item
)
8603 const struct partial_die_info
*part_die
= item
;
8604 return part_die
->offset
;
8607 /* Trivial comparison function for partial_die_info structures: two DIEs
8608 are equal if they have the same offset. */
8611 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
8613 const struct partial_die_info
*part_die_lhs
= item_lhs
;
8614 const struct partial_die_info
*part_die_rhs
= item_rhs
;
8615 return part_die_lhs
->offset
== part_die_rhs
->offset
;
8618 void _initialize_dwarf2_read (void);
8621 _initialize_dwarf2_read (void)
8623 dwarf2_objfile_data_key
= register_objfile_data ();