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"
52 #include "gdb_string.h"
53 #include "gdb_assert.h"
54 #include <sys/types.h>
56 /* A note on memory usage for this file.
58 At the present time, this code reads the debug info sections into
59 the objfile's objfile_obstack. A definite improvement for startup
60 time, on platforms which do not emit relocations for debug
61 sections, would be to use mmap instead. The object's complete
62 debug information is loaded into memory, partly to simplify
63 absolute DIE references.
65 Whether using obstacks or mmap, the sections should remain loaded
66 until the objfile is released, and pointers into the section data
67 can be used for any other data associated to the objfile (symbol
68 names, type names, location expressions to name a few). */
70 #ifndef DWARF2_REG_TO_REGNUM
71 #define DWARF2_REG_TO_REGNUM(REG) (REG)
75 /* .debug_info header for a compilation unit
76 Because of alignment constraints, this structure has padding and cannot
77 be mapped directly onto the beginning of the .debug_info section. */
78 typedef struct comp_unit_header
80 unsigned int length
; /* length of the .debug_info
82 unsigned short version
; /* version number -- 2 for DWARF
84 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
85 unsigned char addr_size
; /* byte size of an address -- 4 */
88 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
91 /* .debug_pubnames header
92 Because of alignment constraints, this structure has padding and cannot
93 be mapped directly onto the beginning of the .debug_info section. */
94 typedef struct pubnames_header
96 unsigned int length
; /* length of the .debug_pubnames
98 unsigned char version
; /* version number -- 2 for DWARF
100 unsigned int info_offset
; /* offset into .debug_info section */
101 unsigned int info_size
; /* byte size of .debug_info section
105 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
107 /* .debug_pubnames header
108 Because of alignment constraints, this structure has padding and cannot
109 be mapped directly onto the beginning of the .debug_info section. */
110 typedef struct aranges_header
112 unsigned int length
; /* byte len of the .debug_aranges
114 unsigned short version
; /* version number -- 2 for DWARF
116 unsigned int info_offset
; /* offset into .debug_info section */
117 unsigned char addr_size
; /* byte size of an address */
118 unsigned char seg_size
; /* byte size of segment descriptor */
121 #define _ACTUAL_ARANGES_HEADER_SIZE 12
123 /* .debug_line statement program prologue
124 Because of alignment constraints, this structure has padding and cannot
125 be mapped directly onto the beginning of the .debug_info section. */
126 typedef struct statement_prologue
128 unsigned int total_length
; /* byte length of the statement
130 unsigned short version
; /* version number -- 2 for DWARF
132 unsigned int prologue_length
; /* # bytes between prologue &
134 unsigned char minimum_instruction_length
; /* byte size of
136 unsigned char default_is_stmt
; /* initial value of is_stmt
139 unsigned char line_range
;
140 unsigned char opcode_base
; /* number assigned to first special
142 unsigned char *standard_opcode_lengths
;
146 static const struct objfile_data
*dwarf2_objfile_data_key
;
148 struct dwarf2_per_objfile
150 /* Sizes of debugging sections. */
151 unsigned int info_size
;
152 unsigned int abbrev_size
;
153 unsigned int line_size
;
154 unsigned int pubnames_size
;
155 unsigned int aranges_size
;
156 unsigned int loc_size
;
157 unsigned int macinfo_size
;
158 unsigned int str_size
;
159 unsigned int ranges_size
;
160 unsigned int frame_size
;
161 unsigned int eh_frame_size
;
163 /* Loaded data from the sections. */
168 char *macinfo_buffer
;
172 /* A list of all the compilation units. This will be set if and
173 only if we have encountered a compilation unit with inter-CU
175 struct dwarf2_per_cu_data
**all_comp_units
;
177 /* The number of compilation units in ALL_COMP_UNITS. */
180 /* A chain of compilation units that are currently read in, so that
181 they can be freed later. */
182 struct dwarf2_per_cu_data
*read_in_chain
;
185 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
187 static asection
*dwarf_info_section
;
188 static asection
*dwarf_abbrev_section
;
189 static asection
*dwarf_line_section
;
190 static asection
*dwarf_pubnames_section
;
191 static asection
*dwarf_aranges_section
;
192 static asection
*dwarf_loc_section
;
193 static asection
*dwarf_macinfo_section
;
194 static asection
*dwarf_str_section
;
195 static asection
*dwarf_ranges_section
;
196 asection
*dwarf_frame_section
;
197 asection
*dwarf_eh_frame_section
;
199 /* names of the debugging sections */
201 #define INFO_SECTION ".debug_info"
202 #define ABBREV_SECTION ".debug_abbrev"
203 #define LINE_SECTION ".debug_line"
204 #define PUBNAMES_SECTION ".debug_pubnames"
205 #define ARANGES_SECTION ".debug_aranges"
206 #define LOC_SECTION ".debug_loc"
207 #define MACINFO_SECTION ".debug_macinfo"
208 #define STR_SECTION ".debug_str"
209 #define RANGES_SECTION ".debug_ranges"
210 #define FRAME_SECTION ".debug_frame"
211 #define EH_FRAME_SECTION ".eh_frame"
213 /* local data types */
215 /* We hold several abbreviation tables in memory at the same time. */
216 #ifndef ABBREV_HASH_SIZE
217 #define ABBREV_HASH_SIZE 121
220 /* The data in a compilation unit header, after target2host
221 translation, looks like this. */
222 struct comp_unit_head
224 unsigned long length
;
226 unsigned int abbrev_offset
;
227 unsigned char addr_size
;
228 unsigned char signed_addr_p
;
229 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
230 unsigned int initial_length_size
; /* size of the length field; either
233 /* Offset to the first byte of this compilation unit header in the
234 * .debug_info section, for resolving relative reference dies. */
238 /* Pointer to this compilation unit header in the .debug_info
243 /* Pointer to the first die of this compilatio unit. This will
244 * be the first byte following the compilation unit header. */
248 /* Pointer to the next compilation unit header in the program. */
250 struct comp_unit_head
*next
;
252 /* Base address of this compilation unit. */
254 CORE_ADDR base_address
;
256 /* Non-zero if base_address has been set. */
261 /* Internal state when decoding a particular compilation unit. */
264 /* The objfile containing this compilation unit. */
265 struct objfile
*objfile
;
267 /* The header of the compilation unit.
269 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
270 should logically be moved to the dwarf2_cu structure. */
271 struct comp_unit_head header
;
273 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
275 /* The language we are debugging. */
276 enum language language
;
277 const struct language_defn
*language_defn
;
279 const char *producer
;
281 /* The generic symbol table building routines have separate lists for
282 file scope symbols and all all other scopes (local scopes). So
283 we need to select the right one to pass to add_symbol_to_list().
284 We do it by keeping a pointer to the correct list in list_in_scope.
286 FIXME: The original dwarf code just treated the file scope as the
287 first local scope, and all other local scopes as nested local
288 scopes, and worked fine. Check to see if we really need to
289 distinguish these in buildsym.c. */
290 struct pending
**list_in_scope
;
292 /* Maintain an array of referenced fundamental types for the current
293 compilation unit being read. For DWARF version 1, we have to construct
294 the fundamental types on the fly, since no information about the
295 fundamental types is supplied. Each such fundamental type is created by
296 calling a language dependent routine to create the type, and then a
297 pointer to that type is then placed in the array at the index specified
298 by it's FT_<TYPENAME> value. The array has a fixed size set by the
299 FT_NUM_MEMBERS compile time constant, which is the number of predefined
300 fundamental types gdb knows how to construct. */
301 struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
303 /* DWARF abbreviation table associated with this compilation unit. */
304 struct abbrev_info
**dwarf2_abbrevs
;
306 /* Storage for the abbrev table. */
307 struct obstack abbrev_obstack
;
309 /* Hash table holding all the loaded partial DIEs. */
312 /* Storage for things with the same lifetime as this read-in compilation
313 unit, including partial DIEs. */
314 struct obstack comp_unit_obstack
;
316 /* When multiple dwarf2_cu structures are living in memory, this field
317 chains them all together, so that they can be released efficiently.
318 We will probably also want a generation counter so that most-recently-used
319 compilation units are cached... */
320 struct dwarf2_per_cu_data
*read_in_chain
;
322 /* Backchain to our per_cu entry if the tree has been built. */
323 struct dwarf2_per_cu_data
*per_cu
;
325 /* How many compilation units ago was this CU last referenced? */
328 /* Mark used when releasing cached dies. */
329 unsigned int mark
: 1;
331 /* This flag will be set if this compilation unit might include
332 inter-compilation-unit references. */
333 unsigned int has_form_ref_addr
: 1;
335 /* This flag will be set if this compilation unit includes any
336 DW_TAG_namespace DIEs. If we know that there are explicit
337 DIEs for namespaces, we don't need to try to infer them
338 from mangled names. */
339 unsigned int has_namespace_info
: 1;
342 struct dwarf2_per_cu_data
344 /* The start offset and length of this compilation unit. 2**31-1
345 bytes should suffice to store the length of any compilation unit
346 - if it doesn't, GDB will fall over anyway. */
347 unsigned long offset
;
348 unsigned long length
: 31;
350 /* Flag indicating this compilation unit will be read in before
351 any of the current compilation units are processed. */
352 unsigned long queued
: 1;
354 /* Set iff currently read in. */
355 struct dwarf2_cu
*cu
;
358 /* The line number information for a compilation unit (found in the
359 .debug_line section) begins with a "statement program header",
360 which contains the following information. */
363 unsigned int total_length
;
364 unsigned short version
;
365 unsigned int header_length
;
366 unsigned char minimum_instruction_length
;
367 unsigned char default_is_stmt
;
369 unsigned char line_range
;
370 unsigned char opcode_base
;
372 /* standard_opcode_lengths[i] is the number of operands for the
373 standard opcode whose value is i. This means that
374 standard_opcode_lengths[0] is unused, and the last meaningful
375 element is standard_opcode_lengths[opcode_base - 1]. */
376 unsigned char *standard_opcode_lengths
;
378 /* The include_directories table. NOTE! These strings are not
379 allocated with xmalloc; instead, they are pointers into
380 debug_line_buffer. If you try to free them, `free' will get
382 unsigned int num_include_dirs
, include_dirs_size
;
385 /* The file_names table. NOTE! These strings are not allocated
386 with xmalloc; instead, they are pointers into debug_line_buffer.
387 Don't try to free them directly. */
388 unsigned int num_file_names
, file_names_size
;
392 unsigned int dir_index
;
393 unsigned int mod_time
;
395 int included_p
; /* Non-zero if referenced by the Line Number Program. */
398 /* The start and end of the statement program following this
399 header. These point into dwarf2_per_objfile->line_buffer. */
400 char *statement_program_start
, *statement_program_end
;
403 /* When we construct a partial symbol table entry we only
404 need this much information. */
405 struct partial_die_info
407 /* Offset of this DIE. */
410 /* DWARF-2 tag for this DIE. */
411 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
413 /* Language code associated with this DIE. This is only used
414 for the compilation unit DIE. */
415 unsigned int language
: 8;
417 /* Assorted flags describing the data found in this DIE. */
418 unsigned int has_children
: 1;
419 unsigned int is_external
: 1;
420 unsigned int is_declaration
: 1;
421 unsigned int has_type
: 1;
422 unsigned int has_specification
: 1;
423 unsigned int has_stmt_list
: 1;
424 unsigned int has_pc_info
: 1;
426 /* Flag set if the SCOPE field of this structure has been
428 unsigned int scope_set
: 1;
430 /* The name of this DIE. Normally the value of DW_AT_name, but
431 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
436 /* The scope to prepend to our children. This is generally
437 allocated on the comp_unit_obstack, so will disappear
438 when this compilation unit leaves the cache. */
441 /* The location description associated with this DIE, if any. */
442 struct dwarf_block
*locdesc
;
444 /* If HAS_PC_INFO, the PC range associated with this DIE. */
448 /* Pointer into the info_buffer pointing at the target of
449 DW_AT_sibling, if any. */
452 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
453 DW_AT_specification (or DW_AT_abstract_origin or
455 unsigned int spec_offset
;
457 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
458 unsigned int line_offset
;
460 /* Pointers to this DIE's parent, first child, and next sibling,
462 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
465 /* This data structure holds the information of an abbrev. */
468 unsigned int number
; /* number identifying abbrev */
469 enum dwarf_tag tag
; /* dwarf tag */
470 unsigned short has_children
; /* boolean */
471 unsigned short num_attrs
; /* number of attributes */
472 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
473 struct abbrev_info
*next
; /* next in chain */
478 enum dwarf_attribute name
;
479 enum dwarf_form form
;
482 /* This data structure holds a complete die structure. */
485 enum dwarf_tag tag
; /* Tag indicating type of die */
486 unsigned int abbrev
; /* Abbrev number */
487 unsigned int offset
; /* Offset in .debug_info section */
488 unsigned int num_attrs
; /* Number of attributes */
489 struct attribute
*attrs
; /* An array of attributes */
490 struct die_info
*next_ref
; /* Next die in ref hash table */
492 /* The dies in a compilation unit form an n-ary tree. PARENT
493 points to this die's parent; CHILD points to the first child of
494 this node; and all the children of a given node are chained
495 together via their SIBLING fields, terminated by a die whose
497 struct die_info
*child
; /* Its first child, if any. */
498 struct die_info
*sibling
; /* Its next sibling, if any. */
499 struct die_info
*parent
; /* Its parent, if any. */
501 struct type
*type
; /* Cached type information */
504 /* Attributes have a name and a value */
507 enum dwarf_attribute name
;
508 enum dwarf_form form
;
512 struct dwarf_block
*blk
;
520 struct function_range
523 CORE_ADDR lowpc
, highpc
;
525 struct function_range
*next
;
528 /* Get at parts of an attribute structure */
530 #define DW_STRING(attr) ((attr)->u.str)
531 #define DW_UNSND(attr) ((attr)->u.unsnd)
532 #define DW_BLOCK(attr) ((attr)->u.blk)
533 #define DW_SND(attr) ((attr)->u.snd)
534 #define DW_ADDR(attr) ((attr)->u.addr)
536 /* Blocks are a bunch of untyped bytes. */
543 #ifndef ATTR_ALLOC_CHUNK
544 #define ATTR_ALLOC_CHUNK 4
547 /* A hash table of die offsets for following references. */
548 #ifndef REF_HASH_SIZE
549 #define REF_HASH_SIZE 1021
552 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
554 /* Allocate fields for structs, unions and enums in this size. */
555 #ifndef DW_FIELD_ALLOC_CHUNK
556 #define DW_FIELD_ALLOC_CHUNK 4
559 /* A zeroed version of a partial die for initialization purposes. */
560 static struct partial_die_info zeroed_partial_die
;
562 /* FIXME: decode_locdesc sets these variables to describe the location
563 to the caller. These ought to be a structure or something. If
564 none of the flags are set, the object lives at the address returned
565 by decode_locdesc. */
567 static int isreg
; /* Object lives in register.
568 decode_locdesc's return value is
569 the register number. */
571 /* We put a pointer to this structure in the read_symtab_private field
576 /* Offset in .debug_info for this compilation unit. */
578 unsigned long dwarf_info_offset
;
581 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
582 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
584 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
585 but this would require a corresponding change in unpack_field_as_long
587 static int bits_per_byte
= 8;
589 /* The routines that read and process dies for a C struct or C++ class
590 pass lists of data member fields and lists of member function fields
591 in an instance of a field_info structure, as defined below. */
594 /* List of data member and baseclasses fields. */
597 struct nextfield
*next
;
604 /* Number of fields. */
607 /* Number of baseclasses. */
610 /* Set if the accesibility of one of the fields is not public. */
611 int non_public_fields
;
613 /* Member function fields array, entries are allocated in the order they
614 are encountered in the object file. */
617 struct nextfnfield
*next
;
618 struct fn_field fnfield
;
622 /* Member function fieldlist array, contains name of possibly overloaded
623 member function, number of overloaded member functions and a pointer
624 to the head of the member function field chain. */
629 struct nextfnfield
*head
;
633 /* Number of entries in the fnfieldlists array. */
637 /* Loaded secondary compilation units are kept in memory until they
638 have not been referenced for the processing of this many
639 compilation units. Set this to zero to disable caching. Cache
640 sizes of up to at least twenty will improve startup time for
641 typical inter-CU-reference binaries, at an obvious memory cost. */
642 static int dwarf2_max_cache_age
= 5;
644 /* Various complaints about symbol reading that don't abort the process */
647 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
649 complaint (&symfile_complaints
,
650 "statement list doesn't fit in .debug_line section");
654 dwarf2_complex_location_expr_complaint (void)
656 complaint (&symfile_complaints
, "location expression too complex");
660 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
663 complaint (&symfile_complaints
,
664 "const value length mismatch for '%s', got %d, expected %d", arg1
,
669 dwarf2_macros_too_long_complaint (void)
671 complaint (&symfile_complaints
,
672 "macro info runs off end of `.debug_macinfo' section");
676 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
678 complaint (&symfile_complaints
,
679 "macro debug info contains a malformed macro definition:\n`%s'",
684 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
686 complaint (&symfile_complaints
,
687 "invalid attribute class or form for '%s' in '%s'", arg1
, arg2
);
690 /* local function prototypes */
692 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
695 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
698 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
701 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
702 struct partial_die_info
*,
703 struct partial_symtab
*);
705 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
707 static void scan_partial_symbols (struct partial_die_info
*,
708 CORE_ADDR
*, CORE_ADDR
*,
711 static void add_partial_symbol (struct partial_die_info
*,
714 static int pdi_needs_namespace (enum dwarf_tag tag
);
716 static void add_partial_namespace (struct partial_die_info
*pdi
,
717 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
718 struct dwarf2_cu
*cu
);
720 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
721 struct dwarf2_cu
*cu
);
723 static char *locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
726 struct dwarf2_cu
*cu
);
728 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
730 static void psymtab_to_symtab_1 (struct partial_symtab
*);
732 char *dwarf2_read_section (struct objfile
*, asection
*);
734 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
736 static void dwarf2_free_abbrev_table (void *);
738 static struct abbrev_info
*peek_die_abbrev (char *, int *, struct dwarf2_cu
*);
740 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
743 static struct partial_die_info
*load_partial_dies (bfd
*, char *, int,
746 static char *read_partial_die (struct partial_die_info
*,
747 struct abbrev_info
*abbrev
, unsigned int,
748 bfd
*, char *, struct dwarf2_cu
*);
750 static struct partial_die_info
*find_partial_die (unsigned long,
752 struct dwarf2_cu
**);
754 static void fixup_partial_die (struct partial_die_info
*,
757 static char *read_full_die (struct die_info
**, bfd
*, char *,
758 struct dwarf2_cu
*, int *);
760 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
761 bfd
*, char *, struct dwarf2_cu
*);
763 static char *read_attribute_value (struct attribute
*, unsigned,
764 bfd
*, char *, struct dwarf2_cu
*);
766 static unsigned int read_1_byte (bfd
*, char *);
768 static int read_1_signed_byte (bfd
*, char *);
770 static unsigned int read_2_bytes (bfd
*, char *);
772 static unsigned int read_4_bytes (bfd
*, char *);
774 static unsigned long read_8_bytes (bfd
*, char *);
776 static CORE_ADDR
read_address (bfd
*, char *ptr
, struct dwarf2_cu
*,
779 static LONGEST
read_initial_length (bfd
*, char *,
780 struct comp_unit_head
*, int *bytes_read
);
782 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
785 static char *read_n_bytes (bfd
*, char *, unsigned int);
787 static char *read_string (bfd
*, char *, unsigned int *);
789 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
792 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
794 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
796 static char *skip_leb128 (bfd
*, char *);
798 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
800 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
803 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
804 struct dwarf2_cu
*cu
);
806 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
808 static struct die_info
*die_specification (struct die_info
*die
,
811 static void free_line_header (struct line_header
*lh
);
813 static void add_file_name (struct line_header
*, char *, unsigned int,
814 unsigned int, unsigned int);
816 static struct line_header
*(dwarf_decode_line_header
817 (unsigned int offset
,
818 bfd
*abfd
, struct dwarf2_cu
*cu
));
820 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
821 struct dwarf2_cu
*, struct partial_symtab
*);
823 static void dwarf2_start_subfile (char *, char *);
825 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
828 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
831 static void dwarf2_const_value_data (struct attribute
*attr
,
835 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
837 static struct type
*die_containing_type (struct die_info
*,
841 static struct type
*type_at_offset (unsigned int, struct objfile
*);
844 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
846 static void read_type_die (struct die_info
*, struct dwarf2_cu
*);
848 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
850 static char *typename_concat (struct obstack
*, const char *prefix
, const char *suffix
,
853 static void read_typedef (struct die_info
*, struct dwarf2_cu
*);
855 static void read_base_type (struct die_info
*, struct dwarf2_cu
*);
857 static void read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
859 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
861 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
863 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
865 static int dwarf2_get_pc_bounds (struct die_info
*,
866 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
868 static void get_scope_pc_bounds (struct die_info
*,
869 CORE_ADDR
*, CORE_ADDR
*,
872 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
875 static void dwarf2_attach_fields_to_type (struct field_info
*,
876 struct type
*, struct dwarf2_cu
*);
878 static void dwarf2_add_member_fn (struct field_info
*,
879 struct die_info
*, struct type
*,
882 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
883 struct type
*, struct dwarf2_cu
*);
885 static void read_structure_type (struct die_info
*, struct dwarf2_cu
*);
887 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
889 static char *determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
891 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
893 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
895 static const char *namespace_name (struct die_info
*die
,
896 int *is_anonymous
, struct dwarf2_cu
*);
898 static void read_enumeration_type (struct die_info
*, struct dwarf2_cu
*);
900 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
902 static struct type
*dwarf_base_type (int, int, struct dwarf2_cu
*);
904 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
906 static void read_array_type (struct die_info
*, struct dwarf2_cu
*);
908 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
911 static void read_tag_pointer_type (struct die_info
*, struct dwarf2_cu
*);
913 static void read_tag_ptr_to_member_type (struct die_info
*,
916 static void read_tag_reference_type (struct die_info
*, struct dwarf2_cu
*);
918 static void read_tag_const_type (struct die_info
*, struct dwarf2_cu
*);
920 static void read_tag_volatile_type (struct die_info
*, struct dwarf2_cu
*);
922 static void read_tag_string_type (struct die_info
*, struct dwarf2_cu
*);
924 static void read_subroutine_type (struct die_info
*, struct dwarf2_cu
*);
926 static struct die_info
*read_comp_unit (char *, bfd
*, struct dwarf2_cu
*);
928 static struct die_info
*read_die_and_children (char *info_ptr
, bfd
*abfd
,
931 struct die_info
*parent
);
933 static struct die_info
*read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
936 struct die_info
*parent
);
938 static void free_die_list (struct die_info
*);
940 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
942 static void process_die (struct die_info
*, struct dwarf2_cu
*);
944 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
946 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
948 static struct die_info
*dwarf2_extension (struct die_info
*die
,
951 static char *dwarf_tag_name (unsigned int);
953 static char *dwarf_attr_name (unsigned int);
955 static char *dwarf_form_name (unsigned int);
957 static char *dwarf_stack_op_name (unsigned int);
959 static char *dwarf_bool_name (unsigned int);
961 static char *dwarf_type_encoding_name (unsigned int);
964 static char *dwarf_cfi_name (unsigned int);
966 struct die_info
*copy_die (struct die_info
*);
969 static struct die_info
*sibling_die (struct die_info
*);
971 static void dump_die (struct die_info
*);
973 static void dump_die_list (struct die_info
*);
975 static void store_in_ref_table (unsigned int, struct die_info
*);
977 static void dwarf2_empty_hash_tables (void);
979 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
982 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
984 static struct die_info
*follow_die_ref (unsigned int);
986 static struct type
*dwarf2_fundamental_type (struct objfile
*, int,
989 /* memory allocation interface */
991 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
993 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
995 static struct die_info
*dwarf_alloc_die (void);
997 static void initialize_cu_func_list (struct dwarf2_cu
*);
999 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1000 struct dwarf2_cu
*);
1002 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1003 char *, bfd
*, struct dwarf2_cu
*);
1005 static int attr_form_is_block (struct attribute
*);
1008 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
1009 struct dwarf2_cu
*cu
);
1011 static char *skip_one_die (char *info_ptr
, struct abbrev_info
*abbrev
,
1012 struct dwarf2_cu
*cu
);
1014 static void free_stack_comp_unit (void *);
1016 static void *hashtab_obstack_allocate (void *data
, size_t size
, size_t count
);
1018 static void dummy_obstack_deallocate (void *object
, void *data
);
1020 static hashval_t
partial_die_hash (const void *item
);
1022 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1024 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1025 (unsigned long offset
, struct objfile
*objfile
);
1027 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1028 (unsigned long offset
, struct objfile
*objfile
);
1030 static void free_one_comp_unit (void *);
1032 static void free_cached_comp_units (void *);
1034 static void age_cached_comp_units (void);
1036 static void free_one_cached_comp_unit (void *);
1038 static void create_all_comp_units (struct objfile
*);
1040 static void dwarf2_mark (struct dwarf2_cu
*);
1042 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1044 /* Try to locate the sections we need for DWARF 2 debugging
1045 information and return true if we have enough to do something. */
1048 dwarf2_has_info (struct objfile
*objfile
)
1050 struct dwarf2_per_objfile
*data
;
1052 /* Initialize per-objfile state. */
1053 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1054 memset (data
, 0, sizeof (*data
));
1055 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1056 dwarf2_per_objfile
= data
;
1058 dwarf_info_section
= 0;
1059 dwarf_abbrev_section
= 0;
1060 dwarf_line_section
= 0;
1061 dwarf_str_section
= 0;
1062 dwarf_macinfo_section
= 0;
1063 dwarf_frame_section
= 0;
1064 dwarf_eh_frame_section
= 0;
1065 dwarf_ranges_section
= 0;
1066 dwarf_loc_section
= 0;
1068 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1069 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
1072 /* This function is mapped across the sections and remembers the
1073 offset and size of each of the debugging sections we are interested
1077 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
1079 if (strcmp (sectp
->name
, INFO_SECTION
) == 0)
1081 dwarf2_per_objfile
->info_size
= bfd_get_section_size (sectp
);
1082 dwarf_info_section
= sectp
;
1084 else if (strcmp (sectp
->name
, ABBREV_SECTION
) == 0)
1086 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size (sectp
);
1087 dwarf_abbrev_section
= sectp
;
1089 else if (strcmp (sectp
->name
, LINE_SECTION
) == 0)
1091 dwarf2_per_objfile
->line_size
= bfd_get_section_size (sectp
);
1092 dwarf_line_section
= sectp
;
1094 else if (strcmp (sectp
->name
, PUBNAMES_SECTION
) == 0)
1096 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size (sectp
);
1097 dwarf_pubnames_section
= sectp
;
1099 else if (strcmp (sectp
->name
, ARANGES_SECTION
) == 0)
1101 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size (sectp
);
1102 dwarf_aranges_section
= sectp
;
1104 else if (strcmp (sectp
->name
, LOC_SECTION
) == 0)
1106 dwarf2_per_objfile
->loc_size
= bfd_get_section_size (sectp
);
1107 dwarf_loc_section
= sectp
;
1109 else if (strcmp (sectp
->name
, MACINFO_SECTION
) == 0)
1111 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size (sectp
);
1112 dwarf_macinfo_section
= sectp
;
1114 else if (strcmp (sectp
->name
, STR_SECTION
) == 0)
1116 dwarf2_per_objfile
->str_size
= bfd_get_section_size (sectp
);
1117 dwarf_str_section
= sectp
;
1119 else if (strcmp (sectp
->name
, FRAME_SECTION
) == 0)
1121 dwarf2_per_objfile
->frame_size
= bfd_get_section_size (sectp
);
1122 dwarf_frame_section
= sectp
;
1124 else if (strcmp (sectp
->name
, EH_FRAME_SECTION
) == 0)
1126 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1127 if (aflag
& SEC_HAS_CONTENTS
)
1129 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size (sectp
);
1130 dwarf_eh_frame_section
= sectp
;
1133 else if (strcmp (sectp
->name
, RANGES_SECTION
) == 0)
1135 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size (sectp
);
1136 dwarf_ranges_section
= sectp
;
1140 /* Build a partial symbol table. */
1143 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1145 /* We definitely need the .debug_info and .debug_abbrev sections */
1147 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1148 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1150 if (dwarf_line_section
)
1151 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1153 dwarf2_per_objfile
->line_buffer
= NULL
;
1155 if (dwarf_str_section
)
1156 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1158 dwarf2_per_objfile
->str_buffer
= NULL
;
1160 if (dwarf_macinfo_section
)
1161 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1162 dwarf_macinfo_section
);
1164 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1166 if (dwarf_ranges_section
)
1167 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1169 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1171 if (dwarf_loc_section
)
1172 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1174 dwarf2_per_objfile
->loc_buffer
= NULL
;
1177 || (objfile
->global_psymbols
.size
== 0
1178 && objfile
->static_psymbols
.size
== 0))
1180 init_psymbol_list (objfile
, 1024);
1184 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1186 /* Things are significantly easier if we have .debug_aranges and
1187 .debug_pubnames sections */
1189 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1193 /* only test this case for now */
1195 /* In this case we have to work a bit harder */
1196 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1201 /* Build the partial symbol table from the information in the
1202 .debug_pubnames and .debug_aranges sections. */
1205 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1207 bfd
*abfd
= objfile
->obfd
;
1208 char *aranges_buffer
, *pubnames_buffer
;
1209 char *aranges_ptr
, *pubnames_ptr
;
1210 unsigned int entry_length
, version
, info_offset
, info_size
;
1212 pubnames_buffer
= dwarf2_read_section (objfile
,
1213 dwarf_pubnames_section
);
1214 pubnames_ptr
= pubnames_buffer
;
1215 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1217 struct comp_unit_head cu_header
;
1220 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1222 pubnames_ptr
+= bytes_read
;
1223 version
= read_1_byte (abfd
, pubnames_ptr
);
1225 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1227 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1231 aranges_buffer
= dwarf2_read_section (objfile
,
1232 dwarf_aranges_section
);
1237 /* Read in the comp unit header information from the debug_info at
1241 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1242 char *info_ptr
, bfd
*abfd
)
1246 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1248 info_ptr
+= bytes_read
;
1249 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1251 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1253 info_ptr
+= bytes_read
;
1254 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1256 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1257 if (signed_addr
< 0)
1258 internal_error (__FILE__
, __LINE__
,
1259 "read_comp_unit_head: dwarf from non elf file");
1260 cu_header
->signed_addr_p
= signed_addr
;
1265 partial_read_comp_unit_head (struct comp_unit_head
*header
, char *info_ptr
,
1268 char *beg_of_comp_unit
= info_ptr
;
1270 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1272 if (header
->version
!= 2)
1273 error ("Dwarf Error: wrong version in compilation unit header "
1274 "(is %d, should be %d) [in module %s]", header
->version
,
1275 2, bfd_get_filename (abfd
));
1277 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1278 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1279 "(offset 0x%lx + 6) [in module %s]",
1280 (long) header
->abbrev_offset
,
1281 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1282 bfd_get_filename (abfd
));
1284 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1285 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1286 error ("Dwarf Error: bad length (0x%lx) in compilation unit header "
1287 "(offset 0x%lx + 0) [in module %s]",
1288 (long) header
->length
,
1289 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1290 bfd_get_filename (abfd
));
1295 /* Allocate a new partial symtab for file named NAME and mark this new
1296 partial symtab as being an include of PST. */
1299 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1300 struct objfile
*objfile
)
1302 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1304 subpst
->section_offsets
= pst
->section_offsets
;
1305 subpst
->textlow
= 0;
1306 subpst
->texthigh
= 0;
1308 subpst
->dependencies
= (struct partial_symtab
**)
1309 obstack_alloc (&objfile
->objfile_obstack
,
1310 sizeof (struct partial_symtab
*));
1311 subpst
->dependencies
[0] = pst
;
1312 subpst
->number_of_dependencies
= 1;
1314 subpst
->globals_offset
= 0;
1315 subpst
->n_global_syms
= 0;
1316 subpst
->statics_offset
= 0;
1317 subpst
->n_static_syms
= 0;
1318 subpst
->symtab
= NULL
;
1319 subpst
->read_symtab
= pst
->read_symtab
;
1322 /* No private part is necessary for include psymtabs. This property
1323 can be used to differentiate between such include psymtabs and
1324 the regular ones. If it ever happens that a regular psymtab can
1325 legitimally have a NULL private part, then we'll have to add a
1326 dedicated field for that in the dwarf2_pinfo structure. */
1327 subpst
->read_symtab_private
= NULL
;
1330 /* Read the Line Number Program data and extract the list of files
1331 included by the source file represented by PST. Build an include
1332 partial symtab for each of these included files.
1334 This procedure assumes that there *is* a Line Number Program in
1335 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1336 before calling this procedure. */
1339 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1340 struct partial_die_info
*pdi
,
1341 struct partial_symtab
*pst
)
1343 struct objfile
*objfile
= cu
->objfile
;
1344 bfd
*abfd
= objfile
->obfd
;
1345 struct line_header
*lh
;
1347 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1349 return; /* No linetable, so no includes. */
1351 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1353 free_line_header (lh
);
1357 /* Build the partial symbol table by doing a quick pass through the
1358 .debug_info and .debug_abbrev sections. */
1361 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1363 /* Instead of reading this into a big buffer, we should probably use
1364 mmap() on architectures that support it. (FIXME) */
1365 bfd
*abfd
= objfile
->obfd
;
1367 char *beg_of_comp_unit
;
1368 struct partial_die_info comp_unit_die
;
1369 struct partial_symtab
*pst
;
1370 struct cleanup
*back_to
;
1371 CORE_ADDR lowpc
, highpc
, baseaddr
;
1373 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1375 /* Any cached compilation units will be linked by the per-objfile
1376 read_in_chain. Make sure to free them when we're done. */
1377 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1379 /* Since the objects we're extracting from .debug_info vary in
1380 length, only the individual functions to extract them (like
1381 read_comp_unit_head and load_partial_die) can really know whether
1382 the buffer is large enough to hold another complete object.
1384 At the moment, they don't actually check that. If .debug_info
1385 holds just one extra byte after the last compilation unit's dies,
1386 then read_comp_unit_head will happily read off the end of the
1387 buffer. read_partial_die is similarly casual. Those functions
1390 For this loop condition, simply checking whether there's any data
1391 left at all should be sufficient. */
1392 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1393 + dwarf2_per_objfile
->info_size
))
1395 struct cleanup
*back_to_inner
;
1396 struct dwarf2_cu cu
;
1397 struct abbrev_info
*abbrev
;
1398 unsigned int bytes_read
;
1399 struct dwarf2_per_cu_data
*this_cu
;
1401 beg_of_comp_unit
= info_ptr
;
1403 memset (&cu
, 0, sizeof (cu
));
1405 obstack_init (&cu
.comp_unit_obstack
);
1407 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1409 cu
.objfile
= objfile
;
1410 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1412 /* Complete the cu_header */
1413 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1414 cu
.header
.first_die_ptr
= info_ptr
;
1415 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1417 cu
.list_in_scope
= &file_symbols
;
1419 /* Read the abbrevs for this compilation unit into a table */
1420 dwarf2_read_abbrevs (abfd
, &cu
);
1421 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1423 if (cu
.has_form_ref_addr
&& dwarf2_per_objfile
->all_comp_units
== NULL
)
1424 create_all_comp_units (objfile
);
1426 /* Read the compilation unit die */
1427 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1428 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1429 abfd
, info_ptr
, &cu
);
1431 /* Set the language we're debugging */
1432 set_cu_language (comp_unit_die
.language
, &cu
);
1434 /* Allocate a new partial symbol table structure */
1435 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1436 comp_unit_die
.name
? comp_unit_die
.name
: "",
1437 comp_unit_die
.lowpc
,
1438 objfile
->global_psymbols
.next
,
1439 objfile
->static_psymbols
.next
);
1441 if (comp_unit_die
.dirname
)
1442 pst
->dirname
= xstrdup (comp_unit_die
.dirname
);
1444 pst
->read_symtab_private
= (char *)
1445 obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct dwarf2_pinfo
));
1446 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1447 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1449 /* Store the function that reads in the rest of the symbol table */
1450 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1452 if (dwarf2_per_objfile
->all_comp_units
!= NULL
)
1454 struct dwarf2_per_cu_data
*per_cu
;
1456 per_cu
= dwarf2_find_comp_unit (cu
.header
.offset
, objfile
);
1458 /* If this compilation unit was already read in, free the
1459 cached copy in order to read it in again. This is
1460 necessary because we skipped some symbols when we first
1461 read in the compilation unit (see load_partial_dies).
1462 This problem could be avoided, but the benefit is
1464 if (per_cu
->cu
!= NULL
)
1465 free_one_cached_comp_unit (per_cu
->cu
);
1469 /* Note that this is a pointer to our stack frame, being
1470 added to a global data structure. It will be cleaned up
1471 in free_stack_comp_unit when we finish with this
1472 compilation unit. */
1478 /* Check if comp unit has_children.
1479 If so, read the rest of the partial symbols from this comp unit.
1480 If not, there's no more debug_info for this comp unit. */
1481 if (comp_unit_die
.has_children
)
1483 struct partial_die_info
*first_die
;
1485 lowpc
= ((CORE_ADDR
) -1);
1486 highpc
= ((CORE_ADDR
) 0);
1488 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1490 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1492 /* If we didn't find a lowpc, set it to highpc to avoid
1493 complaints from `maint check'. */
1494 if (lowpc
== ((CORE_ADDR
) -1))
1497 /* If the compilation unit didn't have an explicit address range,
1498 then use the information extracted from its child dies. */
1499 if (! comp_unit_die
.has_pc_info
)
1501 comp_unit_die
.lowpc
= lowpc
;
1502 comp_unit_die
.highpc
= highpc
;
1505 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1506 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1508 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1509 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1510 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1511 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1512 sort_pst_symbols (pst
);
1514 /* If there is already a psymtab or symtab for a file of this
1515 name, remove it. (If there is a symtab, more drastic things
1516 also happen.) This happens in VxWorks. */
1517 free_named_symtabs (pst
->filename
);
1519 if (comp_unit_die
.has_stmt_list
)
1521 /* Get the list of files included in the current compilation unit,
1522 and build a psymtab for each of them. */
1523 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1526 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1527 + cu
.header
.initial_length_size
;
1529 do_cleanups (back_to_inner
);
1531 do_cleanups (back_to
);
1534 /* Load the DIEs for a secondary CU into memory. */
1537 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1539 bfd
*abfd
= objfile
->obfd
;
1540 char *info_ptr
, *beg_of_comp_unit
;
1541 struct partial_die_info comp_unit_die
;
1542 struct dwarf2_cu
*cu
;
1543 struct abbrev_info
*abbrev
;
1544 unsigned int bytes_read
;
1545 struct cleanup
*back_to
;
1547 info_ptr
= dwarf2_per_objfile
->info_buffer
+ this_cu
->offset
;
1548 beg_of_comp_unit
= info_ptr
;
1550 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1551 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1553 obstack_init (&cu
->comp_unit_obstack
);
1555 cu
->objfile
= objfile
;
1556 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1558 /* Complete the cu_header. */
1559 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1560 cu
->header
.first_die_ptr
= info_ptr
;
1561 cu
->header
.cu_head_ptr
= beg_of_comp_unit
;
1563 /* Read the abbrevs for this compilation unit into a table. */
1564 dwarf2_read_abbrevs (abfd
, cu
);
1565 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1567 /* Read the compilation unit die. */
1568 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1569 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1570 abfd
, info_ptr
, cu
);
1572 /* Set the language we're debugging. */
1573 set_cu_language (comp_unit_die
.language
, cu
);
1575 /* Link this compilation unit into the compilation unit tree. */
1577 cu
->per_cu
= this_cu
;
1579 /* Check if comp unit has_children.
1580 If so, read the rest of the partial symbols from this comp unit.
1581 If not, there's no more debug_info for this comp unit. */
1582 if (comp_unit_die
.has_children
)
1583 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1585 do_cleanups (back_to
);
1588 /* Create a list of all compilation units in OBJFILE. We do this only
1589 if an inter-comp-unit reference is found; presumably if there is one,
1590 there will be many, and one will occur early in the .debug_info section.
1591 So there's no point in building this list incrementally. */
1594 create_all_comp_units (struct objfile
*objfile
)
1598 struct dwarf2_per_cu_data
**all_comp_units
;
1599 char *info_ptr
= dwarf2_per_objfile
->info_buffer
;
1603 all_comp_units
= xmalloc (n_allocated
1604 * sizeof (struct dwarf2_per_cu_data
*));
1606 while (info_ptr
< dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1608 struct comp_unit_head cu_header
;
1609 char *beg_of_comp_unit
;
1610 struct dwarf2_per_cu_data
*this_cu
;
1611 unsigned long offset
;
1614 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
1616 /* Read just enough information to find out where the next
1617 compilation unit is. */
1618 cu_header
.length
= read_initial_length (objfile
->obfd
, info_ptr
,
1619 &cu_header
, &bytes_read
);
1621 /* Save the compilation unit for later lookup. */
1622 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1623 sizeof (struct dwarf2_per_cu_data
));
1624 memset (this_cu
, 0, sizeof (*this_cu
));
1625 this_cu
->offset
= offset
;
1626 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
1628 if (n_comp_units
== n_allocated
)
1631 all_comp_units
= xrealloc (all_comp_units
,
1633 * sizeof (struct dwarf2_per_cu_data
*));
1635 all_comp_units
[n_comp_units
++] = this_cu
;
1637 info_ptr
= info_ptr
+ this_cu
->length
;
1640 dwarf2_per_objfile
->all_comp_units
1641 = obstack_alloc (&objfile
->objfile_obstack
,
1642 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1643 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1644 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1645 xfree (all_comp_units
);
1646 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1649 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1650 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1654 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1655 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1657 struct objfile
*objfile
= cu
->objfile
;
1658 bfd
*abfd
= objfile
->obfd
;
1659 struct partial_die_info
*pdi
;
1661 /* Now, march along the PDI's, descending into ones which have
1662 interesting children but skipping the children of the other ones,
1663 until we reach the end of the compilation unit. */
1669 fixup_partial_die (pdi
, cu
);
1671 /* Anonymous namespaces have no name but have interesting
1672 children, so we need to look at them. Ditto for anonymous
1675 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1676 || pdi
->tag
== DW_TAG_enumeration_type
)
1680 case DW_TAG_subprogram
:
1681 if (pdi
->has_pc_info
)
1683 if (pdi
->lowpc
< *lowpc
)
1685 *lowpc
= pdi
->lowpc
;
1687 if (pdi
->highpc
> *highpc
)
1689 *highpc
= pdi
->highpc
;
1691 if (!pdi
->is_declaration
)
1693 add_partial_symbol (pdi
, cu
);
1697 case DW_TAG_variable
:
1698 case DW_TAG_typedef
:
1699 case DW_TAG_union_type
:
1700 if (!pdi
->is_declaration
)
1702 add_partial_symbol (pdi
, cu
);
1705 case DW_TAG_class_type
:
1706 case DW_TAG_structure_type
:
1707 if (!pdi
->is_declaration
)
1709 add_partial_symbol (pdi
, cu
);
1712 case DW_TAG_enumeration_type
:
1713 if (!pdi
->is_declaration
)
1714 add_partial_enumeration (pdi
, cu
);
1716 case DW_TAG_base_type
:
1717 case DW_TAG_subrange_type
:
1718 /* File scope base type definitions are added to the partial
1720 add_partial_symbol (pdi
, cu
);
1722 case DW_TAG_namespace
:
1723 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1730 /* If the die has a sibling, skip to the sibling. */
1732 pdi
= pdi
->die_sibling
;
1736 /* Functions used to compute the fully scoped name of a partial DIE.
1738 Normally, this is simple. For C++, the parent DIE's fully scoped
1739 name is concatenated with "::" and the partial DIE's name. For
1740 Java, the same thing occurs except that "." is used instead of "::".
1741 Enumerators are an exception; they use the scope of their parent
1742 enumeration type, i.e. the name of the enumeration type is not
1743 prepended to the enumerator.
1745 There are two complexities. One is DW_AT_specification; in this
1746 case "parent" means the parent of the target of the specification,
1747 instead of the direct parent of the DIE. The other is compilers
1748 which do not emit DW_TAG_namespace; in this case we try to guess
1749 the fully qualified name of structure types from their members'
1750 linkage names. This must be done using the DIE's children rather
1751 than the children of any DW_AT_specification target. We only need
1752 to do this for structures at the top level, i.e. if the target of
1753 any DW_AT_specification (if any; otherwise the DIE itself) does not
1756 /* Compute the scope prefix associated with PDI's parent, in
1757 compilation unit CU. The result will be allocated on CU's
1758 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1759 field. NULL is returned if no prefix is necessary. */
1761 partial_die_parent_scope (struct partial_die_info
*pdi
,
1762 struct dwarf2_cu
*cu
)
1764 char *grandparent_scope
;
1765 struct partial_die_info
*parent
, *real_pdi
;
1766 struct dwarf2_cu
*spec_cu
;
1768 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1769 then this means the parent of the specification DIE. */
1773 while (real_pdi
->has_specification
)
1774 real_pdi
= find_partial_die (real_pdi
->spec_offset
, spec_cu
, &spec_cu
);
1776 parent
= real_pdi
->die_parent
;
1780 if (parent
->scope_set
)
1781 return parent
->scope
;
1783 fixup_partial_die (parent
, cu
);
1785 grandparent_scope
= partial_die_parent_scope (parent
, spec_cu
);
1787 if (parent
->tag
== DW_TAG_namespace
1788 || parent
->tag
== DW_TAG_structure_type
1789 || parent
->tag
== DW_TAG_class_type
1790 || parent
->tag
== DW_TAG_union_type
)
1792 if (grandparent_scope
== NULL
)
1793 parent
->scope
= parent
->name
;
1795 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
1798 else if (parent
->tag
== DW_TAG_enumeration_type
)
1799 /* Enumerators should not get the name of the enumeration as a prefix. */
1800 parent
->scope
= grandparent_scope
;
1803 /* FIXME drow/2004-04-01: What should we be doing with
1804 function-local names? For partial symbols, we should probably be
1806 complaint (&symfile_complaints
,
1807 "unhandled containing DIE tag %d for DIE at %d",
1808 parent
->tag
, pdi
->offset
);
1809 parent
->scope
= grandparent_scope
;
1812 parent
->scope_set
= 1;
1813 return parent
->scope
;
1816 /* Return the fully scoped name associated with PDI, from compilation unit
1817 CU. The result will be allocated with malloc. */
1819 partial_die_full_name (struct partial_die_info
*pdi
,
1820 struct dwarf2_cu
*cu
)
1824 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1825 if (parent_scope
== NULL
)
1828 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
1832 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1834 struct objfile
*objfile
= cu
->objfile
;
1837 const char *my_prefix
;
1838 const struct partial_symbol
*psym
= NULL
;
1840 int built_actual_name
= 0;
1842 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1846 if (pdi_needs_namespace (pdi
->tag
))
1848 actual_name
= partial_die_full_name (pdi
, cu
);
1850 built_actual_name
= 1;
1853 if (actual_name
== NULL
)
1854 actual_name
= pdi
->name
;
1858 case DW_TAG_subprogram
:
1859 if (pdi
->is_external
)
1861 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1862 mst_text, objfile); */
1863 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1864 VAR_DOMAIN
, LOC_BLOCK
,
1865 &objfile
->global_psymbols
,
1866 0, pdi
->lowpc
+ baseaddr
,
1867 cu
->language
, objfile
);
1871 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1872 mst_file_text, objfile); */
1873 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1874 VAR_DOMAIN
, LOC_BLOCK
,
1875 &objfile
->static_psymbols
,
1876 0, pdi
->lowpc
+ baseaddr
,
1877 cu
->language
, objfile
);
1880 case DW_TAG_variable
:
1881 if (pdi
->is_external
)
1884 Don't enter into the minimal symbol tables as there is
1885 a minimal symbol table entry from the ELF symbols already.
1886 Enter into partial symbol table if it has a location
1887 descriptor or a type.
1888 If the location descriptor is missing, new_symbol will create
1889 a LOC_UNRESOLVED symbol, the address of the variable will then
1890 be determined from the minimal symbol table whenever the variable
1892 The address for the partial symbol table entry is not
1893 used by GDB, but it comes in handy for debugging partial symbol
1897 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1898 if (pdi
->locdesc
|| pdi
->has_type
)
1899 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1900 VAR_DOMAIN
, LOC_STATIC
,
1901 &objfile
->global_psymbols
,
1903 cu
->language
, objfile
);
1907 /* Static Variable. Skip symbols without location descriptors. */
1908 if (pdi
->locdesc
== NULL
)
1910 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1911 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1912 mst_file_data, objfile); */
1913 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1914 VAR_DOMAIN
, LOC_STATIC
,
1915 &objfile
->static_psymbols
,
1917 cu
->language
, objfile
);
1920 case DW_TAG_typedef
:
1921 case DW_TAG_base_type
:
1922 case DW_TAG_subrange_type
:
1923 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1924 VAR_DOMAIN
, LOC_TYPEDEF
,
1925 &objfile
->static_psymbols
,
1926 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1928 case DW_TAG_namespace
:
1929 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1930 VAR_DOMAIN
, LOC_TYPEDEF
,
1931 &objfile
->global_psymbols
,
1932 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1934 case DW_TAG_class_type
:
1935 case DW_TAG_structure_type
:
1936 case DW_TAG_union_type
:
1937 case DW_TAG_enumeration_type
:
1938 /* Skip aggregate types without children, these are external
1940 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1941 static vs. global. */
1942 if (pdi
->has_children
== 0)
1944 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1945 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1946 (cu
->language
== language_cplus
1947 || cu
->language
== language_java
)
1948 ? &objfile
->global_psymbols
1949 : &objfile
->static_psymbols
,
1950 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1952 if (cu
->language
== language_cplus
1953 || cu
->language
== language_java
)
1955 /* For C++ and Java, these implicitly act as typedefs as well. */
1956 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1957 VAR_DOMAIN
, LOC_TYPEDEF
,
1958 &objfile
->global_psymbols
,
1959 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1962 case DW_TAG_enumerator
:
1963 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1964 VAR_DOMAIN
, LOC_CONST
,
1965 (cu
->language
== language_cplus
1966 || cu
->language
== language_java
)
1967 ? &objfile
->global_psymbols
1968 : &objfile
->static_psymbols
,
1969 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1975 /* Check to see if we should scan the name for possible namespace
1976 info. Only do this if this is C++, if we don't have namespace
1977 debugging info in the file, if the psym is of an appropriate type
1978 (otherwise we'll have psym == NULL), and if we actually had a
1979 mangled name to begin with. */
1981 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
1982 cases which do not set PSYM above? */
1984 if (cu
->language
== language_cplus
1985 && cu
->has_namespace_info
== 0
1987 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
1988 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
1991 if (built_actual_name
)
1992 xfree (actual_name
);
1995 /* Determine whether a die of type TAG living in a C++ class or
1996 namespace needs to have the name of the scope prepended to the
1997 name listed in the die. */
2000 pdi_needs_namespace (enum dwarf_tag tag
)
2004 case DW_TAG_namespace
:
2005 case DW_TAG_typedef
:
2006 case DW_TAG_class_type
:
2007 case DW_TAG_structure_type
:
2008 case DW_TAG_union_type
:
2009 case DW_TAG_enumeration_type
:
2010 case DW_TAG_enumerator
:
2017 /* Read a partial die corresponding to a namespace; also, add a symbol
2018 corresponding to that namespace to the symbol table. NAMESPACE is
2019 the name of the enclosing namespace. */
2022 add_partial_namespace (struct partial_die_info
*pdi
,
2023 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2024 struct dwarf2_cu
*cu
)
2026 struct objfile
*objfile
= cu
->objfile
;
2028 /* Add a symbol for the namespace. */
2030 add_partial_symbol (pdi
, cu
);
2032 /* Now scan partial symbols in that namespace. */
2034 if (pdi
->has_children
)
2035 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
2038 /* See if we can figure out if the class lives in a namespace. We do
2039 this by looking for a member function; its demangled name will
2040 contain namespace info, if there is any. */
2043 guess_structure_name (struct partial_die_info
*struct_pdi
,
2044 struct dwarf2_cu
*cu
)
2046 if ((cu
->language
== language_cplus
2047 || cu
->language
== language_java
)
2048 && cu
->has_namespace_info
== 0
2049 && struct_pdi
->has_children
)
2051 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2052 what template types look like, because the demangler
2053 frequently doesn't give the same name as the debug info. We
2054 could fix this by only using the demangled name to get the
2055 prefix (but see comment in read_structure_type). */
2057 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2058 struct partial_die_info
*real_pdi
;
2059 struct dwarf2_cu
*spec_cu
;
2061 /* If this DIE (this DIE's specification, if any) has a parent, then
2062 we should not do this. We'll prepend the parent's fully qualified
2063 name when we create the partial symbol. */
2065 real_pdi
= struct_pdi
;
2067 while (real_pdi
->has_specification
)
2068 real_pdi
= find_partial_die (real_pdi
->spec_offset
, spec_cu
, &spec_cu
);
2070 if (real_pdi
->die_parent
!= NULL
)
2073 while (child_pdi
!= NULL
)
2075 if (child_pdi
->tag
== DW_TAG_subprogram
)
2077 char *actual_class_name
2078 = language_class_name_from_physname (cu
->language_defn
,
2080 if (actual_class_name
!= NULL
)
2083 = obsavestring (actual_class_name
,
2084 strlen (actual_class_name
),
2085 &cu
->comp_unit_obstack
);
2086 xfree (actual_class_name
);
2091 child_pdi
= child_pdi
->die_sibling
;
2096 /* Read a partial die corresponding to an enumeration type. */
2099 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2100 struct dwarf2_cu
*cu
)
2102 struct objfile
*objfile
= cu
->objfile
;
2103 bfd
*abfd
= objfile
->obfd
;
2104 struct partial_die_info
*pdi
;
2106 if (enum_pdi
->name
!= NULL
)
2107 add_partial_symbol (enum_pdi
, cu
);
2109 pdi
= enum_pdi
->die_child
;
2112 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2113 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
2115 add_partial_symbol (pdi
, cu
);
2116 pdi
= pdi
->die_sibling
;
2120 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2121 Return the corresponding abbrev, or NULL if the number is zero (indicating
2122 an empty DIE). In either case *BYTES_READ will be set to the length of
2123 the initial number. */
2125 static struct abbrev_info
*
2126 peek_die_abbrev (char *info_ptr
, int *bytes_read
, struct dwarf2_cu
*cu
)
2128 bfd
*abfd
= cu
->objfile
->obfd
;
2129 unsigned int abbrev_number
;
2130 struct abbrev_info
*abbrev
;
2132 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2134 if (abbrev_number
== 0)
2137 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2140 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
2141 bfd_get_filename (abfd
));
2147 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2148 pointer to the end of a series of DIEs, terminated by an empty
2149 DIE. Any children of the skipped DIEs will also be skipped. */
2152 skip_children (char *info_ptr
, struct dwarf2_cu
*cu
)
2154 struct abbrev_info
*abbrev
;
2155 unsigned int bytes_read
;
2159 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2161 return info_ptr
+ bytes_read
;
2163 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2167 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2168 should point just after the initial uleb128 of a DIE, and the
2169 abbrev corresponding to that skipped uleb128 should be passed in
2170 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2174 skip_one_die (char *info_ptr
, struct abbrev_info
*abbrev
,
2175 struct dwarf2_cu
*cu
)
2177 unsigned int bytes_read
;
2178 struct attribute attr
;
2179 bfd
*abfd
= cu
->objfile
->obfd
;
2180 unsigned int form
, i
;
2182 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2184 /* The only abbrev we care about is DW_AT_sibling. */
2185 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2187 read_attribute (&attr
, &abbrev
->attrs
[i
],
2188 abfd
, info_ptr
, cu
);
2189 if (attr
.form
== DW_FORM_ref_addr
)
2190 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
2192 return dwarf2_per_objfile
->info_buffer
2193 + dwarf2_get_ref_die_offset (&attr
, cu
);
2196 /* If it isn't DW_AT_sibling, skip this attribute. */
2197 form
= abbrev
->attrs
[i
].form
;
2202 case DW_FORM_ref_addr
:
2203 info_ptr
+= cu
->header
.addr_size
;
2222 case DW_FORM_string
:
2223 read_string (abfd
, info_ptr
, &bytes_read
);
2224 info_ptr
+= bytes_read
;
2227 info_ptr
+= cu
->header
.offset_size
;
2230 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2231 info_ptr
+= bytes_read
;
2233 case DW_FORM_block1
:
2234 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2236 case DW_FORM_block2
:
2237 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2239 case DW_FORM_block4
:
2240 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2244 case DW_FORM_ref_udata
:
2245 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2247 case DW_FORM_indirect
:
2248 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2249 info_ptr
+= bytes_read
;
2250 /* We need to continue parsing from here, so just go back to
2252 goto skip_attribute
;
2255 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
2256 dwarf_form_name (form
),
2257 bfd_get_filename (abfd
));
2261 if (abbrev
->has_children
)
2262 return skip_children (info_ptr
, cu
);
2267 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2268 the next DIE after ORIG_PDI. */
2271 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, char *info_ptr
,
2272 bfd
*abfd
, struct dwarf2_cu
*cu
)
2274 /* Do we know the sibling already? */
2276 if (orig_pdi
->sibling
)
2277 return orig_pdi
->sibling
;
2279 /* Are there any children to deal with? */
2281 if (!orig_pdi
->has_children
)
2284 /* Skip the children the long way. */
2286 return skip_children (info_ptr
, cu
);
2289 /* Expand this partial symbol table into a full symbol table. */
2292 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2294 /* FIXME: This is barely more than a stub. */
2299 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
2305 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
2306 gdb_flush (gdb_stdout
);
2309 psymtab_to_symtab_1 (pst
);
2311 /* Finish up the debug error message. */
2313 printf_filtered ("done.\n");
2319 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2321 struct objfile
*objfile
= pst
->objfile
;
2322 bfd
*abfd
= objfile
->obfd
;
2323 struct dwarf2_cu cu
;
2324 struct die_info
*dies
;
2325 unsigned long offset
;
2326 CORE_ADDR lowpc
, highpc
;
2327 struct die_info
*child_die
;
2329 struct symtab
*symtab
;
2330 struct cleanup
*back_to
;
2331 struct attribute
*attr
;
2335 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2336 if (!pst
->dependencies
[i
]->readin
)
2338 /* Inform about additional files that need to be read in. */
2341 fputs_filtered (" ", gdb_stdout
);
2343 fputs_filtered ("and ", gdb_stdout
);
2345 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2346 wrap_here (""); /* Flush output */
2347 gdb_flush (gdb_stdout
);
2349 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2352 if (pst
->read_symtab_private
== NULL
)
2354 /* It's an include file, no symbols to read for it.
2355 Everything is in the parent symtab. */
2360 dwarf2_per_objfile
= objfile_data (pst
->objfile
, dwarf2_objfile_data_key
);
2362 /* Set local variables from the partial symbol table info. */
2363 offset
= DWARF_INFO_OFFSET (pst
);
2365 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2366 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2368 /* We're in the global namespace. */
2369 processing_current_prefix
= "";
2371 memset (&cu
, 0, sizeof (struct dwarf2_cu
));
2372 obstack_init (&cu
.comp_unit_obstack
);
2373 back_to
= make_cleanup (free_stack_comp_unit
, &cu
);
2376 make_cleanup (really_free_pendings
, NULL
);
2378 cu
.objfile
= objfile
;
2380 /* read in the comp_unit header */
2381 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
2383 /* Read the abbrevs for this compilation unit */
2384 dwarf2_read_abbrevs (abfd
, &cu
);
2385 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2387 cu
.header
.offset
= offset
;
2389 cu
.list_in_scope
= &file_symbols
;
2391 dies
= read_comp_unit (info_ptr
, abfd
, &cu
);
2393 make_cleanup_free_die_list (dies
);
2395 /* Find the base address of the compilation unit for range lists and
2396 location lists. It will normally be specified by DW_AT_low_pc.
2397 In DWARF-3 draft 4, the base address could be overridden by
2398 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2399 compilation units with discontinuous ranges. */
2401 cu
.header
.base_known
= 0;
2402 cu
.header
.base_address
= 0;
2404 attr
= dwarf2_attr (dies
, DW_AT_entry_pc
, &cu
);
2407 cu
.header
.base_address
= DW_ADDR (attr
);
2408 cu
.header
.base_known
= 1;
2412 attr
= dwarf2_attr (dies
, DW_AT_low_pc
, &cu
);
2415 cu
.header
.base_address
= DW_ADDR (attr
);
2416 cu
.header
.base_known
= 1;
2420 /* Do line number decoding in read_file_scope () */
2421 process_die (dies
, &cu
);
2423 /* Some compilers don't define a DW_AT_high_pc attribute for the
2424 compilation unit. If the DW_AT_high_pc is missing, synthesize
2425 it, by scanning the DIE's below the compilation unit. */
2426 get_scope_pc_bounds (dies
, &lowpc
, &highpc
, &cu
);
2428 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2430 /* Set symtab language to language from DW_AT_language.
2431 If the compilation is from a C file generated by language preprocessors,
2432 do not set the language if it was already deduced by start_subfile. */
2434 && !(cu
.language
== language_c
&& symtab
->language
!= language_c
))
2436 symtab
->language
= cu
.language
;
2438 pst
->symtab
= symtab
;
2441 do_cleanups (back_to
);
2444 /* Process a die and its children. */
2447 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2451 case DW_TAG_padding
:
2453 case DW_TAG_compile_unit
:
2454 read_file_scope (die
, cu
);
2456 case DW_TAG_subprogram
:
2457 read_subroutine_type (die
, cu
);
2458 read_func_scope (die
, cu
);
2460 case DW_TAG_inlined_subroutine
:
2461 /* FIXME: These are ignored for now.
2462 They could be used to set breakpoints on all inlined instances
2463 of a function and make GDB `next' properly over inlined functions. */
2465 case DW_TAG_lexical_block
:
2466 case DW_TAG_try_block
:
2467 case DW_TAG_catch_block
:
2468 read_lexical_block_scope (die
, cu
);
2470 case DW_TAG_class_type
:
2471 case DW_TAG_structure_type
:
2472 case DW_TAG_union_type
:
2473 read_structure_type (die
, cu
);
2474 process_structure_scope (die
, cu
);
2476 case DW_TAG_enumeration_type
:
2477 read_enumeration_type (die
, cu
);
2478 process_enumeration_scope (die
, cu
);
2481 /* FIXME drow/2004-03-14: These initialize die->type, but do not create
2482 a symbol or process any children. Therefore it doesn't do anything
2483 that won't be done on-demand by read_type_die. */
2484 case DW_TAG_subroutine_type
:
2485 read_subroutine_type (die
, cu
);
2487 case DW_TAG_array_type
:
2488 read_array_type (die
, cu
);
2490 case DW_TAG_pointer_type
:
2491 read_tag_pointer_type (die
, cu
);
2493 case DW_TAG_ptr_to_member_type
:
2494 read_tag_ptr_to_member_type (die
, cu
);
2496 case DW_TAG_reference_type
:
2497 read_tag_reference_type (die
, cu
);
2499 case DW_TAG_string_type
:
2500 read_tag_string_type (die
, cu
);
2504 case DW_TAG_base_type
:
2505 read_base_type (die
, cu
);
2506 /* Add a typedef symbol for the type definition, if it has a
2508 new_symbol (die
, die
->type
, cu
);
2510 case DW_TAG_subrange_type
:
2511 read_subrange_type (die
, cu
);
2512 /* Add a typedef symbol for the type definition, if it has a
2514 new_symbol (die
, die
->type
, cu
);
2516 case DW_TAG_common_block
:
2517 read_common_block (die
, cu
);
2519 case DW_TAG_common_inclusion
:
2521 case DW_TAG_namespace
:
2522 processing_has_namespace_info
= 1;
2523 read_namespace (die
, cu
);
2525 case DW_TAG_imported_declaration
:
2526 case DW_TAG_imported_module
:
2527 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2528 information contained in these. DW_TAG_imported_declaration
2529 dies shouldn't have children; DW_TAG_imported_module dies
2530 shouldn't in the C++ case, but conceivably could in the
2531 Fortran case, so we'll have to replace this gdb_assert if
2532 Fortran compilers start generating that info. */
2533 processing_has_namespace_info
= 1;
2534 gdb_assert (die
->child
== NULL
);
2537 new_symbol (die
, NULL
, cu
);
2543 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2545 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2549 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2551 struct objfile
*objfile
= cu
->objfile
;
2552 struct comp_unit_head
*cu_header
= &cu
->header
;
2553 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2554 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2555 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2556 struct attribute
*attr
;
2557 char *name
= "<unknown>";
2558 char *comp_dir
= NULL
;
2559 struct die_info
*child_die
;
2560 bfd
*abfd
= objfile
->obfd
;
2561 struct line_header
*line_header
= 0;
2564 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2566 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2568 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2569 from finish_block. */
2570 if (lowpc
== ((CORE_ADDR
) -1))
2575 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2578 name
= DW_STRING (attr
);
2580 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2583 comp_dir
= DW_STRING (attr
);
2586 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2587 directory, get rid of it. */
2588 char *cp
= strchr (comp_dir
, ':');
2590 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2595 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2598 set_cu_language (DW_UNSND (attr
), cu
);
2601 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
2603 cu
->producer
= DW_STRING (attr
);
2605 /* We assume that we're processing GCC output. */
2606 processing_gcc_compilation
= 2;
2608 /* FIXME:Do something here. */
2609 if (dip
->at_producer
!= NULL
)
2611 handle_producer (dip
->at_producer
);
2615 /* The compilation unit may be in a different language or objfile,
2616 zero out all remembered fundamental types. */
2617 memset (cu
->ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
2619 start_symtab (name
, comp_dir
, lowpc
);
2620 record_debugformat ("DWARF 2");
2622 initialize_cu_func_list (cu
);
2624 /* Process all dies in compilation unit. */
2625 if (die
->child
!= NULL
)
2627 child_die
= die
->child
;
2628 while (child_die
&& child_die
->tag
)
2630 process_die (child_die
, cu
);
2631 child_die
= sibling_die (child_die
);
2635 /* Decode line number information if present. */
2636 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2639 unsigned int line_offset
= DW_UNSND (attr
);
2640 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2643 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
2644 (void *) line_header
);
2645 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2649 /* Decode macro information, if present. Dwarf 2 macro information
2650 refers to information in the line number info statement program
2651 header, so we can only read it if we've read the header
2653 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2654 if (attr
&& line_header
)
2656 unsigned int macro_offset
= DW_UNSND (attr
);
2657 dwarf_decode_macros (line_header
, macro_offset
,
2658 comp_dir
, abfd
, cu
);
2660 do_cleanups (back_to
);
2664 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2665 struct dwarf2_cu
*cu
)
2667 struct function_range
*thisfn
;
2669 thisfn
= (struct function_range
*)
2670 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
2671 thisfn
->name
= name
;
2672 thisfn
->lowpc
= lowpc
;
2673 thisfn
->highpc
= highpc
;
2674 thisfn
->seen_line
= 0;
2675 thisfn
->next
= NULL
;
2677 if (cu
->last_fn
== NULL
)
2678 cu
->first_fn
= thisfn
;
2680 cu
->last_fn
->next
= thisfn
;
2682 cu
->last_fn
= thisfn
;
2686 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2688 struct objfile
*objfile
= cu
->objfile
;
2689 struct context_stack
*new;
2692 struct die_info
*child_die
;
2693 struct attribute
*attr
;
2695 const char *previous_prefix
= processing_current_prefix
;
2696 struct cleanup
*back_to
= NULL
;
2699 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2701 name
= dwarf2_linkage_name (die
, cu
);
2703 /* Ignore functions with missing or empty names and functions with
2704 missing or invalid low and high pc attributes. */
2705 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2708 if (cu
->language
== language_cplus
2709 || cu
->language
== language_java
)
2711 struct die_info
*spec_die
= die_specification (die
, cu
);
2713 /* NOTE: carlton/2004-01-23: We have to be careful in the
2714 presence of DW_AT_specification. For example, with GCC 3.4,
2719 // Definition of N::foo.
2723 then we'll have a tree of DIEs like this:
2725 1: DW_TAG_compile_unit
2726 2: DW_TAG_namespace // N
2727 3: DW_TAG_subprogram // declaration of N::foo
2728 4: DW_TAG_subprogram // definition of N::foo
2729 DW_AT_specification // refers to die #3
2731 Thus, when processing die #4, we have to pretend that we're
2732 in the context of its DW_AT_specification, namely the contex
2735 if (spec_die
!= NULL
)
2737 char *specification_prefix
= determine_prefix (spec_die
, cu
);
2738 processing_current_prefix
= specification_prefix
;
2739 back_to
= make_cleanup (xfree
, specification_prefix
);
2746 /* Record the function range for dwarf_decode_lines. */
2747 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
2749 new = push_context (0, lowpc
);
2750 new->name
= new_symbol (die
, die
->type
, cu
);
2752 /* If there is a location expression for DW_AT_frame_base, record
2754 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
2756 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2757 expression is being recorded directly in the function's symbol
2758 and not in a separate frame-base object. I guess this hack is
2759 to avoid adding some sort of frame-base adjunct/annex to the
2760 function's symbol :-(. The problem with doing this is that it
2761 results in a function symbol with a location expression that
2762 has nothing to do with the location of the function, ouch! The
2763 relationship should be: a function's symbol has-a frame base; a
2764 frame-base has-a location expression. */
2765 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
2767 cu
->list_in_scope
= &local_symbols
;
2769 if (die
->child
!= NULL
)
2771 child_die
= die
->child
;
2772 while (child_die
&& child_die
->tag
)
2774 process_die (child_die
, cu
);
2775 child_die
= sibling_die (child_die
);
2779 new = pop_context ();
2780 /* Make a block for the local symbols within. */
2781 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2782 lowpc
, highpc
, objfile
);
2784 /* In C++, we can have functions nested inside functions (e.g., when
2785 a function declares a class that has methods). This means that
2786 when we finish processing a function scope, we may need to go
2787 back to building a containing block's symbol lists. */
2788 local_symbols
= new->locals
;
2789 param_symbols
= new->params
;
2791 /* If we've finished processing a top-level function, subsequent
2792 symbols go in the file symbol list. */
2793 if (outermost_context_p ())
2794 cu
->list_in_scope
= &file_symbols
;
2796 processing_current_prefix
= previous_prefix
;
2797 if (back_to
!= NULL
)
2798 do_cleanups (back_to
);
2801 /* Process all the DIES contained within a lexical block scope. Start
2802 a new scope, process the dies, and then close the scope. */
2805 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2807 struct objfile
*objfile
= cu
->objfile
;
2808 struct context_stack
*new;
2809 CORE_ADDR lowpc
, highpc
;
2810 struct die_info
*child_die
;
2813 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2815 /* Ignore blocks with missing or invalid low and high pc attributes. */
2816 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2817 as multiple lexical blocks? Handling children in a sane way would
2818 be nasty. Might be easier to properly extend generic blocks to
2820 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2825 push_context (0, lowpc
);
2826 if (die
->child
!= NULL
)
2828 child_die
= die
->child
;
2829 while (child_die
&& child_die
->tag
)
2831 process_die (child_die
, cu
);
2832 child_die
= sibling_die (child_die
);
2835 new = pop_context ();
2837 if (local_symbols
!= NULL
)
2839 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2842 local_symbols
= new->locals
;
2845 /* Get low and high pc attributes from a die. Return 1 if the attributes
2846 are present and valid, otherwise, return 0. Return -1 if the range is
2847 discontinuous, i.e. derived from DW_AT_ranges information. */
2849 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2850 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
2852 struct objfile
*objfile
= cu
->objfile
;
2853 struct comp_unit_head
*cu_header
= &cu
->header
;
2854 struct attribute
*attr
;
2855 bfd
*obfd
= objfile
->obfd
;
2860 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
2863 high
= DW_ADDR (attr
);
2864 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
2866 low
= DW_ADDR (attr
);
2868 /* Found high w/o low attribute. */
2871 /* Found consecutive range of addresses. */
2876 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
2879 unsigned int addr_size
= cu_header
->addr_size
;
2880 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2881 /* Value of the DW_AT_ranges attribute is the offset in the
2882 .debug_ranges section. */
2883 unsigned int offset
= DW_UNSND (attr
);
2884 /* Base address selection entry. */
2892 found_base
= cu_header
->base_known
;
2893 base
= cu_header
->base_address
;
2895 if (offset
>= dwarf2_per_objfile
->ranges_size
)
2897 complaint (&symfile_complaints
,
2898 "Offset %d out of bounds for DW_AT_ranges attribute",
2902 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
2904 /* Read in the largest possible address. */
2905 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
2906 if ((marker
& mask
) == mask
)
2908 /* If we found the largest possible address, then
2909 read the base address. */
2910 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2911 buffer
+= 2 * addr_size
;
2912 offset
+= 2 * addr_size
;
2920 CORE_ADDR range_beginning
, range_end
;
2922 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
2923 buffer
+= addr_size
;
2924 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
2925 buffer
+= addr_size
;
2926 offset
+= 2 * addr_size
;
2928 /* An end of list marker is a pair of zero addresses. */
2929 if (range_beginning
== 0 && range_end
== 0)
2930 /* Found the end of list entry. */
2933 /* Each base address selection entry is a pair of 2 values.
2934 The first is the largest possible address, the second is
2935 the base address. Check for a base address here. */
2936 if ((range_beginning
& mask
) == mask
)
2938 /* If we found the largest possible address, then
2939 read the base address. */
2940 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2947 /* We have no valid base address for the ranges
2949 complaint (&symfile_complaints
,
2950 "Invalid .debug_ranges data (no base address)");
2954 range_beginning
+= base
;
2957 /* FIXME: This is recording everything as a low-high
2958 segment of consecutive addresses. We should have a
2959 data structure for discontiguous block ranges
2963 low
= range_beginning
;
2969 if (range_beginning
< low
)
2970 low
= range_beginning
;
2971 if (range_end
> high
)
2977 /* If the first entry is an end-of-list marker, the range
2978 describes an empty scope, i.e. no instructions. */
2988 /* When using the GNU linker, .gnu.linkonce. sections are used to
2989 eliminate duplicate copies of functions and vtables and such.
2990 The linker will arbitrarily choose one and discard the others.
2991 The AT_*_pc values for such functions refer to local labels in
2992 these sections. If the section from that file was discarded, the
2993 labels are not in the output, so the relocs get a value of 0.
2994 If this is a discarded function, mark the pc bounds as invalid,
2995 so that GDB will ignore it. */
2996 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
3004 /* Get the low and high pc's represented by the scope DIE, and store
3005 them in *LOWPC and *HIGHPC. If the correct values can't be
3006 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3009 get_scope_pc_bounds (struct die_info
*die
,
3010 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3011 struct dwarf2_cu
*cu
)
3013 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3014 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3015 CORE_ADDR current_low
, current_high
;
3017 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3019 best_low
= current_low
;
3020 best_high
= current_high
;
3024 struct die_info
*child
= die
->child
;
3026 while (child
&& child
->tag
)
3028 switch (child
->tag
) {
3029 case DW_TAG_subprogram
:
3030 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
3032 best_low
= min (best_low
, current_low
);
3033 best_high
= max (best_high
, current_high
);
3036 case DW_TAG_namespace
:
3037 /* FIXME: carlton/2004-01-16: Should we do this for
3038 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3039 that current GCC's always emit the DIEs corresponding
3040 to definitions of methods of classes as children of a
3041 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3042 the DIEs giving the declarations, which could be
3043 anywhere). But I don't see any reason why the
3044 standards says that they have to be there. */
3045 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3047 if (current_low
!= ((CORE_ADDR
) -1))
3049 best_low
= min (best_low
, current_low
);
3050 best_high
= max (best_high
, current_high
);
3058 child
= sibling_die (child
);
3063 *highpc
= best_high
;
3066 /* Add an aggregate field to the field list. */
3069 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3070 struct dwarf2_cu
*cu
)
3072 struct objfile
*objfile
= cu
->objfile
;
3073 struct nextfield
*new_field
;
3074 struct attribute
*attr
;
3076 char *fieldname
= "";
3078 /* Allocate a new field list entry and link it in. */
3079 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3080 make_cleanup (xfree
, new_field
);
3081 memset (new_field
, 0, sizeof (struct nextfield
));
3082 new_field
->next
= fip
->fields
;
3083 fip
->fields
= new_field
;
3086 /* Handle accessibility and virtuality of field.
3087 The default accessibility for members is public, the default
3088 accessibility for inheritance is private. */
3089 if (die
->tag
!= DW_TAG_inheritance
)
3090 new_field
->accessibility
= DW_ACCESS_public
;
3092 new_field
->accessibility
= DW_ACCESS_private
;
3093 new_field
->virtuality
= DW_VIRTUALITY_none
;
3095 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3097 new_field
->accessibility
= DW_UNSND (attr
);
3098 if (new_field
->accessibility
!= DW_ACCESS_public
)
3099 fip
->non_public_fields
= 1;
3100 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3102 new_field
->virtuality
= DW_UNSND (attr
);
3104 fp
= &new_field
->field
;
3106 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3108 /* Data member other than a C++ static data member. */
3110 /* Get type of field. */
3111 fp
->type
= die_type (die
, cu
);
3113 FIELD_STATIC_KIND (*fp
) = 0;
3115 /* Get bit size of field (zero if none). */
3116 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3119 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3123 FIELD_BITSIZE (*fp
) = 0;
3126 /* Get bit offset of field. */
3127 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3130 FIELD_BITPOS (*fp
) =
3131 decode_locdesc (DW_BLOCK (attr
), cu
) * bits_per_byte
;
3134 FIELD_BITPOS (*fp
) = 0;
3135 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3138 if (BITS_BIG_ENDIAN
)
3140 /* For big endian bits, the DW_AT_bit_offset gives the
3141 additional bit offset from the MSB of the containing
3142 anonymous object to the MSB of the field. We don't
3143 have to do anything special since we don't need to
3144 know the size of the anonymous object. */
3145 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3149 /* For little endian bits, compute the bit offset to the
3150 MSB of the anonymous object, subtract off the number of
3151 bits from the MSB of the field to the MSB of the
3152 object, and then subtract off the number of bits of
3153 the field itself. The result is the bit offset of
3154 the LSB of the field. */
3156 int bit_offset
= DW_UNSND (attr
);
3158 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3161 /* The size of the anonymous object containing
3162 the bit field is explicit, so use the
3163 indicated size (in bytes). */
3164 anonymous_size
= DW_UNSND (attr
);
3168 /* The size of the anonymous object containing
3169 the bit field must be inferred from the type
3170 attribute of the data member containing the
3172 anonymous_size
= TYPE_LENGTH (fp
->type
);
3174 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3175 - bit_offset
- FIELD_BITSIZE (*fp
);
3179 /* Get name of field. */
3180 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3181 if (attr
&& DW_STRING (attr
))
3182 fieldname
= DW_STRING (attr
);
3184 /* The name is already allocated along with this objfile, so we don't
3185 need to duplicate it for the type. */
3186 fp
->name
= fieldname
;
3188 /* Change accessibility for artificial fields (e.g. virtual table
3189 pointer or virtual base class pointer) to private. */
3190 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3192 new_field
->accessibility
= DW_ACCESS_private
;
3193 fip
->non_public_fields
= 1;
3196 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3198 /* C++ static member. */
3200 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3201 is a declaration, but all versions of G++ as of this writing
3202 (so through at least 3.2.1) incorrectly generate
3203 DW_TAG_variable tags. */
3207 /* Get name of field. */
3208 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3209 if (attr
&& DW_STRING (attr
))
3210 fieldname
= DW_STRING (attr
);
3214 /* Get physical name. */
3215 physname
= dwarf2_linkage_name (die
, cu
);
3217 /* The name is already allocated along with this objfile, so we don't
3218 need to duplicate it for the type. */
3219 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3220 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3221 FIELD_NAME (*fp
) = fieldname
;
3223 else if (die
->tag
== DW_TAG_inheritance
)
3225 /* C++ base class field. */
3226 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3228 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
3230 FIELD_BITSIZE (*fp
) = 0;
3231 FIELD_STATIC_KIND (*fp
) = 0;
3232 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3233 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3234 fip
->nbaseclasses
++;
3238 /* Create the vector of fields, and attach it to the type. */
3241 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3242 struct dwarf2_cu
*cu
)
3244 int nfields
= fip
->nfields
;
3246 /* Record the field count, allocate space for the array of fields,
3247 and create blank accessibility bitfields if necessary. */
3248 TYPE_NFIELDS (type
) = nfields
;
3249 TYPE_FIELDS (type
) = (struct field
*)
3250 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3251 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3253 if (fip
->non_public_fields
)
3255 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3257 TYPE_FIELD_PRIVATE_BITS (type
) =
3258 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3259 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3261 TYPE_FIELD_PROTECTED_BITS (type
) =
3262 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3263 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3265 TYPE_FIELD_IGNORE_BITS (type
) =
3266 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3267 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3270 /* If the type has baseclasses, allocate and clear a bit vector for
3271 TYPE_FIELD_VIRTUAL_BITS. */
3272 if (fip
->nbaseclasses
)
3274 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3277 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3278 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
3279 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
3280 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3281 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3284 /* Copy the saved-up fields into the field vector. Start from the head
3285 of the list, adding to the tail of the field array, so that they end
3286 up in the same order in the array in which they were added to the list. */
3287 while (nfields
-- > 0)
3289 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3290 switch (fip
->fields
->accessibility
)
3292 case DW_ACCESS_private
:
3293 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3296 case DW_ACCESS_protected
:
3297 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3300 case DW_ACCESS_public
:
3304 /* Unknown accessibility. Complain and treat it as public. */
3306 complaint (&symfile_complaints
, "unsupported accessibility %d",
3307 fip
->fields
->accessibility
);
3311 if (nfields
< fip
->nbaseclasses
)
3313 switch (fip
->fields
->virtuality
)
3315 case DW_VIRTUALITY_virtual
:
3316 case DW_VIRTUALITY_pure_virtual
:
3317 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3321 fip
->fields
= fip
->fields
->next
;
3325 /* Add a member function to the proper fieldlist. */
3328 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3329 struct type
*type
, struct dwarf2_cu
*cu
)
3331 struct objfile
*objfile
= cu
->objfile
;
3332 struct attribute
*attr
;
3333 struct fnfieldlist
*flp
;
3335 struct fn_field
*fnp
;
3338 struct nextfnfield
*new_fnfield
;
3340 /* Get name of member function. */
3341 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3342 if (attr
&& DW_STRING (attr
))
3343 fieldname
= DW_STRING (attr
);
3347 /* Get the mangled name. */
3348 physname
= dwarf2_linkage_name (die
, cu
);
3350 /* Look up member function name in fieldlist. */
3351 for (i
= 0; i
< fip
->nfnfields
; i
++)
3353 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3357 /* Create new list element if necessary. */
3358 if (i
< fip
->nfnfields
)
3359 flp
= &fip
->fnfieldlists
[i
];
3362 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3364 fip
->fnfieldlists
= (struct fnfieldlist
*)
3365 xrealloc (fip
->fnfieldlists
,
3366 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3367 * sizeof (struct fnfieldlist
));
3368 if (fip
->nfnfields
== 0)
3369 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3371 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3372 flp
->name
= fieldname
;
3378 /* Create a new member function field and chain it to the field list
3380 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3381 make_cleanup (xfree
, new_fnfield
);
3382 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3383 new_fnfield
->next
= flp
->head
;
3384 flp
->head
= new_fnfield
;
3387 /* Fill in the member function field info. */
3388 fnp
= &new_fnfield
->fnfield
;
3389 /* The name is already allocated along with this objfile, so we don't
3390 need to duplicate it for the type. */
3391 fnp
->physname
= physname
? physname
: "";
3392 fnp
->type
= alloc_type (objfile
);
3393 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
3395 int nparams
= TYPE_NFIELDS (die
->type
);
3397 /* TYPE is the domain of this method, and DIE->TYPE is the type
3398 of the method itself (TYPE_CODE_METHOD). */
3399 smash_to_method_type (fnp
->type
, type
,
3400 TYPE_TARGET_TYPE (die
->type
),
3401 TYPE_FIELDS (die
->type
),
3402 TYPE_NFIELDS (die
->type
),
3403 TYPE_VARARGS (die
->type
));
3405 /* Handle static member functions.
3406 Dwarf2 has no clean way to discern C++ static and non-static
3407 member functions. G++ helps GDB by marking the first
3408 parameter for non-static member functions (which is the
3409 this pointer) as artificial. We obtain this information
3410 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3411 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
3412 fnp
->voffset
= VOFFSET_STATIC
;
3415 complaint (&symfile_complaints
, "member function type missing for '%s'",
3418 /* Get fcontext from DW_AT_containing_type if present. */
3419 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3420 fnp
->fcontext
= die_containing_type (die
, cu
);
3422 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3423 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3425 /* Get accessibility. */
3426 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3429 switch (DW_UNSND (attr
))
3431 case DW_ACCESS_private
:
3432 fnp
->is_private
= 1;
3434 case DW_ACCESS_protected
:
3435 fnp
->is_protected
= 1;
3440 /* Check for artificial methods. */
3441 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3442 if (attr
&& DW_UNSND (attr
) != 0)
3443 fnp
->is_artificial
= 1;
3445 /* Get index in virtual function table if it is a virtual member function. */
3446 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3449 /* Support the .debug_loc offsets */
3450 if (attr_form_is_block (attr
))
3452 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3454 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3456 dwarf2_complex_location_expr_complaint ();
3460 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3466 /* Create the vector of member function fields, and attach it to the type. */
3469 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3470 struct dwarf2_cu
*cu
)
3472 struct fnfieldlist
*flp
;
3473 int total_length
= 0;
3476 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3477 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3478 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3480 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3482 struct nextfnfield
*nfp
= flp
->head
;
3483 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3486 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3487 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3488 fn_flp
->fn_fields
= (struct fn_field
*)
3489 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3490 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3491 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3493 total_length
+= flp
->length
;
3496 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3497 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3501 /* Returns non-zero if NAME is the name of a vtable member in CU's
3502 language, zero otherwise. */
3504 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
3506 static const char vptr
[] = "_vptr";
3507 static const char vtable
[] = "vtable";
3509 /* Look for the C++ and Java forms of the vtable. */
3510 if ((cu
->language
== language_java
3511 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
3512 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
3513 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
3520 /* Called when we find the DIE that starts a structure or union scope
3521 (definition) to process all dies that define the members of the
3524 NOTE: we need to call struct_type regardless of whether or not the
3525 DIE has an at_name attribute, since it might be an anonymous
3526 structure or union. This gets the type entered into our set of
3529 However, if the structure is incomplete (an opaque struct/union)
3530 then suppress creating a symbol table entry for it since gdb only
3531 wants to find the one with the complete definition. Note that if
3532 it is complete, we just call new_symbol, which does it's own
3533 checking about whether the struct/union is anonymous or not (and
3534 suppresses creating a symbol table entry itself). */
3537 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3539 struct objfile
*objfile
= cu
->objfile
;
3541 struct attribute
*attr
;
3542 const char *previous_prefix
= processing_current_prefix
;
3543 struct cleanup
*back_to
= NULL
;
3548 type
= alloc_type (objfile
);
3550 INIT_CPLUS_SPECIFIC (type
);
3551 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3552 if (attr
&& DW_STRING (attr
))
3554 if (cu
->language
== language_cplus
3555 || cu
->language
== language_java
)
3557 char *new_prefix
= determine_class_name (die
, cu
);
3558 TYPE_TAG_NAME (type
) = obsavestring (new_prefix
,
3559 strlen (new_prefix
),
3560 &objfile
->objfile_obstack
);
3561 back_to
= make_cleanup (xfree
, new_prefix
);
3562 processing_current_prefix
= new_prefix
;
3566 /* The name is already allocated along with this objfile, so
3567 we don't need to duplicate it for the type. */
3568 TYPE_TAG_NAME (type
) = DW_STRING (attr
);
3572 if (die
->tag
== DW_TAG_structure_type
)
3574 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
3576 else if (die
->tag
== DW_TAG_union_type
)
3578 TYPE_CODE (type
) = TYPE_CODE_UNION
;
3582 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
3584 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
3587 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3590 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3594 TYPE_LENGTH (type
) = 0;
3597 if (die_is_declaration (die
, cu
))
3598 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
3600 /* We need to add the type field to the die immediately so we don't
3601 infinitely recurse when dealing with pointers to the structure
3602 type within the structure itself. */
3605 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3607 struct field_info fi
;
3608 struct die_info
*child_die
;
3609 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
3611 memset (&fi
, 0, sizeof (struct field_info
));
3613 child_die
= die
->child
;
3615 while (child_die
&& child_die
->tag
)
3617 if (child_die
->tag
== DW_TAG_member
3618 || child_die
->tag
== DW_TAG_variable
)
3620 /* NOTE: carlton/2002-11-05: A C++ static data member
3621 should be a DW_TAG_member that is a declaration, but
3622 all versions of G++ as of this writing (so through at
3623 least 3.2.1) incorrectly generate DW_TAG_variable
3624 tags for them instead. */
3625 dwarf2_add_field (&fi
, child_die
, cu
);
3627 else if (child_die
->tag
== DW_TAG_subprogram
)
3629 /* C++ member function. */
3630 read_type_die (child_die
, cu
);
3631 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
3633 else if (child_die
->tag
== DW_TAG_inheritance
)
3635 /* C++ base class field. */
3636 dwarf2_add_field (&fi
, child_die
, cu
);
3638 child_die
= sibling_die (child_die
);
3641 /* Attach fields and member functions to the type. */
3643 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
3646 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
3648 /* Get the type which refers to the base class (possibly this
3649 class itself) which contains the vtable pointer for the current
3650 class from the DW_AT_containing_type attribute. */
3652 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3654 struct type
*t
= die_containing_type (die
, cu
);
3656 TYPE_VPTR_BASETYPE (type
) = t
;
3661 /* Our own class provides vtbl ptr. */
3662 for (i
= TYPE_NFIELDS (t
) - 1;
3663 i
>= TYPE_N_BASECLASSES (t
);
3666 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
3668 if (is_vtable_name (fieldname
, cu
))
3670 TYPE_VPTR_FIELDNO (type
) = i
;
3675 /* Complain if virtual function table field not found. */
3676 if (i
< TYPE_N_BASECLASSES (t
))
3677 complaint (&symfile_complaints
,
3678 "virtual function table pointer not found when defining class '%s'",
3679 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
3684 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3689 do_cleanups (back_to
);
3692 processing_current_prefix
= previous_prefix
;
3693 if (back_to
!= NULL
)
3694 do_cleanups (back_to
);
3698 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3700 struct objfile
*objfile
= cu
->objfile
;
3701 const char *previous_prefix
= processing_current_prefix
;
3702 struct die_info
*child_die
= die
->child
;
3704 if (TYPE_TAG_NAME (die
->type
) != NULL
)
3705 processing_current_prefix
= TYPE_TAG_NAME (die
->type
);
3707 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
3708 snapshots) has been known to create a die giving a declaration
3709 for a class that has, as a child, a die giving a definition for a
3710 nested class. So we have to process our children even if the
3711 current die is a declaration. Normally, of course, a declaration
3712 won't have any children at all. */
3714 while (child_die
!= NULL
&& child_die
->tag
)
3716 if (child_die
->tag
== DW_TAG_member
3717 || child_die
->tag
== DW_TAG_variable
3718 || child_die
->tag
== DW_TAG_inheritance
)
3723 process_die (child_die
, cu
);
3725 child_die
= sibling_die (child_die
);
3728 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3729 new_symbol (die
, die
->type
, cu
);
3731 processing_current_prefix
= previous_prefix
;
3734 /* Given a DW_AT_enumeration_type die, set its type. We do not
3735 complete the type's fields yet, or create any symbols. */
3738 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3740 struct objfile
*objfile
= cu
->objfile
;
3742 struct attribute
*attr
;
3747 type
= alloc_type (objfile
);
3749 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3750 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3751 if (attr
&& DW_STRING (attr
))
3753 char *name
= DW_STRING (attr
);
3755 if (processing_has_namespace_info
)
3757 TYPE_TAG_NAME (type
) = typename_concat (&objfile
->objfile_obstack
,
3758 processing_current_prefix
,
3763 /* The name is already allocated along with this objfile, so
3764 we don't need to duplicate it for the type. */
3765 TYPE_TAG_NAME (type
) = name
;
3769 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3772 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3776 TYPE_LENGTH (type
) = 0;
3782 /* Determine the name of the type represented by DIE, which should be
3783 a named C++ or Java compound type. Return the name in question; the caller
3784 is responsible for xfree()'ing it. */
3787 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
3789 struct cleanup
*back_to
= NULL
;
3790 struct die_info
*spec_die
= die_specification (die
, cu
);
3791 char *new_prefix
= NULL
;
3793 /* If this is the definition of a class that is declared by another
3794 die, then processing_current_prefix may not be accurate; see
3795 read_func_scope for a similar example. */
3796 if (spec_die
!= NULL
)
3798 char *specification_prefix
= determine_prefix (spec_die
, cu
);
3799 processing_current_prefix
= specification_prefix
;
3800 back_to
= make_cleanup (xfree
, specification_prefix
);
3803 /* If we don't have namespace debug info, guess the name by trying
3804 to demangle the names of members, just like we did in
3805 guess_structure_name. */
3806 if (!processing_has_namespace_info
)
3808 struct die_info
*child
;
3810 for (child
= die
->child
;
3811 child
!= NULL
&& child
->tag
!= 0;
3812 child
= sibling_die (child
))
3814 if (child
->tag
== DW_TAG_subprogram
)
3817 = language_class_name_from_physname (cu
->language_defn
,
3821 if (new_prefix
!= NULL
)
3827 if (new_prefix
== NULL
)
3829 const char *name
= dwarf2_name (die
, cu
);
3830 new_prefix
= typename_concat (NULL
, processing_current_prefix
,
3831 name
? name
: "<<anonymous>>",
3835 if (back_to
!= NULL
)
3836 do_cleanups (back_to
);
3841 /* Given a pointer to a die which begins an enumeration, process all
3842 the dies that define the members of the enumeration, and create the
3843 symbol for the enumeration type.
3845 NOTE: We reverse the order of the element list. */
3848 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3850 struct objfile
*objfile
= cu
->objfile
;
3851 struct die_info
*child_die
;
3852 struct field
*fields
;
3853 struct attribute
*attr
;
3856 int unsigned_enum
= 1;
3860 if (die
->child
!= NULL
)
3862 child_die
= die
->child
;
3863 while (child_die
&& child_die
->tag
)
3865 if (child_die
->tag
!= DW_TAG_enumerator
)
3867 process_die (child_die
, cu
);
3871 attr
= dwarf2_attr (child_die
, DW_AT_name
, cu
);
3874 sym
= new_symbol (child_die
, die
->type
, cu
);
3875 if (SYMBOL_VALUE (sym
) < 0)
3878 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3880 fields
= (struct field
*)
3882 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
3883 * sizeof (struct field
));
3886 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
3887 FIELD_TYPE (fields
[num_fields
]) = NULL
;
3888 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
3889 FIELD_BITSIZE (fields
[num_fields
]) = 0;
3890 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
3896 child_die
= sibling_die (child_die
);
3901 TYPE_NFIELDS (die
->type
) = num_fields
;
3902 TYPE_FIELDS (die
->type
) = (struct field
*)
3903 TYPE_ALLOC (die
->type
, sizeof (struct field
) * num_fields
);
3904 memcpy (TYPE_FIELDS (die
->type
), fields
,
3905 sizeof (struct field
) * num_fields
);
3909 TYPE_FLAGS (die
->type
) |= TYPE_FLAG_UNSIGNED
;
3912 new_symbol (die
, die
->type
, cu
);
3915 /* Extract all information from a DW_TAG_array_type DIE and put it in
3916 the DIE's type field. For now, this only handles one dimensional
3920 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3922 struct objfile
*objfile
= cu
->objfile
;
3923 struct die_info
*child_die
;
3924 struct type
*type
= NULL
;
3925 struct type
*element_type
, *range_type
, *index_type
;
3926 struct type
**range_types
= NULL
;
3927 struct attribute
*attr
;
3929 struct cleanup
*back_to
;
3931 /* Return if we've already decoded this type. */
3937 element_type
= die_type (die
, cu
);
3939 /* Irix 6.2 native cc creates array types without children for
3940 arrays with unspecified length. */
3941 if (die
->child
== NULL
)
3943 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
3944 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3945 die
->type
= create_array_type (NULL
, element_type
, range_type
);
3949 back_to
= make_cleanup (null_cleanup
, NULL
);
3950 child_die
= die
->child
;
3951 while (child_die
&& child_die
->tag
)
3953 if (child_die
->tag
== DW_TAG_subrange_type
)
3955 read_subrange_type (child_die
, cu
);
3957 if (child_die
->type
!= NULL
)
3959 /* The range type was succesfully read. Save it for
3960 the array type creation. */
3961 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3963 range_types
= (struct type
**)
3964 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3965 * sizeof (struct type
*));
3967 make_cleanup (free_current_contents
, &range_types
);
3969 range_types
[ndim
++] = child_die
->type
;
3972 child_die
= sibling_die (child_die
);
3975 /* Dwarf2 dimensions are output from left to right, create the
3976 necessary array types in backwards order. */
3978 type
= element_type
;
3980 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
3984 type
= create_array_type (NULL
, type
, range_types
[i
++]);
3989 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3992 /* Understand Dwarf2 support for vector types (like they occur on
3993 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3994 array type. This is not part of the Dwarf2/3 standard yet, but a
3995 custom vendor extension. The main difference between a regular
3996 array and the vector variant is that vectors are passed by value
3998 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4000 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
4002 do_cleanups (back_to
);
4004 /* Install the type in the die. */
4008 static enum dwarf_array_dim_ordering
4009 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4011 struct attribute
*attr
;
4013 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4015 if (attr
) return DW_SND (attr
);
4018 GNU F77 is a special case, as at 08/2004 array type info is the
4019 opposite order to the dwarf2 specification, but data is still
4020 laid out as per normal fortran.
4022 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4026 if (cu
->language
== language_fortran
&&
4027 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4029 return DW_ORD_row_major
;
4032 switch (cu
->language_defn
->la_array_ordering
)
4034 case array_column_major
:
4035 return DW_ORD_col_major
;
4036 case array_row_major
:
4038 return DW_ORD_row_major
;
4043 /* First cut: install each common block member as a global variable. */
4046 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4048 struct die_info
*child_die
;
4049 struct attribute
*attr
;
4051 CORE_ADDR base
= (CORE_ADDR
) 0;
4053 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4056 /* Support the .debug_loc offsets */
4057 if (attr_form_is_block (attr
))
4059 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4061 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
4063 dwarf2_complex_location_expr_complaint ();
4067 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4068 "common block member");
4071 if (die
->child
!= NULL
)
4073 child_die
= die
->child
;
4074 while (child_die
&& child_die
->tag
)
4076 sym
= new_symbol (child_die
, NULL
, cu
);
4077 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4080 SYMBOL_VALUE_ADDRESS (sym
) =
4081 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4082 add_symbol_to_list (sym
, &global_symbols
);
4084 child_die
= sibling_die (child_die
);
4089 /* Read a C++ namespace. */
4092 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4094 struct objfile
*objfile
= cu
->objfile
;
4095 const char *previous_prefix
= processing_current_prefix
;
4098 struct die_info
*current_die
;
4099 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4101 name
= namespace_name (die
, &is_anonymous
, cu
);
4103 /* Now build the name of the current namespace. */
4105 if (previous_prefix
[0] == '\0')
4107 processing_current_prefix
= name
;
4111 char *temp_name
= typename_concat (NULL
, previous_prefix
, name
, cu
);
4112 make_cleanup (xfree
, temp_name
);
4113 processing_current_prefix
= temp_name
;
4116 /* Add a symbol associated to this if we haven't seen the namespace
4117 before. Also, add a using directive if it's an anonymous
4120 if (dwarf2_extension (die
, cu
) == NULL
)
4124 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
4125 this cast will hopefully become unnecessary. */
4126 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
4127 (char *) processing_current_prefix
,
4129 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4131 new_symbol (die
, type
, cu
);
4135 cp_add_using_directive (processing_current_prefix
,
4136 strlen (previous_prefix
),
4137 strlen (processing_current_prefix
));
4140 if (die
->child
!= NULL
)
4142 struct die_info
*child_die
= die
->child
;
4144 while (child_die
&& child_die
->tag
)
4146 process_die (child_die
, cu
);
4147 child_die
= sibling_die (child_die
);
4151 processing_current_prefix
= previous_prefix
;
4152 do_cleanups (back_to
);
4155 /* Return the name of the namespace represented by DIE. Set
4156 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4160 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4162 struct die_info
*current_die
;
4163 const char *name
= NULL
;
4165 /* Loop through the extensions until we find a name. */
4167 for (current_die
= die
;
4168 current_die
!= NULL
;
4169 current_die
= dwarf2_extension (die
, cu
))
4171 name
= dwarf2_name (current_die
, cu
);
4176 /* Is it an anonymous namespace? */
4178 *is_anonymous
= (name
== NULL
);
4180 name
= "(anonymous namespace)";
4185 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4186 the user defined type vector. */
4189 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4191 struct comp_unit_head
*cu_header
= &cu
->header
;
4193 struct attribute
*attr_byte_size
;
4194 struct attribute
*attr_address_class
;
4195 int byte_size
, addr_class
;
4202 type
= lookup_pointer_type (die_type (die
, cu
));
4204 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4206 byte_size
= DW_UNSND (attr_byte_size
);
4208 byte_size
= cu_header
->addr_size
;
4210 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4211 if (attr_address_class
)
4212 addr_class
= DW_UNSND (attr_address_class
);
4214 addr_class
= DW_ADDR_none
;
4216 /* If the pointer size or address class is different than the
4217 default, create a type variant marked as such and set the
4218 length accordingly. */
4219 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4221 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
4225 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
4226 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
4227 type
= make_type_with_address_space (type
, type_flags
);
4229 else if (TYPE_LENGTH (type
) != byte_size
)
4231 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
4234 /* Should we also complain about unhandled address classes? */
4238 TYPE_LENGTH (type
) = byte_size
;
4242 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4243 the user defined type vector. */
4246 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4248 struct objfile
*objfile
= cu
->objfile
;
4250 struct type
*to_type
;
4251 struct type
*domain
;
4258 type
= alloc_type (objfile
);
4259 to_type
= die_type (die
, cu
);
4260 domain
= die_containing_type (die
, cu
);
4261 smash_to_member_type (type
, domain
, to_type
);
4266 /* Extract all information from a DW_TAG_reference_type DIE and add to
4267 the user defined type vector. */
4270 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4272 struct comp_unit_head
*cu_header
= &cu
->header
;
4274 struct attribute
*attr
;
4281 type
= lookup_reference_type (die_type (die
, cu
));
4282 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4285 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4289 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4295 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4297 struct type
*base_type
;
4304 base_type
= die_type (die
, cu
);
4305 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
4309 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4311 struct type
*base_type
;
4318 base_type
= die_type (die
, cu
);
4319 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
4322 /* Extract all information from a DW_TAG_string_type DIE and add to
4323 the user defined type vector. It isn't really a user defined type,
4324 but it behaves like one, with other DIE's using an AT_user_def_type
4325 attribute to reference it. */
4328 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4330 struct objfile
*objfile
= cu
->objfile
;
4331 struct type
*type
, *range_type
, *index_type
, *char_type
;
4332 struct attribute
*attr
;
4333 unsigned int length
;
4340 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4343 length
= DW_UNSND (attr
);
4347 /* check for the DW_AT_byte_size attribute */
4348 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4351 length
= DW_UNSND (attr
);
4358 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
4359 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4360 if (cu
->language
== language_fortran
)
4362 /* Need to create a unique string type for bounds
4364 type
= create_string_type (0, range_type
);
4368 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
, cu
);
4369 type
= create_string_type (char_type
, range_type
);
4374 /* Handle DIES due to C code like:
4378 int (*funcp)(int a, long l);
4382 ('funcp' generates a DW_TAG_subroutine_type DIE)
4386 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4388 struct type
*type
; /* Type that this function returns */
4389 struct type
*ftype
; /* Function that returns above type */
4390 struct attribute
*attr
;
4392 /* Decode the type that this subroutine returns */
4397 type
= die_type (die
, cu
);
4398 ftype
= lookup_function_type (type
);
4400 /* All functions in C++ and Java have prototypes. */
4401 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4402 if ((attr
&& (DW_UNSND (attr
) != 0))
4403 || cu
->language
== language_cplus
4404 || cu
->language
== language_java
)
4405 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
4407 if (die
->child
!= NULL
)
4409 struct die_info
*child_die
;
4413 /* Count the number of parameters.
4414 FIXME: GDB currently ignores vararg functions, but knows about
4415 vararg member functions. */
4416 child_die
= die
->child
;
4417 while (child_die
&& child_die
->tag
)
4419 if (child_die
->tag
== DW_TAG_formal_parameter
)
4421 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4422 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
4423 child_die
= sibling_die (child_die
);
4426 /* Allocate storage for parameters and fill them in. */
4427 TYPE_NFIELDS (ftype
) = nparams
;
4428 TYPE_FIELDS (ftype
) = (struct field
*)
4429 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
4431 child_die
= die
->child
;
4432 while (child_die
&& child_die
->tag
)
4434 if (child_die
->tag
== DW_TAG_formal_parameter
)
4436 /* Dwarf2 has no clean way to discern C++ static and non-static
4437 member functions. G++ helps GDB by marking the first
4438 parameter for non-static member functions (which is the
4439 this pointer) as artificial. We pass this information
4440 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4441 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4443 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4445 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4446 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4449 child_die
= sibling_die (child_die
);
4457 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4459 struct objfile
*objfile
= cu
->objfile
;
4460 struct attribute
*attr
;
4465 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4466 if (attr
&& DW_STRING (attr
))
4468 name
= DW_STRING (attr
);
4470 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
4471 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
4475 /* Find a representation of a given base type and install
4476 it in the TYPE field of the die. */
4479 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4481 struct objfile
*objfile
= cu
->objfile
;
4483 struct attribute
*attr
;
4484 int encoding
= 0, size
= 0;
4486 /* If we've already decoded this die, this is a no-op. */
4492 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4495 encoding
= DW_UNSND (attr
);
4497 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4500 size
= DW_UNSND (attr
);
4502 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4503 if (attr
&& DW_STRING (attr
))
4505 enum type_code code
= TYPE_CODE_INT
;
4510 case DW_ATE_address
:
4511 /* Turn DW_ATE_address into a void * pointer. */
4512 code
= TYPE_CODE_PTR
;
4513 type_flags
|= TYPE_FLAG_UNSIGNED
;
4515 case DW_ATE_boolean
:
4516 code
= TYPE_CODE_BOOL
;
4517 type_flags
|= TYPE_FLAG_UNSIGNED
;
4519 case DW_ATE_complex_float
:
4520 code
= TYPE_CODE_COMPLEX
;
4523 code
= TYPE_CODE_FLT
;
4526 case DW_ATE_signed_char
:
4528 case DW_ATE_unsigned
:
4529 case DW_ATE_unsigned_char
:
4530 type_flags
|= TYPE_FLAG_UNSIGNED
;
4533 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
4534 dwarf_type_encoding_name (encoding
));
4537 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
4538 if (encoding
== DW_ATE_address
)
4539 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
,
4541 else if (encoding
== DW_ATE_complex_float
)
4544 TYPE_TARGET_TYPE (type
)
4545 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
, cu
);
4546 else if (size
== 16)
4547 TYPE_TARGET_TYPE (type
)
4548 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
4550 TYPE_TARGET_TYPE (type
)
4551 = dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
4556 type
= dwarf_base_type (encoding
, size
, cu
);
4561 /* Read the given DW_AT_subrange DIE. */
4564 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4566 struct type
*base_type
;
4567 struct type
*range_type
;
4568 struct attribute
*attr
;
4572 /* If we have already decoded this die, then nothing more to do. */
4576 base_type
= die_type (die
, cu
);
4577 if (base_type
== NULL
)
4579 complaint (&symfile_complaints
,
4580 "DW_AT_type missing from DW_TAG_subrange_type");
4584 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
4585 base_type
= alloc_type (NULL
);
4587 if (cu
->language
== language_fortran
)
4589 /* FORTRAN implies a lower bound of 1, if not given. */
4593 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
4595 low
= dwarf2_get_attr_constant_value (attr
, 0);
4597 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
4600 if (attr
->form
== DW_FORM_block1
)
4602 /* GCC encodes arrays with unspecified or dynamic length
4603 with a DW_FORM_block1 attribute.
4604 FIXME: GDB does not yet know how to handle dynamic
4605 arrays properly, treat them as arrays with unspecified
4608 FIXME: jimb/2003-09-22: GDB does not really know
4609 how to handle arrays of unspecified length
4610 either; we just represent them as zero-length
4611 arrays. Choose an appropriate upper bound given
4612 the lower bound we've computed above. */
4616 high
= dwarf2_get_attr_constant_value (attr
, 1);
4619 range_type
= create_range_type (NULL
, base_type
, low
, high
);
4621 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4622 if (attr
&& DW_STRING (attr
))
4623 TYPE_NAME (range_type
) = DW_STRING (attr
);
4625 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4627 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
4629 die
->type
= range_type
;
4633 /* Read a whole compilation unit into a linked list of dies. */
4635 static struct die_info
*
4636 read_comp_unit (char *info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
4638 /* Reset die reference table; we are
4639 building new ones now. */
4640 dwarf2_empty_hash_tables ();
4642 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
4645 /* Read a single die and all its descendents. Set the die's sibling
4646 field to NULL; set other fields in the die correctly, and set all
4647 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4648 location of the info_ptr after reading all of those dies. PARENT
4649 is the parent of the die in question. */
4651 static struct die_info
*
4652 read_die_and_children (char *info_ptr
, bfd
*abfd
,
4653 struct dwarf2_cu
*cu
,
4654 char **new_info_ptr
,
4655 struct die_info
*parent
)
4657 struct die_info
*die
;
4661 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
4662 store_in_ref_table (die
->offset
, die
);
4666 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
4672 *new_info_ptr
= cur_ptr
;
4675 die
->sibling
= NULL
;
4676 die
->parent
= parent
;
4680 /* Read a die, all of its descendents, and all of its siblings; set
4681 all of the fields of all of the dies correctly. Arguments are as
4682 in read_die_and_children. */
4684 static struct die_info
*
4685 read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
4686 struct dwarf2_cu
*cu
,
4687 char **new_info_ptr
,
4688 struct die_info
*parent
)
4690 struct die_info
*first_die
, *last_sibling
;
4694 first_die
= last_sibling
= NULL
;
4698 struct die_info
*die
4699 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
4707 last_sibling
->sibling
= die
;
4712 *new_info_ptr
= cur_ptr
;
4722 /* Free a linked list of dies. */
4725 free_die_list (struct die_info
*dies
)
4727 struct die_info
*die
, *next
;
4732 if (die
->child
!= NULL
)
4733 free_die_list (die
->child
);
4734 next
= die
->sibling
;
4742 do_free_die_list_cleanup (void *dies
)
4744 free_die_list (dies
);
4747 static struct cleanup
*
4748 make_cleanup_free_die_list (struct die_info
*dies
)
4750 return make_cleanup (do_free_die_list_cleanup
, dies
);
4754 /* Read the contents of the section at OFFSET and of size SIZE from the
4755 object file specified by OBJFILE into the objfile_obstack and return it. */
4758 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
4760 bfd
*abfd
= objfile
->obfd
;
4762 bfd_size_type size
= bfd_get_section_size (sectp
);
4767 buf
= (char *) obstack_alloc (&objfile
->objfile_obstack
, size
);
4769 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
4773 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
4774 || bfd_bread (buf
, size
, abfd
) != size
)
4775 error ("Dwarf Error: Can't read DWARF data from '%s'",
4776 bfd_get_filename (abfd
));
4781 /* In DWARF version 2, the description of the debugging information is
4782 stored in a separate .debug_abbrev section. Before we read any
4783 dies from a section we read in all abbreviations and install them
4784 in a hash table. This function also sets flags in CU describing
4785 the data found in the abbrev table. */
4788 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
4790 struct comp_unit_head
*cu_header
= &cu
->header
;
4792 struct abbrev_info
*cur_abbrev
;
4793 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
4794 unsigned int abbrev_form
, hash_number
;
4795 struct attr_abbrev
*cur_attrs
;
4796 unsigned int allocated_attrs
;
4798 /* Initialize dwarf2 abbrevs */
4799 obstack_init (&cu
->abbrev_obstack
);
4800 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
4802 * sizeof (struct abbrev_info
*)));
4803 memset (cu
->dwarf2_abbrevs
, 0,
4804 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
4806 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
4807 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4808 abbrev_ptr
+= bytes_read
;
4810 allocated_attrs
= ATTR_ALLOC_CHUNK
;
4811 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
4813 /* loop until we reach an abbrev number of 0 */
4814 while (abbrev_number
)
4816 cur_abbrev
= dwarf_alloc_abbrev (cu
);
4818 /* read in abbrev header */
4819 cur_abbrev
->number
= abbrev_number
;
4820 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4821 abbrev_ptr
+= bytes_read
;
4822 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
4825 if (cur_abbrev
->tag
== DW_TAG_namespace
)
4826 cu
->has_namespace_info
= 1;
4828 /* now read in declarations */
4829 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4830 abbrev_ptr
+= bytes_read
;
4831 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4832 abbrev_ptr
+= bytes_read
;
4835 if (cur_abbrev
->num_attrs
== allocated_attrs
)
4837 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
4839 = xrealloc (cur_attrs
, (allocated_attrs
4840 * sizeof (struct attr_abbrev
)));
4843 /* Record whether this compilation unit might have
4844 inter-compilation-unit references. If we don't know what form
4845 this attribute will have, then it might potentially be a
4846 DW_FORM_ref_addr, so we conservatively expect inter-CU
4849 if (abbrev_form
== DW_FORM_ref_addr
4850 || abbrev_form
== DW_FORM_indirect
)
4851 cu
->has_form_ref_addr
= 1;
4853 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
4854 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
4855 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4856 abbrev_ptr
+= bytes_read
;
4857 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4858 abbrev_ptr
+= bytes_read
;
4861 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
4862 (cur_abbrev
->num_attrs
4863 * sizeof (struct attr_abbrev
)));
4864 memcpy (cur_abbrev
->attrs
, cur_attrs
,
4865 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
4867 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
4868 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
4869 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
4871 /* Get next abbreviation.
4872 Under Irix6 the abbreviations for a compilation unit are not
4873 always properly terminated with an abbrev number of 0.
4874 Exit loop if we encounter an abbreviation which we have
4875 already read (which means we are about to read the abbreviations
4876 for the next compile unit) or if the end of the abbreviation
4877 table is reached. */
4878 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
4879 >= dwarf2_per_objfile
->abbrev_size
)
4881 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4882 abbrev_ptr
+= bytes_read
;
4883 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
4890 /* Release the memory used by the abbrev table for a compilation unit. */
4893 dwarf2_free_abbrev_table (void *ptr_to_cu
)
4895 struct dwarf2_cu
*cu
= ptr_to_cu
;
4897 obstack_free (&cu
->abbrev_obstack
, NULL
);
4898 cu
->dwarf2_abbrevs
= NULL
;
4901 /* Lookup an abbrev_info structure in the abbrev hash table. */
4903 static struct abbrev_info
*
4904 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
4906 unsigned int hash_number
;
4907 struct abbrev_info
*abbrev
;
4909 hash_number
= number
% ABBREV_HASH_SIZE
;
4910 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
4914 if (abbrev
->number
== number
)
4917 abbrev
= abbrev
->next
;
4922 /* Returns nonzero if TAG represents a type that we might generate a partial
4926 is_type_tag_for_partial (int tag
)
4931 /* Some types that would be reasonable to generate partial symbols for,
4932 that we don't at present. */
4933 case DW_TAG_array_type
:
4934 case DW_TAG_file_type
:
4935 case DW_TAG_ptr_to_member_type
:
4936 case DW_TAG_set_type
:
4937 case DW_TAG_string_type
:
4938 case DW_TAG_subroutine_type
:
4940 case DW_TAG_base_type
:
4941 case DW_TAG_class_type
:
4942 case DW_TAG_enumeration_type
:
4943 case DW_TAG_structure_type
:
4944 case DW_TAG_subrange_type
:
4945 case DW_TAG_typedef
:
4946 case DW_TAG_union_type
:
4953 /* Load all DIEs that are interesting for partial symbols into memory. */
4955 static struct partial_die_info
*
4956 load_partial_dies (bfd
*abfd
, char *info_ptr
, int building_psymtab
,
4957 struct dwarf2_cu
*cu
)
4959 struct partial_die_info
*part_die
;
4960 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
4961 struct abbrev_info
*abbrev
;
4962 unsigned int bytes_read
;
4964 int nesting_level
= 1;
4970 = htab_create_alloc_ex (cu
->header
.length
/ 12,
4974 &cu
->comp_unit_obstack
,
4975 hashtab_obstack_allocate
,
4976 dummy_obstack_deallocate
);
4978 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
4979 sizeof (struct partial_die_info
));
4983 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4985 /* A NULL abbrev means the end of a series of children. */
4988 if (--nesting_level
== 0)
4990 /* PART_DIE was probably the last thing allocated on the
4991 comp_unit_obstack, so we could call obstack_free
4992 here. We don't do that because the waste is small,
4993 and will be cleaned up when we're done with this
4994 compilation unit. This way, we're also more robust
4995 against other users of the comp_unit_obstack. */
4998 info_ptr
+= bytes_read
;
4999 last_die
= parent_die
;
5000 parent_die
= parent_die
->die_parent
;
5004 /* Check whether this DIE is interesting enough to save. */
5005 if (!is_type_tag_for_partial (abbrev
->tag
)
5006 && abbrev
->tag
!= DW_TAG_enumerator
5007 && abbrev
->tag
!= DW_TAG_subprogram
5008 && abbrev
->tag
!= DW_TAG_variable
5009 && abbrev
->tag
!= DW_TAG_namespace
)
5011 /* Otherwise we skip to the next sibling, if any. */
5012 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5016 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5017 abfd
, info_ptr
, cu
);
5019 /* This two-pass algorithm for processing partial symbols has a
5020 high cost in cache pressure. Thus, handle some simple cases
5021 here which cover the majority of C partial symbols. DIEs
5022 which neither have specification tags in them, nor could have
5023 specification tags elsewhere pointing at them, can simply be
5024 processed and discarded.
5026 This segment is also optional; scan_partial_symbols and
5027 add_partial_symbol will handle these DIEs if we chain
5028 them in normally. When compilers which do not emit large
5029 quantities of duplicate debug information are more common,
5030 this code can probably be removed. */
5032 /* Any complete simple types at the top level (pretty much all
5033 of them, for a language without namespaces), can be processed
5035 if (parent_die
== NULL
5036 && part_die
->has_specification
== 0
5037 && part_die
->is_declaration
== 0
5038 && (part_die
->tag
== DW_TAG_typedef
5039 || part_die
->tag
== DW_TAG_base_type
5040 || part_die
->tag
== DW_TAG_subrange_type
))
5042 if (building_psymtab
&& part_die
->name
!= NULL
)
5043 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5044 VAR_DOMAIN
, LOC_TYPEDEF
,
5045 &cu
->objfile
->static_psymbols
,
5046 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5047 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5051 /* If we're at the second level, and we're an enumerator, and
5052 our parent has no specification (meaning possibly lives in a
5053 namespace elsewhere), then we can add the partial symbol now
5054 instead of queueing it. */
5055 if (part_die
->tag
== DW_TAG_enumerator
5056 && parent_die
!= NULL
5057 && parent_die
->die_parent
== NULL
5058 && parent_die
->tag
== DW_TAG_enumeration_type
5059 && parent_die
->has_specification
== 0)
5061 if (part_die
->name
== NULL
)
5062 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
5063 else if (building_psymtab
)
5064 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5065 VAR_DOMAIN
, LOC_CONST
,
5066 (cu
->language
== language_cplus
5067 || cu
->language
== language_java
)
5068 ? &cu
->objfile
->global_psymbols
5069 : &cu
->objfile
->static_psymbols
,
5070 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5072 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5076 /* We'll save this DIE so link it in. */
5077 part_die
->die_parent
= parent_die
;
5078 part_die
->die_sibling
= NULL
;
5079 part_die
->die_child
= NULL
;
5081 if (last_die
&& last_die
== parent_die
)
5082 last_die
->die_child
= part_die
;
5084 last_die
->die_sibling
= part_die
;
5086 last_die
= part_die
;
5088 if (first_die
== NULL
)
5089 first_die
= part_die
;
5091 /* Maybe add the DIE to the hash table. Not all DIEs that we
5092 find interesting need to be in the hash table, because we
5093 also have the parent/sibling/child chains; only those that we
5094 might refer to by offset later during partial symbol reading.
5096 For now this means things that might have be the target of a
5097 DW_AT_specification, DW_AT_abstract_origin, or
5098 DW_AT_extension. DW_AT_extension will refer only to
5099 namespaces; DW_AT_abstract_origin refers to functions (and
5100 many things under the function DIE, but we do not recurse
5101 into function DIEs during partial symbol reading) and
5102 possibly variables as well; DW_AT_specification refers to
5103 declarations. Declarations ought to have the DW_AT_declaration
5104 flag. It happens that GCC forgets to put it in sometimes, but
5105 only for functions, not for types.
5107 Adding more things than necessary to the hash table is harmless
5108 except for the performance cost. Adding too few will result in
5109 internal errors in find_partial_die. */
5111 if (abbrev
->tag
== DW_TAG_subprogram
5112 || abbrev
->tag
== DW_TAG_variable
5113 || abbrev
->tag
== DW_TAG_namespace
5114 || part_die
->is_declaration
)
5118 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5119 part_die
->offset
, INSERT
);
5123 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5124 sizeof (struct partial_die_info
));
5126 /* For some DIEs we want to follow their children (if any). For C
5127 we have no reason to follow the children of structures; for other
5128 languages we have to, both so that we can get at method physnames
5129 to infer fully qualified class names, and for DW_AT_specification. */
5130 if (last_die
->has_children
5131 && (last_die
->tag
== DW_TAG_namespace
5132 || last_die
->tag
== DW_TAG_enumeration_type
5133 || (cu
->language
!= language_c
5134 && (last_die
->tag
== DW_TAG_class_type
5135 || last_die
->tag
== DW_TAG_structure_type
5136 || last_die
->tag
== DW_TAG_union_type
))))
5139 parent_die
= last_die
;
5143 /* Otherwise we skip to the next sibling, if any. */
5144 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5146 /* Back to the top, do it again. */
5150 /* Read a minimal amount of information into the minimal die structure. */
5153 read_partial_die (struct partial_die_info
*part_die
,
5154 struct abbrev_info
*abbrev
,
5155 unsigned int abbrev_len
, bfd
*abfd
,
5156 char *info_ptr
, struct dwarf2_cu
*cu
)
5158 unsigned int bytes_read
, i
;
5159 struct attribute attr
;
5160 int has_low_pc_attr
= 0;
5161 int has_high_pc_attr
= 0;
5163 memset (part_die
, 0, sizeof (struct partial_die_info
));
5165 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5167 info_ptr
+= abbrev_len
;
5172 part_die
->tag
= abbrev
->tag
;
5173 part_die
->has_children
= abbrev
->has_children
;
5175 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5177 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5179 /* Store the data if it is of an attribute we want to keep in a
5180 partial symbol table. */
5185 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5186 if (part_die
->name
== NULL
)
5187 part_die
->name
= DW_STRING (&attr
);
5189 case DW_AT_comp_dir
:
5190 if (part_die
->dirname
== NULL
)
5191 part_die
->dirname
= DW_STRING (&attr
);
5193 case DW_AT_MIPS_linkage_name
:
5194 part_die
->name
= DW_STRING (&attr
);
5197 has_low_pc_attr
= 1;
5198 part_die
->lowpc
= DW_ADDR (&attr
);
5201 has_high_pc_attr
= 1;
5202 part_die
->highpc
= DW_ADDR (&attr
);
5204 case DW_AT_location
:
5205 /* Support the .debug_loc offsets */
5206 if (attr_form_is_block (&attr
))
5208 part_die
->locdesc
= DW_BLOCK (&attr
);
5210 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
5212 dwarf2_complex_location_expr_complaint ();
5216 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5217 "partial symbol information");
5220 case DW_AT_language
:
5221 part_die
->language
= DW_UNSND (&attr
);
5223 case DW_AT_external
:
5224 part_die
->is_external
= DW_UNSND (&attr
);
5226 case DW_AT_declaration
:
5227 part_die
->is_declaration
= DW_UNSND (&attr
);
5230 part_die
->has_type
= 1;
5232 case DW_AT_abstract_origin
:
5233 case DW_AT_specification
:
5234 case DW_AT_extension
:
5235 part_die
->has_specification
= 1;
5236 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
5239 /* Ignore absolute siblings, they might point outside of
5240 the current compile unit. */
5241 if (attr
.form
== DW_FORM_ref_addr
)
5242 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
5244 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
5245 + dwarf2_get_ref_die_offset (&attr
, cu
);
5247 case DW_AT_stmt_list
:
5248 part_die
->has_stmt_list
= 1;
5249 part_die
->line_offset
= DW_UNSND (&attr
);
5256 /* When using the GNU linker, .gnu.linkonce. sections are used to
5257 eliminate duplicate copies of functions and vtables and such.
5258 The linker will arbitrarily choose one and discard the others.
5259 The AT_*_pc values for such functions refer to local labels in
5260 these sections. If the section from that file was discarded, the
5261 labels are not in the output, so the relocs get a value of 0.
5262 If this is a discarded function, mark the pc bounds as invalid,
5263 so that GDB will ignore it. */
5264 if (has_low_pc_attr
&& has_high_pc_attr
5265 && part_die
->lowpc
< part_die
->highpc
5266 && (part_die
->lowpc
!= 0
5267 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
5268 part_die
->has_pc_info
= 1;
5272 /* Find a cached partial DIE at OFFSET in CU. */
5274 static struct partial_die_info
*
5275 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
5277 struct partial_die_info
*lookup_die
= NULL
;
5278 struct partial_die_info part_die
;
5280 part_die
.offset
= offset
;
5281 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
5283 if (lookup_die
== NULL
)
5284 internal_error (__FILE__
, __LINE__
,
5285 "could not find partial DIE in cache\n");
5290 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
5292 static struct partial_die_info
*
5293 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
,
5294 struct dwarf2_cu
**target_cu
)
5296 struct dwarf2_per_cu_data
*per_cu
;
5298 if (offset
>= cu
->header
.offset
5299 && offset
< cu
->header
.offset
+ cu
->header
.length
)
5302 return find_partial_die_in_comp_unit (offset
, cu
);
5305 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
5307 /* If this offset isn't pointing into a known compilation unit,
5308 the debug information is probably corrupted. */
5310 error ("Dwarf Error: could not find partial DIE containing "
5311 "offset 0x%lx [in module %s]",
5312 (long) offset
, bfd_get_filename (cu
->objfile
->obfd
));
5314 if (per_cu
->cu
== NULL
)
5316 load_comp_unit (per_cu
, cu
->objfile
);
5317 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5318 dwarf2_per_objfile
->read_in_chain
= per_cu
;
5321 per_cu
->cu
->last_used
= 0;
5322 *target_cu
= per_cu
->cu
;
5323 return find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5326 /* Adjust PART_DIE before generating a symbol for it. This function
5327 may set the is_external flag or change the DIE's name. */
5330 fixup_partial_die (struct partial_die_info
*part_die
,
5331 struct dwarf2_cu
*cu
)
5333 /* If we found a reference attribute and the DIE has no name, try
5334 to find a name in the referred to DIE. */
5336 if (part_die
->name
== NULL
&& part_die
->has_specification
)
5338 struct partial_die_info
*spec_die
;
5339 struct dwarf2_cu
*spec_cu
;
5341 spec_die
= find_partial_die (part_die
->spec_offset
, cu
, &spec_cu
);
5343 fixup_partial_die (spec_die
, spec_cu
);
5347 part_die
->name
= spec_die
->name
;
5349 /* Copy DW_AT_external attribute if it is set. */
5350 if (spec_die
->is_external
)
5351 part_die
->is_external
= spec_die
->is_external
;
5355 /* Set default names for some unnamed DIEs. */
5356 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
5357 || part_die
->tag
== DW_TAG_class_type
))
5358 part_die
->name
= "(anonymous class)";
5360 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
5361 part_die
->name
= "(anonymous namespace)";
5363 if (part_die
->tag
== DW_TAG_structure_type
5364 || part_die
->tag
== DW_TAG_class_type
5365 || part_die
->tag
== DW_TAG_union_type
)
5366 guess_structure_name (part_die
, cu
);
5369 /* Read the die from the .debug_info section buffer. Set DIEP to
5370 point to a newly allocated die with its information, except for its
5371 child, sibling, and parent fields. Set HAS_CHILDREN to tell
5372 whether the die has children or not. */
5375 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
5376 struct dwarf2_cu
*cu
, int *has_children
)
5378 unsigned int abbrev_number
, bytes_read
, i
, offset
;
5379 struct abbrev_info
*abbrev
;
5380 struct die_info
*die
;
5382 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5383 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5384 info_ptr
+= bytes_read
;
5387 die
= dwarf_alloc_die ();
5389 die
->abbrev
= abbrev_number
;
5396 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
5399 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
5401 bfd_get_filename (abfd
));
5403 die
= dwarf_alloc_die ();
5404 die
->offset
= offset
;
5405 die
->tag
= abbrev
->tag
;
5406 die
->abbrev
= abbrev_number
;
5409 die
->num_attrs
= abbrev
->num_attrs
;
5410 die
->attrs
= (struct attribute
*)
5411 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
5413 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5415 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
5416 abfd
, info_ptr
, cu
);
5420 *has_children
= abbrev
->has_children
;
5424 /* Read an attribute value described by an attribute form. */
5427 read_attribute_value (struct attribute
*attr
, unsigned form
,
5428 bfd
*abfd
, char *info_ptr
,
5429 struct dwarf2_cu
*cu
)
5431 struct comp_unit_head
*cu_header
= &cu
->header
;
5432 unsigned int bytes_read
;
5433 struct dwarf_block
*blk
;
5439 case DW_FORM_ref_addr
:
5440 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
5441 info_ptr
+= bytes_read
;
5443 case DW_FORM_block2
:
5444 blk
= dwarf_alloc_block (cu
);
5445 blk
->size
= read_2_bytes (abfd
, info_ptr
);
5447 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5448 info_ptr
+= blk
->size
;
5449 DW_BLOCK (attr
) = blk
;
5451 case DW_FORM_block4
:
5452 blk
= dwarf_alloc_block (cu
);
5453 blk
->size
= read_4_bytes (abfd
, info_ptr
);
5455 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5456 info_ptr
+= blk
->size
;
5457 DW_BLOCK (attr
) = blk
;
5460 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
5464 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
5468 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
5471 case DW_FORM_string
:
5472 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
5473 info_ptr
+= bytes_read
;
5476 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
5478 info_ptr
+= bytes_read
;
5481 blk
= dwarf_alloc_block (cu
);
5482 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5483 info_ptr
+= bytes_read
;
5484 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5485 info_ptr
+= blk
->size
;
5486 DW_BLOCK (attr
) = blk
;
5488 case DW_FORM_block1
:
5489 blk
= dwarf_alloc_block (cu
);
5490 blk
->size
= read_1_byte (abfd
, info_ptr
);
5492 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5493 info_ptr
+= blk
->size
;
5494 DW_BLOCK (attr
) = blk
;
5497 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5501 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5505 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
5506 info_ptr
+= bytes_read
;
5509 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5510 info_ptr
+= bytes_read
;
5513 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5517 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
5521 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
5525 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
5528 case DW_FORM_ref_udata
:
5529 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5530 info_ptr
+= bytes_read
;
5532 case DW_FORM_indirect
:
5533 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5534 info_ptr
+= bytes_read
;
5535 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
5538 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
5539 dwarf_form_name (form
),
5540 bfd_get_filename (abfd
));
5545 /* Read an attribute described by an abbreviated attribute. */
5548 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
5549 bfd
*abfd
, char *info_ptr
, struct dwarf2_cu
*cu
)
5551 attr
->name
= abbrev
->name
;
5552 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
5555 /* read dwarf information from a buffer */
5558 read_1_byte (bfd
*abfd
, char *buf
)
5560 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5564 read_1_signed_byte (bfd
*abfd
, char *buf
)
5566 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
5570 read_2_bytes (bfd
*abfd
, char *buf
)
5572 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
5576 read_2_signed_bytes (bfd
*abfd
, char *buf
)
5578 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
5582 read_4_bytes (bfd
*abfd
, char *buf
)
5584 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5588 read_4_signed_bytes (bfd
*abfd
, char *buf
)
5590 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
5593 static unsigned long
5594 read_8_bytes (bfd
*abfd
, char *buf
)
5596 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5600 read_address (bfd
*abfd
, char *buf
, struct dwarf2_cu
*cu
, int *bytes_read
)
5602 struct comp_unit_head
*cu_header
= &cu
->header
;
5603 CORE_ADDR retval
= 0;
5605 if (cu_header
->signed_addr_p
)
5607 switch (cu_header
->addr_size
)
5610 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
5613 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
5616 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
5619 internal_error (__FILE__
, __LINE__
,
5620 "read_address: bad switch, signed [in module %s]",
5621 bfd_get_filename (abfd
));
5626 switch (cu_header
->addr_size
)
5629 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
5632 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5635 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5638 internal_error (__FILE__
, __LINE__
,
5639 "read_address: bad switch, unsigned [in module %s]",
5640 bfd_get_filename (abfd
));
5644 *bytes_read
= cu_header
->addr_size
;
5648 /* Read the initial length from a section. The (draft) DWARF 3
5649 specification allows the initial length to take up either 4 bytes
5650 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
5651 bytes describe the length and all offsets will be 8 bytes in length
5654 An older, non-standard 64-bit format is also handled by this
5655 function. The older format in question stores the initial length
5656 as an 8-byte quantity without an escape value. Lengths greater
5657 than 2^32 aren't very common which means that the initial 4 bytes
5658 is almost always zero. Since a length value of zero doesn't make
5659 sense for the 32-bit format, this initial zero can be considered to
5660 be an escape value which indicates the presence of the older 64-bit
5661 format. As written, the code can't detect (old format) lengths
5662 greater than 4GB. If it becomes necessary to handle lengths somewhat
5663 larger than 4GB, we could allow other small values (such as the
5664 non-sensical values of 1, 2, and 3) to also be used as escape values
5665 indicating the presence of the old format.
5667 The value returned via bytes_read should be used to increment
5668 the relevant pointer after calling read_initial_length().
5670 As a side effect, this function sets the fields initial_length_size
5671 and offset_size in cu_header to the values appropriate for the
5672 length field. (The format of the initial length field determines
5673 the width of file offsets to be fetched later with fetch_offset().)
5675 [ Note: read_initial_length() and read_offset() are based on the
5676 document entitled "DWARF Debugging Information Format", revision
5677 3, draft 8, dated November 19, 2001. This document was obtained
5680 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
5682 This document is only a draft and is subject to change. (So beware.)
5684 Details regarding the older, non-standard 64-bit format were
5685 determined empirically by examining 64-bit ELF files produced
5686 by the SGI toolchain on an IRIX 6.5 machine.
5688 - Kevin, July 16, 2002
5692 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
5697 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5699 if (retval
== 0xffffffff)
5701 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
5703 if (cu_header
!= NULL
)
5705 cu_header
->initial_length_size
= 12;
5706 cu_header
->offset_size
= 8;
5709 else if (retval
== 0)
5711 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
5713 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5715 if (cu_header
!= NULL
)
5717 cu_header
->initial_length_size
= 8;
5718 cu_header
->offset_size
= 8;
5724 if (cu_header
!= NULL
)
5726 cu_header
->initial_length_size
= 4;
5727 cu_header
->offset_size
= 4;
5734 /* Read an offset from the data stream. The size of the offset is
5735 given by cu_header->offset_size. */
5738 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
5743 switch (cu_header
->offset_size
)
5746 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5750 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5754 internal_error (__FILE__
, __LINE__
,
5755 "read_offset: bad switch [in module %s]",
5756 bfd_get_filename (abfd
));
5763 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
5765 /* If the size of a host char is 8 bits, we can return a pointer
5766 to the buffer, otherwise we have to copy the data to a buffer
5767 allocated on the temporary obstack. */
5768 gdb_assert (HOST_CHAR_BIT
== 8);
5773 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5775 /* If the size of a host char is 8 bits, we can return a pointer
5776 to the string, otherwise we have to copy the string to a buffer
5777 allocated on the temporary obstack. */
5778 gdb_assert (HOST_CHAR_BIT
== 8);
5781 *bytes_read_ptr
= 1;
5784 *bytes_read_ptr
= strlen (buf
) + 1;
5789 read_indirect_string (bfd
*abfd
, char *buf
,
5790 const struct comp_unit_head
*cu_header
,
5791 unsigned int *bytes_read_ptr
)
5793 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
5794 (int *) bytes_read_ptr
);
5796 if (dwarf2_per_objfile
->str_buffer
== NULL
)
5798 error ("DW_FORM_strp used without .debug_str section [in module %s]",
5799 bfd_get_filename (abfd
));
5802 if (str_offset
>= dwarf2_per_objfile
->str_size
)
5804 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
5805 bfd_get_filename (abfd
));
5808 gdb_assert (HOST_CHAR_BIT
== 8);
5809 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
5811 return dwarf2_per_objfile
->str_buffer
+ str_offset
;
5814 static unsigned long
5815 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5817 unsigned long result
;
5818 unsigned int num_read
;
5828 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5831 result
|= ((unsigned long)(byte
& 127) << shift
);
5832 if ((byte
& 128) == 0)
5838 *bytes_read_ptr
= num_read
;
5843 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5846 int i
, shift
, size
, num_read
;
5856 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5859 result
|= ((long)(byte
& 127) << shift
);
5861 if ((byte
& 128) == 0)
5866 if ((shift
< size
) && (byte
& 0x40))
5868 result
|= -(1 << shift
);
5870 *bytes_read_ptr
= num_read
;
5874 /* Return a pointer to just past the end of an LEB128 number in BUF. */
5877 skip_leb128 (bfd
*abfd
, char *buf
)
5883 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5885 if ((byte
& 128) == 0)
5891 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
5897 cu
->language
= language_c
;
5899 case DW_LANG_C_plus_plus
:
5900 cu
->language
= language_cplus
;
5902 case DW_LANG_Fortran77
:
5903 case DW_LANG_Fortran90
:
5904 case DW_LANG_Fortran95
:
5905 cu
->language
= language_fortran
;
5907 case DW_LANG_Mips_Assembler
:
5908 cu
->language
= language_asm
;
5911 cu
->language
= language_java
;
5915 case DW_LANG_Cobol74
:
5916 case DW_LANG_Cobol85
:
5917 case DW_LANG_Pascal83
:
5918 case DW_LANG_Modula2
:
5920 cu
->language
= language_minimal
;
5923 cu
->language_defn
= language_def (cu
->language
);
5926 /* Return the named attribute or NULL if not there. */
5928 static struct attribute
*
5929 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
5932 struct attribute
*spec
= NULL
;
5934 for (i
= 0; i
< die
->num_attrs
; ++i
)
5936 if (die
->attrs
[i
].name
== name
)
5938 return &die
->attrs
[i
];
5940 if (die
->attrs
[i
].name
== DW_AT_specification
5941 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
5942 spec
= &die
->attrs
[i
];
5946 struct die_info
*ref_die
=
5947 follow_die_ref (dwarf2_get_ref_die_offset (spec
, cu
));
5950 return dwarf2_attr (ref_die
, name
, cu
);
5956 /* Return non-zero iff the attribute NAME is defined for the given DIE,
5957 and holds a non-zero value. This function should only be used for
5958 DW_FORM_flag attributes. */
5961 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
5963 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
5965 return (attr
&& DW_UNSND (attr
));
5969 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
5971 /* A DIE is a declaration if it has a DW_AT_declaration attribute
5972 which value is non-zero. However, we have to be careful with
5973 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
5974 (via dwarf2_flag_true_p) follows this attribute. So we may
5975 end up accidently finding a declaration attribute that belongs
5976 to a different DIE referenced by the specification attribute,
5977 even though the given DIE does not have a declaration attribute. */
5978 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
5979 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
5982 /* Return the die giving the specification for DIE, if there is
5985 static struct die_info
*
5986 die_specification (struct die_info
*die
, struct dwarf2_cu
*cu
)
5988 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
, cu
);
5990 if (spec_attr
== NULL
)
5993 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr
, cu
));
5996 /* Free the line_header structure *LH, and any arrays and strings it
5999 free_line_header (struct line_header
*lh
)
6001 if (lh
->standard_opcode_lengths
)
6002 xfree (lh
->standard_opcode_lengths
);
6004 /* Remember that all the lh->file_names[i].name pointers are
6005 pointers into debug_line_buffer, and don't need to be freed. */
6007 xfree (lh
->file_names
);
6009 /* Similarly for the include directory names. */
6010 if (lh
->include_dirs
)
6011 xfree (lh
->include_dirs
);
6017 /* Add an entry to LH's include directory table. */
6019 add_include_dir (struct line_header
*lh
, char *include_dir
)
6021 /* Grow the array if necessary. */
6022 if (lh
->include_dirs_size
== 0)
6024 lh
->include_dirs_size
= 1; /* for testing */
6025 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6026 * sizeof (*lh
->include_dirs
));
6028 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6030 lh
->include_dirs_size
*= 2;
6031 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6032 (lh
->include_dirs_size
6033 * sizeof (*lh
->include_dirs
)));
6036 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6040 /* Add an entry to LH's file name table. */
6042 add_file_name (struct line_header
*lh
,
6044 unsigned int dir_index
,
6045 unsigned int mod_time
,
6046 unsigned int length
)
6048 struct file_entry
*fe
;
6050 /* Grow the array if necessary. */
6051 if (lh
->file_names_size
== 0)
6053 lh
->file_names_size
= 1; /* for testing */
6054 lh
->file_names
= xmalloc (lh
->file_names_size
6055 * sizeof (*lh
->file_names
));
6057 else if (lh
->num_file_names
>= lh
->file_names_size
)
6059 lh
->file_names_size
*= 2;
6060 lh
->file_names
= xrealloc (lh
->file_names
,
6061 (lh
->file_names_size
6062 * sizeof (*lh
->file_names
)));
6065 fe
= &lh
->file_names
[lh
->num_file_names
++];
6067 fe
->dir_index
= dir_index
;
6068 fe
->mod_time
= mod_time
;
6069 fe
->length
= length
;
6074 /* Read the statement program header starting at OFFSET in
6075 .debug_line, according to the endianness of ABFD. Return a pointer
6076 to a struct line_header, allocated using xmalloc.
6078 NOTE: the strings in the include directory and file name tables of
6079 the returned object point into debug_line_buffer, and must not be
6081 static struct line_header
*
6082 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6083 struct dwarf2_cu
*cu
)
6085 struct cleanup
*back_to
;
6086 struct line_header
*lh
;
6090 char *cur_dir
, *cur_file
;
6092 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6094 complaint (&symfile_complaints
, "missing .debug_line section");
6098 /* Make sure that at least there's room for the total_length field. That
6099 could be 12 bytes long, but we're just going to fudge that. */
6100 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6102 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6106 lh
= xmalloc (sizeof (*lh
));
6107 memset (lh
, 0, sizeof (*lh
));
6108 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6111 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6113 /* read in the header */
6114 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
6115 line_ptr
+= bytes_read
;
6116 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6117 + dwarf2_per_objfile
->line_size
))
6119 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6122 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6123 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6125 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6126 line_ptr
+= bytes_read
;
6127 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6129 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6131 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
6133 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
6135 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
6137 lh
->standard_opcode_lengths
6138 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
6140 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
6141 for (i
= 1; i
< lh
->opcode_base
; ++i
)
6143 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
6147 /* Read directory table */
6148 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6150 line_ptr
+= bytes_read
;
6151 add_include_dir (lh
, cur_dir
);
6153 line_ptr
+= bytes_read
;
6155 /* Read file name table */
6156 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6158 unsigned int dir_index
, mod_time
, length
;
6160 line_ptr
+= bytes_read
;
6161 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6162 line_ptr
+= bytes_read
;
6163 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6164 line_ptr
+= bytes_read
;
6165 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6166 line_ptr
+= bytes_read
;
6168 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6170 line_ptr
+= bytes_read
;
6171 lh
->statement_program_start
= line_ptr
;
6173 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
6174 + dwarf2_per_objfile
->line_size
))
6175 complaint (&symfile_complaints
,
6176 "line number info header doesn't fit in `.debug_line' section");
6178 discard_cleanups (back_to
);
6182 /* This function exists to work around a bug in certain compilers
6183 (particularly GCC 2.95), in which the first line number marker of a
6184 function does not show up until after the prologue, right before
6185 the second line number marker. This function shifts ADDRESS down
6186 to the beginning of the function if necessary, and is called on
6187 addresses passed to record_line. */
6190 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
6192 struct function_range
*fn
;
6194 /* Find the function_range containing address. */
6199 cu
->cached_fn
= cu
->first_fn
;
6203 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6209 while (fn
&& fn
!= cu
->cached_fn
)
6210 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6220 if (address
!= fn
->lowpc
)
6221 complaint (&symfile_complaints
,
6222 "misplaced first line number at 0x%lx for '%s'",
6223 (unsigned long) address
, fn
->name
);
6228 /* Decode the Line Number Program (LNP) for the given line_header
6229 structure and CU. The actual information extracted and the type
6230 of structures created from the LNP depends on the value of PST.
6232 1. If PST is NULL, then this procedure uses the data from the program
6233 to create all necessary symbol tables, and their linetables.
6234 The compilation directory of the file is passed in COMP_DIR,
6235 and must not be NULL.
6237 2. If PST is not NULL, this procedure reads the program to determine
6238 the list of files included by the unit represented by PST, and
6239 builds all the associated partial symbol tables. In this case,
6240 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
6241 is not used to compute the full name of the symtab, and therefore
6242 omitting it when building the partial symtab does not introduce
6243 the potential for inconsistency - a partial symtab and its associated
6244 symbtab having a different fullname -). */
6247 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
6248 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
6252 unsigned int bytes_read
;
6253 unsigned char op_code
, extended_op
, adj_opcode
;
6255 struct objfile
*objfile
= cu
->objfile
;
6256 const int decode_for_pst_p
= (pst
!= NULL
);
6258 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6260 line_ptr
= lh
->statement_program_start
;
6261 line_end
= lh
->statement_program_end
;
6263 /* Read the statement sequences until there's nothing left. */
6264 while (line_ptr
< line_end
)
6266 /* state machine registers */
6267 CORE_ADDR address
= 0;
6268 unsigned int file
= 1;
6269 unsigned int line
= 1;
6270 unsigned int column
= 0;
6271 int is_stmt
= lh
->default_is_stmt
;
6272 int basic_block
= 0;
6273 int end_sequence
= 0;
6275 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
6277 /* Start a subfile for the current file of the state machine. */
6278 /* lh->include_dirs and lh->file_names are 0-based, but the
6279 directory and file name numbers in the statement program
6281 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
6284 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6287 dwarf2_start_subfile (fe
->name
, dir
);
6290 /* Decode the table. */
6291 while (!end_sequence
)
6293 op_code
= read_1_byte (abfd
, line_ptr
);
6296 if (op_code
>= lh
->opcode_base
)
6297 { /* Special operand. */
6298 adj_opcode
= op_code
- lh
->opcode_base
;
6299 address
+= (adj_opcode
/ lh
->line_range
)
6300 * lh
->minimum_instruction_length
;
6301 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
6302 lh
->file_names
[file
- 1].included_p
= 1;
6303 if (!decode_for_pst_p
)
6305 /* append row to matrix using current values */
6306 record_line (current_subfile
, line
,
6307 check_cu_functions (address
, cu
));
6311 else switch (op_code
)
6313 case DW_LNS_extended_op
:
6314 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6315 line_ptr
+= bytes_read
;
6316 extended_op
= read_1_byte (abfd
, line_ptr
);
6318 switch (extended_op
)
6320 case DW_LNE_end_sequence
:
6322 lh
->file_names
[file
- 1].included_p
= 1;
6323 if (!decode_for_pst_p
)
6324 record_line (current_subfile
, 0, address
);
6326 case DW_LNE_set_address
:
6327 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
6328 line_ptr
+= bytes_read
;
6329 address
+= baseaddr
;
6331 case DW_LNE_define_file
:
6334 unsigned int dir_index
, mod_time
, length
;
6336 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
6337 line_ptr
+= bytes_read
;
6339 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6340 line_ptr
+= bytes_read
;
6342 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6343 line_ptr
+= bytes_read
;
6345 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6346 line_ptr
+= bytes_read
;
6347 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6351 complaint (&symfile_complaints
,
6352 "mangled .debug_line section");
6357 lh
->file_names
[file
- 1].included_p
= 1;
6358 if (!decode_for_pst_p
)
6359 record_line (current_subfile
, line
,
6360 check_cu_functions (address
, cu
));
6363 case DW_LNS_advance_pc
:
6364 address
+= lh
->minimum_instruction_length
6365 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6366 line_ptr
+= bytes_read
;
6368 case DW_LNS_advance_line
:
6369 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
6370 line_ptr
+= bytes_read
;
6372 case DW_LNS_set_file
:
6374 /* lh->include_dirs and lh->file_names are 0-based,
6375 but the directory and file name numbers in the
6376 statement program are 1-based. */
6377 struct file_entry
*fe
;
6379 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6380 line_ptr
+= bytes_read
;
6381 fe
= &lh
->file_names
[file
- 1];
6383 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6386 if (!decode_for_pst_p
)
6387 dwarf2_start_subfile (fe
->name
, dir
);
6390 case DW_LNS_set_column
:
6391 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6392 line_ptr
+= bytes_read
;
6394 case DW_LNS_negate_stmt
:
6395 is_stmt
= (!is_stmt
);
6397 case DW_LNS_set_basic_block
:
6400 /* Add to the address register of the state machine the
6401 address increment value corresponding to special opcode
6402 255. Ie, this value is scaled by the minimum instruction
6403 length since special opcode 255 would have scaled the
6405 case DW_LNS_const_add_pc
:
6406 address
+= (lh
->minimum_instruction_length
6407 * ((255 - lh
->opcode_base
) / lh
->line_range
));
6409 case DW_LNS_fixed_advance_pc
:
6410 address
+= read_2_bytes (abfd
, line_ptr
);
6414 { /* Unknown standard opcode, ignore it. */
6416 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
6418 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6419 line_ptr
+= bytes_read
;
6426 if (decode_for_pst_p
)
6430 /* Now that we're done scanning the Line Header Program, we can
6431 create the psymtab of each included file. */
6432 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
6433 if (lh
->file_names
[file_index
].included_p
== 1)
6435 char *include_name
= lh
->file_names
[file_index
].name
;
6437 if (strcmp (include_name
, pst
->filename
) != 0)
6438 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
6443 /* Start a subfile for DWARF. FILENAME is the name of the file and
6444 DIRNAME the name of the source directory which contains FILENAME
6445 or NULL if not known.
6446 This routine tries to keep line numbers from identical absolute and
6447 relative file names in a common subfile.
6449 Using the `list' example from the GDB testsuite, which resides in
6450 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
6451 of /srcdir/list0.c yields the following debugging information for list0.c:
6453 DW_AT_name: /srcdir/list0.c
6454 DW_AT_comp_dir: /compdir
6455 files.files[0].name: list0.h
6456 files.files[0].dir: /srcdir
6457 files.files[1].name: list0.c
6458 files.files[1].dir: /srcdir
6460 The line number information for list0.c has to end up in a single
6461 subfile, so that `break /srcdir/list0.c:1' works as expected. */
6464 dwarf2_start_subfile (char *filename
, char *dirname
)
6466 /* If the filename isn't absolute, try to match an existing subfile
6467 with the full pathname. */
6469 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
6471 struct subfile
*subfile
;
6472 char *fullname
= concat (dirname
, "/", filename
, NULL
);
6474 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
6476 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
6478 current_subfile
= subfile
;
6485 start_subfile (filename
, dirname
);
6489 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
6490 struct dwarf2_cu
*cu
)
6492 struct objfile
*objfile
= cu
->objfile
;
6493 struct comp_unit_head
*cu_header
= &cu
->header
;
6495 /* NOTE drow/2003-01-30: There used to be a comment and some special
6496 code here to turn a symbol with DW_AT_external and a
6497 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
6498 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
6499 with some versions of binutils) where shared libraries could have
6500 relocations against symbols in their debug information - the
6501 minimal symbol would have the right address, but the debug info
6502 would not. It's no longer necessary, because we will explicitly
6503 apply relocations when we read in the debug information now. */
6505 /* A DW_AT_location attribute with no contents indicates that a
6506 variable has been optimized away. */
6507 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
6509 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
6513 /* Handle one degenerate form of location expression specially, to
6514 preserve GDB's previous behavior when section offsets are
6515 specified. If this is just a DW_OP_addr then mark this symbol
6518 if (attr_form_is_block (attr
)
6519 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
6520 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
6524 SYMBOL_VALUE_ADDRESS (sym
) =
6525 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
6526 fixup_symbol_section (sym
, objfile
);
6527 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
6528 SYMBOL_SECTION (sym
));
6529 SYMBOL_CLASS (sym
) = LOC_STATIC
;
6533 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
6534 expression evaluator, and use LOC_COMPUTED only when necessary
6535 (i.e. when the value of a register or memory location is
6536 referenced, or a thread-local block, etc.). Then again, it might
6537 not be worthwhile. I'm assuming that it isn't unless performance
6538 or memory numbers show me otherwise. */
6540 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
6541 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
6544 /* Given a pointer to a DWARF information entry, figure out if we need
6545 to make a symbol table entry for it, and if so, create a new entry
6546 and return a pointer to it.
6547 If TYPE is NULL, determine symbol type from the die, otherwise
6548 used the passed type. */
6550 static struct symbol
*
6551 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
6553 struct objfile
*objfile
= cu
->objfile
;
6554 struct symbol
*sym
= NULL
;
6556 struct attribute
*attr
= NULL
;
6557 struct attribute
*attr2
= NULL
;
6560 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6562 if (die
->tag
!= DW_TAG_namespace
)
6563 name
= dwarf2_linkage_name (die
, cu
);
6565 name
= TYPE_NAME (type
);
6569 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
6570 sizeof (struct symbol
));
6571 OBJSTAT (objfile
, n_syms
++);
6572 memset (sym
, 0, sizeof (struct symbol
));
6574 /* Cache this symbol's name and the name's demangled form (if any). */
6575 SYMBOL_LANGUAGE (sym
) = cu
->language
;
6576 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
6578 /* Default assumptions.
6579 Use the passed type or decode it from the die. */
6580 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6581 SYMBOL_CLASS (sym
) = LOC_STATIC
;
6583 SYMBOL_TYPE (sym
) = type
;
6585 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
6586 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
6589 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
6594 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6597 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
6599 SYMBOL_CLASS (sym
) = LOC_LABEL
;
6601 case DW_TAG_subprogram
:
6602 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
6604 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
6605 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6606 if (attr2
&& (DW_UNSND (attr2
) != 0))
6608 add_symbol_to_list (sym
, &global_symbols
);
6612 add_symbol_to_list (sym
, cu
->list_in_scope
);
6615 case DW_TAG_variable
:
6616 /* Compilation with minimal debug info may result in variables
6617 with missing type entries. Change the misleading `void' type
6618 to something sensible. */
6619 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
6620 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
6621 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
6622 "<variable, no debug info>",
6624 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6627 dwarf2_const_value (attr
, sym
, cu
);
6628 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6629 if (attr2
&& (DW_UNSND (attr2
) != 0))
6630 add_symbol_to_list (sym
, &global_symbols
);
6632 add_symbol_to_list (sym
, cu
->list_in_scope
);
6635 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6638 var_decode_location (attr
, sym
, cu
);
6639 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6640 if (attr2
&& (DW_UNSND (attr2
) != 0))
6641 add_symbol_to_list (sym
, &global_symbols
);
6643 add_symbol_to_list (sym
, cu
->list_in_scope
);
6647 /* We do not know the address of this symbol.
6648 If it is an external symbol and we have type information
6649 for it, enter the symbol as a LOC_UNRESOLVED symbol.
6650 The address of the variable will then be determined from
6651 the minimal symbol table whenever the variable is
6653 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6654 if (attr2
&& (DW_UNSND (attr2
) != 0)
6655 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
6657 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
6658 add_symbol_to_list (sym
, &global_symbols
);
6662 case DW_TAG_formal_parameter
:
6663 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6666 var_decode_location (attr
, sym
, cu
);
6667 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
6668 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
6669 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
6671 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6674 dwarf2_const_value (attr
, sym
, cu
);
6676 add_symbol_to_list (sym
, cu
->list_in_scope
);
6678 case DW_TAG_unspecified_parameters
:
6679 /* From varargs functions; gdb doesn't seem to have any
6680 interest in this information, so just ignore it for now.
6683 case DW_TAG_class_type
:
6684 case DW_TAG_structure_type
:
6685 case DW_TAG_union_type
:
6686 case DW_TAG_enumeration_type
:
6687 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6688 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6690 /* Make sure that the symbol includes appropriate enclosing
6691 classes/namespaces in its name. These are calculated in
6692 read_structure_type, and the correct name is saved in
6695 if (cu
->language
== language_cplus
6696 || cu
->language
== language_java
)
6698 struct type
*type
= SYMBOL_TYPE (sym
);
6700 if (TYPE_TAG_NAME (type
) != NULL
)
6702 /* FIXME: carlton/2003-11-10: Should this use
6703 SYMBOL_SET_NAMES instead? (The same problem also
6704 arises further down in this function.) */
6705 /* The type's name is already allocated along with
6706 this objfile, so we don't need to duplicate it
6708 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
6713 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
6714 really ever be static objects: otherwise, if you try
6715 to, say, break of a class's method and you're in a file
6716 which doesn't mention that class, it won't work unless
6717 the check for all static symbols in lookup_symbol_aux
6718 saves you. See the OtherFileClass tests in
6719 gdb.c++/namespace.exp. */
6721 struct pending
**list_to_add
;
6723 list_to_add
= (cu
->list_in_scope
== &file_symbols
6724 && (cu
->language
== language_cplus
6725 || cu
->language
== language_java
)
6726 ? &global_symbols
: cu
->list_in_scope
);
6728 add_symbol_to_list (sym
, list_to_add
);
6730 /* The semantics of C++ state that "struct foo { ... }" also
6731 defines a typedef for "foo". A Java class declaration also
6732 defines a typedef for the class. Synthesize a typedef symbol
6733 so that "ptype foo" works as expected. */
6734 if (cu
->language
== language_cplus
6735 || cu
->language
== language_java
)
6737 struct symbol
*typedef_sym
= (struct symbol
*)
6738 obstack_alloc (&objfile
->objfile_obstack
,
6739 sizeof (struct symbol
));
6740 *typedef_sym
= *sym
;
6741 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
6742 /* The symbol's name is already allocated along with
6743 this objfile, so we don't need to duplicate it for
6745 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
6746 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NATURAL_NAME (sym
);
6747 add_symbol_to_list (typedef_sym
, list_to_add
);
6751 case DW_TAG_typedef
:
6752 if (processing_has_namespace_info
6753 && processing_current_prefix
[0] != '\0')
6755 SYMBOL_LINKAGE_NAME (sym
) = typename_concat (&objfile
->objfile_obstack
,
6756 processing_current_prefix
,
6759 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6760 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6761 add_symbol_to_list (sym
, cu
->list_in_scope
);
6763 case DW_TAG_base_type
:
6764 case DW_TAG_subrange_type
:
6765 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6766 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6767 add_symbol_to_list (sym
, cu
->list_in_scope
);
6769 case DW_TAG_enumerator
:
6770 if (processing_has_namespace_info
6771 && processing_current_prefix
[0] != '\0')
6773 SYMBOL_LINKAGE_NAME (sym
) = typename_concat (&objfile
->objfile_obstack
,
6774 processing_current_prefix
,
6777 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6780 dwarf2_const_value (attr
, sym
, cu
);
6783 /* NOTE: carlton/2003-11-10: See comment above in the
6784 DW_TAG_class_type, etc. block. */
6786 struct pending
**list_to_add
;
6788 list_to_add
= (cu
->list_in_scope
== &file_symbols
6789 && (cu
->language
== language_cplus
6790 || cu
->language
== language_java
)
6791 ? &global_symbols
: cu
->list_in_scope
);
6793 add_symbol_to_list (sym
, list_to_add
);
6796 case DW_TAG_namespace
:
6797 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6798 add_symbol_to_list (sym
, &global_symbols
);
6801 /* Not a tag we recognize. Hopefully we aren't processing
6802 trash data, but since we must specifically ignore things
6803 we don't recognize, there is nothing else we should do at
6805 complaint (&symfile_complaints
, "unsupported tag: '%s'",
6806 dwarf_tag_name (die
->tag
));
6813 /* Copy constant value from an attribute to a symbol. */
6816 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
6817 struct dwarf2_cu
*cu
)
6819 struct objfile
*objfile
= cu
->objfile
;
6820 struct comp_unit_head
*cu_header
= &cu
->header
;
6821 struct dwarf_block
*blk
;
6826 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
6827 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
6828 cu_header
->addr_size
,
6829 TYPE_LENGTH (SYMBOL_TYPE
6831 SYMBOL_VALUE_BYTES (sym
) = (char *)
6832 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
6833 /* NOTE: cagney/2003-05-09: In-lined store_address call with
6834 it's body - store_unsigned_integer. */
6835 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
6837 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6839 case DW_FORM_block1
:
6840 case DW_FORM_block2
:
6841 case DW_FORM_block4
:
6843 blk
= DW_BLOCK (attr
);
6844 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
6845 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
6847 TYPE_LENGTH (SYMBOL_TYPE
6849 SYMBOL_VALUE_BYTES (sym
) = (char *)
6850 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
6851 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
6852 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6855 /* The DW_AT_const_value attributes are supposed to carry the
6856 symbol's value "represented as it would be on the target
6857 architecture." By the time we get here, it's already been
6858 converted to host endianness, so we just need to sign- or
6859 zero-extend it as appropriate. */
6861 dwarf2_const_value_data (attr
, sym
, 8);
6864 dwarf2_const_value_data (attr
, sym
, 16);
6867 dwarf2_const_value_data (attr
, sym
, 32);
6870 dwarf2_const_value_data (attr
, sym
, 64);
6874 SYMBOL_VALUE (sym
) = DW_SND (attr
);
6875 SYMBOL_CLASS (sym
) = LOC_CONST
;
6879 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
6880 SYMBOL_CLASS (sym
) = LOC_CONST
;
6884 complaint (&symfile_complaints
,
6885 "unsupported const value attribute form: '%s'",
6886 dwarf_form_name (attr
->form
));
6887 SYMBOL_VALUE (sym
) = 0;
6888 SYMBOL_CLASS (sym
) = LOC_CONST
;
6894 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
6895 or zero-extend it as appropriate for the symbol's type. */
6897 dwarf2_const_value_data (struct attribute
*attr
,
6901 LONGEST l
= DW_UNSND (attr
);
6903 if (bits
< sizeof (l
) * 8)
6905 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
6906 l
&= ((LONGEST
) 1 << bits
) - 1;
6908 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
6911 SYMBOL_VALUE (sym
) = l
;
6912 SYMBOL_CLASS (sym
) = LOC_CONST
;
6916 /* Return the type of the die in question using its DW_AT_type attribute. */
6918 static struct type
*
6919 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6922 struct attribute
*type_attr
;
6923 struct die_info
*type_die
;
6926 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
6929 /* A missing DW_AT_type represents a void type. */
6930 return dwarf2_fundamental_type (cu
->objfile
, FT_VOID
, cu
);
6934 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6935 type_die
= follow_die_ref (ref
);
6938 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
6939 ref
, cu
->objfile
->name
);
6943 type
= tag_type_to_type (type_die
, cu
);
6946 dump_die (type_die
);
6947 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
6953 /* Return the containing type of the die in question using its
6954 DW_AT_containing_type attribute. */
6956 static struct type
*
6957 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6959 struct type
*type
= NULL
;
6960 struct attribute
*type_attr
;
6961 struct die_info
*type_die
= NULL
;
6964 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
6967 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6968 type_die
= follow_die_ref (ref
);
6971 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
6975 type
= tag_type_to_type (type_die
, cu
);
6980 dump_die (type_die
);
6981 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
6988 static struct type
*
6989 type_at_offset (unsigned int offset
, struct dwarf2_cu
*cu
)
6991 struct die_info
*die
;
6994 die
= follow_die_ref (offset
);
6997 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
7000 type
= tag_type_to_type (die
, cu
);
7005 static struct type
*
7006 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7014 read_type_die (die
, cu
);
7018 error ("Dwarf Error: Cannot find type of die [in module %s]",
7026 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7028 char *prefix
= determine_prefix (die
, cu
);
7029 const char *old_prefix
= processing_current_prefix
;
7030 struct cleanup
*back_to
= make_cleanup (xfree
, prefix
);
7031 processing_current_prefix
= prefix
;
7035 case DW_TAG_class_type
:
7036 case DW_TAG_structure_type
:
7037 case DW_TAG_union_type
:
7038 read_structure_type (die
, cu
);
7040 case DW_TAG_enumeration_type
:
7041 read_enumeration_type (die
, cu
);
7043 case DW_TAG_subprogram
:
7044 case DW_TAG_subroutine_type
:
7045 read_subroutine_type (die
, cu
);
7047 case DW_TAG_array_type
:
7048 read_array_type (die
, cu
);
7050 case DW_TAG_pointer_type
:
7051 read_tag_pointer_type (die
, cu
);
7053 case DW_TAG_ptr_to_member_type
:
7054 read_tag_ptr_to_member_type (die
, cu
);
7056 case DW_TAG_reference_type
:
7057 read_tag_reference_type (die
, cu
);
7059 case DW_TAG_const_type
:
7060 read_tag_const_type (die
, cu
);
7062 case DW_TAG_volatile_type
:
7063 read_tag_volatile_type (die
, cu
);
7065 case DW_TAG_string_type
:
7066 read_tag_string_type (die
, cu
);
7068 case DW_TAG_typedef
:
7069 read_typedef (die
, cu
);
7071 case DW_TAG_subrange_type
:
7072 read_subrange_type (die
, cu
);
7074 case DW_TAG_base_type
:
7075 read_base_type (die
, cu
);
7078 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
7079 dwarf_tag_name (die
->tag
));
7083 processing_current_prefix
= old_prefix
;
7084 do_cleanups (back_to
);
7087 /* Return the name of the namespace/class that DIE is defined within,
7088 or "" if we can't tell. The caller should xfree the result. */
7090 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
7091 therein) for an example of how to use this function to deal with
7092 DW_AT_specification. */
7095 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
7097 struct die_info
*parent
;
7099 if (cu
->language
!= language_cplus
7100 && cu
->language
!= language_java
)
7103 parent
= die
->parent
;
7107 return xstrdup ("");
7111 switch (parent
->tag
) {
7112 case DW_TAG_namespace
:
7114 /* FIXME: carlton/2004-03-05: Should I follow extension dies
7115 before doing this check? */
7116 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
7118 return xstrdup (TYPE_TAG_NAME (parent
->type
));
7123 char *parent_prefix
= determine_prefix (parent
, cu
);
7124 char *retval
= typename_concat (NULL
, parent_prefix
,
7125 namespace_name (parent
, &dummy
,
7128 xfree (parent_prefix
);
7133 case DW_TAG_class_type
:
7134 case DW_TAG_structure_type
:
7136 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
7138 return xstrdup (TYPE_TAG_NAME (parent
->type
));
7142 const char *old_prefix
= processing_current_prefix
;
7143 char *new_prefix
= determine_prefix (parent
, cu
);
7146 processing_current_prefix
= new_prefix
;
7147 retval
= determine_class_name (parent
, cu
);
7148 processing_current_prefix
= old_prefix
;
7155 return determine_prefix (parent
, cu
);
7160 /* Return a newly-allocated string formed by concatenating PREFIX and
7161 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
7162 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
7163 perform an obconcat, otherwise allocate storage for the result. The CU argument
7164 is used to determine the language and hence, the appropriate separator. */
7166 #define MAX_SEP_LEN 2 /* sizeof ("::") */
7169 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
7170 struct dwarf2_cu
*cu
)
7174 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
7176 else if (cu
->language
== language_java
)
7183 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
7188 strcpy (retval
, prefix
);
7189 strcat (retval
, sep
);
7192 strcat (retval
, suffix
);
7198 /* We have an obstack. */
7199 return obconcat (obs
, prefix
, sep
, suffix
);
7203 static struct type
*
7204 dwarf_base_type (int encoding
, int size
, struct dwarf2_cu
*cu
)
7206 struct objfile
*objfile
= cu
->objfile
;
7208 /* FIXME - this should not produce a new (struct type *)
7209 every time. It should cache base types. */
7213 case DW_ATE_address
:
7214 type
= dwarf2_fundamental_type (objfile
, FT_VOID
, cu
);
7216 case DW_ATE_boolean
:
7217 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
, cu
);
7219 case DW_ATE_complex_float
:
7222 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
, cu
);
7226 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
, cu
);
7232 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
7236 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
7243 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
7246 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
, cu
);
7250 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
7254 case DW_ATE_signed_char
:
7255 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
7257 case DW_ATE_unsigned
:
7261 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
7264 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
, cu
);
7268 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
, cu
);
7272 case DW_ATE_unsigned_char
:
7273 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
7276 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
7283 copy_die (struct die_info
*old_die
)
7285 struct die_info
*new_die
;
7288 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
7289 memset (new_die
, 0, sizeof (struct die_info
));
7291 new_die
->tag
= old_die
->tag
;
7292 new_die
->has_children
= old_die
->has_children
;
7293 new_die
->abbrev
= old_die
->abbrev
;
7294 new_die
->offset
= old_die
->offset
;
7295 new_die
->type
= NULL
;
7297 num_attrs
= old_die
->num_attrs
;
7298 new_die
->num_attrs
= num_attrs
;
7299 new_die
->attrs
= (struct attribute
*)
7300 xmalloc (num_attrs
* sizeof (struct attribute
));
7302 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
7304 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
7305 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
7306 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
7309 new_die
->next
= NULL
;
7314 /* Return sibling of die, NULL if no sibling. */
7316 static struct die_info
*
7317 sibling_die (struct die_info
*die
)
7319 return die
->sibling
;
7322 /* Get linkage name of a die, return NULL if not found. */
7325 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
7327 struct attribute
*attr
;
7329 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7330 if (attr
&& DW_STRING (attr
))
7331 return DW_STRING (attr
);
7332 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7333 if (attr
&& DW_STRING (attr
))
7334 return DW_STRING (attr
);
7338 /* Get name of a die, return NULL if not found. */
7341 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
7343 struct attribute
*attr
;
7345 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7346 if (attr
&& DW_STRING (attr
))
7347 return DW_STRING (attr
);
7351 /* Return the die that this die in an extension of, or NULL if there
7354 static struct die_info
*
7355 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
7357 struct attribute
*attr
;
7358 struct die_info
*extension_die
;
7361 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
7365 ref
= dwarf2_get_ref_die_offset (attr
, cu
);
7366 extension_die
= follow_die_ref (ref
);
7369 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
7372 return extension_die
;
7375 /* Convert a DIE tag into its string name. */
7378 dwarf_tag_name (unsigned tag
)
7382 case DW_TAG_padding
:
7383 return "DW_TAG_padding";
7384 case DW_TAG_array_type
:
7385 return "DW_TAG_array_type";
7386 case DW_TAG_class_type
:
7387 return "DW_TAG_class_type";
7388 case DW_TAG_entry_point
:
7389 return "DW_TAG_entry_point";
7390 case DW_TAG_enumeration_type
:
7391 return "DW_TAG_enumeration_type";
7392 case DW_TAG_formal_parameter
:
7393 return "DW_TAG_formal_parameter";
7394 case DW_TAG_imported_declaration
:
7395 return "DW_TAG_imported_declaration";
7397 return "DW_TAG_label";
7398 case DW_TAG_lexical_block
:
7399 return "DW_TAG_lexical_block";
7401 return "DW_TAG_member";
7402 case DW_TAG_pointer_type
:
7403 return "DW_TAG_pointer_type";
7404 case DW_TAG_reference_type
:
7405 return "DW_TAG_reference_type";
7406 case DW_TAG_compile_unit
:
7407 return "DW_TAG_compile_unit";
7408 case DW_TAG_string_type
:
7409 return "DW_TAG_string_type";
7410 case DW_TAG_structure_type
:
7411 return "DW_TAG_structure_type";
7412 case DW_TAG_subroutine_type
:
7413 return "DW_TAG_subroutine_type";
7414 case DW_TAG_typedef
:
7415 return "DW_TAG_typedef";
7416 case DW_TAG_union_type
:
7417 return "DW_TAG_union_type";
7418 case DW_TAG_unspecified_parameters
:
7419 return "DW_TAG_unspecified_parameters";
7420 case DW_TAG_variant
:
7421 return "DW_TAG_variant";
7422 case DW_TAG_common_block
:
7423 return "DW_TAG_common_block";
7424 case DW_TAG_common_inclusion
:
7425 return "DW_TAG_common_inclusion";
7426 case DW_TAG_inheritance
:
7427 return "DW_TAG_inheritance";
7428 case DW_TAG_inlined_subroutine
:
7429 return "DW_TAG_inlined_subroutine";
7431 return "DW_TAG_module";
7432 case DW_TAG_ptr_to_member_type
:
7433 return "DW_TAG_ptr_to_member_type";
7434 case DW_TAG_set_type
:
7435 return "DW_TAG_set_type";
7436 case DW_TAG_subrange_type
:
7437 return "DW_TAG_subrange_type";
7438 case DW_TAG_with_stmt
:
7439 return "DW_TAG_with_stmt";
7440 case DW_TAG_access_declaration
:
7441 return "DW_TAG_access_declaration";
7442 case DW_TAG_base_type
:
7443 return "DW_TAG_base_type";
7444 case DW_TAG_catch_block
:
7445 return "DW_TAG_catch_block";
7446 case DW_TAG_const_type
:
7447 return "DW_TAG_const_type";
7448 case DW_TAG_constant
:
7449 return "DW_TAG_constant";
7450 case DW_TAG_enumerator
:
7451 return "DW_TAG_enumerator";
7452 case DW_TAG_file_type
:
7453 return "DW_TAG_file_type";
7455 return "DW_TAG_friend";
7456 case DW_TAG_namelist
:
7457 return "DW_TAG_namelist";
7458 case DW_TAG_namelist_item
:
7459 return "DW_TAG_namelist_item";
7460 case DW_TAG_packed_type
:
7461 return "DW_TAG_packed_type";
7462 case DW_TAG_subprogram
:
7463 return "DW_TAG_subprogram";
7464 case DW_TAG_template_type_param
:
7465 return "DW_TAG_template_type_param";
7466 case DW_TAG_template_value_param
:
7467 return "DW_TAG_template_value_param";
7468 case DW_TAG_thrown_type
:
7469 return "DW_TAG_thrown_type";
7470 case DW_TAG_try_block
:
7471 return "DW_TAG_try_block";
7472 case DW_TAG_variant_part
:
7473 return "DW_TAG_variant_part";
7474 case DW_TAG_variable
:
7475 return "DW_TAG_variable";
7476 case DW_TAG_volatile_type
:
7477 return "DW_TAG_volatile_type";
7478 case DW_TAG_dwarf_procedure
:
7479 return "DW_TAG_dwarf_procedure";
7480 case DW_TAG_restrict_type
:
7481 return "DW_TAG_restrict_type";
7482 case DW_TAG_interface_type
:
7483 return "DW_TAG_interface_type";
7484 case DW_TAG_namespace
:
7485 return "DW_TAG_namespace";
7486 case DW_TAG_imported_module
:
7487 return "DW_TAG_imported_module";
7488 case DW_TAG_unspecified_type
:
7489 return "DW_TAG_unspecified_type";
7490 case DW_TAG_partial_unit
:
7491 return "DW_TAG_partial_unit";
7492 case DW_TAG_imported_unit
:
7493 return "DW_TAG_imported_unit";
7494 case DW_TAG_MIPS_loop
:
7495 return "DW_TAG_MIPS_loop";
7496 case DW_TAG_format_label
:
7497 return "DW_TAG_format_label";
7498 case DW_TAG_function_template
:
7499 return "DW_TAG_function_template";
7500 case DW_TAG_class_template
:
7501 return "DW_TAG_class_template";
7503 return "DW_TAG_<unknown>";
7507 /* Convert a DWARF attribute code into its string name. */
7510 dwarf_attr_name (unsigned attr
)
7515 return "DW_AT_sibling";
7516 case DW_AT_location
:
7517 return "DW_AT_location";
7519 return "DW_AT_name";
7520 case DW_AT_ordering
:
7521 return "DW_AT_ordering";
7522 case DW_AT_subscr_data
:
7523 return "DW_AT_subscr_data";
7524 case DW_AT_byte_size
:
7525 return "DW_AT_byte_size";
7526 case DW_AT_bit_offset
:
7527 return "DW_AT_bit_offset";
7528 case DW_AT_bit_size
:
7529 return "DW_AT_bit_size";
7530 case DW_AT_element_list
:
7531 return "DW_AT_element_list";
7532 case DW_AT_stmt_list
:
7533 return "DW_AT_stmt_list";
7535 return "DW_AT_low_pc";
7537 return "DW_AT_high_pc";
7538 case DW_AT_language
:
7539 return "DW_AT_language";
7541 return "DW_AT_member";
7543 return "DW_AT_discr";
7544 case DW_AT_discr_value
:
7545 return "DW_AT_discr_value";
7546 case DW_AT_visibility
:
7547 return "DW_AT_visibility";
7549 return "DW_AT_import";
7550 case DW_AT_string_length
:
7551 return "DW_AT_string_length";
7552 case DW_AT_common_reference
:
7553 return "DW_AT_common_reference";
7554 case DW_AT_comp_dir
:
7555 return "DW_AT_comp_dir";
7556 case DW_AT_const_value
:
7557 return "DW_AT_const_value";
7558 case DW_AT_containing_type
:
7559 return "DW_AT_containing_type";
7560 case DW_AT_default_value
:
7561 return "DW_AT_default_value";
7563 return "DW_AT_inline";
7564 case DW_AT_is_optional
:
7565 return "DW_AT_is_optional";
7566 case DW_AT_lower_bound
:
7567 return "DW_AT_lower_bound";
7568 case DW_AT_producer
:
7569 return "DW_AT_producer";
7570 case DW_AT_prototyped
:
7571 return "DW_AT_prototyped";
7572 case DW_AT_return_addr
:
7573 return "DW_AT_return_addr";
7574 case DW_AT_start_scope
:
7575 return "DW_AT_start_scope";
7576 case DW_AT_stride_size
:
7577 return "DW_AT_stride_size";
7578 case DW_AT_upper_bound
:
7579 return "DW_AT_upper_bound";
7580 case DW_AT_abstract_origin
:
7581 return "DW_AT_abstract_origin";
7582 case DW_AT_accessibility
:
7583 return "DW_AT_accessibility";
7584 case DW_AT_address_class
:
7585 return "DW_AT_address_class";
7586 case DW_AT_artificial
:
7587 return "DW_AT_artificial";
7588 case DW_AT_base_types
:
7589 return "DW_AT_base_types";
7590 case DW_AT_calling_convention
:
7591 return "DW_AT_calling_convention";
7593 return "DW_AT_count";
7594 case DW_AT_data_member_location
:
7595 return "DW_AT_data_member_location";
7596 case DW_AT_decl_column
:
7597 return "DW_AT_decl_column";
7598 case DW_AT_decl_file
:
7599 return "DW_AT_decl_file";
7600 case DW_AT_decl_line
:
7601 return "DW_AT_decl_line";
7602 case DW_AT_declaration
:
7603 return "DW_AT_declaration";
7604 case DW_AT_discr_list
:
7605 return "DW_AT_discr_list";
7606 case DW_AT_encoding
:
7607 return "DW_AT_encoding";
7608 case DW_AT_external
:
7609 return "DW_AT_external";
7610 case DW_AT_frame_base
:
7611 return "DW_AT_frame_base";
7613 return "DW_AT_friend";
7614 case DW_AT_identifier_case
:
7615 return "DW_AT_identifier_case";
7616 case DW_AT_macro_info
:
7617 return "DW_AT_macro_info";
7618 case DW_AT_namelist_items
:
7619 return "DW_AT_namelist_items";
7620 case DW_AT_priority
:
7621 return "DW_AT_priority";
7623 return "DW_AT_segment";
7624 case DW_AT_specification
:
7625 return "DW_AT_specification";
7626 case DW_AT_static_link
:
7627 return "DW_AT_static_link";
7629 return "DW_AT_type";
7630 case DW_AT_use_location
:
7631 return "DW_AT_use_location";
7632 case DW_AT_variable_parameter
:
7633 return "DW_AT_variable_parameter";
7634 case DW_AT_virtuality
:
7635 return "DW_AT_virtuality";
7636 case DW_AT_vtable_elem_location
:
7637 return "DW_AT_vtable_elem_location";
7638 case DW_AT_allocated
:
7639 return "DW_AT_allocated";
7640 case DW_AT_associated
:
7641 return "DW_AT_associated";
7642 case DW_AT_data_location
:
7643 return "DW_AT_data_location";
7645 return "DW_AT_stride";
7646 case DW_AT_entry_pc
:
7647 return "DW_AT_entry_pc";
7648 case DW_AT_use_UTF8
:
7649 return "DW_AT_use_UTF8";
7650 case DW_AT_extension
:
7651 return "DW_AT_extension";
7653 return "DW_AT_ranges";
7654 case DW_AT_trampoline
:
7655 return "DW_AT_trampoline";
7656 case DW_AT_call_column
:
7657 return "DW_AT_call_column";
7658 case DW_AT_call_file
:
7659 return "DW_AT_call_file";
7660 case DW_AT_call_line
:
7661 return "DW_AT_call_line";
7663 case DW_AT_MIPS_fde
:
7664 return "DW_AT_MIPS_fde";
7665 case DW_AT_MIPS_loop_begin
:
7666 return "DW_AT_MIPS_loop_begin";
7667 case DW_AT_MIPS_tail_loop_begin
:
7668 return "DW_AT_MIPS_tail_loop_begin";
7669 case DW_AT_MIPS_epilog_begin
:
7670 return "DW_AT_MIPS_epilog_begin";
7671 case DW_AT_MIPS_loop_unroll_factor
:
7672 return "DW_AT_MIPS_loop_unroll_factor";
7673 case DW_AT_MIPS_software_pipeline_depth
:
7674 return "DW_AT_MIPS_software_pipeline_depth";
7676 case DW_AT_MIPS_linkage_name
:
7677 return "DW_AT_MIPS_linkage_name";
7679 case DW_AT_sf_names
:
7680 return "DW_AT_sf_names";
7681 case DW_AT_src_info
:
7682 return "DW_AT_src_info";
7683 case DW_AT_mac_info
:
7684 return "DW_AT_mac_info";
7685 case DW_AT_src_coords
:
7686 return "DW_AT_src_coords";
7687 case DW_AT_body_begin
:
7688 return "DW_AT_body_begin";
7689 case DW_AT_body_end
:
7690 return "DW_AT_body_end";
7691 case DW_AT_GNU_vector
:
7692 return "DW_AT_GNU_vector";
7694 return "DW_AT_<unknown>";
7698 /* Convert a DWARF value form code into its string name. */
7701 dwarf_form_name (unsigned form
)
7706 return "DW_FORM_addr";
7707 case DW_FORM_block2
:
7708 return "DW_FORM_block2";
7709 case DW_FORM_block4
:
7710 return "DW_FORM_block4";
7712 return "DW_FORM_data2";
7714 return "DW_FORM_data4";
7716 return "DW_FORM_data8";
7717 case DW_FORM_string
:
7718 return "DW_FORM_string";
7720 return "DW_FORM_block";
7721 case DW_FORM_block1
:
7722 return "DW_FORM_block1";
7724 return "DW_FORM_data1";
7726 return "DW_FORM_flag";
7728 return "DW_FORM_sdata";
7730 return "DW_FORM_strp";
7732 return "DW_FORM_udata";
7733 case DW_FORM_ref_addr
:
7734 return "DW_FORM_ref_addr";
7736 return "DW_FORM_ref1";
7738 return "DW_FORM_ref2";
7740 return "DW_FORM_ref4";
7742 return "DW_FORM_ref8";
7743 case DW_FORM_ref_udata
:
7744 return "DW_FORM_ref_udata";
7745 case DW_FORM_indirect
:
7746 return "DW_FORM_indirect";
7748 return "DW_FORM_<unknown>";
7752 /* Convert a DWARF stack opcode into its string name. */
7755 dwarf_stack_op_name (unsigned op
)
7760 return "DW_OP_addr";
7762 return "DW_OP_deref";
7764 return "DW_OP_const1u";
7766 return "DW_OP_const1s";
7768 return "DW_OP_const2u";
7770 return "DW_OP_const2s";
7772 return "DW_OP_const4u";
7774 return "DW_OP_const4s";
7776 return "DW_OP_const8u";
7778 return "DW_OP_const8s";
7780 return "DW_OP_constu";
7782 return "DW_OP_consts";
7786 return "DW_OP_drop";
7788 return "DW_OP_over";
7790 return "DW_OP_pick";
7792 return "DW_OP_swap";
7796 return "DW_OP_xderef";
7804 return "DW_OP_minus";
7816 return "DW_OP_plus";
7817 case DW_OP_plus_uconst
:
7818 return "DW_OP_plus_uconst";
7824 return "DW_OP_shra";
7842 return "DW_OP_skip";
7844 return "DW_OP_lit0";
7846 return "DW_OP_lit1";
7848 return "DW_OP_lit2";
7850 return "DW_OP_lit3";
7852 return "DW_OP_lit4";
7854 return "DW_OP_lit5";
7856 return "DW_OP_lit6";
7858 return "DW_OP_lit7";
7860 return "DW_OP_lit8";
7862 return "DW_OP_lit9";
7864 return "DW_OP_lit10";
7866 return "DW_OP_lit11";
7868 return "DW_OP_lit12";
7870 return "DW_OP_lit13";
7872 return "DW_OP_lit14";
7874 return "DW_OP_lit15";
7876 return "DW_OP_lit16";
7878 return "DW_OP_lit17";
7880 return "DW_OP_lit18";
7882 return "DW_OP_lit19";
7884 return "DW_OP_lit20";
7886 return "DW_OP_lit21";
7888 return "DW_OP_lit22";
7890 return "DW_OP_lit23";
7892 return "DW_OP_lit24";
7894 return "DW_OP_lit25";
7896 return "DW_OP_lit26";
7898 return "DW_OP_lit27";
7900 return "DW_OP_lit28";
7902 return "DW_OP_lit29";
7904 return "DW_OP_lit30";
7906 return "DW_OP_lit31";
7908 return "DW_OP_reg0";
7910 return "DW_OP_reg1";
7912 return "DW_OP_reg2";
7914 return "DW_OP_reg3";
7916 return "DW_OP_reg4";
7918 return "DW_OP_reg5";
7920 return "DW_OP_reg6";
7922 return "DW_OP_reg7";
7924 return "DW_OP_reg8";
7926 return "DW_OP_reg9";
7928 return "DW_OP_reg10";
7930 return "DW_OP_reg11";
7932 return "DW_OP_reg12";
7934 return "DW_OP_reg13";
7936 return "DW_OP_reg14";
7938 return "DW_OP_reg15";
7940 return "DW_OP_reg16";
7942 return "DW_OP_reg17";
7944 return "DW_OP_reg18";
7946 return "DW_OP_reg19";
7948 return "DW_OP_reg20";
7950 return "DW_OP_reg21";
7952 return "DW_OP_reg22";
7954 return "DW_OP_reg23";
7956 return "DW_OP_reg24";
7958 return "DW_OP_reg25";
7960 return "DW_OP_reg26";
7962 return "DW_OP_reg27";
7964 return "DW_OP_reg28";
7966 return "DW_OP_reg29";
7968 return "DW_OP_reg30";
7970 return "DW_OP_reg31";
7972 return "DW_OP_breg0";
7974 return "DW_OP_breg1";
7976 return "DW_OP_breg2";
7978 return "DW_OP_breg3";
7980 return "DW_OP_breg4";
7982 return "DW_OP_breg5";
7984 return "DW_OP_breg6";
7986 return "DW_OP_breg7";
7988 return "DW_OP_breg8";
7990 return "DW_OP_breg9";
7992 return "DW_OP_breg10";
7994 return "DW_OP_breg11";
7996 return "DW_OP_breg12";
7998 return "DW_OP_breg13";
8000 return "DW_OP_breg14";
8002 return "DW_OP_breg15";
8004 return "DW_OP_breg16";
8006 return "DW_OP_breg17";
8008 return "DW_OP_breg18";
8010 return "DW_OP_breg19";
8012 return "DW_OP_breg20";
8014 return "DW_OP_breg21";
8016 return "DW_OP_breg22";
8018 return "DW_OP_breg23";
8020 return "DW_OP_breg24";
8022 return "DW_OP_breg25";
8024 return "DW_OP_breg26";
8026 return "DW_OP_breg27";
8028 return "DW_OP_breg28";
8030 return "DW_OP_breg29";
8032 return "DW_OP_breg30";
8034 return "DW_OP_breg31";
8036 return "DW_OP_regx";
8038 return "DW_OP_fbreg";
8040 return "DW_OP_bregx";
8042 return "DW_OP_piece";
8043 case DW_OP_deref_size
:
8044 return "DW_OP_deref_size";
8045 case DW_OP_xderef_size
:
8046 return "DW_OP_xderef_size";
8049 /* DWARF 3 extensions. */
8050 case DW_OP_push_object_address
:
8051 return "DW_OP_push_object_address";
8053 return "DW_OP_call2";
8055 return "DW_OP_call4";
8056 case DW_OP_call_ref
:
8057 return "DW_OP_call_ref";
8058 /* GNU extensions. */
8059 case DW_OP_GNU_push_tls_address
:
8060 return "DW_OP_GNU_push_tls_address";
8062 return "OP_<unknown>";
8067 dwarf_bool_name (unsigned mybool
)
8075 /* Convert a DWARF type code into its string name. */
8078 dwarf_type_encoding_name (unsigned enc
)
8082 case DW_ATE_address
:
8083 return "DW_ATE_address";
8084 case DW_ATE_boolean
:
8085 return "DW_ATE_boolean";
8086 case DW_ATE_complex_float
:
8087 return "DW_ATE_complex_float";
8089 return "DW_ATE_float";
8091 return "DW_ATE_signed";
8092 case DW_ATE_signed_char
:
8093 return "DW_ATE_signed_char";
8094 case DW_ATE_unsigned
:
8095 return "DW_ATE_unsigned";
8096 case DW_ATE_unsigned_char
:
8097 return "DW_ATE_unsigned_char";
8098 case DW_ATE_imaginary_float
:
8099 return "DW_ATE_imaginary_float";
8101 return "DW_ATE_<unknown>";
8105 /* Convert a DWARF call frame info operation to its string name. */
8109 dwarf_cfi_name (unsigned cfi_opc
)
8113 case DW_CFA_advance_loc
:
8114 return "DW_CFA_advance_loc";
8116 return "DW_CFA_offset";
8117 case DW_CFA_restore
:
8118 return "DW_CFA_restore";
8120 return "DW_CFA_nop";
8121 case DW_CFA_set_loc
:
8122 return "DW_CFA_set_loc";
8123 case DW_CFA_advance_loc1
:
8124 return "DW_CFA_advance_loc1";
8125 case DW_CFA_advance_loc2
:
8126 return "DW_CFA_advance_loc2";
8127 case DW_CFA_advance_loc4
:
8128 return "DW_CFA_advance_loc4";
8129 case DW_CFA_offset_extended
:
8130 return "DW_CFA_offset_extended";
8131 case DW_CFA_restore_extended
:
8132 return "DW_CFA_restore_extended";
8133 case DW_CFA_undefined
:
8134 return "DW_CFA_undefined";
8135 case DW_CFA_same_value
:
8136 return "DW_CFA_same_value";
8137 case DW_CFA_register
:
8138 return "DW_CFA_register";
8139 case DW_CFA_remember_state
:
8140 return "DW_CFA_remember_state";
8141 case DW_CFA_restore_state
:
8142 return "DW_CFA_restore_state";
8143 case DW_CFA_def_cfa
:
8144 return "DW_CFA_def_cfa";
8145 case DW_CFA_def_cfa_register
:
8146 return "DW_CFA_def_cfa_register";
8147 case DW_CFA_def_cfa_offset
:
8148 return "DW_CFA_def_cfa_offset";
8151 case DW_CFA_def_cfa_expression
:
8152 return "DW_CFA_def_cfa_expression";
8153 case DW_CFA_expression
:
8154 return "DW_CFA_expression";
8155 case DW_CFA_offset_extended_sf
:
8156 return "DW_CFA_offset_extended_sf";
8157 case DW_CFA_def_cfa_sf
:
8158 return "DW_CFA_def_cfa_sf";
8159 case DW_CFA_def_cfa_offset_sf
:
8160 return "DW_CFA_def_cfa_offset_sf";
8162 /* SGI/MIPS specific */
8163 case DW_CFA_MIPS_advance_loc8
:
8164 return "DW_CFA_MIPS_advance_loc8";
8166 /* GNU extensions */
8167 case DW_CFA_GNU_window_save
:
8168 return "DW_CFA_GNU_window_save";
8169 case DW_CFA_GNU_args_size
:
8170 return "DW_CFA_GNU_args_size";
8171 case DW_CFA_GNU_negative_offset_extended
:
8172 return "DW_CFA_GNU_negative_offset_extended";
8175 return "DW_CFA_<unknown>";
8181 dump_die (struct die_info
*die
)
8185 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
8186 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
8187 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
8188 dwarf_bool_name (die
->child
!= NULL
));
8190 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
8191 for (i
= 0; i
< die
->num_attrs
; ++i
)
8193 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
8194 dwarf_attr_name (die
->attrs
[i
].name
),
8195 dwarf_form_name (die
->attrs
[i
].form
));
8196 switch (die
->attrs
[i
].form
)
8198 case DW_FORM_ref_addr
:
8200 fprintf_unfiltered (gdb_stderr
, "address: ");
8201 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
8203 case DW_FORM_block2
:
8204 case DW_FORM_block4
:
8206 case DW_FORM_block1
:
8207 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
8218 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
8220 case DW_FORM_string
:
8222 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
8223 DW_STRING (&die
->attrs
[i
])
8224 ? DW_STRING (&die
->attrs
[i
]) : "");
8227 if (DW_UNSND (&die
->attrs
[i
]))
8228 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
8230 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
8232 case DW_FORM_indirect
:
8233 /* the reader will have reduced the indirect form to
8234 the "base form" so this form should not occur */
8235 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
8238 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
8239 die
->attrs
[i
].form
);
8241 fprintf_unfiltered (gdb_stderr
, "\n");
8246 dump_die_list (struct die_info
*die
)
8251 if (die
->child
!= NULL
)
8252 dump_die_list (die
->child
);
8253 if (die
->sibling
!= NULL
)
8254 dump_die_list (die
->sibling
);
8259 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
8262 struct die_info
*old
;
8264 h
= (offset
% REF_HASH_SIZE
);
8265 old
= die_ref_table
[h
];
8266 die
->next_ref
= old
;
8267 die_ref_table
[h
] = die
;
8272 dwarf2_empty_hash_tables (void)
8274 memset (die_ref_table
, 0, sizeof (die_ref_table
));
8278 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
8280 unsigned int result
= 0;
8284 case DW_FORM_ref_addr
:
8285 result
= DW_ADDR (attr
);
8291 case DW_FORM_ref_udata
:
8292 result
= cu
->header
.offset
+ DW_UNSND (attr
);
8295 complaint (&symfile_complaints
,
8296 "unsupported die ref attribute form: '%s'",
8297 dwarf_form_name (attr
->form
));
8302 /* Return the constant value held by the given attribute. Return -1
8303 if the value held by the attribute is not constant. */
8306 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
8308 if (attr
->form
== DW_FORM_sdata
)
8309 return DW_SND (attr
);
8310 else if (attr
->form
== DW_FORM_udata
8311 || attr
->form
== DW_FORM_data1
8312 || attr
->form
== DW_FORM_data2
8313 || attr
->form
== DW_FORM_data4
8314 || attr
->form
== DW_FORM_data8
)
8315 return DW_UNSND (attr
);
8318 complaint (&symfile_complaints
, "Attribute value is not a constant (%s)",
8319 dwarf_form_name (attr
->form
));
8320 return default_value
;
8324 static struct die_info
*
8325 follow_die_ref (unsigned int offset
)
8327 struct die_info
*die
;
8330 h
= (offset
% REF_HASH_SIZE
);
8331 die
= die_ref_table
[h
];
8334 if (die
->offset
== offset
)
8338 die
= die
->next_ref
;
8343 static struct type
*
8344 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid,
8345 struct dwarf2_cu
*cu
)
8347 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
8349 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
8350 typeid, objfile
->name
);
8353 /* Look for this particular type in the fundamental type vector. If
8354 one is not found, create and install one appropriate for the
8355 current language and the current target machine. */
8357 if (cu
->ftypes
[typeid] == NULL
)
8359 cu
->ftypes
[typeid] = cu
->language_defn
->la_fund_type (objfile
, typeid);
8362 return (cu
->ftypes
[typeid]);
8365 /* Decode simple location descriptions.
8366 Given a pointer to a dwarf block that defines a location, compute
8367 the location and return the value.
8369 NOTE drow/2003-11-18: This function is called in two situations
8370 now: for the address of static or global variables (partial symbols
8371 only) and for offsets into structures which are expected to be
8372 (more or less) constant. The partial symbol case should go away,
8373 and only the constant case should remain. That will let this
8374 function complain more accurately. A few special modes are allowed
8375 without complaint for global variables (for instance, global
8376 register values and thread-local values).
8378 A location description containing no operations indicates that the
8379 object is optimized out. The return value is 0 for that case.
8380 FIXME drow/2003-11-16: No callers check for this case any more; soon all
8381 callers will only want a very basic result and this can become a
8384 When the result is a register number, the global isreg flag is set,
8385 otherwise it is cleared.
8387 Note that stack[0] is unused except as a default error return.
8388 Note that stack overflow is not yet handled. */
8391 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
8393 struct objfile
*objfile
= cu
->objfile
;
8394 struct comp_unit_head
*cu_header
= &cu
->header
;
8396 int size
= blk
->size
;
8397 char *data
= blk
->data
;
8398 CORE_ADDR stack
[64];
8400 unsigned int bytes_read
, unsnd
;
8445 stack
[++stacki
] = op
- DW_OP_lit0
;
8481 stack
[++stacki
] = op
- DW_OP_reg0
;
8483 dwarf2_complex_location_expr_complaint ();
8488 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
8490 stack
[++stacki
] = unsnd
;
8492 dwarf2_complex_location_expr_complaint ();
8496 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
8502 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
8507 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
8512 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
8517 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
8522 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
8527 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
8532 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
8538 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
8543 stack
[stacki
+ 1] = stack
[stacki
];
8548 stack
[stacki
- 1] += stack
[stacki
];
8552 case DW_OP_plus_uconst
:
8553 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
8558 stack
[stacki
- 1] -= stack
[stacki
];
8563 /* If we're not the last op, then we definitely can't encode
8564 this using GDB's address_class enum. This is valid for partial
8565 global symbols, although the variable's address will be bogus
8568 dwarf2_complex_location_expr_complaint ();
8571 case DW_OP_GNU_push_tls_address
:
8572 /* The top of the stack has the offset from the beginning
8573 of the thread control block at which the variable is located. */
8574 /* Nothing should follow this operator, so the top of stack would
8576 /* This is valid for partial global symbols, but the variable's
8577 address will be bogus in the psymtab. */
8579 dwarf2_complex_location_expr_complaint ();
8583 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
8584 dwarf_stack_op_name (op
));
8585 return (stack
[stacki
]);
8588 return (stack
[stacki
]);
8591 /* memory allocation interface */
8593 static struct dwarf_block
*
8594 dwarf_alloc_block (struct dwarf2_cu
*cu
)
8596 struct dwarf_block
*blk
;
8598 blk
= (struct dwarf_block
*)
8599 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
8603 static struct abbrev_info
*
8604 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
8606 struct abbrev_info
*abbrev
;
8608 abbrev
= (struct abbrev_info
*)
8609 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
8610 memset (abbrev
, 0, sizeof (struct abbrev_info
));
8614 static struct die_info
*
8615 dwarf_alloc_die (void)
8617 struct die_info
*die
;
8619 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
8620 memset (die
, 0, sizeof (struct die_info
));
8625 /* Macro support. */
8628 /* Return the full name of file number I in *LH's file name table.
8629 Use COMP_DIR as the name of the current directory of the
8630 compilation. The result is allocated using xmalloc; the caller is
8631 responsible for freeing it. */
8633 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
8635 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
8637 if (IS_ABSOLUTE_PATH (fe
->name
))
8638 return xstrdup (fe
->name
);
8646 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8652 dir_len
= strlen (dir
);
8653 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
8654 strcpy (full_name
, dir
);
8655 full_name
[dir_len
] = '/';
8656 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
8660 return xstrdup (fe
->name
);
8665 static struct macro_source_file
*
8666 macro_start_file (int file
, int line
,
8667 struct macro_source_file
*current_file
,
8668 const char *comp_dir
,
8669 struct line_header
*lh
, struct objfile
*objfile
)
8671 /* The full name of this source file. */
8672 char *full_name
= file_full_name (file
, lh
, comp_dir
);
8674 /* We don't create a macro table for this compilation unit
8675 at all until we actually get a filename. */
8676 if (! pending_macros
)
8677 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
8678 objfile
->macro_cache
);
8681 /* If we have no current file, then this must be the start_file
8682 directive for the compilation unit's main source file. */
8683 current_file
= macro_set_main (pending_macros
, full_name
);
8685 current_file
= macro_include (current_file
, line
, full_name
);
8689 return current_file
;
8693 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
8694 followed by a null byte. */
8696 copy_string (const char *buf
, int len
)
8698 char *s
= xmalloc (len
+ 1);
8699 memcpy (s
, buf
, len
);
8707 consume_improper_spaces (const char *p
, const char *body
)
8711 complaint (&symfile_complaints
,
8712 "macro definition contains spaces in formal argument list:\n`%s'",
8724 parse_macro_definition (struct macro_source_file
*file
, int line
,
8729 /* The body string takes one of two forms. For object-like macro
8730 definitions, it should be:
8732 <macro name> " " <definition>
8734 For function-like macro definitions, it should be:
8736 <macro name> "() " <definition>
8738 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
8740 Spaces may appear only where explicitly indicated, and in the
8743 The Dwarf 2 spec says that an object-like macro's name is always
8744 followed by a space, but versions of GCC around March 2002 omit
8745 the space when the macro's definition is the empty string.
8747 The Dwarf 2 spec says that there should be no spaces between the
8748 formal arguments in a function-like macro's formal argument list,
8749 but versions of GCC around March 2002 include spaces after the
8753 /* Find the extent of the macro name. The macro name is terminated
8754 by either a space or null character (for an object-like macro) or
8755 an opening paren (for a function-like macro). */
8756 for (p
= body
; *p
; p
++)
8757 if (*p
== ' ' || *p
== '(')
8760 if (*p
== ' ' || *p
== '\0')
8762 /* It's an object-like macro. */
8763 int name_len
= p
- body
;
8764 char *name
= copy_string (body
, name_len
);
8765 const char *replacement
;
8768 replacement
= body
+ name_len
+ 1;
8771 dwarf2_macro_malformed_definition_complaint (body
);
8772 replacement
= body
+ name_len
;
8775 macro_define_object (file
, line
, name
, replacement
);
8781 /* It's a function-like macro. */
8782 char *name
= copy_string (body
, p
- body
);
8785 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
8789 p
= consume_improper_spaces (p
, body
);
8791 /* Parse the formal argument list. */
8792 while (*p
&& *p
!= ')')
8794 /* Find the extent of the current argument name. */
8795 const char *arg_start
= p
;
8797 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
8800 if (! *p
|| p
== arg_start
)
8801 dwarf2_macro_malformed_definition_complaint (body
);
8804 /* Make sure argv has room for the new argument. */
8805 if (argc
>= argv_size
)
8808 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
8811 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
8814 p
= consume_improper_spaces (p
, body
);
8816 /* Consume the comma, if present. */
8821 p
= consume_improper_spaces (p
, body
);
8830 /* Perfectly formed definition, no complaints. */
8831 macro_define_function (file
, line
, name
,
8832 argc
, (const char **) argv
,
8834 else if (*p
== '\0')
8836 /* Complain, but do define it. */
8837 dwarf2_macro_malformed_definition_complaint (body
);
8838 macro_define_function (file
, line
, name
,
8839 argc
, (const char **) argv
,
8843 /* Just complain. */
8844 dwarf2_macro_malformed_definition_complaint (body
);
8847 /* Just complain. */
8848 dwarf2_macro_malformed_definition_complaint (body
);
8854 for (i
= 0; i
< argc
; i
++)
8860 dwarf2_macro_malformed_definition_complaint (body
);
8865 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
8866 char *comp_dir
, bfd
*abfd
,
8867 struct dwarf2_cu
*cu
)
8869 char *mac_ptr
, *mac_end
;
8870 struct macro_source_file
*current_file
= 0;
8872 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
8874 complaint (&symfile_complaints
, "missing .debug_macinfo section");
8878 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
8879 mac_end
= dwarf2_per_objfile
->macinfo_buffer
8880 + dwarf2_per_objfile
->macinfo_size
;
8884 enum dwarf_macinfo_record_type macinfo_type
;
8886 /* Do we at least have room for a macinfo type byte? */
8887 if (mac_ptr
>= mac_end
)
8889 dwarf2_macros_too_long_complaint ();
8893 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
8896 switch (macinfo_type
)
8898 /* A zero macinfo type indicates the end of the macro
8903 case DW_MACINFO_define
:
8904 case DW_MACINFO_undef
:
8910 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8911 mac_ptr
+= bytes_read
;
8912 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
8913 mac_ptr
+= bytes_read
;
8916 complaint (&symfile_complaints
,
8917 "debug info gives macro %s outside of any file: %s",
8919 DW_MACINFO_define
? "definition" : macinfo_type
==
8920 DW_MACINFO_undef
? "undefinition" :
8921 "something-or-other", body
);
8924 if (macinfo_type
== DW_MACINFO_define
)
8925 parse_macro_definition (current_file
, line
, body
);
8926 else if (macinfo_type
== DW_MACINFO_undef
)
8927 macro_undef (current_file
, line
, body
);
8932 case DW_MACINFO_start_file
:
8937 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8938 mac_ptr
+= bytes_read
;
8939 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8940 mac_ptr
+= bytes_read
;
8942 current_file
= macro_start_file (file
, line
,
8943 current_file
, comp_dir
,
8948 case DW_MACINFO_end_file
:
8950 complaint (&symfile_complaints
,
8951 "macro debug info has an unmatched `close_file' directive");
8954 current_file
= current_file
->included_by
;
8957 enum dwarf_macinfo_record_type next_type
;
8959 /* GCC circa March 2002 doesn't produce the zero
8960 type byte marking the end of the compilation
8961 unit. Complain if it's not there, but exit no
8964 /* Do we at least have room for a macinfo type byte? */
8965 if (mac_ptr
>= mac_end
)
8967 dwarf2_macros_too_long_complaint ();
8971 /* We don't increment mac_ptr here, so this is just
8973 next_type
= read_1_byte (abfd
, mac_ptr
);
8975 complaint (&symfile_complaints
,
8976 "no terminating 0-type entry for macros in `.debug_macinfo' section");
8983 case DW_MACINFO_vendor_ext
:
8989 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8990 mac_ptr
+= bytes_read
;
8991 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
8992 mac_ptr
+= bytes_read
;
8994 /* We don't recognize any vendor extensions. */
9001 /* Check if the attribute's form is a DW_FORM_block*
9002 if so return true else false. */
9004 attr_form_is_block (struct attribute
*attr
)
9006 return (attr
== NULL
? 0 :
9007 attr
->form
== DW_FORM_block1
9008 || attr
->form
== DW_FORM_block2
9009 || attr
->form
== DW_FORM_block4
9010 || attr
->form
== DW_FORM_block
);
9014 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
9015 struct dwarf2_cu
*cu
)
9017 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
9019 struct dwarf2_loclist_baton
*baton
;
9021 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9022 sizeof (struct dwarf2_loclist_baton
));
9023 baton
->objfile
= cu
->objfile
;
9025 /* We don't know how long the location list is, but make sure we
9026 don't run off the edge of the section. */
9027 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
9028 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
9029 baton
->base_address
= cu
->header
.base_address
;
9030 if (cu
->header
.base_known
== 0)
9031 complaint (&symfile_complaints
,
9032 "Location list used without specifying the CU base address.");
9034 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
9035 SYMBOL_LOCATION_BATON (sym
) = baton
;
9039 struct dwarf2_locexpr_baton
*baton
;
9041 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9042 sizeof (struct dwarf2_locexpr_baton
));
9043 baton
->objfile
= cu
->objfile
;
9045 if (attr_form_is_block (attr
))
9047 /* Note that we're just copying the block's data pointer
9048 here, not the actual data. We're still pointing into the
9049 info_buffer for SYM's objfile; right now we never release
9050 that buffer, but when we do clean up properly this may
9052 baton
->size
= DW_BLOCK (attr
)->size
;
9053 baton
->data
= DW_BLOCK (attr
)->data
;
9057 dwarf2_invalid_attrib_class_complaint ("location description",
9058 SYMBOL_NATURAL_NAME (sym
));
9063 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
9064 SYMBOL_LOCATION_BATON (sym
) = baton
;
9068 /* Locate the compilation unit from CU's objfile which contains the
9069 DIE at OFFSET. Returns NULL on failure. */
9071 static struct dwarf2_per_cu_data
*
9072 dwarf2_find_containing_comp_unit (unsigned long offset
,
9073 struct objfile
*objfile
)
9075 struct dwarf2_per_cu_data
*this_cu
;
9078 if (dwarf2_per_objfile
->all_comp_units
== NULL
)
9079 error ("Dwarf Error: offset 0x%lx points outside this "
9080 "compilation unit [in module %s]",
9081 offset
, bfd_get_filename (objfile
->obfd
));
9084 high
= dwarf2_per_objfile
->n_comp_units
- 1;
9087 int mid
= low
+ (high
- low
) / 2;
9088 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
9093 gdb_assert (low
== high
);
9094 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
9096 gdb_assert (low
> 0);
9097 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
9098 return dwarf2_per_objfile
->all_comp_units
[low
-1];
9102 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
9103 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
9104 && offset
>= this_cu
->offset
+ this_cu
->length
)
9105 error ("invalid dwarf2 offset %ld", offset
);
9106 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
9111 static struct dwarf2_per_cu_data
*
9112 dwarf2_find_comp_unit (unsigned long offset
, struct objfile
*objfile
)
9114 struct dwarf2_per_cu_data
*this_cu
;
9115 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
9116 if (this_cu
->offset
!= offset
)
9117 error ("no compilation unit with offset %ld\n", offset
);
9121 /* Release one cached compilation unit, CU. We unlink it from the tree
9122 of compilation units, but we don't remove it from the read_in_chain;
9123 the caller is responsible for that. */
9126 free_one_comp_unit (void *data
)
9128 struct dwarf2_cu
*cu
= data
;
9130 if (cu
->per_cu
!= NULL
)
9131 cu
->per_cu
->cu
= NULL
;
9134 obstack_free (&cu
->comp_unit_obstack
, NULL
);
9139 /* This cleanup function is passed the address of a dwarf2_cu on the stack
9140 when we're finished with it. We can't free the pointer itself, but be
9141 sure to unlink it from the cache. Also release any associated storage
9142 and perform cache maintenance.
9144 Only used during partial symbol parsing. */
9147 free_stack_comp_unit (void *data
)
9149 struct dwarf2_cu
*cu
= data
;
9151 obstack_free (&cu
->comp_unit_obstack
, NULL
);
9152 cu
->partial_dies
= NULL
;
9154 if (cu
->per_cu
!= NULL
)
9156 /* This compilation unit is on the stack in our caller, so we
9157 should not xfree it. Just unlink it. */
9158 cu
->per_cu
->cu
= NULL
;
9161 /* If we had a per-cu pointer, then we may have other compilation
9162 units loaded, so age them now. */
9163 age_cached_comp_units ();
9167 /* Free all cached compilation units. */
9170 free_cached_comp_units (void *data
)
9172 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
9174 per_cu
= dwarf2_per_objfile
->read_in_chain
;
9175 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
9176 while (per_cu
!= NULL
)
9178 struct dwarf2_per_cu_data
*next_cu
;
9180 next_cu
= per_cu
->cu
->read_in_chain
;
9182 free_one_comp_unit (per_cu
->cu
);
9183 *last_chain
= next_cu
;
9189 /* Increase the age counter on each cached compilation unit, and free
9190 any that are too old. */
9193 age_cached_comp_units (void)
9195 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
9197 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
9198 per_cu
= dwarf2_per_objfile
->read_in_chain
;
9199 while (per_cu
!= NULL
)
9201 per_cu
->cu
->last_used
++;
9202 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
9203 dwarf2_mark (per_cu
->cu
);
9204 per_cu
= per_cu
->cu
->read_in_chain
;
9207 per_cu
= dwarf2_per_objfile
->read_in_chain
;
9208 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
9209 while (per_cu
!= NULL
)
9211 struct dwarf2_per_cu_data
*next_cu
;
9213 next_cu
= per_cu
->cu
->read_in_chain
;
9215 if (!per_cu
->cu
->mark
)
9217 free_one_comp_unit (per_cu
->cu
);
9218 *last_chain
= next_cu
;
9221 last_chain
= &per_cu
->cu
->read_in_chain
;
9227 /* Remove a single compilation unit from the cache. */
9230 free_one_cached_comp_unit (void *target_cu
)
9232 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
9234 per_cu
= dwarf2_per_objfile
->read_in_chain
;
9235 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
9236 while (per_cu
!= NULL
)
9238 struct dwarf2_per_cu_data
*next_cu
;
9240 next_cu
= per_cu
->cu
->read_in_chain
;
9242 if (per_cu
->cu
== target_cu
)
9244 free_one_comp_unit (per_cu
->cu
);
9245 *last_chain
= next_cu
;
9249 last_chain
= &per_cu
->cu
->read_in_chain
;
9255 /* Set the mark field in CU and in every other compilation unit in the
9256 cache that we must keep because we are keeping CU. */
9259 dwarf2_mark (struct dwarf2_cu
*cu
)
9267 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
9271 per_cu
->cu
->mark
= 0;
9272 per_cu
= per_cu
->cu
->read_in_chain
;
9276 /* Allocation function for the libiberty hash table which uses an
9280 hashtab_obstack_allocate (void *data
, size_t size
, size_t count
)
9282 unsigned int total
= size
* count
;
9283 void *ptr
= obstack_alloc ((struct obstack
*) data
, total
);
9284 memset (ptr
, 0, total
);
9288 /* Trivial deallocation function for the libiberty splay tree and hash
9289 table - don't deallocate anything. Rely on later deletion of the
9293 dummy_obstack_deallocate (void *object
, void *data
)
9298 /* Trivial hash function for partial_die_info: the hash value of a DIE
9299 is its offset in .debug_info for this objfile. */
9302 partial_die_hash (const void *item
)
9304 const struct partial_die_info
*part_die
= item
;
9305 return part_die
->offset
;
9308 /* Trivial comparison function for partial_die_info structures: two DIEs
9309 are equal if they have the same offset. */
9312 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
9314 const struct partial_die_info
*part_die_lhs
= item_lhs
;
9315 const struct partial_die_info
*part_die_rhs
= item_rhs
;
9316 return part_die_lhs
->offset
== part_die_rhs
->offset
;
9319 static struct cmd_list_element
*set_dwarf2_cmdlist
;
9320 static struct cmd_list_element
*show_dwarf2_cmdlist
;
9323 set_dwarf2_cmd (char *args
, int from_tty
)
9325 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
9329 show_dwarf2_cmd (char *args
, int from_tty
)
9331 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
9334 void _initialize_dwarf2_read (void);
9337 _initialize_dwarf2_read (void)
9339 dwarf2_objfile_data_key
= register_objfile_data ();
9341 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
,
9342 "Set DWARF 2 specific variables.\n"
9343 "Configure DWARF 2 variables such as the cache size",
9344 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
9345 0/*allow-unknown*/, &maintenance_set_cmdlist
);
9347 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
,
9348 "Show DWARF 2 specific variables\n"
9349 "Show DWARF 2 variables such as the cache size",
9350 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
9351 0/*allow-unknown*/, &maintenance_show_cmdlist
);
9353 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
9354 &dwarf2_max_cache_age
,
9355 "Set the upper bound on the age of cached "
9356 "dwarf2 compilation units.",
9357 "Show the upper bound on the age of cached "
9358 "dwarf2 compilation units.",
9359 "A higher limit means that cached "
9360 "compilation units will be stored\n"
9361 "in memory longer, and more total memory will "
9362 "be used. Zero disables\n"
9363 "caching, which can slow down startup.",
9364 "The upper bound on the age of cached "
9365 "dwarf2 compilation units is %d.",
9366 NULL
, NULL
, &set_dwarf2_cmdlist
,
9367 &show_dwarf2_cmdlist
);