1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
37 #include "expression.h"
38 #include "filenames.h" /* for DOSish file names */
41 #include "complaints.h"
43 #include "dwarf2expr.h"
44 #include "dwarf2loc.h"
45 #include "cp-support.h"
51 #include "typeprint.h"
56 #include "gdb_string.h"
57 #include "gdb_assert.h"
58 #include <sys/types.h>
65 #define MAP_FAILED ((void *) -1)
70 /* .debug_info header for a compilation unit
71 Because of alignment constraints, this structure has padding and cannot
72 be mapped directly onto the beginning of the .debug_info section. */
73 typedef struct comp_unit_header
75 unsigned int length
; /* length of the .debug_info
77 unsigned short version
; /* version number -- 2 for DWARF
79 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
80 unsigned char addr_size
; /* byte size of an address -- 4 */
83 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
86 /* .debug_pubnames header
87 Because of alignment constraints, this structure has padding and cannot
88 be mapped directly onto the beginning of the .debug_info section. */
89 typedef struct pubnames_header
91 unsigned int length
; /* length of the .debug_pubnames
93 unsigned char version
; /* version number -- 2 for DWARF
95 unsigned int info_offset
; /* offset into .debug_info section */
96 unsigned int info_size
; /* byte size of .debug_info section
100 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
102 /* .debug_pubnames header
103 Because of alignment constraints, this structure has padding and cannot
104 be mapped directly onto the beginning of the .debug_info section. */
105 typedef struct aranges_header
107 unsigned int length
; /* byte len of the .debug_aranges
109 unsigned short version
; /* version number -- 2 for DWARF
111 unsigned int info_offset
; /* offset into .debug_info section */
112 unsigned char addr_size
; /* byte size of an address */
113 unsigned char seg_size
; /* byte size of segment descriptor */
116 #define _ACTUAL_ARANGES_HEADER_SIZE 12
118 /* .debug_line statement program prologue
119 Because of alignment constraints, this structure has padding and cannot
120 be mapped directly onto the beginning of the .debug_info section. */
121 typedef struct statement_prologue
123 unsigned int total_length
; /* byte length of the statement
125 unsigned short version
; /* version number -- 2 for DWARF
127 unsigned int prologue_length
; /* # bytes between prologue &
129 unsigned char minimum_instruction_length
; /* byte size of
131 unsigned char default_is_stmt
; /* initial value of is_stmt
134 unsigned char line_range
;
135 unsigned char opcode_base
; /* number assigned to first special
137 unsigned char *standard_opcode_lengths
;
141 /* When non-zero, dump DIEs after they are read in. */
142 static int dwarf2_die_debug
= 0;
146 /* When set, the file that we're processing is known to have debugging
147 info for C++ namespaces. GCC 3.3.x did not produce this information,
148 but later versions do. */
150 static int processing_has_namespace_info
;
152 static const struct objfile_data
*dwarf2_objfile_data_key
;
154 struct dwarf2_section_info
162 struct dwarf2_per_objfile
164 struct dwarf2_section_info info
;
165 struct dwarf2_section_info abbrev
;
166 struct dwarf2_section_info line
;
167 struct dwarf2_section_info pubnames
;
168 struct dwarf2_section_info aranges
;
169 struct dwarf2_section_info loc
;
170 struct dwarf2_section_info macinfo
;
171 struct dwarf2_section_info str
;
172 struct dwarf2_section_info ranges
;
173 struct dwarf2_section_info types
;
174 struct dwarf2_section_info frame
;
175 struct dwarf2_section_info eh_frame
;
177 /* A list of all the compilation units. This is used to locate
178 the target compilation unit of a particular reference. */
179 struct dwarf2_per_cu_data
**all_comp_units
;
181 /* The number of compilation units in ALL_COMP_UNITS. */
184 /* A chain of compilation units that are currently read in, so that
185 they can be freed later. */
186 struct dwarf2_per_cu_data
*read_in_chain
;
188 /* A table mapping .debug_types signatures to its signatured_type entry.
189 This is NULL if the .debug_types section hasn't been read in yet. */
190 htab_t signatured_types
;
192 /* A flag indicating wether this objfile has a section loaded at a
194 int has_section_at_zero
;
197 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
199 /* names of the debugging sections */
201 /* Note that if the debugging section has been compressed, it might
202 have a name like .zdebug_info. */
204 #define INFO_SECTION "debug_info"
205 #define ABBREV_SECTION "debug_abbrev"
206 #define LINE_SECTION "debug_line"
207 #define PUBNAMES_SECTION "debug_pubnames"
208 #define ARANGES_SECTION "debug_aranges"
209 #define LOC_SECTION "debug_loc"
210 #define MACINFO_SECTION "debug_macinfo"
211 #define STR_SECTION "debug_str"
212 #define RANGES_SECTION "debug_ranges"
213 #define TYPES_SECTION "debug_types"
214 #define FRAME_SECTION "debug_frame"
215 #define EH_FRAME_SECTION "eh_frame"
217 /* local data types */
219 /* We hold several abbreviation tables in memory at the same time. */
220 #ifndef ABBREV_HASH_SIZE
221 #define ABBREV_HASH_SIZE 121
224 /* The data in a compilation unit header, after target2host
225 translation, looks like this. */
226 struct comp_unit_head
230 unsigned char addr_size
;
231 unsigned char signed_addr_p
;
232 unsigned int abbrev_offset
;
234 /* Size of file offsets; either 4 or 8. */
235 unsigned int offset_size
;
237 /* Size of the length field; either 4 or 12. */
238 unsigned int initial_length_size
;
240 /* Offset to the first byte of this compilation unit header in the
241 .debug_info section, for resolving relative reference dies. */
244 /* Offset to first die in this cu from the start of the cu.
245 This will be the first byte following the compilation unit header. */
246 unsigned int first_die_offset
;
249 /* Internal state when decoding a particular compilation unit. */
252 /* The objfile containing this compilation unit. */
253 struct objfile
*objfile
;
255 /* The header of the compilation unit. */
256 struct comp_unit_head header
;
258 /* Base address of this compilation unit. */
259 CORE_ADDR base_address
;
261 /* Non-zero if base_address has been set. */
264 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
266 /* The language we are debugging. */
267 enum language language
;
268 const struct language_defn
*language_defn
;
270 const char *producer
;
272 /* The generic symbol table building routines have separate lists for
273 file scope symbols and all all other scopes (local scopes). So
274 we need to select the right one to pass to add_symbol_to_list().
275 We do it by keeping a pointer to the correct list in list_in_scope.
277 FIXME: The original dwarf code just treated the file scope as the
278 first local scope, and all other local scopes as nested local
279 scopes, and worked fine. Check to see if we really need to
280 distinguish these in buildsym.c. */
281 struct pending
**list_in_scope
;
283 /* DWARF abbreviation table associated with this compilation unit. */
284 struct abbrev_info
**dwarf2_abbrevs
;
286 /* Storage for the abbrev table. */
287 struct obstack abbrev_obstack
;
289 /* Hash table holding all the loaded partial DIEs. */
292 /* Storage for things with the same lifetime as this read-in compilation
293 unit, including partial DIEs. */
294 struct obstack comp_unit_obstack
;
296 /* When multiple dwarf2_cu structures are living in memory, this field
297 chains them all together, so that they can be released efficiently.
298 We will probably also want a generation counter so that most-recently-used
299 compilation units are cached... */
300 struct dwarf2_per_cu_data
*read_in_chain
;
302 /* Backchain to our per_cu entry if the tree has been built. */
303 struct dwarf2_per_cu_data
*per_cu
;
305 /* Pointer to the die -> type map. Although it is stored
306 permanently in per_cu, we copy it here to avoid double
310 /* How many compilation units ago was this CU last referenced? */
313 /* A hash table of die offsets for following references. */
316 /* Full DIEs if read in. */
317 struct die_info
*dies
;
319 /* A set of pointers to dwarf2_per_cu_data objects for compilation
320 units referenced by this one. Only set during full symbol processing;
321 partial symbol tables do not have dependencies. */
324 /* Header data from the line table, during full symbol processing. */
325 struct line_header
*line_header
;
327 /* Mark used when releasing cached dies. */
328 unsigned int mark
: 1;
330 /* This flag will be set if this compilation unit might include
331 inter-compilation-unit references. */
332 unsigned int has_form_ref_addr
: 1;
334 /* This flag will be set if this compilation unit includes any
335 DW_TAG_namespace DIEs. If we know that there are explicit
336 DIEs for namespaces, we don't need to try to infer them
337 from mangled names. */
338 unsigned int has_namespace_info
: 1;
341 /* Persistent data held for a compilation unit, even when not
342 processing it. We put a pointer to this structure in the
343 read_symtab_private field of the psymtab. If we encounter
344 inter-compilation-unit references, we also maintain a sorted
345 list of all compilation units. */
347 struct dwarf2_per_cu_data
349 /* The start offset and length of this compilation unit. 2**29-1
350 bytes should suffice to store the length of any compilation unit
351 - if it doesn't, GDB will fall over anyway.
352 NOTE: Unlike comp_unit_head.length, this length includes
353 initial_length_size. */
355 unsigned int length
: 29;
357 /* Flag indicating this compilation unit will be read in before
358 any of the current compilation units are processed. */
359 unsigned int queued
: 1;
361 /* This flag will be set if we need to load absolutely all DIEs
362 for this compilation unit, instead of just the ones we think
363 are interesting. It gets set if we look for a DIE in the
364 hash table and don't find it. */
365 unsigned int load_all_dies
: 1;
367 /* Non-zero if this CU is from .debug_types.
368 Otherwise it's from .debug_info. */
369 unsigned int from_debug_types
: 1;
371 /* Set iff currently read in. */
372 struct dwarf2_cu
*cu
;
374 /* If full symbols for this CU have been read in, then this field
375 holds a map of DIE offsets to types. It isn't always possible
376 to reconstruct this information later, so we have to preserve
380 /* The partial symbol table associated with this compilation unit,
381 or NULL for partial units (which do not have an associated
383 struct partial_symtab
*psymtab
;
386 /* Entry in the signatured_types hash table. */
388 struct signatured_type
392 /* Offset in .debug_types of the TU (type_unit) for this type. */
395 /* Offset in .debug_types of the type defined by this TU. */
396 unsigned int type_offset
;
398 /* The CU(/TU) of this type. */
399 struct dwarf2_per_cu_data per_cu
;
402 /* Struct used to pass misc. parameters to read_die_and_children, et. al.
403 which are used for both .debug_info and .debug_types dies.
404 All parameters here are unchanging for the life of the call.
405 This struct exists to abstract away the constant parameters of
408 struct die_reader_specs
410 /* The bfd of this objfile. */
413 /* The CU of the DIE we are parsing. */
414 struct dwarf2_cu
*cu
;
416 /* Pointer to start of section buffer.
417 This is either the start of .debug_info or .debug_types. */
418 const gdb_byte
*buffer
;
421 /* The line number information for a compilation unit (found in the
422 .debug_line section) begins with a "statement program header",
423 which contains the following information. */
426 unsigned int total_length
;
427 unsigned short version
;
428 unsigned int header_length
;
429 unsigned char minimum_instruction_length
;
430 unsigned char default_is_stmt
;
432 unsigned char line_range
;
433 unsigned char opcode_base
;
435 /* standard_opcode_lengths[i] is the number of operands for the
436 standard opcode whose value is i. This means that
437 standard_opcode_lengths[0] is unused, and the last meaningful
438 element is standard_opcode_lengths[opcode_base - 1]. */
439 unsigned char *standard_opcode_lengths
;
441 /* The include_directories table. NOTE! These strings are not
442 allocated with xmalloc; instead, they are pointers into
443 debug_line_buffer. If you try to free them, `free' will get
445 unsigned int num_include_dirs
, include_dirs_size
;
448 /* The file_names table. NOTE! These strings are not allocated
449 with xmalloc; instead, they are pointers into debug_line_buffer.
450 Don't try to free them directly. */
451 unsigned int num_file_names
, file_names_size
;
455 unsigned int dir_index
;
456 unsigned int mod_time
;
458 int included_p
; /* Non-zero if referenced by the Line Number Program. */
459 struct symtab
*symtab
; /* The associated symbol table, if any. */
462 /* The start and end of the statement program following this
463 header. These point into dwarf2_per_objfile->line_buffer. */
464 gdb_byte
*statement_program_start
, *statement_program_end
;
467 /* When we construct a partial symbol table entry we only
468 need this much information. */
469 struct partial_die_info
471 /* Offset of this DIE. */
474 /* DWARF-2 tag for this DIE. */
475 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
477 /* Assorted flags describing the data found in this DIE. */
478 unsigned int has_children
: 1;
479 unsigned int is_external
: 1;
480 unsigned int is_declaration
: 1;
481 unsigned int has_type
: 1;
482 unsigned int has_specification
: 1;
483 unsigned int has_pc_info
: 1;
485 /* Flag set if the SCOPE field of this structure has been
487 unsigned int scope_set
: 1;
489 /* Flag set if the DIE has a byte_size attribute. */
490 unsigned int has_byte_size
: 1;
492 /* The name of this DIE. Normally the value of DW_AT_name, but
493 sometimes a default name for unnamed DIEs. */
496 /* The scope to prepend to our children. This is generally
497 allocated on the comp_unit_obstack, so will disappear
498 when this compilation unit leaves the cache. */
501 /* The location description associated with this DIE, if any. */
502 struct dwarf_block
*locdesc
;
504 /* If HAS_PC_INFO, the PC range associated with this DIE. */
508 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
509 DW_AT_sibling, if any. */
512 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
513 DW_AT_specification (or DW_AT_abstract_origin or
515 unsigned int spec_offset
;
517 /* Pointers to this DIE's parent, first child, and next sibling,
519 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
522 /* This data structure holds the information of an abbrev. */
525 unsigned int number
; /* number identifying abbrev */
526 enum dwarf_tag tag
; /* dwarf tag */
527 unsigned short has_children
; /* boolean */
528 unsigned short num_attrs
; /* number of attributes */
529 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
530 struct abbrev_info
*next
; /* next in chain */
535 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
536 ENUM_BITFIELD(dwarf_form
) form
: 16;
539 /* Attributes have a name and a value */
542 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
543 ENUM_BITFIELD(dwarf_form
) form
: 15;
545 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
546 field should be in u.str (existing only for DW_STRING) but it is kept
547 here for better struct attribute alignment. */
548 unsigned int string_is_canonical
: 1;
553 struct dwarf_block
*blk
;
557 struct signatured_type
*signatured_type
;
562 /* This data structure holds a complete die structure. */
565 /* DWARF-2 tag for this DIE. */
566 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
568 /* Number of attributes */
569 unsigned short num_attrs
;
574 /* Offset in .debug_info or .debug_types section. */
577 /* The dies in a compilation unit form an n-ary tree. PARENT
578 points to this die's parent; CHILD points to the first child of
579 this node; and all the children of a given node are chained
580 together via their SIBLING fields, terminated by a die whose
582 struct die_info
*child
; /* Its first child, if any. */
583 struct die_info
*sibling
; /* Its next sibling, if any. */
584 struct die_info
*parent
; /* Its parent, if any. */
586 /* An array of attributes, with NUM_ATTRS elements. There may be
587 zero, but it's not common and zero-sized arrays are not
588 sufficiently portable C. */
589 struct attribute attrs
[1];
592 struct function_range
595 CORE_ADDR lowpc
, highpc
;
597 struct function_range
*next
;
600 /* Get at parts of an attribute structure */
602 #define DW_STRING(attr) ((attr)->u.str)
603 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
604 #define DW_UNSND(attr) ((attr)->u.unsnd)
605 #define DW_BLOCK(attr) ((attr)->u.blk)
606 #define DW_SND(attr) ((attr)->u.snd)
607 #define DW_ADDR(attr) ((attr)->u.addr)
608 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
610 /* Blocks are a bunch of untyped bytes. */
617 #ifndef ATTR_ALLOC_CHUNK
618 #define ATTR_ALLOC_CHUNK 4
621 /* Allocate fields for structs, unions and enums in this size. */
622 #ifndef DW_FIELD_ALLOC_CHUNK
623 #define DW_FIELD_ALLOC_CHUNK 4
626 /* A zeroed version of a partial die for initialization purposes. */
627 static struct partial_die_info zeroed_partial_die
;
629 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
630 but this would require a corresponding change in unpack_field_as_long
632 static int bits_per_byte
= 8;
634 /* The routines that read and process dies for a C struct or C++ class
635 pass lists of data member fields and lists of member function fields
636 in an instance of a field_info structure, as defined below. */
639 /* List of data member and baseclasses fields. */
642 struct nextfield
*next
;
647 *fields
, *baseclasses
;
649 /* Number of fields (including baseclasses). */
652 /* Number of baseclasses. */
655 /* Set if the accesibility of one of the fields is not public. */
656 int non_public_fields
;
658 /* Member function fields array, entries are allocated in the order they
659 are encountered in the object file. */
662 struct nextfnfield
*next
;
663 struct fn_field fnfield
;
667 /* Member function fieldlist array, contains name of possibly overloaded
668 member function, number of overloaded member functions and a pointer
669 to the head of the member function field chain. */
674 struct nextfnfield
*head
;
678 /* Number of entries in the fnfieldlists array. */
682 /* One item on the queue of compilation units to read in full symbols
684 struct dwarf2_queue_item
686 struct dwarf2_per_cu_data
*per_cu
;
687 struct dwarf2_queue_item
*next
;
690 /* The current queue. */
691 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
693 /* Loaded secondary compilation units are kept in memory until they
694 have not been referenced for the processing of this many
695 compilation units. Set this to zero to disable caching. Cache
696 sizes of up to at least twenty will improve startup time for
697 typical inter-CU-reference binaries, at an obvious memory cost. */
698 static int dwarf2_max_cache_age
= 5;
700 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
701 struct cmd_list_element
*c
, const char *value
)
703 fprintf_filtered (file
, _("\
704 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
709 /* Various complaints about symbol reading that don't abort the process */
712 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
714 complaint (&symfile_complaints
,
715 _("statement list doesn't fit in .debug_line section"));
719 dwarf2_debug_line_missing_file_complaint (void)
721 complaint (&symfile_complaints
,
722 _(".debug_line section has line data without a file"));
726 dwarf2_debug_line_missing_end_sequence_complaint (void)
728 complaint (&symfile_complaints
,
729 _(".debug_line section has line program sequence without an end"));
733 dwarf2_complex_location_expr_complaint (void)
735 complaint (&symfile_complaints
, _("location expression too complex"));
739 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
742 complaint (&symfile_complaints
,
743 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
748 dwarf2_macros_too_long_complaint (void)
750 complaint (&symfile_complaints
,
751 _("macro info runs off end of `.debug_macinfo' section"));
755 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
757 complaint (&symfile_complaints
,
758 _("macro debug info contains a malformed macro definition:\n`%s'"),
763 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
765 complaint (&symfile_complaints
,
766 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
769 /* local function prototypes */
771 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
774 static void dwarf2_build_psymtabs_easy (struct objfile
*);
777 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
780 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
782 struct partial_symtab
*);
784 static void dwarf2_build_psymtabs_hard (struct objfile
*);
786 static void scan_partial_symbols (struct partial_die_info
*,
787 CORE_ADDR
*, CORE_ADDR
*,
788 int, struct dwarf2_cu
*);
790 static void add_partial_symbol (struct partial_die_info
*,
793 static void add_partial_namespace (struct partial_die_info
*pdi
,
794 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
795 int need_pc
, struct dwarf2_cu
*cu
);
797 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
798 CORE_ADDR
*highpc
, int need_pc
,
799 struct dwarf2_cu
*cu
);
801 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
802 struct dwarf2_cu
*cu
);
804 static void add_partial_subprogram (struct partial_die_info
*pdi
,
805 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
806 int need_pc
, struct dwarf2_cu
*cu
);
808 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
809 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
810 bfd
*abfd
, struct dwarf2_cu
*cu
);
812 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
814 static void psymtab_to_symtab_1 (struct partial_symtab
*);
816 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
818 static void dwarf2_free_abbrev_table (void *);
820 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
823 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
826 static struct partial_die_info
*load_partial_dies (bfd
*,
827 gdb_byte
*, gdb_byte
*,
828 int, struct dwarf2_cu
*);
830 static gdb_byte
*read_partial_die (struct partial_die_info
*,
831 struct abbrev_info
*abbrev
,
833 gdb_byte
*, gdb_byte
*,
836 static struct partial_die_info
*find_partial_die (unsigned int,
839 static void fixup_partial_die (struct partial_die_info
*,
842 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
843 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
845 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
846 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
848 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
850 static int read_1_signed_byte (bfd
*, gdb_byte
*);
852 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
854 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
856 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
858 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
861 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
863 static LONGEST read_checked_initial_length_and_offset
864 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
865 unsigned int *, unsigned int *);
867 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
870 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
872 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
874 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
876 static char *read_indirect_string (bfd
*, gdb_byte
*,
877 const struct comp_unit_head
*,
880 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
882 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
884 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
886 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
888 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
891 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
895 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
896 struct dwarf2_cu
*cu
);
898 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
900 static struct die_info
*die_specification (struct die_info
*die
,
901 struct dwarf2_cu
**);
903 static void free_line_header (struct line_header
*lh
);
905 static void add_file_name (struct line_header
*, char *, unsigned int,
906 unsigned int, unsigned int);
908 static struct line_header
*(dwarf_decode_line_header
909 (unsigned int offset
,
910 bfd
*abfd
, struct dwarf2_cu
*cu
));
912 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
913 struct dwarf2_cu
*, struct partial_symtab
*);
915 static void dwarf2_start_subfile (char *, char *, char *);
917 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
920 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
923 static void dwarf2_const_value_data (struct attribute
*attr
,
927 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
929 static int need_gnat_info (struct dwarf2_cu
*);
931 static struct type
*die_descriptive_type (struct die_info
*, struct dwarf2_cu
*);
933 static void set_descriptive_type (struct type
*, struct die_info
*,
936 static struct type
*die_containing_type (struct die_info
*,
939 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
941 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
943 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
945 static char *typename_concat (struct obstack
*,
950 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
952 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
954 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
956 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
958 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
959 struct dwarf2_cu
*, struct partial_symtab
*);
961 static int dwarf2_get_pc_bounds (struct die_info
*,
962 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
963 struct partial_symtab
*);
965 static void get_scope_pc_bounds (struct die_info
*,
966 CORE_ADDR
*, CORE_ADDR
*,
969 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
970 CORE_ADDR
, struct dwarf2_cu
*);
972 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
975 static void dwarf2_attach_fields_to_type (struct field_info
*,
976 struct type
*, struct dwarf2_cu
*);
978 static void dwarf2_add_member_fn (struct field_info
*,
979 struct die_info
*, struct type
*,
982 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
983 struct type
*, struct dwarf2_cu
*);
985 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
987 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
989 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
991 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
993 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
995 static const char *namespace_name (struct die_info
*die
,
996 int *is_anonymous
, struct dwarf2_cu
*);
998 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1000 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1002 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1003 struct dwarf2_cu
*);
1005 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1007 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1009 gdb_byte
**new_info_ptr
,
1010 struct die_info
*parent
);
1012 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1014 gdb_byte
**new_info_ptr
,
1015 struct die_info
*parent
);
1017 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1019 gdb_byte
**new_info_ptr
,
1020 struct die_info
*parent
);
1022 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1023 struct die_info
**, gdb_byte
*,
1026 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1028 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1031 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1033 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1034 struct dwarf2_cu
**);
1036 static char *dwarf_tag_name (unsigned int);
1038 static char *dwarf_attr_name (unsigned int);
1040 static char *dwarf_form_name (unsigned int);
1042 static char *dwarf_stack_op_name (unsigned int);
1044 static char *dwarf_bool_name (unsigned int);
1046 static char *dwarf_type_encoding_name (unsigned int);
1049 static char *dwarf_cfi_name (unsigned int);
1052 static struct die_info
*sibling_die (struct die_info
*);
1054 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1056 static void dump_die_for_error (struct die_info
*);
1058 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1061 /*static*/ void dump_die (struct die_info
*, int max_level
);
1063 static void store_in_ref_table (struct die_info
*,
1064 struct dwarf2_cu
*);
1066 static int is_ref_attr (struct attribute
*);
1068 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1070 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1072 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1074 struct dwarf2_cu
**);
1076 static struct die_info
*follow_die_ref (struct die_info
*,
1078 struct dwarf2_cu
**);
1080 static struct die_info
*follow_die_sig (struct die_info
*,
1082 struct dwarf2_cu
**);
1084 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1085 unsigned int offset
);
1087 static void read_signatured_type (struct objfile
*,
1088 struct signatured_type
*type_sig
);
1090 /* memory allocation interface */
1092 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1094 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1096 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1098 static void initialize_cu_func_list (struct dwarf2_cu
*);
1100 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1101 struct dwarf2_cu
*);
1103 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1104 char *, bfd
*, struct dwarf2_cu
*);
1106 static int attr_form_is_block (struct attribute
*);
1108 static int attr_form_is_section_offset (struct attribute
*);
1110 static int attr_form_is_constant (struct attribute
*);
1112 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1114 struct dwarf2_cu
*cu
);
1116 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1117 struct abbrev_info
*abbrev
,
1118 struct dwarf2_cu
*cu
);
1120 static void free_stack_comp_unit (void *);
1122 static hashval_t
partial_die_hash (const void *item
);
1124 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1126 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1127 (unsigned int offset
, struct objfile
*objfile
);
1129 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1130 (unsigned int offset
, struct objfile
*objfile
);
1132 static struct dwarf2_cu
*alloc_one_comp_unit (struct objfile
*objfile
);
1134 static void free_one_comp_unit (void *);
1136 static void free_cached_comp_units (void *);
1138 static void age_cached_comp_units (void);
1140 static void free_one_cached_comp_unit (void *);
1142 static struct type
*set_die_type (struct die_info
*, struct type
*,
1143 struct dwarf2_cu
*);
1145 static void create_all_comp_units (struct objfile
*);
1147 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1150 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1152 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1153 struct dwarf2_per_cu_data
*);
1155 static void dwarf2_mark (struct dwarf2_cu
*);
1157 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1159 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1161 /* Try to locate the sections we need for DWARF 2 debugging
1162 information and return true if we have enough to do something. */
1165 dwarf2_has_info (struct objfile
*objfile
)
1167 struct dwarf2_per_objfile
*data
;
1169 /* Initialize per-objfile state. */
1170 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1171 memset (data
, 0, sizeof (*data
));
1172 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1173 dwarf2_per_objfile
= data
;
1175 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1176 return (data
->info
.asection
!= NULL
&& data
->abbrev
.asection
!= NULL
);
1179 /* When loading sections, we can either look for ".<name>", or for
1180 * ".z<name>", which indicates a compressed section. */
1183 section_is_p (const char *section_name
, const char *name
)
1185 return (section_name
[0] == '.'
1186 && (strcmp (section_name
+ 1, name
) == 0
1187 || (section_name
[1] == 'z'
1188 && strcmp (section_name
+ 2, name
) == 0)));
1191 /* This function is mapped across the sections and remembers the
1192 offset and size of each of the debugging sections we are interested
1196 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1198 if (section_is_p (sectp
->name
, INFO_SECTION
))
1200 dwarf2_per_objfile
->info
.asection
= sectp
;
1201 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1203 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1205 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1206 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1208 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1210 dwarf2_per_objfile
->line
.asection
= sectp
;
1211 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1213 else if (section_is_p (sectp
->name
, PUBNAMES_SECTION
))
1215 dwarf2_per_objfile
->pubnames
.asection
= sectp
;
1216 dwarf2_per_objfile
->pubnames
.size
= bfd_get_section_size (sectp
);
1218 else if (section_is_p (sectp
->name
, ARANGES_SECTION
))
1220 dwarf2_per_objfile
->aranges
.asection
= sectp
;
1221 dwarf2_per_objfile
->aranges
.size
= bfd_get_section_size (sectp
);
1223 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1225 dwarf2_per_objfile
->loc
.asection
= sectp
;
1226 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1228 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1230 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1231 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1233 else if (section_is_p (sectp
->name
, STR_SECTION
))
1235 dwarf2_per_objfile
->str
.asection
= sectp
;
1236 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1238 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1240 dwarf2_per_objfile
->frame
.asection
= sectp
;
1241 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1243 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1245 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1246 if (aflag
& SEC_HAS_CONTENTS
)
1248 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1249 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1252 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1254 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1255 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1257 else if (section_is_p (sectp
->name
, TYPES_SECTION
))
1259 dwarf2_per_objfile
->types
.asection
= sectp
;
1260 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1263 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1264 && bfd_section_vma (abfd
, sectp
) == 0)
1265 dwarf2_per_objfile
->has_section_at_zero
= 1;
1268 /* Decompress a section that was compressed using zlib. Store the
1269 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1272 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1273 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1275 bfd
*abfd
= objfile
->obfd
;
1277 error (_("Support for zlib-compressed DWARF data (from '%s') "
1278 "is disabled in this copy of GDB"),
1279 bfd_get_filename (abfd
));
1281 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1282 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1283 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1284 bfd_size_type uncompressed_size
;
1285 gdb_byte
*uncompressed_buffer
;
1288 int header_size
= 12;
1290 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1291 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
1292 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1293 bfd_get_filename (abfd
));
1295 /* Read the zlib header. In this case, it should be "ZLIB" followed
1296 by the uncompressed section size, 8 bytes in big-endian order. */
1297 if (compressed_size
< header_size
1298 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1299 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1300 bfd_get_filename (abfd
));
1301 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1302 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1303 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1304 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1305 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1306 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1307 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1308 uncompressed_size
+= compressed_buffer
[11];
1310 /* It is possible the section consists of several compressed
1311 buffers concatenated together, so we uncompress in a loop. */
1315 strm
.avail_in
= compressed_size
- header_size
;
1316 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1317 strm
.avail_out
= uncompressed_size
;
1318 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1320 rc
= inflateInit (&strm
);
1321 while (strm
.avail_in
> 0)
1324 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1325 bfd_get_filename (abfd
), rc
);
1326 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1327 + (uncompressed_size
- strm
.avail_out
));
1328 rc
= inflate (&strm
, Z_FINISH
);
1329 if (rc
!= Z_STREAM_END
)
1330 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1331 bfd_get_filename (abfd
), rc
);
1332 rc
= inflateReset (&strm
);
1334 rc
= inflateEnd (&strm
);
1336 || strm
.avail_out
!= 0)
1337 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1338 bfd_get_filename (abfd
), rc
);
1340 do_cleanups (cleanup
);
1341 *outbuf
= uncompressed_buffer
;
1342 *outsize
= uncompressed_size
;
1346 /* Read the contents of the section SECTP from object file specified by
1347 OBJFILE, store info about the section into INFO.
1348 If the section is compressed, uncompress it before returning. */
1351 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1353 bfd
*abfd
= objfile
->obfd
;
1354 asection
*sectp
= info
->asection
;
1355 gdb_byte
*buf
, *retbuf
;
1356 unsigned char header
[4];
1358 info
->buffer
= NULL
;
1359 info
->was_mmapped
= 0;
1361 if (info
->asection
== NULL
|| info
->size
== 0)
1364 /* Check if the file has a 4-byte header indicating compression. */
1365 if (info
->size
> sizeof (header
)
1366 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1367 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1369 /* Upon decompression, update the buffer and its size. */
1370 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1372 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1380 pagesize
= getpagesize ();
1382 /* Only try to mmap sections which are large enough: we don't want to
1383 waste space due to fragmentation. Also, only try mmap for sections
1384 without relocations. */
1386 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1388 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1389 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1390 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1391 MAP_PRIVATE
, pg_offset
);
1393 if (retbuf
!= MAP_FAILED
)
1395 info
->was_mmapped
= 1;
1396 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1402 /* If we get here, we are a normal, not-compressed section. */
1404 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1406 /* When debugging .o files, we may need to apply relocations; see
1407 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1408 We never compress sections in .o files, so we only need to
1409 try this when the section is not compressed. */
1410 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1413 info
->buffer
= retbuf
;
1417 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1418 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1419 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1420 bfd_get_filename (abfd
));
1423 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1427 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1428 asection
**sectp
, gdb_byte
**bufp
,
1429 bfd_size_type
*sizep
)
1431 struct dwarf2_per_objfile
*data
1432 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1433 struct dwarf2_section_info
*info
;
1434 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1435 info
= &data
->eh_frame
;
1436 else if (section_is_p (section_name
, FRAME_SECTION
))
1437 info
= &data
->frame
;
1441 if (info
->asection
!= NULL
&& info
->size
!= 0 && info
->buffer
== NULL
)
1442 /* We haven't read this section in yet. Do it now. */
1443 dwarf2_read_section (objfile
, info
);
1445 *sectp
= info
->asection
;
1446 *bufp
= info
->buffer
;
1447 *sizep
= info
->size
;
1450 /* Build a partial symbol table. */
1453 dwarf2_build_psymtabs (struct objfile
*objfile
)
1455 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
1456 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->abbrev
);
1457 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->line
);
1458 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->str
);
1459 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->macinfo
);
1460 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
1461 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
1462 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->loc
);
1463 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->eh_frame
);
1464 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->frame
);
1466 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
1468 init_psymbol_list (objfile
, 1024);
1472 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1474 /* Things are significantly easier if we have .debug_aranges and
1475 .debug_pubnames sections */
1477 dwarf2_build_psymtabs_easy (objfile
);
1481 /* only test this case for now */
1483 /* In this case we have to work a bit harder */
1484 dwarf2_build_psymtabs_hard (objfile
);
1489 /* Build the partial symbol table from the information in the
1490 .debug_pubnames and .debug_aranges sections. */
1493 dwarf2_build_psymtabs_easy (struct objfile
*objfile
)
1495 bfd
*abfd
= objfile
->obfd
;
1496 char *aranges_buffer
, *pubnames_buffer
;
1497 char *aranges_ptr
, *pubnames_ptr
;
1498 unsigned int entry_length
, version
, info_offset
, info_size
;
1500 pubnames_buffer
= dwarf2_read_section (objfile
,
1501 dwarf_pubnames_section
);
1502 pubnames_ptr
= pubnames_buffer
;
1503 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames
.size
)
1505 unsigned int bytes_read
;
1507 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &bytes_read
);
1508 pubnames_ptr
+= bytes_read
;
1509 version
= read_1_byte (abfd
, pubnames_ptr
);
1511 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1513 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1517 aranges_buffer
= dwarf2_read_section (objfile
,
1518 dwarf_aranges_section
);
1523 /* Return TRUE if OFFSET is within CU_HEADER. */
1526 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
1528 unsigned int bottom
= cu_header
->offset
;
1529 unsigned int top
= (cu_header
->offset
1531 + cu_header
->initial_length_size
);
1532 return (offset
>= bottom
&& offset
< top
);
1535 /* Read in the comp unit header information from the debug_info at info_ptr.
1536 NOTE: This leaves members offset, first_die_offset to be filled in
1540 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1541 gdb_byte
*info_ptr
, bfd
*abfd
)
1544 unsigned int bytes_read
;
1546 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
1547 cu_header
->initial_length_size
= bytes_read
;
1548 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
1549 info_ptr
+= bytes_read
;
1550 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1552 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1554 info_ptr
+= bytes_read
;
1555 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1557 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1558 if (signed_addr
< 0)
1559 internal_error (__FILE__
, __LINE__
,
1560 _("read_comp_unit_head: dwarf from non elf file"));
1561 cu_header
->signed_addr_p
= signed_addr
;
1567 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1568 gdb_byte
*buffer
, unsigned int buffer_size
,
1571 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1573 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1575 if (header
->version
!= 2 && header
->version
!= 3)
1576 error (_("Dwarf Error: wrong version in compilation unit header "
1577 "(is %d, should be %d) [in module %s]"), header
->version
,
1578 2, bfd_get_filename (abfd
));
1580 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
1581 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1582 "(offset 0x%lx + 6) [in module %s]"),
1583 (long) header
->abbrev_offset
,
1584 (long) (beg_of_comp_unit
- buffer
),
1585 bfd_get_filename (abfd
));
1587 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1588 > buffer
+ buffer_size
)
1589 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1590 "(offset 0x%lx + 0) [in module %s]"),
1591 (long) header
->length
,
1592 (long) (beg_of_comp_unit
- buffer
),
1593 bfd_get_filename (abfd
));
1598 /* Read in the types comp unit header information from .debug_types entry at
1599 types_ptr. The result is a pointer to one past the end of the header. */
1602 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
1603 ULONGEST
*signature
,
1604 gdb_byte
*types_ptr
, bfd
*abfd
)
1606 unsigned int bytes_read
;
1607 gdb_byte
*initial_types_ptr
= types_ptr
;
1609 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
1611 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
1613 *signature
= read_8_bytes (abfd
, types_ptr
);
1615 types_ptr
+= cu_header
->offset_size
;
1616 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
1621 /* Allocate a new partial symtab for file named NAME and mark this new
1622 partial symtab as being an include of PST. */
1625 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1626 struct objfile
*objfile
)
1628 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1630 subpst
->section_offsets
= pst
->section_offsets
;
1631 subpst
->textlow
= 0;
1632 subpst
->texthigh
= 0;
1634 subpst
->dependencies
= (struct partial_symtab
**)
1635 obstack_alloc (&objfile
->objfile_obstack
,
1636 sizeof (struct partial_symtab
*));
1637 subpst
->dependencies
[0] = pst
;
1638 subpst
->number_of_dependencies
= 1;
1640 subpst
->globals_offset
= 0;
1641 subpst
->n_global_syms
= 0;
1642 subpst
->statics_offset
= 0;
1643 subpst
->n_static_syms
= 0;
1644 subpst
->symtab
= NULL
;
1645 subpst
->read_symtab
= pst
->read_symtab
;
1648 /* No private part is necessary for include psymtabs. This property
1649 can be used to differentiate between such include psymtabs and
1650 the regular ones. */
1651 subpst
->read_symtab_private
= NULL
;
1654 /* Read the Line Number Program data and extract the list of files
1655 included by the source file represented by PST. Build an include
1656 partial symtab for each of these included files. */
1659 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1660 struct die_info
*die
,
1661 struct partial_symtab
*pst
)
1663 struct objfile
*objfile
= cu
->objfile
;
1664 bfd
*abfd
= objfile
->obfd
;
1665 struct line_header
*lh
= NULL
;
1666 struct attribute
*attr
;
1668 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
1671 unsigned int line_offset
= DW_UNSND (attr
);
1672 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
1675 return; /* No linetable, so no includes. */
1677 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1679 free_line_header (lh
);
1683 hash_type_signature (const void *item
)
1685 const struct signatured_type
*type_sig
= item
;
1686 /* This drops the top 32 bits of the signature, but is ok for a hash. */
1687 return type_sig
->signature
;
1691 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
1693 const struct signatured_type
*lhs
= item_lhs
;
1694 const struct signatured_type
*rhs
= item_rhs
;
1695 return lhs
->signature
== rhs
->signature
;
1698 /* Create the hash table of all entries in the .debug_types section.
1699 The result is zero if there is an error (e.g. missing .debug_types section),
1700 otherwise non-zero. */
1703 create_debug_types_hash_table (struct objfile
*objfile
)
1705 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
;
1708 if (info_ptr
== NULL
)
1710 dwarf2_per_objfile
->signatured_types
= NULL
;
1714 types_htab
= htab_create_alloc_ex (41,
1715 hash_type_signature
,
1718 &objfile
->objfile_obstack
,
1719 hashtab_obstack_allocate
,
1720 dummy_obstack_deallocate
);
1722 if (dwarf2_die_debug
)
1723 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
1725 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
1727 unsigned int offset
;
1728 unsigned int offset_size
;
1729 unsigned int type_offset
;
1730 unsigned int length
, initial_length_size
;
1731 unsigned short version
;
1733 struct signatured_type
*type_sig
;
1735 gdb_byte
*ptr
= info_ptr
;
1737 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
1739 /* We need to read the type's signature in order to build the hash
1740 table, but we don't need to read anything else just yet. */
1742 /* Sanity check to ensure entire cu is present. */
1743 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
1744 if (ptr
+ length
+ initial_length_size
1745 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
1747 complaint (&symfile_complaints
,
1748 _("debug type entry runs off end of `.debug_types' section, ignored"));
1752 offset_size
= initial_length_size
== 4 ? 4 : 8;
1753 ptr
+= initial_length_size
;
1754 version
= bfd_get_16 (objfile
->obfd
, ptr
);
1756 ptr
+= offset_size
; /* abbrev offset */
1757 ptr
+= 1; /* address size */
1758 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
1760 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
1762 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
1763 memset (type_sig
, 0, sizeof (*type_sig
));
1764 type_sig
->signature
= signature
;
1765 type_sig
->offset
= offset
;
1766 type_sig
->type_offset
= type_offset
;
1768 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
1769 gdb_assert (slot
!= NULL
);
1772 if (dwarf2_die_debug
)
1773 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
1774 offset
, phex (signature
, sizeof (signature
)));
1776 info_ptr
= info_ptr
+ initial_length_size
+ length
;
1779 dwarf2_per_objfile
->signatured_types
= types_htab
;
1784 /* Lookup a signature based type.
1785 Returns NULL if SIG is not present in the table. */
1787 static struct signatured_type
*
1788 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
1790 struct signatured_type find_entry
, *entry
;
1792 if (dwarf2_per_objfile
->signatured_types
== NULL
)
1794 complaint (&symfile_complaints
,
1795 _("missing `.debug_types' section for DW_FORM_sig8 die"));
1799 find_entry
.signature
= sig
;
1800 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
1804 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
1807 init_cu_die_reader (struct die_reader_specs
*reader
,
1808 struct dwarf2_cu
*cu
)
1810 reader
->abfd
= cu
->objfile
->obfd
;
1812 if (cu
->per_cu
->from_debug_types
)
1813 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
1815 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
1818 /* Find the base address of the compilation unit for range lists and
1819 location lists. It will normally be specified by DW_AT_low_pc.
1820 In DWARF-3 draft 4, the base address could be overridden by
1821 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1822 compilation units with discontinuous ranges. */
1825 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
1827 struct attribute
*attr
;
1830 cu
->base_address
= 0;
1832 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
1835 cu
->base_address
= DW_ADDR (attr
);
1840 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
1843 cu
->base_address
= DW_ADDR (attr
);
1849 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
1850 to combine the common parts.
1851 Process a compilation unit for a psymtab.
1852 BUFFER is a pointer to the beginning of the dwarf section buffer,
1853 either .debug_info or debug_types.
1854 INFO_PTR is a pointer to the start of the CU.
1855 Returns a pointer to the next CU. */
1858 process_psymtab_comp_unit (struct objfile
*objfile
,
1859 struct dwarf2_per_cu_data
*this_cu
,
1860 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1861 unsigned int buffer_size
)
1863 bfd
*abfd
= objfile
->obfd
;
1864 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1865 struct die_info
*comp_unit_die
;
1866 struct partial_symtab
*pst
;
1868 struct cleanup
*back_to_inner
;
1869 struct dwarf2_cu cu
;
1870 unsigned int bytes_read
;
1871 int has_children
, has_pc_info
;
1872 struct attribute
*attr
;
1874 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
1875 struct die_reader_specs reader_specs
;
1877 memset (&cu
, 0, sizeof (cu
));
1878 cu
.objfile
= objfile
;
1879 obstack_init (&cu
.comp_unit_obstack
);
1881 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1883 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
1884 buffer
, buffer_size
,
1887 /* Complete the cu_header. */
1888 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
1889 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1891 cu
.list_in_scope
= &file_symbols
;
1893 /* If this compilation unit was already read in, free the
1894 cached copy in order to read it in again. This is
1895 necessary because we skipped some symbols when we first
1896 read in the compilation unit (see load_partial_dies).
1897 This problem could be avoided, but the benefit is
1899 if (this_cu
->cu
!= NULL
)
1900 free_one_cached_comp_unit (this_cu
->cu
);
1902 /* Note that this is a pointer to our stack frame, being
1903 added to a global data structure. It will be cleaned up
1904 in free_stack_comp_unit when we finish with this
1905 compilation unit. */
1907 cu
.per_cu
= this_cu
;
1909 /* Read the abbrevs for this compilation unit into a table. */
1910 dwarf2_read_abbrevs (abfd
, &cu
);
1911 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1913 /* Read the compilation unit die. */
1914 if (this_cu
->from_debug_types
)
1915 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
1916 init_cu_die_reader (&reader_specs
, &cu
);
1917 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
1920 if (this_cu
->from_debug_types
)
1922 /* offset,length haven't been set yet for type units. */
1923 this_cu
->offset
= cu
.header
.offset
;
1924 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
1926 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
1928 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1929 + cu
.header
.initial_length_size
);
1930 do_cleanups (back_to_inner
);
1934 /* Set the language we're debugging. */
1935 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, &cu
);
1937 set_cu_language (DW_UNSND (attr
), &cu
);
1939 set_cu_language (language_minimal
, &cu
);
1941 /* Allocate a new partial symbol table structure. */
1942 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
1943 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1944 (attr
!= NULL
) ? DW_STRING (attr
) : "",
1945 /* TEXTLOW and TEXTHIGH are set below. */
1947 objfile
->global_psymbols
.next
,
1948 objfile
->static_psymbols
.next
);
1950 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
1952 pst
->dirname
= DW_STRING (attr
);
1954 pst
->read_symtab_private
= (char *) this_cu
;
1956 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1958 /* Store the function that reads in the rest of the symbol table */
1959 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1961 this_cu
->psymtab
= pst
;
1963 dwarf2_find_base_address (comp_unit_die
, &cu
);
1965 /* Possibly set the default values of LOWPC and HIGHPC from
1967 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
1968 &best_highpc
, &cu
, pst
);
1969 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
1970 /* Store the contiguous range if it is not empty; it can be empty for
1971 CUs with no code. */
1972 addrmap_set_empty (objfile
->psymtabs_addrmap
,
1973 best_lowpc
+ baseaddr
,
1974 best_highpc
+ baseaddr
- 1, pst
);
1976 /* Check if comp unit has_children.
1977 If so, read the rest of the partial symbols from this comp unit.
1978 If not, there's no more debug_info for this comp unit. */
1981 struct partial_die_info
*first_die
;
1982 CORE_ADDR lowpc
, highpc
;
1984 lowpc
= ((CORE_ADDR
) -1);
1985 highpc
= ((CORE_ADDR
) 0);
1987 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
1989 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
1990 ! has_pc_info
, &cu
);
1992 /* If we didn't find a lowpc, set it to highpc to avoid
1993 complaints from `maint check'. */
1994 if (lowpc
== ((CORE_ADDR
) -1))
1997 /* If the compilation unit didn't have an explicit address range,
1998 then use the information extracted from its child dies. */
2002 best_highpc
= highpc
;
2005 pst
->textlow
= best_lowpc
+ baseaddr
;
2006 pst
->texthigh
= best_highpc
+ baseaddr
;
2008 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
2009 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
2010 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
2011 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
2012 sort_pst_symbols (pst
);
2014 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
2015 + cu
.header
.initial_length_size
);
2017 if (this_cu
->from_debug_types
)
2019 /* It's not clear we want to do anything with stmt lists here.
2020 Waiting to see what gcc ultimately does. */
2024 /* Get the list of files included in the current compilation unit,
2025 and build a psymtab for each of them. */
2026 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
2029 do_cleanups (back_to_inner
);
2034 /* Traversal function for htab_traverse_noresize.
2035 Process one .debug_types comp-unit. */
2038 process_type_comp_unit (void **slot
, void *info
)
2040 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
2041 struct objfile
*objfile
= (struct objfile
*) info
;
2042 struct dwarf2_per_cu_data
*this_cu
;
2044 this_cu
= &entry
->per_cu
;
2045 this_cu
->from_debug_types
= 1;
2047 process_psymtab_comp_unit (objfile
, this_cu
,
2048 dwarf2_per_objfile
->types
.buffer
,
2049 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
2050 dwarf2_per_objfile
->types
.size
);
2055 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
2056 Build partial symbol tables for the .debug_types comp-units. */
2059 build_type_psymtabs (struct objfile
*objfile
)
2061 if (! create_debug_types_hash_table (objfile
))
2064 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
2065 process_type_comp_unit
, objfile
);
2068 /* Build the partial symbol table by doing a quick pass through the
2069 .debug_info and .debug_abbrev sections. */
2072 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
2074 /* Instead of reading this into a big buffer, we should probably use
2075 mmap() on architectures that support it. (FIXME) */
2076 bfd
*abfd
= objfile
->obfd
;
2078 struct cleanup
*back_to
;
2080 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
2082 /* Any cached compilation units will be linked by the per-objfile
2083 read_in_chain. Make sure to free them when we're done. */
2084 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2086 build_type_psymtabs (objfile
);
2088 create_all_comp_units (objfile
);
2090 objfile
->psymtabs_addrmap
=
2091 addrmap_create_mutable (&objfile
->objfile_obstack
);
2093 /* Since the objects we're extracting from .debug_info vary in
2094 length, only the individual functions to extract them (like
2095 read_comp_unit_head and load_partial_die) can really know whether
2096 the buffer is large enough to hold another complete object.
2098 At the moment, they don't actually check that. If .debug_info
2099 holds just one extra byte after the last compilation unit's dies,
2100 then read_comp_unit_head will happily read off the end of the
2101 buffer. read_partial_die is similarly casual. Those functions
2104 For this loop condition, simply checking whether there's any data
2105 left at all should be sufficient. */
2107 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
2108 + dwarf2_per_objfile
->info
.size
))
2110 struct dwarf2_per_cu_data
*this_cu
;
2112 this_cu
= dwarf2_find_comp_unit (info_ptr
- dwarf2_per_objfile
->info
.buffer
,
2115 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
2116 dwarf2_per_objfile
->info
.buffer
,
2118 dwarf2_per_objfile
->info
.size
);
2121 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
2122 &objfile
->objfile_obstack
);
2124 do_cleanups (back_to
);
2127 /* Load the partial DIEs for a secondary CU into memory. */
2130 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
2131 struct objfile
*objfile
)
2133 bfd
*abfd
= objfile
->obfd
;
2134 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
2135 struct die_info
*comp_unit_die
;
2136 struct dwarf2_cu
*cu
;
2137 unsigned int bytes_read
;
2138 struct cleanup
*back_to
;
2139 struct attribute
*attr
;
2141 struct die_reader_specs reader_specs
;
2143 gdb_assert (! this_cu
->from_debug_types
);
2145 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
2146 beg_of_comp_unit
= info_ptr
;
2148 cu
= alloc_one_comp_unit (objfile
);
2150 /* ??? Missing cleanup for CU? */
2152 /* Link this compilation unit into the compilation unit tree. */
2154 cu
->per_cu
= this_cu
;
2155 cu
->type_hash
= this_cu
->type_hash
;
2157 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
2158 dwarf2_per_objfile
->info
.buffer
,
2159 dwarf2_per_objfile
->info
.size
,
2162 /* Complete the cu_header. */
2163 cu
->header
.offset
= this_cu
->offset
;
2164 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2166 /* Read the abbrevs for this compilation unit into a table. */
2167 dwarf2_read_abbrevs (abfd
, cu
);
2168 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2170 /* Read the compilation unit die. */
2171 init_cu_die_reader (&reader_specs
, cu
);
2172 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2175 /* Set the language we're debugging. */
2176 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
2178 set_cu_language (DW_UNSND (attr
), cu
);
2180 set_cu_language (language_minimal
, cu
);
2182 /* Check if comp unit has_children.
2183 If so, read the rest of the partial symbols from this comp unit.
2184 If not, there's no more debug_info for this comp unit. */
2186 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
2188 do_cleanups (back_to
);
2191 /* Create a list of all compilation units in OBJFILE. We do this only
2192 if an inter-comp-unit reference is found; presumably if there is one,
2193 there will be many, and one will occur early in the .debug_info section.
2194 So there's no point in building this list incrementally. */
2197 create_all_comp_units (struct objfile
*objfile
)
2201 struct dwarf2_per_cu_data
**all_comp_units
;
2202 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info
.buffer
;
2206 all_comp_units
= xmalloc (n_allocated
2207 * sizeof (struct dwarf2_per_cu_data
*));
2209 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
2211 unsigned int length
, initial_length_size
;
2212 gdb_byte
*beg_of_comp_unit
;
2213 struct dwarf2_per_cu_data
*this_cu
;
2214 unsigned int offset
;
2216 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
2218 /* Read just enough information to find out where the next
2219 compilation unit is. */
2220 length
= read_initial_length (objfile
->obfd
, info_ptr
,
2221 &initial_length_size
);
2223 /* Save the compilation unit for later lookup. */
2224 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
2225 sizeof (struct dwarf2_per_cu_data
));
2226 memset (this_cu
, 0, sizeof (*this_cu
));
2227 this_cu
->offset
= offset
;
2228 this_cu
->length
= length
+ initial_length_size
;
2230 if (n_comp_units
== n_allocated
)
2233 all_comp_units
= xrealloc (all_comp_units
,
2235 * sizeof (struct dwarf2_per_cu_data
*));
2237 all_comp_units
[n_comp_units
++] = this_cu
;
2239 info_ptr
= info_ptr
+ this_cu
->length
;
2242 dwarf2_per_objfile
->all_comp_units
2243 = obstack_alloc (&objfile
->objfile_obstack
,
2244 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
2245 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
2246 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
2247 xfree (all_comp_units
);
2248 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
2251 /* Process all loaded DIEs for compilation unit CU, starting at
2252 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
2253 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
2254 DW_AT_ranges). If NEED_PC is set, then this function will set
2255 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
2256 and record the covered ranges in the addrmap. */
2259 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
2260 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2262 struct objfile
*objfile
= cu
->objfile
;
2263 bfd
*abfd
= objfile
->obfd
;
2264 struct partial_die_info
*pdi
;
2266 /* Now, march along the PDI's, descending into ones which have
2267 interesting children but skipping the children of the other ones,
2268 until we reach the end of the compilation unit. */
2274 fixup_partial_die (pdi
, cu
);
2276 /* Anonymous namespaces have no name but have interesting
2277 children, so we need to look at them. Ditto for anonymous
2280 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
2281 || pdi
->tag
== DW_TAG_enumeration_type
)
2285 case DW_TAG_subprogram
:
2286 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2288 case DW_TAG_variable
:
2289 case DW_TAG_typedef
:
2290 case DW_TAG_union_type
:
2291 if (!pdi
->is_declaration
)
2293 add_partial_symbol (pdi
, cu
);
2296 case DW_TAG_class_type
:
2297 case DW_TAG_interface_type
:
2298 case DW_TAG_structure_type
:
2299 if (!pdi
->is_declaration
)
2301 add_partial_symbol (pdi
, cu
);
2304 case DW_TAG_enumeration_type
:
2305 if (!pdi
->is_declaration
)
2306 add_partial_enumeration (pdi
, cu
);
2308 case DW_TAG_base_type
:
2309 case DW_TAG_subrange_type
:
2310 /* File scope base type definitions are added to the partial
2312 add_partial_symbol (pdi
, cu
);
2314 case DW_TAG_namespace
:
2315 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
2318 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
2325 /* If the die has a sibling, skip to the sibling. */
2327 pdi
= pdi
->die_sibling
;
2331 /* Functions used to compute the fully scoped name of a partial DIE.
2333 Normally, this is simple. For C++, the parent DIE's fully scoped
2334 name is concatenated with "::" and the partial DIE's name. For
2335 Java, the same thing occurs except that "." is used instead of "::".
2336 Enumerators are an exception; they use the scope of their parent
2337 enumeration type, i.e. the name of the enumeration type is not
2338 prepended to the enumerator.
2340 There are two complexities. One is DW_AT_specification; in this
2341 case "parent" means the parent of the target of the specification,
2342 instead of the direct parent of the DIE. The other is compilers
2343 which do not emit DW_TAG_namespace; in this case we try to guess
2344 the fully qualified name of structure types from their members'
2345 linkage names. This must be done using the DIE's children rather
2346 than the children of any DW_AT_specification target. We only need
2347 to do this for structures at the top level, i.e. if the target of
2348 any DW_AT_specification (if any; otherwise the DIE itself) does not
2351 /* Compute the scope prefix associated with PDI's parent, in
2352 compilation unit CU. The result will be allocated on CU's
2353 comp_unit_obstack, or a copy of the already allocated PDI->NAME
2354 field. NULL is returned if no prefix is necessary. */
2356 partial_die_parent_scope (struct partial_die_info
*pdi
,
2357 struct dwarf2_cu
*cu
)
2359 char *grandparent_scope
;
2360 struct partial_die_info
*parent
, *real_pdi
;
2362 /* We need to look at our parent DIE; if we have a DW_AT_specification,
2363 then this means the parent of the specification DIE. */
2366 while (real_pdi
->has_specification
)
2367 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2369 parent
= real_pdi
->die_parent
;
2373 if (parent
->scope_set
)
2374 return parent
->scope
;
2376 fixup_partial_die (parent
, cu
);
2378 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
2380 if (parent
->tag
== DW_TAG_namespace
2381 || parent
->tag
== DW_TAG_structure_type
2382 || parent
->tag
== DW_TAG_class_type
2383 || parent
->tag
== DW_TAG_interface_type
2384 || parent
->tag
== DW_TAG_union_type
2385 || parent
->tag
== DW_TAG_enumeration_type
)
2387 if (grandparent_scope
== NULL
)
2388 parent
->scope
= parent
->name
;
2390 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
2393 else if (parent
->tag
== DW_TAG_enumerator
)
2394 /* Enumerators should not get the name of the enumeration as a prefix. */
2395 parent
->scope
= grandparent_scope
;
2398 /* FIXME drow/2004-04-01: What should we be doing with
2399 function-local names? For partial symbols, we should probably be
2401 complaint (&symfile_complaints
,
2402 _("unhandled containing DIE tag %d for DIE at %d"),
2403 parent
->tag
, pdi
->offset
);
2404 parent
->scope
= grandparent_scope
;
2407 parent
->scope_set
= 1;
2408 return parent
->scope
;
2411 /* Return the fully scoped name associated with PDI, from compilation unit
2412 CU. The result will be allocated with malloc. */
2414 partial_die_full_name (struct partial_die_info
*pdi
,
2415 struct dwarf2_cu
*cu
)
2419 parent_scope
= partial_die_parent_scope (pdi
, cu
);
2420 if (parent_scope
== NULL
)
2423 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
2427 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
2429 struct objfile
*objfile
= cu
->objfile
;
2431 char *actual_name
= NULL
;
2432 const char *my_prefix
;
2433 const struct partial_symbol
*psym
= NULL
;
2435 int built_actual_name
= 0;
2437 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2439 actual_name
= partial_die_full_name (pdi
, cu
);
2441 built_actual_name
= 1;
2443 if (actual_name
== NULL
)
2444 actual_name
= pdi
->name
;
2448 case DW_TAG_subprogram
:
2449 if (pdi
->is_external
|| cu
->language
== language_ada
)
2451 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
2452 of the global scope. But in Ada, we want to be able to access
2453 nested procedures globally. So all Ada subprograms are stored
2454 in the global scope. */
2455 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2456 mst_text, objfile); */
2457 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2459 VAR_DOMAIN
, LOC_BLOCK
,
2460 &objfile
->global_psymbols
,
2461 0, pdi
->lowpc
+ baseaddr
,
2462 cu
->language
, objfile
);
2466 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2467 mst_file_text, objfile); */
2468 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2470 VAR_DOMAIN
, LOC_BLOCK
,
2471 &objfile
->static_psymbols
,
2472 0, pdi
->lowpc
+ baseaddr
,
2473 cu
->language
, objfile
);
2476 case DW_TAG_variable
:
2477 if (pdi
->is_external
)
2480 Don't enter into the minimal symbol tables as there is
2481 a minimal symbol table entry from the ELF symbols already.
2482 Enter into partial symbol table if it has a location
2483 descriptor or a type.
2484 If the location descriptor is missing, new_symbol will create
2485 a LOC_UNRESOLVED symbol, the address of the variable will then
2486 be determined from the minimal symbol table whenever the variable
2488 The address for the partial symbol table entry is not
2489 used by GDB, but it comes in handy for debugging partial symbol
2493 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2494 if (pdi
->locdesc
|| pdi
->has_type
)
2495 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2497 VAR_DOMAIN
, LOC_STATIC
,
2498 &objfile
->global_psymbols
,
2500 cu
->language
, objfile
);
2504 /* Static Variable. Skip symbols without location descriptors. */
2505 if (pdi
->locdesc
== NULL
)
2507 if (built_actual_name
)
2508 xfree (actual_name
);
2511 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2512 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2513 mst_file_data, objfile); */
2514 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2516 VAR_DOMAIN
, LOC_STATIC
,
2517 &objfile
->static_psymbols
,
2519 cu
->language
, objfile
);
2522 case DW_TAG_typedef
:
2523 case DW_TAG_base_type
:
2524 case DW_TAG_subrange_type
:
2525 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2527 VAR_DOMAIN
, LOC_TYPEDEF
,
2528 &objfile
->static_psymbols
,
2529 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2531 case DW_TAG_namespace
:
2532 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2534 VAR_DOMAIN
, LOC_TYPEDEF
,
2535 &objfile
->global_psymbols
,
2536 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2538 case DW_TAG_class_type
:
2539 case DW_TAG_interface_type
:
2540 case DW_TAG_structure_type
:
2541 case DW_TAG_union_type
:
2542 case DW_TAG_enumeration_type
:
2543 /* Skip external references. The DWARF standard says in the section
2544 about "Structure, Union, and Class Type Entries": "An incomplete
2545 structure, union or class type is represented by a structure,
2546 union or class entry that does not have a byte size attribute
2547 and that has a DW_AT_declaration attribute." */
2548 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2550 if (built_actual_name
)
2551 xfree (actual_name
);
2555 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2556 static vs. global. */
2557 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2559 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2560 (cu
->language
== language_cplus
2561 || cu
->language
== language_java
)
2562 ? &objfile
->global_psymbols
2563 : &objfile
->static_psymbols
,
2564 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2567 case DW_TAG_enumerator
:
2568 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2570 VAR_DOMAIN
, LOC_CONST
,
2571 (cu
->language
== language_cplus
2572 || cu
->language
== language_java
)
2573 ? &objfile
->global_psymbols
2574 : &objfile
->static_psymbols
,
2575 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2581 if (built_actual_name
)
2582 xfree (actual_name
);
2585 /* Read a partial die corresponding to a namespace; also, add a symbol
2586 corresponding to that namespace to the symbol table. NAMESPACE is
2587 the name of the enclosing namespace. */
2590 add_partial_namespace (struct partial_die_info
*pdi
,
2591 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2592 int need_pc
, struct dwarf2_cu
*cu
)
2594 struct objfile
*objfile
= cu
->objfile
;
2596 /* Add a symbol for the namespace. */
2598 add_partial_symbol (pdi
, cu
);
2600 /* Now scan partial symbols in that namespace. */
2602 if (pdi
->has_children
)
2603 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2606 /* Read a partial die corresponding to a Fortran module. */
2609 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
2610 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2612 /* Now scan partial symbols in that module.
2614 FIXME: Support the separate Fortran module namespaces. */
2616 if (pdi
->has_children
)
2617 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2620 /* Read a partial die corresponding to a subprogram and create a partial
2621 symbol for that subprogram. When the CU language allows it, this
2622 routine also defines a partial symbol for each nested subprogram
2623 that this subprogram contains.
2625 DIE my also be a lexical block, in which case we simply search
2626 recursively for suprograms defined inside that lexical block.
2627 Again, this is only performed when the CU language allows this
2628 type of definitions. */
2631 add_partial_subprogram (struct partial_die_info
*pdi
,
2632 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2633 int need_pc
, struct dwarf2_cu
*cu
)
2635 if (pdi
->tag
== DW_TAG_subprogram
)
2637 if (pdi
->has_pc_info
)
2639 if (pdi
->lowpc
< *lowpc
)
2640 *lowpc
= pdi
->lowpc
;
2641 if (pdi
->highpc
> *highpc
)
2642 *highpc
= pdi
->highpc
;
2646 struct objfile
*objfile
= cu
->objfile
;
2648 baseaddr
= ANOFFSET (objfile
->section_offsets
,
2649 SECT_OFF_TEXT (objfile
));
2650 addrmap_set_empty (objfile
->psymtabs_addrmap
,
2651 pdi
->lowpc
+ baseaddr
,
2652 pdi
->highpc
- 1 + baseaddr
,
2653 cu
->per_cu
->psymtab
);
2655 if (!pdi
->is_declaration
)
2656 add_partial_symbol (pdi
, cu
);
2660 if (! pdi
->has_children
)
2663 if (cu
->language
== language_ada
)
2665 pdi
= pdi
->die_child
;
2668 fixup_partial_die (pdi
, cu
);
2669 if (pdi
->tag
== DW_TAG_subprogram
2670 || pdi
->tag
== DW_TAG_lexical_block
)
2671 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2672 pdi
= pdi
->die_sibling
;
2677 /* See if we can figure out if the class lives in a namespace. We do
2678 this by looking for a member function; its demangled name will
2679 contain namespace info, if there is any. */
2682 guess_structure_name (struct partial_die_info
*struct_pdi
,
2683 struct dwarf2_cu
*cu
)
2685 if ((cu
->language
== language_cplus
2686 || cu
->language
== language_java
)
2687 && cu
->has_namespace_info
== 0
2688 && struct_pdi
->has_children
)
2690 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2691 what template types look like, because the demangler
2692 frequently doesn't give the same name as the debug info. We
2693 could fix this by only using the demangled name to get the
2694 prefix (but see comment in read_structure_type). */
2696 struct partial_die_info
*real_pdi
;
2698 /* If this DIE (this DIE's specification, if any) has a parent, then
2699 we should not do this. We'll prepend the parent's fully qualified
2700 name when we create the partial symbol. */
2702 real_pdi
= struct_pdi
;
2703 while (real_pdi
->has_specification
)
2704 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2706 if (real_pdi
->die_parent
!= NULL
)
2711 /* Read a partial die corresponding to an enumeration type. */
2714 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2715 struct dwarf2_cu
*cu
)
2717 struct objfile
*objfile
= cu
->objfile
;
2718 bfd
*abfd
= objfile
->obfd
;
2719 struct partial_die_info
*pdi
;
2721 if (enum_pdi
->name
!= NULL
)
2722 add_partial_symbol (enum_pdi
, cu
);
2724 pdi
= enum_pdi
->die_child
;
2727 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2728 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2730 add_partial_symbol (pdi
, cu
);
2731 pdi
= pdi
->die_sibling
;
2735 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2736 Return the corresponding abbrev, or NULL if the number is zero (indicating
2737 an empty DIE). In either case *BYTES_READ will be set to the length of
2738 the initial number. */
2740 static struct abbrev_info
*
2741 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2742 struct dwarf2_cu
*cu
)
2744 bfd
*abfd
= cu
->objfile
->obfd
;
2745 unsigned int abbrev_number
;
2746 struct abbrev_info
*abbrev
;
2748 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2750 if (abbrev_number
== 0)
2753 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2756 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2757 bfd_get_filename (abfd
));
2763 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2764 Returns a pointer to the end of a series of DIEs, terminated by an empty
2765 DIE. Any children of the skipped DIEs will also be skipped. */
2768 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2770 struct abbrev_info
*abbrev
;
2771 unsigned int bytes_read
;
2775 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2777 return info_ptr
+ bytes_read
;
2779 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
2783 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2784 INFO_PTR should point just after the initial uleb128 of a DIE, and the
2785 abbrev corresponding to that skipped uleb128 should be passed in
2786 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2790 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
2791 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
2793 unsigned int bytes_read
;
2794 struct attribute attr
;
2795 bfd
*abfd
= cu
->objfile
->obfd
;
2796 unsigned int form
, i
;
2798 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2800 /* The only abbrev we care about is DW_AT_sibling. */
2801 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2803 read_attribute (&attr
, &abbrev
->attrs
[i
],
2804 abfd
, info_ptr
, cu
);
2805 if (attr
.form
== DW_FORM_ref_addr
)
2806 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2808 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
2811 /* If it isn't DW_AT_sibling, skip this attribute. */
2812 form
= abbrev
->attrs
[i
].form
;
2816 case DW_FORM_ref_addr
:
2817 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
2818 and later it is offset sized. */
2819 if (cu
->header
.version
== 2)
2820 info_ptr
+= cu
->header
.addr_size
;
2822 info_ptr
+= cu
->header
.offset_size
;
2825 info_ptr
+= cu
->header
.addr_size
;
2845 case DW_FORM_string
:
2846 read_string (abfd
, info_ptr
, &bytes_read
);
2847 info_ptr
+= bytes_read
;
2850 info_ptr
+= cu
->header
.offset_size
;
2853 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2854 info_ptr
+= bytes_read
;
2856 case DW_FORM_block1
:
2857 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2859 case DW_FORM_block2
:
2860 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2862 case DW_FORM_block4
:
2863 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2867 case DW_FORM_ref_udata
:
2868 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2870 case DW_FORM_indirect
:
2871 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2872 info_ptr
+= bytes_read
;
2873 /* We need to continue parsing from here, so just go back to
2875 goto skip_attribute
;
2878 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2879 dwarf_form_name (form
),
2880 bfd_get_filename (abfd
));
2884 if (abbrev
->has_children
)
2885 return skip_children (buffer
, info_ptr
, cu
);
2890 /* Locate ORIG_PDI's sibling.
2891 INFO_PTR should point to the start of the next DIE after ORIG_PDI
2895 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
2896 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
2897 bfd
*abfd
, struct dwarf2_cu
*cu
)
2899 /* Do we know the sibling already? */
2901 if (orig_pdi
->sibling
)
2902 return orig_pdi
->sibling
;
2904 /* Are there any children to deal with? */
2906 if (!orig_pdi
->has_children
)
2909 /* Skip the children the long way. */
2911 return skip_children (buffer
, info_ptr
, cu
);
2914 /* Expand this partial symbol table into a full symbol table. */
2917 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2919 /* FIXME: This is barely more than a stub. */
2924 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2930 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2931 gdb_flush (gdb_stdout
);
2934 /* Restore our global data. */
2935 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2936 dwarf2_objfile_data_key
);
2938 /* If this psymtab is constructed from a debug-only objfile, the
2939 has_section_at_zero flag will not necessarily be correct. We
2940 can get the correct value for this flag by looking at the data
2941 associated with the (presumably stripped) associated objfile. */
2942 if (pst
->objfile
->separate_debug_objfile_backlink
)
2944 struct dwarf2_per_objfile
*dpo_backlink
2945 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
2946 dwarf2_objfile_data_key
);
2947 dwarf2_per_objfile
->has_section_at_zero
2948 = dpo_backlink
->has_section_at_zero
;
2951 psymtab_to_symtab_1 (pst
);
2953 /* Finish up the debug error message. */
2955 printf_filtered (_("done.\n"));
2960 /* Add PER_CU to the queue. */
2963 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2965 struct dwarf2_queue_item
*item
;
2968 item
= xmalloc (sizeof (*item
));
2969 item
->per_cu
= per_cu
;
2972 if (dwarf2_queue
== NULL
)
2973 dwarf2_queue
= item
;
2975 dwarf2_queue_tail
->next
= item
;
2977 dwarf2_queue_tail
= item
;
2980 /* Process the queue. */
2983 process_queue (struct objfile
*objfile
)
2985 struct dwarf2_queue_item
*item
, *next_item
;
2987 /* The queue starts out with one item, but following a DIE reference
2988 may load a new CU, adding it to the end of the queue. */
2989 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2991 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2992 process_full_comp_unit (item
->per_cu
);
2994 item
->per_cu
->queued
= 0;
2995 next_item
= item
->next
;
2999 dwarf2_queue_tail
= NULL
;
3002 /* Free all allocated queue entries. This function only releases anything if
3003 an error was thrown; if the queue was processed then it would have been
3004 freed as we went along. */
3007 dwarf2_release_queue (void *dummy
)
3009 struct dwarf2_queue_item
*item
, *last
;
3011 item
= dwarf2_queue
;
3014 /* Anything still marked queued is likely to be in an
3015 inconsistent state, so discard it. */
3016 if (item
->per_cu
->queued
)
3018 if (item
->per_cu
->cu
!= NULL
)
3019 free_one_cached_comp_unit (item
->per_cu
->cu
);
3020 item
->per_cu
->queued
= 0;
3028 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
3031 /* Read in full symbols for PST, and anything it depends on. */
3034 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
3036 struct dwarf2_per_cu_data
*per_cu
;
3037 struct cleanup
*back_to
;
3040 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
3041 if (!pst
->dependencies
[i
]->readin
)
3043 /* Inform about additional files that need to be read in. */
3046 /* FIXME: i18n: Need to make this a single string. */
3047 fputs_filtered (" ", gdb_stdout
);
3049 fputs_filtered ("and ", gdb_stdout
);
3051 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
3052 wrap_here (""); /* Flush output */
3053 gdb_flush (gdb_stdout
);
3055 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
3058 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
3062 /* It's an include file, no symbols to read for it.
3063 Everything is in the parent symtab. */
3068 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
3070 queue_comp_unit (per_cu
, pst
->objfile
);
3072 if (per_cu
->from_debug_types
)
3073 read_signatured_type_at_offset (pst
->objfile
, per_cu
->offset
);
3075 load_full_comp_unit (per_cu
, pst
->objfile
);
3077 process_queue (pst
->objfile
);
3079 /* Age the cache, releasing compilation units that have not
3080 been used recently. */
3081 age_cached_comp_units ();
3083 do_cleanups (back_to
);
3086 /* Load the DIEs associated with PER_CU into memory. */
3089 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
3091 bfd
*abfd
= objfile
->obfd
;
3092 struct dwarf2_cu
*cu
;
3093 unsigned int offset
;
3094 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3095 struct cleanup
*back_to
, *free_cu_cleanup
;
3096 struct attribute
*attr
;
3099 gdb_assert (! per_cu
->from_debug_types
);
3101 /* Set local variables from the partial symbol table info. */
3102 offset
= per_cu
->offset
;
3104 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
3105 beg_of_comp_unit
= info_ptr
;
3107 cu
= alloc_one_comp_unit (objfile
);
3109 /* If an error occurs while loading, release our storage. */
3110 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3112 /* Read in the comp_unit header. */
3113 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
3115 /* Complete the cu_header. */
3116 cu
->header
.offset
= offset
;
3117 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3119 /* Read the abbrevs for this compilation unit. */
3120 dwarf2_read_abbrevs (abfd
, cu
);
3121 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3123 /* Link this compilation unit into the compilation unit tree. */
3125 cu
->per_cu
= per_cu
;
3126 cu
->type_hash
= per_cu
->type_hash
;
3128 cu
->dies
= read_comp_unit (info_ptr
, cu
);
3130 /* We try not to read any attributes in this function, because not
3131 all objfiles needed for references have been loaded yet, and symbol
3132 table processing isn't initialized. But we have to set the CU language,
3133 or we won't be able to build types correctly. */
3134 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
3136 set_cu_language (DW_UNSND (attr
), cu
);
3138 set_cu_language (language_minimal
, cu
);
3140 /* Link this CU into read_in_chain. */
3141 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3142 dwarf2_per_objfile
->read_in_chain
= per_cu
;
3144 do_cleanups (back_to
);
3146 /* We've successfully allocated this compilation unit. Let our caller
3147 clean it up when finished with it. */
3148 discard_cleanups (free_cu_cleanup
);
3151 /* Generate full symbol information for PST and CU, whose DIEs have
3152 already been loaded into memory. */
3155 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
3157 struct partial_symtab
*pst
= per_cu
->psymtab
;
3158 struct dwarf2_cu
*cu
= per_cu
->cu
;
3159 struct objfile
*objfile
= pst
->objfile
;
3160 bfd
*abfd
= objfile
->obfd
;
3161 CORE_ADDR lowpc
, highpc
;
3162 struct symtab
*symtab
;
3163 struct cleanup
*back_to
;
3166 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3169 back_to
= make_cleanup (really_free_pendings
, NULL
);
3171 cu
->list_in_scope
= &file_symbols
;
3173 dwarf2_find_base_address (cu
->dies
, cu
);
3175 /* Do line number decoding in read_file_scope () */
3176 process_die (cu
->dies
, cu
);
3178 /* Some compilers don't define a DW_AT_high_pc attribute for the
3179 compilation unit. If the DW_AT_high_pc is missing, synthesize
3180 it, by scanning the DIE's below the compilation unit. */
3181 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
3183 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
3185 /* Set symtab language to language from DW_AT_language.
3186 If the compilation is from a C file generated by language preprocessors,
3187 do not set the language if it was already deduced by start_subfile. */
3189 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
3191 symtab
->language
= cu
->language
;
3193 pst
->symtab
= symtab
;
3196 do_cleanups (back_to
);
3199 /* Process a die and its children. */
3202 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
3206 case DW_TAG_padding
:
3208 case DW_TAG_compile_unit
:
3209 read_file_scope (die
, cu
);
3211 case DW_TAG_type_unit
:
3212 read_type_unit_scope (die
, cu
);
3214 case DW_TAG_subprogram
:
3215 case DW_TAG_inlined_subroutine
:
3216 read_func_scope (die
, cu
);
3218 case DW_TAG_lexical_block
:
3219 case DW_TAG_try_block
:
3220 case DW_TAG_catch_block
:
3221 read_lexical_block_scope (die
, cu
);
3223 case DW_TAG_class_type
:
3224 case DW_TAG_interface_type
:
3225 case DW_TAG_structure_type
:
3226 case DW_TAG_union_type
:
3227 process_structure_scope (die
, cu
);
3229 case DW_TAG_enumeration_type
:
3230 process_enumeration_scope (die
, cu
);
3233 /* These dies have a type, but processing them does not create
3234 a symbol or recurse to process the children. Therefore we can
3235 read them on-demand through read_type_die. */
3236 case DW_TAG_subroutine_type
:
3237 case DW_TAG_set_type
:
3238 case DW_TAG_array_type
:
3239 case DW_TAG_pointer_type
:
3240 case DW_TAG_ptr_to_member_type
:
3241 case DW_TAG_reference_type
:
3242 case DW_TAG_string_type
:
3245 case DW_TAG_base_type
:
3246 case DW_TAG_subrange_type
:
3247 case DW_TAG_typedef
:
3248 /* Add a typedef symbol for the type definition, if it has a
3250 new_symbol (die
, read_type_die (die
, cu
), cu
);
3252 case DW_TAG_common_block
:
3253 read_common_block (die
, cu
);
3255 case DW_TAG_common_inclusion
:
3257 case DW_TAG_namespace
:
3258 processing_has_namespace_info
= 1;
3259 read_namespace (die
, cu
);
3262 read_module (die
, cu
);
3264 case DW_TAG_imported_declaration
:
3265 case DW_TAG_imported_module
:
3266 processing_has_namespace_info
= 1;
3267 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
3268 || cu
->language
!= language_fortran
))
3269 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
3270 dwarf_tag_name (die
->tag
));
3271 read_import_statement (die
, cu
);
3274 new_symbol (die
, NULL
, cu
);
3279 /* A helper function for dwarf2_compute_name which determines whether DIE
3280 needs to have the name of the scope prepended to the name listed in the
3284 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3288 case DW_TAG_namespace
:
3289 case DW_TAG_typedef
:
3290 case DW_TAG_class_type
:
3291 case DW_TAG_interface_type
:
3292 case DW_TAG_structure_type
:
3293 case DW_TAG_union_type
:
3294 case DW_TAG_enumeration_type
:
3295 case DW_TAG_enumerator
:
3296 case DW_TAG_subprogram
:
3300 case DW_TAG_variable
:
3301 /* We only need to prefix "globally" visible variables. These include
3302 any variable marked with DW_AT_external or any variable that
3303 lives in a namespace. [Variables in anonymous namespaces
3304 require prefixing, but they are not DW_AT_external.] */
3306 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
3308 struct dwarf2_cu
*spec_cu
= cu
;
3309 return die_needs_namespace (die_specification (die
, &spec_cu
),
3313 if (dwarf2_attr (die
, DW_AT_external
, cu
)
3314 || die
->parent
->tag
== DW_TAG_namespace
)
3324 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
3325 compute the physname for the object, which include a method's
3326 formal parameters (C++/Java) and return type (Java).
3328 For Ada, return the DIE's linkage name rather than the fully qualified
3329 name. PHYSNAME is ignored..
3331 The result is allocated on the objfile_obstack and canonicalized. */
3334 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
3338 name
= dwarf2_name (die
, cu
);
3340 /* These are the only languages we know how to qualify names in. */
3342 && (cu
->language
== language_cplus
|| cu
->language
== language_java
))
3344 if (die_needs_namespace (die
, cu
))
3348 struct ui_file
*buf
;
3350 prefix
= determine_prefix (die
, cu
);
3351 buf
= mem_fileopen ();
3352 if (*prefix
!= '\0')
3354 char *prefixed_name
= typename_concat (NULL
, prefix
, name
, cu
);
3355 fputs_unfiltered (prefixed_name
, buf
);
3356 xfree (prefixed_name
);
3359 fputs_unfiltered (name
? name
: "", buf
);
3361 /* For Java and C++ methods, append formal parameter type
3362 information, if PHYSNAME. */
3364 if (physname
&& die
->tag
== DW_TAG_subprogram
3365 && (cu
->language
== language_cplus
3366 || cu
->language
== language_java
))
3368 struct type
*type
= read_type_die (die
, cu
);
3370 c_type_print_args (type
, buf
, 0, cu
->language
);
3372 if (cu
->language
== language_java
)
3374 /* For java, we must append the return type to method
3376 if (die
->tag
== DW_TAG_subprogram
)
3377 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
3380 else if (cu
->language
== language_cplus
)
3382 if (TYPE_NFIELDS (type
) > 0
3383 && TYPE_FIELD_ARTIFICIAL (type
, 0)
3384 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0))))
3385 fputs_unfiltered (" const", buf
);
3389 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
3391 ui_file_delete (buf
);
3393 if (cu
->language
== language_cplus
)
3396 = dwarf2_canonicalize_name (name
, cu
,
3397 &cu
->objfile
->objfile_obstack
);
3403 else if (cu
->language
== language_ada
)
3405 /* For Ada unit, we prefer the linkage name over the name, as
3406 the former contains the exported name, which the user expects
3407 to be able to reference. Ideally, we want the user to be able
3408 to reference this entity using either natural or linkage name,
3409 but we haven't started looking at this enhancement yet. */
3410 struct attribute
*attr
;
3412 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
3413 if (attr
&& DW_STRING (attr
))
3414 name
= DW_STRING (attr
);
3420 /* Return the fully qualified name of DIE, based on its DW_AT_name.
3421 If scope qualifiers are appropriate they will be added. The result
3422 will be allocated on the objfile_obstack, or NULL if the DIE does
3423 not have a name. NAME may either be from a previous call to
3424 dwarf2_name or NULL.
3426 The output string will be canonicalized (if C++/Java). */
3429 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
3431 return dwarf2_compute_name (name
, die
, cu
, 0);
3434 /* Construct a physname for the given DIE in CU. NAME may either be
3435 from a previous call to dwarf2_name or NULL. The result will be
3436 allocated on the objfile_objstack or NULL if the DIE does not have a
3439 The output string will be canonicalized (if C++/Java). */
3442 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
3444 return dwarf2_compute_name (name
, die
, cu
, 1);
3447 /* Read the import statement specified by the given die and record it. */
3450 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
3452 struct attribute
*import_attr
;
3453 struct die_info
*imported_die
;
3454 struct dwarf2_cu
*imported_cu
;
3455 const char *imported_name
;
3456 const char *imported_name_prefix
;
3459 const char *import_prefix
;
3460 char *canonical_name
;
3462 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
3463 if (import_attr
== NULL
)
3465 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
3466 dwarf_tag_name (die
->tag
));
3471 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
3472 imported_name
= dwarf2_name (imported_die
, imported_cu
);
3473 if (imported_name
== NULL
)
3475 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
3477 The import in the following code:
3491 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
3492 <52> DW_AT_decl_file : 1
3493 <53> DW_AT_decl_line : 6
3494 <54> DW_AT_import : <0x75>
3495 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
3497 <5b> DW_AT_decl_file : 1
3498 <5c> DW_AT_decl_line : 2
3499 <5d> DW_AT_type : <0x6e>
3501 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
3502 <76> DW_AT_byte_size : 4
3503 <77> DW_AT_encoding : 5 (signed)
3505 imports the wrong die ( 0x75 instead of 0x58 ).
3506 This case will be ignored until the gcc bug is fixed. */
3510 /* Figure out the local name after import. */
3511 import_alias
= dwarf2_name (die
, cu
);
3513 /* Figure out where the statement is being imported to. */
3514 import_prefix
= determine_prefix (die
, cu
);
3516 /* Figure out what the scope of the imported die is and prepend it
3517 to the name of the imported die. */
3518 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
3520 if (strlen (imported_name_prefix
) > 0)
3522 canonical_name
= alloca (strlen (imported_name_prefix
)
3523 + 2 + strlen (imported_name
) + 1);
3524 strcpy (canonical_name
, imported_name_prefix
);
3525 strcat (canonical_name
, "::");
3526 strcat (canonical_name
, imported_name
);
3530 canonical_name
= alloca (strlen (imported_name
) + 1);
3531 strcpy (canonical_name
, imported_name
);
3534 cp_add_using_directive (import_prefix
,
3537 &cu
->objfile
->objfile_obstack
);
3541 initialize_cu_func_list (struct dwarf2_cu
*cu
)
3543 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
3547 free_cu_line_header (void *arg
)
3549 struct dwarf2_cu
*cu
= arg
;
3551 free_line_header (cu
->line_header
);
3552 cu
->line_header
= NULL
;
3556 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3558 struct objfile
*objfile
= cu
->objfile
;
3559 struct comp_unit_head
*cu_header
= &cu
->header
;
3560 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3561 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
3562 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
3563 struct attribute
*attr
;
3565 char *comp_dir
= NULL
;
3566 struct die_info
*child_die
;
3567 bfd
*abfd
= objfile
->obfd
;
3568 struct line_header
*line_header
= 0;
3571 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3573 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
3575 /* If we didn't find a lowpc, set it to highpc to avoid complaints
3576 from finish_block. */
3577 if (lowpc
== ((CORE_ADDR
) -1))
3582 /* Find the filename. Do not use dwarf2_name here, since the filename
3583 is not a source language identifier. */
3584 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3587 name
= DW_STRING (attr
);
3590 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
3592 comp_dir
= DW_STRING (attr
);
3593 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
3595 comp_dir
= ldirname (name
);
3596 if (comp_dir
!= NULL
)
3597 make_cleanup (xfree
, comp_dir
);
3599 if (comp_dir
!= NULL
)
3601 /* Irix 6.2 native cc prepends <machine>.: to the compilation
3602 directory, get rid of it. */
3603 char *cp
= strchr (comp_dir
, ':');
3605 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
3612 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
3615 set_cu_language (DW_UNSND (attr
), cu
);
3618 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3620 cu
->producer
= DW_STRING (attr
);
3622 /* We assume that we're processing GCC output. */
3623 processing_gcc_compilation
= 2;
3625 processing_has_namespace_info
= 0;
3627 start_symtab (name
, comp_dir
, lowpc
);
3628 record_debugformat ("DWARF 2");
3629 record_producer (cu
->producer
);
3631 initialize_cu_func_list (cu
);
3633 /* Decode line number information if present. We do this before
3634 processing child DIEs, so that the line header table is available
3635 for DW_AT_decl_file. */
3636 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3639 unsigned int line_offset
= DW_UNSND (attr
);
3640 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3643 cu
->line_header
= line_header
;
3644 make_cleanup (free_cu_line_header
, cu
);
3645 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
3649 /* Process all dies in compilation unit. */
3650 if (die
->child
!= NULL
)
3652 child_die
= die
->child
;
3653 while (child_die
&& child_die
->tag
)
3655 process_die (child_die
, cu
);
3656 child_die
= sibling_die (child_die
);
3660 /* Decode macro information, if present. Dwarf 2 macro information
3661 refers to information in the line number info statement program
3662 header, so we can only read it if we've read the header
3664 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
3665 if (attr
&& line_header
)
3667 unsigned int macro_offset
= DW_UNSND (attr
);
3668 dwarf_decode_macros (line_header
, macro_offset
,
3669 comp_dir
, abfd
, cu
);
3671 do_cleanups (back_to
);
3674 /* For TUs we want to skip the first top level sibling if it's not the
3675 actual type being defined by this TU. In this case the first top
3676 level sibling is there to provide context only. */
3679 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3681 struct objfile
*objfile
= cu
->objfile
;
3682 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3684 struct attribute
*attr
;
3686 char *comp_dir
= NULL
;
3687 struct die_info
*child_die
;
3688 bfd
*abfd
= objfile
->obfd
;
3689 struct line_header
*line_header
= 0;
3691 /* start_symtab needs a low pc, but we don't really have one.
3692 Do what read_file_scope would do in the absence of such info. */
3693 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3695 /* Find the filename. Do not use dwarf2_name here, since the filename
3696 is not a source language identifier. */
3697 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3699 name
= DW_STRING (attr
);
3701 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
3703 comp_dir
= DW_STRING (attr
);
3704 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
3706 comp_dir
= ldirname (name
);
3707 if (comp_dir
!= NULL
)
3708 make_cleanup (xfree
, comp_dir
);
3714 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
3716 set_cu_language (DW_UNSND (attr
), cu
);
3718 /* This isn't technically needed today. It is done for symmetry
3719 with read_file_scope. */
3720 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3722 cu
->producer
= DW_STRING (attr
);
3724 /* We assume that we're processing GCC output. */
3725 processing_gcc_compilation
= 2;
3727 processing_has_namespace_info
= 0;
3729 start_symtab (name
, comp_dir
, lowpc
);
3730 record_debugformat ("DWARF 2");
3731 record_producer (cu
->producer
);
3733 /* Process the dies in the type unit. */
3734 if (die
->child
== NULL
)
3736 dump_die_for_error (die
);
3737 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
3738 bfd_get_filename (abfd
));
3741 child_die
= die
->child
;
3743 while (child_die
&& child_die
->tag
)
3745 process_die (child_die
, cu
);
3747 child_die
= sibling_die (child_die
);
3750 do_cleanups (back_to
);
3754 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
3755 struct dwarf2_cu
*cu
)
3757 struct function_range
*thisfn
;
3759 thisfn
= (struct function_range
*)
3760 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
3761 thisfn
->name
= name
;
3762 thisfn
->lowpc
= lowpc
;
3763 thisfn
->highpc
= highpc
;
3764 thisfn
->seen_line
= 0;
3765 thisfn
->next
= NULL
;
3767 if (cu
->last_fn
== NULL
)
3768 cu
->first_fn
= thisfn
;
3770 cu
->last_fn
->next
= thisfn
;
3772 cu
->last_fn
= thisfn
;
3775 /* qsort helper for inherit_abstract_dies. */
3778 unsigned_int_compar (const void *ap
, const void *bp
)
3780 unsigned int a
= *(unsigned int *) ap
;
3781 unsigned int b
= *(unsigned int *) bp
;
3783 return (a
> b
) - (b
> a
);
3786 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
3787 Inherit only the children of the DW_AT_abstract_origin DIE not being already
3788 referenced by DW_AT_abstract_origin from the children of the current DIE. */
3791 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
3793 struct die_info
*child_die
;
3794 unsigned die_children_count
;
3795 /* CU offsets which were referenced by children of the current DIE. */
3797 unsigned *offsets_end
, *offsetp
;
3798 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
3799 struct die_info
*origin_die
;
3800 /* Iterator of the ORIGIN_DIE children. */
3801 struct die_info
*origin_child_die
;
3802 struct cleanup
*cleanups
;
3803 struct attribute
*attr
;
3805 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
3809 origin_die
= follow_die_ref (die
, attr
, &cu
);
3810 if (die
->tag
!= origin_die
->tag
3811 && !(die
->tag
== DW_TAG_inlined_subroutine
3812 && origin_die
->tag
== DW_TAG_subprogram
))
3813 complaint (&symfile_complaints
,
3814 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
3815 die
->offset
, origin_die
->offset
);
3817 child_die
= die
->child
;
3818 die_children_count
= 0;
3819 while (child_die
&& child_die
->tag
)
3821 child_die
= sibling_die (child_die
);
3822 die_children_count
++;
3824 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
3825 cleanups
= make_cleanup (xfree
, offsets
);
3827 offsets_end
= offsets
;
3828 child_die
= die
->child
;
3829 while (child_die
&& child_die
->tag
)
3831 /* For each CHILD_DIE, find the corresponding child of
3832 ORIGIN_DIE. If there is more than one layer of
3833 DW_AT_abstract_origin, follow them all; there shouldn't be,
3834 but GCC versions at least through 4.4 generate this (GCC PR
3836 struct die_info
*child_origin_die
= child_die
;
3839 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
, cu
);
3842 child_origin_die
= follow_die_ref (child_origin_die
, attr
, &cu
);
3845 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
3846 counterpart may exist. */
3847 if (child_origin_die
!= child_die
)
3849 if (child_die
->tag
!= child_origin_die
->tag
3850 && !(child_die
->tag
== DW_TAG_inlined_subroutine
3851 && child_origin_die
->tag
== DW_TAG_subprogram
))
3852 complaint (&symfile_complaints
,
3853 _("Child DIE 0x%x and its abstract origin 0x%x have "
3854 "different tags"), child_die
->offset
,
3855 child_origin_die
->offset
);
3856 if (child_origin_die
->parent
!= origin_die
)
3857 complaint (&symfile_complaints
,
3858 _("Child DIE 0x%x and its abstract origin 0x%x have "
3859 "different parents"), child_die
->offset
,
3860 child_origin_die
->offset
);
3862 *offsets_end
++ = child_origin_die
->offset
;
3864 child_die
= sibling_die (child_die
);
3866 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
3867 unsigned_int_compar
);
3868 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
3869 if (offsetp
[-1] == *offsetp
)
3870 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
3871 "to DIE 0x%x as their abstract origin"),
3872 die
->offset
, *offsetp
);
3875 origin_child_die
= origin_die
->child
;
3876 while (origin_child_die
&& origin_child_die
->tag
)
3878 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
3879 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
3881 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
3883 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
3884 process_die (origin_child_die
, cu
);
3886 origin_child_die
= sibling_die (origin_child_die
);
3889 do_cleanups (cleanups
);
3893 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3895 struct objfile
*objfile
= cu
->objfile
;
3896 struct context_stack
*new;
3899 struct die_info
*child_die
;
3900 struct attribute
*attr
, *call_line
, *call_file
;
3903 struct block
*block
;
3904 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
3908 /* If we do not have call site information, we can't show the
3909 caller of this inlined function. That's too confusing, so
3910 only use the scope for local variables. */
3911 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
3912 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
3913 if (call_line
== NULL
|| call_file
== NULL
)
3915 read_lexical_block_scope (die
, cu
);
3920 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3922 name
= dwarf2_name (die
, cu
);
3924 /* Ignore functions with missing or empty names and functions with
3925 missing or invalid low and high pc attributes. */
3926 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
3932 /* Record the function range for dwarf_decode_lines. */
3933 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3935 new = push_context (0, lowpc
);
3936 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3938 /* If there is a location expression for DW_AT_frame_base, record
3940 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3942 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3943 expression is being recorded directly in the function's symbol
3944 and not in a separate frame-base object. I guess this hack is
3945 to avoid adding some sort of frame-base adjunct/annex to the
3946 function's symbol :-(. The problem with doing this is that it
3947 results in a function symbol with a location expression that
3948 has nothing to do with the location of the function, ouch! The
3949 relationship should be: a function's symbol has-a frame base; a
3950 frame-base has-a location expression. */
3951 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3953 cu
->list_in_scope
= &local_symbols
;
3955 if (die
->child
!= NULL
)
3957 child_die
= die
->child
;
3958 while (child_die
&& child_die
->tag
)
3960 process_die (child_die
, cu
);
3961 child_die
= sibling_die (child_die
);
3965 inherit_abstract_dies (die
, cu
);
3967 new = pop_context ();
3968 /* Make a block for the local symbols within. */
3969 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3970 lowpc
, highpc
, objfile
);
3972 /* For C++, set the block's scope. */
3973 if (cu
->language
== language_cplus
)
3974 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3975 determine_prefix (die
, cu
),
3976 processing_has_namespace_info
);
3978 /* If we have address ranges, record them. */
3979 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3981 /* In C++, we can have functions nested inside functions (e.g., when
3982 a function declares a class that has methods). This means that
3983 when we finish processing a function scope, we may need to go
3984 back to building a containing block's symbol lists. */
3985 local_symbols
= new->locals
;
3986 param_symbols
= new->params
;
3987 using_directives
= new->using_directives
;
3989 /* If we've finished processing a top-level function, subsequent
3990 symbols go in the file symbol list. */
3991 if (outermost_context_p ())
3992 cu
->list_in_scope
= &file_symbols
;
3995 /* Process all the DIES contained within a lexical block scope. Start
3996 a new scope, process the dies, and then close the scope. */
3999 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4001 struct objfile
*objfile
= cu
->objfile
;
4002 struct context_stack
*new;
4003 CORE_ADDR lowpc
, highpc
;
4004 struct die_info
*child_die
;
4007 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4009 /* Ignore blocks with missing or invalid low and high pc attributes. */
4010 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
4011 as multiple lexical blocks? Handling children in a sane way would
4012 be nasty. Might be easier to properly extend generic blocks to
4014 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
4019 push_context (0, lowpc
);
4020 if (die
->child
!= NULL
)
4022 child_die
= die
->child
;
4023 while (child_die
&& child_die
->tag
)
4025 process_die (child_die
, cu
);
4026 child_die
= sibling_die (child_die
);
4029 new = pop_context ();
4031 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
4034 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
4037 /* Note that recording ranges after traversing children, as we
4038 do here, means that recording a parent's ranges entails
4039 walking across all its children's ranges as they appear in
4040 the address map, which is quadratic behavior.
4042 It would be nicer to record the parent's ranges before
4043 traversing its children, simply overriding whatever you find
4044 there. But since we don't even decide whether to create a
4045 block until after we've traversed its children, that's hard
4047 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
4049 local_symbols
= new->locals
;
4050 using_directives
= new->using_directives
;
4053 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
4054 Return 1 if the attributes are present and valid, otherwise, return 0.
4055 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
4058 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
4059 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
4060 struct partial_symtab
*ranges_pst
)
4062 struct objfile
*objfile
= cu
->objfile
;
4063 struct comp_unit_head
*cu_header
= &cu
->header
;
4064 bfd
*obfd
= objfile
->obfd
;
4065 unsigned int addr_size
= cu_header
->addr_size
;
4066 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
4067 /* Base address selection entry. */
4078 found_base
= cu
->base_known
;
4079 base
= cu
->base_address
;
4081 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
4083 complaint (&symfile_complaints
,
4084 _("Offset %d out of bounds for DW_AT_ranges attribute"),
4088 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
4090 /* Read in the largest possible address. */
4091 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
4092 if ((marker
& mask
) == mask
)
4094 /* If we found the largest possible address, then
4095 read the base address. */
4096 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
4097 buffer
+= 2 * addr_size
;
4098 offset
+= 2 * addr_size
;
4104 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4108 CORE_ADDR range_beginning
, range_end
;
4110 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
4111 buffer
+= addr_size
;
4112 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
4113 buffer
+= addr_size
;
4114 offset
+= 2 * addr_size
;
4116 /* An end of list marker is a pair of zero addresses. */
4117 if (range_beginning
== 0 && range_end
== 0)
4118 /* Found the end of list entry. */
4121 /* Each base address selection entry is a pair of 2 values.
4122 The first is the largest possible address, the second is
4123 the base address. Check for a base address here. */
4124 if ((range_beginning
& mask
) == mask
)
4126 /* If we found the largest possible address, then
4127 read the base address. */
4128 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
4135 /* We have no valid base address for the ranges
4137 complaint (&symfile_complaints
,
4138 _("Invalid .debug_ranges data (no base address)"));
4142 range_beginning
+= base
;
4145 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
4146 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4147 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
4150 /* FIXME: This is recording everything as a low-high
4151 segment of consecutive addresses. We should have a
4152 data structure for discontiguous block ranges
4156 low
= range_beginning
;
4162 if (range_beginning
< low
)
4163 low
= range_beginning
;
4164 if (range_end
> high
)
4170 /* If the first entry is an end-of-list marker, the range
4171 describes an empty scope, i.e. no instructions. */
4177 *high_return
= high
;
4181 /* Get low and high pc attributes from a die. Return 1 if the attributes
4182 are present and valid, otherwise, return 0. Return -1 if the range is
4183 discontinuous, i.e. derived from DW_AT_ranges information. */
4185 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
4186 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
4187 struct partial_symtab
*pst
)
4189 struct attribute
*attr
;
4194 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
4197 high
= DW_ADDR (attr
);
4198 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4200 low
= DW_ADDR (attr
);
4202 /* Found high w/o low attribute. */
4205 /* Found consecutive range of addresses. */
4210 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
4213 /* Value of the DW_AT_ranges attribute is the offset in the
4214 .debug_ranges section. */
4215 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
4217 /* Found discontinuous range of addresses. */
4225 /* When using the GNU linker, .gnu.linkonce. sections are used to
4226 eliminate duplicate copies of functions and vtables and such.
4227 The linker will arbitrarily choose one and discard the others.
4228 The AT_*_pc values for such functions refer to local labels in
4229 these sections. If the section from that file was discarded, the
4230 labels are not in the output, so the relocs get a value of 0.
4231 If this is a discarded function, mark the pc bounds as invalid,
4232 so that GDB will ignore it. */
4233 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
4241 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
4242 its low and high PC addresses. Do nothing if these addresses could not
4243 be determined. Otherwise, set LOWPC to the low address if it is smaller,
4244 and HIGHPC to the high address if greater than HIGHPC. */
4247 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
4248 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4249 struct dwarf2_cu
*cu
)
4251 CORE_ADDR low
, high
;
4252 struct die_info
*child
= die
->child
;
4254 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
4256 *lowpc
= min (*lowpc
, low
);
4257 *highpc
= max (*highpc
, high
);
4260 /* If the language does not allow nested subprograms (either inside
4261 subprograms or lexical blocks), we're done. */
4262 if (cu
->language
!= language_ada
)
4265 /* Check all the children of the given DIE. If it contains nested
4266 subprograms, then check their pc bounds. Likewise, we need to
4267 check lexical blocks as well, as they may also contain subprogram
4269 while (child
&& child
->tag
)
4271 if (child
->tag
== DW_TAG_subprogram
4272 || child
->tag
== DW_TAG_lexical_block
)
4273 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
4274 child
= sibling_die (child
);
4278 /* Get the low and high pc's represented by the scope DIE, and store
4279 them in *LOWPC and *HIGHPC. If the correct values can't be
4280 determined, set *LOWPC to -1 and *HIGHPC to 0. */
4283 get_scope_pc_bounds (struct die_info
*die
,
4284 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4285 struct dwarf2_cu
*cu
)
4287 CORE_ADDR best_low
= (CORE_ADDR
) -1;
4288 CORE_ADDR best_high
= (CORE_ADDR
) 0;
4289 CORE_ADDR current_low
, current_high
;
4291 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
4293 best_low
= current_low
;
4294 best_high
= current_high
;
4298 struct die_info
*child
= die
->child
;
4300 while (child
&& child
->tag
)
4302 switch (child
->tag
) {
4303 case DW_TAG_subprogram
:
4304 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
4306 case DW_TAG_namespace
:
4307 /* FIXME: carlton/2004-01-16: Should we do this for
4308 DW_TAG_class_type/DW_TAG_structure_type, too? I think
4309 that current GCC's always emit the DIEs corresponding
4310 to definitions of methods of classes as children of a
4311 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
4312 the DIEs giving the declarations, which could be
4313 anywhere). But I don't see any reason why the
4314 standards says that they have to be there. */
4315 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
4317 if (current_low
!= ((CORE_ADDR
) -1))
4319 best_low
= min (best_low
, current_low
);
4320 best_high
= max (best_high
, current_high
);
4328 child
= sibling_die (child
);
4333 *highpc
= best_high
;
4336 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
4339 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
4340 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
4342 struct attribute
*attr
;
4344 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
4347 CORE_ADDR high
= DW_ADDR (attr
);
4348 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4351 CORE_ADDR low
= DW_ADDR (attr
);
4352 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
4356 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
4359 bfd
*obfd
= cu
->objfile
->obfd
;
4361 /* The value of the DW_AT_ranges attribute is the offset of the
4362 address range list in the .debug_ranges section. */
4363 unsigned long offset
= DW_UNSND (attr
);
4364 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
4366 /* For some target architectures, but not others, the
4367 read_address function sign-extends the addresses it returns.
4368 To recognize base address selection entries, we need a
4370 unsigned int addr_size
= cu
->header
.addr_size
;
4371 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
4373 /* The base address, to which the next pair is relative. Note
4374 that this 'base' is a DWARF concept: most entries in a range
4375 list are relative, to reduce the number of relocs against the
4376 debugging information. This is separate from this function's
4377 'baseaddr' argument, which GDB uses to relocate debugging
4378 information from a shared library based on the address at
4379 which the library was loaded. */
4380 CORE_ADDR base
= cu
->base_address
;
4381 int base_known
= cu
->base_known
;
4383 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
4385 complaint (&symfile_complaints
,
4386 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
4393 unsigned int bytes_read
;
4394 CORE_ADDR start
, end
;
4396 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
4397 buffer
+= bytes_read
;
4398 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
4399 buffer
+= bytes_read
;
4401 /* Did we find the end of the range list? */
4402 if (start
== 0 && end
== 0)
4405 /* Did we find a base address selection entry? */
4406 else if ((start
& base_select_mask
) == base_select_mask
)
4412 /* We found an ordinary address range. */
4417 complaint (&symfile_complaints
,
4418 _("Invalid .debug_ranges data (no base address)"));
4422 record_block_range (block
,
4423 baseaddr
+ base
+ start
,
4424 baseaddr
+ base
+ end
- 1);
4430 /* Add an aggregate field to the field list. */
4433 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
4434 struct dwarf2_cu
*cu
)
4436 struct objfile
*objfile
= cu
->objfile
;
4437 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4438 struct nextfield
*new_field
;
4439 struct attribute
*attr
;
4441 char *fieldname
= "";
4443 /* Allocate a new field list entry and link it in. */
4444 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
4445 make_cleanup (xfree
, new_field
);
4446 memset (new_field
, 0, sizeof (struct nextfield
));
4448 if (die
->tag
== DW_TAG_inheritance
)
4450 new_field
->next
= fip
->baseclasses
;
4451 fip
->baseclasses
= new_field
;
4455 new_field
->next
= fip
->fields
;
4456 fip
->fields
= new_field
;
4460 /* Handle accessibility and virtuality of field.
4461 The default accessibility for members is public, the default
4462 accessibility for inheritance is private. */
4463 if (die
->tag
!= DW_TAG_inheritance
)
4464 new_field
->accessibility
= DW_ACCESS_public
;
4466 new_field
->accessibility
= DW_ACCESS_private
;
4467 new_field
->virtuality
= DW_VIRTUALITY_none
;
4469 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
4471 new_field
->accessibility
= DW_UNSND (attr
);
4472 if (new_field
->accessibility
!= DW_ACCESS_public
)
4473 fip
->non_public_fields
= 1;
4474 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
4476 new_field
->virtuality
= DW_UNSND (attr
);
4478 fp
= &new_field
->field
;
4480 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
4482 /* Data member other than a C++ static data member. */
4484 /* Get type of field. */
4485 fp
->type
= die_type (die
, cu
);
4487 SET_FIELD_BITPOS (*fp
, 0);
4489 /* Get bit size of field (zero if none). */
4490 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
4493 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
4497 FIELD_BITSIZE (*fp
) = 0;
4500 /* Get bit offset of field. */
4501 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
4504 int byte_offset
= 0;
4506 if (attr_form_is_section_offset (attr
))
4507 dwarf2_complex_location_expr_complaint ();
4508 else if (attr_form_is_constant (attr
))
4509 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
4510 else if (attr_form_is_block (attr
))
4511 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
4513 dwarf2_complex_location_expr_complaint ();
4515 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
4517 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
4520 if (gdbarch_bits_big_endian (gdbarch
))
4522 /* For big endian bits, the DW_AT_bit_offset gives the
4523 additional bit offset from the MSB of the containing
4524 anonymous object to the MSB of the field. We don't
4525 have to do anything special since we don't need to
4526 know the size of the anonymous object. */
4527 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
4531 /* For little endian bits, compute the bit offset to the
4532 MSB of the anonymous object, subtract off the number of
4533 bits from the MSB of the field to the MSB of the
4534 object, and then subtract off the number of bits of
4535 the field itself. The result is the bit offset of
4536 the LSB of the field. */
4538 int bit_offset
= DW_UNSND (attr
);
4540 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4543 /* The size of the anonymous object containing
4544 the bit field is explicit, so use the
4545 indicated size (in bytes). */
4546 anonymous_size
= DW_UNSND (attr
);
4550 /* The size of the anonymous object containing
4551 the bit field must be inferred from the type
4552 attribute of the data member containing the
4554 anonymous_size
= TYPE_LENGTH (fp
->type
);
4556 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
4557 - bit_offset
- FIELD_BITSIZE (*fp
);
4561 /* Get name of field. */
4562 fieldname
= dwarf2_name (die
, cu
);
4563 if (fieldname
== NULL
)
4566 /* The name is already allocated along with this objfile, so we don't
4567 need to duplicate it for the type. */
4568 fp
->name
= fieldname
;
4570 /* Change accessibility for artificial fields (e.g. virtual table
4571 pointer or virtual base class pointer) to private. */
4572 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
4574 FIELD_ARTIFICIAL (*fp
) = 1;
4575 new_field
->accessibility
= DW_ACCESS_private
;
4576 fip
->non_public_fields
= 1;
4579 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
4581 /* C++ static member. */
4583 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
4584 is a declaration, but all versions of G++ as of this writing
4585 (so through at least 3.2.1) incorrectly generate
4586 DW_TAG_variable tags. */
4590 /* Get name of field. */
4591 fieldname
= dwarf2_name (die
, cu
);
4592 if (fieldname
== NULL
)
4595 /* Get physical name. */
4596 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
4598 /* The name is already allocated along with this objfile, so we don't
4599 need to duplicate it for the type. */
4600 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
4601 FIELD_TYPE (*fp
) = die_type (die
, cu
);
4602 FIELD_NAME (*fp
) = fieldname
;
4604 else if (die
->tag
== DW_TAG_inheritance
)
4606 /* C++ base class field. */
4607 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
4610 int byte_offset
= 0;
4612 if (attr_form_is_section_offset (attr
))
4613 dwarf2_complex_location_expr_complaint ();
4614 else if (attr_form_is_constant (attr
))
4615 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
4616 else if (attr_form_is_block (attr
))
4617 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
4619 dwarf2_complex_location_expr_complaint ();
4621 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
4623 FIELD_BITSIZE (*fp
) = 0;
4624 FIELD_TYPE (*fp
) = die_type (die
, cu
);
4625 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
4626 fip
->nbaseclasses
++;
4630 /* Create the vector of fields, and attach it to the type. */
4633 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
4634 struct dwarf2_cu
*cu
)
4636 int nfields
= fip
->nfields
;
4638 /* Record the field count, allocate space for the array of fields,
4639 and create blank accessibility bitfields if necessary. */
4640 TYPE_NFIELDS (type
) = nfields
;
4641 TYPE_FIELDS (type
) = (struct field
*)
4642 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
4643 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
4645 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
4647 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4649 TYPE_FIELD_PRIVATE_BITS (type
) =
4650 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4651 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
4653 TYPE_FIELD_PROTECTED_BITS (type
) =
4654 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4655 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
4657 TYPE_FIELD_IGNORE_BITS (type
) =
4658 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4659 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
4662 /* If the type has baseclasses, allocate and clear a bit vector for
4663 TYPE_FIELD_VIRTUAL_BITS. */
4664 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
4666 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
4667 unsigned char *pointer
;
4669 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4670 pointer
= TYPE_ALLOC (type
, num_bytes
);
4671 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
4672 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
4673 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
4676 /* Copy the saved-up fields into the field vector. Start from the head
4677 of the list, adding to the tail of the field array, so that they end
4678 up in the same order in the array in which they were added to the list. */
4679 while (nfields
-- > 0)
4681 struct nextfield
*fieldp
;
4685 fieldp
= fip
->fields
;
4686 fip
->fields
= fieldp
->next
;
4690 fieldp
= fip
->baseclasses
;
4691 fip
->baseclasses
= fieldp
->next
;
4694 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
4695 switch (fieldp
->accessibility
)
4697 case DW_ACCESS_private
:
4698 if (cu
->language
!= language_ada
)
4699 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
4702 case DW_ACCESS_protected
:
4703 if (cu
->language
!= language_ada
)
4704 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
4707 case DW_ACCESS_public
:
4711 /* Unknown accessibility. Complain and treat it as public. */
4713 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
4714 fieldp
->accessibility
);
4718 if (nfields
< fip
->nbaseclasses
)
4720 switch (fieldp
->virtuality
)
4722 case DW_VIRTUALITY_virtual
:
4723 case DW_VIRTUALITY_pure_virtual
:
4724 if (cu
->language
== language_ada
)
4725 error ("unexpected virtuality in component of Ada type");
4726 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
4733 /* Add a member function to the proper fieldlist. */
4736 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
4737 struct type
*type
, struct dwarf2_cu
*cu
)
4739 struct objfile
*objfile
= cu
->objfile
;
4740 struct attribute
*attr
;
4741 struct fnfieldlist
*flp
;
4743 struct fn_field
*fnp
;
4746 struct nextfnfield
*new_fnfield
;
4747 struct type
*this_type
;
4749 if (cu
->language
== language_ada
)
4750 error ("unexpected member function in Ada type");
4752 /* Get name of member function. */
4753 fieldname
= dwarf2_name (die
, cu
);
4754 if (fieldname
== NULL
)
4757 /* Get the mangled name. */
4758 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
4760 /* Look up member function name in fieldlist. */
4761 for (i
= 0; i
< fip
->nfnfields
; i
++)
4763 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
4767 /* Create new list element if necessary. */
4768 if (i
< fip
->nfnfields
)
4769 flp
= &fip
->fnfieldlists
[i
];
4772 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4774 fip
->fnfieldlists
= (struct fnfieldlist
*)
4775 xrealloc (fip
->fnfieldlists
,
4776 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
4777 * sizeof (struct fnfieldlist
));
4778 if (fip
->nfnfields
== 0)
4779 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
4781 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
4782 flp
->name
= fieldname
;
4788 /* Create a new member function field and chain it to the field list
4790 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
4791 make_cleanup (xfree
, new_fnfield
);
4792 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
4793 new_fnfield
->next
= flp
->head
;
4794 flp
->head
= new_fnfield
;
4797 /* Fill in the member function field info. */
4798 fnp
= &new_fnfield
->fnfield
;
4799 /* The name is already allocated along with this objfile, so we don't
4800 need to duplicate it for the type. */
4801 fnp
->physname
= physname
? physname
: "";
4802 fnp
->type
= alloc_type (objfile
);
4803 this_type
= read_type_die (die
, cu
);
4804 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
4806 int nparams
= TYPE_NFIELDS (this_type
);
4808 /* TYPE is the domain of this method, and THIS_TYPE is the type
4809 of the method itself (TYPE_CODE_METHOD). */
4810 smash_to_method_type (fnp
->type
, type
,
4811 TYPE_TARGET_TYPE (this_type
),
4812 TYPE_FIELDS (this_type
),
4813 TYPE_NFIELDS (this_type
),
4814 TYPE_VARARGS (this_type
));
4816 /* Handle static member functions.
4817 Dwarf2 has no clean way to discern C++ static and non-static
4818 member functions. G++ helps GDB by marking the first
4819 parameter for non-static member functions (which is the
4820 this pointer) as artificial. We obtain this information
4821 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
4822 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
4823 fnp
->voffset
= VOFFSET_STATIC
;
4826 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
4829 /* Get fcontext from DW_AT_containing_type if present. */
4830 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4831 fnp
->fcontext
= die_containing_type (die
, cu
);
4833 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
4834 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
4836 /* Get accessibility. */
4837 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
4840 switch (DW_UNSND (attr
))
4842 case DW_ACCESS_private
:
4843 fnp
->is_private
= 1;
4845 case DW_ACCESS_protected
:
4846 fnp
->is_protected
= 1;
4851 /* Check for artificial methods. */
4852 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
4853 if (attr
&& DW_UNSND (attr
) != 0)
4854 fnp
->is_artificial
= 1;
4856 /* Get index in virtual function table if it is a virtual member
4857 function. For GCC, this is an offset in the appropriate
4858 virtual table, as specified by DW_AT_containing_type. For
4859 everyone else, it is an expression to be evaluated relative
4860 to the object address. */
4862 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
4863 if (attr
&& fnp
->fcontext
)
4865 /* Support the .debug_loc offsets */
4866 if (attr_form_is_block (attr
))
4868 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
4870 else if (attr_form_is_section_offset (attr
))
4872 dwarf2_complex_location_expr_complaint ();
4876 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
4882 /* We only support trivial expressions here. This hack will work
4883 for v3 classes, which always start with the vtable pointer. */
4884 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0
4885 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref
)
4887 struct dwarf_block blk
;
4888 blk
.size
= DW_BLOCK (attr
)->size
- 1;
4889 blk
.data
= DW_BLOCK (attr
)->data
+ 1;
4890 fnp
->voffset
= decode_locdesc (&blk
, cu
);
4891 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
4892 dwarf2_complex_location_expr_complaint ();
4894 fnp
->voffset
/= cu
->header
.addr_size
;
4896 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
4899 dwarf2_complex_location_expr_complaint ();
4903 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
4904 if (attr
&& DW_UNSND (attr
))
4906 /* GCC does this, as of 2008-08-25; PR debug/37237. */
4907 complaint (&symfile_complaints
,
4908 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
4909 fieldname
, die
->offset
);
4910 TYPE_CPLUS_DYNAMIC (type
) = 1;
4915 /* Create the vector of member function fields, and attach it to the type. */
4918 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
4919 struct dwarf2_cu
*cu
)
4921 struct fnfieldlist
*flp
;
4922 int total_length
= 0;
4925 if (cu
->language
== language_ada
)
4926 error ("unexpected member functions in Ada type");
4928 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4929 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
4930 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
4932 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
4934 struct nextfnfield
*nfp
= flp
->head
;
4935 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
4938 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
4939 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
4940 fn_flp
->fn_fields
= (struct fn_field
*)
4941 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
4942 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
4943 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
4945 total_length
+= flp
->length
;
4948 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
4949 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
4952 /* Returns non-zero if NAME is the name of a vtable member in CU's
4953 language, zero otherwise. */
4955 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
4957 static const char vptr
[] = "_vptr";
4958 static const char vtable
[] = "vtable";
4960 /* Look for the C++ and Java forms of the vtable. */
4961 if ((cu
->language
== language_java
4962 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
4963 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
4964 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
4970 /* GCC outputs unnamed structures that are really pointers to member
4971 functions, with the ABI-specified layout. If TYPE describes
4972 such a structure, smash it into a member function type.
4974 GCC shouldn't do this; it should just output pointer to member DIEs.
4975 This is GCC PR debug/28767. */
4978 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
4980 struct type
*pfn_type
, *domain_type
, *new_type
;
4982 /* Check for a structure with no name and two children. */
4983 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
4986 /* Check for __pfn and __delta members. */
4987 if (TYPE_FIELD_NAME (type
, 0) == NULL
4988 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
4989 || TYPE_FIELD_NAME (type
, 1) == NULL
4990 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
4993 /* Find the type of the method. */
4994 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
4995 if (pfn_type
== NULL
4996 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
4997 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
5000 /* Look for the "this" argument. */
5001 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
5002 if (TYPE_NFIELDS (pfn_type
) == 0
5003 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
5004 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
5007 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
5008 new_type
= alloc_type (objfile
);
5009 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
5010 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
5011 TYPE_VARARGS (pfn_type
));
5012 smash_to_methodptr_type (type
, new_type
);
5015 /* Called when we find the DIE that starts a structure or union scope
5016 (definition) to process all dies that define the members of the
5019 NOTE: we need to call struct_type regardless of whether or not the
5020 DIE has an at_name attribute, since it might be an anonymous
5021 structure or union. This gets the type entered into our set of
5024 However, if the structure is incomplete (an opaque struct/union)
5025 then suppress creating a symbol table entry for it since gdb only
5026 wants to find the one with the complete definition. Note that if
5027 it is complete, we just call new_symbol, which does it's own
5028 checking about whether the struct/union is anonymous or not (and
5029 suppresses creating a symbol table entry itself). */
5031 static struct type
*
5032 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5034 struct objfile
*objfile
= cu
->objfile
;
5036 struct attribute
*attr
;
5038 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5040 /* If the definition of this type lives in .debug_types, read that type.
5041 Don't follow DW_AT_specification though, that will take us back up
5042 the chain and we want to go down. */
5043 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
5046 struct dwarf2_cu
*type_cu
= cu
;
5047 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
5048 /* We could just recurse on read_structure_type, but we need to call
5049 get_die_type to ensure only one type for this DIE is created.
5050 This is important, for example, because for c++ classes we need
5051 TYPE_NAME set which is only done by new_symbol. Blech. */
5052 type
= read_type_die (type_die
, type_cu
);
5053 return set_die_type (die
, type
, cu
);
5056 type
= alloc_type (objfile
);
5057 INIT_CPLUS_SPECIFIC (type
);
5059 name
= dwarf2_name (die
, cu
);
5062 if (cu
->language
== language_cplus
5063 || cu
->language
== language_java
)
5065 TYPE_TAG_NAME (type
) = (char *) dwarf2_full_name (name
, die
, cu
);
5066 if (die
->tag
== DW_TAG_structure_type
5067 || die
->tag
== DW_TAG_class_type
)
5068 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
5072 /* The name is already allocated along with this objfile, so
5073 we don't need to duplicate it for the type. */
5074 TYPE_TAG_NAME (type
) = (char *) name
;
5075 if (die
->tag
== DW_TAG_class_type
)
5076 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
5080 if (die
->tag
== DW_TAG_structure_type
)
5082 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
5084 else if (die
->tag
== DW_TAG_union_type
)
5086 TYPE_CODE (type
) = TYPE_CODE_UNION
;
5090 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
5093 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
5094 TYPE_DECLARED_CLASS (type
) = 1;
5096 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5099 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5103 TYPE_LENGTH (type
) = 0;
5106 TYPE_STUB_SUPPORTED (type
) = 1;
5107 if (die_is_declaration (die
, cu
))
5108 TYPE_STUB (type
) = 1;
5110 set_descriptive_type (type
, die
, cu
);
5112 /* We need to add the type field to the die immediately so we don't
5113 infinitely recurse when dealing with pointers to the structure
5114 type within the structure itself. */
5115 set_die_type (die
, type
, cu
);
5117 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
5119 struct field_info fi
;
5120 struct die_info
*child_die
;
5122 memset (&fi
, 0, sizeof (struct field_info
));
5124 child_die
= die
->child
;
5126 while (child_die
&& child_die
->tag
)
5128 if (child_die
->tag
== DW_TAG_member
5129 || child_die
->tag
== DW_TAG_variable
)
5131 /* NOTE: carlton/2002-11-05: A C++ static data member
5132 should be a DW_TAG_member that is a declaration, but
5133 all versions of G++ as of this writing (so through at
5134 least 3.2.1) incorrectly generate DW_TAG_variable
5135 tags for them instead. */
5136 dwarf2_add_field (&fi
, child_die
, cu
);
5138 else if (child_die
->tag
== DW_TAG_subprogram
)
5140 /* C++ member function. */
5141 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
5143 else if (child_die
->tag
== DW_TAG_inheritance
)
5145 /* C++ base class field. */
5146 dwarf2_add_field (&fi
, child_die
, cu
);
5148 child_die
= sibling_die (child_die
);
5151 /* Attach fields and member functions to the type. */
5153 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
5156 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
5158 /* Get the type which refers to the base class (possibly this
5159 class itself) which contains the vtable pointer for the current
5160 class from the DW_AT_containing_type attribute. This use of
5161 DW_AT_containing_type is a GNU extension. */
5163 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
5165 struct type
*t
= die_containing_type (die
, cu
);
5167 TYPE_VPTR_BASETYPE (type
) = t
;
5172 /* Our own class provides vtbl ptr. */
5173 for (i
= TYPE_NFIELDS (t
) - 1;
5174 i
>= TYPE_N_BASECLASSES (t
);
5177 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
5179 if (is_vtable_name (fieldname
, cu
))
5181 TYPE_VPTR_FIELDNO (type
) = i
;
5186 /* Complain if virtual function table field not found. */
5187 if (i
< TYPE_N_BASECLASSES (t
))
5188 complaint (&symfile_complaints
,
5189 _("virtual function table pointer not found when defining class '%s'"),
5190 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
5195 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
5198 else if (cu
->producer
5199 && strncmp (cu
->producer
,
5200 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
5202 /* The IBM XLC compiler does not provide direct indication
5203 of the containing type, but the vtable pointer is
5204 always named __vfp. */
5208 for (i
= TYPE_NFIELDS (type
) - 1;
5209 i
>= TYPE_N_BASECLASSES (type
);
5212 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
5214 TYPE_VPTR_FIELDNO (type
) = i
;
5215 TYPE_VPTR_BASETYPE (type
) = type
;
5223 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
5225 do_cleanups (back_to
);
5230 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5232 struct objfile
*objfile
= cu
->objfile
;
5233 struct die_info
*child_die
= die
->child
;
5234 struct type
*this_type
;
5236 this_type
= get_die_type (die
, cu
);
5237 if (this_type
== NULL
)
5238 this_type
= read_structure_type (die
, cu
);
5240 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
5241 snapshots) has been known to create a die giving a declaration
5242 for a class that has, as a child, a die giving a definition for a
5243 nested class. So we have to process our children even if the
5244 current die is a declaration. Normally, of course, a declaration
5245 won't have any children at all. */
5247 while (child_die
!= NULL
&& child_die
->tag
)
5249 if (child_die
->tag
== DW_TAG_member
5250 || child_die
->tag
== DW_TAG_variable
5251 || child_die
->tag
== DW_TAG_inheritance
)
5256 process_die (child_die
, cu
);
5258 child_die
= sibling_die (child_die
);
5261 /* Do not consider external references. According to the DWARF standard,
5262 these DIEs are identified by the fact that they have no byte_size
5263 attribute, and a declaration attribute. */
5264 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
5265 || !die_is_declaration (die
, cu
))
5266 new_symbol (die
, this_type
, cu
);
5269 /* Given a DW_AT_enumeration_type die, set its type. We do not
5270 complete the type's fields yet, or create any symbols. */
5272 static struct type
*
5273 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5275 struct objfile
*objfile
= cu
->objfile
;
5277 struct attribute
*attr
;
5280 /* If the definition of this type lives in .debug_types, read that type.
5281 Don't follow DW_AT_specification though, that will take us back up
5282 the chain and we want to go down. */
5283 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
5286 struct dwarf2_cu
*type_cu
= cu
;
5287 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
5288 type
= read_type_die (type_die
, type_cu
);
5289 return set_die_type (die
, type
, cu
);
5292 type
= alloc_type (objfile
);
5294 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
5295 name
= dwarf2_full_name (NULL
, die
, cu
);
5297 TYPE_TAG_NAME (type
) = (char *) name
;
5299 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5302 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5306 TYPE_LENGTH (type
) = 0;
5309 /* The enumeration DIE can be incomplete. In Ada, any type can be
5310 declared as private in the package spec, and then defined only
5311 inside the package body. Such types are known as Taft Amendment
5312 Types. When another package uses such a type, an incomplete DIE
5313 may be generated by the compiler. */
5314 if (die_is_declaration (die
, cu
))
5315 TYPE_STUB (type
) = 1;
5317 return set_die_type (die
, type
, cu
);
5320 /* Given a pointer to a die which begins an enumeration, process all
5321 the dies that define the members of the enumeration, and create the
5322 symbol for the enumeration type.
5324 NOTE: We reverse the order of the element list. */
5327 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5329 struct objfile
*objfile
= cu
->objfile
;
5330 struct die_info
*child_die
;
5331 struct field
*fields
;
5334 int unsigned_enum
= 1;
5336 struct type
*this_type
;
5340 this_type
= get_die_type (die
, cu
);
5341 if (this_type
== NULL
)
5342 this_type
= read_enumeration_type (die
, cu
);
5343 if (die
->child
!= NULL
)
5345 child_die
= die
->child
;
5346 while (child_die
&& child_die
->tag
)
5348 if (child_die
->tag
!= DW_TAG_enumerator
)
5350 process_die (child_die
, cu
);
5354 name
= dwarf2_name (child_die
, cu
);
5357 sym
= new_symbol (child_die
, this_type
, cu
);
5358 if (SYMBOL_VALUE (sym
) < 0)
5361 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
5363 fields
= (struct field
*)
5365 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
5366 * sizeof (struct field
));
5369 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
5370 FIELD_TYPE (fields
[num_fields
]) = NULL
;
5371 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
5372 FIELD_BITSIZE (fields
[num_fields
]) = 0;
5378 child_die
= sibling_die (child_die
);
5383 TYPE_NFIELDS (this_type
) = num_fields
;
5384 TYPE_FIELDS (this_type
) = (struct field
*)
5385 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
5386 memcpy (TYPE_FIELDS (this_type
), fields
,
5387 sizeof (struct field
) * num_fields
);
5391 TYPE_UNSIGNED (this_type
) = 1;
5394 new_symbol (die
, this_type
, cu
);
5397 /* Extract all information from a DW_TAG_array_type DIE and put it in
5398 the DIE's type field. For now, this only handles one dimensional
5401 static struct type
*
5402 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5404 struct objfile
*objfile
= cu
->objfile
;
5405 struct die_info
*child_die
;
5406 struct type
*type
= NULL
;
5407 struct type
*element_type
, *range_type
, *index_type
;
5408 struct type
**range_types
= NULL
;
5409 struct attribute
*attr
;
5411 struct cleanup
*back_to
;
5414 element_type
= die_type (die
, cu
);
5416 /* Irix 6.2 native cc creates array types without children for
5417 arrays with unspecified length. */
5418 if (die
->child
== NULL
)
5420 index_type
= objfile_type (objfile
)->builtin_int
;
5421 range_type
= create_range_type (NULL
, index_type
, 0, -1);
5422 type
= create_array_type (NULL
, element_type
, range_type
);
5423 return set_die_type (die
, type
, cu
);
5426 back_to
= make_cleanup (null_cleanup
, NULL
);
5427 child_die
= die
->child
;
5428 while (child_die
&& child_die
->tag
)
5430 if (child_die
->tag
== DW_TAG_subrange_type
)
5432 struct type
*child_type
= read_type_die (child_die
, cu
);
5433 if (child_type
!= NULL
)
5435 /* The range type was succesfully read. Save it for
5436 the array type creation. */
5437 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
5439 range_types
= (struct type
**)
5440 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
5441 * sizeof (struct type
*));
5443 make_cleanup (free_current_contents
, &range_types
);
5445 range_types
[ndim
++] = child_type
;
5448 child_die
= sibling_die (child_die
);
5451 /* Dwarf2 dimensions are output from left to right, create the
5452 necessary array types in backwards order. */
5454 type
= element_type
;
5456 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
5460 type
= create_array_type (NULL
, type
, range_types
[i
++]);
5465 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
5468 /* Understand Dwarf2 support for vector types (like they occur on
5469 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
5470 array type. This is not part of the Dwarf2/3 standard yet, but a
5471 custom vendor extension. The main difference between a regular
5472 array and the vector variant is that vectors are passed by value
5474 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
5476 make_vector_type (type
);
5478 name
= dwarf2_name (die
, cu
);
5480 TYPE_NAME (type
) = name
;
5482 set_descriptive_type (type
, die
, cu
);
5484 do_cleanups (back_to
);
5486 /* Install the type in the die. */
5487 return set_die_type (die
, type
, cu
);
5490 static enum dwarf_array_dim_ordering
5491 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
5493 struct attribute
*attr
;
5495 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
5497 if (attr
) return DW_SND (attr
);
5500 GNU F77 is a special case, as at 08/2004 array type info is the
5501 opposite order to the dwarf2 specification, but data is still
5502 laid out as per normal fortran.
5504 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
5508 if (cu
->language
== language_fortran
5509 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
5511 return DW_ORD_row_major
;
5514 switch (cu
->language_defn
->la_array_ordering
)
5516 case array_column_major
:
5517 return DW_ORD_col_major
;
5518 case array_row_major
:
5520 return DW_ORD_row_major
;
5524 /* Extract all information from a DW_TAG_set_type DIE and put it in
5525 the DIE's type field. */
5527 static struct type
*
5528 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5530 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
5532 return set_die_type (die
, set_type
, cu
);
5535 /* First cut: install each common block member as a global variable. */
5538 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
5540 struct die_info
*child_die
;
5541 struct attribute
*attr
;
5543 CORE_ADDR base
= (CORE_ADDR
) 0;
5545 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
5548 /* Support the .debug_loc offsets */
5549 if (attr_form_is_block (attr
))
5551 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
5553 else if (attr_form_is_section_offset (attr
))
5555 dwarf2_complex_location_expr_complaint ();
5559 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5560 "common block member");
5563 if (die
->child
!= NULL
)
5565 child_die
= die
->child
;
5566 while (child_die
&& child_die
->tag
)
5568 sym
= new_symbol (child_die
, NULL
, cu
);
5569 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
5572 CORE_ADDR byte_offset
= 0;
5574 if (attr_form_is_section_offset (attr
))
5575 dwarf2_complex_location_expr_complaint ();
5576 else if (attr_form_is_constant (attr
))
5577 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
5578 else if (attr_form_is_block (attr
))
5579 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
5581 dwarf2_complex_location_expr_complaint ();
5583 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
5584 add_symbol_to_list (sym
, &global_symbols
);
5586 child_die
= sibling_die (child_die
);
5591 /* Create a type for a C++ namespace. */
5593 static struct type
*
5594 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5596 struct objfile
*objfile
= cu
->objfile
;
5597 const char *previous_prefix
, *name
;
5601 /* For extensions, reuse the type of the original namespace. */
5602 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
5604 struct die_info
*ext_die
;
5605 struct dwarf2_cu
*ext_cu
= cu
;
5606 ext_die
= dwarf2_extension (die
, &ext_cu
);
5607 type
= read_type_die (ext_die
, ext_cu
);
5608 return set_die_type (die
, type
, cu
);
5611 name
= namespace_name (die
, &is_anonymous
, cu
);
5613 /* Now build the name of the current namespace. */
5615 previous_prefix
= determine_prefix (die
, cu
);
5616 if (previous_prefix
[0] != '\0')
5617 name
= typename_concat (&objfile
->objfile_obstack
,
5618 previous_prefix
, name
, cu
);
5620 /* Create the type. */
5621 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
5623 TYPE_NAME (type
) = (char *) name
;
5624 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5626 set_die_type (die
, type
, cu
);
5631 /* Read a C++ namespace. */
5634 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
5636 struct objfile
*objfile
= cu
->objfile
;
5640 /* Add a symbol associated to this if we haven't seen the namespace
5641 before. Also, add a using directive if it's an anonymous
5644 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
5648 type
= read_type_die (die
, cu
);
5649 new_symbol (die
, type
, cu
);
5651 name
= namespace_name (die
, &is_anonymous
, cu
);
5654 const char *previous_prefix
= determine_prefix (die
, cu
);
5655 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
5656 &objfile
->objfile_obstack
);
5660 if (die
->child
!= NULL
)
5662 struct die_info
*child_die
= die
->child
;
5664 while (child_die
&& child_die
->tag
)
5666 process_die (child_die
, cu
);
5667 child_die
= sibling_die (child_die
);
5672 /* Read a Fortran module. */
5675 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
5677 struct die_info
*child_die
= die
->child
;
5679 /* FIXME: Support the separate Fortran module namespaces. */
5681 while (child_die
&& child_die
->tag
)
5683 process_die (child_die
, cu
);
5684 child_die
= sibling_die (child_die
);
5688 /* Return the name of the namespace represented by DIE. Set
5689 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
5693 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
5695 struct die_info
*current_die
;
5696 const char *name
= NULL
;
5698 /* Loop through the extensions until we find a name. */
5700 for (current_die
= die
;
5701 current_die
!= NULL
;
5702 current_die
= dwarf2_extension (die
, &cu
))
5704 name
= dwarf2_name (current_die
, cu
);
5709 /* Is it an anonymous namespace? */
5711 *is_anonymous
= (name
== NULL
);
5713 name
= "(anonymous namespace)";
5718 /* Extract all information from a DW_TAG_pointer_type DIE and add to
5719 the user defined type vector. */
5721 static struct type
*
5722 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5724 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5725 struct comp_unit_head
*cu_header
= &cu
->header
;
5727 struct attribute
*attr_byte_size
;
5728 struct attribute
*attr_address_class
;
5729 int byte_size
, addr_class
;
5731 type
= lookup_pointer_type (die_type (die
, cu
));
5733 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5735 byte_size
= DW_UNSND (attr_byte_size
);
5737 byte_size
= cu_header
->addr_size
;
5739 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
5740 if (attr_address_class
)
5741 addr_class
= DW_UNSND (attr_address_class
);
5743 addr_class
= DW_ADDR_none
;
5745 /* If the pointer size or address class is different than the
5746 default, create a type variant marked as such and set the
5747 length accordingly. */
5748 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
5750 if (gdbarch_address_class_type_flags_p (gdbarch
))
5754 type_flags
= gdbarch_address_class_type_flags
5755 (gdbarch
, byte_size
, addr_class
);
5756 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
5758 type
= make_type_with_address_space (type
, type_flags
);
5760 else if (TYPE_LENGTH (type
) != byte_size
)
5762 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
5765 /* Should we also complain about unhandled address classes? */
5769 TYPE_LENGTH (type
) = byte_size
;
5770 return set_die_type (die
, type
, cu
);
5773 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
5774 the user defined type vector. */
5776 static struct type
*
5777 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5779 struct objfile
*objfile
= cu
->objfile
;
5781 struct type
*to_type
;
5782 struct type
*domain
;
5784 to_type
= die_type (die
, cu
);
5785 domain
= die_containing_type (die
, cu
);
5787 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
5788 type
= lookup_methodptr_type (to_type
);
5790 type
= lookup_memberptr_type (to_type
, domain
);
5792 return set_die_type (die
, type
, cu
);
5795 /* Extract all information from a DW_TAG_reference_type DIE and add to
5796 the user defined type vector. */
5798 static struct type
*
5799 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5801 struct comp_unit_head
*cu_header
= &cu
->header
;
5803 struct attribute
*attr
;
5805 type
= lookup_reference_type (die_type (die
, cu
));
5806 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5809 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5813 TYPE_LENGTH (type
) = cu_header
->addr_size
;
5815 return set_die_type (die
, type
, cu
);
5818 static struct type
*
5819 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5821 struct type
*base_type
, *cv_type
;
5823 base_type
= die_type (die
, cu
);
5824 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
5825 return set_die_type (die
, cv_type
, cu
);
5828 static struct type
*
5829 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5831 struct type
*base_type
, *cv_type
;
5833 base_type
= die_type (die
, cu
);
5834 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
5835 return set_die_type (die
, cv_type
, cu
);
5838 /* Extract all information from a DW_TAG_string_type DIE and add to
5839 the user defined type vector. It isn't really a user defined type,
5840 but it behaves like one, with other DIE's using an AT_user_def_type
5841 attribute to reference it. */
5843 static struct type
*
5844 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5846 struct objfile
*objfile
= cu
->objfile
;
5847 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5848 struct type
*type
, *range_type
, *index_type
, *char_type
;
5849 struct attribute
*attr
;
5850 unsigned int length
;
5852 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
5855 length
= DW_UNSND (attr
);
5859 /* check for the DW_AT_byte_size attribute */
5860 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5863 length
= DW_UNSND (attr
);
5871 index_type
= objfile_type (objfile
)->builtin_int
;
5872 range_type
= create_range_type (NULL
, index_type
, 1, length
);
5873 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
5874 type
= create_string_type (NULL
, char_type
, range_type
);
5876 return set_die_type (die
, type
, cu
);
5879 /* Handle DIES due to C code like:
5883 int (*funcp)(int a, long l);
5887 ('funcp' generates a DW_TAG_subroutine_type DIE)
5890 static struct type
*
5891 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5893 struct type
*type
; /* Type that this function returns */
5894 struct type
*ftype
; /* Function that returns above type */
5895 struct attribute
*attr
;
5897 type
= die_type (die
, cu
);
5898 ftype
= lookup_function_type (type
);
5900 /* All functions in C++, Pascal and Java have prototypes. */
5901 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
5902 if ((attr
&& (DW_UNSND (attr
) != 0))
5903 || cu
->language
== language_cplus
5904 || cu
->language
== language_java
5905 || cu
->language
== language_pascal
)
5906 TYPE_PROTOTYPED (ftype
) = 1;
5908 /* Store the calling convention in the type if it's available in
5909 the subroutine die. Otherwise set the calling convention to
5910 the default value DW_CC_normal. */
5911 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
5912 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
5914 /* We need to add the subroutine type to the die immediately so
5915 we don't infinitely recurse when dealing with parameters
5916 declared as the same subroutine type. */
5917 set_die_type (die
, ftype
, cu
);
5919 if (die
->child
!= NULL
)
5921 struct die_info
*child_die
;
5925 /* Count the number of parameters.
5926 FIXME: GDB currently ignores vararg functions, but knows about
5927 vararg member functions. */
5928 child_die
= die
->child
;
5929 while (child_die
&& child_die
->tag
)
5931 if (child_die
->tag
== DW_TAG_formal_parameter
)
5933 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
5934 TYPE_VARARGS (ftype
) = 1;
5935 child_die
= sibling_die (child_die
);
5938 /* Allocate storage for parameters and fill them in. */
5939 TYPE_NFIELDS (ftype
) = nparams
;
5940 TYPE_FIELDS (ftype
) = (struct field
*)
5941 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
5943 child_die
= die
->child
;
5944 while (child_die
&& child_die
->tag
)
5946 if (child_die
->tag
== DW_TAG_formal_parameter
)
5948 /* Dwarf2 has no clean way to discern C++ static and non-static
5949 member functions. G++ helps GDB by marking the first
5950 parameter for non-static member functions (which is the
5951 this pointer) as artificial. We pass this information
5952 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
5953 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
5955 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
5957 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
5958 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
5961 child_die
= sibling_die (child_die
);
5968 static struct type
*
5969 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
5971 struct objfile
*objfile
= cu
->objfile
;
5972 struct attribute
*attr
;
5973 const char *name
= NULL
;
5974 struct type
*this_type
;
5976 name
= dwarf2_full_name (NULL
, die
, cu
);
5977 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
5978 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
5979 TYPE_NAME (this_type
) = (char *) name
;
5980 set_die_type (die
, this_type
, cu
);
5981 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
5985 /* Find a representation of a given base type and install
5986 it in the TYPE field of the die. */
5988 static struct type
*
5989 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5991 struct objfile
*objfile
= cu
->objfile
;
5993 struct attribute
*attr
;
5994 int encoding
= 0, size
= 0;
5996 enum type_code code
= TYPE_CODE_INT
;
5998 struct type
*target_type
= NULL
;
6000 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
6003 encoding
= DW_UNSND (attr
);
6005 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6008 size
= DW_UNSND (attr
);
6010 name
= dwarf2_name (die
, cu
);
6013 complaint (&symfile_complaints
,
6014 _("DW_AT_name missing from DW_TAG_base_type"));
6019 case DW_ATE_address
:
6020 /* Turn DW_ATE_address into a void * pointer. */
6021 code
= TYPE_CODE_PTR
;
6022 type_flags
|= TYPE_FLAG_UNSIGNED
;
6023 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
6025 case DW_ATE_boolean
:
6026 code
= TYPE_CODE_BOOL
;
6027 type_flags
|= TYPE_FLAG_UNSIGNED
;
6029 case DW_ATE_complex_float
:
6030 code
= TYPE_CODE_COMPLEX
;
6031 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
6033 case DW_ATE_decimal_float
:
6034 code
= TYPE_CODE_DECFLOAT
;
6037 code
= TYPE_CODE_FLT
;
6041 case DW_ATE_unsigned
:
6042 type_flags
|= TYPE_FLAG_UNSIGNED
;
6044 case DW_ATE_signed_char
:
6045 if (cu
->language
== language_ada
|| cu
->language
== language_m2
6046 || cu
->language
== language_pascal
)
6047 code
= TYPE_CODE_CHAR
;
6049 case DW_ATE_unsigned_char
:
6050 if (cu
->language
== language_ada
|| cu
->language
== language_m2
6051 || cu
->language
== language_pascal
)
6052 code
= TYPE_CODE_CHAR
;
6053 type_flags
|= TYPE_FLAG_UNSIGNED
;
6056 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
6057 dwarf_type_encoding_name (encoding
));
6061 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
6062 TYPE_NAME (type
) = name
;
6063 TYPE_TARGET_TYPE (type
) = target_type
;
6065 if (name
&& strcmp (name
, "char") == 0)
6066 TYPE_NOSIGN (type
) = 1;
6068 return set_die_type (die
, type
, cu
);
6071 /* Read the given DW_AT_subrange DIE. */
6073 static struct type
*
6074 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6076 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
6077 struct type
*base_type
;
6078 struct type
*range_type
;
6079 struct attribute
*attr
;
6083 LONGEST negative_mask
;
6085 base_type
= die_type (die
, cu
);
6086 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
6088 complaint (&symfile_complaints
,
6089 _("DW_AT_type missing from DW_TAG_subrange_type"));
6091 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
6092 0, NULL
, cu
->objfile
);
6095 if (cu
->language
== language_fortran
)
6097 /* FORTRAN implies a lower bound of 1, if not given. */
6101 /* FIXME: For variable sized arrays either of these could be
6102 a variable rather than a constant value. We'll allow it,
6103 but we don't know how to handle it. */
6104 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
6106 low
= dwarf2_get_attr_constant_value (attr
, 0);
6108 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
6111 if (attr
->form
== DW_FORM_block1
)
6113 /* GCC encodes arrays with unspecified or dynamic length
6114 with a DW_FORM_block1 attribute.
6115 FIXME: GDB does not yet know how to handle dynamic
6116 arrays properly, treat them as arrays with unspecified
6119 FIXME: jimb/2003-09-22: GDB does not really know
6120 how to handle arrays of unspecified length
6121 either; we just represent them as zero-length
6122 arrays. Choose an appropriate upper bound given
6123 the lower bound we've computed above. */
6127 high
= dwarf2_get_attr_constant_value (attr
, 1);
6131 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
6132 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
6133 low
|= negative_mask
;
6134 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
6135 high
|= negative_mask
;
6137 range_type
= create_range_type (NULL
, base_type
, low
, high
);
6139 name
= dwarf2_name (die
, cu
);
6141 TYPE_NAME (range_type
) = name
;
6143 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6145 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
6147 set_descriptive_type (range_type
, die
, cu
);
6149 return set_die_type (die
, range_type
, cu
);
6152 static struct type
*
6153 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6157 /* For now, we only support the C meaning of an unspecified type: void. */
6159 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
6160 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
6162 return set_die_type (die
, type
, cu
);
6165 /* Trivial hash function for die_info: the hash value of a DIE
6166 is its offset in .debug_info for this objfile. */
6169 die_hash (const void *item
)
6171 const struct die_info
*die
= item
;
6175 /* Trivial comparison function for die_info structures: two DIEs
6176 are equal if they have the same offset. */
6179 die_eq (const void *item_lhs
, const void *item_rhs
)
6181 const struct die_info
*die_lhs
= item_lhs
;
6182 const struct die_info
*die_rhs
= item_rhs
;
6183 return die_lhs
->offset
== die_rhs
->offset
;
6186 /* Read a whole compilation unit into a linked list of dies. */
6188 static struct die_info
*
6189 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6191 struct die_reader_specs reader_specs
;
6193 gdb_assert (cu
->die_hash
== NULL
);
6195 = htab_create_alloc_ex (cu
->header
.length
/ 12,
6199 &cu
->comp_unit_obstack
,
6200 hashtab_obstack_allocate
,
6201 dummy_obstack_deallocate
);
6203 init_cu_die_reader (&reader_specs
, cu
);
6205 return read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
6208 /* Main entry point for reading a DIE and all children.
6209 Read the DIE and dump it if requested. */
6211 static struct die_info
*
6212 read_die_and_children (const struct die_reader_specs
*reader
,
6214 gdb_byte
**new_info_ptr
,
6215 struct die_info
*parent
)
6217 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
6218 new_info_ptr
, parent
);
6220 if (dwarf2_die_debug
)
6222 fprintf_unfiltered (gdb_stdlog
,
6223 "\nRead die from %s of %s:\n",
6224 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
6226 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
6228 : "unknown section",
6229 reader
->abfd
->filename
);
6230 dump_die (result
, dwarf2_die_debug
);
6236 /* Read a single die and all its descendents. Set the die's sibling
6237 field to NULL; set other fields in the die correctly, and set all
6238 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
6239 location of the info_ptr after reading all of those dies. PARENT
6240 is the parent of the die in question. */
6242 static struct die_info
*
6243 read_die_and_children_1 (const struct die_reader_specs
*reader
,
6245 gdb_byte
**new_info_ptr
,
6246 struct die_info
*parent
)
6248 struct die_info
*die
;
6252 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
6255 *new_info_ptr
= cur_ptr
;
6258 store_in_ref_table (die
, reader
->cu
);
6261 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
6265 *new_info_ptr
= cur_ptr
;
6268 die
->sibling
= NULL
;
6269 die
->parent
= parent
;
6273 /* Read a die, all of its descendents, and all of its siblings; set
6274 all of the fields of all of the dies correctly. Arguments are as
6275 in read_die_and_children. */
6277 static struct die_info
*
6278 read_die_and_siblings (const struct die_reader_specs
*reader
,
6280 gdb_byte
**new_info_ptr
,
6281 struct die_info
*parent
)
6283 struct die_info
*first_die
, *last_sibling
;
6287 first_die
= last_sibling
= NULL
;
6291 struct die_info
*die
6292 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
6296 *new_info_ptr
= cur_ptr
;
6303 last_sibling
->sibling
= die
;
6309 /* Read the die from the .debug_info section buffer. Set DIEP to
6310 point to a newly allocated die with its information, except for its
6311 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6312 whether the die has children or not. */
6315 read_full_die (const struct die_reader_specs
*reader
,
6316 struct die_info
**diep
, gdb_byte
*info_ptr
,
6319 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6320 struct abbrev_info
*abbrev
;
6321 struct die_info
*die
;
6322 struct dwarf2_cu
*cu
= reader
->cu
;
6323 bfd
*abfd
= reader
->abfd
;
6325 offset
= info_ptr
- reader
->buffer
;
6326 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6327 info_ptr
+= bytes_read
;
6335 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6337 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6339 bfd_get_filename (abfd
));
6341 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6342 die
->offset
= offset
;
6343 die
->tag
= abbrev
->tag
;
6344 die
->abbrev
= abbrev_number
;
6346 die
->num_attrs
= abbrev
->num_attrs
;
6348 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6349 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6350 abfd
, info_ptr
, cu
);
6353 *has_children
= abbrev
->has_children
;
6357 /* In DWARF version 2, the description of the debugging information is
6358 stored in a separate .debug_abbrev section. Before we read any
6359 dies from a section we read in all abbreviations and install them
6360 in a hash table. This function also sets flags in CU describing
6361 the data found in the abbrev table. */
6364 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
6366 struct comp_unit_head
*cu_header
= &cu
->header
;
6367 gdb_byte
*abbrev_ptr
;
6368 struct abbrev_info
*cur_abbrev
;
6369 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
6370 unsigned int abbrev_form
, hash_number
;
6371 struct attr_abbrev
*cur_attrs
;
6372 unsigned int allocated_attrs
;
6374 /* Initialize dwarf2 abbrevs */
6375 obstack_init (&cu
->abbrev_obstack
);
6376 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
6378 * sizeof (struct abbrev_info
*)));
6379 memset (cu
->dwarf2_abbrevs
, 0,
6380 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
6382 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
6383 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6384 abbrev_ptr
+= bytes_read
;
6386 allocated_attrs
= ATTR_ALLOC_CHUNK
;
6387 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
6389 /* loop until we reach an abbrev number of 0 */
6390 while (abbrev_number
)
6392 cur_abbrev
= dwarf_alloc_abbrev (cu
);
6394 /* read in abbrev header */
6395 cur_abbrev
->number
= abbrev_number
;
6396 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6397 abbrev_ptr
+= bytes_read
;
6398 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
6401 if (cur_abbrev
->tag
== DW_TAG_namespace
)
6402 cu
->has_namespace_info
= 1;
6404 /* now read in declarations */
6405 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6406 abbrev_ptr
+= bytes_read
;
6407 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6408 abbrev_ptr
+= bytes_read
;
6411 if (cur_abbrev
->num_attrs
== allocated_attrs
)
6413 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
6415 = xrealloc (cur_attrs
, (allocated_attrs
6416 * sizeof (struct attr_abbrev
)));
6419 /* Record whether this compilation unit might have
6420 inter-compilation-unit references. If we don't know what form
6421 this attribute will have, then it might potentially be a
6422 DW_FORM_ref_addr, so we conservatively expect inter-CU
6425 if (abbrev_form
== DW_FORM_ref_addr
6426 || abbrev_form
== DW_FORM_indirect
)
6427 cu
->has_form_ref_addr
= 1;
6429 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
6430 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
6431 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6432 abbrev_ptr
+= bytes_read
;
6433 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6434 abbrev_ptr
+= bytes_read
;
6437 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
6438 (cur_abbrev
->num_attrs
6439 * sizeof (struct attr_abbrev
)));
6440 memcpy (cur_abbrev
->attrs
, cur_attrs
,
6441 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
6443 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
6444 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
6445 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
6447 /* Get next abbreviation.
6448 Under Irix6 the abbreviations for a compilation unit are not
6449 always properly terminated with an abbrev number of 0.
6450 Exit loop if we encounter an abbreviation which we have
6451 already read (which means we are about to read the abbreviations
6452 for the next compile unit) or if the end of the abbreviation
6453 table is reached. */
6454 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
6455 >= dwarf2_per_objfile
->abbrev
.size
)
6457 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6458 abbrev_ptr
+= bytes_read
;
6459 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
6466 /* Release the memory used by the abbrev table for a compilation unit. */
6469 dwarf2_free_abbrev_table (void *ptr_to_cu
)
6471 struct dwarf2_cu
*cu
= ptr_to_cu
;
6473 obstack_free (&cu
->abbrev_obstack
, NULL
);
6474 cu
->dwarf2_abbrevs
= NULL
;
6477 /* Lookup an abbrev_info structure in the abbrev hash table. */
6479 static struct abbrev_info
*
6480 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
6482 unsigned int hash_number
;
6483 struct abbrev_info
*abbrev
;
6485 hash_number
= number
% ABBREV_HASH_SIZE
;
6486 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
6490 if (abbrev
->number
== number
)
6493 abbrev
= abbrev
->next
;
6498 /* Returns nonzero if TAG represents a type that we might generate a partial
6502 is_type_tag_for_partial (int tag
)
6507 /* Some types that would be reasonable to generate partial symbols for,
6508 that we don't at present. */
6509 case DW_TAG_array_type
:
6510 case DW_TAG_file_type
:
6511 case DW_TAG_ptr_to_member_type
:
6512 case DW_TAG_set_type
:
6513 case DW_TAG_string_type
:
6514 case DW_TAG_subroutine_type
:
6516 case DW_TAG_base_type
:
6517 case DW_TAG_class_type
:
6518 case DW_TAG_interface_type
:
6519 case DW_TAG_enumeration_type
:
6520 case DW_TAG_structure_type
:
6521 case DW_TAG_subrange_type
:
6522 case DW_TAG_typedef
:
6523 case DW_TAG_union_type
:
6530 /* Load all DIEs that are interesting for partial symbols into memory. */
6532 static struct partial_die_info
*
6533 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
6534 int building_psymtab
, struct dwarf2_cu
*cu
)
6536 struct partial_die_info
*part_die
;
6537 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
6538 struct abbrev_info
*abbrev
;
6539 unsigned int bytes_read
;
6540 unsigned int load_all
= 0;
6542 int nesting_level
= 1;
6547 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
6551 = htab_create_alloc_ex (cu
->header
.length
/ 12,
6555 &cu
->comp_unit_obstack
,
6556 hashtab_obstack_allocate
,
6557 dummy_obstack_deallocate
);
6559 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
6560 sizeof (struct partial_die_info
));
6564 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
6566 /* A NULL abbrev means the end of a series of children. */
6569 if (--nesting_level
== 0)
6571 /* PART_DIE was probably the last thing allocated on the
6572 comp_unit_obstack, so we could call obstack_free
6573 here. We don't do that because the waste is small,
6574 and will be cleaned up when we're done with this
6575 compilation unit. This way, we're also more robust
6576 against other users of the comp_unit_obstack. */
6579 info_ptr
+= bytes_read
;
6580 last_die
= parent_die
;
6581 parent_die
= parent_die
->die_parent
;
6585 /* Check whether this DIE is interesting enough to save. Normally
6586 we would not be interested in members here, but there may be
6587 later variables referencing them via DW_AT_specification (for
6590 && !is_type_tag_for_partial (abbrev
->tag
)
6591 && abbrev
->tag
!= DW_TAG_enumerator
6592 && abbrev
->tag
!= DW_TAG_subprogram
6593 && abbrev
->tag
!= DW_TAG_lexical_block
6594 && abbrev
->tag
!= DW_TAG_variable
6595 && abbrev
->tag
!= DW_TAG_namespace
6596 && abbrev
->tag
!= DW_TAG_member
)
6598 /* Otherwise we skip to the next sibling, if any. */
6599 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
6603 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
6604 buffer
, info_ptr
, cu
);
6606 /* This two-pass algorithm for processing partial symbols has a
6607 high cost in cache pressure. Thus, handle some simple cases
6608 here which cover the majority of C partial symbols. DIEs
6609 which neither have specification tags in them, nor could have
6610 specification tags elsewhere pointing at them, can simply be
6611 processed and discarded.
6613 This segment is also optional; scan_partial_symbols and
6614 add_partial_symbol will handle these DIEs if we chain
6615 them in normally. When compilers which do not emit large
6616 quantities of duplicate debug information are more common,
6617 this code can probably be removed. */
6619 /* Any complete simple types at the top level (pretty much all
6620 of them, for a language without namespaces), can be processed
6622 if (parent_die
== NULL
6623 && part_die
->has_specification
== 0
6624 && part_die
->is_declaration
== 0
6625 && (part_die
->tag
== DW_TAG_typedef
6626 || part_die
->tag
== DW_TAG_base_type
6627 || part_die
->tag
== DW_TAG_subrange_type
))
6629 if (building_psymtab
&& part_die
->name
!= NULL
)
6630 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
6631 VAR_DOMAIN
, LOC_TYPEDEF
,
6632 &cu
->objfile
->static_psymbols
,
6633 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
6634 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
6638 /* If we're at the second level, and we're an enumerator, and
6639 our parent has no specification (meaning possibly lives in a
6640 namespace elsewhere), then we can add the partial symbol now
6641 instead of queueing it. */
6642 if (part_die
->tag
== DW_TAG_enumerator
6643 && parent_die
!= NULL
6644 && parent_die
->die_parent
== NULL
6645 && parent_die
->tag
== DW_TAG_enumeration_type
6646 && parent_die
->has_specification
== 0)
6648 if (part_die
->name
== NULL
)
6649 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
6650 else if (building_psymtab
)
6651 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
6652 VAR_DOMAIN
, LOC_CONST
,
6653 (cu
->language
== language_cplus
6654 || cu
->language
== language_java
)
6655 ? &cu
->objfile
->global_psymbols
6656 : &cu
->objfile
->static_psymbols
,
6657 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
6659 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
6663 /* We'll save this DIE so link it in. */
6664 part_die
->die_parent
= parent_die
;
6665 part_die
->die_sibling
= NULL
;
6666 part_die
->die_child
= NULL
;
6668 if (last_die
&& last_die
== parent_die
)
6669 last_die
->die_child
= part_die
;
6671 last_die
->die_sibling
= part_die
;
6673 last_die
= part_die
;
6675 if (first_die
== NULL
)
6676 first_die
= part_die
;
6678 /* Maybe add the DIE to the hash table. Not all DIEs that we
6679 find interesting need to be in the hash table, because we
6680 also have the parent/sibling/child chains; only those that we
6681 might refer to by offset later during partial symbol reading.
6683 For now this means things that might have be the target of a
6684 DW_AT_specification, DW_AT_abstract_origin, or
6685 DW_AT_extension. DW_AT_extension will refer only to
6686 namespaces; DW_AT_abstract_origin refers to functions (and
6687 many things under the function DIE, but we do not recurse
6688 into function DIEs during partial symbol reading) and
6689 possibly variables as well; DW_AT_specification refers to
6690 declarations. Declarations ought to have the DW_AT_declaration
6691 flag. It happens that GCC forgets to put it in sometimes, but
6692 only for functions, not for types.
6694 Adding more things than necessary to the hash table is harmless
6695 except for the performance cost. Adding too few will result in
6696 wasted time in find_partial_die, when we reread the compilation
6697 unit with load_all_dies set. */
6700 || abbrev
->tag
== DW_TAG_subprogram
6701 || abbrev
->tag
== DW_TAG_variable
6702 || abbrev
->tag
== DW_TAG_namespace
6703 || part_die
->is_declaration
)
6707 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
6708 part_die
->offset
, INSERT
);
6712 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
6713 sizeof (struct partial_die_info
));
6715 /* For some DIEs we want to follow their children (if any). For C
6716 we have no reason to follow the children of structures; for other
6717 languages we have to, both so that we can get at method physnames
6718 to infer fully qualified class names, and for DW_AT_specification.
6720 For Ada, we need to scan the children of subprograms and lexical
6721 blocks as well because Ada allows the definition of nested
6722 entities that could be interesting for the debugger, such as
6723 nested subprograms for instance. */
6724 if (last_die
->has_children
6726 || last_die
->tag
== DW_TAG_namespace
6727 || last_die
->tag
== DW_TAG_enumeration_type
6728 || (cu
->language
!= language_c
6729 && (last_die
->tag
== DW_TAG_class_type
6730 || last_die
->tag
== DW_TAG_interface_type
6731 || last_die
->tag
== DW_TAG_structure_type
6732 || last_die
->tag
== DW_TAG_union_type
))
6733 || (cu
->language
== language_ada
6734 && (last_die
->tag
== DW_TAG_subprogram
6735 || last_die
->tag
== DW_TAG_lexical_block
))))
6738 parent_die
= last_die
;
6742 /* Otherwise we skip to the next sibling, if any. */
6743 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
6745 /* Back to the top, do it again. */
6749 /* Read a minimal amount of information into the minimal die structure. */
6752 read_partial_die (struct partial_die_info
*part_die
,
6753 struct abbrev_info
*abbrev
,
6754 unsigned int abbrev_len
, bfd
*abfd
,
6755 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
6756 struct dwarf2_cu
*cu
)
6758 unsigned int bytes_read
, i
;
6759 struct attribute attr
;
6760 int has_low_pc_attr
= 0;
6761 int has_high_pc_attr
= 0;
6763 memset (part_die
, 0, sizeof (struct partial_die_info
));
6765 part_die
->offset
= info_ptr
- buffer
;
6767 info_ptr
+= abbrev_len
;
6772 part_die
->tag
= abbrev
->tag
;
6773 part_die
->has_children
= abbrev
->has_children
;
6775 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6777 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
6779 /* Store the data if it is of an attribute we want to keep in a
6780 partial symbol table. */
6784 switch (part_die
->tag
)
6786 case DW_TAG_compile_unit
:
6787 case DW_TAG_type_unit
:
6788 /* Compilation units have a DW_AT_name that is a filename, not
6789 a source language identifier. */
6790 case DW_TAG_enumeration_type
:
6791 case DW_TAG_enumerator
:
6792 /* These tags always have simple identifiers already; no need
6793 to canonicalize them. */
6794 part_die
->name
= DW_STRING (&attr
);
6798 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
6799 &cu
->objfile
->objfile_obstack
);
6803 case DW_AT_MIPS_linkage_name
:
6804 if (cu
->language
== language_ada
)
6805 part_die
->name
= DW_STRING (&attr
);
6808 has_low_pc_attr
= 1;
6809 part_die
->lowpc
= DW_ADDR (&attr
);
6812 has_high_pc_attr
= 1;
6813 part_die
->highpc
= DW_ADDR (&attr
);
6815 case DW_AT_location
:
6816 /* Support the .debug_loc offsets */
6817 if (attr_form_is_block (&attr
))
6819 part_die
->locdesc
= DW_BLOCK (&attr
);
6821 else if (attr_form_is_section_offset (&attr
))
6823 dwarf2_complex_location_expr_complaint ();
6827 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6828 "partial symbol information");
6831 case DW_AT_external
:
6832 part_die
->is_external
= DW_UNSND (&attr
);
6834 case DW_AT_declaration
:
6835 part_die
->is_declaration
= DW_UNSND (&attr
);
6838 part_die
->has_type
= 1;
6840 case DW_AT_abstract_origin
:
6841 case DW_AT_specification
:
6842 case DW_AT_extension
:
6843 part_die
->has_specification
= 1;
6844 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
6847 /* Ignore absolute siblings, they might point outside of
6848 the current compile unit. */
6849 if (attr
.form
== DW_FORM_ref_addr
)
6850 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
6852 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
6854 case DW_AT_byte_size
:
6855 part_die
->has_byte_size
= 1;
6857 case DW_AT_calling_convention
:
6858 /* DWARF doesn't provide a way to identify a program's source-level
6859 entry point. DW_AT_calling_convention attributes are only meant
6860 to describe functions' calling conventions.
6862 However, because it's a necessary piece of information in
6863 Fortran, and because DW_CC_program is the only piece of debugging
6864 information whose definition refers to a 'main program' at all,
6865 several compilers have begun marking Fortran main programs with
6866 DW_CC_program --- even when those functions use the standard
6867 calling conventions.
6869 So until DWARF specifies a way to provide this information and
6870 compilers pick up the new representation, we'll support this
6872 if (DW_UNSND (&attr
) == DW_CC_program
6873 && cu
->language
== language_fortran
)
6874 set_main_name (part_die
->name
);
6881 /* When using the GNU linker, .gnu.linkonce. sections are used to
6882 eliminate duplicate copies of functions and vtables and such.
6883 The linker will arbitrarily choose one and discard the others.
6884 The AT_*_pc values for such functions refer to local labels in
6885 these sections. If the section from that file was discarded, the
6886 labels are not in the output, so the relocs get a value of 0.
6887 If this is a discarded function, mark the pc bounds as invalid,
6888 so that GDB will ignore it. */
6889 if (has_low_pc_attr
&& has_high_pc_attr
6890 && part_die
->lowpc
< part_die
->highpc
6891 && (part_die
->lowpc
!= 0
6892 || dwarf2_per_objfile
->has_section_at_zero
))
6893 part_die
->has_pc_info
= 1;
6898 /* Find a cached partial DIE at OFFSET in CU. */
6900 static struct partial_die_info
*
6901 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
6903 struct partial_die_info
*lookup_die
= NULL
;
6904 struct partial_die_info part_die
;
6906 part_die
.offset
= offset
;
6907 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
6912 /* Find a partial DIE at OFFSET, which may or may not be in CU,
6913 except in the case of .debug_types DIEs which do not reference
6914 outside their CU (they do however referencing other types via
6917 static struct partial_die_info
*
6918 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
6920 struct dwarf2_per_cu_data
*per_cu
= NULL
;
6921 struct partial_die_info
*pd
= NULL
;
6923 if (cu
->per_cu
->from_debug_types
)
6925 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6931 if (offset_in_cu_p (&cu
->header
, offset
))
6933 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6938 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6940 if (per_cu
->cu
== NULL
)
6942 load_partial_comp_unit (per_cu
, cu
->objfile
);
6943 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6944 dwarf2_per_objfile
->read_in_chain
= per_cu
;
6947 per_cu
->cu
->last_used
= 0;
6948 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6950 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
6952 struct cleanup
*back_to
;
6953 struct partial_die_info comp_unit_die
;
6954 struct abbrev_info
*abbrev
;
6955 unsigned int bytes_read
;
6958 per_cu
->load_all_dies
= 1;
6960 /* Re-read the DIEs. */
6961 back_to
= make_cleanup (null_cleanup
, 0);
6962 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
6964 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
6965 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
6967 info_ptr
= (dwarf2_per_objfile
->info
.buffer
6968 + per_cu
->cu
->header
.offset
6969 + per_cu
->cu
->header
.first_die_offset
);
6970 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
6971 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
6972 per_cu
->cu
->objfile
->obfd
,
6973 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
6975 if (comp_unit_die
.has_children
)
6976 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
6977 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
6979 do_cleanups (back_to
);
6981 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6987 internal_error (__FILE__
, __LINE__
,
6988 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
6989 offset
, bfd_get_filename (cu
->objfile
->obfd
));
6993 /* Adjust PART_DIE before generating a symbol for it. This function
6994 may set the is_external flag or change the DIE's name. */
6997 fixup_partial_die (struct partial_die_info
*part_die
,
6998 struct dwarf2_cu
*cu
)
7000 /* If we found a reference attribute and the DIE has no name, try
7001 to find a name in the referred to DIE. */
7003 if (part_die
->name
== NULL
&& part_die
->has_specification
)
7005 struct partial_die_info
*spec_die
;
7007 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
7009 fixup_partial_die (spec_die
, cu
);
7013 part_die
->name
= spec_die
->name
;
7015 /* Copy DW_AT_external attribute if it is set. */
7016 if (spec_die
->is_external
)
7017 part_die
->is_external
= spec_die
->is_external
;
7021 /* Set default names for some unnamed DIEs. */
7022 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
7023 || part_die
->tag
== DW_TAG_class_type
))
7024 part_die
->name
= "(anonymous class)";
7026 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
7027 part_die
->name
= "(anonymous namespace)";
7029 if (part_die
->tag
== DW_TAG_structure_type
7030 || part_die
->tag
== DW_TAG_class_type
7031 || part_die
->tag
== DW_TAG_union_type
)
7032 guess_structure_name (part_die
, cu
);
7035 /* Read an attribute value described by an attribute form. */
7038 read_attribute_value (struct attribute
*attr
, unsigned form
,
7039 bfd
*abfd
, gdb_byte
*info_ptr
,
7040 struct dwarf2_cu
*cu
)
7042 struct comp_unit_head
*cu_header
= &cu
->header
;
7043 unsigned int bytes_read
;
7044 struct dwarf_block
*blk
;
7049 case DW_FORM_ref_addr
:
7050 if (cu
->header
.version
== 2)
7051 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
7053 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
7054 info_ptr
+= bytes_read
;
7057 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
7058 info_ptr
+= bytes_read
;
7060 case DW_FORM_block2
:
7061 blk
= dwarf_alloc_block (cu
);
7062 blk
->size
= read_2_bytes (abfd
, info_ptr
);
7064 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7065 info_ptr
+= blk
->size
;
7066 DW_BLOCK (attr
) = blk
;
7068 case DW_FORM_block4
:
7069 blk
= dwarf_alloc_block (cu
);
7070 blk
->size
= read_4_bytes (abfd
, info_ptr
);
7072 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7073 info_ptr
+= blk
->size
;
7074 DW_BLOCK (attr
) = blk
;
7077 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
7081 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
7085 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
7088 case DW_FORM_string
:
7089 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
7090 DW_STRING_IS_CANONICAL (attr
) = 0;
7091 info_ptr
+= bytes_read
;
7094 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
7096 DW_STRING_IS_CANONICAL (attr
) = 0;
7097 info_ptr
+= bytes_read
;
7100 blk
= dwarf_alloc_block (cu
);
7101 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7102 info_ptr
+= bytes_read
;
7103 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7104 info_ptr
+= blk
->size
;
7105 DW_BLOCK (attr
) = blk
;
7107 case DW_FORM_block1
:
7108 blk
= dwarf_alloc_block (cu
);
7109 blk
->size
= read_1_byte (abfd
, info_ptr
);
7111 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7112 info_ptr
+= blk
->size
;
7113 DW_BLOCK (attr
) = blk
;
7116 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
7120 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
7124 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
7125 info_ptr
+= bytes_read
;
7128 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7129 info_ptr
+= bytes_read
;
7132 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
7136 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
7140 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
7144 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
7148 /* Convert the signature to something we can record in DW_UNSND
7150 NOTE: This is NULL if the type wasn't found. */
7151 DW_SIGNATURED_TYPE (attr
) =
7152 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
7155 case DW_FORM_ref_udata
:
7156 DW_ADDR (attr
) = (cu
->header
.offset
7157 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
7158 info_ptr
+= bytes_read
;
7160 case DW_FORM_indirect
:
7161 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7162 info_ptr
+= bytes_read
;
7163 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
7166 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
7167 dwarf_form_name (form
),
7168 bfd_get_filename (abfd
));
7171 /* We have seen instances where the compiler tried to emit a byte
7172 size attribute of -1 which ended up being encoded as an unsigned
7173 0xffffffff. Although 0xffffffff is technically a valid size value,
7174 an object of this size seems pretty unlikely so we can relatively
7175 safely treat these cases as if the size attribute was invalid and
7176 treat them as zero by default. */
7177 if (attr
->name
== DW_AT_byte_size
7178 && form
== DW_FORM_data4
7179 && DW_UNSND (attr
) >= 0xffffffff)
7182 (&symfile_complaints
,
7183 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
7184 hex_string (DW_UNSND (attr
)));
7185 DW_UNSND (attr
) = 0;
7191 /* Read an attribute described by an abbreviated attribute. */
7194 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
7195 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
7197 attr
->name
= abbrev
->name
;
7198 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
7201 /* read dwarf information from a buffer */
7204 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
7206 return bfd_get_8 (abfd
, buf
);
7210 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
7212 return bfd_get_signed_8 (abfd
, buf
);
7216 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
7218 return bfd_get_16 (abfd
, buf
);
7222 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
7224 return bfd_get_signed_16 (abfd
, buf
);
7228 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
7230 return bfd_get_32 (abfd
, buf
);
7234 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
7236 return bfd_get_signed_32 (abfd
, buf
);
7240 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
7242 return bfd_get_64 (abfd
, buf
);
7246 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
7247 unsigned int *bytes_read
)
7249 struct comp_unit_head
*cu_header
= &cu
->header
;
7250 CORE_ADDR retval
= 0;
7252 if (cu_header
->signed_addr_p
)
7254 switch (cu_header
->addr_size
)
7257 retval
= bfd_get_signed_16 (abfd
, buf
);
7260 retval
= bfd_get_signed_32 (abfd
, buf
);
7263 retval
= bfd_get_signed_64 (abfd
, buf
);
7266 internal_error (__FILE__
, __LINE__
,
7267 _("read_address: bad switch, signed [in module %s]"),
7268 bfd_get_filename (abfd
));
7273 switch (cu_header
->addr_size
)
7276 retval
= bfd_get_16 (abfd
, buf
);
7279 retval
= bfd_get_32 (abfd
, buf
);
7282 retval
= bfd_get_64 (abfd
, buf
);
7285 internal_error (__FILE__
, __LINE__
,
7286 _("read_address: bad switch, unsigned [in module %s]"),
7287 bfd_get_filename (abfd
));
7291 *bytes_read
= cu_header
->addr_size
;
7295 /* Read the initial length from a section. The (draft) DWARF 3
7296 specification allows the initial length to take up either 4 bytes
7297 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
7298 bytes describe the length and all offsets will be 8 bytes in length
7301 An older, non-standard 64-bit format is also handled by this
7302 function. The older format in question stores the initial length
7303 as an 8-byte quantity without an escape value. Lengths greater
7304 than 2^32 aren't very common which means that the initial 4 bytes
7305 is almost always zero. Since a length value of zero doesn't make
7306 sense for the 32-bit format, this initial zero can be considered to
7307 be an escape value which indicates the presence of the older 64-bit
7308 format. As written, the code can't detect (old format) lengths
7309 greater than 4GB. If it becomes necessary to handle lengths
7310 somewhat larger than 4GB, we could allow other small values (such
7311 as the non-sensical values of 1, 2, and 3) to also be used as
7312 escape values indicating the presence of the old format.
7314 The value returned via bytes_read should be used to increment the
7315 relevant pointer after calling read_initial_length().
7317 [ Note: read_initial_length() and read_offset() are based on the
7318 document entitled "DWARF Debugging Information Format", revision
7319 3, draft 8, dated November 19, 2001. This document was obtained
7322 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
7324 This document is only a draft and is subject to change. (So beware.)
7326 Details regarding the older, non-standard 64-bit format were
7327 determined empirically by examining 64-bit ELF files produced by
7328 the SGI toolchain on an IRIX 6.5 machine.
7330 - Kevin, July 16, 2002
7334 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
7336 LONGEST length
= bfd_get_32 (abfd
, buf
);
7338 if (length
== 0xffffffff)
7340 length
= bfd_get_64 (abfd
, buf
+ 4);
7343 else if (length
== 0)
7345 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
7346 length
= bfd_get_64 (abfd
, buf
);
7357 /* Cover function for read_initial_length.
7358 Returns the length of the object at BUF, and stores the size of the
7359 initial length in *BYTES_READ and stores the size that offsets will be in
7361 If the initial length size is not equivalent to that specified in
7362 CU_HEADER then issue a complaint.
7363 This is useful when reading non-comp-unit headers. */
7366 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
7367 const struct comp_unit_head
*cu_header
,
7368 unsigned int *bytes_read
,
7369 unsigned int *offset_size
)
7371 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
7373 gdb_assert (cu_header
->initial_length_size
== 4
7374 || cu_header
->initial_length_size
== 8
7375 || cu_header
->initial_length_size
== 12);
7377 if (cu_header
->initial_length_size
!= *bytes_read
)
7378 complaint (&symfile_complaints
,
7379 _("intermixed 32-bit and 64-bit DWARF sections"));
7381 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
7385 /* Read an offset from the data stream. The size of the offset is
7386 given by cu_header->offset_size. */
7389 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
7390 unsigned int *bytes_read
)
7392 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
7393 *bytes_read
= cu_header
->offset_size
;
7397 /* Read an offset from the data stream. */
7400 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
7404 switch (offset_size
)
7407 retval
= bfd_get_32 (abfd
, buf
);
7410 retval
= bfd_get_64 (abfd
, buf
);
7413 internal_error (__FILE__
, __LINE__
,
7414 _("read_offset_1: bad switch [in module %s]"),
7415 bfd_get_filename (abfd
));
7422 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
7424 /* If the size of a host char is 8 bits, we can return a pointer
7425 to the buffer, otherwise we have to copy the data to a buffer
7426 allocated on the temporary obstack. */
7427 gdb_assert (HOST_CHAR_BIT
== 8);
7432 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7434 /* If the size of a host char is 8 bits, we can return a pointer
7435 to the string, otherwise we have to copy the string to a buffer
7436 allocated on the temporary obstack. */
7437 gdb_assert (HOST_CHAR_BIT
== 8);
7440 *bytes_read_ptr
= 1;
7443 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
7444 return (char *) buf
;
7448 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
7449 const struct comp_unit_head
*cu_header
,
7450 unsigned int *bytes_read_ptr
)
7452 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
7454 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
7456 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
7457 bfd_get_filename (abfd
));
7460 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
7462 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
7463 bfd_get_filename (abfd
));
7466 gdb_assert (HOST_CHAR_BIT
== 8);
7467 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
7469 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
7472 static unsigned long
7473 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7475 unsigned long result
;
7476 unsigned int num_read
;
7486 byte
= bfd_get_8 (abfd
, buf
);
7489 result
|= ((unsigned long)(byte
& 127) << shift
);
7490 if ((byte
& 128) == 0)
7496 *bytes_read_ptr
= num_read
;
7501 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7504 int i
, shift
, num_read
;
7513 byte
= bfd_get_8 (abfd
, buf
);
7516 result
|= ((long)(byte
& 127) << shift
);
7518 if ((byte
& 128) == 0)
7523 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
7524 result
|= -(((long)1) << shift
);
7525 *bytes_read_ptr
= num_read
;
7529 /* Return a pointer to just past the end of an LEB128 number in BUF. */
7532 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
7538 byte
= bfd_get_8 (abfd
, buf
);
7540 if ((byte
& 128) == 0)
7546 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
7553 cu
->language
= language_c
;
7555 case DW_LANG_C_plus_plus
:
7556 cu
->language
= language_cplus
;
7558 case DW_LANG_Fortran77
:
7559 case DW_LANG_Fortran90
:
7560 case DW_LANG_Fortran95
:
7561 cu
->language
= language_fortran
;
7563 case DW_LANG_Mips_Assembler
:
7564 cu
->language
= language_asm
;
7567 cu
->language
= language_java
;
7571 cu
->language
= language_ada
;
7573 case DW_LANG_Modula2
:
7574 cu
->language
= language_m2
;
7576 case DW_LANG_Pascal83
:
7577 cu
->language
= language_pascal
;
7580 cu
->language
= language_objc
;
7582 case DW_LANG_Cobol74
:
7583 case DW_LANG_Cobol85
:
7585 cu
->language
= language_minimal
;
7588 cu
->language_defn
= language_def (cu
->language
);
7591 /* Return the named attribute or NULL if not there. */
7593 static struct attribute
*
7594 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
7597 struct attribute
*spec
= NULL
;
7599 for (i
= 0; i
< die
->num_attrs
; ++i
)
7601 if (die
->attrs
[i
].name
== name
)
7602 return &die
->attrs
[i
];
7603 if (die
->attrs
[i
].name
== DW_AT_specification
7604 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
7605 spec
= &die
->attrs
[i
];
7610 die
= follow_die_ref (die
, spec
, &cu
);
7611 return dwarf2_attr (die
, name
, cu
);
7617 /* Return the named attribute or NULL if not there,
7618 but do not follow DW_AT_specification, etc.
7619 This is for use in contexts where we're reading .debug_types dies.
7620 Following DW_AT_specification, DW_AT_abstract_origin will take us
7621 back up the chain, and we want to go down. */
7623 static struct attribute
*
7624 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
7625 struct dwarf2_cu
*cu
)
7629 for (i
= 0; i
< die
->num_attrs
; ++i
)
7630 if (die
->attrs
[i
].name
== name
)
7631 return &die
->attrs
[i
];
7636 /* Return non-zero iff the attribute NAME is defined for the given DIE,
7637 and holds a non-zero value. This function should only be used for
7638 DW_FORM_flag attributes. */
7641 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
7643 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
7645 return (attr
&& DW_UNSND (attr
));
7649 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
7651 /* A DIE is a declaration if it has a DW_AT_declaration attribute
7652 which value is non-zero. However, we have to be careful with
7653 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
7654 (via dwarf2_flag_true_p) follows this attribute. So we may
7655 end up accidently finding a declaration attribute that belongs
7656 to a different DIE referenced by the specification attribute,
7657 even though the given DIE does not have a declaration attribute. */
7658 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
7659 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
7662 /* Return the die giving the specification for DIE, if there is
7663 one. *SPEC_CU is the CU containing DIE on input, and the CU
7664 containing the return value on output. If there is no
7665 specification, but there is an abstract origin, that is
7668 static struct die_info
*
7669 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
7671 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
7674 if (spec_attr
== NULL
)
7675 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
7677 if (spec_attr
== NULL
)
7680 return follow_die_ref (die
, spec_attr
, spec_cu
);
7683 /* Free the line_header structure *LH, and any arrays and strings it
7686 free_line_header (struct line_header
*lh
)
7688 if (lh
->standard_opcode_lengths
)
7689 xfree (lh
->standard_opcode_lengths
);
7691 /* Remember that all the lh->file_names[i].name pointers are
7692 pointers into debug_line_buffer, and don't need to be freed. */
7694 xfree (lh
->file_names
);
7696 /* Similarly for the include directory names. */
7697 if (lh
->include_dirs
)
7698 xfree (lh
->include_dirs
);
7704 /* Add an entry to LH's include directory table. */
7706 add_include_dir (struct line_header
*lh
, char *include_dir
)
7708 /* Grow the array if necessary. */
7709 if (lh
->include_dirs_size
== 0)
7711 lh
->include_dirs_size
= 1; /* for testing */
7712 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
7713 * sizeof (*lh
->include_dirs
));
7715 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
7717 lh
->include_dirs_size
*= 2;
7718 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
7719 (lh
->include_dirs_size
7720 * sizeof (*lh
->include_dirs
)));
7723 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
7727 /* Add an entry to LH's file name table. */
7729 add_file_name (struct line_header
*lh
,
7731 unsigned int dir_index
,
7732 unsigned int mod_time
,
7733 unsigned int length
)
7735 struct file_entry
*fe
;
7737 /* Grow the array if necessary. */
7738 if (lh
->file_names_size
== 0)
7740 lh
->file_names_size
= 1; /* for testing */
7741 lh
->file_names
= xmalloc (lh
->file_names_size
7742 * sizeof (*lh
->file_names
));
7744 else if (lh
->num_file_names
>= lh
->file_names_size
)
7746 lh
->file_names_size
*= 2;
7747 lh
->file_names
= xrealloc (lh
->file_names
,
7748 (lh
->file_names_size
7749 * sizeof (*lh
->file_names
)));
7752 fe
= &lh
->file_names
[lh
->num_file_names
++];
7754 fe
->dir_index
= dir_index
;
7755 fe
->mod_time
= mod_time
;
7756 fe
->length
= length
;
7762 /* Read the statement program header starting at OFFSET in
7763 .debug_line, according to the endianness of ABFD. Return a pointer
7764 to a struct line_header, allocated using xmalloc.
7766 NOTE: the strings in the include directory and file name tables of
7767 the returned object point into debug_line_buffer, and must not be
7769 static struct line_header
*
7770 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
7771 struct dwarf2_cu
*cu
)
7773 struct cleanup
*back_to
;
7774 struct line_header
*lh
;
7776 unsigned int bytes_read
, offset_size
;
7778 char *cur_dir
, *cur_file
;
7780 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
7782 complaint (&symfile_complaints
, _("missing .debug_line section"));
7786 /* Make sure that at least there's room for the total_length field.
7787 That could be 12 bytes long, but we're just going to fudge that. */
7788 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
7790 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7794 lh
= xmalloc (sizeof (*lh
));
7795 memset (lh
, 0, sizeof (*lh
));
7796 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
7799 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
7801 /* Read in the header. */
7803 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
7804 &bytes_read
, &offset_size
);
7805 line_ptr
+= bytes_read
;
7806 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
7807 + dwarf2_per_objfile
->line
.size
))
7809 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7812 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
7813 lh
->version
= read_2_bytes (abfd
, line_ptr
);
7815 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
7816 line_ptr
+= offset_size
;
7817 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
7819 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
7821 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
7823 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
7825 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
7827 lh
->standard_opcode_lengths
7828 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
7830 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
7831 for (i
= 1; i
< lh
->opcode_base
; ++i
)
7833 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
7837 /* Read directory table. */
7838 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7840 line_ptr
+= bytes_read
;
7841 add_include_dir (lh
, cur_dir
);
7843 line_ptr
+= bytes_read
;
7845 /* Read file name table. */
7846 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7848 unsigned int dir_index
, mod_time
, length
;
7850 line_ptr
+= bytes_read
;
7851 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7852 line_ptr
+= bytes_read
;
7853 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7854 line_ptr
+= bytes_read
;
7855 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7856 line_ptr
+= bytes_read
;
7858 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7860 line_ptr
+= bytes_read
;
7861 lh
->statement_program_start
= line_ptr
;
7863 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
7864 + dwarf2_per_objfile
->line
.size
))
7865 complaint (&symfile_complaints
,
7866 _("line number info header doesn't fit in `.debug_line' section"));
7868 discard_cleanups (back_to
);
7872 /* This function exists to work around a bug in certain compilers
7873 (particularly GCC 2.95), in which the first line number marker of a
7874 function does not show up until after the prologue, right before
7875 the second line number marker. This function shifts ADDRESS down
7876 to the beginning of the function if necessary, and is called on
7877 addresses passed to record_line. */
7880 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
7882 struct function_range
*fn
;
7884 /* Find the function_range containing address. */
7889 cu
->cached_fn
= cu
->first_fn
;
7893 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7899 while (fn
&& fn
!= cu
->cached_fn
)
7900 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7910 if (address
!= fn
->lowpc
)
7911 complaint (&symfile_complaints
,
7912 _("misplaced first line number at 0x%lx for '%s'"),
7913 (unsigned long) address
, fn
->name
);
7918 /* Decode the Line Number Program (LNP) for the given line_header
7919 structure and CU. The actual information extracted and the type
7920 of structures created from the LNP depends on the value of PST.
7922 1. If PST is NULL, then this procedure uses the data from the program
7923 to create all necessary symbol tables, and their linetables.
7924 The compilation directory of the file is passed in COMP_DIR,
7925 and must not be NULL.
7927 2. If PST is not NULL, this procedure reads the program to determine
7928 the list of files included by the unit represented by PST, and
7929 builds all the associated partial symbol tables. In this case,
7930 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7931 is not used to compute the full name of the symtab, and therefore
7932 omitting it when building the partial symtab does not introduce
7933 the potential for inconsistency - a partial symtab and its associated
7934 symbtab having a different fullname -). */
7937 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
7938 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
7940 gdb_byte
*line_ptr
, *extended_end
;
7942 unsigned int bytes_read
, extended_len
;
7943 unsigned char op_code
, extended_op
, adj_opcode
;
7945 struct objfile
*objfile
= cu
->objfile
;
7946 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7947 const int decode_for_pst_p
= (pst
!= NULL
);
7948 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
7950 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7952 line_ptr
= lh
->statement_program_start
;
7953 line_end
= lh
->statement_program_end
;
7955 /* Read the statement sequences until there's nothing left. */
7956 while (line_ptr
< line_end
)
7958 /* state machine registers */
7959 CORE_ADDR address
= 0;
7960 unsigned int file
= 1;
7961 unsigned int line
= 1;
7962 unsigned int column
= 0;
7963 int is_stmt
= lh
->default_is_stmt
;
7964 int basic_block
= 0;
7965 int end_sequence
= 0;
7968 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
7970 /* Start a subfile for the current file of the state machine. */
7971 /* lh->include_dirs and lh->file_names are 0-based, but the
7972 directory and file name numbers in the statement program
7974 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7978 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7980 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7983 /* Decode the table. */
7984 while (!end_sequence
)
7986 op_code
= read_1_byte (abfd
, line_ptr
);
7988 if (line_ptr
> line_end
)
7990 dwarf2_debug_line_missing_end_sequence_complaint ();
7994 if (op_code
>= lh
->opcode_base
)
7996 /* Special operand. */
7997 adj_opcode
= op_code
- lh
->opcode_base
;
7998 address
+= (adj_opcode
/ lh
->line_range
)
7999 * lh
->minimum_instruction_length
;
8000 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
8001 if (lh
->num_file_names
< file
|| file
== 0)
8002 dwarf2_debug_line_missing_file_complaint ();
8005 lh
->file_names
[file
- 1].included_p
= 1;
8006 if (!decode_for_pst_p
&& is_stmt
)
8008 if (last_subfile
!= current_subfile
)
8010 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8012 record_line (last_subfile
, 0, addr
);
8013 last_subfile
= current_subfile
;
8015 /* Append row to matrix using current values. */
8016 addr
= check_cu_functions (address
, cu
);
8017 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
8018 record_line (current_subfile
, line
, addr
);
8023 else switch (op_code
)
8025 case DW_LNS_extended_op
:
8026 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8027 line_ptr
+= bytes_read
;
8028 extended_end
= line_ptr
+ extended_len
;
8029 extended_op
= read_1_byte (abfd
, line_ptr
);
8031 switch (extended_op
)
8033 case DW_LNE_end_sequence
:
8036 case DW_LNE_set_address
:
8037 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
8038 line_ptr
+= bytes_read
;
8039 address
+= baseaddr
;
8041 case DW_LNE_define_file
:
8044 unsigned int dir_index
, mod_time
, length
;
8046 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
8047 line_ptr
+= bytes_read
;
8049 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8050 line_ptr
+= bytes_read
;
8052 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8053 line_ptr
+= bytes_read
;
8055 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8056 line_ptr
+= bytes_read
;
8057 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
8060 case DW_LNE_set_discriminator
:
8061 /* The discriminator is not interesting to the debugger;
8063 line_ptr
= extended_end
;
8066 complaint (&symfile_complaints
,
8067 _("mangled .debug_line section"));
8070 /* Make sure that we parsed the extended op correctly. If e.g.
8071 we expected a different address size than the producer used,
8072 we may have read the wrong number of bytes. */
8073 if (line_ptr
!= extended_end
)
8075 complaint (&symfile_complaints
,
8076 _("mangled .debug_line section"));
8081 if (lh
->num_file_names
< file
|| file
== 0)
8082 dwarf2_debug_line_missing_file_complaint ();
8085 lh
->file_names
[file
- 1].included_p
= 1;
8086 if (!decode_for_pst_p
&& is_stmt
)
8088 if (last_subfile
!= current_subfile
)
8090 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8092 record_line (last_subfile
, 0, addr
);
8093 last_subfile
= current_subfile
;
8095 addr
= check_cu_functions (address
, cu
);
8096 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
8097 record_line (current_subfile
, line
, addr
);
8102 case DW_LNS_advance_pc
:
8103 address
+= lh
->minimum_instruction_length
8104 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8105 line_ptr
+= bytes_read
;
8107 case DW_LNS_advance_line
:
8108 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
8109 line_ptr
+= bytes_read
;
8111 case DW_LNS_set_file
:
8113 /* The arrays lh->include_dirs and lh->file_names are
8114 0-based, but the directory and file name numbers in
8115 the statement program are 1-based. */
8116 struct file_entry
*fe
;
8119 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8120 line_ptr
+= bytes_read
;
8121 if (lh
->num_file_names
< file
|| file
== 0)
8122 dwarf2_debug_line_missing_file_complaint ();
8125 fe
= &lh
->file_names
[file
- 1];
8127 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8128 if (!decode_for_pst_p
)
8130 last_subfile
= current_subfile
;
8131 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
8136 case DW_LNS_set_column
:
8137 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8138 line_ptr
+= bytes_read
;
8140 case DW_LNS_negate_stmt
:
8141 is_stmt
= (!is_stmt
);
8143 case DW_LNS_set_basic_block
:
8146 /* Add to the address register of the state machine the
8147 address increment value corresponding to special opcode
8148 255. I.e., this value is scaled by the minimum
8149 instruction length since special opcode 255 would have
8150 scaled the the increment. */
8151 case DW_LNS_const_add_pc
:
8152 address
+= (lh
->minimum_instruction_length
8153 * ((255 - lh
->opcode_base
) / lh
->line_range
));
8155 case DW_LNS_fixed_advance_pc
:
8156 address
+= read_2_bytes (abfd
, line_ptr
);
8161 /* Unknown standard opcode, ignore it. */
8164 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
8166 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8167 line_ptr
+= bytes_read
;
8172 if (lh
->num_file_names
< file
|| file
== 0)
8173 dwarf2_debug_line_missing_file_complaint ();
8176 lh
->file_names
[file
- 1].included_p
= 1;
8177 if (!decode_for_pst_p
)
8179 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8180 record_line (current_subfile
, 0, addr
);
8185 if (decode_for_pst_p
)
8189 /* Now that we're done scanning the Line Header Program, we can
8190 create the psymtab of each included file. */
8191 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
8192 if (lh
->file_names
[file_index
].included_p
== 1)
8194 const struct file_entry fe
= lh
->file_names
[file_index
];
8195 char *include_name
= fe
.name
;
8196 char *dir_name
= NULL
;
8197 char *pst_filename
= pst
->filename
;
8200 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
8202 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
8204 include_name
= concat (dir_name
, SLASH_STRING
,
8205 include_name
, (char *)NULL
);
8206 make_cleanup (xfree
, include_name
);
8209 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
8211 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
8212 pst_filename
, (char *)NULL
);
8213 make_cleanup (xfree
, pst_filename
);
8216 if (strcmp (include_name
, pst_filename
) != 0)
8217 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
8222 /* Make sure a symtab is created for every file, even files
8223 which contain only variables (i.e. no code with associated
8227 struct file_entry
*fe
;
8229 for (i
= 0; i
< lh
->num_file_names
; i
++)
8232 fe
= &lh
->file_names
[i
];
8234 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8235 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
8237 /* Skip the main file; we don't need it, and it must be
8238 allocated last, so that it will show up before the
8239 non-primary symtabs in the objfile's symtab list. */
8240 if (current_subfile
== first_subfile
)
8243 if (current_subfile
->symtab
== NULL
)
8244 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
8246 fe
->symtab
= current_subfile
->symtab
;
8251 /* Start a subfile for DWARF. FILENAME is the name of the file and
8252 DIRNAME the name of the source directory which contains FILENAME
8253 or NULL if not known. COMP_DIR is the compilation directory for the
8254 linetable's compilation unit or NULL if not known.
8255 This routine tries to keep line numbers from identical absolute and
8256 relative file names in a common subfile.
8258 Using the `list' example from the GDB testsuite, which resides in
8259 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
8260 of /srcdir/list0.c yields the following debugging information for list0.c:
8262 DW_AT_name: /srcdir/list0.c
8263 DW_AT_comp_dir: /compdir
8264 files.files[0].name: list0.h
8265 files.files[0].dir: /srcdir
8266 files.files[1].name: list0.c
8267 files.files[1].dir: /srcdir
8269 The line number information for list0.c has to end up in a single
8270 subfile, so that `break /srcdir/list0.c:1' works as expected.
8271 start_subfile will ensure that this happens provided that we pass the
8272 concatenation of files.files[1].dir and files.files[1].name as the
8276 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
8280 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
8281 `start_symtab' will always pass the contents of DW_AT_comp_dir as
8282 second argument to start_subfile. To be consistent, we do the
8283 same here. In order not to lose the line information directory,
8284 we concatenate it to the filename when it makes sense.
8285 Note that the Dwarf3 standard says (speaking of filenames in line
8286 information): ``The directory index is ignored for file names
8287 that represent full path names''. Thus ignoring dirname in the
8288 `else' branch below isn't an issue. */
8290 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
8291 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
8293 fullname
= filename
;
8295 start_subfile (fullname
, comp_dir
);
8297 if (fullname
!= filename
)
8302 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
8303 struct dwarf2_cu
*cu
)
8305 struct objfile
*objfile
= cu
->objfile
;
8306 struct comp_unit_head
*cu_header
= &cu
->header
;
8308 /* NOTE drow/2003-01-30: There used to be a comment and some special
8309 code here to turn a symbol with DW_AT_external and a
8310 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
8311 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
8312 with some versions of binutils) where shared libraries could have
8313 relocations against symbols in their debug information - the
8314 minimal symbol would have the right address, but the debug info
8315 would not. It's no longer necessary, because we will explicitly
8316 apply relocations when we read in the debug information now. */
8318 /* A DW_AT_location attribute with no contents indicates that a
8319 variable has been optimized away. */
8320 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
8322 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
8326 /* Handle one degenerate form of location expression specially, to
8327 preserve GDB's previous behavior when section offsets are
8328 specified. If this is just a DW_OP_addr then mark this symbol
8331 if (attr_form_is_block (attr
)
8332 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
8333 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
8337 SYMBOL_VALUE_ADDRESS (sym
) =
8338 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
8339 SYMBOL_CLASS (sym
) = LOC_STATIC
;
8340 fixup_symbol_section (sym
, objfile
);
8341 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
8342 SYMBOL_SECTION (sym
));
8346 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
8347 expression evaluator, and use LOC_COMPUTED only when necessary
8348 (i.e. when the value of a register or memory location is
8349 referenced, or a thread-local block, etc.). Then again, it might
8350 not be worthwhile. I'm assuming that it isn't unless performance
8351 or memory numbers show me otherwise. */
8353 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
8354 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
8357 /* Given a pointer to a DWARF information entry, figure out if we need
8358 to make a symbol table entry for it, and if so, create a new entry
8359 and return a pointer to it.
8360 If TYPE is NULL, determine symbol type from the die, otherwise
8361 used the passed type. */
8363 static struct symbol
*
8364 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
8366 struct objfile
*objfile
= cu
->objfile
;
8367 struct symbol
*sym
= NULL
;
8369 struct attribute
*attr
= NULL
;
8370 struct attribute
*attr2
= NULL
;
8372 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
8374 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8376 name
= dwarf2_name (die
, cu
);
8379 const char *linkagename
;
8381 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
8382 sizeof (struct symbol
));
8383 OBJSTAT (objfile
, n_syms
++);
8384 memset (sym
, 0, sizeof (struct symbol
));
8386 /* Cache this symbol's name and the name's demangled form (if any). */
8387 SYMBOL_LANGUAGE (sym
) = cu
->language
;
8388 linkagename
= dwarf2_physname (name
, die
, cu
);
8389 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
8391 /* Default assumptions.
8392 Use the passed type or decode it from the die. */
8393 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8394 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
8396 SYMBOL_TYPE (sym
) = type
;
8398 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
8399 attr
= dwarf2_attr (die
,
8400 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
8404 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
8407 attr
= dwarf2_attr (die
,
8408 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
8412 int file_index
= DW_UNSND (attr
);
8413 if (cu
->line_header
== NULL
8414 || file_index
> cu
->line_header
->num_file_names
)
8415 complaint (&symfile_complaints
,
8416 _("file index out of range"));
8417 else if (file_index
> 0)
8419 struct file_entry
*fe
;
8420 fe
= &cu
->line_header
->file_names
[file_index
- 1];
8421 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
8428 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8431 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
8433 SYMBOL_CLASS (sym
) = LOC_LABEL
;
8435 case DW_TAG_subprogram
:
8436 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8438 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
8439 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8440 if ((attr2
&& (DW_UNSND (attr2
) != 0))
8441 || cu
->language
== language_ada
)
8443 /* Subprograms marked external are stored as a global symbol.
8444 Ada subprograms, whether marked external or not, are always
8445 stored as a global symbol, because we want to be able to
8446 access them globally. For instance, we want to be able
8447 to break on a nested subprogram without having to
8448 specify the context. */
8449 add_symbol_to_list (sym
, &global_symbols
);
8453 add_symbol_to_list (sym
, cu
->list_in_scope
);
8456 case DW_TAG_inlined_subroutine
:
8457 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8459 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
8460 SYMBOL_INLINED (sym
) = 1;
8461 /* Do not add the symbol to any lists. It will be found via
8462 BLOCK_FUNCTION from the blockvector. */
8464 case DW_TAG_variable
:
8465 /* Compilation with minimal debug info may result in variables
8466 with missing type entries. Change the misleading `void' type
8467 to something sensible. */
8468 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
8470 = objfile_type (objfile
)->nodebug_data_symbol
;
8472 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8475 dwarf2_const_value (attr
, sym
, cu
);
8476 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8477 if (attr2
&& (DW_UNSND (attr2
) != 0))
8478 add_symbol_to_list (sym
, &global_symbols
);
8480 add_symbol_to_list (sym
, cu
->list_in_scope
);
8483 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8486 var_decode_location (attr
, sym
, cu
);
8487 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8488 if (attr2
&& (DW_UNSND (attr2
) != 0))
8489 add_symbol_to_list (sym
, &global_symbols
);
8491 add_symbol_to_list (sym
, cu
->list_in_scope
);
8495 /* We do not know the address of this symbol.
8496 If it is an external symbol and we have type information
8497 for it, enter the symbol as a LOC_UNRESOLVED symbol.
8498 The address of the variable will then be determined from
8499 the minimal symbol table whenever the variable is
8501 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8502 if (attr2
&& (DW_UNSND (attr2
) != 0)
8503 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
8505 struct pending
**list_to_add
;
8507 /* A variable with DW_AT_external is never static, but it
8508 may be block-scoped. */
8509 list_to_add
= (cu
->list_in_scope
== &file_symbols
8510 ? &global_symbols
: cu
->list_in_scope
);
8512 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
8513 add_symbol_to_list (sym
, list_to_add
);
8515 else if (!die_is_declaration (die
, cu
))
8517 /* Use the default LOC_OPTIMIZED_OUT class. */
8518 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
8519 add_symbol_to_list (sym
, cu
->list_in_scope
);
8523 case DW_TAG_formal_parameter
:
8524 /* If we are inside a function, mark this as an argument. If
8525 not, we might be looking at an argument to an inlined function
8526 when we do not have enough information to show inlined frames;
8527 pretend it's a local variable in that case so that the user can
8529 if (context_stack_depth
> 0
8530 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
8531 SYMBOL_IS_ARGUMENT (sym
) = 1;
8532 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8535 var_decode_location (attr
, sym
, cu
);
8537 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8540 dwarf2_const_value (attr
, sym
, cu
);
8542 add_symbol_to_list (sym
, cu
->list_in_scope
);
8544 case DW_TAG_unspecified_parameters
:
8545 /* From varargs functions; gdb doesn't seem to have any
8546 interest in this information, so just ignore it for now.
8549 case DW_TAG_class_type
:
8550 case DW_TAG_interface_type
:
8551 case DW_TAG_structure_type
:
8552 case DW_TAG_union_type
:
8553 case DW_TAG_set_type
:
8554 case DW_TAG_enumeration_type
:
8555 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8556 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8558 /* Make sure that the symbol includes appropriate enclosing
8559 classes/namespaces in its name. These are calculated in
8560 read_structure_type, and the correct name is saved in
8563 if (cu
->language
== language_cplus
8564 || cu
->language
== language_java
)
8566 struct type
*type
= SYMBOL_TYPE (sym
);
8568 if (TYPE_TAG_NAME (type
) != NULL
)
8570 /* FIXME: carlton/2003-11-10: Should this use
8571 SYMBOL_SET_NAMES instead? (The same problem also
8572 arises further down in this function.) */
8573 /* The type's name is already allocated along with
8574 this objfile, so we don't need to duplicate it
8576 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
8581 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
8582 really ever be static objects: otherwise, if you try
8583 to, say, break of a class's method and you're in a file
8584 which doesn't mention that class, it won't work unless
8585 the check for all static symbols in lookup_symbol_aux
8586 saves you. See the OtherFileClass tests in
8587 gdb.c++/namespace.exp. */
8589 struct pending
**list_to_add
;
8591 list_to_add
= (cu
->list_in_scope
== &file_symbols
8592 && (cu
->language
== language_cplus
8593 || cu
->language
== language_java
)
8594 ? &global_symbols
: cu
->list_in_scope
);
8596 add_symbol_to_list (sym
, list_to_add
);
8598 /* The semantics of C++ state that "struct foo { ... }" also
8599 defines a typedef for "foo". A Java class declaration also
8600 defines a typedef for the class. */
8601 if (cu
->language
== language_cplus
8602 || cu
->language
== language_java
8603 || cu
->language
== language_ada
)
8605 /* The symbol's name is already allocated along with
8606 this objfile, so we don't need to duplicate it for
8608 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
8609 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
8613 case DW_TAG_typedef
:
8614 SYMBOL_LINKAGE_NAME (sym
)
8615 = (char *) dwarf2_full_name (name
, die
, cu
);
8616 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8617 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8618 add_symbol_to_list (sym
, cu
->list_in_scope
);
8620 case DW_TAG_base_type
:
8621 case DW_TAG_subrange_type
:
8622 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8623 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8624 add_symbol_to_list (sym
, cu
->list_in_scope
);
8626 case DW_TAG_enumerator
:
8627 SYMBOL_LINKAGE_NAME (sym
)
8628 = (char *) dwarf2_full_name (name
, die
, cu
);
8629 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8632 dwarf2_const_value (attr
, sym
, cu
);
8635 /* NOTE: carlton/2003-11-10: See comment above in the
8636 DW_TAG_class_type, etc. block. */
8638 struct pending
**list_to_add
;
8640 list_to_add
= (cu
->list_in_scope
== &file_symbols
8641 && (cu
->language
== language_cplus
8642 || cu
->language
== language_java
)
8643 ? &global_symbols
: cu
->list_in_scope
);
8645 add_symbol_to_list (sym
, list_to_add
);
8648 case DW_TAG_namespace
:
8649 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8650 add_symbol_to_list (sym
, &global_symbols
);
8653 /* Not a tag we recognize. Hopefully we aren't processing
8654 trash data, but since we must specifically ignore things
8655 we don't recognize, there is nothing else we should do at
8657 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
8658 dwarf_tag_name (die
->tag
));
8662 /* For the benefit of old versions of GCC, check for anonymous
8663 namespaces based on the demangled name. */
8664 if (!processing_has_namespace_info
8665 && cu
->language
== language_cplus
)
8666 cp_scan_for_anonymous_namespaces (sym
);
8671 /* Copy constant value from an attribute to a symbol. */
8674 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
8675 struct dwarf2_cu
*cu
)
8677 struct objfile
*objfile
= cu
->objfile
;
8678 struct comp_unit_head
*cu_header
= &cu
->header
;
8679 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
8680 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
8681 struct dwarf_block
*blk
;
8686 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
8687 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
8688 cu_header
->addr_size
,
8689 TYPE_LENGTH (SYMBOL_TYPE
8691 SYMBOL_VALUE_BYTES (sym
) =
8692 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
8693 /* NOTE: cagney/2003-05-09: In-lined store_address call with
8694 it's body - store_unsigned_integer. */
8695 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
8696 byte_order
, DW_ADDR (attr
));
8697 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8699 case DW_FORM_string
:
8701 /* DW_STRING is already allocated on the obstack, point directly
8703 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
8704 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8706 case DW_FORM_block1
:
8707 case DW_FORM_block2
:
8708 case DW_FORM_block4
:
8710 blk
= DW_BLOCK (attr
);
8711 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
8712 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
8714 TYPE_LENGTH (SYMBOL_TYPE
8716 SYMBOL_VALUE_BYTES (sym
) =
8717 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
8718 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
8719 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8722 /* The DW_AT_const_value attributes are supposed to carry the
8723 symbol's value "represented as it would be on the target
8724 architecture." By the time we get here, it's already been
8725 converted to host endianness, so we just need to sign- or
8726 zero-extend it as appropriate. */
8728 dwarf2_const_value_data (attr
, sym
, 8);
8731 dwarf2_const_value_data (attr
, sym
, 16);
8734 dwarf2_const_value_data (attr
, sym
, 32);
8737 dwarf2_const_value_data (attr
, sym
, 64);
8741 SYMBOL_VALUE (sym
) = DW_SND (attr
);
8742 SYMBOL_CLASS (sym
) = LOC_CONST
;
8746 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
8747 SYMBOL_CLASS (sym
) = LOC_CONST
;
8751 complaint (&symfile_complaints
,
8752 _("unsupported const value attribute form: '%s'"),
8753 dwarf_form_name (attr
->form
));
8754 SYMBOL_VALUE (sym
) = 0;
8755 SYMBOL_CLASS (sym
) = LOC_CONST
;
8761 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
8762 or zero-extend it as appropriate for the symbol's type. */
8764 dwarf2_const_value_data (struct attribute
*attr
,
8768 LONGEST l
= DW_UNSND (attr
);
8770 if (bits
< sizeof (l
) * 8)
8772 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
8773 l
&= ((LONGEST
) 1 << bits
) - 1;
8775 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
8778 SYMBOL_VALUE (sym
) = l
;
8779 SYMBOL_CLASS (sym
) = LOC_CONST
;
8783 /* Return the type of the die in question using its DW_AT_type attribute. */
8785 static struct type
*
8786 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8789 struct attribute
*type_attr
;
8790 struct die_info
*type_die
;
8792 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
8795 /* A missing DW_AT_type represents a void type. */
8796 return objfile_type (cu
->objfile
)->builtin_void
;
8799 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
8801 type
= tag_type_to_type (type_die
, cu
);
8804 dump_die_for_error (type_die
);
8805 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
8811 /* True iff CU's producer generates GNAT Ada auxiliary information
8812 that allows to find parallel types through that information instead
8813 of having to do expensive parallel lookups by type name. */
8816 need_gnat_info (struct dwarf2_cu
*cu
)
8818 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
8819 of GNAT produces this auxiliary information, without any indication
8820 that it is produced. Part of enhancing the FSF version of GNAT
8821 to produce that information will be to put in place an indicator
8822 that we can use in order to determine whether the descriptive type
8823 info is available or not. One suggestion that has been made is
8824 to use a new attribute, attached to the CU die. For now, assume
8825 that the descriptive type info is not available. */
8830 /* Return the auxiliary type of the die in question using its
8831 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
8832 attribute is not present. */
8834 static struct type
*
8835 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8838 struct attribute
*type_attr
;
8839 struct die_info
*type_die
;
8841 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
8845 type_die
= follow_die_ref (die
, type_attr
, &cu
);
8846 type
= tag_type_to_type (type_die
, cu
);
8849 dump_die_for_error (type_die
);
8850 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
8856 /* If DIE has a descriptive_type attribute, then set the TYPE's
8857 descriptive type accordingly. */
8860 set_descriptive_type (struct type
*type
, struct die_info
*die
,
8861 struct dwarf2_cu
*cu
)
8863 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
8865 if (descriptive_type
)
8867 ALLOCATE_GNAT_AUX_TYPE (type
);
8868 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
8872 /* Return the containing type of the die in question using its
8873 DW_AT_containing_type attribute. */
8875 static struct type
*
8876 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8878 struct type
*type
= NULL
;
8879 struct attribute
*type_attr
;
8880 struct die_info
*type_die
= NULL
;
8882 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
8885 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
8886 type
= tag_type_to_type (type_die
, cu
);
8891 dump_die_for_error (type_die
);
8892 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
8898 static struct type
*
8899 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8901 struct type
*this_type
;
8903 this_type
= read_type_die (die
, cu
);
8906 dump_die_for_error (die
);
8907 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
8913 static struct type
*
8914 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8916 struct type
*this_type
;
8918 this_type
= get_die_type (die
, cu
);
8924 case DW_TAG_class_type
:
8925 case DW_TAG_interface_type
:
8926 case DW_TAG_structure_type
:
8927 case DW_TAG_union_type
:
8928 this_type
= read_structure_type (die
, cu
);
8930 case DW_TAG_enumeration_type
:
8931 this_type
= read_enumeration_type (die
, cu
);
8933 case DW_TAG_subprogram
:
8934 case DW_TAG_subroutine_type
:
8935 case DW_TAG_inlined_subroutine
:
8936 this_type
= read_subroutine_type (die
, cu
);
8938 case DW_TAG_array_type
:
8939 this_type
= read_array_type (die
, cu
);
8941 case DW_TAG_set_type
:
8942 this_type
= read_set_type (die
, cu
);
8944 case DW_TAG_pointer_type
:
8945 this_type
= read_tag_pointer_type (die
, cu
);
8947 case DW_TAG_ptr_to_member_type
:
8948 this_type
= read_tag_ptr_to_member_type (die
, cu
);
8950 case DW_TAG_reference_type
:
8951 this_type
= read_tag_reference_type (die
, cu
);
8953 case DW_TAG_const_type
:
8954 this_type
= read_tag_const_type (die
, cu
);
8956 case DW_TAG_volatile_type
:
8957 this_type
= read_tag_volatile_type (die
, cu
);
8959 case DW_TAG_string_type
:
8960 this_type
= read_tag_string_type (die
, cu
);
8962 case DW_TAG_typedef
:
8963 this_type
= read_typedef (die
, cu
);
8965 case DW_TAG_subrange_type
:
8966 this_type
= read_subrange_type (die
, cu
);
8968 case DW_TAG_base_type
:
8969 this_type
= read_base_type (die
, cu
);
8971 case DW_TAG_unspecified_type
:
8972 this_type
= read_unspecified_type (die
, cu
);
8974 case DW_TAG_namespace
:
8975 this_type
= read_namespace_type (die
, cu
);
8978 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
8979 dwarf_tag_name (die
->tag
));
8986 /* Return the name of the namespace/class that DIE is defined within,
8987 or "" if we can't tell. The caller should not xfree the result.
8989 For example, if we're within the method foo() in the following
8999 then determine_prefix on foo's die will return "N::C". */
9002 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
9004 struct die_info
*parent
, *spec_die
;
9005 struct dwarf2_cu
*spec_cu
;
9006 struct type
*parent_type
;
9008 if (cu
->language
!= language_cplus
9009 && cu
->language
!= language_java
)
9012 /* We have to be careful in the presence of DW_AT_specification.
9013 For example, with GCC 3.4, given the code
9017 // Definition of N::foo.
9021 then we'll have a tree of DIEs like this:
9023 1: DW_TAG_compile_unit
9024 2: DW_TAG_namespace // N
9025 3: DW_TAG_subprogram // declaration of N::foo
9026 4: DW_TAG_subprogram // definition of N::foo
9027 DW_AT_specification // refers to die #3
9029 Thus, when processing die #4, we have to pretend that we're in
9030 the context of its DW_AT_specification, namely the contex of die
9033 spec_die
= die_specification (die
, &spec_cu
);
9034 if (spec_die
== NULL
)
9035 parent
= die
->parent
;
9038 parent
= spec_die
->parent
;
9045 switch (parent
->tag
)
9047 case DW_TAG_namespace
:
9048 parent_type
= read_type_die (parent
, cu
);
9049 /* We give a name to even anonymous namespaces. */
9050 return TYPE_TAG_NAME (parent_type
);
9051 case DW_TAG_class_type
:
9052 case DW_TAG_interface_type
:
9053 case DW_TAG_structure_type
:
9054 case DW_TAG_union_type
:
9055 parent_type
= read_type_die (parent
, cu
);
9056 if (TYPE_TAG_NAME (parent_type
) != NULL
)
9057 return TYPE_TAG_NAME (parent_type
);
9059 /* An anonymous structure is only allowed non-static data
9060 members; no typedefs, no member functions, et cetera.
9061 So it does not need a prefix. */
9064 return determine_prefix (parent
, cu
);
9068 /* Return a newly-allocated string formed by concatenating PREFIX and
9069 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
9070 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
9071 perform an obconcat, otherwise allocate storage for the result. The CU argument
9072 is used to determine the language and hence, the appropriate separator. */
9074 #define MAX_SEP_LEN 2 /* sizeof ("::") */
9077 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
9078 struct dwarf2_cu
*cu
)
9082 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
9084 else if (cu
->language
== language_java
)
9096 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
9097 strcpy (retval
, prefix
);
9098 strcat (retval
, sep
);
9099 strcat (retval
, suffix
);
9104 /* We have an obstack. */
9105 return obconcat (obs
, prefix
, sep
, suffix
);
9109 /* Return sibling of die, NULL if no sibling. */
9111 static struct die_info
*
9112 sibling_die (struct die_info
*die
)
9114 return die
->sibling
;
9117 /* Get name of a die, return NULL if not found. */
9120 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
9121 struct obstack
*obstack
)
9123 if (name
&& cu
->language
== language_cplus
)
9125 char *canon_name
= cp_canonicalize_string (name
);
9127 if (canon_name
!= NULL
)
9129 if (strcmp (canon_name
, name
) != 0)
9130 name
= obsavestring (canon_name
, strlen (canon_name
),
9139 /* Get name of a die, return NULL if not found. */
9142 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9144 struct attribute
*attr
;
9146 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
9147 if (!attr
|| !DW_STRING (attr
))
9152 case DW_TAG_compile_unit
:
9153 /* Compilation units have a DW_AT_name that is a filename, not
9154 a source language identifier. */
9155 case DW_TAG_enumeration_type
:
9156 case DW_TAG_enumerator
:
9157 /* These tags always have simple identifiers already; no need
9158 to canonicalize them. */
9159 return DW_STRING (attr
);
9161 if (!DW_STRING_IS_CANONICAL (attr
))
9164 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
9165 &cu
->objfile
->objfile_obstack
);
9166 DW_STRING_IS_CANONICAL (attr
) = 1;
9168 return DW_STRING (attr
);
9172 /* Return the die that this die in an extension of, or NULL if there
9173 is none. *EXT_CU is the CU containing DIE on input, and the CU
9174 containing the return value on output. */
9176 static struct die_info
*
9177 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
9179 struct attribute
*attr
;
9181 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
9185 return follow_die_ref (die
, attr
, ext_cu
);
9188 /* Convert a DIE tag into its string name. */
9191 dwarf_tag_name (unsigned tag
)
9195 case DW_TAG_padding
:
9196 return "DW_TAG_padding";
9197 case DW_TAG_array_type
:
9198 return "DW_TAG_array_type";
9199 case DW_TAG_class_type
:
9200 return "DW_TAG_class_type";
9201 case DW_TAG_entry_point
:
9202 return "DW_TAG_entry_point";
9203 case DW_TAG_enumeration_type
:
9204 return "DW_TAG_enumeration_type";
9205 case DW_TAG_formal_parameter
:
9206 return "DW_TAG_formal_parameter";
9207 case DW_TAG_imported_declaration
:
9208 return "DW_TAG_imported_declaration";
9210 return "DW_TAG_label";
9211 case DW_TAG_lexical_block
:
9212 return "DW_TAG_lexical_block";
9214 return "DW_TAG_member";
9215 case DW_TAG_pointer_type
:
9216 return "DW_TAG_pointer_type";
9217 case DW_TAG_reference_type
:
9218 return "DW_TAG_reference_type";
9219 case DW_TAG_compile_unit
:
9220 return "DW_TAG_compile_unit";
9221 case DW_TAG_string_type
:
9222 return "DW_TAG_string_type";
9223 case DW_TAG_structure_type
:
9224 return "DW_TAG_structure_type";
9225 case DW_TAG_subroutine_type
:
9226 return "DW_TAG_subroutine_type";
9227 case DW_TAG_typedef
:
9228 return "DW_TAG_typedef";
9229 case DW_TAG_union_type
:
9230 return "DW_TAG_union_type";
9231 case DW_TAG_unspecified_parameters
:
9232 return "DW_TAG_unspecified_parameters";
9233 case DW_TAG_variant
:
9234 return "DW_TAG_variant";
9235 case DW_TAG_common_block
:
9236 return "DW_TAG_common_block";
9237 case DW_TAG_common_inclusion
:
9238 return "DW_TAG_common_inclusion";
9239 case DW_TAG_inheritance
:
9240 return "DW_TAG_inheritance";
9241 case DW_TAG_inlined_subroutine
:
9242 return "DW_TAG_inlined_subroutine";
9244 return "DW_TAG_module";
9245 case DW_TAG_ptr_to_member_type
:
9246 return "DW_TAG_ptr_to_member_type";
9247 case DW_TAG_set_type
:
9248 return "DW_TAG_set_type";
9249 case DW_TAG_subrange_type
:
9250 return "DW_TAG_subrange_type";
9251 case DW_TAG_with_stmt
:
9252 return "DW_TAG_with_stmt";
9253 case DW_TAG_access_declaration
:
9254 return "DW_TAG_access_declaration";
9255 case DW_TAG_base_type
:
9256 return "DW_TAG_base_type";
9257 case DW_TAG_catch_block
:
9258 return "DW_TAG_catch_block";
9259 case DW_TAG_const_type
:
9260 return "DW_TAG_const_type";
9261 case DW_TAG_constant
:
9262 return "DW_TAG_constant";
9263 case DW_TAG_enumerator
:
9264 return "DW_TAG_enumerator";
9265 case DW_TAG_file_type
:
9266 return "DW_TAG_file_type";
9268 return "DW_TAG_friend";
9269 case DW_TAG_namelist
:
9270 return "DW_TAG_namelist";
9271 case DW_TAG_namelist_item
:
9272 return "DW_TAG_namelist_item";
9273 case DW_TAG_packed_type
:
9274 return "DW_TAG_packed_type";
9275 case DW_TAG_subprogram
:
9276 return "DW_TAG_subprogram";
9277 case DW_TAG_template_type_param
:
9278 return "DW_TAG_template_type_param";
9279 case DW_TAG_template_value_param
:
9280 return "DW_TAG_template_value_param";
9281 case DW_TAG_thrown_type
:
9282 return "DW_TAG_thrown_type";
9283 case DW_TAG_try_block
:
9284 return "DW_TAG_try_block";
9285 case DW_TAG_variant_part
:
9286 return "DW_TAG_variant_part";
9287 case DW_TAG_variable
:
9288 return "DW_TAG_variable";
9289 case DW_TAG_volatile_type
:
9290 return "DW_TAG_volatile_type";
9291 case DW_TAG_dwarf_procedure
:
9292 return "DW_TAG_dwarf_procedure";
9293 case DW_TAG_restrict_type
:
9294 return "DW_TAG_restrict_type";
9295 case DW_TAG_interface_type
:
9296 return "DW_TAG_interface_type";
9297 case DW_TAG_namespace
:
9298 return "DW_TAG_namespace";
9299 case DW_TAG_imported_module
:
9300 return "DW_TAG_imported_module";
9301 case DW_TAG_unspecified_type
:
9302 return "DW_TAG_unspecified_type";
9303 case DW_TAG_partial_unit
:
9304 return "DW_TAG_partial_unit";
9305 case DW_TAG_imported_unit
:
9306 return "DW_TAG_imported_unit";
9307 case DW_TAG_condition
:
9308 return "DW_TAG_condition";
9309 case DW_TAG_shared_type
:
9310 return "DW_TAG_shared_type";
9311 case DW_TAG_type_unit
:
9312 return "DW_TAG_type_unit";
9313 case DW_TAG_MIPS_loop
:
9314 return "DW_TAG_MIPS_loop";
9315 case DW_TAG_HP_array_descriptor
:
9316 return "DW_TAG_HP_array_descriptor";
9317 case DW_TAG_format_label
:
9318 return "DW_TAG_format_label";
9319 case DW_TAG_function_template
:
9320 return "DW_TAG_function_template";
9321 case DW_TAG_class_template
:
9322 return "DW_TAG_class_template";
9323 case DW_TAG_GNU_BINCL
:
9324 return "DW_TAG_GNU_BINCL";
9325 case DW_TAG_GNU_EINCL
:
9326 return "DW_TAG_GNU_EINCL";
9327 case DW_TAG_upc_shared_type
:
9328 return "DW_TAG_upc_shared_type";
9329 case DW_TAG_upc_strict_type
:
9330 return "DW_TAG_upc_strict_type";
9331 case DW_TAG_upc_relaxed_type
:
9332 return "DW_TAG_upc_relaxed_type";
9333 case DW_TAG_PGI_kanji_type
:
9334 return "DW_TAG_PGI_kanji_type";
9335 case DW_TAG_PGI_interface_block
:
9336 return "DW_TAG_PGI_interface_block";
9338 return "DW_TAG_<unknown>";
9342 /* Convert a DWARF attribute code into its string name. */
9345 dwarf_attr_name (unsigned attr
)
9350 return "DW_AT_sibling";
9351 case DW_AT_location
:
9352 return "DW_AT_location";
9354 return "DW_AT_name";
9355 case DW_AT_ordering
:
9356 return "DW_AT_ordering";
9357 case DW_AT_subscr_data
:
9358 return "DW_AT_subscr_data";
9359 case DW_AT_byte_size
:
9360 return "DW_AT_byte_size";
9361 case DW_AT_bit_offset
:
9362 return "DW_AT_bit_offset";
9363 case DW_AT_bit_size
:
9364 return "DW_AT_bit_size";
9365 case DW_AT_element_list
:
9366 return "DW_AT_element_list";
9367 case DW_AT_stmt_list
:
9368 return "DW_AT_stmt_list";
9370 return "DW_AT_low_pc";
9372 return "DW_AT_high_pc";
9373 case DW_AT_language
:
9374 return "DW_AT_language";
9376 return "DW_AT_member";
9378 return "DW_AT_discr";
9379 case DW_AT_discr_value
:
9380 return "DW_AT_discr_value";
9381 case DW_AT_visibility
:
9382 return "DW_AT_visibility";
9384 return "DW_AT_import";
9385 case DW_AT_string_length
:
9386 return "DW_AT_string_length";
9387 case DW_AT_common_reference
:
9388 return "DW_AT_common_reference";
9389 case DW_AT_comp_dir
:
9390 return "DW_AT_comp_dir";
9391 case DW_AT_const_value
:
9392 return "DW_AT_const_value";
9393 case DW_AT_containing_type
:
9394 return "DW_AT_containing_type";
9395 case DW_AT_default_value
:
9396 return "DW_AT_default_value";
9398 return "DW_AT_inline";
9399 case DW_AT_is_optional
:
9400 return "DW_AT_is_optional";
9401 case DW_AT_lower_bound
:
9402 return "DW_AT_lower_bound";
9403 case DW_AT_producer
:
9404 return "DW_AT_producer";
9405 case DW_AT_prototyped
:
9406 return "DW_AT_prototyped";
9407 case DW_AT_return_addr
:
9408 return "DW_AT_return_addr";
9409 case DW_AT_start_scope
:
9410 return "DW_AT_start_scope";
9411 case DW_AT_bit_stride
:
9412 return "DW_AT_bit_stride";
9413 case DW_AT_upper_bound
:
9414 return "DW_AT_upper_bound";
9415 case DW_AT_abstract_origin
:
9416 return "DW_AT_abstract_origin";
9417 case DW_AT_accessibility
:
9418 return "DW_AT_accessibility";
9419 case DW_AT_address_class
:
9420 return "DW_AT_address_class";
9421 case DW_AT_artificial
:
9422 return "DW_AT_artificial";
9423 case DW_AT_base_types
:
9424 return "DW_AT_base_types";
9425 case DW_AT_calling_convention
:
9426 return "DW_AT_calling_convention";
9428 return "DW_AT_count";
9429 case DW_AT_data_member_location
:
9430 return "DW_AT_data_member_location";
9431 case DW_AT_decl_column
:
9432 return "DW_AT_decl_column";
9433 case DW_AT_decl_file
:
9434 return "DW_AT_decl_file";
9435 case DW_AT_decl_line
:
9436 return "DW_AT_decl_line";
9437 case DW_AT_declaration
:
9438 return "DW_AT_declaration";
9439 case DW_AT_discr_list
:
9440 return "DW_AT_discr_list";
9441 case DW_AT_encoding
:
9442 return "DW_AT_encoding";
9443 case DW_AT_external
:
9444 return "DW_AT_external";
9445 case DW_AT_frame_base
:
9446 return "DW_AT_frame_base";
9448 return "DW_AT_friend";
9449 case DW_AT_identifier_case
:
9450 return "DW_AT_identifier_case";
9451 case DW_AT_macro_info
:
9452 return "DW_AT_macro_info";
9453 case DW_AT_namelist_items
:
9454 return "DW_AT_namelist_items";
9455 case DW_AT_priority
:
9456 return "DW_AT_priority";
9458 return "DW_AT_segment";
9459 case DW_AT_specification
:
9460 return "DW_AT_specification";
9461 case DW_AT_static_link
:
9462 return "DW_AT_static_link";
9464 return "DW_AT_type";
9465 case DW_AT_use_location
:
9466 return "DW_AT_use_location";
9467 case DW_AT_variable_parameter
:
9468 return "DW_AT_variable_parameter";
9469 case DW_AT_virtuality
:
9470 return "DW_AT_virtuality";
9471 case DW_AT_vtable_elem_location
:
9472 return "DW_AT_vtable_elem_location";
9473 /* DWARF 3 values. */
9474 case DW_AT_allocated
:
9475 return "DW_AT_allocated";
9476 case DW_AT_associated
:
9477 return "DW_AT_associated";
9478 case DW_AT_data_location
:
9479 return "DW_AT_data_location";
9480 case DW_AT_byte_stride
:
9481 return "DW_AT_byte_stride";
9482 case DW_AT_entry_pc
:
9483 return "DW_AT_entry_pc";
9484 case DW_AT_use_UTF8
:
9485 return "DW_AT_use_UTF8";
9486 case DW_AT_extension
:
9487 return "DW_AT_extension";
9489 return "DW_AT_ranges";
9490 case DW_AT_trampoline
:
9491 return "DW_AT_trampoline";
9492 case DW_AT_call_column
:
9493 return "DW_AT_call_column";
9494 case DW_AT_call_file
:
9495 return "DW_AT_call_file";
9496 case DW_AT_call_line
:
9497 return "DW_AT_call_line";
9498 case DW_AT_description
:
9499 return "DW_AT_description";
9500 case DW_AT_binary_scale
:
9501 return "DW_AT_binary_scale";
9502 case DW_AT_decimal_scale
:
9503 return "DW_AT_decimal_scale";
9505 return "DW_AT_small";
9506 case DW_AT_decimal_sign
:
9507 return "DW_AT_decimal_sign";
9508 case DW_AT_digit_count
:
9509 return "DW_AT_digit_count";
9510 case DW_AT_picture_string
:
9511 return "DW_AT_picture_string";
9513 return "DW_AT_mutable";
9514 case DW_AT_threads_scaled
:
9515 return "DW_AT_threads_scaled";
9516 case DW_AT_explicit
:
9517 return "DW_AT_explicit";
9518 case DW_AT_object_pointer
:
9519 return "DW_AT_object_pointer";
9520 case DW_AT_endianity
:
9521 return "DW_AT_endianity";
9522 case DW_AT_elemental
:
9523 return "DW_AT_elemental";
9525 return "DW_AT_pure";
9526 case DW_AT_recursive
:
9527 return "DW_AT_recursive";
9528 /* DWARF 4 values. */
9529 case DW_AT_signature
:
9530 return "DW_AT_signature";
9531 /* SGI/MIPS extensions. */
9532 #ifdef MIPS /* collides with DW_AT_HP_block_index */
9533 case DW_AT_MIPS_fde
:
9534 return "DW_AT_MIPS_fde";
9536 case DW_AT_MIPS_loop_begin
:
9537 return "DW_AT_MIPS_loop_begin";
9538 case DW_AT_MIPS_tail_loop_begin
:
9539 return "DW_AT_MIPS_tail_loop_begin";
9540 case DW_AT_MIPS_epilog_begin
:
9541 return "DW_AT_MIPS_epilog_begin";
9542 case DW_AT_MIPS_loop_unroll_factor
:
9543 return "DW_AT_MIPS_loop_unroll_factor";
9544 case DW_AT_MIPS_software_pipeline_depth
:
9545 return "DW_AT_MIPS_software_pipeline_depth";
9546 case DW_AT_MIPS_linkage_name
:
9547 return "DW_AT_MIPS_linkage_name";
9548 case DW_AT_MIPS_stride
:
9549 return "DW_AT_MIPS_stride";
9550 case DW_AT_MIPS_abstract_name
:
9551 return "DW_AT_MIPS_abstract_name";
9552 case DW_AT_MIPS_clone_origin
:
9553 return "DW_AT_MIPS_clone_origin";
9554 case DW_AT_MIPS_has_inlines
:
9555 return "DW_AT_MIPS_has_inlines";
9556 /* HP extensions. */
9557 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
9558 case DW_AT_HP_block_index
:
9559 return "DW_AT_HP_block_index";
9561 case DW_AT_HP_unmodifiable
:
9562 return "DW_AT_HP_unmodifiable";
9563 case DW_AT_HP_actuals_stmt_list
:
9564 return "DW_AT_HP_actuals_stmt_list";
9565 case DW_AT_HP_proc_per_section
:
9566 return "DW_AT_HP_proc_per_section";
9567 case DW_AT_HP_raw_data_ptr
:
9568 return "DW_AT_HP_raw_data_ptr";
9569 case DW_AT_HP_pass_by_reference
:
9570 return "DW_AT_HP_pass_by_reference";
9571 case DW_AT_HP_opt_level
:
9572 return "DW_AT_HP_opt_level";
9573 case DW_AT_HP_prof_version_id
:
9574 return "DW_AT_HP_prof_version_id";
9575 case DW_AT_HP_opt_flags
:
9576 return "DW_AT_HP_opt_flags";
9577 case DW_AT_HP_cold_region_low_pc
:
9578 return "DW_AT_HP_cold_region_low_pc";
9579 case DW_AT_HP_cold_region_high_pc
:
9580 return "DW_AT_HP_cold_region_high_pc";
9581 case DW_AT_HP_all_variables_modifiable
:
9582 return "DW_AT_HP_all_variables_modifiable";
9583 case DW_AT_HP_linkage_name
:
9584 return "DW_AT_HP_linkage_name";
9585 case DW_AT_HP_prof_flags
:
9586 return "DW_AT_HP_prof_flags";
9587 /* GNU extensions. */
9588 case DW_AT_sf_names
:
9589 return "DW_AT_sf_names";
9590 case DW_AT_src_info
:
9591 return "DW_AT_src_info";
9592 case DW_AT_mac_info
:
9593 return "DW_AT_mac_info";
9594 case DW_AT_src_coords
:
9595 return "DW_AT_src_coords";
9596 case DW_AT_body_begin
:
9597 return "DW_AT_body_begin";
9598 case DW_AT_body_end
:
9599 return "DW_AT_body_end";
9600 case DW_AT_GNU_vector
:
9601 return "DW_AT_GNU_vector";
9602 /* VMS extensions. */
9603 case DW_AT_VMS_rtnbeg_pd_address
:
9604 return "DW_AT_VMS_rtnbeg_pd_address";
9605 /* UPC extension. */
9606 case DW_AT_upc_threads_scaled
:
9607 return "DW_AT_upc_threads_scaled";
9608 /* PGI (STMicroelectronics) extensions. */
9609 case DW_AT_PGI_lbase
:
9610 return "DW_AT_PGI_lbase";
9611 case DW_AT_PGI_soffset
:
9612 return "DW_AT_PGI_soffset";
9613 case DW_AT_PGI_lstride
:
9614 return "DW_AT_PGI_lstride";
9616 return "DW_AT_<unknown>";
9620 /* Convert a DWARF value form code into its string name. */
9623 dwarf_form_name (unsigned form
)
9628 return "DW_FORM_addr";
9629 case DW_FORM_block2
:
9630 return "DW_FORM_block2";
9631 case DW_FORM_block4
:
9632 return "DW_FORM_block4";
9634 return "DW_FORM_data2";
9636 return "DW_FORM_data4";
9638 return "DW_FORM_data8";
9639 case DW_FORM_string
:
9640 return "DW_FORM_string";
9642 return "DW_FORM_block";
9643 case DW_FORM_block1
:
9644 return "DW_FORM_block1";
9646 return "DW_FORM_data1";
9648 return "DW_FORM_flag";
9650 return "DW_FORM_sdata";
9652 return "DW_FORM_strp";
9654 return "DW_FORM_udata";
9655 case DW_FORM_ref_addr
:
9656 return "DW_FORM_ref_addr";
9658 return "DW_FORM_ref1";
9660 return "DW_FORM_ref2";
9662 return "DW_FORM_ref4";
9664 return "DW_FORM_ref8";
9665 case DW_FORM_ref_udata
:
9666 return "DW_FORM_ref_udata";
9667 case DW_FORM_indirect
:
9668 return "DW_FORM_indirect";
9669 case DW_FORM_sec_offset
:
9670 return "DW_FORM_sec_offset";
9671 case DW_FORM_exprloc
:
9672 return "DW_FORM_exprloc";
9673 case DW_FORM_flag_present
:
9674 return "DW_FORM_flag_present";
9676 return "DW_FORM_sig8";
9678 return "DW_FORM_<unknown>";
9682 /* Convert a DWARF stack opcode into its string name. */
9685 dwarf_stack_op_name (unsigned op
)
9690 return "DW_OP_addr";
9692 return "DW_OP_deref";
9694 return "DW_OP_const1u";
9696 return "DW_OP_const1s";
9698 return "DW_OP_const2u";
9700 return "DW_OP_const2s";
9702 return "DW_OP_const4u";
9704 return "DW_OP_const4s";
9706 return "DW_OP_const8u";
9708 return "DW_OP_const8s";
9710 return "DW_OP_constu";
9712 return "DW_OP_consts";
9716 return "DW_OP_drop";
9718 return "DW_OP_over";
9720 return "DW_OP_pick";
9722 return "DW_OP_swap";
9726 return "DW_OP_xderef";
9734 return "DW_OP_minus";
9746 return "DW_OP_plus";
9747 case DW_OP_plus_uconst
:
9748 return "DW_OP_plus_uconst";
9754 return "DW_OP_shra";
9772 return "DW_OP_skip";
9774 return "DW_OP_lit0";
9776 return "DW_OP_lit1";
9778 return "DW_OP_lit2";
9780 return "DW_OP_lit3";
9782 return "DW_OP_lit4";
9784 return "DW_OP_lit5";
9786 return "DW_OP_lit6";
9788 return "DW_OP_lit7";
9790 return "DW_OP_lit8";
9792 return "DW_OP_lit9";
9794 return "DW_OP_lit10";
9796 return "DW_OP_lit11";
9798 return "DW_OP_lit12";
9800 return "DW_OP_lit13";
9802 return "DW_OP_lit14";
9804 return "DW_OP_lit15";
9806 return "DW_OP_lit16";
9808 return "DW_OP_lit17";
9810 return "DW_OP_lit18";
9812 return "DW_OP_lit19";
9814 return "DW_OP_lit20";
9816 return "DW_OP_lit21";
9818 return "DW_OP_lit22";
9820 return "DW_OP_lit23";
9822 return "DW_OP_lit24";
9824 return "DW_OP_lit25";
9826 return "DW_OP_lit26";
9828 return "DW_OP_lit27";
9830 return "DW_OP_lit28";
9832 return "DW_OP_lit29";
9834 return "DW_OP_lit30";
9836 return "DW_OP_lit31";
9838 return "DW_OP_reg0";
9840 return "DW_OP_reg1";
9842 return "DW_OP_reg2";
9844 return "DW_OP_reg3";
9846 return "DW_OP_reg4";
9848 return "DW_OP_reg5";
9850 return "DW_OP_reg6";
9852 return "DW_OP_reg7";
9854 return "DW_OP_reg8";
9856 return "DW_OP_reg9";
9858 return "DW_OP_reg10";
9860 return "DW_OP_reg11";
9862 return "DW_OP_reg12";
9864 return "DW_OP_reg13";
9866 return "DW_OP_reg14";
9868 return "DW_OP_reg15";
9870 return "DW_OP_reg16";
9872 return "DW_OP_reg17";
9874 return "DW_OP_reg18";
9876 return "DW_OP_reg19";
9878 return "DW_OP_reg20";
9880 return "DW_OP_reg21";
9882 return "DW_OP_reg22";
9884 return "DW_OP_reg23";
9886 return "DW_OP_reg24";
9888 return "DW_OP_reg25";
9890 return "DW_OP_reg26";
9892 return "DW_OP_reg27";
9894 return "DW_OP_reg28";
9896 return "DW_OP_reg29";
9898 return "DW_OP_reg30";
9900 return "DW_OP_reg31";
9902 return "DW_OP_breg0";
9904 return "DW_OP_breg1";
9906 return "DW_OP_breg2";
9908 return "DW_OP_breg3";
9910 return "DW_OP_breg4";
9912 return "DW_OP_breg5";
9914 return "DW_OP_breg6";
9916 return "DW_OP_breg7";
9918 return "DW_OP_breg8";
9920 return "DW_OP_breg9";
9922 return "DW_OP_breg10";
9924 return "DW_OP_breg11";
9926 return "DW_OP_breg12";
9928 return "DW_OP_breg13";
9930 return "DW_OP_breg14";
9932 return "DW_OP_breg15";
9934 return "DW_OP_breg16";
9936 return "DW_OP_breg17";
9938 return "DW_OP_breg18";
9940 return "DW_OP_breg19";
9942 return "DW_OP_breg20";
9944 return "DW_OP_breg21";
9946 return "DW_OP_breg22";
9948 return "DW_OP_breg23";
9950 return "DW_OP_breg24";
9952 return "DW_OP_breg25";
9954 return "DW_OP_breg26";
9956 return "DW_OP_breg27";
9958 return "DW_OP_breg28";
9960 return "DW_OP_breg29";
9962 return "DW_OP_breg30";
9964 return "DW_OP_breg31";
9966 return "DW_OP_regx";
9968 return "DW_OP_fbreg";
9970 return "DW_OP_bregx";
9972 return "DW_OP_piece";
9973 case DW_OP_deref_size
:
9974 return "DW_OP_deref_size";
9975 case DW_OP_xderef_size
:
9976 return "DW_OP_xderef_size";
9979 /* DWARF 3 extensions. */
9980 case DW_OP_push_object_address
:
9981 return "DW_OP_push_object_address";
9983 return "DW_OP_call2";
9985 return "DW_OP_call4";
9986 case DW_OP_call_ref
:
9987 return "DW_OP_call_ref";
9988 /* GNU extensions. */
9989 case DW_OP_form_tls_address
:
9990 return "DW_OP_form_tls_address";
9991 case DW_OP_call_frame_cfa
:
9992 return "DW_OP_call_frame_cfa";
9993 case DW_OP_bit_piece
:
9994 return "DW_OP_bit_piece";
9995 case DW_OP_GNU_push_tls_address
:
9996 return "DW_OP_GNU_push_tls_address";
9997 case DW_OP_GNU_uninit
:
9998 return "DW_OP_GNU_uninit";
9999 /* HP extensions. */
10000 case DW_OP_HP_is_value
:
10001 return "DW_OP_HP_is_value";
10002 case DW_OP_HP_fltconst4
:
10003 return "DW_OP_HP_fltconst4";
10004 case DW_OP_HP_fltconst8
:
10005 return "DW_OP_HP_fltconst8";
10006 case DW_OP_HP_mod_range
:
10007 return "DW_OP_HP_mod_range";
10008 case DW_OP_HP_unmod_range
:
10009 return "DW_OP_HP_unmod_range";
10011 return "DW_OP_HP_tls";
10013 return "OP_<unknown>";
10018 dwarf_bool_name (unsigned mybool
)
10026 /* Convert a DWARF type code into its string name. */
10029 dwarf_type_encoding_name (unsigned enc
)
10034 return "DW_ATE_void";
10035 case DW_ATE_address
:
10036 return "DW_ATE_address";
10037 case DW_ATE_boolean
:
10038 return "DW_ATE_boolean";
10039 case DW_ATE_complex_float
:
10040 return "DW_ATE_complex_float";
10042 return "DW_ATE_float";
10043 case DW_ATE_signed
:
10044 return "DW_ATE_signed";
10045 case DW_ATE_signed_char
:
10046 return "DW_ATE_signed_char";
10047 case DW_ATE_unsigned
:
10048 return "DW_ATE_unsigned";
10049 case DW_ATE_unsigned_char
:
10050 return "DW_ATE_unsigned_char";
10052 case DW_ATE_imaginary_float
:
10053 return "DW_ATE_imaginary_float";
10054 case DW_ATE_packed_decimal
:
10055 return "DW_ATE_packed_decimal";
10056 case DW_ATE_numeric_string
:
10057 return "DW_ATE_numeric_string";
10058 case DW_ATE_edited
:
10059 return "DW_ATE_edited";
10060 case DW_ATE_signed_fixed
:
10061 return "DW_ATE_signed_fixed";
10062 case DW_ATE_unsigned_fixed
:
10063 return "DW_ATE_unsigned_fixed";
10064 case DW_ATE_decimal_float
:
10065 return "DW_ATE_decimal_float";
10066 /* HP extensions. */
10067 case DW_ATE_HP_float80
:
10068 return "DW_ATE_HP_float80";
10069 case DW_ATE_HP_complex_float80
:
10070 return "DW_ATE_HP_complex_float80";
10071 case DW_ATE_HP_float128
:
10072 return "DW_ATE_HP_float128";
10073 case DW_ATE_HP_complex_float128
:
10074 return "DW_ATE_HP_complex_float128";
10075 case DW_ATE_HP_floathpintel
:
10076 return "DW_ATE_HP_floathpintel";
10077 case DW_ATE_HP_imaginary_float80
:
10078 return "DW_ATE_HP_imaginary_float80";
10079 case DW_ATE_HP_imaginary_float128
:
10080 return "DW_ATE_HP_imaginary_float128";
10082 return "DW_ATE_<unknown>";
10086 /* Convert a DWARF call frame info operation to its string name. */
10090 dwarf_cfi_name (unsigned cfi_opc
)
10094 case DW_CFA_advance_loc
:
10095 return "DW_CFA_advance_loc";
10096 case DW_CFA_offset
:
10097 return "DW_CFA_offset";
10098 case DW_CFA_restore
:
10099 return "DW_CFA_restore";
10101 return "DW_CFA_nop";
10102 case DW_CFA_set_loc
:
10103 return "DW_CFA_set_loc";
10104 case DW_CFA_advance_loc1
:
10105 return "DW_CFA_advance_loc1";
10106 case DW_CFA_advance_loc2
:
10107 return "DW_CFA_advance_loc2";
10108 case DW_CFA_advance_loc4
:
10109 return "DW_CFA_advance_loc4";
10110 case DW_CFA_offset_extended
:
10111 return "DW_CFA_offset_extended";
10112 case DW_CFA_restore_extended
:
10113 return "DW_CFA_restore_extended";
10114 case DW_CFA_undefined
:
10115 return "DW_CFA_undefined";
10116 case DW_CFA_same_value
:
10117 return "DW_CFA_same_value";
10118 case DW_CFA_register
:
10119 return "DW_CFA_register";
10120 case DW_CFA_remember_state
:
10121 return "DW_CFA_remember_state";
10122 case DW_CFA_restore_state
:
10123 return "DW_CFA_restore_state";
10124 case DW_CFA_def_cfa
:
10125 return "DW_CFA_def_cfa";
10126 case DW_CFA_def_cfa_register
:
10127 return "DW_CFA_def_cfa_register";
10128 case DW_CFA_def_cfa_offset
:
10129 return "DW_CFA_def_cfa_offset";
10131 case DW_CFA_def_cfa_expression
:
10132 return "DW_CFA_def_cfa_expression";
10133 case DW_CFA_expression
:
10134 return "DW_CFA_expression";
10135 case DW_CFA_offset_extended_sf
:
10136 return "DW_CFA_offset_extended_sf";
10137 case DW_CFA_def_cfa_sf
:
10138 return "DW_CFA_def_cfa_sf";
10139 case DW_CFA_def_cfa_offset_sf
:
10140 return "DW_CFA_def_cfa_offset_sf";
10141 case DW_CFA_val_offset
:
10142 return "DW_CFA_val_offset";
10143 case DW_CFA_val_offset_sf
:
10144 return "DW_CFA_val_offset_sf";
10145 case DW_CFA_val_expression
:
10146 return "DW_CFA_val_expression";
10147 /* SGI/MIPS specific. */
10148 case DW_CFA_MIPS_advance_loc8
:
10149 return "DW_CFA_MIPS_advance_loc8";
10150 /* GNU extensions. */
10151 case DW_CFA_GNU_window_save
:
10152 return "DW_CFA_GNU_window_save";
10153 case DW_CFA_GNU_args_size
:
10154 return "DW_CFA_GNU_args_size";
10155 case DW_CFA_GNU_negative_offset_extended
:
10156 return "DW_CFA_GNU_negative_offset_extended";
10158 return "DW_CFA_<unknown>";
10164 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
10168 print_spaces (indent
, f
);
10169 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
10170 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
10172 if (die
->parent
!= NULL
)
10174 print_spaces (indent
, f
);
10175 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
10176 die
->parent
->offset
);
10179 print_spaces (indent
, f
);
10180 fprintf_unfiltered (f
, " has children: %s\n",
10181 dwarf_bool_name (die
->child
!= NULL
));
10183 print_spaces (indent
, f
);
10184 fprintf_unfiltered (f
, " attributes:\n");
10186 for (i
= 0; i
< die
->num_attrs
; ++i
)
10188 print_spaces (indent
, f
);
10189 fprintf_unfiltered (f
, " %s (%s) ",
10190 dwarf_attr_name (die
->attrs
[i
].name
),
10191 dwarf_form_name (die
->attrs
[i
].form
));
10193 switch (die
->attrs
[i
].form
)
10195 case DW_FORM_ref_addr
:
10197 fprintf_unfiltered (f
, "address: ");
10198 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
10200 case DW_FORM_block2
:
10201 case DW_FORM_block4
:
10202 case DW_FORM_block
:
10203 case DW_FORM_block1
:
10204 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
10209 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
10210 (long) (DW_ADDR (&die
->attrs
[i
])));
10212 case DW_FORM_data1
:
10213 case DW_FORM_data2
:
10214 case DW_FORM_data4
:
10215 case DW_FORM_data8
:
10216 case DW_FORM_udata
:
10217 case DW_FORM_sdata
:
10218 fprintf_unfiltered (f
, "constant: %s",
10219 pulongest (DW_UNSND (&die
->attrs
[i
])));
10222 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
10223 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
10224 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
10226 fprintf_unfiltered (f
, "signatured type, offset: unknown");
10228 case DW_FORM_string
:
10230 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
10231 DW_STRING (&die
->attrs
[i
])
10232 ? DW_STRING (&die
->attrs
[i
]) : "",
10233 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
10236 if (DW_UNSND (&die
->attrs
[i
]))
10237 fprintf_unfiltered (f
, "flag: TRUE");
10239 fprintf_unfiltered (f
, "flag: FALSE");
10241 case DW_FORM_indirect
:
10242 /* the reader will have reduced the indirect form to
10243 the "base form" so this form should not occur */
10244 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
10247 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
10248 die
->attrs
[i
].form
);
10251 fprintf_unfiltered (f
, "\n");
10256 dump_die_for_error (struct die_info
*die
)
10258 dump_die_shallow (gdb_stderr
, 0, die
);
10262 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
10264 int indent
= level
* 4;
10266 gdb_assert (die
!= NULL
);
10268 if (level
>= max_level
)
10271 dump_die_shallow (f
, indent
, die
);
10273 if (die
->child
!= NULL
)
10275 print_spaces (indent
, f
);
10276 fprintf_unfiltered (f
, " Children:");
10277 if (level
+ 1 < max_level
)
10279 fprintf_unfiltered (f
, "\n");
10280 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
10284 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
10288 if (die
->sibling
!= NULL
&& level
> 0)
10290 dump_die_1 (f
, level
, max_level
, die
->sibling
);
10294 /* This is called from the pdie macro in gdbinit.in.
10295 It's not static so gcc will keep a copy callable from gdb. */
10298 dump_die (struct die_info
*die
, int max_level
)
10300 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
10304 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
10308 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
10314 is_ref_attr (struct attribute
*attr
)
10316 switch (attr
->form
)
10318 case DW_FORM_ref_addr
:
10323 case DW_FORM_ref_udata
:
10330 static unsigned int
10331 dwarf2_get_ref_die_offset (struct attribute
*attr
)
10333 if (is_ref_attr (attr
))
10334 return DW_ADDR (attr
);
10336 complaint (&symfile_complaints
,
10337 _("unsupported die ref attribute form: '%s'"),
10338 dwarf_form_name (attr
->form
));
10342 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
10343 * the value held by the attribute is not constant. */
10346 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
10348 if (attr
->form
== DW_FORM_sdata
)
10349 return DW_SND (attr
);
10350 else if (attr
->form
== DW_FORM_udata
10351 || attr
->form
== DW_FORM_data1
10352 || attr
->form
== DW_FORM_data2
10353 || attr
->form
== DW_FORM_data4
10354 || attr
->form
== DW_FORM_data8
)
10355 return DW_UNSND (attr
);
10358 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
10359 dwarf_form_name (attr
->form
));
10360 return default_value
;
10364 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
10365 unit and add it to our queue.
10366 The result is non-zero if PER_CU was queued, otherwise the result is zero
10367 meaning either PER_CU is already queued or it is already loaded. */
10370 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
10371 struct dwarf2_per_cu_data
*per_cu
)
10373 /* Mark the dependence relation so that we don't flush PER_CU
10375 dwarf2_add_dependence (this_cu
, per_cu
);
10377 /* If it's already on the queue, we have nothing to do. */
10378 if (per_cu
->queued
)
10381 /* If the compilation unit is already loaded, just mark it as
10383 if (per_cu
->cu
!= NULL
)
10385 per_cu
->cu
->last_used
= 0;
10389 /* Add it to the queue. */
10390 queue_comp_unit (per_cu
, this_cu
->objfile
);
10395 /* Follow reference or signature attribute ATTR of SRC_DIE.
10396 On entry *REF_CU is the CU of SRC_DIE.
10397 On exit *REF_CU is the CU of the result. */
10399 static struct die_info
*
10400 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
10401 struct dwarf2_cu
**ref_cu
)
10403 struct die_info
*die
;
10405 if (is_ref_attr (attr
))
10406 die
= follow_die_ref (src_die
, attr
, ref_cu
);
10407 else if (attr
->form
== DW_FORM_sig8
)
10408 die
= follow_die_sig (src_die
, attr
, ref_cu
);
10411 dump_die_for_error (src_die
);
10412 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
10413 (*ref_cu
)->objfile
->name
);
10419 /* Follow reference attribute ATTR of SRC_DIE.
10420 On entry *REF_CU is the CU of SRC_DIE.
10421 On exit *REF_CU is the CU of the result. */
10423 static struct die_info
*
10424 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
10425 struct dwarf2_cu
**ref_cu
)
10427 struct die_info
*die
;
10428 unsigned int offset
;
10429 struct die_info temp_die
;
10430 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
10432 gdb_assert (cu
->per_cu
!= NULL
);
10434 offset
= dwarf2_get_ref_die_offset (attr
);
10436 if (cu
->per_cu
->from_debug_types
)
10438 /* .debug_types CUs cannot reference anything outside their CU.
10439 If they need to, they have to reference a signatured type via
10441 if (! offset_in_cu_p (&cu
->header
, offset
))
10445 else if (! offset_in_cu_p (&cu
->header
, offset
))
10447 struct dwarf2_per_cu_data
*per_cu
;
10448 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
10450 /* If necessary, add it to the queue and load its DIEs. */
10451 if (maybe_queue_comp_unit (cu
, per_cu
))
10452 load_full_comp_unit (per_cu
, cu
->objfile
);
10454 target_cu
= per_cu
->cu
;
10459 *ref_cu
= target_cu
;
10460 temp_die
.offset
= offset
;
10461 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
10467 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
10468 "at 0x%x [in module %s]"),
10469 offset
, src_die
->offset
, cu
->objfile
->name
);
10472 /* Follow the signature attribute ATTR in SRC_DIE.
10473 On entry *REF_CU is the CU of SRC_DIE.
10474 On exit *REF_CU is the CU of the result. */
10476 static struct die_info
*
10477 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
10478 struct dwarf2_cu
**ref_cu
)
10480 struct objfile
*objfile
= (*ref_cu
)->objfile
;
10481 struct die_info temp_die
;
10482 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
10483 struct dwarf2_cu
*sig_cu
;
10484 struct die_info
*die
;
10486 /* sig_type will be NULL if the signatured type is missing from
10488 if (sig_type
== NULL
)
10489 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
10490 "at 0x%x [in module %s]"),
10491 src_die
->offset
, objfile
->name
);
10493 /* If necessary, add it to the queue and load its DIEs. */
10495 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
10496 read_signatured_type (objfile
, sig_type
);
10498 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
10500 sig_cu
= sig_type
->per_cu
.cu
;
10501 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
10502 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
10509 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
10510 "at 0x%x [in module %s]"),
10511 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
10514 /* Given an offset of a signatured type, return its signatured_type. */
10516 static struct signatured_type
*
10517 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
10519 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
10520 unsigned int length
, initial_length_size
;
10521 unsigned int sig_offset
;
10522 struct signatured_type find_entry
, *type_sig
;
10524 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
10525 sig_offset
= (initial_length_size
10527 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
10528 + 1 /*address_size*/);
10529 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
10530 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
10532 /* This is only used to lookup previously recorded types.
10533 If we didn't find it, it's our bug. */
10534 gdb_assert (type_sig
!= NULL
);
10535 gdb_assert (offset
== type_sig
->offset
);
10540 /* Read in signatured type at OFFSET and build its CU and die(s). */
10543 read_signatured_type_at_offset (struct objfile
*objfile
,
10544 unsigned int offset
)
10546 struct signatured_type
*type_sig
;
10548 /* We have the section offset, but we need the signature to do the
10549 hash table lookup. */
10550 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
10552 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
10554 read_signatured_type (objfile
, type_sig
);
10556 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
10559 /* Read in a signatured type and build its CU and DIEs. */
10562 read_signatured_type (struct objfile
*objfile
,
10563 struct signatured_type
*type_sig
)
10565 gdb_byte
*types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
10566 struct die_reader_specs reader_specs
;
10567 struct dwarf2_cu
*cu
;
10568 ULONGEST signature
;
10569 struct cleanup
*back_to
, *free_cu_cleanup
;
10570 struct attribute
*attr
;
10572 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
10574 cu
= xmalloc (sizeof (struct dwarf2_cu
));
10575 memset (cu
, 0, sizeof (struct dwarf2_cu
));
10576 obstack_init (&cu
->comp_unit_obstack
);
10577 cu
->objfile
= objfile
;
10578 type_sig
->per_cu
.cu
= cu
;
10579 cu
->per_cu
= &type_sig
->per_cu
;
10581 /* If an error occurs while loading, release our storage. */
10582 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
10584 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
10585 types_ptr
, objfile
->obfd
);
10586 gdb_assert (signature
== type_sig
->signature
);
10589 = htab_create_alloc_ex (cu
->header
.length
/ 12,
10593 &cu
->comp_unit_obstack
,
10594 hashtab_obstack_allocate
,
10595 dummy_obstack_deallocate
);
10597 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
10598 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
10600 init_cu_die_reader (&reader_specs
, cu
);
10602 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
10605 /* We try not to read any attributes in this function, because not
10606 all objfiles needed for references have been loaded yet, and symbol
10607 table processing isn't initialized. But we have to set the CU language,
10608 or we won't be able to build types correctly. */
10609 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
10611 set_cu_language (DW_UNSND (attr
), cu
);
10613 set_cu_language (language_minimal
, cu
);
10615 do_cleanups (back_to
);
10617 /* We've successfully allocated this compilation unit. Let our caller
10618 clean it up when finished with it. */
10619 discard_cleanups (free_cu_cleanup
);
10621 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
10622 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
10625 /* Decode simple location descriptions.
10626 Given a pointer to a dwarf block that defines a location, compute
10627 the location and return the value.
10629 NOTE drow/2003-11-18: This function is called in two situations
10630 now: for the address of static or global variables (partial symbols
10631 only) and for offsets into structures which are expected to be
10632 (more or less) constant. The partial symbol case should go away,
10633 and only the constant case should remain. That will let this
10634 function complain more accurately. A few special modes are allowed
10635 without complaint for global variables (for instance, global
10636 register values and thread-local values).
10638 A location description containing no operations indicates that the
10639 object is optimized out. The return value is 0 for that case.
10640 FIXME drow/2003-11-16: No callers check for this case any more; soon all
10641 callers will only want a very basic result and this can become a
10644 Note that stack[0] is unused except as a default error return.
10645 Note that stack overflow is not yet handled. */
10648 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
10650 struct objfile
*objfile
= cu
->objfile
;
10651 struct comp_unit_head
*cu_header
= &cu
->header
;
10653 int size
= blk
->size
;
10654 gdb_byte
*data
= blk
->data
;
10655 CORE_ADDR stack
[64];
10657 unsigned int bytes_read
, unsnd
;
10701 stack
[++stacki
] = op
- DW_OP_lit0
;
10736 stack
[++stacki
] = op
- DW_OP_reg0
;
10738 dwarf2_complex_location_expr_complaint ();
10742 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
10744 stack
[++stacki
] = unsnd
;
10746 dwarf2_complex_location_expr_complaint ();
10750 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
10755 case DW_OP_const1u
:
10756 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
10760 case DW_OP_const1s
:
10761 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
10765 case DW_OP_const2u
:
10766 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
10770 case DW_OP_const2s
:
10771 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
10775 case DW_OP_const4u
:
10776 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
10780 case DW_OP_const4s
:
10781 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
10786 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
10792 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
10797 stack
[stacki
+ 1] = stack
[stacki
];
10802 stack
[stacki
- 1] += stack
[stacki
];
10806 case DW_OP_plus_uconst
:
10807 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
10812 stack
[stacki
- 1] -= stack
[stacki
];
10817 /* If we're not the last op, then we definitely can't encode
10818 this using GDB's address_class enum. This is valid for partial
10819 global symbols, although the variable's address will be bogus
10822 dwarf2_complex_location_expr_complaint ();
10825 case DW_OP_GNU_push_tls_address
:
10826 /* The top of the stack has the offset from the beginning
10827 of the thread control block at which the variable is located. */
10828 /* Nothing should follow this operator, so the top of stack would
10830 /* This is valid for partial global symbols, but the variable's
10831 address will be bogus in the psymtab. */
10833 dwarf2_complex_location_expr_complaint ();
10836 case DW_OP_GNU_uninit
:
10840 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
10841 dwarf_stack_op_name (op
));
10842 return (stack
[stacki
]);
10845 return (stack
[stacki
]);
10848 /* memory allocation interface */
10850 static struct dwarf_block
*
10851 dwarf_alloc_block (struct dwarf2_cu
*cu
)
10853 struct dwarf_block
*blk
;
10855 blk
= (struct dwarf_block
*)
10856 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
10860 static struct abbrev_info
*
10861 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
10863 struct abbrev_info
*abbrev
;
10865 abbrev
= (struct abbrev_info
*)
10866 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
10867 memset (abbrev
, 0, sizeof (struct abbrev_info
));
10871 static struct die_info
*
10872 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
10874 struct die_info
*die
;
10875 size_t size
= sizeof (struct die_info
);
10878 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
10880 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
10881 memset (die
, 0, sizeof (struct die_info
));
10886 /* Macro support. */
10889 /* Return the full name of file number I in *LH's file name table.
10890 Use COMP_DIR as the name of the current directory of the
10891 compilation. The result is allocated using xmalloc; the caller is
10892 responsible for freeing it. */
10894 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
10896 /* Is the file number a valid index into the line header's file name
10897 table? Remember that file numbers start with one, not zero. */
10898 if (1 <= file
&& file
<= lh
->num_file_names
)
10900 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10902 if (IS_ABSOLUTE_PATH (fe
->name
))
10903 return xstrdup (fe
->name
);
10911 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10917 dir_len
= strlen (dir
);
10918 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
10919 strcpy (full_name
, dir
);
10920 full_name
[dir_len
] = '/';
10921 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
10925 return xstrdup (fe
->name
);
10930 /* The compiler produced a bogus file number. We can at least
10931 record the macro definitions made in the file, even if we
10932 won't be able to find the file by name. */
10933 char fake_name
[80];
10934 sprintf (fake_name
, "<bad macro file number %d>", file
);
10936 complaint (&symfile_complaints
,
10937 _("bad file number in macro information (%d)"),
10940 return xstrdup (fake_name
);
10945 static struct macro_source_file
*
10946 macro_start_file (int file
, int line
,
10947 struct macro_source_file
*current_file
,
10948 const char *comp_dir
,
10949 struct line_header
*lh
, struct objfile
*objfile
)
10951 /* The full name of this source file. */
10952 char *full_name
= file_full_name (file
, lh
, comp_dir
);
10954 /* We don't create a macro table for this compilation unit
10955 at all until we actually get a filename. */
10956 if (! pending_macros
)
10957 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
10958 objfile
->macro_cache
);
10960 if (! current_file
)
10961 /* If we have no current file, then this must be the start_file
10962 directive for the compilation unit's main source file. */
10963 current_file
= macro_set_main (pending_macros
, full_name
);
10965 current_file
= macro_include (current_file
, line
, full_name
);
10969 return current_file
;
10973 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
10974 followed by a null byte. */
10976 copy_string (const char *buf
, int len
)
10978 char *s
= xmalloc (len
+ 1);
10979 memcpy (s
, buf
, len
);
10986 static const char *
10987 consume_improper_spaces (const char *p
, const char *body
)
10991 complaint (&symfile_complaints
,
10992 _("macro definition contains spaces in formal argument list:\n`%s'"),
11004 parse_macro_definition (struct macro_source_file
*file
, int line
,
11009 /* The body string takes one of two forms. For object-like macro
11010 definitions, it should be:
11012 <macro name> " " <definition>
11014 For function-like macro definitions, it should be:
11016 <macro name> "() " <definition>
11018 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
11020 Spaces may appear only where explicitly indicated, and in the
11023 The Dwarf 2 spec says that an object-like macro's name is always
11024 followed by a space, but versions of GCC around March 2002 omit
11025 the space when the macro's definition is the empty string.
11027 The Dwarf 2 spec says that there should be no spaces between the
11028 formal arguments in a function-like macro's formal argument list,
11029 but versions of GCC around March 2002 include spaces after the
11033 /* Find the extent of the macro name. The macro name is terminated
11034 by either a space or null character (for an object-like macro) or
11035 an opening paren (for a function-like macro). */
11036 for (p
= body
; *p
; p
++)
11037 if (*p
== ' ' || *p
== '(')
11040 if (*p
== ' ' || *p
== '\0')
11042 /* It's an object-like macro. */
11043 int name_len
= p
- body
;
11044 char *name
= copy_string (body
, name_len
);
11045 const char *replacement
;
11048 replacement
= body
+ name_len
+ 1;
11051 dwarf2_macro_malformed_definition_complaint (body
);
11052 replacement
= body
+ name_len
;
11055 macro_define_object (file
, line
, name
, replacement
);
11059 else if (*p
== '(')
11061 /* It's a function-like macro. */
11062 char *name
= copy_string (body
, p
- body
);
11065 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
11069 p
= consume_improper_spaces (p
, body
);
11071 /* Parse the formal argument list. */
11072 while (*p
&& *p
!= ')')
11074 /* Find the extent of the current argument name. */
11075 const char *arg_start
= p
;
11077 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
11080 if (! *p
|| p
== arg_start
)
11081 dwarf2_macro_malformed_definition_complaint (body
);
11084 /* Make sure argv has room for the new argument. */
11085 if (argc
>= argv_size
)
11088 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
11091 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
11094 p
= consume_improper_spaces (p
, body
);
11096 /* Consume the comma, if present. */
11101 p
= consume_improper_spaces (p
, body
);
11110 /* Perfectly formed definition, no complaints. */
11111 macro_define_function (file
, line
, name
,
11112 argc
, (const char **) argv
,
11114 else if (*p
== '\0')
11116 /* Complain, but do define it. */
11117 dwarf2_macro_malformed_definition_complaint (body
);
11118 macro_define_function (file
, line
, name
,
11119 argc
, (const char **) argv
,
11123 /* Just complain. */
11124 dwarf2_macro_malformed_definition_complaint (body
);
11127 /* Just complain. */
11128 dwarf2_macro_malformed_definition_complaint (body
);
11134 for (i
= 0; i
< argc
; i
++)
11140 dwarf2_macro_malformed_definition_complaint (body
);
11145 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
11146 char *comp_dir
, bfd
*abfd
,
11147 struct dwarf2_cu
*cu
)
11149 gdb_byte
*mac_ptr
, *mac_end
;
11150 struct macro_source_file
*current_file
= 0;
11151 enum dwarf_macinfo_record_type macinfo_type
;
11152 int at_commandline
;
11154 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
11156 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
11160 /* First pass: Find the name of the base filename.
11161 This filename is needed in order to process all macros whose definition
11162 (or undefinition) comes from the command line. These macros are defined
11163 before the first DW_MACINFO_start_file entry, and yet still need to be
11164 associated to the base file.
11166 To determine the base file name, we scan the macro definitions until we
11167 reach the first DW_MACINFO_start_file entry. We then initialize
11168 CURRENT_FILE accordingly so that any macro definition found before the
11169 first DW_MACINFO_start_file can still be associated to the base file. */
11171 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
11172 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
11173 + dwarf2_per_objfile
->macinfo
.size
;
11177 /* Do we at least have room for a macinfo type byte? */
11178 if (mac_ptr
>= mac_end
)
11180 /* Complaint is printed during the second pass as GDB will probably
11181 stop the first pass earlier upon finding DW_MACINFO_start_file. */
11185 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
11188 switch (macinfo_type
)
11190 /* A zero macinfo type indicates the end of the macro
11195 case DW_MACINFO_define
:
11196 case DW_MACINFO_undef
:
11197 /* Only skip the data by MAC_PTR. */
11199 unsigned int bytes_read
;
11201 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11202 mac_ptr
+= bytes_read
;
11203 read_string (abfd
, mac_ptr
, &bytes_read
);
11204 mac_ptr
+= bytes_read
;
11208 case DW_MACINFO_start_file
:
11210 unsigned int bytes_read
;
11213 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11214 mac_ptr
+= bytes_read
;
11215 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11216 mac_ptr
+= bytes_read
;
11218 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
11223 case DW_MACINFO_end_file
:
11224 /* No data to skip by MAC_PTR. */
11227 case DW_MACINFO_vendor_ext
:
11228 /* Only skip the data by MAC_PTR. */
11230 unsigned int bytes_read
;
11232 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11233 mac_ptr
+= bytes_read
;
11234 read_string (abfd
, mac_ptr
, &bytes_read
);
11235 mac_ptr
+= bytes_read
;
11242 } while (macinfo_type
!= 0 && current_file
== NULL
);
11244 /* Second pass: Process all entries.
11246 Use the AT_COMMAND_LINE flag to determine whether we are still processing
11247 command-line macro definitions/undefinitions. This flag is unset when we
11248 reach the first DW_MACINFO_start_file entry. */
11250 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
11252 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
11253 GDB is still reading the definitions from command line. First
11254 DW_MACINFO_start_file will need to be ignored as it was already executed
11255 to create CURRENT_FILE for the main source holding also the command line
11256 definitions. On first met DW_MACINFO_start_file this flag is reset to
11257 normally execute all the remaining DW_MACINFO_start_file macinfos. */
11259 at_commandline
= 1;
11263 /* Do we at least have room for a macinfo type byte? */
11264 if (mac_ptr
>= mac_end
)
11266 dwarf2_macros_too_long_complaint ();
11270 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
11273 switch (macinfo_type
)
11275 /* A zero macinfo type indicates the end of the macro
11280 case DW_MACINFO_define
:
11281 case DW_MACINFO_undef
:
11283 unsigned int bytes_read
;
11287 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11288 mac_ptr
+= bytes_read
;
11289 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
11290 mac_ptr
+= bytes_read
;
11292 if (! current_file
)
11294 /* DWARF violation as no main source is present. */
11295 complaint (&symfile_complaints
,
11296 _("debug info with no main source gives macro %s "
11298 macinfo_type
== DW_MACINFO_define
?
11300 macinfo_type
== DW_MACINFO_undef
?
11301 _("undefinition") :
11302 _("something-or-other"), line
, body
);
11305 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
11306 complaint (&symfile_complaints
,
11307 _("debug info gives %s macro %s with %s line %d: %s"),
11308 at_commandline
? _("command-line") : _("in-file"),
11309 macinfo_type
== DW_MACINFO_define
?
11311 macinfo_type
== DW_MACINFO_undef
?
11312 _("undefinition") :
11313 _("something-or-other"),
11314 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
11316 if (macinfo_type
== DW_MACINFO_define
)
11317 parse_macro_definition (current_file
, line
, body
);
11318 else if (macinfo_type
== DW_MACINFO_undef
)
11319 macro_undef (current_file
, line
, body
);
11323 case DW_MACINFO_start_file
:
11325 unsigned int bytes_read
;
11328 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11329 mac_ptr
+= bytes_read
;
11330 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11331 mac_ptr
+= bytes_read
;
11333 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
11334 complaint (&symfile_complaints
,
11335 _("debug info gives source %d included "
11336 "from %s at %s line %d"),
11337 file
, at_commandline
? _("command-line") : _("file"),
11338 line
== 0 ? _("zero") : _("non-zero"), line
);
11340 if (at_commandline
)
11342 /* This DW_MACINFO_start_file was executed in the pass one. */
11343 at_commandline
= 0;
11346 current_file
= macro_start_file (file
, line
,
11347 current_file
, comp_dir
,
11352 case DW_MACINFO_end_file
:
11353 if (! current_file
)
11354 complaint (&symfile_complaints
,
11355 _("macro debug info has an unmatched `close_file' directive"));
11358 current_file
= current_file
->included_by
;
11359 if (! current_file
)
11361 enum dwarf_macinfo_record_type next_type
;
11363 /* GCC circa March 2002 doesn't produce the zero
11364 type byte marking the end of the compilation
11365 unit. Complain if it's not there, but exit no
11368 /* Do we at least have room for a macinfo type byte? */
11369 if (mac_ptr
>= mac_end
)
11371 dwarf2_macros_too_long_complaint ();
11375 /* We don't increment mac_ptr here, so this is just
11377 next_type
= read_1_byte (abfd
, mac_ptr
);
11378 if (next_type
!= 0)
11379 complaint (&symfile_complaints
,
11380 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
11387 case DW_MACINFO_vendor_ext
:
11389 unsigned int bytes_read
;
11393 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11394 mac_ptr
+= bytes_read
;
11395 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
11396 mac_ptr
+= bytes_read
;
11398 /* We don't recognize any vendor extensions. */
11402 } while (macinfo_type
!= 0);
11405 /* Check if the attribute's form is a DW_FORM_block*
11406 if so return true else false. */
11408 attr_form_is_block (struct attribute
*attr
)
11410 return (attr
== NULL
? 0 :
11411 attr
->form
== DW_FORM_block1
11412 || attr
->form
== DW_FORM_block2
11413 || attr
->form
== DW_FORM_block4
11414 || attr
->form
== DW_FORM_block
);
11417 /* Return non-zero if ATTR's value is a section offset --- classes
11418 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
11419 You may use DW_UNSND (attr) to retrieve such offsets.
11421 Section 7.5.4, "Attribute Encodings", explains that no attribute
11422 may have a value that belongs to more than one of these classes; it
11423 would be ambiguous if we did, because we use the same forms for all
11426 attr_form_is_section_offset (struct attribute
*attr
)
11428 return (attr
->form
== DW_FORM_data4
11429 || attr
->form
== DW_FORM_data8
);
11433 /* Return non-zero if ATTR's value falls in the 'constant' class, or
11434 zero otherwise. When this function returns true, you can apply
11435 dwarf2_get_attr_constant_value to it.
11437 However, note that for some attributes you must check
11438 attr_form_is_section_offset before using this test. DW_FORM_data4
11439 and DW_FORM_data8 are members of both the constant class, and of
11440 the classes that contain offsets into other debug sections
11441 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
11442 that, if an attribute's can be either a constant or one of the
11443 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
11444 taken as section offsets, not constants. */
11446 attr_form_is_constant (struct attribute
*attr
)
11448 switch (attr
->form
)
11450 case DW_FORM_sdata
:
11451 case DW_FORM_udata
:
11452 case DW_FORM_data1
:
11453 case DW_FORM_data2
:
11454 case DW_FORM_data4
:
11455 case DW_FORM_data8
:
11463 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
11464 struct dwarf2_cu
*cu
)
11466 if (attr_form_is_section_offset (attr
)
11467 /* ".debug_loc" may not exist at all, or the offset may be outside
11468 the section. If so, fall through to the complaint in the
11470 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
11472 struct dwarf2_loclist_baton
*baton
;
11474 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
11475 sizeof (struct dwarf2_loclist_baton
));
11476 baton
->per_cu
= cu
->per_cu
;
11477 gdb_assert (baton
->per_cu
);
11479 /* We don't know how long the location list is, but make sure we
11480 don't run off the edge of the section. */
11481 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
11482 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
11483 baton
->base_address
= cu
->base_address
;
11484 if (cu
->base_known
== 0)
11485 complaint (&symfile_complaints
,
11486 _("Location list used without specifying the CU base address."));
11488 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
11489 SYMBOL_LOCATION_BATON (sym
) = baton
;
11493 struct dwarf2_locexpr_baton
*baton
;
11495 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
11496 sizeof (struct dwarf2_locexpr_baton
));
11497 baton
->per_cu
= cu
->per_cu
;
11498 gdb_assert (baton
->per_cu
);
11500 if (attr_form_is_block (attr
))
11502 /* Note that we're just copying the block's data pointer
11503 here, not the actual data. We're still pointing into the
11504 info_buffer for SYM's objfile; right now we never release
11505 that buffer, but when we do clean up properly this may
11507 baton
->size
= DW_BLOCK (attr
)->size
;
11508 baton
->data
= DW_BLOCK (attr
)->data
;
11512 dwarf2_invalid_attrib_class_complaint ("location description",
11513 SYMBOL_NATURAL_NAME (sym
));
11515 baton
->data
= NULL
;
11518 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11519 SYMBOL_LOCATION_BATON (sym
) = baton
;
11523 /* Return the OBJFILE associated with the compilation unit CU. */
11526 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
11528 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
11530 /* Return the master objfile, so that we can report and look up the
11531 correct file containing this variable. */
11532 if (objfile
->separate_debug_objfile_backlink
)
11533 objfile
= objfile
->separate_debug_objfile_backlink
;
11538 /* Return the address size given in the compilation unit header for CU. */
11541 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
11544 return per_cu
->cu
->header
.addr_size
;
11547 /* If the CU is not currently read in, we re-read its header. */
11548 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
11549 struct dwarf2_per_objfile
*per_objfile
11550 = objfile_data (objfile
, dwarf2_objfile_data_key
);
11551 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
11553 struct comp_unit_head cu_header
;
11554 memset (&cu_header
, 0, sizeof cu_header
);
11555 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
11556 return cu_header
.addr_size
;
11560 /* Locate the .debug_info compilation unit from CU's objfile which contains
11561 the DIE at OFFSET. Raises an error on failure. */
11563 static struct dwarf2_per_cu_data
*
11564 dwarf2_find_containing_comp_unit (unsigned int offset
,
11565 struct objfile
*objfile
)
11567 struct dwarf2_per_cu_data
*this_cu
;
11571 high
= dwarf2_per_objfile
->n_comp_units
- 1;
11574 int mid
= low
+ (high
- low
) / 2;
11575 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
11580 gdb_assert (low
== high
);
11581 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
11584 error (_("Dwarf Error: could not find partial DIE containing "
11585 "offset 0x%lx [in module %s]"),
11586 (long) offset
, bfd_get_filename (objfile
->obfd
));
11588 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
11589 return dwarf2_per_objfile
->all_comp_units
[low
-1];
11593 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
11594 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
11595 && offset
>= this_cu
->offset
+ this_cu
->length
)
11596 error (_("invalid dwarf2 offset %u"), offset
);
11597 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
11602 /* Locate the compilation unit from OBJFILE which is located at exactly
11603 OFFSET. Raises an error on failure. */
11605 static struct dwarf2_per_cu_data
*
11606 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
11608 struct dwarf2_per_cu_data
*this_cu
;
11609 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
11610 if (this_cu
->offset
!= offset
)
11611 error (_("no compilation unit with offset %u."), offset
);
11615 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
11617 static struct dwarf2_cu
*
11618 alloc_one_comp_unit (struct objfile
*objfile
)
11620 struct dwarf2_cu
*cu
= xcalloc (1, sizeof (struct dwarf2_cu
));
11621 cu
->objfile
= objfile
;
11622 obstack_init (&cu
->comp_unit_obstack
);
11626 /* Release one cached compilation unit, CU. We unlink it from the tree
11627 of compilation units, but we don't remove it from the read_in_chain;
11628 the caller is responsible for that.
11629 NOTE: DATA is a void * because this function is also used as a
11630 cleanup routine. */
11633 free_one_comp_unit (void *data
)
11635 struct dwarf2_cu
*cu
= data
;
11637 if (cu
->per_cu
!= NULL
)
11638 cu
->per_cu
->cu
= NULL
;
11641 obstack_free (&cu
->comp_unit_obstack
, NULL
);
11646 /* This cleanup function is passed the address of a dwarf2_cu on the stack
11647 when we're finished with it. We can't free the pointer itself, but be
11648 sure to unlink it from the cache. Also release any associated storage
11649 and perform cache maintenance.
11651 Only used during partial symbol parsing. */
11654 free_stack_comp_unit (void *data
)
11656 struct dwarf2_cu
*cu
= data
;
11658 obstack_free (&cu
->comp_unit_obstack
, NULL
);
11659 cu
->partial_dies
= NULL
;
11661 if (cu
->per_cu
!= NULL
)
11663 /* This compilation unit is on the stack in our caller, so we
11664 should not xfree it. Just unlink it. */
11665 cu
->per_cu
->cu
= NULL
;
11668 /* If we had a per-cu pointer, then we may have other compilation
11669 units loaded, so age them now. */
11670 age_cached_comp_units ();
11674 /* Free all cached compilation units. */
11677 free_cached_comp_units (void *data
)
11679 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11681 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11682 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11683 while (per_cu
!= NULL
)
11685 struct dwarf2_per_cu_data
*next_cu
;
11687 next_cu
= per_cu
->cu
->read_in_chain
;
11689 free_one_comp_unit (per_cu
->cu
);
11690 *last_chain
= next_cu
;
11696 /* Increase the age counter on each cached compilation unit, and free
11697 any that are too old. */
11700 age_cached_comp_units (void)
11702 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11704 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
11705 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11706 while (per_cu
!= NULL
)
11708 per_cu
->cu
->last_used
++;
11709 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
11710 dwarf2_mark (per_cu
->cu
);
11711 per_cu
= per_cu
->cu
->read_in_chain
;
11714 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11715 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11716 while (per_cu
!= NULL
)
11718 struct dwarf2_per_cu_data
*next_cu
;
11720 next_cu
= per_cu
->cu
->read_in_chain
;
11722 if (!per_cu
->cu
->mark
)
11724 free_one_comp_unit (per_cu
->cu
);
11725 *last_chain
= next_cu
;
11728 last_chain
= &per_cu
->cu
->read_in_chain
;
11734 /* Remove a single compilation unit from the cache. */
11737 free_one_cached_comp_unit (void *target_cu
)
11739 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11741 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11742 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11743 while (per_cu
!= NULL
)
11745 struct dwarf2_per_cu_data
*next_cu
;
11747 next_cu
= per_cu
->cu
->read_in_chain
;
11749 if (per_cu
->cu
== target_cu
)
11751 free_one_comp_unit (per_cu
->cu
);
11752 *last_chain
= next_cu
;
11756 last_chain
= &per_cu
->cu
->read_in_chain
;
11762 /* Release all extra memory associated with OBJFILE. */
11765 dwarf2_free_objfile (struct objfile
*objfile
)
11767 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
11769 if (dwarf2_per_objfile
== NULL
)
11772 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
11773 free_cached_comp_units (NULL
);
11775 /* Everything else should be on the objfile obstack. */
11778 /* A pair of DIE offset and GDB type pointer. We store these
11779 in a hash table separate from the DIEs, and preserve them
11780 when the DIEs are flushed out of cache. */
11782 struct dwarf2_offset_and_type
11784 unsigned int offset
;
11788 /* Hash function for a dwarf2_offset_and_type. */
11791 offset_and_type_hash (const void *item
)
11793 const struct dwarf2_offset_and_type
*ofs
= item
;
11794 return ofs
->offset
;
11797 /* Equality function for a dwarf2_offset_and_type. */
11800 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
11802 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
11803 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
11804 return ofs_lhs
->offset
== ofs_rhs
->offset
;
11807 /* Set the type associated with DIE to TYPE. Save it in CU's hash
11808 table if necessary. For convenience, return TYPE. */
11810 static struct type
*
11811 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11813 struct dwarf2_offset_and_type
**slot
, ofs
;
11815 /* For Ada types, make sure that the gnat-specific data is always
11816 initialized (if not already set). There are a few types where
11817 we should not be doing so, because the type-specific area is
11818 already used to hold some other piece of info (eg: TYPE_CODE_FLT
11819 where the type-specific area is used to store the floatformat).
11820 But this is not a problem, because the gnat-specific information
11821 is actually not needed for these types. */
11822 if (need_gnat_info (cu
)
11823 && TYPE_CODE (type
) != TYPE_CODE_FUNC
11824 && TYPE_CODE (type
) != TYPE_CODE_FLT
11825 && !HAVE_GNAT_AUX_INFO (type
))
11826 INIT_GNAT_SPECIFIC (type
);
11828 if (cu
->type_hash
== NULL
)
11830 gdb_assert (cu
->per_cu
!= NULL
);
11831 cu
->per_cu
->type_hash
11832 = htab_create_alloc_ex (cu
->header
.length
/ 24,
11833 offset_and_type_hash
,
11834 offset_and_type_eq
,
11836 &cu
->objfile
->objfile_obstack
,
11837 hashtab_obstack_allocate
,
11838 dummy_obstack_deallocate
);
11839 cu
->type_hash
= cu
->per_cu
->type_hash
;
11842 ofs
.offset
= die
->offset
;
11844 slot
= (struct dwarf2_offset_and_type
**)
11845 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
11846 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
11851 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
11852 not have a saved type. */
11854 static struct type
*
11855 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11857 struct dwarf2_offset_and_type
*slot
, ofs
;
11858 htab_t type_hash
= cu
->type_hash
;
11860 if (type_hash
== NULL
)
11863 ofs
.offset
= die
->offset
;
11864 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
11871 /* Add a dependence relationship from CU to REF_PER_CU. */
11874 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
11875 struct dwarf2_per_cu_data
*ref_per_cu
)
11879 if (cu
->dependencies
== NULL
)
11881 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
11882 NULL
, &cu
->comp_unit_obstack
,
11883 hashtab_obstack_allocate
,
11884 dummy_obstack_deallocate
);
11886 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
11888 *slot
= ref_per_cu
;
11891 /* Subroutine of dwarf2_mark to pass to htab_traverse.
11892 Set the mark field in every compilation unit in the
11893 cache that we must keep because we are keeping CU. */
11896 dwarf2_mark_helper (void **slot
, void *data
)
11898 struct dwarf2_per_cu_data
*per_cu
;
11900 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
11901 if (per_cu
->cu
->mark
)
11903 per_cu
->cu
->mark
= 1;
11905 if (per_cu
->cu
->dependencies
!= NULL
)
11906 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
11911 /* Set the mark field in CU and in every other compilation unit in the
11912 cache that we must keep because we are keeping CU. */
11915 dwarf2_mark (struct dwarf2_cu
*cu
)
11920 if (cu
->dependencies
!= NULL
)
11921 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
11925 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
11929 per_cu
->cu
->mark
= 0;
11930 per_cu
= per_cu
->cu
->read_in_chain
;
11934 /* Trivial hash function for partial_die_info: the hash value of a DIE
11935 is its offset in .debug_info for this objfile. */
11938 partial_die_hash (const void *item
)
11940 const struct partial_die_info
*part_die
= item
;
11941 return part_die
->offset
;
11944 /* Trivial comparison function for partial_die_info structures: two DIEs
11945 are equal if they have the same offset. */
11948 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
11950 const struct partial_die_info
*part_die_lhs
= item_lhs
;
11951 const struct partial_die_info
*part_die_rhs
= item_rhs
;
11952 return part_die_lhs
->offset
== part_die_rhs
->offset
;
11955 static struct cmd_list_element
*set_dwarf2_cmdlist
;
11956 static struct cmd_list_element
*show_dwarf2_cmdlist
;
11959 set_dwarf2_cmd (char *args
, int from_tty
)
11961 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
11965 show_dwarf2_cmd (char *args
, int from_tty
)
11967 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
11970 /* If section described by INFO was mmapped, munmap it now. */
11973 munmap_section_buffer (struct dwarf2_section_info
*info
)
11975 if (info
->was_mmapped
)
11978 intptr_t begin
= (intptr_t) info
->buffer
;
11979 intptr_t map_begin
= begin
& ~(pagesize
- 1);
11980 size_t map_length
= info
->size
+ begin
- map_begin
;
11981 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
11983 /* Without HAVE_MMAP, we should never be here to begin with. */
11989 /* munmap debug sections for OBJFILE, if necessary. */
11992 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
11994 struct dwarf2_per_objfile
*data
= d
;
11995 munmap_section_buffer (&data
->info
);
11996 munmap_section_buffer (&data
->abbrev
);
11997 munmap_section_buffer (&data
->line
);
11998 munmap_section_buffer (&data
->str
);
11999 munmap_section_buffer (&data
->macinfo
);
12000 munmap_section_buffer (&data
->ranges
);
12001 munmap_section_buffer (&data
->loc
);
12002 munmap_section_buffer (&data
->frame
);
12003 munmap_section_buffer (&data
->eh_frame
);
12006 void _initialize_dwarf2_read (void);
12009 _initialize_dwarf2_read (void)
12011 dwarf2_objfile_data_key
12012 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
12014 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
12015 Set DWARF 2 specific variables.\n\
12016 Configure DWARF 2 variables such as the cache size"),
12017 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
12018 0/*allow-unknown*/, &maintenance_set_cmdlist
);
12020 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
12021 Show DWARF 2 specific variables\n\
12022 Show DWARF 2 variables such as the cache size"),
12023 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
12024 0/*allow-unknown*/, &maintenance_show_cmdlist
);
12026 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
12027 &dwarf2_max_cache_age
, _("\
12028 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
12029 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
12030 A higher limit means that cached compilation units will be stored\n\
12031 in memory longer, and more total memory will be used. Zero disables\n\
12032 caching, which can slow down startup."),
12034 show_dwarf2_max_cache_age
,
12035 &set_dwarf2_cmdlist
,
12036 &show_dwarf2_cmdlist
);
12038 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
12039 Set debugging of the dwarf2 DIE reader."), _("\
12040 Show debugging of the dwarf2 DIE reader."), _("\
12041 When enabled (non-zero), DIEs are dumped after they are read in.\n\
12042 The value is the maximum depth to print."),
12045 &setdebuglist
, &showdebuglist
);