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"
53 #include "gdb_string.h"
54 #include "gdb_assert.h"
55 #include <sys/types.h>
62 #define MAP_FAILED ((void *) -1)
67 /* .debug_info header for a compilation unit
68 Because of alignment constraints, this structure has padding and cannot
69 be mapped directly onto the beginning of the .debug_info section. */
70 typedef struct comp_unit_header
72 unsigned int length
; /* length of the .debug_info
74 unsigned short version
; /* version number -- 2 for DWARF
76 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
77 unsigned char addr_size
; /* byte size of an address -- 4 */
80 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
83 /* .debug_pubnames header
84 Because of alignment constraints, this structure has padding and cannot
85 be mapped directly onto the beginning of the .debug_info section. */
86 typedef struct pubnames_header
88 unsigned int length
; /* length of the .debug_pubnames
90 unsigned char version
; /* version number -- 2 for DWARF
92 unsigned int info_offset
; /* offset into .debug_info section */
93 unsigned int info_size
; /* byte size of .debug_info section
97 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
99 /* .debug_pubnames header
100 Because of alignment constraints, this structure has padding and cannot
101 be mapped directly onto the beginning of the .debug_info section. */
102 typedef struct aranges_header
104 unsigned int length
; /* byte len of the .debug_aranges
106 unsigned short version
; /* version number -- 2 for DWARF
108 unsigned int info_offset
; /* offset into .debug_info section */
109 unsigned char addr_size
; /* byte size of an address */
110 unsigned char seg_size
; /* byte size of segment descriptor */
113 #define _ACTUAL_ARANGES_HEADER_SIZE 12
115 /* .debug_line statement program prologue
116 Because of alignment constraints, this structure has padding and cannot
117 be mapped directly onto the beginning of the .debug_info section. */
118 typedef struct statement_prologue
120 unsigned int total_length
; /* byte length of the statement
122 unsigned short version
; /* version number -- 2 for DWARF
124 unsigned int prologue_length
; /* # bytes between prologue &
126 unsigned char minimum_instruction_length
; /* byte size of
128 unsigned char default_is_stmt
; /* initial value of is_stmt
131 unsigned char line_range
;
132 unsigned char opcode_base
; /* number assigned to first special
134 unsigned char *standard_opcode_lengths
;
138 /* When non-zero, dump DIEs after they are read in. */
139 static int dwarf2_die_debug
= 0;
143 /* When set, the file that we're processing is known to have debugging
144 info for C++ namespaces. GCC 3.3.x did not produce this information,
145 but later versions do. */
147 static int processing_has_namespace_info
;
149 static const struct objfile_data
*dwarf2_objfile_data_key
;
151 struct dwarf2_section_info
159 struct dwarf2_per_objfile
161 struct dwarf2_section_info info
;
162 struct dwarf2_section_info abbrev
;
163 struct dwarf2_section_info line
;
164 struct dwarf2_section_info pubnames
;
165 struct dwarf2_section_info aranges
;
166 struct dwarf2_section_info loc
;
167 struct dwarf2_section_info macinfo
;
168 struct dwarf2_section_info str
;
169 struct dwarf2_section_info ranges
;
170 struct dwarf2_section_info types
;
171 struct dwarf2_section_info frame
;
172 struct dwarf2_section_info eh_frame
;
174 /* A list of all the compilation units. This is used to locate
175 the target compilation unit of a particular reference. */
176 struct dwarf2_per_cu_data
**all_comp_units
;
178 /* The number of compilation units in ALL_COMP_UNITS. */
181 /* A chain of compilation units that are currently read in, so that
182 they can be freed later. */
183 struct dwarf2_per_cu_data
*read_in_chain
;
185 /* A table mapping .debug_types signatures to its signatured_type entry.
186 This is NULL if the .debug_types section hasn't been read in yet. */
187 htab_t signatured_types
;
189 /* A flag indicating wether this objfile has a section loaded at a
191 int has_section_at_zero
;
194 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
196 /* names of the debugging sections */
198 /* Note that if the debugging section has been compressed, it might
199 have a name like .zdebug_info. */
201 #define INFO_SECTION "debug_info"
202 #define ABBREV_SECTION "debug_abbrev"
203 #define LINE_SECTION "debug_line"
204 #define PUBNAMES_SECTION "debug_pubnames"
205 #define ARANGES_SECTION "debug_aranges"
206 #define LOC_SECTION "debug_loc"
207 #define MACINFO_SECTION "debug_macinfo"
208 #define STR_SECTION "debug_str"
209 #define RANGES_SECTION "debug_ranges"
210 #define TYPES_SECTION "debug_types"
211 #define FRAME_SECTION "debug_frame"
212 #define EH_FRAME_SECTION "eh_frame"
214 /* local data types */
216 /* We hold several abbreviation tables in memory at the same time. */
217 #ifndef ABBREV_HASH_SIZE
218 #define ABBREV_HASH_SIZE 121
221 /* The data in a compilation unit header, after target2host
222 translation, looks like this. */
223 struct comp_unit_head
227 unsigned char addr_size
;
228 unsigned char signed_addr_p
;
229 unsigned int abbrev_offset
;
231 /* Size of file offsets; either 4 or 8. */
232 unsigned int offset_size
;
234 /* Size of the length field; either 4 or 12. */
235 unsigned int initial_length_size
;
237 /* Offset to the first byte of this compilation unit header in the
238 .debug_info section, for resolving relative reference dies. */
241 /* Offset to first die in this cu from the start of the cu.
242 This will be the first byte following the compilation unit header. */
243 unsigned int first_die_offset
;
246 /* Internal state when decoding a particular compilation unit. */
249 /* The objfile containing this compilation unit. */
250 struct objfile
*objfile
;
252 /* The header of the compilation unit. */
253 struct comp_unit_head header
;
255 /* Base address of this compilation unit. */
256 CORE_ADDR base_address
;
258 /* Non-zero if base_address has been set. */
261 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
263 /* The language we are debugging. */
264 enum language language
;
265 const struct language_defn
*language_defn
;
267 const char *producer
;
269 /* The generic symbol table building routines have separate lists for
270 file scope symbols and all all other scopes (local scopes). So
271 we need to select the right one to pass to add_symbol_to_list().
272 We do it by keeping a pointer to the correct list in list_in_scope.
274 FIXME: The original dwarf code just treated the file scope as the
275 first local scope, and all other local scopes as nested local
276 scopes, and worked fine. Check to see if we really need to
277 distinguish these in buildsym.c. */
278 struct pending
**list_in_scope
;
280 /* DWARF abbreviation table associated with this compilation unit. */
281 struct abbrev_info
**dwarf2_abbrevs
;
283 /* Storage for the abbrev table. */
284 struct obstack abbrev_obstack
;
286 /* Hash table holding all the loaded partial DIEs. */
289 /* Storage for things with the same lifetime as this read-in compilation
290 unit, including partial DIEs. */
291 struct obstack comp_unit_obstack
;
293 /* When multiple dwarf2_cu structures are living in memory, this field
294 chains them all together, so that they can be released efficiently.
295 We will probably also want a generation counter so that most-recently-used
296 compilation units are cached... */
297 struct dwarf2_per_cu_data
*read_in_chain
;
299 /* Backchain to our per_cu entry if the tree has been built. */
300 struct dwarf2_per_cu_data
*per_cu
;
302 /* Pointer to the die -> type map. Although it is stored
303 permanently in per_cu, we copy it here to avoid double
307 /* How many compilation units ago was this CU last referenced? */
310 /* A hash table of die offsets for following references. */
313 /* Full DIEs if read in. */
314 struct die_info
*dies
;
316 /* A set of pointers to dwarf2_per_cu_data objects for compilation
317 units referenced by this one. Only set during full symbol processing;
318 partial symbol tables do not have dependencies. */
321 /* Header data from the line table, during full symbol processing. */
322 struct line_header
*line_header
;
324 /* Mark used when releasing cached dies. */
325 unsigned int mark
: 1;
327 /* This flag will be set if this compilation unit might include
328 inter-compilation-unit references. */
329 unsigned int has_form_ref_addr
: 1;
331 /* This flag will be set if this compilation unit includes any
332 DW_TAG_namespace DIEs. If we know that there are explicit
333 DIEs for namespaces, we don't need to try to infer them
334 from mangled names. */
335 unsigned int has_namespace_info
: 1;
338 /* Persistent data held for a compilation unit, even when not
339 processing it. We put a pointer to this structure in the
340 read_symtab_private field of the psymtab. If we encounter
341 inter-compilation-unit references, we also maintain a sorted
342 list of all compilation units. */
344 struct dwarf2_per_cu_data
346 /* The start offset and length of this compilation unit. 2**29-1
347 bytes should suffice to store the length of any compilation unit
348 - if it doesn't, GDB will fall over anyway.
349 NOTE: Unlike comp_unit_head.length, this length includes
350 initial_length_size. */
352 unsigned int length
: 29;
354 /* Flag indicating this compilation unit will be read in before
355 any of the current compilation units are processed. */
356 unsigned int queued
: 1;
358 /* This flag will be set if we need to load absolutely all DIEs
359 for this compilation unit, instead of just the ones we think
360 are interesting. It gets set if we look for a DIE in the
361 hash table and don't find it. */
362 unsigned int load_all_dies
: 1;
364 /* Non-zero if this CU is from .debug_types.
365 Otherwise it's from .debug_info. */
366 unsigned int from_debug_types
: 1;
368 /* Set iff currently read in. */
369 struct dwarf2_cu
*cu
;
371 /* If full symbols for this CU have been read in, then this field
372 holds a map of DIE offsets to types. It isn't always possible
373 to reconstruct this information later, so we have to preserve
377 /* The partial symbol table associated with this compilation unit,
378 or NULL for partial units (which do not have an associated
380 struct partial_symtab
*psymtab
;
383 /* Entry in the signatured_types hash table. */
385 struct signatured_type
389 /* Offset in .debug_types of the TU (type_unit) for this type. */
392 /* Offset in .debug_types of the type defined by this TU. */
393 unsigned int type_offset
;
395 /* The CU(/TU) of this type. */
396 struct dwarf2_per_cu_data per_cu
;
399 /* Struct used to pass misc. parameters to read_die_and_children, et. al.
400 which are used for both .debug_info and .debug_types dies.
401 All parameters here are unchanging for the life of the call.
402 This struct exists to abstract away the constant parameters of
405 struct die_reader_specs
407 /* The bfd of this objfile. */
410 /* The CU of the DIE we are parsing. */
411 struct dwarf2_cu
*cu
;
413 /* Pointer to start of section buffer.
414 This is either the start of .debug_info or .debug_types. */
415 const gdb_byte
*buffer
;
418 /* The line number information for a compilation unit (found in the
419 .debug_line section) begins with a "statement program header",
420 which contains the following information. */
423 unsigned int total_length
;
424 unsigned short version
;
425 unsigned int header_length
;
426 unsigned char minimum_instruction_length
;
427 unsigned char default_is_stmt
;
429 unsigned char line_range
;
430 unsigned char opcode_base
;
432 /* standard_opcode_lengths[i] is the number of operands for the
433 standard opcode whose value is i. This means that
434 standard_opcode_lengths[0] is unused, and the last meaningful
435 element is standard_opcode_lengths[opcode_base - 1]. */
436 unsigned char *standard_opcode_lengths
;
438 /* The include_directories table. NOTE! These strings are not
439 allocated with xmalloc; instead, they are pointers into
440 debug_line_buffer. If you try to free them, `free' will get
442 unsigned int num_include_dirs
, include_dirs_size
;
445 /* The file_names table. NOTE! These strings are not allocated
446 with xmalloc; instead, they are pointers into debug_line_buffer.
447 Don't try to free them directly. */
448 unsigned int num_file_names
, file_names_size
;
452 unsigned int dir_index
;
453 unsigned int mod_time
;
455 int included_p
; /* Non-zero if referenced by the Line Number Program. */
456 struct symtab
*symtab
; /* The associated symbol table, if any. */
459 /* The start and end of the statement program following this
460 header. These point into dwarf2_per_objfile->line_buffer. */
461 gdb_byte
*statement_program_start
, *statement_program_end
;
464 /* When we construct a partial symbol table entry we only
465 need this much information. */
466 struct partial_die_info
468 /* Offset of this DIE. */
471 /* DWARF-2 tag for this DIE. */
472 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
474 /* Assorted flags describing the data found in this DIE. */
475 unsigned int has_children
: 1;
476 unsigned int is_external
: 1;
477 unsigned int is_declaration
: 1;
478 unsigned int has_type
: 1;
479 unsigned int has_specification
: 1;
480 unsigned int has_pc_info
: 1;
482 /* Flag set if the SCOPE field of this structure has been
484 unsigned int scope_set
: 1;
486 /* Flag set if the DIE has a byte_size attribute. */
487 unsigned int has_byte_size
: 1;
489 /* The name of this DIE. Normally the value of DW_AT_name, but
490 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
494 /* The scope to prepend to our children. This is generally
495 allocated on the comp_unit_obstack, so will disappear
496 when this compilation unit leaves the cache. */
499 /* The location description associated with this DIE, if any. */
500 struct dwarf_block
*locdesc
;
502 /* If HAS_PC_INFO, the PC range associated with this DIE. */
506 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
507 DW_AT_sibling, if any. */
510 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
511 DW_AT_specification (or DW_AT_abstract_origin or
513 unsigned int spec_offset
;
515 /* Pointers to this DIE's parent, first child, and next sibling,
517 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
520 /* This data structure holds the information of an abbrev. */
523 unsigned int number
; /* number identifying abbrev */
524 enum dwarf_tag tag
; /* dwarf tag */
525 unsigned short has_children
; /* boolean */
526 unsigned short num_attrs
; /* number of attributes */
527 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
528 struct abbrev_info
*next
; /* next in chain */
533 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
534 ENUM_BITFIELD(dwarf_form
) form
: 16;
537 /* Attributes have a name and a value */
540 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
541 ENUM_BITFIELD(dwarf_form
) form
: 15;
543 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
544 field should be in u.str (existing only for DW_STRING) but it is kept
545 here for better struct attribute alignment. */
546 unsigned int string_is_canonical
: 1;
551 struct dwarf_block
*blk
;
555 struct signatured_type
*signatured_type
;
560 /* This data structure holds a complete die structure. */
563 /* DWARF-2 tag for this DIE. */
564 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
566 /* Number of attributes */
567 unsigned short num_attrs
;
572 /* Offset in .debug_info or .debug_types section. */
575 /* The dies in a compilation unit form an n-ary tree. PARENT
576 points to this die's parent; CHILD points to the first child of
577 this node; and all the children of a given node are chained
578 together via their SIBLING fields, terminated by a die whose
580 struct die_info
*child
; /* Its first child, if any. */
581 struct die_info
*sibling
; /* Its next sibling, if any. */
582 struct die_info
*parent
; /* Its parent, if any. */
584 /* An array of attributes, with NUM_ATTRS elements. There may be
585 zero, but it's not common and zero-sized arrays are not
586 sufficiently portable C. */
587 struct attribute attrs
[1];
590 struct function_range
593 CORE_ADDR lowpc
, highpc
;
595 struct function_range
*next
;
598 /* Get at parts of an attribute structure */
600 #define DW_STRING(attr) ((attr)->u.str)
601 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
602 #define DW_UNSND(attr) ((attr)->u.unsnd)
603 #define DW_BLOCK(attr) ((attr)->u.blk)
604 #define DW_SND(attr) ((attr)->u.snd)
605 #define DW_ADDR(attr) ((attr)->u.addr)
606 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
608 /* Blocks are a bunch of untyped bytes. */
615 #ifndef ATTR_ALLOC_CHUNK
616 #define ATTR_ALLOC_CHUNK 4
619 /* Allocate fields for structs, unions and enums in this size. */
620 #ifndef DW_FIELD_ALLOC_CHUNK
621 #define DW_FIELD_ALLOC_CHUNK 4
624 /* A zeroed version of a partial die for initialization purposes. */
625 static struct partial_die_info zeroed_partial_die
;
627 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
628 but this would require a corresponding change in unpack_field_as_long
630 static int bits_per_byte
= 8;
632 /* The routines that read and process dies for a C struct or C++ class
633 pass lists of data member fields and lists of member function fields
634 in an instance of a field_info structure, as defined below. */
637 /* List of data member and baseclasses fields. */
640 struct nextfield
*next
;
645 *fields
, *baseclasses
;
647 /* Number of fields (including baseclasses). */
650 /* Number of baseclasses. */
653 /* Set if the accesibility of one of the fields is not public. */
654 int non_public_fields
;
656 /* Member function fields array, entries are allocated in the order they
657 are encountered in the object file. */
660 struct nextfnfield
*next
;
661 struct fn_field fnfield
;
665 /* Member function fieldlist array, contains name of possibly overloaded
666 member function, number of overloaded member functions and a pointer
667 to the head of the member function field chain. */
672 struct nextfnfield
*head
;
676 /* Number of entries in the fnfieldlists array. */
680 /* One item on the queue of compilation units to read in full symbols
682 struct dwarf2_queue_item
684 struct dwarf2_per_cu_data
*per_cu
;
685 struct dwarf2_queue_item
*next
;
688 /* The current queue. */
689 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
691 /* Loaded secondary compilation units are kept in memory until they
692 have not been referenced for the processing of this many
693 compilation units. Set this to zero to disable caching. Cache
694 sizes of up to at least twenty will improve startup time for
695 typical inter-CU-reference binaries, at an obvious memory cost. */
696 static int dwarf2_max_cache_age
= 5;
698 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
699 struct cmd_list_element
*c
, const char *value
)
701 fprintf_filtered (file
, _("\
702 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
707 /* Various complaints about symbol reading that don't abort the process */
710 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
712 complaint (&symfile_complaints
,
713 _("statement list doesn't fit in .debug_line section"));
717 dwarf2_debug_line_missing_file_complaint (void)
719 complaint (&symfile_complaints
,
720 _(".debug_line section has line data without a file"));
724 dwarf2_debug_line_missing_end_sequence_complaint (void)
726 complaint (&symfile_complaints
,
727 _(".debug_line section has line program sequence without an end"));
731 dwarf2_complex_location_expr_complaint (void)
733 complaint (&symfile_complaints
, _("location expression too complex"));
737 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
740 complaint (&symfile_complaints
,
741 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
746 dwarf2_macros_too_long_complaint (void)
748 complaint (&symfile_complaints
,
749 _("macro info runs off end of `.debug_macinfo' section"));
753 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
755 complaint (&symfile_complaints
,
756 _("macro debug info contains a malformed macro definition:\n`%s'"),
761 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
763 complaint (&symfile_complaints
,
764 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
767 /* local function prototypes */
769 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
772 static void dwarf2_build_psymtabs_easy (struct objfile
*);
775 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
778 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
780 struct partial_symtab
*);
782 static void dwarf2_build_psymtabs_hard (struct objfile
*);
784 static void scan_partial_symbols (struct partial_die_info
*,
785 CORE_ADDR
*, CORE_ADDR
*,
786 int, struct dwarf2_cu
*);
788 static void add_partial_symbol (struct partial_die_info
*,
791 static int pdi_needs_namespace (enum dwarf_tag tag
);
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 const char *determine_class_name (struct die_info
*die
,
988 struct dwarf2_cu
*cu
);
990 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
992 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
994 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
996 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
998 static const char *namespace_name (struct die_info
*die
,
999 int *is_anonymous
, struct dwarf2_cu
*);
1001 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1003 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1005 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1006 struct dwarf2_cu
*);
1008 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1010 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1012 gdb_byte
**new_info_ptr
,
1013 struct die_info
*parent
);
1015 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1017 gdb_byte
**new_info_ptr
,
1018 struct die_info
*parent
);
1020 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1022 gdb_byte
**new_info_ptr
,
1023 struct die_info
*parent
);
1025 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1026 struct die_info
**, gdb_byte
*,
1029 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1031 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
1033 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1036 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1038 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1039 struct dwarf2_cu
**);
1041 static char *dwarf_tag_name (unsigned int);
1043 static char *dwarf_attr_name (unsigned int);
1045 static char *dwarf_form_name (unsigned int);
1047 static char *dwarf_stack_op_name (unsigned int);
1049 static char *dwarf_bool_name (unsigned int);
1051 static char *dwarf_type_encoding_name (unsigned int);
1054 static char *dwarf_cfi_name (unsigned int);
1057 static struct die_info
*sibling_die (struct die_info
*);
1059 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1061 static void dump_die_for_error (struct die_info
*);
1063 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1066 /*static*/ void dump_die (struct die_info
*, int max_level
);
1068 static void store_in_ref_table (struct die_info
*,
1069 struct dwarf2_cu
*);
1071 static int is_ref_attr (struct attribute
*);
1073 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1075 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1077 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1079 struct dwarf2_cu
**);
1081 static struct die_info
*follow_die_ref (struct die_info
*,
1083 struct dwarf2_cu
**);
1085 static struct die_info
*follow_die_sig (struct die_info
*,
1087 struct dwarf2_cu
**);
1089 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1090 unsigned int offset
);
1092 static void read_signatured_type (struct objfile
*,
1093 struct signatured_type
*type_sig
);
1095 /* memory allocation interface */
1097 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1099 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1101 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1103 static void initialize_cu_func_list (struct dwarf2_cu
*);
1105 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1106 struct dwarf2_cu
*);
1108 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1109 char *, bfd
*, struct dwarf2_cu
*);
1111 static int attr_form_is_block (struct attribute
*);
1113 static int attr_form_is_section_offset (struct attribute
*);
1115 static int attr_form_is_constant (struct attribute
*);
1117 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1119 struct dwarf2_cu
*cu
);
1121 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1122 struct abbrev_info
*abbrev
,
1123 struct dwarf2_cu
*cu
);
1125 static void free_stack_comp_unit (void *);
1127 static hashval_t
partial_die_hash (const void *item
);
1129 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1131 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1132 (unsigned int offset
, struct objfile
*objfile
);
1134 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1135 (unsigned int offset
, struct objfile
*objfile
);
1137 static struct dwarf2_cu
*alloc_one_comp_unit (struct objfile
*objfile
);
1139 static void free_one_comp_unit (void *);
1141 static void free_cached_comp_units (void *);
1143 static void age_cached_comp_units (void);
1145 static void free_one_cached_comp_unit (void *);
1147 static struct type
*set_die_type (struct die_info
*, struct type
*,
1148 struct dwarf2_cu
*);
1150 static void create_all_comp_units (struct objfile
*);
1152 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1155 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1157 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1158 struct dwarf2_per_cu_data
*);
1160 static void dwarf2_mark (struct dwarf2_cu
*);
1162 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1164 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1166 /* Try to locate the sections we need for DWARF 2 debugging
1167 information and return true if we have enough to do something. */
1170 dwarf2_has_info (struct objfile
*objfile
)
1172 struct dwarf2_per_objfile
*data
;
1174 /* Initialize per-objfile state. */
1175 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1176 memset (data
, 0, sizeof (*data
));
1177 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1178 dwarf2_per_objfile
= data
;
1180 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1181 return (data
->info
.asection
!= NULL
&& data
->abbrev
.asection
!= NULL
);
1184 /* When loading sections, we can either look for ".<name>", or for
1185 * ".z<name>", which indicates a compressed section. */
1188 section_is_p (const char *section_name
, const char *name
)
1190 return (section_name
[0] == '.'
1191 && (strcmp (section_name
+ 1, name
) == 0
1192 || (section_name
[1] == 'z'
1193 && strcmp (section_name
+ 2, name
) == 0)));
1196 /* This function is mapped across the sections and remembers the
1197 offset and size of each of the debugging sections we are interested
1201 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1203 if (section_is_p (sectp
->name
, INFO_SECTION
))
1205 dwarf2_per_objfile
->info
.asection
= sectp
;
1206 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1208 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1210 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1211 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1213 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1215 dwarf2_per_objfile
->line
.asection
= sectp
;
1216 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1218 else if (section_is_p (sectp
->name
, PUBNAMES_SECTION
))
1220 dwarf2_per_objfile
->pubnames
.asection
= sectp
;
1221 dwarf2_per_objfile
->pubnames
.size
= bfd_get_section_size (sectp
);
1223 else if (section_is_p (sectp
->name
, ARANGES_SECTION
))
1225 dwarf2_per_objfile
->aranges
.asection
= sectp
;
1226 dwarf2_per_objfile
->aranges
.size
= bfd_get_section_size (sectp
);
1228 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1230 dwarf2_per_objfile
->loc
.asection
= sectp
;
1231 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1233 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1235 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1236 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1238 else if (section_is_p (sectp
->name
, STR_SECTION
))
1240 dwarf2_per_objfile
->str
.asection
= sectp
;
1241 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1243 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1245 dwarf2_per_objfile
->frame
.asection
= sectp
;
1246 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1248 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1250 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1251 if (aflag
& SEC_HAS_CONTENTS
)
1253 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1254 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1257 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1259 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1260 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1262 else if (section_is_p (sectp
->name
, TYPES_SECTION
))
1264 dwarf2_per_objfile
->types
.asection
= sectp
;
1265 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1268 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1269 && bfd_section_vma (abfd
, sectp
) == 0)
1270 dwarf2_per_objfile
->has_section_at_zero
= 1;
1273 /* Decompress a section that was compressed using zlib. Store the
1274 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1277 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1278 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1280 bfd
*abfd
= objfile
->obfd
;
1282 error (_("Support for zlib-compressed DWARF data (from '%s') "
1283 "is disabled in this copy of GDB"),
1284 bfd_get_filename (abfd
));
1286 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1287 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1288 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1289 bfd_size_type uncompressed_size
;
1290 gdb_byte
*uncompressed_buffer
;
1293 int header_size
= 12;
1295 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1296 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
1297 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1298 bfd_get_filename (abfd
));
1300 /* Read the zlib header. In this case, it should be "ZLIB" followed
1301 by the uncompressed section size, 8 bytes in big-endian order. */
1302 if (compressed_size
< header_size
1303 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1304 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1305 bfd_get_filename (abfd
));
1306 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1307 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1308 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1309 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1310 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1311 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1312 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1313 uncompressed_size
+= compressed_buffer
[11];
1315 /* It is possible the section consists of several compressed
1316 buffers concatenated together, so we uncompress in a loop. */
1320 strm
.avail_in
= compressed_size
- header_size
;
1321 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1322 strm
.avail_out
= uncompressed_size
;
1323 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1325 rc
= inflateInit (&strm
);
1326 while (strm
.avail_in
> 0)
1329 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1330 bfd_get_filename (abfd
), rc
);
1331 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1332 + (uncompressed_size
- strm
.avail_out
));
1333 rc
= inflate (&strm
, Z_FINISH
);
1334 if (rc
!= Z_STREAM_END
)
1335 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1336 bfd_get_filename (abfd
), rc
);
1337 rc
= inflateReset (&strm
);
1339 rc
= inflateEnd (&strm
);
1341 || strm
.avail_out
!= 0)
1342 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1343 bfd_get_filename (abfd
), rc
);
1345 do_cleanups (cleanup
);
1346 *outbuf
= uncompressed_buffer
;
1347 *outsize
= uncompressed_size
;
1351 /* Read the contents of the section SECTP from object file specified by
1352 OBJFILE, store info about the section into INFO.
1353 If the section is compressed, uncompress it before returning. */
1356 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1358 bfd
*abfd
= objfile
->obfd
;
1359 asection
*sectp
= info
->asection
;
1360 gdb_byte
*buf
, *retbuf
;
1361 unsigned char header
[4];
1363 info
->buffer
= NULL
;
1364 info
->was_mmapped
= 0;
1366 if (info
->asection
== NULL
|| info
->size
== 0)
1369 /* Check if the file has a 4-byte header indicating compression. */
1370 if (info
->size
> sizeof (header
)
1371 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1372 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1374 /* Upon decompression, update the buffer and its size. */
1375 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1377 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1385 pagesize
= getpagesize ();
1387 /* Only try to mmap sections which are large enough: we don't want to
1388 waste space due to fragmentation. Also, only try mmap for sections
1389 without relocations. */
1391 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1393 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1394 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1395 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1396 MAP_PRIVATE
, pg_offset
);
1398 if (retbuf
!= MAP_FAILED
)
1400 info
->was_mmapped
= 1;
1401 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1407 /* If we get here, we are a normal, not-compressed section. */
1409 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1411 /* When debugging .o files, we may need to apply relocations; see
1412 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1413 We never compress sections in .o files, so we only need to
1414 try this when the section is not compressed. */
1415 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
1418 info
->buffer
= retbuf
;
1422 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1423 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1424 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1425 bfd_get_filename (abfd
));
1428 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1432 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1433 asection
**sectp
, gdb_byte
**bufp
,
1434 bfd_size_type
*sizep
)
1436 struct dwarf2_per_objfile
*data
1437 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1438 struct dwarf2_section_info
*info
;
1439 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1440 info
= &data
->eh_frame
;
1441 else if (section_is_p (section_name
, FRAME_SECTION
))
1442 info
= &data
->frame
;
1446 if (info
->asection
!= NULL
&& info
->size
!= 0 && info
->buffer
== NULL
)
1447 /* We haven't read this section in yet. Do it now. */
1448 dwarf2_read_section (objfile
, info
);
1450 *sectp
= info
->asection
;
1451 *bufp
= info
->buffer
;
1452 *sizep
= info
->size
;
1455 /* Build a partial symbol table. */
1458 dwarf2_build_psymtabs (struct objfile
*objfile
)
1460 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
1461 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->abbrev
);
1462 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->line
);
1463 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->str
);
1464 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->macinfo
);
1465 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
1466 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
1467 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->loc
);
1468 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->eh_frame
);
1469 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->frame
);
1471 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
1473 init_psymbol_list (objfile
, 1024);
1477 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1479 /* Things are significantly easier if we have .debug_aranges and
1480 .debug_pubnames sections */
1482 dwarf2_build_psymtabs_easy (objfile
);
1486 /* only test this case for now */
1488 /* In this case we have to work a bit harder */
1489 dwarf2_build_psymtabs_hard (objfile
);
1494 /* Build the partial symbol table from the information in the
1495 .debug_pubnames and .debug_aranges sections. */
1498 dwarf2_build_psymtabs_easy (struct objfile
*objfile
)
1500 bfd
*abfd
= objfile
->obfd
;
1501 char *aranges_buffer
, *pubnames_buffer
;
1502 char *aranges_ptr
, *pubnames_ptr
;
1503 unsigned int entry_length
, version
, info_offset
, info_size
;
1505 pubnames_buffer
= dwarf2_read_section (objfile
,
1506 dwarf_pubnames_section
);
1507 pubnames_ptr
= pubnames_buffer
;
1508 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames
.size
)
1510 unsigned int bytes_read
;
1512 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &bytes_read
);
1513 pubnames_ptr
+= bytes_read
;
1514 version
= read_1_byte (abfd
, pubnames_ptr
);
1516 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1518 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1522 aranges_buffer
= dwarf2_read_section (objfile
,
1523 dwarf_aranges_section
);
1528 /* Return TRUE if OFFSET is within CU_HEADER. */
1531 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
1533 unsigned int bottom
= cu_header
->offset
;
1534 unsigned int top
= (cu_header
->offset
1536 + cu_header
->initial_length_size
);
1537 return (offset
>= bottom
&& offset
< top
);
1540 /* Read in the comp unit header information from the debug_info at info_ptr.
1541 NOTE: This leaves members offset, first_die_offset to be filled in
1545 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1546 gdb_byte
*info_ptr
, bfd
*abfd
)
1549 unsigned int bytes_read
;
1551 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
1552 cu_header
->initial_length_size
= bytes_read
;
1553 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
1554 info_ptr
+= bytes_read
;
1555 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1557 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1559 info_ptr
+= bytes_read
;
1560 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1562 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1563 if (signed_addr
< 0)
1564 internal_error (__FILE__
, __LINE__
,
1565 _("read_comp_unit_head: dwarf from non elf file"));
1566 cu_header
->signed_addr_p
= signed_addr
;
1572 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1573 gdb_byte
*buffer
, unsigned int buffer_size
,
1576 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1578 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1580 if (header
->version
!= 2 && header
->version
!= 3)
1581 error (_("Dwarf Error: wrong version in compilation unit header "
1582 "(is %d, should be %d) [in module %s]"), header
->version
,
1583 2, bfd_get_filename (abfd
));
1585 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
1586 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1587 "(offset 0x%lx + 6) [in module %s]"),
1588 (long) header
->abbrev_offset
,
1589 (long) (beg_of_comp_unit
- buffer
),
1590 bfd_get_filename (abfd
));
1592 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1593 > buffer
+ buffer_size
)
1594 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1595 "(offset 0x%lx + 0) [in module %s]"),
1596 (long) header
->length
,
1597 (long) (beg_of_comp_unit
- buffer
),
1598 bfd_get_filename (abfd
));
1603 /* Read in the types comp unit header information from .debug_types entry at
1604 types_ptr. The result is a pointer to one past the end of the header. */
1607 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
1608 ULONGEST
*signature
,
1609 gdb_byte
*types_ptr
, bfd
*abfd
)
1611 unsigned int bytes_read
;
1612 gdb_byte
*initial_types_ptr
= types_ptr
;
1614 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
1616 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
1618 *signature
= read_8_bytes (abfd
, types_ptr
);
1620 types_ptr
+= cu_header
->offset_size
;
1621 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
1626 /* Allocate a new partial symtab for file named NAME and mark this new
1627 partial symtab as being an include of PST. */
1630 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1631 struct objfile
*objfile
)
1633 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1635 subpst
->section_offsets
= pst
->section_offsets
;
1636 subpst
->textlow
= 0;
1637 subpst
->texthigh
= 0;
1639 subpst
->dependencies
= (struct partial_symtab
**)
1640 obstack_alloc (&objfile
->objfile_obstack
,
1641 sizeof (struct partial_symtab
*));
1642 subpst
->dependencies
[0] = pst
;
1643 subpst
->number_of_dependencies
= 1;
1645 subpst
->globals_offset
= 0;
1646 subpst
->n_global_syms
= 0;
1647 subpst
->statics_offset
= 0;
1648 subpst
->n_static_syms
= 0;
1649 subpst
->symtab
= NULL
;
1650 subpst
->read_symtab
= pst
->read_symtab
;
1653 /* No private part is necessary for include psymtabs. This property
1654 can be used to differentiate between such include psymtabs and
1655 the regular ones. */
1656 subpst
->read_symtab_private
= NULL
;
1659 /* Read the Line Number Program data and extract the list of files
1660 included by the source file represented by PST. Build an include
1661 partial symtab for each of these included files. */
1664 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1665 struct die_info
*die
,
1666 struct partial_symtab
*pst
)
1668 struct objfile
*objfile
= cu
->objfile
;
1669 bfd
*abfd
= objfile
->obfd
;
1670 struct line_header
*lh
= NULL
;
1671 struct attribute
*attr
;
1673 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
1676 unsigned int line_offset
= DW_UNSND (attr
);
1677 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
1680 return; /* No linetable, so no includes. */
1682 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1684 free_line_header (lh
);
1688 hash_type_signature (const void *item
)
1690 const struct signatured_type
*type_sig
= item
;
1691 /* This drops the top 32 bits of the signature, but is ok for a hash. */
1692 return type_sig
->signature
;
1696 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
1698 const struct signatured_type
*lhs
= item_lhs
;
1699 const struct signatured_type
*rhs
= item_rhs
;
1700 return lhs
->signature
== rhs
->signature
;
1703 /* Create the hash table of all entries in the .debug_types section.
1704 The result is zero if there is an error (e.g. missing .debug_types section),
1705 otherwise non-zero. */
1708 create_debug_types_hash_table (struct objfile
*objfile
)
1710 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
;
1713 if (info_ptr
== NULL
)
1715 dwarf2_per_objfile
->signatured_types
= NULL
;
1719 types_htab
= htab_create_alloc_ex (41,
1720 hash_type_signature
,
1723 &objfile
->objfile_obstack
,
1724 hashtab_obstack_allocate
,
1725 dummy_obstack_deallocate
);
1727 if (dwarf2_die_debug
)
1728 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
1730 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
1732 unsigned int offset
;
1733 unsigned int offset_size
;
1734 unsigned int type_offset
;
1735 unsigned int length
, initial_length_size
;
1736 unsigned short version
;
1738 struct signatured_type
*type_sig
;
1740 gdb_byte
*ptr
= info_ptr
;
1742 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
1744 /* We need to read the type's signature in order to build the hash
1745 table, but we don't need to read anything else just yet. */
1747 /* Sanity check to ensure entire cu is present. */
1748 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
1749 if (ptr
+ length
+ initial_length_size
1750 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
1752 complaint (&symfile_complaints
,
1753 _("debug type entry runs off end of `.debug_types' section, ignored"));
1757 offset_size
= initial_length_size
== 4 ? 4 : 8;
1758 ptr
+= initial_length_size
;
1759 version
= bfd_get_16 (objfile
->obfd
, ptr
);
1761 ptr
+= offset_size
; /* abbrev offset */
1762 ptr
+= 1; /* address size */
1763 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
1765 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
1767 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
1768 memset (type_sig
, 0, sizeof (*type_sig
));
1769 type_sig
->signature
= signature
;
1770 type_sig
->offset
= offset
;
1771 type_sig
->type_offset
= type_offset
;
1773 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
1774 gdb_assert (slot
!= NULL
);
1777 if (dwarf2_die_debug
)
1778 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
1779 offset
, phex (signature
, sizeof (signature
)));
1781 info_ptr
= info_ptr
+ initial_length_size
+ length
;
1784 dwarf2_per_objfile
->signatured_types
= types_htab
;
1789 /* Lookup a signature based type.
1790 Returns NULL if SIG is not present in the table. */
1792 static struct signatured_type
*
1793 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
1795 struct signatured_type find_entry
, *entry
;
1797 if (dwarf2_per_objfile
->signatured_types
== NULL
)
1799 complaint (&symfile_complaints
,
1800 _("missing `.debug_types' section for DW_FORM_sig8 die"));
1804 find_entry
.signature
= sig
;
1805 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
1809 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
1812 init_cu_die_reader (struct die_reader_specs
*reader
,
1813 struct dwarf2_cu
*cu
)
1815 reader
->abfd
= cu
->objfile
->obfd
;
1817 if (cu
->per_cu
->from_debug_types
)
1818 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
1820 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
1823 /* Find the base address of the compilation unit for range lists and
1824 location lists. It will normally be specified by DW_AT_low_pc.
1825 In DWARF-3 draft 4, the base address could be overridden by
1826 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1827 compilation units with discontinuous ranges. */
1830 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
1832 struct attribute
*attr
;
1835 cu
->base_address
= 0;
1837 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
1840 cu
->base_address
= DW_ADDR (attr
);
1845 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
1848 cu
->base_address
= DW_ADDR (attr
);
1854 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
1855 to combine the common parts.
1856 Process a compilation unit for a psymtab.
1857 BUFFER is a pointer to the beginning of the dwarf section buffer,
1858 either .debug_info or debug_types.
1859 INFO_PTR is a pointer to the start of the CU.
1860 Returns a pointer to the next CU. */
1863 process_psymtab_comp_unit (struct objfile
*objfile
,
1864 struct dwarf2_per_cu_data
*this_cu
,
1865 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1866 unsigned int buffer_size
)
1868 bfd
*abfd
= objfile
->obfd
;
1869 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1870 struct die_info
*comp_unit_die
;
1871 struct partial_symtab
*pst
;
1873 struct cleanup
*back_to_inner
;
1874 struct dwarf2_cu cu
;
1875 unsigned int bytes_read
;
1876 int has_children
, has_pc_info
;
1877 struct attribute
*attr
;
1879 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
1880 struct die_reader_specs reader_specs
;
1882 memset (&cu
, 0, sizeof (cu
));
1883 cu
.objfile
= objfile
;
1884 obstack_init (&cu
.comp_unit_obstack
);
1886 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1888 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
1889 buffer
, buffer_size
,
1892 /* Complete the cu_header. */
1893 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
1894 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1896 cu
.list_in_scope
= &file_symbols
;
1898 /* If this compilation unit was already read in, free the
1899 cached copy in order to read it in again. This is
1900 necessary because we skipped some symbols when we first
1901 read in the compilation unit (see load_partial_dies).
1902 This problem could be avoided, but the benefit is
1904 if (this_cu
->cu
!= NULL
)
1905 free_one_cached_comp_unit (this_cu
->cu
);
1907 /* Note that this is a pointer to our stack frame, being
1908 added to a global data structure. It will be cleaned up
1909 in free_stack_comp_unit when we finish with this
1910 compilation unit. */
1912 cu
.per_cu
= this_cu
;
1914 /* Read the abbrevs for this compilation unit into a table. */
1915 dwarf2_read_abbrevs (abfd
, &cu
);
1916 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1918 /* Read the compilation unit die. */
1919 if (this_cu
->from_debug_types
)
1920 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
1921 init_cu_die_reader (&reader_specs
, &cu
);
1922 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
1925 if (this_cu
->from_debug_types
)
1927 /* offset,length haven't been set yet for type units. */
1928 this_cu
->offset
= cu
.header
.offset
;
1929 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
1931 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
1933 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1934 + cu
.header
.initial_length_size
);
1935 do_cleanups (back_to_inner
);
1939 /* Set the language we're debugging. */
1940 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, &cu
);
1942 set_cu_language (DW_UNSND (attr
), &cu
);
1944 set_cu_language (language_minimal
, &cu
);
1946 /* Allocate a new partial symbol table structure. */
1947 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
1948 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1949 (attr
!= NULL
) ? DW_STRING (attr
) : "",
1950 /* TEXTLOW and TEXTHIGH are set below. */
1952 objfile
->global_psymbols
.next
,
1953 objfile
->static_psymbols
.next
);
1955 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
1957 pst
->dirname
= DW_STRING (attr
);
1959 pst
->read_symtab_private
= (char *) this_cu
;
1961 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1963 /* Store the function that reads in the rest of the symbol table */
1964 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1966 this_cu
->psymtab
= pst
;
1968 dwarf2_find_base_address (comp_unit_die
, &cu
);
1970 /* Possibly set the default values of LOWPC and HIGHPC from
1972 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
1973 &best_highpc
, &cu
, pst
);
1974 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
1975 /* Store the contiguous range if it is not empty; it can be empty for
1976 CUs with no code. */
1977 addrmap_set_empty (objfile
->psymtabs_addrmap
,
1978 best_lowpc
+ baseaddr
,
1979 best_highpc
+ baseaddr
- 1, pst
);
1981 /* Check if comp unit has_children.
1982 If so, read the rest of the partial symbols from this comp unit.
1983 If not, there's no more debug_info for this comp unit. */
1986 struct partial_die_info
*first_die
;
1987 CORE_ADDR lowpc
, highpc
;
1989 lowpc
= ((CORE_ADDR
) -1);
1990 highpc
= ((CORE_ADDR
) 0);
1992 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
1994 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
1995 ! has_pc_info
, &cu
);
1997 /* If we didn't find a lowpc, set it to highpc to avoid
1998 complaints from `maint check'. */
1999 if (lowpc
== ((CORE_ADDR
) -1))
2002 /* If the compilation unit didn't have an explicit address range,
2003 then use the information extracted from its child dies. */
2007 best_highpc
= highpc
;
2010 pst
->textlow
= best_lowpc
+ baseaddr
;
2011 pst
->texthigh
= best_highpc
+ baseaddr
;
2013 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
2014 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
2015 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
2016 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
2017 sort_pst_symbols (pst
);
2019 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
2020 + cu
.header
.initial_length_size
);
2022 if (this_cu
->from_debug_types
)
2024 /* It's not clear we want to do anything with stmt lists here.
2025 Waiting to see what gcc ultimately does. */
2029 /* Get the list of files included in the current compilation unit,
2030 and build a psymtab for each of them. */
2031 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
2034 do_cleanups (back_to_inner
);
2039 /* Traversal function for htab_traverse_noresize.
2040 Process one .debug_types comp-unit. */
2043 process_type_comp_unit (void **slot
, void *info
)
2045 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
2046 struct objfile
*objfile
= (struct objfile
*) info
;
2047 struct dwarf2_per_cu_data
*this_cu
;
2049 this_cu
= &entry
->per_cu
;
2050 this_cu
->from_debug_types
= 1;
2052 process_psymtab_comp_unit (objfile
, this_cu
,
2053 dwarf2_per_objfile
->types
.buffer
,
2054 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
2055 dwarf2_per_objfile
->types
.size
);
2060 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
2061 Build partial symbol tables for the .debug_types comp-units. */
2064 build_type_psymtabs (struct objfile
*objfile
)
2066 if (! create_debug_types_hash_table (objfile
))
2069 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
2070 process_type_comp_unit
, objfile
);
2073 /* Build the partial symbol table by doing a quick pass through the
2074 .debug_info and .debug_abbrev sections. */
2077 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
2079 /* Instead of reading this into a big buffer, we should probably use
2080 mmap() on architectures that support it. (FIXME) */
2081 bfd
*abfd
= objfile
->obfd
;
2083 struct cleanup
*back_to
;
2085 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
2087 /* Any cached compilation units will be linked by the per-objfile
2088 read_in_chain. Make sure to free them when we're done. */
2089 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2091 build_type_psymtabs (objfile
);
2093 create_all_comp_units (objfile
);
2095 objfile
->psymtabs_addrmap
=
2096 addrmap_create_mutable (&objfile
->objfile_obstack
);
2098 /* Since the objects we're extracting from .debug_info vary in
2099 length, only the individual functions to extract them (like
2100 read_comp_unit_head and load_partial_die) can really know whether
2101 the buffer is large enough to hold another complete object.
2103 At the moment, they don't actually check that. If .debug_info
2104 holds just one extra byte after the last compilation unit's dies,
2105 then read_comp_unit_head will happily read off the end of the
2106 buffer. read_partial_die is similarly casual. Those functions
2109 For this loop condition, simply checking whether there's any data
2110 left at all should be sufficient. */
2112 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
2113 + dwarf2_per_objfile
->info
.size
))
2115 struct dwarf2_per_cu_data
*this_cu
;
2117 this_cu
= dwarf2_find_comp_unit (info_ptr
- dwarf2_per_objfile
->info
.buffer
,
2120 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
2121 dwarf2_per_objfile
->info
.buffer
,
2123 dwarf2_per_objfile
->info
.size
);
2126 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
2127 &objfile
->objfile_obstack
);
2129 do_cleanups (back_to
);
2132 /* Load the partial DIEs for a secondary CU into memory. */
2135 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
2136 struct objfile
*objfile
)
2138 bfd
*abfd
= objfile
->obfd
;
2139 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
2140 struct die_info
*comp_unit_die
;
2141 struct dwarf2_cu
*cu
;
2142 unsigned int bytes_read
;
2143 struct cleanup
*back_to
;
2144 struct attribute
*attr
;
2146 struct die_reader_specs reader_specs
;
2148 gdb_assert (! this_cu
->from_debug_types
);
2150 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
2151 beg_of_comp_unit
= info_ptr
;
2153 cu
= alloc_one_comp_unit (objfile
);
2155 /* ??? Missing cleanup for CU? */
2157 /* Link this compilation unit into the compilation unit tree. */
2159 cu
->per_cu
= this_cu
;
2160 cu
->type_hash
= this_cu
->type_hash
;
2162 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
2163 dwarf2_per_objfile
->info
.buffer
,
2164 dwarf2_per_objfile
->info
.size
,
2167 /* Complete the cu_header. */
2168 cu
->header
.offset
= this_cu
->offset
;
2169 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2171 /* Read the abbrevs for this compilation unit into a table. */
2172 dwarf2_read_abbrevs (abfd
, cu
);
2173 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2175 /* Read the compilation unit die. */
2176 init_cu_die_reader (&reader_specs
, cu
);
2177 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2180 /* Set the language we're debugging. */
2181 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
2183 set_cu_language (DW_UNSND (attr
), cu
);
2185 set_cu_language (language_minimal
, cu
);
2187 /* Check if comp unit has_children.
2188 If so, read the rest of the partial symbols from this comp unit.
2189 If not, there's no more debug_info for this comp unit. */
2191 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
2193 do_cleanups (back_to
);
2196 /* Create a list of all compilation units in OBJFILE. We do this only
2197 if an inter-comp-unit reference is found; presumably if there is one,
2198 there will be many, and one will occur early in the .debug_info section.
2199 So there's no point in building this list incrementally. */
2202 create_all_comp_units (struct objfile
*objfile
)
2206 struct dwarf2_per_cu_data
**all_comp_units
;
2207 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info
.buffer
;
2211 all_comp_units
= xmalloc (n_allocated
2212 * sizeof (struct dwarf2_per_cu_data
*));
2214 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
2216 unsigned int length
, initial_length_size
;
2217 gdb_byte
*beg_of_comp_unit
;
2218 struct dwarf2_per_cu_data
*this_cu
;
2219 unsigned int offset
;
2221 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
2223 /* Read just enough information to find out where the next
2224 compilation unit is. */
2225 length
= read_initial_length (objfile
->obfd
, info_ptr
,
2226 &initial_length_size
);
2228 /* Save the compilation unit for later lookup. */
2229 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
2230 sizeof (struct dwarf2_per_cu_data
));
2231 memset (this_cu
, 0, sizeof (*this_cu
));
2232 this_cu
->offset
= offset
;
2233 this_cu
->length
= length
+ initial_length_size
;
2235 if (n_comp_units
== n_allocated
)
2238 all_comp_units
= xrealloc (all_comp_units
,
2240 * sizeof (struct dwarf2_per_cu_data
*));
2242 all_comp_units
[n_comp_units
++] = this_cu
;
2244 info_ptr
= info_ptr
+ this_cu
->length
;
2247 dwarf2_per_objfile
->all_comp_units
2248 = obstack_alloc (&objfile
->objfile_obstack
,
2249 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
2250 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
2251 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
2252 xfree (all_comp_units
);
2253 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
2256 /* Process all loaded DIEs for compilation unit CU, starting at
2257 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
2258 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
2259 DW_AT_ranges). If NEED_PC is set, then this function will set
2260 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
2261 and record the covered ranges in the addrmap. */
2264 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
2265 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2267 struct objfile
*objfile
= cu
->objfile
;
2268 bfd
*abfd
= objfile
->obfd
;
2269 struct partial_die_info
*pdi
;
2271 /* Now, march along the PDI's, descending into ones which have
2272 interesting children but skipping the children of the other ones,
2273 until we reach the end of the compilation unit. */
2279 fixup_partial_die (pdi
, cu
);
2281 /* Anonymous namespaces have no name but have interesting
2282 children, so we need to look at them. Ditto for anonymous
2285 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
2286 || pdi
->tag
== DW_TAG_enumeration_type
)
2290 case DW_TAG_subprogram
:
2291 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2293 case DW_TAG_variable
:
2294 case DW_TAG_typedef
:
2295 case DW_TAG_union_type
:
2296 if (!pdi
->is_declaration
)
2298 add_partial_symbol (pdi
, cu
);
2301 case DW_TAG_class_type
:
2302 case DW_TAG_interface_type
:
2303 case DW_TAG_structure_type
:
2304 if (!pdi
->is_declaration
)
2306 add_partial_symbol (pdi
, cu
);
2309 case DW_TAG_enumeration_type
:
2310 if (!pdi
->is_declaration
)
2311 add_partial_enumeration (pdi
, cu
);
2313 case DW_TAG_base_type
:
2314 case DW_TAG_subrange_type
:
2315 /* File scope base type definitions are added to the partial
2317 add_partial_symbol (pdi
, cu
);
2319 case DW_TAG_namespace
:
2320 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
2323 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
2330 /* If the die has a sibling, skip to the sibling. */
2332 pdi
= pdi
->die_sibling
;
2336 /* Functions used to compute the fully scoped name of a partial DIE.
2338 Normally, this is simple. For C++, the parent DIE's fully scoped
2339 name is concatenated with "::" and the partial DIE's name. For
2340 Java, the same thing occurs except that "." is used instead of "::".
2341 Enumerators are an exception; they use the scope of their parent
2342 enumeration type, i.e. the name of the enumeration type is not
2343 prepended to the enumerator.
2345 There are two complexities. One is DW_AT_specification; in this
2346 case "parent" means the parent of the target of the specification,
2347 instead of the direct parent of the DIE. The other is compilers
2348 which do not emit DW_TAG_namespace; in this case we try to guess
2349 the fully qualified name of structure types from their members'
2350 linkage names. This must be done using the DIE's children rather
2351 than the children of any DW_AT_specification target. We only need
2352 to do this for structures at the top level, i.e. if the target of
2353 any DW_AT_specification (if any; otherwise the DIE itself) does not
2356 /* Compute the scope prefix associated with PDI's parent, in
2357 compilation unit CU. The result will be allocated on CU's
2358 comp_unit_obstack, or a copy of the already allocated PDI->NAME
2359 field. NULL is returned if no prefix is necessary. */
2361 partial_die_parent_scope (struct partial_die_info
*pdi
,
2362 struct dwarf2_cu
*cu
)
2364 char *grandparent_scope
;
2365 struct partial_die_info
*parent
, *real_pdi
;
2367 /* We need to look at our parent DIE; if we have a DW_AT_specification,
2368 then this means the parent of the specification DIE. */
2371 while (real_pdi
->has_specification
)
2372 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2374 parent
= real_pdi
->die_parent
;
2378 if (parent
->scope_set
)
2379 return parent
->scope
;
2381 fixup_partial_die (parent
, cu
);
2383 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
2385 if (parent
->tag
== DW_TAG_namespace
2386 || parent
->tag
== DW_TAG_structure_type
2387 || parent
->tag
== DW_TAG_class_type
2388 || parent
->tag
== DW_TAG_interface_type
2389 || parent
->tag
== DW_TAG_union_type
2390 || parent
->tag
== DW_TAG_enumeration_type
)
2392 if (grandparent_scope
== NULL
)
2393 parent
->scope
= parent
->name
;
2395 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
2398 else if (parent
->tag
== DW_TAG_enumerator
)
2399 /* Enumerators should not get the name of the enumeration as a prefix. */
2400 parent
->scope
= grandparent_scope
;
2403 /* FIXME drow/2004-04-01: What should we be doing with
2404 function-local names? For partial symbols, we should probably be
2406 complaint (&symfile_complaints
,
2407 _("unhandled containing DIE tag %d for DIE at %d"),
2408 parent
->tag
, pdi
->offset
);
2409 parent
->scope
= grandparent_scope
;
2412 parent
->scope_set
= 1;
2413 return parent
->scope
;
2416 /* Return the fully scoped name associated with PDI, from compilation unit
2417 CU. The result will be allocated with malloc. */
2419 partial_die_full_name (struct partial_die_info
*pdi
,
2420 struct dwarf2_cu
*cu
)
2424 parent_scope
= partial_die_parent_scope (pdi
, cu
);
2425 if (parent_scope
== NULL
)
2428 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
2432 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
2434 struct objfile
*objfile
= cu
->objfile
;
2436 char *actual_name
= NULL
;
2437 const char *my_prefix
;
2438 const struct partial_symbol
*psym
= NULL
;
2440 int built_actual_name
= 0;
2442 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2444 if (pdi_needs_namespace (pdi
->tag
))
2446 actual_name
= partial_die_full_name (pdi
, cu
);
2448 built_actual_name
= 1;
2451 if (actual_name
== NULL
)
2452 actual_name
= pdi
->name
;
2456 case DW_TAG_subprogram
:
2457 if (pdi
->is_external
|| cu
->language
== language_ada
)
2459 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
2460 of the global scope. But in Ada, we want to be able to access
2461 nested procedures globally. So all Ada subprograms are stored
2462 in the global scope. */
2463 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2464 mst_text, objfile); */
2465 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2467 VAR_DOMAIN
, LOC_BLOCK
,
2468 &objfile
->global_psymbols
,
2469 0, pdi
->lowpc
+ baseaddr
,
2470 cu
->language
, objfile
);
2474 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2475 mst_file_text, objfile); */
2476 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2478 VAR_DOMAIN
, LOC_BLOCK
,
2479 &objfile
->static_psymbols
,
2480 0, pdi
->lowpc
+ baseaddr
,
2481 cu
->language
, objfile
);
2484 case DW_TAG_variable
:
2485 if (pdi
->is_external
)
2488 Don't enter into the minimal symbol tables as there is
2489 a minimal symbol table entry from the ELF symbols already.
2490 Enter into partial symbol table if it has a location
2491 descriptor or a type.
2492 If the location descriptor is missing, new_symbol will create
2493 a LOC_UNRESOLVED symbol, the address of the variable will then
2494 be determined from the minimal symbol table whenever the variable
2496 The address for the partial symbol table entry is not
2497 used by GDB, but it comes in handy for debugging partial symbol
2501 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2502 if (pdi
->locdesc
|| pdi
->has_type
)
2503 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2505 VAR_DOMAIN
, LOC_STATIC
,
2506 &objfile
->global_psymbols
,
2508 cu
->language
, objfile
);
2512 /* Static Variable. Skip symbols without location descriptors. */
2513 if (pdi
->locdesc
== NULL
)
2515 if (built_actual_name
)
2516 xfree (actual_name
);
2519 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2520 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2521 mst_file_data, objfile); */
2522 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2524 VAR_DOMAIN
, LOC_STATIC
,
2525 &objfile
->static_psymbols
,
2527 cu
->language
, objfile
);
2530 case DW_TAG_typedef
:
2531 case DW_TAG_base_type
:
2532 case DW_TAG_subrange_type
:
2533 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2535 VAR_DOMAIN
, LOC_TYPEDEF
,
2536 &objfile
->static_psymbols
,
2537 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2539 case DW_TAG_namespace
:
2540 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2542 VAR_DOMAIN
, LOC_TYPEDEF
,
2543 &objfile
->global_psymbols
,
2544 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2546 case DW_TAG_class_type
:
2547 case DW_TAG_interface_type
:
2548 case DW_TAG_structure_type
:
2549 case DW_TAG_union_type
:
2550 case DW_TAG_enumeration_type
:
2551 /* Skip external references. The DWARF standard says in the section
2552 about "Structure, Union, and Class Type Entries": "An incomplete
2553 structure, union or class type is represented by a structure,
2554 union or class entry that does not have a byte size attribute
2555 and that has a DW_AT_declaration attribute." */
2556 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2558 if (built_actual_name
)
2559 xfree (actual_name
);
2563 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2564 static vs. global. */
2565 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2567 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2568 (cu
->language
== language_cplus
2569 || cu
->language
== language_java
)
2570 ? &objfile
->global_psymbols
2571 : &objfile
->static_psymbols
,
2572 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2575 case DW_TAG_enumerator
:
2576 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2578 VAR_DOMAIN
, LOC_CONST
,
2579 (cu
->language
== language_cplus
2580 || cu
->language
== language_java
)
2581 ? &objfile
->global_psymbols
2582 : &objfile
->static_psymbols
,
2583 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2589 /* Check to see if we should scan the name for possible namespace
2590 info. Only do this if this is C++, if we don't have namespace
2591 debugging info in the file, if the psym is of an appropriate type
2592 (otherwise we'll have psym == NULL), and if we actually had a
2593 mangled name to begin with. */
2595 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2596 cases which do not set PSYM above? */
2598 if (cu
->language
== language_cplus
2599 && cu
->has_namespace_info
== 0
2601 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2602 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2605 if (built_actual_name
)
2606 xfree (actual_name
);
2609 /* Determine whether a die of type TAG living in a C++ class or
2610 namespace needs to have the name of the scope prepended to the
2611 name listed in the die. */
2614 pdi_needs_namespace (enum dwarf_tag tag
)
2618 case DW_TAG_namespace
:
2619 case DW_TAG_typedef
:
2620 case DW_TAG_class_type
:
2621 case DW_TAG_interface_type
:
2622 case DW_TAG_structure_type
:
2623 case DW_TAG_union_type
:
2624 case DW_TAG_enumeration_type
:
2625 case DW_TAG_enumerator
:
2632 /* Read a partial die corresponding to a namespace; also, add a symbol
2633 corresponding to that namespace to the symbol table. NAMESPACE is
2634 the name of the enclosing namespace. */
2637 add_partial_namespace (struct partial_die_info
*pdi
,
2638 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2639 int need_pc
, struct dwarf2_cu
*cu
)
2641 struct objfile
*objfile
= cu
->objfile
;
2643 /* Add a symbol for the namespace. */
2645 add_partial_symbol (pdi
, cu
);
2647 /* Now scan partial symbols in that namespace. */
2649 if (pdi
->has_children
)
2650 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2653 /* Read a partial die corresponding to a Fortran module. */
2656 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
2657 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2659 /* Now scan partial symbols in that module.
2661 FIXME: Support the separate Fortran module namespaces. */
2663 if (pdi
->has_children
)
2664 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2667 /* Read a partial die corresponding to a subprogram and create a partial
2668 symbol for that subprogram. When the CU language allows it, this
2669 routine also defines a partial symbol for each nested subprogram
2670 that this subprogram contains.
2672 DIE my also be a lexical block, in which case we simply search
2673 recursively for suprograms defined inside that lexical block.
2674 Again, this is only performed when the CU language allows this
2675 type of definitions. */
2678 add_partial_subprogram (struct partial_die_info
*pdi
,
2679 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2680 int need_pc
, struct dwarf2_cu
*cu
)
2682 if (pdi
->tag
== DW_TAG_subprogram
)
2684 if (pdi
->has_pc_info
)
2686 if (pdi
->lowpc
< *lowpc
)
2687 *lowpc
= pdi
->lowpc
;
2688 if (pdi
->highpc
> *highpc
)
2689 *highpc
= pdi
->highpc
;
2693 struct objfile
*objfile
= cu
->objfile
;
2695 baseaddr
= ANOFFSET (objfile
->section_offsets
,
2696 SECT_OFF_TEXT (objfile
));
2697 addrmap_set_empty (objfile
->psymtabs_addrmap
,
2698 pdi
->lowpc
, pdi
->highpc
- 1,
2699 cu
->per_cu
->psymtab
);
2701 if (!pdi
->is_declaration
)
2702 add_partial_symbol (pdi
, cu
);
2706 if (! pdi
->has_children
)
2709 if (cu
->language
== language_ada
)
2711 pdi
= pdi
->die_child
;
2714 fixup_partial_die (pdi
, cu
);
2715 if (pdi
->tag
== DW_TAG_subprogram
2716 || pdi
->tag
== DW_TAG_lexical_block
)
2717 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2718 pdi
= pdi
->die_sibling
;
2723 /* See if we can figure out if the class lives in a namespace. We do
2724 this by looking for a member function; its demangled name will
2725 contain namespace info, if there is any. */
2728 guess_structure_name (struct partial_die_info
*struct_pdi
,
2729 struct dwarf2_cu
*cu
)
2731 if ((cu
->language
== language_cplus
2732 || cu
->language
== language_java
)
2733 && cu
->has_namespace_info
== 0
2734 && struct_pdi
->has_children
)
2736 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2737 what template types look like, because the demangler
2738 frequently doesn't give the same name as the debug info. We
2739 could fix this by only using the demangled name to get the
2740 prefix (but see comment in read_structure_type). */
2742 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2743 struct partial_die_info
*real_pdi
;
2745 /* If this DIE (this DIE's specification, if any) has a parent, then
2746 we should not do this. We'll prepend the parent's fully qualified
2747 name when we create the partial symbol. */
2749 real_pdi
= struct_pdi
;
2750 while (real_pdi
->has_specification
)
2751 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2753 if (real_pdi
->die_parent
!= NULL
)
2756 while (child_pdi
!= NULL
)
2758 if (child_pdi
->tag
== DW_TAG_subprogram
)
2760 char *actual_class_name
2761 = language_class_name_from_physname (cu
->language_defn
,
2763 if (actual_class_name
!= NULL
)
2766 = obsavestring (actual_class_name
,
2767 strlen (actual_class_name
),
2768 &cu
->comp_unit_obstack
);
2769 xfree (actual_class_name
);
2774 child_pdi
= child_pdi
->die_sibling
;
2779 /* Read a partial die corresponding to an enumeration type. */
2782 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2783 struct dwarf2_cu
*cu
)
2785 struct objfile
*objfile
= cu
->objfile
;
2786 bfd
*abfd
= objfile
->obfd
;
2787 struct partial_die_info
*pdi
;
2789 if (enum_pdi
->name
!= NULL
)
2790 add_partial_symbol (enum_pdi
, cu
);
2792 pdi
= enum_pdi
->die_child
;
2795 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2796 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2798 add_partial_symbol (pdi
, cu
);
2799 pdi
= pdi
->die_sibling
;
2803 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2804 Return the corresponding abbrev, or NULL if the number is zero (indicating
2805 an empty DIE). In either case *BYTES_READ will be set to the length of
2806 the initial number. */
2808 static struct abbrev_info
*
2809 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2810 struct dwarf2_cu
*cu
)
2812 bfd
*abfd
= cu
->objfile
->obfd
;
2813 unsigned int abbrev_number
;
2814 struct abbrev_info
*abbrev
;
2816 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2818 if (abbrev_number
== 0)
2821 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2824 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2825 bfd_get_filename (abfd
));
2831 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2832 Returns a pointer to the end of a series of DIEs, terminated by an empty
2833 DIE. Any children of the skipped DIEs will also be skipped. */
2836 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2838 struct abbrev_info
*abbrev
;
2839 unsigned int bytes_read
;
2843 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2845 return info_ptr
+ bytes_read
;
2847 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
2851 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2852 INFO_PTR should point just after the initial uleb128 of a DIE, and the
2853 abbrev corresponding to that skipped uleb128 should be passed in
2854 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2858 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
2859 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
2861 unsigned int bytes_read
;
2862 struct attribute attr
;
2863 bfd
*abfd
= cu
->objfile
->obfd
;
2864 unsigned int form
, i
;
2866 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2868 /* The only abbrev we care about is DW_AT_sibling. */
2869 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2871 read_attribute (&attr
, &abbrev
->attrs
[i
],
2872 abfd
, info_ptr
, cu
);
2873 if (attr
.form
== DW_FORM_ref_addr
)
2874 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2876 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
2879 /* If it isn't DW_AT_sibling, skip this attribute. */
2880 form
= abbrev
->attrs
[i
].form
;
2885 case DW_FORM_ref_addr
:
2886 info_ptr
+= cu
->header
.addr_size
;
2906 case DW_FORM_string
:
2907 read_string (abfd
, info_ptr
, &bytes_read
);
2908 info_ptr
+= bytes_read
;
2911 info_ptr
+= cu
->header
.offset_size
;
2914 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2915 info_ptr
+= bytes_read
;
2917 case DW_FORM_block1
:
2918 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2920 case DW_FORM_block2
:
2921 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2923 case DW_FORM_block4
:
2924 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2928 case DW_FORM_ref_udata
:
2929 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2931 case DW_FORM_indirect
:
2932 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2933 info_ptr
+= bytes_read
;
2934 /* We need to continue parsing from here, so just go back to
2936 goto skip_attribute
;
2939 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2940 dwarf_form_name (form
),
2941 bfd_get_filename (abfd
));
2945 if (abbrev
->has_children
)
2946 return skip_children (buffer
, info_ptr
, cu
);
2951 /* Locate ORIG_PDI's sibling.
2952 INFO_PTR should point to the start of the next DIE after ORIG_PDI
2956 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
2957 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
2958 bfd
*abfd
, struct dwarf2_cu
*cu
)
2960 /* Do we know the sibling already? */
2962 if (orig_pdi
->sibling
)
2963 return orig_pdi
->sibling
;
2965 /* Are there any children to deal with? */
2967 if (!orig_pdi
->has_children
)
2970 /* Skip the children the long way. */
2972 return skip_children (buffer
, info_ptr
, cu
);
2975 /* Expand this partial symbol table into a full symbol table. */
2978 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2980 /* FIXME: This is barely more than a stub. */
2985 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2991 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2992 gdb_flush (gdb_stdout
);
2995 /* Restore our global data. */
2996 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2997 dwarf2_objfile_data_key
);
2999 /* If this psymtab is constructed from a debug-only objfile, the
3000 has_section_at_zero flag will not necessarily be correct. We
3001 can get the correct value for this flag by looking at the data
3002 associated with the (presumably stripped) associated objfile. */
3003 if (pst
->objfile
->separate_debug_objfile_backlink
)
3005 struct dwarf2_per_objfile
*dpo_backlink
3006 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
3007 dwarf2_objfile_data_key
);
3008 dwarf2_per_objfile
->has_section_at_zero
3009 = dpo_backlink
->has_section_at_zero
;
3012 psymtab_to_symtab_1 (pst
);
3014 /* Finish up the debug error message. */
3016 printf_filtered (_("done.\n"));
3021 /* Add PER_CU to the queue. */
3024 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
3026 struct dwarf2_queue_item
*item
;
3029 item
= xmalloc (sizeof (*item
));
3030 item
->per_cu
= per_cu
;
3033 if (dwarf2_queue
== NULL
)
3034 dwarf2_queue
= item
;
3036 dwarf2_queue_tail
->next
= item
;
3038 dwarf2_queue_tail
= item
;
3041 /* Process the queue. */
3044 process_queue (struct objfile
*objfile
)
3046 struct dwarf2_queue_item
*item
, *next_item
;
3048 /* The queue starts out with one item, but following a DIE reference
3049 may load a new CU, adding it to the end of the queue. */
3050 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
3052 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
3053 process_full_comp_unit (item
->per_cu
);
3055 item
->per_cu
->queued
= 0;
3056 next_item
= item
->next
;
3060 dwarf2_queue_tail
= NULL
;
3063 /* Free all allocated queue entries. This function only releases anything if
3064 an error was thrown; if the queue was processed then it would have been
3065 freed as we went along. */
3068 dwarf2_release_queue (void *dummy
)
3070 struct dwarf2_queue_item
*item
, *last
;
3072 item
= dwarf2_queue
;
3075 /* Anything still marked queued is likely to be in an
3076 inconsistent state, so discard it. */
3077 if (item
->per_cu
->queued
)
3079 if (item
->per_cu
->cu
!= NULL
)
3080 free_one_cached_comp_unit (item
->per_cu
->cu
);
3081 item
->per_cu
->queued
= 0;
3089 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
3092 /* Read in full symbols for PST, and anything it depends on. */
3095 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
3097 struct dwarf2_per_cu_data
*per_cu
;
3098 struct cleanup
*back_to
;
3101 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
3102 if (!pst
->dependencies
[i
]->readin
)
3104 /* Inform about additional files that need to be read in. */
3107 /* FIXME: i18n: Need to make this a single string. */
3108 fputs_filtered (" ", gdb_stdout
);
3110 fputs_filtered ("and ", gdb_stdout
);
3112 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
3113 wrap_here (""); /* Flush output */
3114 gdb_flush (gdb_stdout
);
3116 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
3119 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
3123 /* It's an include file, no symbols to read for it.
3124 Everything is in the parent symtab. */
3129 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
3131 queue_comp_unit (per_cu
, pst
->objfile
);
3133 if (per_cu
->from_debug_types
)
3134 read_signatured_type_at_offset (pst
->objfile
, per_cu
->offset
);
3136 load_full_comp_unit (per_cu
, pst
->objfile
);
3138 process_queue (pst
->objfile
);
3140 /* Age the cache, releasing compilation units that have not
3141 been used recently. */
3142 age_cached_comp_units ();
3144 do_cleanups (back_to
);
3147 /* Load the DIEs associated with PER_CU into memory. */
3150 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
3152 bfd
*abfd
= objfile
->obfd
;
3153 struct dwarf2_cu
*cu
;
3154 unsigned int offset
;
3155 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3156 struct cleanup
*back_to
, *free_cu_cleanup
;
3157 struct attribute
*attr
;
3160 gdb_assert (! per_cu
->from_debug_types
);
3162 /* Set local variables from the partial symbol table info. */
3163 offset
= per_cu
->offset
;
3165 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
3166 beg_of_comp_unit
= info_ptr
;
3168 cu
= alloc_one_comp_unit (objfile
);
3170 /* If an error occurs while loading, release our storage. */
3171 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3173 /* Read in the comp_unit header. */
3174 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
3176 /* Complete the cu_header. */
3177 cu
->header
.offset
= offset
;
3178 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3180 /* Read the abbrevs for this compilation unit. */
3181 dwarf2_read_abbrevs (abfd
, cu
);
3182 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3184 /* Link this compilation unit into the compilation unit tree. */
3186 cu
->per_cu
= per_cu
;
3187 cu
->type_hash
= per_cu
->type_hash
;
3189 cu
->dies
= read_comp_unit (info_ptr
, cu
);
3191 /* We try not to read any attributes in this function, because not
3192 all objfiles needed for references have been loaded yet, and symbol
3193 table processing isn't initialized. But we have to set the CU language,
3194 or we won't be able to build types correctly. */
3195 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
3197 set_cu_language (DW_UNSND (attr
), cu
);
3199 set_cu_language (language_minimal
, cu
);
3201 /* Link this CU into read_in_chain. */
3202 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3203 dwarf2_per_objfile
->read_in_chain
= per_cu
;
3205 do_cleanups (back_to
);
3207 /* We've successfully allocated this compilation unit. Let our caller
3208 clean it up when finished with it. */
3209 discard_cleanups (free_cu_cleanup
);
3212 /* Generate full symbol information for PST and CU, whose DIEs have
3213 already been loaded into memory. */
3216 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
3218 struct partial_symtab
*pst
= per_cu
->psymtab
;
3219 struct dwarf2_cu
*cu
= per_cu
->cu
;
3220 struct objfile
*objfile
= pst
->objfile
;
3221 bfd
*abfd
= objfile
->obfd
;
3222 CORE_ADDR lowpc
, highpc
;
3223 struct symtab
*symtab
;
3224 struct cleanup
*back_to
;
3227 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3230 back_to
= make_cleanup (really_free_pendings
, NULL
);
3232 cu
->list_in_scope
= &file_symbols
;
3234 dwarf2_find_base_address (cu
->dies
, cu
);
3236 /* Do line number decoding in read_file_scope () */
3237 process_die (cu
->dies
, cu
);
3239 /* Some compilers don't define a DW_AT_high_pc attribute for the
3240 compilation unit. If the DW_AT_high_pc is missing, synthesize
3241 it, by scanning the DIE's below the compilation unit. */
3242 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
3244 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
3246 /* Set symtab language to language from DW_AT_language.
3247 If the compilation is from a C file generated by language preprocessors,
3248 do not set the language if it was already deduced by start_subfile. */
3250 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
3252 symtab
->language
= cu
->language
;
3254 pst
->symtab
= symtab
;
3257 do_cleanups (back_to
);
3260 /* Process a die and its children. */
3263 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
3267 case DW_TAG_padding
:
3269 case DW_TAG_compile_unit
:
3270 read_file_scope (die
, cu
);
3272 case DW_TAG_type_unit
:
3273 read_type_unit_scope (die
, cu
);
3275 case DW_TAG_subprogram
:
3276 case DW_TAG_inlined_subroutine
:
3277 read_func_scope (die
, cu
);
3279 case DW_TAG_lexical_block
:
3280 case DW_TAG_try_block
:
3281 case DW_TAG_catch_block
:
3282 read_lexical_block_scope (die
, cu
);
3284 case DW_TAG_class_type
:
3285 case DW_TAG_interface_type
:
3286 case DW_TAG_structure_type
:
3287 case DW_TAG_union_type
:
3288 process_structure_scope (die
, cu
);
3290 case DW_TAG_enumeration_type
:
3291 process_enumeration_scope (die
, cu
);
3294 /* These dies have a type, but processing them does not create
3295 a symbol or recurse to process the children. Therefore we can
3296 read them on-demand through read_type_die. */
3297 case DW_TAG_subroutine_type
:
3298 case DW_TAG_set_type
:
3299 case DW_TAG_array_type
:
3300 case DW_TAG_pointer_type
:
3301 case DW_TAG_ptr_to_member_type
:
3302 case DW_TAG_reference_type
:
3303 case DW_TAG_string_type
:
3306 case DW_TAG_base_type
:
3307 case DW_TAG_subrange_type
:
3308 case DW_TAG_typedef
:
3309 /* Add a typedef symbol for the type definition, if it has a
3311 new_symbol (die
, read_type_die (die
, cu
), cu
);
3313 case DW_TAG_common_block
:
3314 read_common_block (die
, cu
);
3316 case DW_TAG_common_inclusion
:
3318 case DW_TAG_namespace
:
3319 processing_has_namespace_info
= 1;
3320 read_namespace (die
, cu
);
3323 read_module (die
, cu
);
3325 case DW_TAG_imported_declaration
:
3326 case DW_TAG_imported_module
:
3327 processing_has_namespace_info
= 1;
3328 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
3329 || cu
->language
!= language_fortran
))
3330 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
3331 dwarf_tag_name (die
->tag
));
3332 read_import_statement (die
, cu
);
3335 new_symbol (die
, NULL
, cu
);
3340 /* Return the fully qualified name of DIE, based on its DW_AT_name.
3341 If scope qualifiers are appropriate they will be added. The result
3342 will be allocated on the objfile_obstack, or NULL if the DIE does
3346 dwarf2_full_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
3348 struct attribute
*attr
;
3349 char *prefix
, *name
;
3350 struct ui_file
*buf
= NULL
;
3352 name
= dwarf2_name (die
, cu
);
3356 /* These are the only languages we know how to qualify names in. */
3357 if (cu
->language
!= language_cplus
3358 && cu
->language
!= language_java
)
3361 /* If no prefix is necessary for this type of DIE, return the
3362 unqualified name. The other three tags listed could be handled
3363 in pdi_needs_namespace, but that requires broader changes. */
3364 if (!pdi_needs_namespace (die
->tag
)
3365 && die
->tag
!= DW_TAG_subprogram
3366 && die
->tag
!= DW_TAG_variable
3367 && die
->tag
!= DW_TAG_member
)
3370 prefix
= determine_prefix (die
, cu
);
3371 if (*prefix
!= '\0')
3372 name
= typename_concat (&cu
->objfile
->objfile_obstack
, prefix
,
3378 /* Read the import statement specified by the given die and record it. */
3381 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
3383 struct attribute
*import_attr
;
3384 struct die_info
*imported_die
;
3385 struct dwarf2_cu
*imported_cu
;
3386 const char *imported_name
;
3387 const char *imported_name_prefix
;
3388 const char *import_prefix
;
3389 char *canonical_name
;
3391 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
3392 if (import_attr
== NULL
)
3394 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
3395 dwarf_tag_name (die
->tag
));
3400 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
3401 imported_name
= dwarf2_name (imported_die
, imported_cu
);
3402 if (imported_name
== NULL
)
3404 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
3406 The import in the following code:
3420 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
3421 <52> DW_AT_decl_file : 1
3422 <53> DW_AT_decl_line : 6
3423 <54> DW_AT_import : <0x75>
3424 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
3426 <5b> DW_AT_decl_file : 1
3427 <5c> DW_AT_decl_line : 2
3428 <5d> DW_AT_type : <0x6e>
3430 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
3431 <76> DW_AT_byte_size : 4
3432 <77> DW_AT_encoding : 5 (signed)
3434 imports the wrong die ( 0x75 instead of 0x58 ).
3435 This case will be ignored until the gcc bug is fixed. */
3439 /* FIXME: dwarf2_name (die); for the local name after import. */
3441 /* Figure out where the statement is being imported to. */
3442 import_prefix
= determine_prefix (die
, cu
);
3444 /* Figure out what the scope of the imported die is and prepend it
3445 to the name of the imported die. */
3446 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
3448 if (strlen (imported_name_prefix
) > 0)
3450 canonical_name
= alloca (strlen (imported_name_prefix
) + 2 + strlen (imported_name
) + 1);
3451 strcpy (canonical_name
, imported_name_prefix
);
3452 strcat (canonical_name
, "::");
3453 strcat (canonical_name
, imported_name
);
3457 canonical_name
= alloca (strlen (imported_name
) + 1);
3458 strcpy (canonical_name
, imported_name
);
3461 using_directives
= cp_add_using (import_prefix
,canonical_name
, using_directives
);
3465 initialize_cu_func_list (struct dwarf2_cu
*cu
)
3467 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
3471 free_cu_line_header (void *arg
)
3473 struct dwarf2_cu
*cu
= arg
;
3475 free_line_header (cu
->line_header
);
3476 cu
->line_header
= NULL
;
3480 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3482 struct objfile
*objfile
= cu
->objfile
;
3483 struct comp_unit_head
*cu_header
= &cu
->header
;
3484 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3485 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
3486 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
3487 struct attribute
*attr
;
3489 char *comp_dir
= NULL
;
3490 struct die_info
*child_die
;
3491 bfd
*abfd
= objfile
->obfd
;
3492 struct line_header
*line_header
= 0;
3495 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3497 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
3499 /* If we didn't find a lowpc, set it to highpc to avoid complaints
3500 from finish_block. */
3501 if (lowpc
== ((CORE_ADDR
) -1))
3506 /* Find the filename. Do not use dwarf2_name here, since the filename
3507 is not a source language identifier. */
3508 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3511 name
= DW_STRING (attr
);
3514 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
3516 comp_dir
= DW_STRING (attr
);
3517 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
3519 comp_dir
= ldirname (name
);
3520 if (comp_dir
!= NULL
)
3521 make_cleanup (xfree
, comp_dir
);
3523 if (comp_dir
!= NULL
)
3525 /* Irix 6.2 native cc prepends <machine>.: to the compilation
3526 directory, get rid of it. */
3527 char *cp
= strchr (comp_dir
, ':');
3529 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
3536 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
3539 set_cu_language (DW_UNSND (attr
), cu
);
3542 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3544 cu
->producer
= DW_STRING (attr
);
3546 /* We assume that we're processing GCC output. */
3547 processing_gcc_compilation
= 2;
3549 processing_has_namespace_info
= 0;
3551 start_symtab (name
, comp_dir
, lowpc
);
3552 record_debugformat ("DWARF 2");
3553 record_producer (cu
->producer
);
3555 initialize_cu_func_list (cu
);
3557 /* Decode line number information if present. We do this before
3558 processing child DIEs, so that the line header table is available
3559 for DW_AT_decl_file. */
3560 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3563 unsigned int line_offset
= DW_UNSND (attr
);
3564 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3567 cu
->line_header
= line_header
;
3568 make_cleanup (free_cu_line_header
, cu
);
3569 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
3573 /* Process all dies in compilation unit. */
3574 if (die
->child
!= NULL
)
3576 child_die
= die
->child
;
3577 while (child_die
&& child_die
->tag
)
3579 process_die (child_die
, cu
);
3580 child_die
= sibling_die (child_die
);
3584 /* Decode macro information, if present. Dwarf 2 macro information
3585 refers to information in the line number info statement program
3586 header, so we can only read it if we've read the header
3588 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
3589 if (attr
&& line_header
)
3591 unsigned int macro_offset
= DW_UNSND (attr
);
3592 dwarf_decode_macros (line_header
, macro_offset
,
3593 comp_dir
, abfd
, cu
);
3595 do_cleanups (back_to
);
3598 /* For TUs we want to skip the first top level sibling if it's not the
3599 actual type being defined by this TU. In this case the first top
3600 level sibling is there to provide context only. */
3603 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3605 struct objfile
*objfile
= cu
->objfile
;
3606 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3608 struct attribute
*attr
;
3610 char *comp_dir
= NULL
;
3611 struct die_info
*child_die
;
3612 bfd
*abfd
= objfile
->obfd
;
3613 struct line_header
*line_header
= 0;
3615 /* start_symtab needs a low pc, but we don't really have one.
3616 Do what read_file_scope would do in the absence of such info. */
3617 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3619 /* Find the filename. Do not use dwarf2_name here, since the filename
3620 is not a source language identifier. */
3621 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3623 name
= DW_STRING (attr
);
3625 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
3627 comp_dir
= DW_STRING (attr
);
3628 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
3630 comp_dir
= ldirname (name
);
3631 if (comp_dir
!= NULL
)
3632 make_cleanup (xfree
, comp_dir
);
3638 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
3640 set_cu_language (DW_UNSND (attr
), cu
);
3642 /* This isn't technically needed today. It is done for symmetry
3643 with read_file_scope. */
3644 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3646 cu
->producer
= DW_STRING (attr
);
3648 /* We assume that we're processing GCC output. */
3649 processing_gcc_compilation
= 2;
3651 processing_has_namespace_info
= 0;
3653 start_symtab (name
, comp_dir
, lowpc
);
3654 record_debugformat ("DWARF 2");
3655 record_producer (cu
->producer
);
3657 /* Process the dies in the type unit. */
3658 if (die
->child
== NULL
)
3660 dump_die_for_error (die
);
3661 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
3662 bfd_get_filename (abfd
));
3665 child_die
= die
->child
;
3667 while (child_die
&& child_die
->tag
)
3669 process_die (child_die
, cu
);
3671 child_die
= sibling_die (child_die
);
3674 do_cleanups (back_to
);
3678 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
3679 struct dwarf2_cu
*cu
)
3681 struct function_range
*thisfn
;
3683 thisfn
= (struct function_range
*)
3684 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
3685 thisfn
->name
= name
;
3686 thisfn
->lowpc
= lowpc
;
3687 thisfn
->highpc
= highpc
;
3688 thisfn
->seen_line
= 0;
3689 thisfn
->next
= NULL
;
3691 if (cu
->last_fn
== NULL
)
3692 cu
->first_fn
= thisfn
;
3694 cu
->last_fn
->next
= thisfn
;
3696 cu
->last_fn
= thisfn
;
3699 /* qsort helper for inherit_abstract_dies. */
3702 unsigned_int_compar (const void *ap
, const void *bp
)
3704 unsigned int a
= *(unsigned int *) ap
;
3705 unsigned int b
= *(unsigned int *) bp
;
3707 return (a
> b
) - (b
> a
);
3710 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
3711 Inherit only the children of the DW_AT_abstract_origin DIE not being already
3712 referenced by DW_AT_abstract_origin from the children of the current DIE. */
3715 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
3717 struct die_info
*child_die
;
3718 unsigned die_children_count
;
3719 /* CU offsets which were referenced by children of the current DIE. */
3721 unsigned *offsets_end
, *offsetp
;
3722 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
3723 struct die_info
*origin_die
;
3724 /* Iterator of the ORIGIN_DIE children. */
3725 struct die_info
*origin_child_die
;
3726 struct cleanup
*cleanups
;
3727 struct attribute
*attr
;
3729 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
3733 origin_die
= follow_die_ref (die
, attr
, &cu
);
3734 if (die
->tag
!= origin_die
->tag
3735 && !(die
->tag
== DW_TAG_inlined_subroutine
3736 && origin_die
->tag
== DW_TAG_subprogram
))
3737 complaint (&symfile_complaints
,
3738 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
3739 die
->offset
, origin_die
->offset
);
3741 child_die
= die
->child
;
3742 die_children_count
= 0;
3743 while (child_die
&& child_die
->tag
)
3745 child_die
= sibling_die (child_die
);
3746 die_children_count
++;
3748 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
3749 cleanups
= make_cleanup (xfree
, offsets
);
3751 offsets_end
= offsets
;
3752 child_die
= die
->child
;
3753 while (child_die
&& child_die
->tag
)
3755 /* For each CHILD_DIE, find the corresponding child of
3756 ORIGIN_DIE. If there is more than one layer of
3757 DW_AT_abstract_origin, follow them all; there shouldn't be,
3758 but GCC versions at least through 4.4 generate this (GCC PR
3760 struct die_info
*child_origin_die
= child_die
;
3763 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
, cu
);
3766 child_origin_die
= follow_die_ref (child_origin_die
, attr
, &cu
);
3769 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
3770 counterpart may exist. */
3771 if (child_origin_die
!= child_die
)
3773 if (child_die
->tag
!= child_origin_die
->tag
3774 && !(child_die
->tag
== DW_TAG_inlined_subroutine
3775 && child_origin_die
->tag
== DW_TAG_subprogram
))
3776 complaint (&symfile_complaints
,
3777 _("Child DIE 0x%x and its abstract origin 0x%x have "
3778 "different tags"), child_die
->offset
,
3779 child_origin_die
->offset
);
3780 if (child_origin_die
->parent
!= origin_die
)
3781 complaint (&symfile_complaints
,
3782 _("Child DIE 0x%x and its abstract origin 0x%x have "
3783 "different parents"), child_die
->offset
,
3784 child_origin_die
->offset
);
3786 *offsets_end
++ = child_origin_die
->offset
;
3788 child_die
= sibling_die (child_die
);
3790 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
3791 unsigned_int_compar
);
3792 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
3793 if (offsetp
[-1] == *offsetp
)
3794 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
3795 "to DIE 0x%x as their abstract origin"),
3796 die
->offset
, *offsetp
);
3799 origin_child_die
= origin_die
->child
;
3800 while (origin_child_die
&& origin_child_die
->tag
)
3802 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
3803 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
3805 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
3807 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
3808 process_die (origin_child_die
, cu
);
3810 origin_child_die
= sibling_die (origin_child_die
);
3813 do_cleanups (cleanups
);
3817 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3819 struct objfile
*objfile
= cu
->objfile
;
3820 struct context_stack
*new;
3823 struct die_info
*child_die
;
3824 struct attribute
*attr
, *call_line
, *call_file
;
3827 struct block
*block
;
3828 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
3832 /* If we do not have call site information, we can't show the
3833 caller of this inlined function. That's too confusing, so
3834 only use the scope for local variables. */
3835 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
3836 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
3837 if (call_line
== NULL
|| call_file
== NULL
)
3839 read_lexical_block_scope (die
, cu
);
3844 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3846 name
= dwarf2_linkage_name (die
, cu
);
3848 /* Ignore functions with missing or empty names and functions with
3849 missing or invalid low and high pc attributes. */
3850 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
3856 /* Record the function range for dwarf_decode_lines. */
3857 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3859 new = push_context (0, lowpc
);
3860 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3862 /* If there is a location expression for DW_AT_frame_base, record
3864 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3866 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3867 expression is being recorded directly in the function's symbol
3868 and not in a separate frame-base object. I guess this hack is
3869 to avoid adding some sort of frame-base adjunct/annex to the
3870 function's symbol :-(. The problem with doing this is that it
3871 results in a function symbol with a location expression that
3872 has nothing to do with the location of the function, ouch! The
3873 relationship should be: a function's symbol has-a frame base; a
3874 frame-base has-a location expression. */
3875 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3877 cu
->list_in_scope
= &local_symbols
;
3879 if (die
->child
!= NULL
)
3881 child_die
= die
->child
;
3882 while (child_die
&& child_die
->tag
)
3884 process_die (child_die
, cu
);
3885 child_die
= sibling_die (child_die
);
3889 inherit_abstract_dies (die
, cu
);
3891 new = pop_context ();
3892 /* Make a block for the local symbols within. */
3893 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3894 lowpc
, highpc
, objfile
);
3896 /* For C++, set the block's scope. */
3897 if (cu
->language
== language_cplus
)
3898 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3899 determine_prefix (die
, cu
),
3900 processing_has_namespace_info
);
3902 /* If we have address ranges, record them. */
3903 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3905 /* In C++, we can have functions nested inside functions (e.g., when
3906 a function declares a class that has methods). This means that
3907 when we finish processing a function scope, we may need to go
3908 back to building a containing block's symbol lists. */
3909 local_symbols
= new->locals
;
3910 param_symbols
= new->params
;
3911 using_directives
= new->using_directives
;
3913 /* If we've finished processing a top-level function, subsequent
3914 symbols go in the file symbol list. */
3915 if (outermost_context_p ())
3916 cu
->list_in_scope
= &file_symbols
;
3919 /* Process all the DIES contained within a lexical block scope. Start
3920 a new scope, process the dies, and then close the scope. */
3923 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3925 struct objfile
*objfile
= cu
->objfile
;
3926 struct context_stack
*new;
3927 CORE_ADDR lowpc
, highpc
;
3928 struct die_info
*child_die
;
3931 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3933 /* Ignore blocks with missing or invalid low and high pc attributes. */
3934 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3935 as multiple lexical blocks? Handling children in a sane way would
3936 be nasty. Might be easier to properly extend generic blocks to
3938 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
3943 push_context (0, lowpc
);
3944 if (die
->child
!= NULL
)
3946 child_die
= die
->child
;
3947 while (child_die
&& child_die
->tag
)
3949 process_die (child_die
, cu
);
3950 child_die
= sibling_die (child_die
);
3953 new = pop_context ();
3955 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
3958 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3961 /* Note that recording ranges after traversing children, as we
3962 do here, means that recording a parent's ranges entails
3963 walking across all its children's ranges as they appear in
3964 the address map, which is quadratic behavior.
3966 It would be nicer to record the parent's ranges before
3967 traversing its children, simply overriding whatever you find
3968 there. But since we don't even decide whether to create a
3969 block until after we've traversed its children, that's hard
3971 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3973 local_symbols
= new->locals
;
3974 using_directives
= new->using_directives
;
3977 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3978 Return 1 if the attributes are present and valid, otherwise, return 0.
3979 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3982 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3983 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3984 struct partial_symtab
*ranges_pst
)
3986 struct objfile
*objfile
= cu
->objfile
;
3987 struct comp_unit_head
*cu_header
= &cu
->header
;
3988 bfd
*obfd
= objfile
->obfd
;
3989 unsigned int addr_size
= cu_header
->addr_size
;
3990 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3991 /* Base address selection entry. */
4002 found_base
= cu
->base_known
;
4003 base
= cu
->base_address
;
4005 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
4007 complaint (&symfile_complaints
,
4008 _("Offset %d out of bounds for DW_AT_ranges attribute"),
4012 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
4014 /* Read in the largest possible address. */
4015 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
4016 if ((marker
& mask
) == mask
)
4018 /* If we found the largest possible address, then
4019 read the base address. */
4020 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
4021 buffer
+= 2 * addr_size
;
4022 offset
+= 2 * addr_size
;
4028 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4032 CORE_ADDR range_beginning
, range_end
;
4034 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
4035 buffer
+= addr_size
;
4036 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
4037 buffer
+= addr_size
;
4038 offset
+= 2 * addr_size
;
4040 /* An end of list marker is a pair of zero addresses. */
4041 if (range_beginning
== 0 && range_end
== 0)
4042 /* Found the end of list entry. */
4045 /* Each base address selection entry is a pair of 2 values.
4046 The first is the largest possible address, the second is
4047 the base address. Check for a base address here. */
4048 if ((range_beginning
& mask
) == mask
)
4050 /* If we found the largest possible address, then
4051 read the base address. */
4052 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
4059 /* We have no valid base address for the ranges
4061 complaint (&symfile_complaints
,
4062 _("Invalid .debug_ranges data (no base address)"));
4066 range_beginning
+= base
;
4069 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
4070 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4071 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
4074 /* FIXME: This is recording everything as a low-high
4075 segment of consecutive addresses. We should have a
4076 data structure for discontiguous block ranges
4080 low
= range_beginning
;
4086 if (range_beginning
< low
)
4087 low
= range_beginning
;
4088 if (range_end
> high
)
4094 /* If the first entry is an end-of-list marker, the range
4095 describes an empty scope, i.e. no instructions. */
4101 *high_return
= high
;
4105 /* Get low and high pc attributes from a die. Return 1 if the attributes
4106 are present and valid, otherwise, return 0. Return -1 if the range is
4107 discontinuous, i.e. derived from DW_AT_ranges information. */
4109 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
4110 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
4111 struct partial_symtab
*pst
)
4113 struct attribute
*attr
;
4118 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
4121 high
= DW_ADDR (attr
);
4122 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4124 low
= DW_ADDR (attr
);
4126 /* Found high w/o low attribute. */
4129 /* Found consecutive range of addresses. */
4134 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
4137 /* Value of the DW_AT_ranges attribute is the offset in the
4138 .debug_ranges section. */
4139 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
4141 /* Found discontinuous range of addresses. */
4149 /* When using the GNU linker, .gnu.linkonce. sections are used to
4150 eliminate duplicate copies of functions and vtables and such.
4151 The linker will arbitrarily choose one and discard the others.
4152 The AT_*_pc values for such functions refer to local labels in
4153 these sections. If the section from that file was discarded, the
4154 labels are not in the output, so the relocs get a value of 0.
4155 If this is a discarded function, mark the pc bounds as invalid,
4156 so that GDB will ignore it. */
4157 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
4165 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
4166 its low and high PC addresses. Do nothing if these addresses could not
4167 be determined. Otherwise, set LOWPC to the low address if it is smaller,
4168 and HIGHPC to the high address if greater than HIGHPC. */
4171 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
4172 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4173 struct dwarf2_cu
*cu
)
4175 CORE_ADDR low
, high
;
4176 struct die_info
*child
= die
->child
;
4178 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
4180 *lowpc
= min (*lowpc
, low
);
4181 *highpc
= max (*highpc
, high
);
4184 /* If the language does not allow nested subprograms (either inside
4185 subprograms or lexical blocks), we're done. */
4186 if (cu
->language
!= language_ada
)
4189 /* Check all the children of the given DIE. If it contains nested
4190 subprograms, then check their pc bounds. Likewise, we need to
4191 check lexical blocks as well, as they may also contain subprogram
4193 while (child
&& child
->tag
)
4195 if (child
->tag
== DW_TAG_subprogram
4196 || child
->tag
== DW_TAG_lexical_block
)
4197 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
4198 child
= sibling_die (child
);
4202 /* Get the low and high pc's represented by the scope DIE, and store
4203 them in *LOWPC and *HIGHPC. If the correct values can't be
4204 determined, set *LOWPC to -1 and *HIGHPC to 0. */
4207 get_scope_pc_bounds (struct die_info
*die
,
4208 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4209 struct dwarf2_cu
*cu
)
4211 CORE_ADDR best_low
= (CORE_ADDR
) -1;
4212 CORE_ADDR best_high
= (CORE_ADDR
) 0;
4213 CORE_ADDR current_low
, current_high
;
4215 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
4217 best_low
= current_low
;
4218 best_high
= current_high
;
4222 struct die_info
*child
= die
->child
;
4224 while (child
&& child
->tag
)
4226 switch (child
->tag
) {
4227 case DW_TAG_subprogram
:
4228 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
4230 case DW_TAG_namespace
:
4231 /* FIXME: carlton/2004-01-16: Should we do this for
4232 DW_TAG_class_type/DW_TAG_structure_type, too? I think
4233 that current GCC's always emit the DIEs corresponding
4234 to definitions of methods of classes as children of a
4235 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
4236 the DIEs giving the declarations, which could be
4237 anywhere). But I don't see any reason why the
4238 standards says that they have to be there. */
4239 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
4241 if (current_low
!= ((CORE_ADDR
) -1))
4243 best_low
= min (best_low
, current_low
);
4244 best_high
= max (best_high
, current_high
);
4252 child
= sibling_die (child
);
4257 *highpc
= best_high
;
4260 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
4263 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
4264 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
4266 struct attribute
*attr
;
4268 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
4271 CORE_ADDR high
= DW_ADDR (attr
);
4272 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4275 CORE_ADDR low
= DW_ADDR (attr
);
4276 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
4280 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
4283 bfd
*obfd
= cu
->objfile
->obfd
;
4285 /* The value of the DW_AT_ranges attribute is the offset of the
4286 address range list in the .debug_ranges section. */
4287 unsigned long offset
= DW_UNSND (attr
);
4288 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
4290 /* For some target architectures, but not others, the
4291 read_address function sign-extends the addresses it returns.
4292 To recognize base address selection entries, we need a
4294 unsigned int addr_size
= cu
->header
.addr_size
;
4295 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
4297 /* The base address, to which the next pair is relative. Note
4298 that this 'base' is a DWARF concept: most entries in a range
4299 list are relative, to reduce the number of relocs against the
4300 debugging information. This is separate from this function's
4301 'baseaddr' argument, which GDB uses to relocate debugging
4302 information from a shared library based on the address at
4303 which the library was loaded. */
4304 CORE_ADDR base
= cu
->base_address
;
4305 int base_known
= cu
->base_known
;
4307 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
4309 complaint (&symfile_complaints
,
4310 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
4317 unsigned int bytes_read
;
4318 CORE_ADDR start
, end
;
4320 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
4321 buffer
+= bytes_read
;
4322 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
4323 buffer
+= bytes_read
;
4325 /* Did we find the end of the range list? */
4326 if (start
== 0 && end
== 0)
4329 /* Did we find a base address selection entry? */
4330 else if ((start
& base_select_mask
) == base_select_mask
)
4336 /* We found an ordinary address range. */
4341 complaint (&symfile_complaints
,
4342 _("Invalid .debug_ranges data (no base address)"));
4346 record_block_range (block
,
4347 baseaddr
+ base
+ start
,
4348 baseaddr
+ base
+ end
- 1);
4354 /* Add an aggregate field to the field list. */
4357 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
4358 struct dwarf2_cu
*cu
)
4360 struct objfile
*objfile
= cu
->objfile
;
4361 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4362 struct nextfield
*new_field
;
4363 struct attribute
*attr
;
4365 char *fieldname
= "";
4367 /* Allocate a new field list entry and link it in. */
4368 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
4369 make_cleanup (xfree
, new_field
);
4370 memset (new_field
, 0, sizeof (struct nextfield
));
4372 if (die
->tag
== DW_TAG_inheritance
)
4374 new_field
->next
= fip
->baseclasses
;
4375 fip
->baseclasses
= new_field
;
4379 new_field
->next
= fip
->fields
;
4380 fip
->fields
= new_field
;
4384 /* Handle accessibility and virtuality of field.
4385 The default accessibility for members is public, the default
4386 accessibility for inheritance is private. */
4387 if (die
->tag
!= DW_TAG_inheritance
)
4388 new_field
->accessibility
= DW_ACCESS_public
;
4390 new_field
->accessibility
= DW_ACCESS_private
;
4391 new_field
->virtuality
= DW_VIRTUALITY_none
;
4393 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
4395 new_field
->accessibility
= DW_UNSND (attr
);
4396 if (new_field
->accessibility
!= DW_ACCESS_public
)
4397 fip
->non_public_fields
= 1;
4398 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
4400 new_field
->virtuality
= DW_UNSND (attr
);
4402 fp
= &new_field
->field
;
4404 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
4406 /* Data member other than a C++ static data member. */
4408 /* Get type of field. */
4409 fp
->type
= die_type (die
, cu
);
4411 SET_FIELD_BITPOS (*fp
, 0);
4413 /* Get bit size of field (zero if none). */
4414 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
4417 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
4421 FIELD_BITSIZE (*fp
) = 0;
4424 /* Get bit offset of field. */
4425 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
4428 int byte_offset
= 0;
4430 if (attr_form_is_section_offset (attr
))
4431 dwarf2_complex_location_expr_complaint ();
4432 else if (attr_form_is_constant (attr
))
4433 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
4434 else if (attr_form_is_block (attr
))
4435 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
4437 dwarf2_complex_location_expr_complaint ();
4439 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
4441 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
4444 if (gdbarch_bits_big_endian (gdbarch
))
4446 /* For big endian bits, the DW_AT_bit_offset gives the
4447 additional bit offset from the MSB of the containing
4448 anonymous object to the MSB of the field. We don't
4449 have to do anything special since we don't need to
4450 know the size of the anonymous object. */
4451 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
4455 /* For little endian bits, compute the bit offset to the
4456 MSB of the anonymous object, subtract off the number of
4457 bits from the MSB of the field to the MSB of the
4458 object, and then subtract off the number of bits of
4459 the field itself. The result is the bit offset of
4460 the LSB of the field. */
4462 int bit_offset
= DW_UNSND (attr
);
4464 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4467 /* The size of the anonymous object containing
4468 the bit field is explicit, so use the
4469 indicated size (in bytes). */
4470 anonymous_size
= DW_UNSND (attr
);
4474 /* The size of the anonymous object containing
4475 the bit field must be inferred from the type
4476 attribute of the data member containing the
4478 anonymous_size
= TYPE_LENGTH (fp
->type
);
4480 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
4481 - bit_offset
- FIELD_BITSIZE (*fp
);
4485 /* Get name of field. */
4486 fieldname
= dwarf2_name (die
, cu
);
4487 if (fieldname
== NULL
)
4490 /* The name is already allocated along with this objfile, so we don't
4491 need to duplicate it for the type. */
4492 fp
->name
= fieldname
;
4494 /* Change accessibility for artificial fields (e.g. virtual table
4495 pointer or virtual base class pointer) to private. */
4496 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
4498 FIELD_ARTIFICIAL (*fp
) = 1;
4499 new_field
->accessibility
= DW_ACCESS_private
;
4500 fip
->non_public_fields
= 1;
4503 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
4505 /* C++ static member. */
4507 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
4508 is a declaration, but all versions of G++ as of this writing
4509 (so through at least 3.2.1) incorrectly generate
4510 DW_TAG_variable tags. */
4514 /* Get name of field. */
4515 fieldname
= dwarf2_name (die
, cu
);
4516 if (fieldname
== NULL
)
4519 /* Get physical name. */
4520 physname
= dwarf2_linkage_name (die
, cu
);
4522 /* The name is already allocated along with this objfile, so we don't
4523 need to duplicate it for the type. */
4524 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
4525 FIELD_TYPE (*fp
) = die_type (die
, cu
);
4526 FIELD_NAME (*fp
) = fieldname
;
4528 else if (die
->tag
== DW_TAG_inheritance
)
4530 /* C++ base class field. */
4531 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
4534 int byte_offset
= 0;
4536 if (attr_form_is_section_offset (attr
))
4537 dwarf2_complex_location_expr_complaint ();
4538 else if (attr_form_is_constant (attr
))
4539 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
4540 else if (attr_form_is_block (attr
))
4541 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
4543 dwarf2_complex_location_expr_complaint ();
4545 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
4547 FIELD_BITSIZE (*fp
) = 0;
4548 FIELD_TYPE (*fp
) = die_type (die
, cu
);
4549 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
4550 fip
->nbaseclasses
++;
4554 /* Create the vector of fields, and attach it to the type. */
4557 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
4558 struct dwarf2_cu
*cu
)
4560 int nfields
= fip
->nfields
;
4562 /* Record the field count, allocate space for the array of fields,
4563 and create blank accessibility bitfields if necessary. */
4564 TYPE_NFIELDS (type
) = nfields
;
4565 TYPE_FIELDS (type
) = (struct field
*)
4566 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
4567 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
4569 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
4571 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4573 TYPE_FIELD_PRIVATE_BITS (type
) =
4574 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4575 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
4577 TYPE_FIELD_PROTECTED_BITS (type
) =
4578 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4579 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
4581 TYPE_FIELD_IGNORE_BITS (type
) =
4582 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4583 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
4586 /* If the type has baseclasses, allocate and clear a bit vector for
4587 TYPE_FIELD_VIRTUAL_BITS. */
4588 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
4590 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
4591 unsigned char *pointer
;
4593 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4594 pointer
= TYPE_ALLOC (type
, num_bytes
);
4595 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
4596 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
4597 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
4600 /* Copy the saved-up fields into the field vector. Start from the head
4601 of the list, adding to the tail of the field array, so that they end
4602 up in the same order in the array in which they were added to the list. */
4603 while (nfields
-- > 0)
4605 struct nextfield
*fieldp
;
4609 fieldp
= fip
->fields
;
4610 fip
->fields
= fieldp
->next
;
4614 fieldp
= fip
->baseclasses
;
4615 fip
->baseclasses
= fieldp
->next
;
4618 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
4619 switch (fieldp
->accessibility
)
4621 case DW_ACCESS_private
:
4622 if (cu
->language
!= language_ada
)
4623 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
4626 case DW_ACCESS_protected
:
4627 if (cu
->language
!= language_ada
)
4628 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
4631 case DW_ACCESS_public
:
4635 /* Unknown accessibility. Complain and treat it as public. */
4637 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
4638 fieldp
->accessibility
);
4642 if (nfields
< fip
->nbaseclasses
)
4644 switch (fieldp
->virtuality
)
4646 case DW_VIRTUALITY_virtual
:
4647 case DW_VIRTUALITY_pure_virtual
:
4648 if (cu
->language
== language_ada
)
4649 error ("unexpected virtuality in component of Ada type");
4650 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
4657 /* Add a member function to the proper fieldlist. */
4660 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
4661 struct type
*type
, struct dwarf2_cu
*cu
)
4663 struct objfile
*objfile
= cu
->objfile
;
4664 struct attribute
*attr
;
4665 struct fnfieldlist
*flp
;
4667 struct fn_field
*fnp
;
4670 struct nextfnfield
*new_fnfield
;
4671 struct type
*this_type
;
4673 if (cu
->language
== language_ada
)
4674 error ("unexpected member function in Ada type");
4676 /* Get name of member function. */
4677 fieldname
= dwarf2_name (die
, cu
);
4678 if (fieldname
== NULL
)
4681 /* Get the mangled name. */
4682 physname
= dwarf2_linkage_name (die
, cu
);
4684 /* Look up member function name in fieldlist. */
4685 for (i
= 0; i
< fip
->nfnfields
; i
++)
4687 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
4691 /* Create new list element if necessary. */
4692 if (i
< fip
->nfnfields
)
4693 flp
= &fip
->fnfieldlists
[i
];
4696 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4698 fip
->fnfieldlists
= (struct fnfieldlist
*)
4699 xrealloc (fip
->fnfieldlists
,
4700 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
4701 * sizeof (struct fnfieldlist
));
4702 if (fip
->nfnfields
== 0)
4703 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
4705 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
4706 flp
->name
= fieldname
;
4712 /* Create a new member function field and chain it to the field list
4714 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
4715 make_cleanup (xfree
, new_fnfield
);
4716 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
4717 new_fnfield
->next
= flp
->head
;
4718 flp
->head
= new_fnfield
;
4721 /* Fill in the member function field info. */
4722 fnp
= &new_fnfield
->fnfield
;
4723 /* The name is already allocated along with this objfile, so we don't
4724 need to duplicate it for the type. */
4725 fnp
->physname
= physname
? physname
: "";
4726 fnp
->type
= alloc_type (objfile
);
4727 this_type
= read_type_die (die
, cu
);
4728 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
4730 int nparams
= TYPE_NFIELDS (this_type
);
4732 /* TYPE is the domain of this method, and THIS_TYPE is the type
4733 of the method itself (TYPE_CODE_METHOD). */
4734 smash_to_method_type (fnp
->type
, type
,
4735 TYPE_TARGET_TYPE (this_type
),
4736 TYPE_FIELDS (this_type
),
4737 TYPE_NFIELDS (this_type
),
4738 TYPE_VARARGS (this_type
));
4740 /* Handle static member functions.
4741 Dwarf2 has no clean way to discern C++ static and non-static
4742 member functions. G++ helps GDB by marking the first
4743 parameter for non-static member functions (which is the
4744 this pointer) as artificial. We obtain this information
4745 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
4746 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
4747 fnp
->voffset
= VOFFSET_STATIC
;
4750 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
4753 /* Get fcontext from DW_AT_containing_type if present. */
4754 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4755 fnp
->fcontext
= die_containing_type (die
, cu
);
4757 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
4758 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
4760 /* Get accessibility. */
4761 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
4764 switch (DW_UNSND (attr
))
4766 case DW_ACCESS_private
:
4767 fnp
->is_private
= 1;
4769 case DW_ACCESS_protected
:
4770 fnp
->is_protected
= 1;
4775 /* Check for artificial methods. */
4776 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
4777 if (attr
&& DW_UNSND (attr
) != 0)
4778 fnp
->is_artificial
= 1;
4780 /* Get index in virtual function table if it is a virtual member
4781 function. For GCC, this is an offset in the appropriate
4782 virtual table, as specified by DW_AT_containing_type. For
4783 everyone else, it is an expression to be evaluated relative
4784 to the object address. */
4786 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
4787 if (attr
&& fnp
->fcontext
)
4789 /* Support the .debug_loc offsets */
4790 if (attr_form_is_block (attr
))
4792 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
4794 else if (attr_form_is_section_offset (attr
))
4796 dwarf2_complex_location_expr_complaint ();
4800 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
4806 /* We only support trivial expressions here. This hack will work
4807 for v3 classes, which always start with the vtable pointer. */
4808 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0
4809 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref
)
4811 struct dwarf_block blk
;
4812 blk
.size
= DW_BLOCK (attr
)->size
- 1;
4813 blk
.data
= DW_BLOCK (attr
)->data
+ 1;
4814 fnp
->voffset
= decode_locdesc (&blk
, cu
);
4815 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
4816 dwarf2_complex_location_expr_complaint ();
4818 fnp
->voffset
/= cu
->header
.addr_size
;
4820 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
4823 dwarf2_complex_location_expr_complaint ();
4827 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
4828 if (attr
&& DW_UNSND (attr
))
4830 /* GCC does this, as of 2008-08-25; PR debug/37237. */
4831 complaint (&symfile_complaints
,
4832 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
4833 fieldname
, die
->offset
);
4834 TYPE_CPLUS_DYNAMIC (type
) = 1;
4839 /* Create the vector of member function fields, and attach it to the type. */
4842 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
4843 struct dwarf2_cu
*cu
)
4845 struct fnfieldlist
*flp
;
4846 int total_length
= 0;
4849 if (cu
->language
== language_ada
)
4850 error ("unexpected member functions in Ada type");
4852 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4853 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
4854 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
4856 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
4858 struct nextfnfield
*nfp
= flp
->head
;
4859 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
4862 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
4863 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
4864 fn_flp
->fn_fields
= (struct fn_field
*)
4865 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
4866 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
4867 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
4869 total_length
+= flp
->length
;
4872 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
4873 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
4876 /* Returns non-zero if NAME is the name of a vtable member in CU's
4877 language, zero otherwise. */
4879 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
4881 static const char vptr
[] = "_vptr";
4882 static const char vtable
[] = "vtable";
4884 /* Look for the C++ and Java forms of the vtable. */
4885 if ((cu
->language
== language_java
4886 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
4887 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
4888 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
4894 /* GCC outputs unnamed structures that are really pointers to member
4895 functions, with the ABI-specified layout. If TYPE describes
4896 such a structure, smash it into a member function type.
4898 GCC shouldn't do this; it should just output pointer to member DIEs.
4899 This is GCC PR debug/28767. */
4902 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
4904 struct type
*pfn_type
, *domain_type
, *new_type
;
4906 /* Check for a structure with no name and two children. */
4907 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
4910 /* Check for __pfn and __delta members. */
4911 if (TYPE_FIELD_NAME (type
, 0) == NULL
4912 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
4913 || TYPE_FIELD_NAME (type
, 1) == NULL
4914 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
4917 /* Find the type of the method. */
4918 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
4919 if (pfn_type
== NULL
4920 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
4921 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
4924 /* Look for the "this" argument. */
4925 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
4926 if (TYPE_NFIELDS (pfn_type
) == 0
4927 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
4928 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
4931 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
4932 new_type
= alloc_type (objfile
);
4933 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
4934 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
4935 TYPE_VARARGS (pfn_type
));
4936 smash_to_methodptr_type (type
, new_type
);
4939 /* Called when we find the DIE that starts a structure or union scope
4940 (definition) to process all dies that define the members of the
4943 NOTE: we need to call struct_type regardless of whether or not the
4944 DIE has an at_name attribute, since it might be an anonymous
4945 structure or union. This gets the type entered into our set of
4948 However, if the structure is incomplete (an opaque struct/union)
4949 then suppress creating a symbol table entry for it since gdb only
4950 wants to find the one with the complete definition. Note that if
4951 it is complete, we just call new_symbol, which does it's own
4952 checking about whether the struct/union is anonymous or not (and
4953 suppresses creating a symbol table entry itself). */
4955 static struct type
*
4956 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4958 struct objfile
*objfile
= cu
->objfile
;
4960 struct attribute
*attr
;
4962 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4964 /* If the definition of this type lives in .debug_types, read that type.
4965 Don't follow DW_AT_specification though, that will take us back up
4966 the chain and we want to go down. */
4967 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
4970 struct dwarf2_cu
*type_cu
= cu
;
4971 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
4972 /* We could just recurse on read_structure_type, but we need to call
4973 get_die_type to ensure only one type for this DIE is created.
4974 This is important, for example, because for c++ classes we need
4975 TYPE_NAME set which is only done by new_symbol. Blech. */
4976 type
= read_type_die (type_die
, type_cu
);
4977 return set_die_type (die
, type
, cu
);
4980 type
= alloc_type (objfile
);
4981 INIT_CPLUS_SPECIFIC (type
);
4983 name
= dwarf2_name (die
, cu
);
4986 if (cu
->language
== language_cplus
4987 || cu
->language
== language_java
)
4989 const char *new_prefix
= determine_class_name (die
, cu
);
4990 TYPE_TAG_NAME (type
) = (char *) new_prefix
;
4994 /* The name is already allocated along with this objfile, so
4995 we don't need to duplicate it for the type. */
4996 TYPE_TAG_NAME (type
) = name
;
5000 if (die
->tag
== DW_TAG_structure_type
)
5002 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
5004 else if (die
->tag
== DW_TAG_union_type
)
5006 TYPE_CODE (type
) = TYPE_CODE_UNION
;
5010 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
5013 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
5014 TYPE_DECLARED_CLASS (type
) = 1;
5016 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5019 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5023 TYPE_LENGTH (type
) = 0;
5026 TYPE_STUB_SUPPORTED (type
) = 1;
5027 if (die_is_declaration (die
, cu
))
5028 TYPE_STUB (type
) = 1;
5030 set_descriptive_type (type
, die
, cu
);
5032 /* We need to add the type field to the die immediately so we don't
5033 infinitely recurse when dealing with pointers to the structure
5034 type within the structure itself. */
5035 set_die_type (die
, type
, cu
);
5037 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
5039 struct field_info fi
;
5040 struct die_info
*child_die
;
5042 memset (&fi
, 0, sizeof (struct field_info
));
5044 child_die
= die
->child
;
5046 while (child_die
&& child_die
->tag
)
5048 if (child_die
->tag
== DW_TAG_member
5049 || child_die
->tag
== DW_TAG_variable
)
5051 /* NOTE: carlton/2002-11-05: A C++ static data member
5052 should be a DW_TAG_member that is a declaration, but
5053 all versions of G++ as of this writing (so through at
5054 least 3.2.1) incorrectly generate DW_TAG_variable
5055 tags for them instead. */
5056 dwarf2_add_field (&fi
, child_die
, cu
);
5058 else if (child_die
->tag
== DW_TAG_subprogram
)
5060 /* C++ member function. */
5061 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
5063 else if (child_die
->tag
== DW_TAG_inheritance
)
5065 /* C++ base class field. */
5066 dwarf2_add_field (&fi
, child_die
, cu
);
5068 child_die
= sibling_die (child_die
);
5071 /* Attach fields and member functions to the type. */
5073 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
5076 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
5078 /* Get the type which refers to the base class (possibly this
5079 class itself) which contains the vtable pointer for the current
5080 class from the DW_AT_containing_type attribute. This use of
5081 DW_AT_containing_type is a GNU extension. */
5083 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
5085 struct type
*t
= die_containing_type (die
, cu
);
5087 TYPE_VPTR_BASETYPE (type
) = t
;
5092 /* Our own class provides vtbl ptr. */
5093 for (i
= TYPE_NFIELDS (t
) - 1;
5094 i
>= TYPE_N_BASECLASSES (t
);
5097 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
5099 if (is_vtable_name (fieldname
, cu
))
5101 TYPE_VPTR_FIELDNO (type
) = i
;
5106 /* Complain if virtual function table field not found. */
5107 if (i
< TYPE_N_BASECLASSES (t
))
5108 complaint (&symfile_complaints
,
5109 _("virtual function table pointer not found when defining class '%s'"),
5110 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
5115 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
5118 else if (cu
->producer
5119 && strncmp (cu
->producer
,
5120 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
5122 /* The IBM XLC compiler does not provide direct indication
5123 of the containing type, but the vtable pointer is
5124 always named __vfp. */
5128 for (i
= TYPE_NFIELDS (type
) - 1;
5129 i
>= TYPE_N_BASECLASSES (type
);
5132 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
5134 TYPE_VPTR_FIELDNO (type
) = i
;
5135 TYPE_VPTR_BASETYPE (type
) = type
;
5143 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
5145 do_cleanups (back_to
);
5150 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5152 struct objfile
*objfile
= cu
->objfile
;
5153 struct die_info
*child_die
= die
->child
;
5154 struct type
*this_type
;
5156 this_type
= get_die_type (die
, cu
);
5157 if (this_type
== NULL
)
5158 this_type
= read_structure_type (die
, cu
);
5160 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
5161 snapshots) has been known to create a die giving a declaration
5162 for a class that has, as a child, a die giving a definition for a
5163 nested class. So we have to process our children even if the
5164 current die is a declaration. Normally, of course, a declaration
5165 won't have any children at all. */
5167 while (child_die
!= NULL
&& child_die
->tag
)
5169 if (child_die
->tag
== DW_TAG_member
5170 || child_die
->tag
== DW_TAG_variable
5171 || child_die
->tag
== DW_TAG_inheritance
)
5176 process_die (child_die
, cu
);
5178 child_die
= sibling_die (child_die
);
5181 /* Do not consider external references. According to the DWARF standard,
5182 these DIEs are identified by the fact that they have no byte_size
5183 attribute, and a declaration attribute. */
5184 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
5185 || !die_is_declaration (die
, cu
))
5186 new_symbol (die
, this_type
, cu
);
5189 /* Given a DW_AT_enumeration_type die, set its type. We do not
5190 complete the type's fields yet, or create any symbols. */
5192 static struct type
*
5193 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5195 struct objfile
*objfile
= cu
->objfile
;
5197 struct attribute
*attr
;
5200 /* If the definition of this type lives in .debug_types, read that type.
5201 Don't follow DW_AT_specification though, that will take us back up
5202 the chain and we want to go down. */
5203 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
5206 struct dwarf2_cu
*type_cu
= cu
;
5207 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
5208 type
= read_type_die (type_die
, type_cu
);
5209 return set_die_type (die
, type
, cu
);
5212 type
= alloc_type (objfile
);
5214 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
5215 name
= dwarf2_full_name (die
, cu
);
5217 TYPE_TAG_NAME (type
) = (char *) name
;
5219 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5222 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5226 TYPE_LENGTH (type
) = 0;
5229 /* The enumeration DIE can be incomplete. In Ada, any type can be
5230 declared as private in the package spec, and then defined only
5231 inside the package body. Such types are known as Taft Amendment
5232 Types. When another package uses such a type, an incomplete DIE
5233 may be generated by the compiler. */
5234 if (die_is_declaration (die
, cu
))
5235 TYPE_STUB (type
) = 1;
5237 return set_die_type (die
, type
, cu
);
5240 /* Determine the name of the type represented by DIE, which should be
5241 a named C++ or Java compound type. Return the name in question,
5242 allocated on the objfile obstack. */
5245 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
5247 const char *new_prefix
= NULL
;
5249 /* If we don't have namespace debug info, guess the name by trying
5250 to demangle the names of members, just like we did in
5251 guess_structure_name. */
5252 if (!processing_has_namespace_info
)
5254 struct die_info
*child
;
5256 for (child
= die
->child
;
5257 child
!= NULL
&& child
->tag
!= 0;
5258 child
= sibling_die (child
))
5260 if (child
->tag
== DW_TAG_subprogram
)
5263 = language_class_name_from_physname (cu
->language_defn
,
5267 if (phys_prefix
!= NULL
)
5270 = obsavestring (phys_prefix
, strlen (phys_prefix
),
5271 &cu
->objfile
->objfile_obstack
);
5272 xfree (phys_prefix
);
5279 if (new_prefix
== NULL
)
5280 new_prefix
= dwarf2_full_name (die
, cu
);
5285 /* Given a pointer to a die which begins an enumeration, process all
5286 the dies that define the members of the enumeration, and create the
5287 symbol for the enumeration type.
5289 NOTE: We reverse the order of the element list. */
5292 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5294 struct objfile
*objfile
= cu
->objfile
;
5295 struct die_info
*child_die
;
5296 struct field
*fields
;
5299 int unsigned_enum
= 1;
5301 struct type
*this_type
;
5305 this_type
= get_die_type (die
, cu
);
5306 if (this_type
== NULL
)
5307 this_type
= read_enumeration_type (die
, cu
);
5308 if (die
->child
!= NULL
)
5310 child_die
= die
->child
;
5311 while (child_die
&& child_die
->tag
)
5313 if (child_die
->tag
!= DW_TAG_enumerator
)
5315 process_die (child_die
, cu
);
5319 name
= dwarf2_name (child_die
, cu
);
5322 sym
= new_symbol (child_die
, this_type
, cu
);
5323 if (SYMBOL_VALUE (sym
) < 0)
5326 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
5328 fields
= (struct field
*)
5330 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
5331 * sizeof (struct field
));
5334 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
5335 FIELD_TYPE (fields
[num_fields
]) = NULL
;
5336 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
5337 FIELD_BITSIZE (fields
[num_fields
]) = 0;
5343 child_die
= sibling_die (child_die
);
5348 TYPE_NFIELDS (this_type
) = num_fields
;
5349 TYPE_FIELDS (this_type
) = (struct field
*)
5350 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
5351 memcpy (TYPE_FIELDS (this_type
), fields
,
5352 sizeof (struct field
) * num_fields
);
5356 TYPE_UNSIGNED (this_type
) = 1;
5359 new_symbol (die
, this_type
, cu
);
5362 /* Extract all information from a DW_TAG_array_type DIE and put it in
5363 the DIE's type field. For now, this only handles one dimensional
5366 static struct type
*
5367 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5369 struct objfile
*objfile
= cu
->objfile
;
5370 struct die_info
*child_die
;
5371 struct type
*type
= NULL
;
5372 struct type
*element_type
, *range_type
, *index_type
;
5373 struct type
**range_types
= NULL
;
5374 struct attribute
*attr
;
5376 struct cleanup
*back_to
;
5379 element_type
= die_type (die
, cu
);
5381 /* Irix 6.2 native cc creates array types without children for
5382 arrays with unspecified length. */
5383 if (die
->child
== NULL
)
5385 index_type
= objfile_type (objfile
)->builtin_int
;
5386 range_type
= create_range_type (NULL
, index_type
, 0, -1);
5387 type
= create_array_type (NULL
, element_type
, range_type
);
5388 return set_die_type (die
, type
, cu
);
5391 back_to
= make_cleanup (null_cleanup
, NULL
);
5392 child_die
= die
->child
;
5393 while (child_die
&& child_die
->tag
)
5395 if (child_die
->tag
== DW_TAG_subrange_type
)
5397 struct type
*child_type
= read_type_die (child_die
, cu
);
5398 if (child_type
!= NULL
)
5400 /* The range type was succesfully read. Save it for
5401 the array type creation. */
5402 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
5404 range_types
= (struct type
**)
5405 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
5406 * sizeof (struct type
*));
5408 make_cleanup (free_current_contents
, &range_types
);
5410 range_types
[ndim
++] = child_type
;
5413 child_die
= sibling_die (child_die
);
5416 /* Dwarf2 dimensions are output from left to right, create the
5417 necessary array types in backwards order. */
5419 type
= element_type
;
5421 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
5425 type
= create_array_type (NULL
, type
, range_types
[i
++]);
5430 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
5433 /* Understand Dwarf2 support for vector types (like they occur on
5434 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
5435 array type. This is not part of the Dwarf2/3 standard yet, but a
5436 custom vendor extension. The main difference between a regular
5437 array and the vector variant is that vectors are passed by value
5439 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
5441 make_vector_type (type
);
5443 name
= dwarf2_name (die
, cu
);
5445 TYPE_NAME (type
) = name
;
5447 set_descriptive_type (type
, die
, cu
);
5449 do_cleanups (back_to
);
5451 /* Install the type in the die. */
5452 return set_die_type (die
, type
, cu
);
5455 static enum dwarf_array_dim_ordering
5456 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
5458 struct attribute
*attr
;
5460 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
5462 if (attr
) return DW_SND (attr
);
5465 GNU F77 is a special case, as at 08/2004 array type info is the
5466 opposite order to the dwarf2 specification, but data is still
5467 laid out as per normal fortran.
5469 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
5473 if (cu
->language
== language_fortran
5474 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
5476 return DW_ORD_row_major
;
5479 switch (cu
->language_defn
->la_array_ordering
)
5481 case array_column_major
:
5482 return DW_ORD_col_major
;
5483 case array_row_major
:
5485 return DW_ORD_row_major
;
5489 /* Extract all information from a DW_TAG_set_type DIE and put it in
5490 the DIE's type field. */
5492 static struct type
*
5493 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5495 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
5497 return set_die_type (die
, set_type
, cu
);
5500 /* First cut: install each common block member as a global variable. */
5503 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
5505 struct die_info
*child_die
;
5506 struct attribute
*attr
;
5508 CORE_ADDR base
= (CORE_ADDR
) 0;
5510 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
5513 /* Support the .debug_loc offsets */
5514 if (attr_form_is_block (attr
))
5516 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
5518 else if (attr_form_is_section_offset (attr
))
5520 dwarf2_complex_location_expr_complaint ();
5524 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5525 "common block member");
5528 if (die
->child
!= NULL
)
5530 child_die
= die
->child
;
5531 while (child_die
&& child_die
->tag
)
5533 sym
= new_symbol (child_die
, NULL
, cu
);
5534 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
5537 CORE_ADDR byte_offset
= 0;
5539 if (attr_form_is_section_offset (attr
))
5540 dwarf2_complex_location_expr_complaint ();
5541 else if (attr_form_is_constant (attr
))
5542 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
5543 else if (attr_form_is_block (attr
))
5544 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
5546 dwarf2_complex_location_expr_complaint ();
5548 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
5549 add_symbol_to_list (sym
, &global_symbols
);
5551 child_die
= sibling_die (child_die
);
5556 /* Create a type for a C++ namespace. */
5558 static struct type
*
5559 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5561 struct objfile
*objfile
= cu
->objfile
;
5562 const char *previous_prefix
, *name
;
5566 /* For extensions, reuse the type of the original namespace. */
5567 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
5569 struct die_info
*ext_die
;
5570 struct dwarf2_cu
*ext_cu
= cu
;
5571 ext_die
= dwarf2_extension (die
, &ext_cu
);
5572 type
= read_type_die (ext_die
, ext_cu
);
5573 return set_die_type (die
, type
, cu
);
5576 name
= namespace_name (die
, &is_anonymous
, cu
);
5578 /* Now build the name of the current namespace. */
5580 previous_prefix
= determine_prefix (die
, cu
);
5581 if (previous_prefix
[0] != '\0')
5582 name
= typename_concat (&objfile
->objfile_obstack
,
5583 previous_prefix
, name
, cu
);
5585 /* Create the type. */
5586 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
5588 TYPE_NAME (type
) = (char *) name
;
5589 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5591 set_die_type (die
, type
, cu
);
5596 /* Read a C++ namespace. */
5599 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
5601 struct objfile
*objfile
= cu
->objfile
;
5605 /* Add a symbol associated to this if we haven't seen the namespace
5606 before. Also, add a using directive if it's an anonymous
5609 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
5613 type
= read_type_die (die
, cu
);
5614 new_symbol (die
, type
, cu
);
5616 name
= namespace_name (die
, &is_anonymous
, cu
);
5619 const char *previous_prefix
= determine_prefix (die
, cu
);
5620 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
));
5624 if (die
->child
!= NULL
)
5626 struct die_info
*child_die
= die
->child
;
5628 while (child_die
&& child_die
->tag
)
5630 process_die (child_die
, cu
);
5631 child_die
= sibling_die (child_die
);
5636 /* Read a Fortran module. */
5639 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
5641 struct die_info
*child_die
= die
->child
;
5643 /* FIXME: Support the separate Fortran module namespaces. */
5645 while (child_die
&& child_die
->tag
)
5647 process_die (child_die
, cu
);
5648 child_die
= sibling_die (child_die
);
5652 /* Return the name of the namespace represented by DIE. Set
5653 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
5657 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
5659 struct die_info
*current_die
;
5660 const char *name
= NULL
;
5662 /* Loop through the extensions until we find a name. */
5664 for (current_die
= die
;
5665 current_die
!= NULL
;
5666 current_die
= dwarf2_extension (die
, &cu
))
5668 name
= dwarf2_name (current_die
, cu
);
5673 /* Is it an anonymous namespace? */
5675 *is_anonymous
= (name
== NULL
);
5677 name
= "(anonymous namespace)";
5682 /* Extract all information from a DW_TAG_pointer_type DIE and add to
5683 the user defined type vector. */
5685 static struct type
*
5686 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5688 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5689 struct comp_unit_head
*cu_header
= &cu
->header
;
5691 struct attribute
*attr_byte_size
;
5692 struct attribute
*attr_address_class
;
5693 int byte_size
, addr_class
;
5695 type
= lookup_pointer_type (die_type (die
, cu
));
5697 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5699 byte_size
= DW_UNSND (attr_byte_size
);
5701 byte_size
= cu_header
->addr_size
;
5703 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
5704 if (attr_address_class
)
5705 addr_class
= DW_UNSND (attr_address_class
);
5707 addr_class
= DW_ADDR_none
;
5709 /* If the pointer size or address class is different than the
5710 default, create a type variant marked as such and set the
5711 length accordingly. */
5712 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
5714 if (gdbarch_address_class_type_flags_p (gdbarch
))
5718 type_flags
= gdbarch_address_class_type_flags
5719 (gdbarch
, byte_size
, addr_class
);
5720 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
5722 type
= make_type_with_address_space (type
, type_flags
);
5724 else if (TYPE_LENGTH (type
) != byte_size
)
5726 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
5729 /* Should we also complain about unhandled address classes? */
5733 TYPE_LENGTH (type
) = byte_size
;
5734 return set_die_type (die
, type
, cu
);
5737 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
5738 the user defined type vector. */
5740 static struct type
*
5741 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5743 struct objfile
*objfile
= cu
->objfile
;
5745 struct type
*to_type
;
5746 struct type
*domain
;
5748 to_type
= die_type (die
, cu
);
5749 domain
= die_containing_type (die
, cu
);
5751 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
5752 type
= lookup_methodptr_type (to_type
);
5754 type
= lookup_memberptr_type (to_type
, domain
);
5756 return set_die_type (die
, type
, cu
);
5759 /* Extract all information from a DW_TAG_reference_type DIE and add to
5760 the user defined type vector. */
5762 static struct type
*
5763 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5765 struct comp_unit_head
*cu_header
= &cu
->header
;
5767 struct attribute
*attr
;
5769 type
= lookup_reference_type (die_type (die
, cu
));
5770 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5773 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5777 TYPE_LENGTH (type
) = cu_header
->addr_size
;
5779 return set_die_type (die
, type
, cu
);
5782 static struct type
*
5783 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5785 struct type
*base_type
, *cv_type
;
5787 base_type
= die_type (die
, cu
);
5788 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
5789 return set_die_type (die
, cv_type
, cu
);
5792 static struct type
*
5793 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5795 struct type
*base_type
, *cv_type
;
5797 base_type
= die_type (die
, cu
);
5798 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
5799 return set_die_type (die
, cv_type
, cu
);
5802 /* Extract all information from a DW_TAG_string_type DIE and add to
5803 the user defined type vector. It isn't really a user defined type,
5804 but it behaves like one, with other DIE's using an AT_user_def_type
5805 attribute to reference it. */
5807 static struct type
*
5808 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5810 struct objfile
*objfile
= cu
->objfile
;
5811 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5812 struct type
*type
, *range_type
, *index_type
, *char_type
;
5813 struct attribute
*attr
;
5814 unsigned int length
;
5816 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
5819 length
= DW_UNSND (attr
);
5823 /* check for the DW_AT_byte_size attribute */
5824 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5827 length
= DW_UNSND (attr
);
5835 index_type
= objfile_type (objfile
)->builtin_int
;
5836 range_type
= create_range_type (NULL
, index_type
, 1, length
);
5837 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
5838 type
= create_string_type (NULL
, char_type
, range_type
);
5840 return set_die_type (die
, type
, cu
);
5843 /* Handle DIES due to C code like:
5847 int (*funcp)(int a, long l);
5851 ('funcp' generates a DW_TAG_subroutine_type DIE)
5854 static struct type
*
5855 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5857 struct type
*type
; /* Type that this function returns */
5858 struct type
*ftype
; /* Function that returns above type */
5859 struct attribute
*attr
;
5861 type
= die_type (die
, cu
);
5862 ftype
= lookup_function_type (type
);
5864 /* All functions in C++, Pascal and Java have prototypes. */
5865 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
5866 if ((attr
&& (DW_UNSND (attr
) != 0))
5867 || cu
->language
== language_cplus
5868 || cu
->language
== language_java
5869 || cu
->language
== language_pascal
)
5870 TYPE_PROTOTYPED (ftype
) = 1;
5872 /* Store the calling convention in the type if it's available in
5873 the subroutine die. Otherwise set the calling convention to
5874 the default value DW_CC_normal. */
5875 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
5876 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
5878 /* We need to add the subroutine type to the die immediately so
5879 we don't infinitely recurse when dealing with parameters
5880 declared as the same subroutine type. */
5881 set_die_type (die
, ftype
, cu
);
5883 if (die
->child
!= NULL
)
5885 struct die_info
*child_die
;
5889 /* Count the number of parameters.
5890 FIXME: GDB currently ignores vararg functions, but knows about
5891 vararg member functions. */
5892 child_die
= die
->child
;
5893 while (child_die
&& child_die
->tag
)
5895 if (child_die
->tag
== DW_TAG_formal_parameter
)
5897 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
5898 TYPE_VARARGS (ftype
) = 1;
5899 child_die
= sibling_die (child_die
);
5902 /* Allocate storage for parameters and fill them in. */
5903 TYPE_NFIELDS (ftype
) = nparams
;
5904 TYPE_FIELDS (ftype
) = (struct field
*)
5905 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
5907 child_die
= die
->child
;
5908 while (child_die
&& child_die
->tag
)
5910 if (child_die
->tag
== DW_TAG_formal_parameter
)
5912 /* Dwarf2 has no clean way to discern C++ static and non-static
5913 member functions. G++ helps GDB by marking the first
5914 parameter for non-static member functions (which is the
5915 this pointer) as artificial. We pass this information
5916 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
5917 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
5919 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
5921 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
5922 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
5925 child_die
= sibling_die (child_die
);
5932 static struct type
*
5933 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
5935 struct objfile
*objfile
= cu
->objfile
;
5936 struct attribute
*attr
;
5937 const char *name
= NULL
;
5938 struct type
*this_type
;
5940 name
= dwarf2_full_name (die
, cu
);
5941 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
5942 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
5943 TYPE_NAME (this_type
) = (char *) name
;
5944 set_die_type (die
, this_type
, cu
);
5945 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
5949 /* Find a representation of a given base type and install
5950 it in the TYPE field of the die. */
5952 static struct type
*
5953 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5955 struct objfile
*objfile
= cu
->objfile
;
5957 struct attribute
*attr
;
5958 int encoding
= 0, size
= 0;
5960 enum type_code code
= TYPE_CODE_INT
;
5962 struct type
*target_type
= NULL
;
5964 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
5967 encoding
= DW_UNSND (attr
);
5969 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5972 size
= DW_UNSND (attr
);
5974 name
= dwarf2_name (die
, cu
);
5977 complaint (&symfile_complaints
,
5978 _("DW_AT_name missing from DW_TAG_base_type"));
5983 case DW_ATE_address
:
5984 /* Turn DW_ATE_address into a void * pointer. */
5985 code
= TYPE_CODE_PTR
;
5986 type_flags
|= TYPE_FLAG_UNSIGNED
;
5987 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
5989 case DW_ATE_boolean
:
5990 code
= TYPE_CODE_BOOL
;
5991 type_flags
|= TYPE_FLAG_UNSIGNED
;
5993 case DW_ATE_complex_float
:
5994 code
= TYPE_CODE_COMPLEX
;
5995 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
5997 case DW_ATE_decimal_float
:
5998 code
= TYPE_CODE_DECFLOAT
;
6001 code
= TYPE_CODE_FLT
;
6005 case DW_ATE_unsigned
:
6006 type_flags
|= TYPE_FLAG_UNSIGNED
;
6008 case DW_ATE_signed_char
:
6009 if (cu
->language
== language_ada
|| cu
->language
== language_m2
6010 || cu
->language
== language_pascal
)
6011 code
= TYPE_CODE_CHAR
;
6013 case DW_ATE_unsigned_char
:
6014 if (cu
->language
== language_ada
|| cu
->language
== language_m2
6015 || cu
->language
== language_pascal
)
6016 code
= TYPE_CODE_CHAR
;
6017 type_flags
|= TYPE_FLAG_UNSIGNED
;
6020 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
6021 dwarf_type_encoding_name (encoding
));
6025 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
6026 TYPE_NAME (type
) = name
;
6027 TYPE_TARGET_TYPE (type
) = target_type
;
6029 if (name
&& strcmp (name
, "char") == 0)
6030 TYPE_NOSIGN (type
) = 1;
6032 return set_die_type (die
, type
, cu
);
6035 /* Read the given DW_AT_subrange DIE. */
6037 static struct type
*
6038 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6040 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
6041 struct type
*base_type
;
6042 struct type
*range_type
;
6043 struct attribute
*attr
;
6047 LONGEST negative_mask
;
6049 base_type
= die_type (die
, cu
);
6050 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
6052 complaint (&symfile_complaints
,
6053 _("DW_AT_type missing from DW_TAG_subrange_type"));
6055 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
6056 0, NULL
, cu
->objfile
);
6059 if (cu
->language
== language_fortran
)
6061 /* FORTRAN implies a lower bound of 1, if not given. */
6065 /* FIXME: For variable sized arrays either of these could be
6066 a variable rather than a constant value. We'll allow it,
6067 but we don't know how to handle it. */
6068 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
6070 low
= dwarf2_get_attr_constant_value (attr
, 0);
6072 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
6075 if (attr
->form
== DW_FORM_block1
)
6077 /* GCC encodes arrays with unspecified or dynamic length
6078 with a DW_FORM_block1 attribute.
6079 FIXME: GDB does not yet know how to handle dynamic
6080 arrays properly, treat them as arrays with unspecified
6083 FIXME: jimb/2003-09-22: GDB does not really know
6084 how to handle arrays of unspecified length
6085 either; we just represent them as zero-length
6086 arrays. Choose an appropriate upper bound given
6087 the lower bound we've computed above. */
6091 high
= dwarf2_get_attr_constant_value (attr
, 1);
6095 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
6096 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
6097 low
|= negative_mask
;
6098 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
6099 high
|= negative_mask
;
6101 range_type
= create_range_type (NULL
, base_type
, low
, high
);
6103 name
= dwarf2_name (die
, cu
);
6105 TYPE_NAME (range_type
) = name
;
6107 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6109 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
6111 set_descriptive_type (range_type
, die
, cu
);
6113 return set_die_type (die
, range_type
, cu
);
6116 static struct type
*
6117 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6121 /* For now, we only support the C meaning of an unspecified type: void. */
6123 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
6124 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
6126 return set_die_type (die
, type
, cu
);
6129 /* Trivial hash function for die_info: the hash value of a DIE
6130 is its offset in .debug_info for this objfile. */
6133 die_hash (const void *item
)
6135 const struct die_info
*die
= item
;
6139 /* Trivial comparison function for die_info structures: two DIEs
6140 are equal if they have the same offset. */
6143 die_eq (const void *item_lhs
, const void *item_rhs
)
6145 const struct die_info
*die_lhs
= item_lhs
;
6146 const struct die_info
*die_rhs
= item_rhs
;
6147 return die_lhs
->offset
== die_rhs
->offset
;
6150 /* Read a whole compilation unit into a linked list of dies. */
6152 static struct die_info
*
6153 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6155 struct die_reader_specs reader_specs
;
6157 gdb_assert (cu
->die_hash
== NULL
);
6159 = htab_create_alloc_ex (cu
->header
.length
/ 12,
6163 &cu
->comp_unit_obstack
,
6164 hashtab_obstack_allocate
,
6165 dummy_obstack_deallocate
);
6167 init_cu_die_reader (&reader_specs
, cu
);
6169 return read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
6172 /* Main entry point for reading a DIE and all children.
6173 Read the DIE and dump it if requested. */
6175 static struct die_info
*
6176 read_die_and_children (const struct die_reader_specs
*reader
,
6178 gdb_byte
**new_info_ptr
,
6179 struct die_info
*parent
)
6181 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
6182 new_info_ptr
, parent
);
6184 if (dwarf2_die_debug
)
6186 fprintf_unfiltered (gdb_stdlog
,
6187 "\nRead die from %s of %s:\n",
6188 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
6190 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
6192 : "unknown section",
6193 reader
->abfd
->filename
);
6194 dump_die (result
, dwarf2_die_debug
);
6200 /* Read a single die and all its descendents. Set the die's sibling
6201 field to NULL; set other fields in the die correctly, and set all
6202 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
6203 location of the info_ptr after reading all of those dies. PARENT
6204 is the parent of the die in question. */
6206 static struct die_info
*
6207 read_die_and_children_1 (const struct die_reader_specs
*reader
,
6209 gdb_byte
**new_info_ptr
,
6210 struct die_info
*parent
)
6212 struct die_info
*die
;
6216 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
6219 *new_info_ptr
= cur_ptr
;
6222 store_in_ref_table (die
, reader
->cu
);
6225 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
6229 *new_info_ptr
= cur_ptr
;
6232 die
->sibling
= NULL
;
6233 die
->parent
= parent
;
6237 /* Read a die, all of its descendents, and all of its siblings; set
6238 all of the fields of all of the dies correctly. Arguments are as
6239 in read_die_and_children. */
6241 static struct die_info
*
6242 read_die_and_siblings (const struct die_reader_specs
*reader
,
6244 gdb_byte
**new_info_ptr
,
6245 struct die_info
*parent
)
6247 struct die_info
*first_die
, *last_sibling
;
6251 first_die
= last_sibling
= NULL
;
6255 struct die_info
*die
6256 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
6260 *new_info_ptr
= cur_ptr
;
6267 last_sibling
->sibling
= die
;
6273 /* Read the die from the .debug_info section buffer. Set DIEP to
6274 point to a newly allocated die with its information, except for its
6275 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6276 whether the die has children or not. */
6279 read_full_die (const struct die_reader_specs
*reader
,
6280 struct die_info
**diep
, gdb_byte
*info_ptr
,
6283 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6284 struct abbrev_info
*abbrev
;
6285 struct die_info
*die
;
6286 struct dwarf2_cu
*cu
= reader
->cu
;
6287 bfd
*abfd
= reader
->abfd
;
6289 offset
= info_ptr
- reader
->buffer
;
6290 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6291 info_ptr
+= bytes_read
;
6299 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6301 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6303 bfd_get_filename (abfd
));
6305 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6306 die
->offset
= offset
;
6307 die
->tag
= abbrev
->tag
;
6308 die
->abbrev
= abbrev_number
;
6310 die
->num_attrs
= abbrev
->num_attrs
;
6312 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6313 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6314 abfd
, info_ptr
, cu
);
6317 *has_children
= abbrev
->has_children
;
6321 /* In DWARF version 2, the description of the debugging information is
6322 stored in a separate .debug_abbrev section. Before we read any
6323 dies from a section we read in all abbreviations and install them
6324 in a hash table. This function also sets flags in CU describing
6325 the data found in the abbrev table. */
6328 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
6330 struct comp_unit_head
*cu_header
= &cu
->header
;
6331 gdb_byte
*abbrev_ptr
;
6332 struct abbrev_info
*cur_abbrev
;
6333 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
6334 unsigned int abbrev_form
, hash_number
;
6335 struct attr_abbrev
*cur_attrs
;
6336 unsigned int allocated_attrs
;
6338 /* Initialize dwarf2 abbrevs */
6339 obstack_init (&cu
->abbrev_obstack
);
6340 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
6342 * sizeof (struct abbrev_info
*)));
6343 memset (cu
->dwarf2_abbrevs
, 0,
6344 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
6346 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
6347 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6348 abbrev_ptr
+= bytes_read
;
6350 allocated_attrs
= ATTR_ALLOC_CHUNK
;
6351 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
6353 /* loop until we reach an abbrev number of 0 */
6354 while (abbrev_number
)
6356 cur_abbrev
= dwarf_alloc_abbrev (cu
);
6358 /* read in abbrev header */
6359 cur_abbrev
->number
= abbrev_number
;
6360 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6361 abbrev_ptr
+= bytes_read
;
6362 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
6365 if (cur_abbrev
->tag
== DW_TAG_namespace
)
6366 cu
->has_namespace_info
= 1;
6368 /* now read in declarations */
6369 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6370 abbrev_ptr
+= bytes_read
;
6371 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6372 abbrev_ptr
+= bytes_read
;
6375 if (cur_abbrev
->num_attrs
== allocated_attrs
)
6377 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
6379 = xrealloc (cur_attrs
, (allocated_attrs
6380 * sizeof (struct attr_abbrev
)));
6383 /* Record whether this compilation unit might have
6384 inter-compilation-unit references. If we don't know what form
6385 this attribute will have, then it might potentially be a
6386 DW_FORM_ref_addr, so we conservatively expect inter-CU
6389 if (abbrev_form
== DW_FORM_ref_addr
6390 || abbrev_form
== DW_FORM_indirect
)
6391 cu
->has_form_ref_addr
= 1;
6393 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
6394 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
6395 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6396 abbrev_ptr
+= bytes_read
;
6397 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6398 abbrev_ptr
+= bytes_read
;
6401 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
6402 (cur_abbrev
->num_attrs
6403 * sizeof (struct attr_abbrev
)));
6404 memcpy (cur_abbrev
->attrs
, cur_attrs
,
6405 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
6407 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
6408 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
6409 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
6411 /* Get next abbreviation.
6412 Under Irix6 the abbreviations for a compilation unit are not
6413 always properly terminated with an abbrev number of 0.
6414 Exit loop if we encounter an abbreviation which we have
6415 already read (which means we are about to read the abbreviations
6416 for the next compile unit) or if the end of the abbreviation
6417 table is reached. */
6418 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
6419 >= dwarf2_per_objfile
->abbrev
.size
)
6421 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6422 abbrev_ptr
+= bytes_read
;
6423 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
6430 /* Release the memory used by the abbrev table for a compilation unit. */
6433 dwarf2_free_abbrev_table (void *ptr_to_cu
)
6435 struct dwarf2_cu
*cu
= ptr_to_cu
;
6437 obstack_free (&cu
->abbrev_obstack
, NULL
);
6438 cu
->dwarf2_abbrevs
= NULL
;
6441 /* Lookup an abbrev_info structure in the abbrev hash table. */
6443 static struct abbrev_info
*
6444 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
6446 unsigned int hash_number
;
6447 struct abbrev_info
*abbrev
;
6449 hash_number
= number
% ABBREV_HASH_SIZE
;
6450 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
6454 if (abbrev
->number
== number
)
6457 abbrev
= abbrev
->next
;
6462 /* Returns nonzero if TAG represents a type that we might generate a partial
6466 is_type_tag_for_partial (int tag
)
6471 /* Some types that would be reasonable to generate partial symbols for,
6472 that we don't at present. */
6473 case DW_TAG_array_type
:
6474 case DW_TAG_file_type
:
6475 case DW_TAG_ptr_to_member_type
:
6476 case DW_TAG_set_type
:
6477 case DW_TAG_string_type
:
6478 case DW_TAG_subroutine_type
:
6480 case DW_TAG_base_type
:
6481 case DW_TAG_class_type
:
6482 case DW_TAG_interface_type
:
6483 case DW_TAG_enumeration_type
:
6484 case DW_TAG_structure_type
:
6485 case DW_TAG_subrange_type
:
6486 case DW_TAG_typedef
:
6487 case DW_TAG_union_type
:
6494 /* Load all DIEs that are interesting for partial symbols into memory. */
6496 static struct partial_die_info
*
6497 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
6498 int building_psymtab
, struct dwarf2_cu
*cu
)
6500 struct partial_die_info
*part_die
;
6501 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
6502 struct abbrev_info
*abbrev
;
6503 unsigned int bytes_read
;
6504 unsigned int load_all
= 0;
6506 int nesting_level
= 1;
6511 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
6515 = htab_create_alloc_ex (cu
->header
.length
/ 12,
6519 &cu
->comp_unit_obstack
,
6520 hashtab_obstack_allocate
,
6521 dummy_obstack_deallocate
);
6523 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
6524 sizeof (struct partial_die_info
));
6528 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
6530 /* A NULL abbrev means the end of a series of children. */
6533 if (--nesting_level
== 0)
6535 /* PART_DIE was probably the last thing allocated on the
6536 comp_unit_obstack, so we could call obstack_free
6537 here. We don't do that because the waste is small,
6538 and will be cleaned up when we're done with this
6539 compilation unit. This way, we're also more robust
6540 against other users of the comp_unit_obstack. */
6543 info_ptr
+= bytes_read
;
6544 last_die
= parent_die
;
6545 parent_die
= parent_die
->die_parent
;
6549 /* Check whether this DIE is interesting enough to save. Normally
6550 we would not be interested in members here, but there may be
6551 later variables referencing them via DW_AT_specification (for
6554 && !is_type_tag_for_partial (abbrev
->tag
)
6555 && abbrev
->tag
!= DW_TAG_enumerator
6556 && abbrev
->tag
!= DW_TAG_subprogram
6557 && abbrev
->tag
!= DW_TAG_lexical_block
6558 && abbrev
->tag
!= DW_TAG_variable
6559 && abbrev
->tag
!= DW_TAG_namespace
6560 && abbrev
->tag
!= DW_TAG_member
)
6562 /* Otherwise we skip to the next sibling, if any. */
6563 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
6567 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
6568 buffer
, info_ptr
, cu
);
6570 /* This two-pass algorithm for processing partial symbols has a
6571 high cost in cache pressure. Thus, handle some simple cases
6572 here which cover the majority of C partial symbols. DIEs
6573 which neither have specification tags in them, nor could have
6574 specification tags elsewhere pointing at them, can simply be
6575 processed and discarded.
6577 This segment is also optional; scan_partial_symbols and
6578 add_partial_symbol will handle these DIEs if we chain
6579 them in normally. When compilers which do not emit large
6580 quantities of duplicate debug information are more common,
6581 this code can probably be removed. */
6583 /* Any complete simple types at the top level (pretty much all
6584 of them, for a language without namespaces), can be processed
6586 if (parent_die
== NULL
6587 && part_die
->has_specification
== 0
6588 && part_die
->is_declaration
== 0
6589 && (part_die
->tag
== DW_TAG_typedef
6590 || part_die
->tag
== DW_TAG_base_type
6591 || part_die
->tag
== DW_TAG_subrange_type
))
6593 if (building_psymtab
&& part_die
->name
!= NULL
)
6594 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
6595 VAR_DOMAIN
, LOC_TYPEDEF
,
6596 &cu
->objfile
->static_psymbols
,
6597 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
6598 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
6602 /* If we're at the second level, and we're an enumerator, and
6603 our parent has no specification (meaning possibly lives in a
6604 namespace elsewhere), then we can add the partial symbol now
6605 instead of queueing it. */
6606 if (part_die
->tag
== DW_TAG_enumerator
6607 && parent_die
!= NULL
6608 && parent_die
->die_parent
== NULL
6609 && parent_die
->tag
== DW_TAG_enumeration_type
6610 && parent_die
->has_specification
== 0)
6612 if (part_die
->name
== NULL
)
6613 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
6614 else if (building_psymtab
)
6615 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
6616 VAR_DOMAIN
, LOC_CONST
,
6617 (cu
->language
== language_cplus
6618 || cu
->language
== language_java
)
6619 ? &cu
->objfile
->global_psymbols
6620 : &cu
->objfile
->static_psymbols
,
6621 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
6623 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
6627 /* We'll save this DIE so link it in. */
6628 part_die
->die_parent
= parent_die
;
6629 part_die
->die_sibling
= NULL
;
6630 part_die
->die_child
= NULL
;
6632 if (last_die
&& last_die
== parent_die
)
6633 last_die
->die_child
= part_die
;
6635 last_die
->die_sibling
= part_die
;
6637 last_die
= part_die
;
6639 if (first_die
== NULL
)
6640 first_die
= part_die
;
6642 /* Maybe add the DIE to the hash table. Not all DIEs that we
6643 find interesting need to be in the hash table, because we
6644 also have the parent/sibling/child chains; only those that we
6645 might refer to by offset later during partial symbol reading.
6647 For now this means things that might have be the target of a
6648 DW_AT_specification, DW_AT_abstract_origin, or
6649 DW_AT_extension. DW_AT_extension will refer only to
6650 namespaces; DW_AT_abstract_origin refers to functions (and
6651 many things under the function DIE, but we do not recurse
6652 into function DIEs during partial symbol reading) and
6653 possibly variables as well; DW_AT_specification refers to
6654 declarations. Declarations ought to have the DW_AT_declaration
6655 flag. It happens that GCC forgets to put it in sometimes, but
6656 only for functions, not for types.
6658 Adding more things than necessary to the hash table is harmless
6659 except for the performance cost. Adding too few will result in
6660 wasted time in find_partial_die, when we reread the compilation
6661 unit with load_all_dies set. */
6664 || abbrev
->tag
== DW_TAG_subprogram
6665 || abbrev
->tag
== DW_TAG_variable
6666 || abbrev
->tag
== DW_TAG_namespace
6667 || part_die
->is_declaration
)
6671 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
6672 part_die
->offset
, INSERT
);
6676 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
6677 sizeof (struct partial_die_info
));
6679 /* For some DIEs we want to follow their children (if any). For C
6680 we have no reason to follow the children of structures; for other
6681 languages we have to, both so that we can get at method physnames
6682 to infer fully qualified class names, and for DW_AT_specification.
6684 For Ada, we need to scan the children of subprograms and lexical
6685 blocks as well because Ada allows the definition of nested
6686 entities that could be interesting for the debugger, such as
6687 nested subprograms for instance. */
6688 if (last_die
->has_children
6690 || last_die
->tag
== DW_TAG_namespace
6691 || last_die
->tag
== DW_TAG_enumeration_type
6692 || (cu
->language
!= language_c
6693 && (last_die
->tag
== DW_TAG_class_type
6694 || last_die
->tag
== DW_TAG_interface_type
6695 || last_die
->tag
== DW_TAG_structure_type
6696 || last_die
->tag
== DW_TAG_union_type
))
6697 || (cu
->language
== language_ada
6698 && (last_die
->tag
== DW_TAG_subprogram
6699 || last_die
->tag
== DW_TAG_lexical_block
))))
6702 parent_die
= last_die
;
6706 /* Otherwise we skip to the next sibling, if any. */
6707 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
6709 /* Back to the top, do it again. */
6713 /* Read a minimal amount of information into the minimal die structure. */
6716 read_partial_die (struct partial_die_info
*part_die
,
6717 struct abbrev_info
*abbrev
,
6718 unsigned int abbrev_len
, bfd
*abfd
,
6719 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
6720 struct dwarf2_cu
*cu
)
6722 unsigned int bytes_read
, i
;
6723 struct attribute attr
;
6724 int has_low_pc_attr
= 0;
6725 int has_high_pc_attr
= 0;
6727 memset (part_die
, 0, sizeof (struct partial_die_info
));
6729 part_die
->offset
= info_ptr
- buffer
;
6731 info_ptr
+= abbrev_len
;
6736 part_die
->tag
= abbrev
->tag
;
6737 part_die
->has_children
= abbrev
->has_children
;
6739 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6741 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
6743 /* Store the data if it is of an attribute we want to keep in a
6744 partial symbol table. */
6748 switch (part_die
->tag
)
6750 case DW_TAG_compile_unit
:
6751 case DW_TAG_type_unit
:
6752 /* Compilation units have a DW_AT_name that is a filename, not
6753 a source language identifier. */
6754 case DW_TAG_enumeration_type
:
6755 case DW_TAG_enumerator
:
6756 /* These tags always have simple identifiers already; no need
6757 to canonicalize them. */
6758 part_die
->name
= DW_STRING (&attr
);
6762 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
6763 &cu
->objfile
->objfile_obstack
);
6767 case DW_AT_MIPS_linkage_name
:
6768 part_die
->name
= DW_STRING (&attr
);
6771 has_low_pc_attr
= 1;
6772 part_die
->lowpc
= DW_ADDR (&attr
);
6775 has_high_pc_attr
= 1;
6776 part_die
->highpc
= DW_ADDR (&attr
);
6778 case DW_AT_location
:
6779 /* Support the .debug_loc offsets */
6780 if (attr_form_is_block (&attr
))
6782 part_die
->locdesc
= DW_BLOCK (&attr
);
6784 else if (attr_form_is_section_offset (&attr
))
6786 dwarf2_complex_location_expr_complaint ();
6790 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6791 "partial symbol information");
6794 case DW_AT_external
:
6795 part_die
->is_external
= DW_UNSND (&attr
);
6797 case DW_AT_declaration
:
6798 part_die
->is_declaration
= DW_UNSND (&attr
);
6801 part_die
->has_type
= 1;
6803 case DW_AT_abstract_origin
:
6804 case DW_AT_specification
:
6805 case DW_AT_extension
:
6806 part_die
->has_specification
= 1;
6807 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
6810 /* Ignore absolute siblings, they might point outside of
6811 the current compile unit. */
6812 if (attr
.form
== DW_FORM_ref_addr
)
6813 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
6815 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
6817 case DW_AT_byte_size
:
6818 part_die
->has_byte_size
= 1;
6820 case DW_AT_calling_convention
:
6821 /* DWARF doesn't provide a way to identify a program's source-level
6822 entry point. DW_AT_calling_convention attributes are only meant
6823 to describe functions' calling conventions.
6825 However, because it's a necessary piece of information in
6826 Fortran, and because DW_CC_program is the only piece of debugging
6827 information whose definition refers to a 'main program' at all,
6828 several compilers have begun marking Fortran main programs with
6829 DW_CC_program --- even when those functions use the standard
6830 calling conventions.
6832 So until DWARF specifies a way to provide this information and
6833 compilers pick up the new representation, we'll support this
6835 if (DW_UNSND (&attr
) == DW_CC_program
6836 && cu
->language
== language_fortran
)
6837 set_main_name (part_die
->name
);
6844 /* When using the GNU linker, .gnu.linkonce. sections are used to
6845 eliminate duplicate copies of functions and vtables and such.
6846 The linker will arbitrarily choose one and discard the others.
6847 The AT_*_pc values for such functions refer to local labels in
6848 these sections. If the section from that file was discarded, the
6849 labels are not in the output, so the relocs get a value of 0.
6850 If this is a discarded function, mark the pc bounds as invalid,
6851 so that GDB will ignore it. */
6852 if (has_low_pc_attr
&& has_high_pc_attr
6853 && part_die
->lowpc
< part_die
->highpc
6854 && (part_die
->lowpc
!= 0
6855 || dwarf2_per_objfile
->has_section_at_zero
))
6856 part_die
->has_pc_info
= 1;
6861 /* Find a cached partial DIE at OFFSET in CU. */
6863 static struct partial_die_info
*
6864 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
6866 struct partial_die_info
*lookup_die
= NULL
;
6867 struct partial_die_info part_die
;
6869 part_die
.offset
= offset
;
6870 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
6875 /* Find a partial DIE at OFFSET, which may or may not be in CU,
6876 except in the case of .debug_types DIEs which do not reference
6877 outside their CU (they do however referencing other types via
6880 static struct partial_die_info
*
6881 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
6883 struct dwarf2_per_cu_data
*per_cu
= NULL
;
6884 struct partial_die_info
*pd
= NULL
;
6886 if (cu
->per_cu
->from_debug_types
)
6888 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6894 if (offset_in_cu_p (&cu
->header
, offset
))
6896 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6901 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6903 if (per_cu
->cu
== NULL
)
6905 load_partial_comp_unit (per_cu
, cu
->objfile
);
6906 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6907 dwarf2_per_objfile
->read_in_chain
= per_cu
;
6910 per_cu
->cu
->last_used
= 0;
6911 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6913 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
6915 struct cleanup
*back_to
;
6916 struct partial_die_info comp_unit_die
;
6917 struct abbrev_info
*abbrev
;
6918 unsigned int bytes_read
;
6921 per_cu
->load_all_dies
= 1;
6923 /* Re-read the DIEs. */
6924 back_to
= make_cleanup (null_cleanup
, 0);
6925 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
6927 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
6928 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
6930 info_ptr
= (dwarf2_per_objfile
->info
.buffer
6931 + per_cu
->cu
->header
.offset
6932 + per_cu
->cu
->header
.first_die_offset
);
6933 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
6934 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
6935 per_cu
->cu
->objfile
->obfd
,
6936 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
6938 if (comp_unit_die
.has_children
)
6939 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
6940 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
6942 do_cleanups (back_to
);
6944 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6950 internal_error (__FILE__
, __LINE__
,
6951 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
6952 offset
, bfd_get_filename (cu
->objfile
->obfd
));
6956 /* Adjust PART_DIE before generating a symbol for it. This function
6957 may set the is_external flag or change the DIE's name. */
6960 fixup_partial_die (struct partial_die_info
*part_die
,
6961 struct dwarf2_cu
*cu
)
6963 /* If we found a reference attribute and the DIE has no name, try
6964 to find a name in the referred to DIE. */
6966 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6968 struct partial_die_info
*spec_die
;
6970 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6972 fixup_partial_die (spec_die
, cu
);
6976 part_die
->name
= spec_die
->name
;
6978 /* Copy DW_AT_external attribute if it is set. */
6979 if (spec_die
->is_external
)
6980 part_die
->is_external
= spec_die
->is_external
;
6984 /* Set default names for some unnamed DIEs. */
6985 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6986 || part_die
->tag
== DW_TAG_class_type
))
6987 part_die
->name
= "(anonymous class)";
6989 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6990 part_die
->name
= "(anonymous namespace)";
6992 if (part_die
->tag
== DW_TAG_structure_type
6993 || part_die
->tag
== DW_TAG_class_type
6994 || part_die
->tag
== DW_TAG_union_type
)
6995 guess_structure_name (part_die
, cu
);
6998 /* Read an attribute value described by an attribute form. */
7001 read_attribute_value (struct attribute
*attr
, unsigned form
,
7002 bfd
*abfd
, gdb_byte
*info_ptr
,
7003 struct dwarf2_cu
*cu
)
7005 struct comp_unit_head
*cu_header
= &cu
->header
;
7006 unsigned int bytes_read
;
7007 struct dwarf_block
*blk
;
7013 case DW_FORM_ref_addr
:
7014 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
7015 info_ptr
+= bytes_read
;
7017 case DW_FORM_block2
:
7018 blk
= dwarf_alloc_block (cu
);
7019 blk
->size
= read_2_bytes (abfd
, info_ptr
);
7021 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7022 info_ptr
+= blk
->size
;
7023 DW_BLOCK (attr
) = blk
;
7025 case DW_FORM_block4
:
7026 blk
= dwarf_alloc_block (cu
);
7027 blk
->size
= read_4_bytes (abfd
, info_ptr
);
7029 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7030 info_ptr
+= blk
->size
;
7031 DW_BLOCK (attr
) = blk
;
7034 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
7038 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
7042 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
7045 case DW_FORM_string
:
7046 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
7047 DW_STRING_IS_CANONICAL (attr
) = 0;
7048 info_ptr
+= bytes_read
;
7051 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
7053 DW_STRING_IS_CANONICAL (attr
) = 0;
7054 info_ptr
+= bytes_read
;
7057 blk
= dwarf_alloc_block (cu
);
7058 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7059 info_ptr
+= bytes_read
;
7060 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7061 info_ptr
+= blk
->size
;
7062 DW_BLOCK (attr
) = blk
;
7064 case DW_FORM_block1
:
7065 blk
= dwarf_alloc_block (cu
);
7066 blk
->size
= read_1_byte (abfd
, info_ptr
);
7068 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7069 info_ptr
+= blk
->size
;
7070 DW_BLOCK (attr
) = blk
;
7073 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
7077 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
7081 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
7082 info_ptr
+= bytes_read
;
7085 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7086 info_ptr
+= bytes_read
;
7089 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
7093 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
7097 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
7101 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
7105 /* Convert the signature to something we can record in DW_UNSND
7107 NOTE: This is NULL if the type wasn't found. */
7108 DW_SIGNATURED_TYPE (attr
) =
7109 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
7112 case DW_FORM_ref_udata
:
7113 DW_ADDR (attr
) = (cu
->header
.offset
7114 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
7115 info_ptr
+= bytes_read
;
7117 case DW_FORM_indirect
:
7118 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7119 info_ptr
+= bytes_read
;
7120 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
7123 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
7124 dwarf_form_name (form
),
7125 bfd_get_filename (abfd
));
7128 /* We have seen instances where the compiler tried to emit a byte
7129 size attribute of -1 which ended up being encoded as an unsigned
7130 0xffffffff. Although 0xffffffff is technically a valid size value,
7131 an object of this size seems pretty unlikely so we can relatively
7132 safely treat these cases as if the size attribute was invalid and
7133 treat them as zero by default. */
7134 if (attr
->name
== DW_AT_byte_size
7135 && form
== DW_FORM_data4
7136 && DW_UNSND (attr
) >= 0xffffffff)
7139 (&symfile_complaints
,
7140 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
7141 hex_string (DW_UNSND (attr
)));
7142 DW_UNSND (attr
) = 0;
7148 /* Read an attribute described by an abbreviated attribute. */
7151 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
7152 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
7154 attr
->name
= abbrev
->name
;
7155 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
7158 /* read dwarf information from a buffer */
7161 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
7163 return bfd_get_8 (abfd
, buf
);
7167 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
7169 return bfd_get_signed_8 (abfd
, buf
);
7173 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
7175 return bfd_get_16 (abfd
, buf
);
7179 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
7181 return bfd_get_signed_16 (abfd
, buf
);
7185 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
7187 return bfd_get_32 (abfd
, buf
);
7191 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
7193 return bfd_get_signed_32 (abfd
, buf
);
7197 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
7199 return bfd_get_64 (abfd
, buf
);
7203 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
7204 unsigned int *bytes_read
)
7206 struct comp_unit_head
*cu_header
= &cu
->header
;
7207 CORE_ADDR retval
= 0;
7209 if (cu_header
->signed_addr_p
)
7211 switch (cu_header
->addr_size
)
7214 retval
= bfd_get_signed_16 (abfd
, buf
);
7217 retval
= bfd_get_signed_32 (abfd
, buf
);
7220 retval
= bfd_get_signed_64 (abfd
, buf
);
7223 internal_error (__FILE__
, __LINE__
,
7224 _("read_address: bad switch, signed [in module %s]"),
7225 bfd_get_filename (abfd
));
7230 switch (cu_header
->addr_size
)
7233 retval
= bfd_get_16 (abfd
, buf
);
7236 retval
= bfd_get_32 (abfd
, buf
);
7239 retval
= bfd_get_64 (abfd
, buf
);
7242 internal_error (__FILE__
, __LINE__
,
7243 _("read_address: bad switch, unsigned [in module %s]"),
7244 bfd_get_filename (abfd
));
7248 *bytes_read
= cu_header
->addr_size
;
7252 /* Read the initial length from a section. The (draft) DWARF 3
7253 specification allows the initial length to take up either 4 bytes
7254 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
7255 bytes describe the length and all offsets will be 8 bytes in length
7258 An older, non-standard 64-bit format is also handled by this
7259 function. The older format in question stores the initial length
7260 as an 8-byte quantity without an escape value. Lengths greater
7261 than 2^32 aren't very common which means that the initial 4 bytes
7262 is almost always zero. Since a length value of zero doesn't make
7263 sense for the 32-bit format, this initial zero can be considered to
7264 be an escape value which indicates the presence of the older 64-bit
7265 format. As written, the code can't detect (old format) lengths
7266 greater than 4GB. If it becomes necessary to handle lengths
7267 somewhat larger than 4GB, we could allow other small values (such
7268 as the non-sensical values of 1, 2, and 3) to also be used as
7269 escape values indicating the presence of the old format.
7271 The value returned via bytes_read should be used to increment the
7272 relevant pointer after calling read_initial_length().
7274 [ Note: read_initial_length() and read_offset() are based on the
7275 document entitled "DWARF Debugging Information Format", revision
7276 3, draft 8, dated November 19, 2001. This document was obtained
7279 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
7281 This document is only a draft and is subject to change. (So beware.)
7283 Details regarding the older, non-standard 64-bit format were
7284 determined empirically by examining 64-bit ELF files produced by
7285 the SGI toolchain on an IRIX 6.5 machine.
7287 - Kevin, July 16, 2002
7291 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
7293 LONGEST length
= bfd_get_32 (abfd
, buf
);
7295 if (length
== 0xffffffff)
7297 length
= bfd_get_64 (abfd
, buf
+ 4);
7300 else if (length
== 0)
7302 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
7303 length
= bfd_get_64 (abfd
, buf
);
7314 /* Cover function for read_initial_length.
7315 Returns the length of the object at BUF, and stores the size of the
7316 initial length in *BYTES_READ and stores the size that offsets will be in
7318 If the initial length size is not equivalent to that specified in
7319 CU_HEADER then issue a complaint.
7320 This is useful when reading non-comp-unit headers. */
7323 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
7324 const struct comp_unit_head
*cu_header
,
7325 unsigned int *bytes_read
,
7326 unsigned int *offset_size
)
7328 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
7330 gdb_assert (cu_header
->initial_length_size
== 4
7331 || cu_header
->initial_length_size
== 8
7332 || cu_header
->initial_length_size
== 12);
7334 if (cu_header
->initial_length_size
!= *bytes_read
)
7335 complaint (&symfile_complaints
,
7336 _("intermixed 32-bit and 64-bit DWARF sections"));
7338 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
7342 /* Read an offset from the data stream. The size of the offset is
7343 given by cu_header->offset_size. */
7346 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
7347 unsigned int *bytes_read
)
7349 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
7350 *bytes_read
= cu_header
->offset_size
;
7354 /* Read an offset from the data stream. */
7357 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
7361 switch (offset_size
)
7364 retval
= bfd_get_32 (abfd
, buf
);
7367 retval
= bfd_get_64 (abfd
, buf
);
7370 internal_error (__FILE__
, __LINE__
,
7371 _("read_offset_1: bad switch [in module %s]"),
7372 bfd_get_filename (abfd
));
7379 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
7381 /* If the size of a host char is 8 bits, we can return a pointer
7382 to the buffer, otherwise we have to copy the data to a buffer
7383 allocated on the temporary obstack. */
7384 gdb_assert (HOST_CHAR_BIT
== 8);
7389 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7391 /* If the size of a host char is 8 bits, we can return a pointer
7392 to the string, otherwise we have to copy the string to a buffer
7393 allocated on the temporary obstack. */
7394 gdb_assert (HOST_CHAR_BIT
== 8);
7397 *bytes_read_ptr
= 1;
7400 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
7401 return (char *) buf
;
7405 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
7406 const struct comp_unit_head
*cu_header
,
7407 unsigned int *bytes_read_ptr
)
7409 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
7411 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
7413 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
7414 bfd_get_filename (abfd
));
7417 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
7419 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
7420 bfd_get_filename (abfd
));
7423 gdb_assert (HOST_CHAR_BIT
== 8);
7424 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
7426 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
7429 static unsigned long
7430 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7432 unsigned long result
;
7433 unsigned int num_read
;
7443 byte
= bfd_get_8 (abfd
, buf
);
7446 result
|= ((unsigned long)(byte
& 127) << shift
);
7447 if ((byte
& 128) == 0)
7453 *bytes_read_ptr
= num_read
;
7458 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7461 int i
, shift
, num_read
;
7470 byte
= bfd_get_8 (abfd
, buf
);
7473 result
|= ((long)(byte
& 127) << shift
);
7475 if ((byte
& 128) == 0)
7480 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
7481 result
|= -(((long)1) << shift
);
7482 *bytes_read_ptr
= num_read
;
7486 /* Return a pointer to just past the end of an LEB128 number in BUF. */
7489 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
7495 byte
= bfd_get_8 (abfd
, buf
);
7497 if ((byte
& 128) == 0)
7503 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
7510 cu
->language
= language_c
;
7512 case DW_LANG_C_plus_plus
:
7513 cu
->language
= language_cplus
;
7515 case DW_LANG_Fortran77
:
7516 case DW_LANG_Fortran90
:
7517 case DW_LANG_Fortran95
:
7518 cu
->language
= language_fortran
;
7520 case DW_LANG_Mips_Assembler
:
7521 cu
->language
= language_asm
;
7524 cu
->language
= language_java
;
7528 cu
->language
= language_ada
;
7530 case DW_LANG_Modula2
:
7531 cu
->language
= language_m2
;
7533 case DW_LANG_Pascal83
:
7534 cu
->language
= language_pascal
;
7537 cu
->language
= language_objc
;
7539 case DW_LANG_Cobol74
:
7540 case DW_LANG_Cobol85
:
7542 cu
->language
= language_minimal
;
7545 cu
->language_defn
= language_def (cu
->language
);
7548 /* Return the named attribute or NULL if not there. */
7550 static struct attribute
*
7551 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
7554 struct attribute
*spec
= NULL
;
7556 for (i
= 0; i
< die
->num_attrs
; ++i
)
7558 if (die
->attrs
[i
].name
== name
)
7559 return &die
->attrs
[i
];
7560 if (die
->attrs
[i
].name
== DW_AT_specification
7561 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
7562 spec
= &die
->attrs
[i
];
7567 die
= follow_die_ref (die
, spec
, &cu
);
7568 return dwarf2_attr (die
, name
, cu
);
7574 /* Return the named attribute or NULL if not there,
7575 but do not follow DW_AT_specification, etc.
7576 This is for use in contexts where we're reading .debug_types dies.
7577 Following DW_AT_specification, DW_AT_abstract_origin will take us
7578 back up the chain, and we want to go down. */
7580 static struct attribute
*
7581 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
7582 struct dwarf2_cu
*cu
)
7586 for (i
= 0; i
< die
->num_attrs
; ++i
)
7587 if (die
->attrs
[i
].name
== name
)
7588 return &die
->attrs
[i
];
7593 /* Return non-zero iff the attribute NAME is defined for the given DIE,
7594 and holds a non-zero value. This function should only be used for
7595 DW_FORM_flag attributes. */
7598 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
7600 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
7602 return (attr
&& DW_UNSND (attr
));
7606 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
7608 /* A DIE is a declaration if it has a DW_AT_declaration attribute
7609 which value is non-zero. However, we have to be careful with
7610 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
7611 (via dwarf2_flag_true_p) follows this attribute. So we may
7612 end up accidently finding a declaration attribute that belongs
7613 to a different DIE referenced by the specification attribute,
7614 even though the given DIE does not have a declaration attribute. */
7615 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
7616 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
7619 /* Return the die giving the specification for DIE, if there is
7620 one. *SPEC_CU is the CU containing DIE on input, and the CU
7621 containing the return value on output. If there is no
7622 specification, but there is an abstract origin, that is
7625 static struct die_info
*
7626 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
7628 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
7631 if (spec_attr
== NULL
)
7632 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
7634 if (spec_attr
== NULL
)
7637 return follow_die_ref (die
, spec_attr
, spec_cu
);
7640 /* Free the line_header structure *LH, and any arrays and strings it
7643 free_line_header (struct line_header
*lh
)
7645 if (lh
->standard_opcode_lengths
)
7646 xfree (lh
->standard_opcode_lengths
);
7648 /* Remember that all the lh->file_names[i].name pointers are
7649 pointers into debug_line_buffer, and don't need to be freed. */
7651 xfree (lh
->file_names
);
7653 /* Similarly for the include directory names. */
7654 if (lh
->include_dirs
)
7655 xfree (lh
->include_dirs
);
7661 /* Add an entry to LH's include directory table. */
7663 add_include_dir (struct line_header
*lh
, char *include_dir
)
7665 /* Grow the array if necessary. */
7666 if (lh
->include_dirs_size
== 0)
7668 lh
->include_dirs_size
= 1; /* for testing */
7669 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
7670 * sizeof (*lh
->include_dirs
));
7672 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
7674 lh
->include_dirs_size
*= 2;
7675 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
7676 (lh
->include_dirs_size
7677 * sizeof (*lh
->include_dirs
)));
7680 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
7684 /* Add an entry to LH's file name table. */
7686 add_file_name (struct line_header
*lh
,
7688 unsigned int dir_index
,
7689 unsigned int mod_time
,
7690 unsigned int length
)
7692 struct file_entry
*fe
;
7694 /* Grow the array if necessary. */
7695 if (lh
->file_names_size
== 0)
7697 lh
->file_names_size
= 1; /* for testing */
7698 lh
->file_names
= xmalloc (lh
->file_names_size
7699 * sizeof (*lh
->file_names
));
7701 else if (lh
->num_file_names
>= lh
->file_names_size
)
7703 lh
->file_names_size
*= 2;
7704 lh
->file_names
= xrealloc (lh
->file_names
,
7705 (lh
->file_names_size
7706 * sizeof (*lh
->file_names
)));
7709 fe
= &lh
->file_names
[lh
->num_file_names
++];
7711 fe
->dir_index
= dir_index
;
7712 fe
->mod_time
= mod_time
;
7713 fe
->length
= length
;
7719 /* Read the statement program header starting at OFFSET in
7720 .debug_line, according to the endianness of ABFD. Return a pointer
7721 to a struct line_header, allocated using xmalloc.
7723 NOTE: the strings in the include directory and file name tables of
7724 the returned object point into debug_line_buffer, and must not be
7726 static struct line_header
*
7727 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
7728 struct dwarf2_cu
*cu
)
7730 struct cleanup
*back_to
;
7731 struct line_header
*lh
;
7733 unsigned int bytes_read
, offset_size
;
7735 char *cur_dir
, *cur_file
;
7737 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
7739 complaint (&symfile_complaints
, _("missing .debug_line section"));
7743 /* Make sure that at least there's room for the total_length field.
7744 That could be 12 bytes long, but we're just going to fudge that. */
7745 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
7747 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7751 lh
= xmalloc (sizeof (*lh
));
7752 memset (lh
, 0, sizeof (*lh
));
7753 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
7756 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
7758 /* Read in the header. */
7760 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
7761 &bytes_read
, &offset_size
);
7762 line_ptr
+= bytes_read
;
7763 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
7764 + dwarf2_per_objfile
->line
.size
))
7766 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7769 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
7770 lh
->version
= read_2_bytes (abfd
, line_ptr
);
7772 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
7773 line_ptr
+= offset_size
;
7774 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
7776 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
7778 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
7780 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
7782 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
7784 lh
->standard_opcode_lengths
7785 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
7787 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
7788 for (i
= 1; i
< lh
->opcode_base
; ++i
)
7790 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
7794 /* Read directory table. */
7795 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7797 line_ptr
+= bytes_read
;
7798 add_include_dir (lh
, cur_dir
);
7800 line_ptr
+= bytes_read
;
7802 /* Read file name table. */
7803 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7805 unsigned int dir_index
, mod_time
, length
;
7807 line_ptr
+= bytes_read
;
7808 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7809 line_ptr
+= bytes_read
;
7810 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7811 line_ptr
+= bytes_read
;
7812 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7813 line_ptr
+= bytes_read
;
7815 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7817 line_ptr
+= bytes_read
;
7818 lh
->statement_program_start
= line_ptr
;
7820 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
7821 + dwarf2_per_objfile
->line
.size
))
7822 complaint (&symfile_complaints
,
7823 _("line number info header doesn't fit in `.debug_line' section"));
7825 discard_cleanups (back_to
);
7829 /* This function exists to work around a bug in certain compilers
7830 (particularly GCC 2.95), in which the first line number marker of a
7831 function does not show up until after the prologue, right before
7832 the second line number marker. This function shifts ADDRESS down
7833 to the beginning of the function if necessary, and is called on
7834 addresses passed to record_line. */
7837 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
7839 struct function_range
*fn
;
7841 /* Find the function_range containing address. */
7846 cu
->cached_fn
= cu
->first_fn
;
7850 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7856 while (fn
&& fn
!= cu
->cached_fn
)
7857 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7867 if (address
!= fn
->lowpc
)
7868 complaint (&symfile_complaints
,
7869 _("misplaced first line number at 0x%lx for '%s'"),
7870 (unsigned long) address
, fn
->name
);
7875 /* Decode the Line Number Program (LNP) for the given line_header
7876 structure and CU. The actual information extracted and the type
7877 of structures created from the LNP depends on the value of PST.
7879 1. If PST is NULL, then this procedure uses the data from the program
7880 to create all necessary symbol tables, and their linetables.
7881 The compilation directory of the file is passed in COMP_DIR,
7882 and must not be NULL.
7884 2. If PST is not NULL, this procedure reads the program to determine
7885 the list of files included by the unit represented by PST, and
7886 builds all the associated partial symbol tables. In this case,
7887 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7888 is not used to compute the full name of the symtab, and therefore
7889 omitting it when building the partial symtab does not introduce
7890 the potential for inconsistency - a partial symtab and its associated
7891 symbtab having a different fullname -). */
7894 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
7895 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
7897 gdb_byte
*line_ptr
, *extended_end
;
7899 unsigned int bytes_read
, extended_len
;
7900 unsigned char op_code
, extended_op
, adj_opcode
;
7902 struct objfile
*objfile
= cu
->objfile
;
7903 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7904 const int decode_for_pst_p
= (pst
!= NULL
);
7905 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
7907 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7909 line_ptr
= lh
->statement_program_start
;
7910 line_end
= lh
->statement_program_end
;
7912 /* Read the statement sequences until there's nothing left. */
7913 while (line_ptr
< line_end
)
7915 /* state machine registers */
7916 CORE_ADDR address
= 0;
7917 unsigned int file
= 1;
7918 unsigned int line
= 1;
7919 unsigned int column
= 0;
7920 int is_stmt
= lh
->default_is_stmt
;
7921 int basic_block
= 0;
7922 int end_sequence
= 0;
7925 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
7927 /* Start a subfile for the current file of the state machine. */
7928 /* lh->include_dirs and lh->file_names are 0-based, but the
7929 directory and file name numbers in the statement program
7931 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7935 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7937 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7940 /* Decode the table. */
7941 while (!end_sequence
)
7943 op_code
= read_1_byte (abfd
, line_ptr
);
7945 if (line_ptr
> line_end
)
7947 dwarf2_debug_line_missing_end_sequence_complaint ();
7951 if (op_code
>= lh
->opcode_base
)
7953 /* Special operand. */
7954 adj_opcode
= op_code
- lh
->opcode_base
;
7955 address
+= (adj_opcode
/ lh
->line_range
)
7956 * lh
->minimum_instruction_length
;
7957 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7958 if (lh
->num_file_names
< file
|| file
== 0)
7959 dwarf2_debug_line_missing_file_complaint ();
7962 lh
->file_names
[file
- 1].included_p
= 1;
7963 if (!decode_for_pst_p
&& is_stmt
)
7965 if (last_subfile
!= current_subfile
)
7967 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
7969 record_line (last_subfile
, 0, addr
);
7970 last_subfile
= current_subfile
;
7972 /* Append row to matrix using current values. */
7973 addr
= check_cu_functions (address
, cu
);
7974 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
7975 record_line (current_subfile
, line
, addr
);
7980 else switch (op_code
)
7982 case DW_LNS_extended_op
:
7983 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7984 line_ptr
+= bytes_read
;
7985 extended_end
= line_ptr
+ extended_len
;
7986 extended_op
= read_1_byte (abfd
, line_ptr
);
7988 switch (extended_op
)
7990 case DW_LNE_end_sequence
:
7993 case DW_LNE_set_address
:
7994 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7995 line_ptr
+= bytes_read
;
7996 address
+= baseaddr
;
7998 case DW_LNE_define_file
:
8001 unsigned int dir_index
, mod_time
, length
;
8003 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
8004 line_ptr
+= bytes_read
;
8006 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8007 line_ptr
+= bytes_read
;
8009 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8010 line_ptr
+= bytes_read
;
8012 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8013 line_ptr
+= bytes_read
;
8014 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
8017 case DW_LNE_set_discriminator
:
8018 /* The discriminator is not interesting to the debugger;
8020 line_ptr
= extended_end
;
8023 complaint (&symfile_complaints
,
8024 _("mangled .debug_line section"));
8027 /* Make sure that we parsed the extended op correctly. If e.g.
8028 we expected a different address size than the producer used,
8029 we may have read the wrong number of bytes. */
8030 if (line_ptr
!= extended_end
)
8032 complaint (&symfile_complaints
,
8033 _("mangled .debug_line section"));
8038 if (lh
->num_file_names
< file
|| file
== 0)
8039 dwarf2_debug_line_missing_file_complaint ();
8042 lh
->file_names
[file
- 1].included_p
= 1;
8043 if (!decode_for_pst_p
&& is_stmt
)
8045 if (last_subfile
!= current_subfile
)
8047 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8049 record_line (last_subfile
, 0, addr
);
8050 last_subfile
= current_subfile
;
8052 addr
= check_cu_functions (address
, cu
);
8053 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
8054 record_line (current_subfile
, line
, addr
);
8059 case DW_LNS_advance_pc
:
8060 address
+= lh
->minimum_instruction_length
8061 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8062 line_ptr
+= bytes_read
;
8064 case DW_LNS_advance_line
:
8065 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
8066 line_ptr
+= bytes_read
;
8068 case DW_LNS_set_file
:
8070 /* The arrays lh->include_dirs and lh->file_names are
8071 0-based, but the directory and file name numbers in
8072 the statement program are 1-based. */
8073 struct file_entry
*fe
;
8076 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8077 line_ptr
+= bytes_read
;
8078 if (lh
->num_file_names
< file
|| file
== 0)
8079 dwarf2_debug_line_missing_file_complaint ();
8082 fe
= &lh
->file_names
[file
- 1];
8084 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8085 if (!decode_for_pst_p
)
8087 last_subfile
= current_subfile
;
8088 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
8093 case DW_LNS_set_column
:
8094 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8095 line_ptr
+= bytes_read
;
8097 case DW_LNS_negate_stmt
:
8098 is_stmt
= (!is_stmt
);
8100 case DW_LNS_set_basic_block
:
8103 /* Add to the address register of the state machine the
8104 address increment value corresponding to special opcode
8105 255. I.e., this value is scaled by the minimum
8106 instruction length since special opcode 255 would have
8107 scaled the the increment. */
8108 case DW_LNS_const_add_pc
:
8109 address
+= (lh
->minimum_instruction_length
8110 * ((255 - lh
->opcode_base
) / lh
->line_range
));
8112 case DW_LNS_fixed_advance_pc
:
8113 address
+= read_2_bytes (abfd
, line_ptr
);
8118 /* Unknown standard opcode, ignore it. */
8121 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
8123 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8124 line_ptr
+= bytes_read
;
8129 if (lh
->num_file_names
< file
|| file
== 0)
8130 dwarf2_debug_line_missing_file_complaint ();
8133 lh
->file_names
[file
- 1].included_p
= 1;
8134 if (!decode_for_pst_p
)
8136 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8137 record_line (current_subfile
, 0, addr
);
8142 if (decode_for_pst_p
)
8146 /* Now that we're done scanning the Line Header Program, we can
8147 create the psymtab of each included file. */
8148 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
8149 if (lh
->file_names
[file_index
].included_p
== 1)
8151 const struct file_entry fe
= lh
->file_names
[file_index
];
8152 char *include_name
= fe
.name
;
8153 char *dir_name
= NULL
;
8154 char *pst_filename
= pst
->filename
;
8157 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
8159 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
8161 include_name
= concat (dir_name
, SLASH_STRING
,
8162 include_name
, (char *)NULL
);
8163 make_cleanup (xfree
, include_name
);
8166 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
8168 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
8169 pst_filename
, (char *)NULL
);
8170 make_cleanup (xfree
, pst_filename
);
8173 if (strcmp (include_name
, pst_filename
) != 0)
8174 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
8179 /* Make sure a symtab is created for every file, even files
8180 which contain only variables (i.e. no code with associated
8184 struct file_entry
*fe
;
8186 for (i
= 0; i
< lh
->num_file_names
; i
++)
8189 fe
= &lh
->file_names
[i
];
8191 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8192 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
8194 /* Skip the main file; we don't need it, and it must be
8195 allocated last, so that it will show up before the
8196 non-primary symtabs in the objfile's symtab list. */
8197 if (current_subfile
== first_subfile
)
8200 if (current_subfile
->symtab
== NULL
)
8201 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
8203 fe
->symtab
= current_subfile
->symtab
;
8208 /* Start a subfile for DWARF. FILENAME is the name of the file and
8209 DIRNAME the name of the source directory which contains FILENAME
8210 or NULL if not known. COMP_DIR is the compilation directory for the
8211 linetable's compilation unit or NULL if not known.
8212 This routine tries to keep line numbers from identical absolute and
8213 relative file names in a common subfile.
8215 Using the `list' example from the GDB testsuite, which resides in
8216 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
8217 of /srcdir/list0.c yields the following debugging information for list0.c:
8219 DW_AT_name: /srcdir/list0.c
8220 DW_AT_comp_dir: /compdir
8221 files.files[0].name: list0.h
8222 files.files[0].dir: /srcdir
8223 files.files[1].name: list0.c
8224 files.files[1].dir: /srcdir
8226 The line number information for list0.c has to end up in a single
8227 subfile, so that `break /srcdir/list0.c:1' works as expected.
8228 start_subfile will ensure that this happens provided that we pass the
8229 concatenation of files.files[1].dir and files.files[1].name as the
8233 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
8237 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
8238 `start_symtab' will always pass the contents of DW_AT_comp_dir as
8239 second argument to start_subfile. To be consistent, we do the
8240 same here. In order not to lose the line information directory,
8241 we concatenate it to the filename when it makes sense.
8242 Note that the Dwarf3 standard says (speaking of filenames in line
8243 information): ``The directory index is ignored for file names
8244 that represent full path names''. Thus ignoring dirname in the
8245 `else' branch below isn't an issue. */
8247 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
8248 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
8250 fullname
= filename
;
8252 start_subfile (fullname
, comp_dir
);
8254 if (fullname
!= filename
)
8259 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
8260 struct dwarf2_cu
*cu
)
8262 struct objfile
*objfile
= cu
->objfile
;
8263 struct comp_unit_head
*cu_header
= &cu
->header
;
8265 /* NOTE drow/2003-01-30: There used to be a comment and some special
8266 code here to turn a symbol with DW_AT_external and a
8267 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
8268 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
8269 with some versions of binutils) where shared libraries could have
8270 relocations against symbols in their debug information - the
8271 minimal symbol would have the right address, but the debug info
8272 would not. It's no longer necessary, because we will explicitly
8273 apply relocations when we read in the debug information now. */
8275 /* A DW_AT_location attribute with no contents indicates that a
8276 variable has been optimized away. */
8277 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
8279 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
8283 /* Handle one degenerate form of location expression specially, to
8284 preserve GDB's previous behavior when section offsets are
8285 specified. If this is just a DW_OP_addr then mark this symbol
8288 if (attr_form_is_block (attr
)
8289 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
8290 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
8294 SYMBOL_VALUE_ADDRESS (sym
) =
8295 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
8296 SYMBOL_CLASS (sym
) = LOC_STATIC
;
8297 fixup_symbol_section (sym
, objfile
);
8298 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
8299 SYMBOL_SECTION (sym
));
8303 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
8304 expression evaluator, and use LOC_COMPUTED only when necessary
8305 (i.e. when the value of a register or memory location is
8306 referenced, or a thread-local block, etc.). Then again, it might
8307 not be worthwhile. I'm assuming that it isn't unless performance
8308 or memory numbers show me otherwise. */
8310 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
8311 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
8314 /* Given a pointer to a DWARF information entry, figure out if we need
8315 to make a symbol table entry for it, and if so, create a new entry
8316 and return a pointer to it.
8317 If TYPE is NULL, determine symbol type from the die, otherwise
8318 used the passed type. */
8320 static struct symbol
*
8321 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
8323 struct objfile
*objfile
= cu
->objfile
;
8324 struct symbol
*sym
= NULL
;
8326 struct attribute
*attr
= NULL
;
8327 struct attribute
*attr2
= NULL
;
8329 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
8331 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8333 if (die
->tag
!= DW_TAG_namespace
)
8334 name
= dwarf2_linkage_name (die
, cu
);
8336 name
= TYPE_NAME (type
);
8340 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
8341 sizeof (struct symbol
));
8342 OBJSTAT (objfile
, n_syms
++);
8343 memset (sym
, 0, sizeof (struct symbol
));
8345 /* Cache this symbol's name and the name's demangled form (if any). */
8346 SYMBOL_LANGUAGE (sym
) = cu
->language
;
8347 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), 0, objfile
);
8349 /* Default assumptions.
8350 Use the passed type or decode it from the die. */
8351 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8352 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
8354 SYMBOL_TYPE (sym
) = type
;
8356 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
8357 attr
= dwarf2_attr (die
,
8358 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
8362 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
8365 attr
= dwarf2_attr (die
,
8366 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
8370 int file_index
= DW_UNSND (attr
);
8371 if (cu
->line_header
== NULL
8372 || file_index
> cu
->line_header
->num_file_names
)
8373 complaint (&symfile_complaints
,
8374 _("file index out of range"));
8375 else if (file_index
> 0)
8377 struct file_entry
*fe
;
8378 fe
= &cu
->line_header
->file_names
[file_index
- 1];
8379 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
8386 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8389 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
8391 SYMBOL_CLASS (sym
) = LOC_LABEL
;
8393 case DW_TAG_subprogram
:
8394 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8396 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
8397 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8398 if ((attr2
&& (DW_UNSND (attr2
) != 0))
8399 || cu
->language
== language_ada
)
8401 /* Subprograms marked external are stored as a global symbol.
8402 Ada subprograms, whether marked external or not, are always
8403 stored as a global symbol, because we want to be able to
8404 access them globally. For instance, we want to be able
8405 to break on a nested subprogram without having to
8406 specify the context. */
8407 add_symbol_to_list (sym
, &global_symbols
);
8411 add_symbol_to_list (sym
, cu
->list_in_scope
);
8414 case DW_TAG_inlined_subroutine
:
8415 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8417 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
8418 SYMBOL_INLINED (sym
) = 1;
8419 /* Do not add the symbol to any lists. It will be found via
8420 BLOCK_FUNCTION from the blockvector. */
8422 case DW_TAG_variable
:
8423 /* Compilation with minimal debug info may result in variables
8424 with missing type entries. Change the misleading `void' type
8425 to something sensible. */
8426 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
8428 = objfile_type (objfile
)->nodebug_data_symbol
;
8430 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8433 dwarf2_const_value (attr
, sym
, cu
);
8434 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8435 if (attr2
&& (DW_UNSND (attr2
) != 0))
8436 add_symbol_to_list (sym
, &global_symbols
);
8438 add_symbol_to_list (sym
, cu
->list_in_scope
);
8441 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8444 var_decode_location (attr
, sym
, cu
);
8445 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8446 if (attr2
&& (DW_UNSND (attr2
) != 0))
8447 add_symbol_to_list (sym
, &global_symbols
);
8449 add_symbol_to_list (sym
, cu
->list_in_scope
);
8453 /* We do not know the address of this symbol.
8454 If it is an external symbol and we have type information
8455 for it, enter the symbol as a LOC_UNRESOLVED symbol.
8456 The address of the variable will then be determined from
8457 the minimal symbol table whenever the variable is
8459 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8460 if (attr2
&& (DW_UNSND (attr2
) != 0)
8461 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
8463 struct pending
**list_to_add
;
8465 /* A variable with DW_AT_external is never static, but it
8466 may be block-scoped. */
8467 list_to_add
= (cu
->list_in_scope
== &file_symbols
8468 ? &global_symbols
: cu
->list_in_scope
);
8470 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
8471 add_symbol_to_list (sym
, list_to_add
);
8473 else if (!die_is_declaration (die
, cu
))
8475 /* Use the default LOC_OPTIMIZED_OUT class. */
8476 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
8477 add_symbol_to_list (sym
, cu
->list_in_scope
);
8481 case DW_TAG_formal_parameter
:
8482 /* If we are inside a function, mark this as an argument. If
8483 not, we might be looking at an argument to an inlined function
8484 when we do not have enough information to show inlined frames;
8485 pretend it's a local variable in that case so that the user can
8487 if (context_stack_depth
> 0
8488 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
8489 SYMBOL_IS_ARGUMENT (sym
) = 1;
8490 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8493 var_decode_location (attr
, sym
, cu
);
8495 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8498 dwarf2_const_value (attr
, sym
, cu
);
8500 add_symbol_to_list (sym
, cu
->list_in_scope
);
8502 case DW_TAG_unspecified_parameters
:
8503 /* From varargs functions; gdb doesn't seem to have any
8504 interest in this information, so just ignore it for now.
8507 case DW_TAG_class_type
:
8508 case DW_TAG_interface_type
:
8509 case DW_TAG_structure_type
:
8510 case DW_TAG_union_type
:
8511 case DW_TAG_set_type
:
8512 case DW_TAG_enumeration_type
:
8513 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8514 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8516 /* Make sure that the symbol includes appropriate enclosing
8517 classes/namespaces in its name. These are calculated in
8518 read_structure_type, and the correct name is saved in
8521 if (cu
->language
== language_cplus
8522 || cu
->language
== language_java
)
8524 struct type
*type
= SYMBOL_TYPE (sym
);
8526 if (TYPE_TAG_NAME (type
) != NULL
)
8528 /* FIXME: carlton/2003-11-10: Should this use
8529 SYMBOL_SET_NAMES instead? (The same problem also
8530 arises further down in this function.) */
8531 /* The type's name is already allocated along with
8532 this objfile, so we don't need to duplicate it
8534 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
8539 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
8540 really ever be static objects: otherwise, if you try
8541 to, say, break of a class's method and you're in a file
8542 which doesn't mention that class, it won't work unless
8543 the check for all static symbols in lookup_symbol_aux
8544 saves you. See the OtherFileClass tests in
8545 gdb.c++/namespace.exp. */
8547 struct pending
**list_to_add
;
8549 list_to_add
= (cu
->list_in_scope
== &file_symbols
8550 && (cu
->language
== language_cplus
8551 || cu
->language
== language_java
)
8552 ? &global_symbols
: cu
->list_in_scope
);
8554 add_symbol_to_list (sym
, list_to_add
);
8556 /* The semantics of C++ state that "struct foo { ... }" also
8557 defines a typedef for "foo". A Java class declaration also
8558 defines a typedef for the class. */
8559 if (cu
->language
== language_cplus
8560 || cu
->language
== language_java
8561 || cu
->language
== language_ada
)
8563 /* The symbol's name is already allocated along with
8564 this objfile, so we don't need to duplicate it for
8566 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
8567 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
8571 case DW_TAG_typedef
:
8572 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
8573 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8574 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8575 add_symbol_to_list (sym
, cu
->list_in_scope
);
8577 case DW_TAG_base_type
:
8578 case DW_TAG_subrange_type
:
8579 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8580 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8581 add_symbol_to_list (sym
, cu
->list_in_scope
);
8583 case DW_TAG_enumerator
:
8584 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
8585 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8588 dwarf2_const_value (attr
, sym
, cu
);
8591 /* NOTE: carlton/2003-11-10: See comment above in the
8592 DW_TAG_class_type, etc. block. */
8594 struct pending
**list_to_add
;
8596 list_to_add
= (cu
->list_in_scope
== &file_symbols
8597 && (cu
->language
== language_cplus
8598 || cu
->language
== language_java
)
8599 ? &global_symbols
: cu
->list_in_scope
);
8601 add_symbol_to_list (sym
, list_to_add
);
8604 case DW_TAG_namespace
:
8605 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8606 add_symbol_to_list (sym
, &global_symbols
);
8609 /* Not a tag we recognize. Hopefully we aren't processing
8610 trash data, but since we must specifically ignore things
8611 we don't recognize, there is nothing else we should do at
8613 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
8614 dwarf_tag_name (die
->tag
));
8618 /* For the benefit of old versions of GCC, check for anonymous
8619 namespaces based on the demangled name. */
8620 if (!processing_has_namespace_info
8621 && cu
->language
== language_cplus
8622 && dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
) != NULL
)
8623 cp_scan_for_anonymous_namespaces (sym
);
8628 /* Copy constant value from an attribute to a symbol. */
8631 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
8632 struct dwarf2_cu
*cu
)
8634 struct objfile
*objfile
= cu
->objfile
;
8635 struct comp_unit_head
*cu_header
= &cu
->header
;
8636 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
8637 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
8638 struct dwarf_block
*blk
;
8643 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
8644 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
8645 cu_header
->addr_size
,
8646 TYPE_LENGTH (SYMBOL_TYPE
8648 SYMBOL_VALUE_BYTES (sym
) =
8649 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
8650 /* NOTE: cagney/2003-05-09: In-lined store_address call with
8651 it's body - store_unsigned_integer. */
8652 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
8653 byte_order
, DW_ADDR (attr
));
8654 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8656 case DW_FORM_string
:
8658 /* DW_STRING is already allocated on the obstack, point directly
8660 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
8661 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8663 case DW_FORM_block1
:
8664 case DW_FORM_block2
:
8665 case DW_FORM_block4
:
8667 blk
= DW_BLOCK (attr
);
8668 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
8669 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
8671 TYPE_LENGTH (SYMBOL_TYPE
8673 SYMBOL_VALUE_BYTES (sym
) =
8674 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
8675 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
8676 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8679 /* The DW_AT_const_value attributes are supposed to carry the
8680 symbol's value "represented as it would be on the target
8681 architecture." By the time we get here, it's already been
8682 converted to host endianness, so we just need to sign- or
8683 zero-extend it as appropriate. */
8685 dwarf2_const_value_data (attr
, sym
, 8);
8688 dwarf2_const_value_data (attr
, sym
, 16);
8691 dwarf2_const_value_data (attr
, sym
, 32);
8694 dwarf2_const_value_data (attr
, sym
, 64);
8698 SYMBOL_VALUE (sym
) = DW_SND (attr
);
8699 SYMBOL_CLASS (sym
) = LOC_CONST
;
8703 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
8704 SYMBOL_CLASS (sym
) = LOC_CONST
;
8708 complaint (&symfile_complaints
,
8709 _("unsupported const value attribute form: '%s'"),
8710 dwarf_form_name (attr
->form
));
8711 SYMBOL_VALUE (sym
) = 0;
8712 SYMBOL_CLASS (sym
) = LOC_CONST
;
8718 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
8719 or zero-extend it as appropriate for the symbol's type. */
8721 dwarf2_const_value_data (struct attribute
*attr
,
8725 LONGEST l
= DW_UNSND (attr
);
8727 if (bits
< sizeof (l
) * 8)
8729 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
8730 l
&= ((LONGEST
) 1 << bits
) - 1;
8732 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
8735 SYMBOL_VALUE (sym
) = l
;
8736 SYMBOL_CLASS (sym
) = LOC_CONST
;
8740 /* Return the type of the die in question using its DW_AT_type attribute. */
8742 static struct type
*
8743 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8746 struct attribute
*type_attr
;
8747 struct die_info
*type_die
;
8749 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
8752 /* A missing DW_AT_type represents a void type. */
8753 return objfile_type (cu
->objfile
)->builtin_void
;
8756 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
8758 type
= tag_type_to_type (type_die
, cu
);
8761 dump_die_for_error (type_die
);
8762 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
8768 /* True iff CU's producer generates GNAT Ada auxiliary information
8769 that allows to find parallel types through that information instead
8770 of having to do expensive parallel lookups by type name. */
8773 need_gnat_info (struct dwarf2_cu
*cu
)
8775 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
8776 of GNAT produces this auxiliary information, without any indication
8777 that it is produced. Part of enhancing the FSF version of GNAT
8778 to produce that information will be to put in place an indicator
8779 that we can use in order to determine whether the descriptive type
8780 info is available or not. One suggestion that has been made is
8781 to use a new attribute, attached to the CU die. For now, assume
8782 that the descriptive type info is not available. */
8787 /* Return the auxiliary type of the die in question using its
8788 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
8789 attribute is not present. */
8791 static struct type
*
8792 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8795 struct attribute
*type_attr
;
8796 struct die_info
*type_die
;
8798 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
8802 type_die
= follow_die_ref (die
, type_attr
, &cu
);
8803 type
= tag_type_to_type (type_die
, cu
);
8806 dump_die_for_error (type_die
);
8807 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
8813 /* If DIE has a descriptive_type attribute, then set the TYPE's
8814 descriptive type accordingly. */
8817 set_descriptive_type (struct type
*type
, struct die_info
*die
,
8818 struct dwarf2_cu
*cu
)
8820 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
8822 if (descriptive_type
)
8824 ALLOCATE_GNAT_AUX_TYPE (type
);
8825 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
8829 /* Return the containing type of the die in question using its
8830 DW_AT_containing_type attribute. */
8832 static struct type
*
8833 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8835 struct type
*type
= NULL
;
8836 struct attribute
*type_attr
;
8837 struct die_info
*type_die
= NULL
;
8839 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
8842 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
8843 type
= tag_type_to_type (type_die
, cu
);
8848 dump_die_for_error (type_die
);
8849 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
8855 static struct type
*
8856 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8858 struct type
*this_type
;
8860 this_type
= read_type_die (die
, cu
);
8863 dump_die_for_error (die
);
8864 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
8870 static struct type
*
8871 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8873 struct type
*this_type
;
8875 this_type
= get_die_type (die
, cu
);
8881 case DW_TAG_class_type
:
8882 case DW_TAG_interface_type
:
8883 case DW_TAG_structure_type
:
8884 case DW_TAG_union_type
:
8885 this_type
= read_structure_type (die
, cu
);
8887 case DW_TAG_enumeration_type
:
8888 this_type
= read_enumeration_type (die
, cu
);
8890 case DW_TAG_subprogram
:
8891 case DW_TAG_subroutine_type
:
8892 case DW_TAG_inlined_subroutine
:
8893 this_type
= read_subroutine_type (die
, cu
);
8895 case DW_TAG_array_type
:
8896 this_type
= read_array_type (die
, cu
);
8898 case DW_TAG_set_type
:
8899 this_type
= read_set_type (die
, cu
);
8901 case DW_TAG_pointer_type
:
8902 this_type
= read_tag_pointer_type (die
, cu
);
8904 case DW_TAG_ptr_to_member_type
:
8905 this_type
= read_tag_ptr_to_member_type (die
, cu
);
8907 case DW_TAG_reference_type
:
8908 this_type
= read_tag_reference_type (die
, cu
);
8910 case DW_TAG_const_type
:
8911 this_type
= read_tag_const_type (die
, cu
);
8913 case DW_TAG_volatile_type
:
8914 this_type
= read_tag_volatile_type (die
, cu
);
8916 case DW_TAG_string_type
:
8917 this_type
= read_tag_string_type (die
, cu
);
8919 case DW_TAG_typedef
:
8920 this_type
= read_typedef (die
, cu
);
8922 case DW_TAG_subrange_type
:
8923 this_type
= read_subrange_type (die
, cu
);
8925 case DW_TAG_base_type
:
8926 this_type
= read_base_type (die
, cu
);
8928 case DW_TAG_unspecified_type
:
8929 this_type
= read_unspecified_type (die
, cu
);
8931 case DW_TAG_namespace
:
8932 this_type
= read_namespace_type (die
, cu
);
8935 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
8936 dwarf_tag_name (die
->tag
));
8943 /* Return the name of the namespace/class that DIE is defined within,
8944 or "" if we can't tell. The caller should not xfree the result.
8946 For example, if we're within the method foo() in the following
8956 then determine_prefix on foo's die will return "N::C". */
8959 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
8961 struct die_info
*parent
, *spec_die
;
8962 struct dwarf2_cu
*spec_cu
;
8963 struct type
*parent_type
;
8965 if (cu
->language
!= language_cplus
8966 && cu
->language
!= language_java
)
8969 /* We have to be careful in the presence of DW_AT_specification.
8970 For example, with GCC 3.4, given the code
8974 // Definition of N::foo.
8978 then we'll have a tree of DIEs like this:
8980 1: DW_TAG_compile_unit
8981 2: DW_TAG_namespace // N
8982 3: DW_TAG_subprogram // declaration of N::foo
8983 4: DW_TAG_subprogram // definition of N::foo
8984 DW_AT_specification // refers to die #3
8986 Thus, when processing die #4, we have to pretend that we're in
8987 the context of its DW_AT_specification, namely the contex of die
8990 spec_die
= die_specification (die
, &spec_cu
);
8991 if (spec_die
== NULL
)
8992 parent
= die
->parent
;
8995 parent
= spec_die
->parent
;
9002 switch (parent
->tag
)
9004 case DW_TAG_namespace
:
9005 parent_type
= read_type_die (parent
, cu
);
9006 /* We give a name to even anonymous namespaces. */
9007 return TYPE_TAG_NAME (parent_type
);
9008 case DW_TAG_class_type
:
9009 case DW_TAG_interface_type
:
9010 case DW_TAG_structure_type
:
9011 case DW_TAG_union_type
:
9012 parent_type
= read_type_die (parent
, cu
);
9013 if (TYPE_TAG_NAME (parent_type
) != NULL
)
9014 return TYPE_TAG_NAME (parent_type
);
9016 /* An anonymous structure is only allowed non-static data
9017 members; no typedefs, no member functions, et cetera.
9018 So it does not need a prefix. */
9021 return determine_prefix (parent
, cu
);
9025 /* Return a newly-allocated string formed by concatenating PREFIX and
9026 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
9027 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
9028 perform an obconcat, otherwise allocate storage for the result. The CU argument
9029 is used to determine the language and hence, the appropriate separator. */
9031 #define MAX_SEP_LEN 2 /* sizeof ("::") */
9034 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
9035 struct dwarf2_cu
*cu
)
9039 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
9041 else if (cu
->language
== language_java
)
9053 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
9054 strcpy (retval
, prefix
);
9055 strcat (retval
, sep
);
9056 strcat (retval
, suffix
);
9061 /* We have an obstack. */
9062 return obconcat (obs
, prefix
, sep
, suffix
);
9066 /* Return sibling of die, NULL if no sibling. */
9068 static struct die_info
*
9069 sibling_die (struct die_info
*die
)
9071 return die
->sibling
;
9074 /* Get linkage name of a die, return NULL if not found. */
9077 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9079 struct attribute
*attr
;
9081 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9082 if (attr
&& DW_STRING (attr
))
9083 return DW_STRING (attr
);
9084 return dwarf2_name (die
, cu
);
9087 /* Get name of a die, return NULL if not found. */
9090 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
9091 struct obstack
*obstack
)
9093 if (name
&& cu
->language
== language_cplus
)
9095 char *canon_name
= cp_canonicalize_string (name
);
9097 if (canon_name
!= NULL
)
9099 if (strcmp (canon_name
, name
) != 0)
9100 name
= obsavestring (canon_name
, strlen (canon_name
),
9109 /* Get name of a die, return NULL if not found. */
9112 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9114 struct attribute
*attr
;
9116 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
9117 if (!attr
|| !DW_STRING (attr
))
9122 case DW_TAG_compile_unit
:
9123 /* Compilation units have a DW_AT_name that is a filename, not
9124 a source language identifier. */
9125 case DW_TAG_enumeration_type
:
9126 case DW_TAG_enumerator
:
9127 /* These tags always have simple identifiers already; no need
9128 to canonicalize them. */
9129 return DW_STRING (attr
);
9131 if (!DW_STRING_IS_CANONICAL (attr
))
9134 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
9135 &cu
->objfile
->objfile_obstack
);
9136 DW_STRING_IS_CANONICAL (attr
) = 1;
9138 return DW_STRING (attr
);
9142 /* Return the die that this die in an extension of, or NULL if there
9143 is none. *EXT_CU is the CU containing DIE on input, and the CU
9144 containing the return value on output. */
9146 static struct die_info
*
9147 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
9149 struct attribute
*attr
;
9151 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
9155 return follow_die_ref (die
, attr
, ext_cu
);
9158 /* Convert a DIE tag into its string name. */
9161 dwarf_tag_name (unsigned tag
)
9165 case DW_TAG_padding
:
9166 return "DW_TAG_padding";
9167 case DW_TAG_array_type
:
9168 return "DW_TAG_array_type";
9169 case DW_TAG_class_type
:
9170 return "DW_TAG_class_type";
9171 case DW_TAG_entry_point
:
9172 return "DW_TAG_entry_point";
9173 case DW_TAG_enumeration_type
:
9174 return "DW_TAG_enumeration_type";
9175 case DW_TAG_formal_parameter
:
9176 return "DW_TAG_formal_parameter";
9177 case DW_TAG_imported_declaration
:
9178 return "DW_TAG_imported_declaration";
9180 return "DW_TAG_label";
9181 case DW_TAG_lexical_block
:
9182 return "DW_TAG_lexical_block";
9184 return "DW_TAG_member";
9185 case DW_TAG_pointer_type
:
9186 return "DW_TAG_pointer_type";
9187 case DW_TAG_reference_type
:
9188 return "DW_TAG_reference_type";
9189 case DW_TAG_compile_unit
:
9190 return "DW_TAG_compile_unit";
9191 case DW_TAG_string_type
:
9192 return "DW_TAG_string_type";
9193 case DW_TAG_structure_type
:
9194 return "DW_TAG_structure_type";
9195 case DW_TAG_subroutine_type
:
9196 return "DW_TAG_subroutine_type";
9197 case DW_TAG_typedef
:
9198 return "DW_TAG_typedef";
9199 case DW_TAG_union_type
:
9200 return "DW_TAG_union_type";
9201 case DW_TAG_unspecified_parameters
:
9202 return "DW_TAG_unspecified_parameters";
9203 case DW_TAG_variant
:
9204 return "DW_TAG_variant";
9205 case DW_TAG_common_block
:
9206 return "DW_TAG_common_block";
9207 case DW_TAG_common_inclusion
:
9208 return "DW_TAG_common_inclusion";
9209 case DW_TAG_inheritance
:
9210 return "DW_TAG_inheritance";
9211 case DW_TAG_inlined_subroutine
:
9212 return "DW_TAG_inlined_subroutine";
9214 return "DW_TAG_module";
9215 case DW_TAG_ptr_to_member_type
:
9216 return "DW_TAG_ptr_to_member_type";
9217 case DW_TAG_set_type
:
9218 return "DW_TAG_set_type";
9219 case DW_TAG_subrange_type
:
9220 return "DW_TAG_subrange_type";
9221 case DW_TAG_with_stmt
:
9222 return "DW_TAG_with_stmt";
9223 case DW_TAG_access_declaration
:
9224 return "DW_TAG_access_declaration";
9225 case DW_TAG_base_type
:
9226 return "DW_TAG_base_type";
9227 case DW_TAG_catch_block
:
9228 return "DW_TAG_catch_block";
9229 case DW_TAG_const_type
:
9230 return "DW_TAG_const_type";
9231 case DW_TAG_constant
:
9232 return "DW_TAG_constant";
9233 case DW_TAG_enumerator
:
9234 return "DW_TAG_enumerator";
9235 case DW_TAG_file_type
:
9236 return "DW_TAG_file_type";
9238 return "DW_TAG_friend";
9239 case DW_TAG_namelist
:
9240 return "DW_TAG_namelist";
9241 case DW_TAG_namelist_item
:
9242 return "DW_TAG_namelist_item";
9243 case DW_TAG_packed_type
:
9244 return "DW_TAG_packed_type";
9245 case DW_TAG_subprogram
:
9246 return "DW_TAG_subprogram";
9247 case DW_TAG_template_type_param
:
9248 return "DW_TAG_template_type_param";
9249 case DW_TAG_template_value_param
:
9250 return "DW_TAG_template_value_param";
9251 case DW_TAG_thrown_type
:
9252 return "DW_TAG_thrown_type";
9253 case DW_TAG_try_block
:
9254 return "DW_TAG_try_block";
9255 case DW_TAG_variant_part
:
9256 return "DW_TAG_variant_part";
9257 case DW_TAG_variable
:
9258 return "DW_TAG_variable";
9259 case DW_TAG_volatile_type
:
9260 return "DW_TAG_volatile_type";
9261 case DW_TAG_dwarf_procedure
:
9262 return "DW_TAG_dwarf_procedure";
9263 case DW_TAG_restrict_type
:
9264 return "DW_TAG_restrict_type";
9265 case DW_TAG_interface_type
:
9266 return "DW_TAG_interface_type";
9267 case DW_TAG_namespace
:
9268 return "DW_TAG_namespace";
9269 case DW_TAG_imported_module
:
9270 return "DW_TAG_imported_module";
9271 case DW_TAG_unspecified_type
:
9272 return "DW_TAG_unspecified_type";
9273 case DW_TAG_partial_unit
:
9274 return "DW_TAG_partial_unit";
9275 case DW_TAG_imported_unit
:
9276 return "DW_TAG_imported_unit";
9277 case DW_TAG_condition
:
9278 return "DW_TAG_condition";
9279 case DW_TAG_shared_type
:
9280 return "DW_TAG_shared_type";
9281 case DW_TAG_type_unit
:
9282 return "DW_TAG_type_unit";
9283 case DW_TAG_MIPS_loop
:
9284 return "DW_TAG_MIPS_loop";
9285 case DW_TAG_HP_array_descriptor
:
9286 return "DW_TAG_HP_array_descriptor";
9287 case DW_TAG_format_label
:
9288 return "DW_TAG_format_label";
9289 case DW_TAG_function_template
:
9290 return "DW_TAG_function_template";
9291 case DW_TAG_class_template
:
9292 return "DW_TAG_class_template";
9293 case DW_TAG_GNU_BINCL
:
9294 return "DW_TAG_GNU_BINCL";
9295 case DW_TAG_GNU_EINCL
:
9296 return "DW_TAG_GNU_EINCL";
9297 case DW_TAG_upc_shared_type
:
9298 return "DW_TAG_upc_shared_type";
9299 case DW_TAG_upc_strict_type
:
9300 return "DW_TAG_upc_strict_type";
9301 case DW_TAG_upc_relaxed_type
:
9302 return "DW_TAG_upc_relaxed_type";
9303 case DW_TAG_PGI_kanji_type
:
9304 return "DW_TAG_PGI_kanji_type";
9305 case DW_TAG_PGI_interface_block
:
9306 return "DW_TAG_PGI_interface_block";
9308 return "DW_TAG_<unknown>";
9312 /* Convert a DWARF attribute code into its string name. */
9315 dwarf_attr_name (unsigned attr
)
9320 return "DW_AT_sibling";
9321 case DW_AT_location
:
9322 return "DW_AT_location";
9324 return "DW_AT_name";
9325 case DW_AT_ordering
:
9326 return "DW_AT_ordering";
9327 case DW_AT_subscr_data
:
9328 return "DW_AT_subscr_data";
9329 case DW_AT_byte_size
:
9330 return "DW_AT_byte_size";
9331 case DW_AT_bit_offset
:
9332 return "DW_AT_bit_offset";
9333 case DW_AT_bit_size
:
9334 return "DW_AT_bit_size";
9335 case DW_AT_element_list
:
9336 return "DW_AT_element_list";
9337 case DW_AT_stmt_list
:
9338 return "DW_AT_stmt_list";
9340 return "DW_AT_low_pc";
9342 return "DW_AT_high_pc";
9343 case DW_AT_language
:
9344 return "DW_AT_language";
9346 return "DW_AT_member";
9348 return "DW_AT_discr";
9349 case DW_AT_discr_value
:
9350 return "DW_AT_discr_value";
9351 case DW_AT_visibility
:
9352 return "DW_AT_visibility";
9354 return "DW_AT_import";
9355 case DW_AT_string_length
:
9356 return "DW_AT_string_length";
9357 case DW_AT_common_reference
:
9358 return "DW_AT_common_reference";
9359 case DW_AT_comp_dir
:
9360 return "DW_AT_comp_dir";
9361 case DW_AT_const_value
:
9362 return "DW_AT_const_value";
9363 case DW_AT_containing_type
:
9364 return "DW_AT_containing_type";
9365 case DW_AT_default_value
:
9366 return "DW_AT_default_value";
9368 return "DW_AT_inline";
9369 case DW_AT_is_optional
:
9370 return "DW_AT_is_optional";
9371 case DW_AT_lower_bound
:
9372 return "DW_AT_lower_bound";
9373 case DW_AT_producer
:
9374 return "DW_AT_producer";
9375 case DW_AT_prototyped
:
9376 return "DW_AT_prototyped";
9377 case DW_AT_return_addr
:
9378 return "DW_AT_return_addr";
9379 case DW_AT_start_scope
:
9380 return "DW_AT_start_scope";
9381 case DW_AT_bit_stride
:
9382 return "DW_AT_bit_stride";
9383 case DW_AT_upper_bound
:
9384 return "DW_AT_upper_bound";
9385 case DW_AT_abstract_origin
:
9386 return "DW_AT_abstract_origin";
9387 case DW_AT_accessibility
:
9388 return "DW_AT_accessibility";
9389 case DW_AT_address_class
:
9390 return "DW_AT_address_class";
9391 case DW_AT_artificial
:
9392 return "DW_AT_artificial";
9393 case DW_AT_base_types
:
9394 return "DW_AT_base_types";
9395 case DW_AT_calling_convention
:
9396 return "DW_AT_calling_convention";
9398 return "DW_AT_count";
9399 case DW_AT_data_member_location
:
9400 return "DW_AT_data_member_location";
9401 case DW_AT_decl_column
:
9402 return "DW_AT_decl_column";
9403 case DW_AT_decl_file
:
9404 return "DW_AT_decl_file";
9405 case DW_AT_decl_line
:
9406 return "DW_AT_decl_line";
9407 case DW_AT_declaration
:
9408 return "DW_AT_declaration";
9409 case DW_AT_discr_list
:
9410 return "DW_AT_discr_list";
9411 case DW_AT_encoding
:
9412 return "DW_AT_encoding";
9413 case DW_AT_external
:
9414 return "DW_AT_external";
9415 case DW_AT_frame_base
:
9416 return "DW_AT_frame_base";
9418 return "DW_AT_friend";
9419 case DW_AT_identifier_case
:
9420 return "DW_AT_identifier_case";
9421 case DW_AT_macro_info
:
9422 return "DW_AT_macro_info";
9423 case DW_AT_namelist_items
:
9424 return "DW_AT_namelist_items";
9425 case DW_AT_priority
:
9426 return "DW_AT_priority";
9428 return "DW_AT_segment";
9429 case DW_AT_specification
:
9430 return "DW_AT_specification";
9431 case DW_AT_static_link
:
9432 return "DW_AT_static_link";
9434 return "DW_AT_type";
9435 case DW_AT_use_location
:
9436 return "DW_AT_use_location";
9437 case DW_AT_variable_parameter
:
9438 return "DW_AT_variable_parameter";
9439 case DW_AT_virtuality
:
9440 return "DW_AT_virtuality";
9441 case DW_AT_vtable_elem_location
:
9442 return "DW_AT_vtable_elem_location";
9443 /* DWARF 3 values. */
9444 case DW_AT_allocated
:
9445 return "DW_AT_allocated";
9446 case DW_AT_associated
:
9447 return "DW_AT_associated";
9448 case DW_AT_data_location
:
9449 return "DW_AT_data_location";
9450 case DW_AT_byte_stride
:
9451 return "DW_AT_byte_stride";
9452 case DW_AT_entry_pc
:
9453 return "DW_AT_entry_pc";
9454 case DW_AT_use_UTF8
:
9455 return "DW_AT_use_UTF8";
9456 case DW_AT_extension
:
9457 return "DW_AT_extension";
9459 return "DW_AT_ranges";
9460 case DW_AT_trampoline
:
9461 return "DW_AT_trampoline";
9462 case DW_AT_call_column
:
9463 return "DW_AT_call_column";
9464 case DW_AT_call_file
:
9465 return "DW_AT_call_file";
9466 case DW_AT_call_line
:
9467 return "DW_AT_call_line";
9468 case DW_AT_description
:
9469 return "DW_AT_description";
9470 case DW_AT_binary_scale
:
9471 return "DW_AT_binary_scale";
9472 case DW_AT_decimal_scale
:
9473 return "DW_AT_decimal_scale";
9475 return "DW_AT_small";
9476 case DW_AT_decimal_sign
:
9477 return "DW_AT_decimal_sign";
9478 case DW_AT_digit_count
:
9479 return "DW_AT_digit_count";
9480 case DW_AT_picture_string
:
9481 return "DW_AT_picture_string";
9483 return "DW_AT_mutable";
9484 case DW_AT_threads_scaled
:
9485 return "DW_AT_threads_scaled";
9486 case DW_AT_explicit
:
9487 return "DW_AT_explicit";
9488 case DW_AT_object_pointer
:
9489 return "DW_AT_object_pointer";
9490 case DW_AT_endianity
:
9491 return "DW_AT_endianity";
9492 case DW_AT_elemental
:
9493 return "DW_AT_elemental";
9495 return "DW_AT_pure";
9496 case DW_AT_recursive
:
9497 return "DW_AT_recursive";
9498 /* DWARF 4 values. */
9499 case DW_AT_signature
:
9500 return "DW_AT_signature";
9501 /* SGI/MIPS extensions. */
9502 #ifdef MIPS /* collides with DW_AT_HP_block_index */
9503 case DW_AT_MIPS_fde
:
9504 return "DW_AT_MIPS_fde";
9506 case DW_AT_MIPS_loop_begin
:
9507 return "DW_AT_MIPS_loop_begin";
9508 case DW_AT_MIPS_tail_loop_begin
:
9509 return "DW_AT_MIPS_tail_loop_begin";
9510 case DW_AT_MIPS_epilog_begin
:
9511 return "DW_AT_MIPS_epilog_begin";
9512 case DW_AT_MIPS_loop_unroll_factor
:
9513 return "DW_AT_MIPS_loop_unroll_factor";
9514 case DW_AT_MIPS_software_pipeline_depth
:
9515 return "DW_AT_MIPS_software_pipeline_depth";
9516 case DW_AT_MIPS_linkage_name
:
9517 return "DW_AT_MIPS_linkage_name";
9518 case DW_AT_MIPS_stride
:
9519 return "DW_AT_MIPS_stride";
9520 case DW_AT_MIPS_abstract_name
:
9521 return "DW_AT_MIPS_abstract_name";
9522 case DW_AT_MIPS_clone_origin
:
9523 return "DW_AT_MIPS_clone_origin";
9524 case DW_AT_MIPS_has_inlines
:
9525 return "DW_AT_MIPS_has_inlines";
9526 /* HP extensions. */
9527 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
9528 case DW_AT_HP_block_index
:
9529 return "DW_AT_HP_block_index";
9531 case DW_AT_HP_unmodifiable
:
9532 return "DW_AT_HP_unmodifiable";
9533 case DW_AT_HP_actuals_stmt_list
:
9534 return "DW_AT_HP_actuals_stmt_list";
9535 case DW_AT_HP_proc_per_section
:
9536 return "DW_AT_HP_proc_per_section";
9537 case DW_AT_HP_raw_data_ptr
:
9538 return "DW_AT_HP_raw_data_ptr";
9539 case DW_AT_HP_pass_by_reference
:
9540 return "DW_AT_HP_pass_by_reference";
9541 case DW_AT_HP_opt_level
:
9542 return "DW_AT_HP_opt_level";
9543 case DW_AT_HP_prof_version_id
:
9544 return "DW_AT_HP_prof_version_id";
9545 case DW_AT_HP_opt_flags
:
9546 return "DW_AT_HP_opt_flags";
9547 case DW_AT_HP_cold_region_low_pc
:
9548 return "DW_AT_HP_cold_region_low_pc";
9549 case DW_AT_HP_cold_region_high_pc
:
9550 return "DW_AT_HP_cold_region_high_pc";
9551 case DW_AT_HP_all_variables_modifiable
:
9552 return "DW_AT_HP_all_variables_modifiable";
9553 case DW_AT_HP_linkage_name
:
9554 return "DW_AT_HP_linkage_name";
9555 case DW_AT_HP_prof_flags
:
9556 return "DW_AT_HP_prof_flags";
9557 /* GNU extensions. */
9558 case DW_AT_sf_names
:
9559 return "DW_AT_sf_names";
9560 case DW_AT_src_info
:
9561 return "DW_AT_src_info";
9562 case DW_AT_mac_info
:
9563 return "DW_AT_mac_info";
9564 case DW_AT_src_coords
:
9565 return "DW_AT_src_coords";
9566 case DW_AT_body_begin
:
9567 return "DW_AT_body_begin";
9568 case DW_AT_body_end
:
9569 return "DW_AT_body_end";
9570 case DW_AT_GNU_vector
:
9571 return "DW_AT_GNU_vector";
9572 /* VMS extensions. */
9573 case DW_AT_VMS_rtnbeg_pd_address
:
9574 return "DW_AT_VMS_rtnbeg_pd_address";
9575 /* UPC extension. */
9576 case DW_AT_upc_threads_scaled
:
9577 return "DW_AT_upc_threads_scaled";
9578 /* PGI (STMicroelectronics) extensions. */
9579 case DW_AT_PGI_lbase
:
9580 return "DW_AT_PGI_lbase";
9581 case DW_AT_PGI_soffset
:
9582 return "DW_AT_PGI_soffset";
9583 case DW_AT_PGI_lstride
:
9584 return "DW_AT_PGI_lstride";
9586 return "DW_AT_<unknown>";
9590 /* Convert a DWARF value form code into its string name. */
9593 dwarf_form_name (unsigned form
)
9598 return "DW_FORM_addr";
9599 case DW_FORM_block2
:
9600 return "DW_FORM_block2";
9601 case DW_FORM_block4
:
9602 return "DW_FORM_block4";
9604 return "DW_FORM_data2";
9606 return "DW_FORM_data4";
9608 return "DW_FORM_data8";
9609 case DW_FORM_string
:
9610 return "DW_FORM_string";
9612 return "DW_FORM_block";
9613 case DW_FORM_block1
:
9614 return "DW_FORM_block1";
9616 return "DW_FORM_data1";
9618 return "DW_FORM_flag";
9620 return "DW_FORM_sdata";
9622 return "DW_FORM_strp";
9624 return "DW_FORM_udata";
9625 case DW_FORM_ref_addr
:
9626 return "DW_FORM_ref_addr";
9628 return "DW_FORM_ref1";
9630 return "DW_FORM_ref2";
9632 return "DW_FORM_ref4";
9634 return "DW_FORM_ref8";
9635 case DW_FORM_ref_udata
:
9636 return "DW_FORM_ref_udata";
9637 case DW_FORM_indirect
:
9638 return "DW_FORM_indirect";
9639 case DW_FORM_sec_offset
:
9640 return "DW_FORM_sec_offset";
9641 case DW_FORM_exprloc
:
9642 return "DW_FORM_exprloc";
9643 case DW_FORM_flag_present
:
9644 return "DW_FORM_flag_present";
9646 return "DW_FORM_sig8";
9648 return "DW_FORM_<unknown>";
9652 /* Convert a DWARF stack opcode into its string name. */
9655 dwarf_stack_op_name (unsigned op
)
9660 return "DW_OP_addr";
9662 return "DW_OP_deref";
9664 return "DW_OP_const1u";
9666 return "DW_OP_const1s";
9668 return "DW_OP_const2u";
9670 return "DW_OP_const2s";
9672 return "DW_OP_const4u";
9674 return "DW_OP_const4s";
9676 return "DW_OP_const8u";
9678 return "DW_OP_const8s";
9680 return "DW_OP_constu";
9682 return "DW_OP_consts";
9686 return "DW_OP_drop";
9688 return "DW_OP_over";
9690 return "DW_OP_pick";
9692 return "DW_OP_swap";
9696 return "DW_OP_xderef";
9704 return "DW_OP_minus";
9716 return "DW_OP_plus";
9717 case DW_OP_plus_uconst
:
9718 return "DW_OP_plus_uconst";
9724 return "DW_OP_shra";
9742 return "DW_OP_skip";
9744 return "DW_OP_lit0";
9746 return "DW_OP_lit1";
9748 return "DW_OP_lit2";
9750 return "DW_OP_lit3";
9752 return "DW_OP_lit4";
9754 return "DW_OP_lit5";
9756 return "DW_OP_lit6";
9758 return "DW_OP_lit7";
9760 return "DW_OP_lit8";
9762 return "DW_OP_lit9";
9764 return "DW_OP_lit10";
9766 return "DW_OP_lit11";
9768 return "DW_OP_lit12";
9770 return "DW_OP_lit13";
9772 return "DW_OP_lit14";
9774 return "DW_OP_lit15";
9776 return "DW_OP_lit16";
9778 return "DW_OP_lit17";
9780 return "DW_OP_lit18";
9782 return "DW_OP_lit19";
9784 return "DW_OP_lit20";
9786 return "DW_OP_lit21";
9788 return "DW_OP_lit22";
9790 return "DW_OP_lit23";
9792 return "DW_OP_lit24";
9794 return "DW_OP_lit25";
9796 return "DW_OP_lit26";
9798 return "DW_OP_lit27";
9800 return "DW_OP_lit28";
9802 return "DW_OP_lit29";
9804 return "DW_OP_lit30";
9806 return "DW_OP_lit31";
9808 return "DW_OP_reg0";
9810 return "DW_OP_reg1";
9812 return "DW_OP_reg2";
9814 return "DW_OP_reg3";
9816 return "DW_OP_reg4";
9818 return "DW_OP_reg5";
9820 return "DW_OP_reg6";
9822 return "DW_OP_reg7";
9824 return "DW_OP_reg8";
9826 return "DW_OP_reg9";
9828 return "DW_OP_reg10";
9830 return "DW_OP_reg11";
9832 return "DW_OP_reg12";
9834 return "DW_OP_reg13";
9836 return "DW_OP_reg14";
9838 return "DW_OP_reg15";
9840 return "DW_OP_reg16";
9842 return "DW_OP_reg17";
9844 return "DW_OP_reg18";
9846 return "DW_OP_reg19";
9848 return "DW_OP_reg20";
9850 return "DW_OP_reg21";
9852 return "DW_OP_reg22";
9854 return "DW_OP_reg23";
9856 return "DW_OP_reg24";
9858 return "DW_OP_reg25";
9860 return "DW_OP_reg26";
9862 return "DW_OP_reg27";
9864 return "DW_OP_reg28";
9866 return "DW_OP_reg29";
9868 return "DW_OP_reg30";
9870 return "DW_OP_reg31";
9872 return "DW_OP_breg0";
9874 return "DW_OP_breg1";
9876 return "DW_OP_breg2";
9878 return "DW_OP_breg3";
9880 return "DW_OP_breg4";
9882 return "DW_OP_breg5";
9884 return "DW_OP_breg6";
9886 return "DW_OP_breg7";
9888 return "DW_OP_breg8";
9890 return "DW_OP_breg9";
9892 return "DW_OP_breg10";
9894 return "DW_OP_breg11";
9896 return "DW_OP_breg12";
9898 return "DW_OP_breg13";
9900 return "DW_OP_breg14";
9902 return "DW_OP_breg15";
9904 return "DW_OP_breg16";
9906 return "DW_OP_breg17";
9908 return "DW_OP_breg18";
9910 return "DW_OP_breg19";
9912 return "DW_OP_breg20";
9914 return "DW_OP_breg21";
9916 return "DW_OP_breg22";
9918 return "DW_OP_breg23";
9920 return "DW_OP_breg24";
9922 return "DW_OP_breg25";
9924 return "DW_OP_breg26";
9926 return "DW_OP_breg27";
9928 return "DW_OP_breg28";
9930 return "DW_OP_breg29";
9932 return "DW_OP_breg30";
9934 return "DW_OP_breg31";
9936 return "DW_OP_regx";
9938 return "DW_OP_fbreg";
9940 return "DW_OP_bregx";
9942 return "DW_OP_piece";
9943 case DW_OP_deref_size
:
9944 return "DW_OP_deref_size";
9945 case DW_OP_xderef_size
:
9946 return "DW_OP_xderef_size";
9949 /* DWARF 3 extensions. */
9950 case DW_OP_push_object_address
:
9951 return "DW_OP_push_object_address";
9953 return "DW_OP_call2";
9955 return "DW_OP_call4";
9956 case DW_OP_call_ref
:
9957 return "DW_OP_call_ref";
9958 /* GNU extensions. */
9959 case DW_OP_form_tls_address
:
9960 return "DW_OP_form_tls_address";
9961 case DW_OP_call_frame_cfa
:
9962 return "DW_OP_call_frame_cfa";
9963 case DW_OP_bit_piece
:
9964 return "DW_OP_bit_piece";
9965 case DW_OP_GNU_push_tls_address
:
9966 return "DW_OP_GNU_push_tls_address";
9967 case DW_OP_GNU_uninit
:
9968 return "DW_OP_GNU_uninit";
9969 /* HP extensions. */
9970 case DW_OP_HP_is_value
:
9971 return "DW_OP_HP_is_value";
9972 case DW_OP_HP_fltconst4
:
9973 return "DW_OP_HP_fltconst4";
9974 case DW_OP_HP_fltconst8
:
9975 return "DW_OP_HP_fltconst8";
9976 case DW_OP_HP_mod_range
:
9977 return "DW_OP_HP_mod_range";
9978 case DW_OP_HP_unmod_range
:
9979 return "DW_OP_HP_unmod_range";
9981 return "DW_OP_HP_tls";
9983 return "OP_<unknown>";
9988 dwarf_bool_name (unsigned mybool
)
9996 /* Convert a DWARF type code into its string name. */
9999 dwarf_type_encoding_name (unsigned enc
)
10004 return "DW_ATE_void";
10005 case DW_ATE_address
:
10006 return "DW_ATE_address";
10007 case DW_ATE_boolean
:
10008 return "DW_ATE_boolean";
10009 case DW_ATE_complex_float
:
10010 return "DW_ATE_complex_float";
10012 return "DW_ATE_float";
10013 case DW_ATE_signed
:
10014 return "DW_ATE_signed";
10015 case DW_ATE_signed_char
:
10016 return "DW_ATE_signed_char";
10017 case DW_ATE_unsigned
:
10018 return "DW_ATE_unsigned";
10019 case DW_ATE_unsigned_char
:
10020 return "DW_ATE_unsigned_char";
10022 case DW_ATE_imaginary_float
:
10023 return "DW_ATE_imaginary_float";
10024 case DW_ATE_packed_decimal
:
10025 return "DW_ATE_packed_decimal";
10026 case DW_ATE_numeric_string
:
10027 return "DW_ATE_numeric_string";
10028 case DW_ATE_edited
:
10029 return "DW_ATE_edited";
10030 case DW_ATE_signed_fixed
:
10031 return "DW_ATE_signed_fixed";
10032 case DW_ATE_unsigned_fixed
:
10033 return "DW_ATE_unsigned_fixed";
10034 case DW_ATE_decimal_float
:
10035 return "DW_ATE_decimal_float";
10036 /* HP extensions. */
10037 case DW_ATE_HP_float80
:
10038 return "DW_ATE_HP_float80";
10039 case DW_ATE_HP_complex_float80
:
10040 return "DW_ATE_HP_complex_float80";
10041 case DW_ATE_HP_float128
:
10042 return "DW_ATE_HP_float128";
10043 case DW_ATE_HP_complex_float128
:
10044 return "DW_ATE_HP_complex_float128";
10045 case DW_ATE_HP_floathpintel
:
10046 return "DW_ATE_HP_floathpintel";
10047 case DW_ATE_HP_imaginary_float80
:
10048 return "DW_ATE_HP_imaginary_float80";
10049 case DW_ATE_HP_imaginary_float128
:
10050 return "DW_ATE_HP_imaginary_float128";
10052 return "DW_ATE_<unknown>";
10056 /* Convert a DWARF call frame info operation to its string name. */
10060 dwarf_cfi_name (unsigned cfi_opc
)
10064 case DW_CFA_advance_loc
:
10065 return "DW_CFA_advance_loc";
10066 case DW_CFA_offset
:
10067 return "DW_CFA_offset";
10068 case DW_CFA_restore
:
10069 return "DW_CFA_restore";
10071 return "DW_CFA_nop";
10072 case DW_CFA_set_loc
:
10073 return "DW_CFA_set_loc";
10074 case DW_CFA_advance_loc1
:
10075 return "DW_CFA_advance_loc1";
10076 case DW_CFA_advance_loc2
:
10077 return "DW_CFA_advance_loc2";
10078 case DW_CFA_advance_loc4
:
10079 return "DW_CFA_advance_loc4";
10080 case DW_CFA_offset_extended
:
10081 return "DW_CFA_offset_extended";
10082 case DW_CFA_restore_extended
:
10083 return "DW_CFA_restore_extended";
10084 case DW_CFA_undefined
:
10085 return "DW_CFA_undefined";
10086 case DW_CFA_same_value
:
10087 return "DW_CFA_same_value";
10088 case DW_CFA_register
:
10089 return "DW_CFA_register";
10090 case DW_CFA_remember_state
:
10091 return "DW_CFA_remember_state";
10092 case DW_CFA_restore_state
:
10093 return "DW_CFA_restore_state";
10094 case DW_CFA_def_cfa
:
10095 return "DW_CFA_def_cfa";
10096 case DW_CFA_def_cfa_register
:
10097 return "DW_CFA_def_cfa_register";
10098 case DW_CFA_def_cfa_offset
:
10099 return "DW_CFA_def_cfa_offset";
10101 case DW_CFA_def_cfa_expression
:
10102 return "DW_CFA_def_cfa_expression";
10103 case DW_CFA_expression
:
10104 return "DW_CFA_expression";
10105 case DW_CFA_offset_extended_sf
:
10106 return "DW_CFA_offset_extended_sf";
10107 case DW_CFA_def_cfa_sf
:
10108 return "DW_CFA_def_cfa_sf";
10109 case DW_CFA_def_cfa_offset_sf
:
10110 return "DW_CFA_def_cfa_offset_sf";
10111 case DW_CFA_val_offset
:
10112 return "DW_CFA_val_offset";
10113 case DW_CFA_val_offset_sf
:
10114 return "DW_CFA_val_offset_sf";
10115 case DW_CFA_val_expression
:
10116 return "DW_CFA_val_expression";
10117 /* SGI/MIPS specific. */
10118 case DW_CFA_MIPS_advance_loc8
:
10119 return "DW_CFA_MIPS_advance_loc8";
10120 /* GNU extensions. */
10121 case DW_CFA_GNU_window_save
:
10122 return "DW_CFA_GNU_window_save";
10123 case DW_CFA_GNU_args_size
:
10124 return "DW_CFA_GNU_args_size";
10125 case DW_CFA_GNU_negative_offset_extended
:
10126 return "DW_CFA_GNU_negative_offset_extended";
10128 return "DW_CFA_<unknown>";
10134 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
10138 print_spaces (indent
, f
);
10139 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
10140 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
10142 if (die
->parent
!= NULL
)
10144 print_spaces (indent
, f
);
10145 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
10146 die
->parent
->offset
);
10149 print_spaces (indent
, f
);
10150 fprintf_unfiltered (f
, " has children: %s\n",
10151 dwarf_bool_name (die
->child
!= NULL
));
10153 print_spaces (indent
, f
);
10154 fprintf_unfiltered (f
, " attributes:\n");
10156 for (i
= 0; i
< die
->num_attrs
; ++i
)
10158 print_spaces (indent
, f
);
10159 fprintf_unfiltered (f
, " %s (%s) ",
10160 dwarf_attr_name (die
->attrs
[i
].name
),
10161 dwarf_form_name (die
->attrs
[i
].form
));
10163 switch (die
->attrs
[i
].form
)
10165 case DW_FORM_ref_addr
:
10167 fprintf_unfiltered (f
, "address: ");
10168 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
10170 case DW_FORM_block2
:
10171 case DW_FORM_block4
:
10172 case DW_FORM_block
:
10173 case DW_FORM_block1
:
10174 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
10179 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
10180 (long) (DW_ADDR (&die
->attrs
[i
])));
10182 case DW_FORM_data1
:
10183 case DW_FORM_data2
:
10184 case DW_FORM_data4
:
10185 case DW_FORM_data8
:
10186 case DW_FORM_udata
:
10187 case DW_FORM_sdata
:
10188 fprintf_unfiltered (f
, "constant: %s",
10189 pulongest (DW_UNSND (&die
->attrs
[i
])));
10192 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
10193 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
10194 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
10196 fprintf_unfiltered (f
, "signatured type, offset: unknown");
10198 case DW_FORM_string
:
10200 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
10201 DW_STRING (&die
->attrs
[i
])
10202 ? DW_STRING (&die
->attrs
[i
]) : "",
10203 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
10206 if (DW_UNSND (&die
->attrs
[i
]))
10207 fprintf_unfiltered (f
, "flag: TRUE");
10209 fprintf_unfiltered (f
, "flag: FALSE");
10211 case DW_FORM_indirect
:
10212 /* the reader will have reduced the indirect form to
10213 the "base form" so this form should not occur */
10214 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
10217 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
10218 die
->attrs
[i
].form
);
10221 fprintf_unfiltered (f
, "\n");
10226 dump_die_for_error (struct die_info
*die
)
10228 dump_die_shallow (gdb_stderr
, 0, die
);
10232 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
10234 int indent
= level
* 4;
10236 gdb_assert (die
!= NULL
);
10238 if (level
>= max_level
)
10241 dump_die_shallow (f
, indent
, die
);
10243 if (die
->child
!= NULL
)
10245 print_spaces (indent
, f
);
10246 fprintf_unfiltered (f
, " Children:");
10247 if (level
+ 1 < max_level
)
10249 fprintf_unfiltered (f
, "\n");
10250 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
10254 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
10258 if (die
->sibling
!= NULL
&& level
> 0)
10260 dump_die_1 (f
, level
, max_level
, die
->sibling
);
10264 /* This is called from the pdie macro in gdbinit.in.
10265 It's not static so gcc will keep a copy callable from gdb. */
10268 dump_die (struct die_info
*die
, int max_level
)
10270 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
10274 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
10278 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
10284 is_ref_attr (struct attribute
*attr
)
10286 switch (attr
->form
)
10288 case DW_FORM_ref_addr
:
10293 case DW_FORM_ref_udata
:
10300 static unsigned int
10301 dwarf2_get_ref_die_offset (struct attribute
*attr
)
10303 if (is_ref_attr (attr
))
10304 return DW_ADDR (attr
);
10306 complaint (&symfile_complaints
,
10307 _("unsupported die ref attribute form: '%s'"),
10308 dwarf_form_name (attr
->form
));
10312 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
10313 * the value held by the attribute is not constant. */
10316 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
10318 if (attr
->form
== DW_FORM_sdata
)
10319 return DW_SND (attr
);
10320 else if (attr
->form
== DW_FORM_udata
10321 || attr
->form
== DW_FORM_data1
10322 || attr
->form
== DW_FORM_data2
10323 || attr
->form
== DW_FORM_data4
10324 || attr
->form
== DW_FORM_data8
)
10325 return DW_UNSND (attr
);
10328 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
10329 dwarf_form_name (attr
->form
));
10330 return default_value
;
10334 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
10335 unit and add it to our queue.
10336 The result is non-zero if PER_CU was queued, otherwise the result is zero
10337 meaning either PER_CU is already queued or it is already loaded. */
10340 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
10341 struct dwarf2_per_cu_data
*per_cu
)
10343 /* Mark the dependence relation so that we don't flush PER_CU
10345 dwarf2_add_dependence (this_cu
, per_cu
);
10347 /* If it's already on the queue, we have nothing to do. */
10348 if (per_cu
->queued
)
10351 /* If the compilation unit is already loaded, just mark it as
10353 if (per_cu
->cu
!= NULL
)
10355 per_cu
->cu
->last_used
= 0;
10359 /* Add it to the queue. */
10360 queue_comp_unit (per_cu
, this_cu
->objfile
);
10365 /* Follow reference or signature attribute ATTR of SRC_DIE.
10366 On entry *REF_CU is the CU of SRC_DIE.
10367 On exit *REF_CU is the CU of the result. */
10369 static struct die_info
*
10370 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
10371 struct dwarf2_cu
**ref_cu
)
10373 struct die_info
*die
;
10375 if (is_ref_attr (attr
))
10376 die
= follow_die_ref (src_die
, attr
, ref_cu
);
10377 else if (attr
->form
== DW_FORM_sig8
)
10378 die
= follow_die_sig (src_die
, attr
, ref_cu
);
10381 dump_die_for_error (src_die
);
10382 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
10383 (*ref_cu
)->objfile
->name
);
10389 /* Follow reference attribute ATTR of SRC_DIE.
10390 On entry *REF_CU is the CU of SRC_DIE.
10391 On exit *REF_CU is the CU of the result. */
10393 static struct die_info
*
10394 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
10395 struct dwarf2_cu
**ref_cu
)
10397 struct die_info
*die
;
10398 unsigned int offset
;
10399 struct die_info temp_die
;
10400 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
10402 gdb_assert (cu
->per_cu
!= NULL
);
10404 offset
= dwarf2_get_ref_die_offset (attr
);
10406 if (cu
->per_cu
->from_debug_types
)
10408 /* .debug_types CUs cannot reference anything outside their CU.
10409 If they need to, they have to reference a signatured type via
10411 if (! offset_in_cu_p (&cu
->header
, offset
))
10415 else if (! offset_in_cu_p (&cu
->header
, offset
))
10417 struct dwarf2_per_cu_data
*per_cu
;
10418 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
10420 /* If necessary, add it to the queue and load its DIEs. */
10421 if (maybe_queue_comp_unit (cu
, per_cu
))
10422 load_full_comp_unit (per_cu
, cu
->objfile
);
10424 target_cu
= per_cu
->cu
;
10429 *ref_cu
= target_cu
;
10430 temp_die
.offset
= offset
;
10431 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
10437 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
10438 "at 0x%x [in module %s]"),
10439 offset
, src_die
->offset
, cu
->objfile
->name
);
10442 /* Follow the signature attribute ATTR in SRC_DIE.
10443 On entry *REF_CU is the CU of SRC_DIE.
10444 On exit *REF_CU is the CU of the result. */
10446 static struct die_info
*
10447 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
10448 struct dwarf2_cu
**ref_cu
)
10450 struct objfile
*objfile
= (*ref_cu
)->objfile
;
10451 struct die_info temp_die
;
10452 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
10453 struct dwarf2_cu
*sig_cu
;
10454 struct die_info
*die
;
10456 /* sig_type will be NULL if the signatured type is missing from
10458 if (sig_type
== NULL
)
10459 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
10460 "at 0x%x [in module %s]"),
10461 src_die
->offset
, objfile
->name
);
10463 /* If necessary, add it to the queue and load its DIEs. */
10465 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
10466 read_signatured_type (objfile
, sig_type
);
10468 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
10470 sig_cu
= sig_type
->per_cu
.cu
;
10471 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
10472 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
10479 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
10480 "at 0x%x [in module %s]"),
10481 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
10484 /* Given an offset of a signatured type, return its signatured_type. */
10486 static struct signatured_type
*
10487 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
10489 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
10490 unsigned int length
, initial_length_size
;
10491 unsigned int sig_offset
;
10492 struct signatured_type find_entry
, *type_sig
;
10494 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
10495 sig_offset
= (initial_length_size
10497 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
10498 + 1 /*address_size*/);
10499 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
10500 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
10502 /* This is only used to lookup previously recorded types.
10503 If we didn't find it, it's our bug. */
10504 gdb_assert (type_sig
!= NULL
);
10505 gdb_assert (offset
== type_sig
->offset
);
10510 /* Read in signatured type at OFFSET and build its CU and die(s). */
10513 read_signatured_type_at_offset (struct objfile
*objfile
,
10514 unsigned int offset
)
10516 struct signatured_type
*type_sig
;
10518 /* We have the section offset, but we need the signature to do the
10519 hash table lookup. */
10520 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
10522 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
10524 read_signatured_type (objfile
, type_sig
);
10526 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
10529 /* Read in a signatured type and build its CU and DIEs. */
10532 read_signatured_type (struct objfile
*objfile
,
10533 struct signatured_type
*type_sig
)
10535 gdb_byte
*types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
10536 struct die_reader_specs reader_specs
;
10537 struct dwarf2_cu
*cu
;
10538 ULONGEST signature
;
10539 struct cleanup
*back_to
, *free_cu_cleanup
;
10540 struct attribute
*attr
;
10542 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
10544 cu
= xmalloc (sizeof (struct dwarf2_cu
));
10545 memset (cu
, 0, sizeof (struct dwarf2_cu
));
10546 obstack_init (&cu
->comp_unit_obstack
);
10547 cu
->objfile
= objfile
;
10548 type_sig
->per_cu
.cu
= cu
;
10549 cu
->per_cu
= &type_sig
->per_cu
;
10551 /* If an error occurs while loading, release our storage. */
10552 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
10554 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
10555 types_ptr
, objfile
->obfd
);
10556 gdb_assert (signature
== type_sig
->signature
);
10559 = htab_create_alloc_ex (cu
->header
.length
/ 12,
10563 &cu
->comp_unit_obstack
,
10564 hashtab_obstack_allocate
,
10565 dummy_obstack_deallocate
);
10567 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
10568 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
10570 init_cu_die_reader (&reader_specs
, cu
);
10572 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
10575 /* We try not to read any attributes in this function, because not
10576 all objfiles needed for references have been loaded yet, and symbol
10577 table processing isn't initialized. But we have to set the CU language,
10578 or we won't be able to build types correctly. */
10579 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
10581 set_cu_language (DW_UNSND (attr
), cu
);
10583 set_cu_language (language_minimal
, cu
);
10585 do_cleanups (back_to
);
10587 /* We've successfully allocated this compilation unit. Let our caller
10588 clean it up when finished with it. */
10589 discard_cleanups (free_cu_cleanup
);
10591 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
10592 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
10595 /* Decode simple location descriptions.
10596 Given a pointer to a dwarf block that defines a location, compute
10597 the location and return the value.
10599 NOTE drow/2003-11-18: This function is called in two situations
10600 now: for the address of static or global variables (partial symbols
10601 only) and for offsets into structures which are expected to be
10602 (more or less) constant. The partial symbol case should go away,
10603 and only the constant case should remain. That will let this
10604 function complain more accurately. A few special modes are allowed
10605 without complaint for global variables (for instance, global
10606 register values and thread-local values).
10608 A location description containing no operations indicates that the
10609 object is optimized out. The return value is 0 for that case.
10610 FIXME drow/2003-11-16: No callers check for this case any more; soon all
10611 callers will only want a very basic result and this can become a
10614 Note that stack[0] is unused except as a default error return.
10615 Note that stack overflow is not yet handled. */
10618 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
10620 struct objfile
*objfile
= cu
->objfile
;
10621 struct comp_unit_head
*cu_header
= &cu
->header
;
10623 int size
= blk
->size
;
10624 gdb_byte
*data
= blk
->data
;
10625 CORE_ADDR stack
[64];
10627 unsigned int bytes_read
, unsnd
;
10671 stack
[++stacki
] = op
- DW_OP_lit0
;
10706 stack
[++stacki
] = op
- DW_OP_reg0
;
10708 dwarf2_complex_location_expr_complaint ();
10712 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
10714 stack
[++stacki
] = unsnd
;
10716 dwarf2_complex_location_expr_complaint ();
10720 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
10725 case DW_OP_const1u
:
10726 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
10730 case DW_OP_const1s
:
10731 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
10735 case DW_OP_const2u
:
10736 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
10740 case DW_OP_const2s
:
10741 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
10745 case DW_OP_const4u
:
10746 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
10750 case DW_OP_const4s
:
10751 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
10756 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
10762 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
10767 stack
[stacki
+ 1] = stack
[stacki
];
10772 stack
[stacki
- 1] += stack
[stacki
];
10776 case DW_OP_plus_uconst
:
10777 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
10782 stack
[stacki
- 1] -= stack
[stacki
];
10787 /* If we're not the last op, then we definitely can't encode
10788 this using GDB's address_class enum. This is valid for partial
10789 global symbols, although the variable's address will be bogus
10792 dwarf2_complex_location_expr_complaint ();
10795 case DW_OP_GNU_push_tls_address
:
10796 /* The top of the stack has the offset from the beginning
10797 of the thread control block at which the variable is located. */
10798 /* Nothing should follow this operator, so the top of stack would
10800 /* This is valid for partial global symbols, but the variable's
10801 address will be bogus in the psymtab. */
10803 dwarf2_complex_location_expr_complaint ();
10806 case DW_OP_GNU_uninit
:
10810 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
10811 dwarf_stack_op_name (op
));
10812 return (stack
[stacki
]);
10815 return (stack
[stacki
]);
10818 /* memory allocation interface */
10820 static struct dwarf_block
*
10821 dwarf_alloc_block (struct dwarf2_cu
*cu
)
10823 struct dwarf_block
*blk
;
10825 blk
= (struct dwarf_block
*)
10826 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
10830 static struct abbrev_info
*
10831 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
10833 struct abbrev_info
*abbrev
;
10835 abbrev
= (struct abbrev_info
*)
10836 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
10837 memset (abbrev
, 0, sizeof (struct abbrev_info
));
10841 static struct die_info
*
10842 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
10844 struct die_info
*die
;
10845 size_t size
= sizeof (struct die_info
);
10848 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
10850 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
10851 memset (die
, 0, sizeof (struct die_info
));
10856 /* Macro support. */
10859 /* Return the full name of file number I in *LH's file name table.
10860 Use COMP_DIR as the name of the current directory of the
10861 compilation. The result is allocated using xmalloc; the caller is
10862 responsible for freeing it. */
10864 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
10866 /* Is the file number a valid index into the line header's file name
10867 table? Remember that file numbers start with one, not zero. */
10868 if (1 <= file
&& file
<= lh
->num_file_names
)
10870 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10872 if (IS_ABSOLUTE_PATH (fe
->name
))
10873 return xstrdup (fe
->name
);
10881 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10887 dir_len
= strlen (dir
);
10888 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
10889 strcpy (full_name
, dir
);
10890 full_name
[dir_len
] = '/';
10891 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
10895 return xstrdup (fe
->name
);
10900 /* The compiler produced a bogus file number. We can at least
10901 record the macro definitions made in the file, even if we
10902 won't be able to find the file by name. */
10903 char fake_name
[80];
10904 sprintf (fake_name
, "<bad macro file number %d>", file
);
10906 complaint (&symfile_complaints
,
10907 _("bad file number in macro information (%d)"),
10910 return xstrdup (fake_name
);
10915 static struct macro_source_file
*
10916 macro_start_file (int file
, int line
,
10917 struct macro_source_file
*current_file
,
10918 const char *comp_dir
,
10919 struct line_header
*lh
, struct objfile
*objfile
)
10921 /* The full name of this source file. */
10922 char *full_name
= file_full_name (file
, lh
, comp_dir
);
10924 /* We don't create a macro table for this compilation unit
10925 at all until we actually get a filename. */
10926 if (! pending_macros
)
10927 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
10928 objfile
->macro_cache
);
10930 if (! current_file
)
10931 /* If we have no current file, then this must be the start_file
10932 directive for the compilation unit's main source file. */
10933 current_file
= macro_set_main (pending_macros
, full_name
);
10935 current_file
= macro_include (current_file
, line
, full_name
);
10939 return current_file
;
10943 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
10944 followed by a null byte. */
10946 copy_string (const char *buf
, int len
)
10948 char *s
= xmalloc (len
+ 1);
10949 memcpy (s
, buf
, len
);
10956 static const char *
10957 consume_improper_spaces (const char *p
, const char *body
)
10961 complaint (&symfile_complaints
,
10962 _("macro definition contains spaces in formal argument list:\n`%s'"),
10974 parse_macro_definition (struct macro_source_file
*file
, int line
,
10979 /* The body string takes one of two forms. For object-like macro
10980 definitions, it should be:
10982 <macro name> " " <definition>
10984 For function-like macro definitions, it should be:
10986 <macro name> "() " <definition>
10988 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
10990 Spaces may appear only where explicitly indicated, and in the
10993 The Dwarf 2 spec says that an object-like macro's name is always
10994 followed by a space, but versions of GCC around March 2002 omit
10995 the space when the macro's definition is the empty string.
10997 The Dwarf 2 spec says that there should be no spaces between the
10998 formal arguments in a function-like macro's formal argument list,
10999 but versions of GCC around March 2002 include spaces after the
11003 /* Find the extent of the macro name. The macro name is terminated
11004 by either a space or null character (for an object-like macro) or
11005 an opening paren (for a function-like macro). */
11006 for (p
= body
; *p
; p
++)
11007 if (*p
== ' ' || *p
== '(')
11010 if (*p
== ' ' || *p
== '\0')
11012 /* It's an object-like macro. */
11013 int name_len
= p
- body
;
11014 char *name
= copy_string (body
, name_len
);
11015 const char *replacement
;
11018 replacement
= body
+ name_len
+ 1;
11021 dwarf2_macro_malformed_definition_complaint (body
);
11022 replacement
= body
+ name_len
;
11025 macro_define_object (file
, line
, name
, replacement
);
11029 else if (*p
== '(')
11031 /* It's a function-like macro. */
11032 char *name
= copy_string (body
, p
- body
);
11035 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
11039 p
= consume_improper_spaces (p
, body
);
11041 /* Parse the formal argument list. */
11042 while (*p
&& *p
!= ')')
11044 /* Find the extent of the current argument name. */
11045 const char *arg_start
= p
;
11047 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
11050 if (! *p
|| p
== arg_start
)
11051 dwarf2_macro_malformed_definition_complaint (body
);
11054 /* Make sure argv has room for the new argument. */
11055 if (argc
>= argv_size
)
11058 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
11061 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
11064 p
= consume_improper_spaces (p
, body
);
11066 /* Consume the comma, if present. */
11071 p
= consume_improper_spaces (p
, body
);
11080 /* Perfectly formed definition, no complaints. */
11081 macro_define_function (file
, line
, name
,
11082 argc
, (const char **) argv
,
11084 else if (*p
== '\0')
11086 /* Complain, but do define it. */
11087 dwarf2_macro_malformed_definition_complaint (body
);
11088 macro_define_function (file
, line
, name
,
11089 argc
, (const char **) argv
,
11093 /* Just complain. */
11094 dwarf2_macro_malformed_definition_complaint (body
);
11097 /* Just complain. */
11098 dwarf2_macro_malformed_definition_complaint (body
);
11104 for (i
= 0; i
< argc
; i
++)
11110 dwarf2_macro_malformed_definition_complaint (body
);
11115 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
11116 char *comp_dir
, bfd
*abfd
,
11117 struct dwarf2_cu
*cu
)
11119 gdb_byte
*mac_ptr
, *mac_end
;
11120 struct macro_source_file
*current_file
= 0;
11121 enum dwarf_macinfo_record_type macinfo_type
;
11122 int at_commandline
;
11124 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
11126 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
11130 /* First pass: Find the name of the base filename.
11131 This filename is needed in order to process all macros whose definition
11132 (or undefinition) comes from the command line. These macros are defined
11133 before the first DW_MACINFO_start_file entry, and yet still need to be
11134 associated to the base file.
11136 To determine the base file name, we scan the macro definitions until we
11137 reach the first DW_MACINFO_start_file entry. We then initialize
11138 CURRENT_FILE accordingly so that any macro definition found before the
11139 first DW_MACINFO_start_file can still be associated to the base file. */
11141 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
11142 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
11143 + dwarf2_per_objfile
->macinfo
.size
;
11147 /* Do we at least have room for a macinfo type byte? */
11148 if (mac_ptr
>= mac_end
)
11150 /* Complaint is printed during the second pass as GDB will probably
11151 stop the first pass earlier upon finding DW_MACINFO_start_file. */
11155 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
11158 switch (macinfo_type
)
11160 /* A zero macinfo type indicates the end of the macro
11165 case DW_MACINFO_define
:
11166 case DW_MACINFO_undef
:
11167 /* Only skip the data by MAC_PTR. */
11169 unsigned int bytes_read
;
11171 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11172 mac_ptr
+= bytes_read
;
11173 read_string (abfd
, mac_ptr
, &bytes_read
);
11174 mac_ptr
+= bytes_read
;
11178 case DW_MACINFO_start_file
:
11180 unsigned int bytes_read
;
11183 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11184 mac_ptr
+= bytes_read
;
11185 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11186 mac_ptr
+= bytes_read
;
11188 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
11193 case DW_MACINFO_end_file
:
11194 /* No data to skip by MAC_PTR. */
11197 case DW_MACINFO_vendor_ext
:
11198 /* Only skip the data by MAC_PTR. */
11200 unsigned int bytes_read
;
11202 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11203 mac_ptr
+= bytes_read
;
11204 read_string (abfd
, mac_ptr
, &bytes_read
);
11205 mac_ptr
+= bytes_read
;
11212 } while (macinfo_type
!= 0 && current_file
== NULL
);
11214 /* Second pass: Process all entries.
11216 Use the AT_COMMAND_LINE flag to determine whether we are still processing
11217 command-line macro definitions/undefinitions. This flag is unset when we
11218 reach the first DW_MACINFO_start_file entry. */
11220 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
11222 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
11223 GDB is still reading the definitions from command line. First
11224 DW_MACINFO_start_file will need to be ignored as it was already executed
11225 to create CURRENT_FILE for the main source holding also the command line
11226 definitions. On first met DW_MACINFO_start_file this flag is reset to
11227 normally execute all the remaining DW_MACINFO_start_file macinfos. */
11229 at_commandline
= 1;
11233 /* Do we at least have room for a macinfo type byte? */
11234 if (mac_ptr
>= mac_end
)
11236 dwarf2_macros_too_long_complaint ();
11240 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
11243 switch (macinfo_type
)
11245 /* A zero macinfo type indicates the end of the macro
11250 case DW_MACINFO_define
:
11251 case DW_MACINFO_undef
:
11253 unsigned int bytes_read
;
11257 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11258 mac_ptr
+= bytes_read
;
11259 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
11260 mac_ptr
+= bytes_read
;
11262 if (! current_file
)
11264 /* DWARF violation as no main source is present. */
11265 complaint (&symfile_complaints
,
11266 _("debug info with no main source gives macro %s "
11268 macinfo_type
== DW_MACINFO_define
?
11270 macinfo_type
== DW_MACINFO_undef
?
11271 _("undefinition") :
11272 _("something-or-other"), line
, body
);
11275 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
11276 complaint (&symfile_complaints
,
11277 _("debug info gives %s macro %s with %s line %d: %s"),
11278 at_commandline
? _("command-line") : _("in-file"),
11279 macinfo_type
== DW_MACINFO_define
?
11281 macinfo_type
== DW_MACINFO_undef
?
11282 _("undefinition") :
11283 _("something-or-other"),
11284 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
11286 if (macinfo_type
== DW_MACINFO_define
)
11287 parse_macro_definition (current_file
, line
, body
);
11288 else if (macinfo_type
== DW_MACINFO_undef
)
11289 macro_undef (current_file
, line
, body
);
11293 case DW_MACINFO_start_file
:
11295 unsigned int bytes_read
;
11298 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11299 mac_ptr
+= bytes_read
;
11300 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11301 mac_ptr
+= bytes_read
;
11303 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
11304 complaint (&symfile_complaints
,
11305 _("debug info gives source %d included "
11306 "from %s at %s line %d"),
11307 file
, at_commandline
? _("command-line") : _("file"),
11308 line
== 0 ? _("zero") : _("non-zero"), line
);
11310 if (at_commandline
)
11312 /* This DW_MACINFO_start_file was executed in the pass one. */
11313 at_commandline
= 0;
11316 current_file
= macro_start_file (file
, line
,
11317 current_file
, comp_dir
,
11322 case DW_MACINFO_end_file
:
11323 if (! current_file
)
11324 complaint (&symfile_complaints
,
11325 _("macro debug info has an unmatched `close_file' directive"));
11328 current_file
= current_file
->included_by
;
11329 if (! current_file
)
11331 enum dwarf_macinfo_record_type next_type
;
11333 /* GCC circa March 2002 doesn't produce the zero
11334 type byte marking the end of the compilation
11335 unit. Complain if it's not there, but exit no
11338 /* Do we at least have room for a macinfo type byte? */
11339 if (mac_ptr
>= mac_end
)
11341 dwarf2_macros_too_long_complaint ();
11345 /* We don't increment mac_ptr here, so this is just
11347 next_type
= read_1_byte (abfd
, mac_ptr
);
11348 if (next_type
!= 0)
11349 complaint (&symfile_complaints
,
11350 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
11357 case DW_MACINFO_vendor_ext
:
11359 unsigned int bytes_read
;
11363 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11364 mac_ptr
+= bytes_read
;
11365 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
11366 mac_ptr
+= bytes_read
;
11368 /* We don't recognize any vendor extensions. */
11372 } while (macinfo_type
!= 0);
11375 /* Check if the attribute's form is a DW_FORM_block*
11376 if so return true else false. */
11378 attr_form_is_block (struct attribute
*attr
)
11380 return (attr
== NULL
? 0 :
11381 attr
->form
== DW_FORM_block1
11382 || attr
->form
== DW_FORM_block2
11383 || attr
->form
== DW_FORM_block4
11384 || attr
->form
== DW_FORM_block
);
11387 /* Return non-zero if ATTR's value is a section offset --- classes
11388 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
11389 You may use DW_UNSND (attr) to retrieve such offsets.
11391 Section 7.5.4, "Attribute Encodings", explains that no attribute
11392 may have a value that belongs to more than one of these classes; it
11393 would be ambiguous if we did, because we use the same forms for all
11396 attr_form_is_section_offset (struct attribute
*attr
)
11398 return (attr
->form
== DW_FORM_data4
11399 || attr
->form
== DW_FORM_data8
);
11403 /* Return non-zero if ATTR's value falls in the 'constant' class, or
11404 zero otherwise. When this function returns true, you can apply
11405 dwarf2_get_attr_constant_value to it.
11407 However, note that for some attributes you must check
11408 attr_form_is_section_offset before using this test. DW_FORM_data4
11409 and DW_FORM_data8 are members of both the constant class, and of
11410 the classes that contain offsets into other debug sections
11411 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
11412 that, if an attribute's can be either a constant or one of the
11413 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
11414 taken as section offsets, not constants. */
11416 attr_form_is_constant (struct attribute
*attr
)
11418 switch (attr
->form
)
11420 case DW_FORM_sdata
:
11421 case DW_FORM_udata
:
11422 case DW_FORM_data1
:
11423 case DW_FORM_data2
:
11424 case DW_FORM_data4
:
11425 case DW_FORM_data8
:
11433 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
11434 struct dwarf2_cu
*cu
)
11436 if (attr_form_is_section_offset (attr
)
11437 /* ".debug_loc" may not exist at all, or the offset may be outside
11438 the section. If so, fall through to the complaint in the
11440 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
11442 struct dwarf2_loclist_baton
*baton
;
11444 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
11445 sizeof (struct dwarf2_loclist_baton
));
11446 baton
->per_cu
= cu
->per_cu
;
11447 gdb_assert (baton
->per_cu
);
11449 /* We don't know how long the location list is, but make sure we
11450 don't run off the edge of the section. */
11451 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
11452 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
11453 baton
->base_address
= cu
->base_address
;
11454 if (cu
->base_known
== 0)
11455 complaint (&symfile_complaints
,
11456 _("Location list used without specifying the CU base address."));
11458 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
11459 SYMBOL_LOCATION_BATON (sym
) = baton
;
11463 struct dwarf2_locexpr_baton
*baton
;
11465 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
11466 sizeof (struct dwarf2_locexpr_baton
));
11467 baton
->per_cu
= cu
->per_cu
;
11468 gdb_assert (baton
->per_cu
);
11470 if (attr_form_is_block (attr
))
11472 /* Note that we're just copying the block's data pointer
11473 here, not the actual data. We're still pointing into the
11474 info_buffer for SYM's objfile; right now we never release
11475 that buffer, but when we do clean up properly this may
11477 baton
->size
= DW_BLOCK (attr
)->size
;
11478 baton
->data
= DW_BLOCK (attr
)->data
;
11482 dwarf2_invalid_attrib_class_complaint ("location description",
11483 SYMBOL_NATURAL_NAME (sym
));
11485 baton
->data
= NULL
;
11488 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11489 SYMBOL_LOCATION_BATON (sym
) = baton
;
11493 /* Return the OBJFILE associated with the compilation unit CU. */
11496 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
11498 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
11500 /* Return the master objfile, so that we can report and look up the
11501 correct file containing this variable. */
11502 if (objfile
->separate_debug_objfile_backlink
)
11503 objfile
= objfile
->separate_debug_objfile_backlink
;
11508 /* Return the address size given in the compilation unit header for CU. */
11511 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
11514 return per_cu
->cu
->header
.addr_size
;
11517 /* If the CU is not currently read in, we re-read its header. */
11518 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
11519 struct dwarf2_per_objfile
*per_objfile
11520 = objfile_data (objfile
, dwarf2_objfile_data_key
);
11521 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
11523 struct comp_unit_head cu_header
;
11524 memset (&cu_header
, 0, sizeof cu_header
);
11525 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
11526 return cu_header
.addr_size
;
11530 /* Locate the .debug_info compilation unit from CU's objfile which contains
11531 the DIE at OFFSET. Raises an error on failure. */
11533 static struct dwarf2_per_cu_data
*
11534 dwarf2_find_containing_comp_unit (unsigned int offset
,
11535 struct objfile
*objfile
)
11537 struct dwarf2_per_cu_data
*this_cu
;
11541 high
= dwarf2_per_objfile
->n_comp_units
- 1;
11544 int mid
= low
+ (high
- low
) / 2;
11545 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
11550 gdb_assert (low
== high
);
11551 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
11554 error (_("Dwarf Error: could not find partial DIE containing "
11555 "offset 0x%lx [in module %s]"),
11556 (long) offset
, bfd_get_filename (objfile
->obfd
));
11558 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
11559 return dwarf2_per_objfile
->all_comp_units
[low
-1];
11563 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
11564 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
11565 && offset
>= this_cu
->offset
+ this_cu
->length
)
11566 error (_("invalid dwarf2 offset %u"), offset
);
11567 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
11572 /* Locate the compilation unit from OBJFILE which is located at exactly
11573 OFFSET. Raises an error on failure. */
11575 static struct dwarf2_per_cu_data
*
11576 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
11578 struct dwarf2_per_cu_data
*this_cu
;
11579 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
11580 if (this_cu
->offset
!= offset
)
11581 error (_("no compilation unit with offset %u."), offset
);
11585 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
11587 static struct dwarf2_cu
*
11588 alloc_one_comp_unit (struct objfile
*objfile
)
11590 struct dwarf2_cu
*cu
= xcalloc (1, sizeof (struct dwarf2_cu
));
11591 cu
->objfile
= objfile
;
11592 obstack_init (&cu
->comp_unit_obstack
);
11596 /* Release one cached compilation unit, CU. We unlink it from the tree
11597 of compilation units, but we don't remove it from the read_in_chain;
11598 the caller is responsible for that.
11599 NOTE: DATA is a void * because this function is also used as a
11600 cleanup routine. */
11603 free_one_comp_unit (void *data
)
11605 struct dwarf2_cu
*cu
= data
;
11607 if (cu
->per_cu
!= NULL
)
11608 cu
->per_cu
->cu
= NULL
;
11611 obstack_free (&cu
->comp_unit_obstack
, NULL
);
11616 /* This cleanup function is passed the address of a dwarf2_cu on the stack
11617 when we're finished with it. We can't free the pointer itself, but be
11618 sure to unlink it from the cache. Also release any associated storage
11619 and perform cache maintenance.
11621 Only used during partial symbol parsing. */
11624 free_stack_comp_unit (void *data
)
11626 struct dwarf2_cu
*cu
= data
;
11628 obstack_free (&cu
->comp_unit_obstack
, NULL
);
11629 cu
->partial_dies
= NULL
;
11631 if (cu
->per_cu
!= NULL
)
11633 /* This compilation unit is on the stack in our caller, so we
11634 should not xfree it. Just unlink it. */
11635 cu
->per_cu
->cu
= NULL
;
11638 /* If we had a per-cu pointer, then we may have other compilation
11639 units loaded, so age them now. */
11640 age_cached_comp_units ();
11644 /* Free all cached compilation units. */
11647 free_cached_comp_units (void *data
)
11649 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11651 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11652 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11653 while (per_cu
!= NULL
)
11655 struct dwarf2_per_cu_data
*next_cu
;
11657 next_cu
= per_cu
->cu
->read_in_chain
;
11659 free_one_comp_unit (per_cu
->cu
);
11660 *last_chain
= next_cu
;
11666 /* Increase the age counter on each cached compilation unit, and free
11667 any that are too old. */
11670 age_cached_comp_units (void)
11672 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11674 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
11675 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11676 while (per_cu
!= NULL
)
11678 per_cu
->cu
->last_used
++;
11679 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
11680 dwarf2_mark (per_cu
->cu
);
11681 per_cu
= per_cu
->cu
->read_in_chain
;
11684 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11685 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11686 while (per_cu
!= NULL
)
11688 struct dwarf2_per_cu_data
*next_cu
;
11690 next_cu
= per_cu
->cu
->read_in_chain
;
11692 if (!per_cu
->cu
->mark
)
11694 free_one_comp_unit (per_cu
->cu
);
11695 *last_chain
= next_cu
;
11698 last_chain
= &per_cu
->cu
->read_in_chain
;
11704 /* Remove a single compilation unit from the cache. */
11707 free_one_cached_comp_unit (void *target_cu
)
11709 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11711 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11712 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11713 while (per_cu
!= NULL
)
11715 struct dwarf2_per_cu_data
*next_cu
;
11717 next_cu
= per_cu
->cu
->read_in_chain
;
11719 if (per_cu
->cu
== target_cu
)
11721 free_one_comp_unit (per_cu
->cu
);
11722 *last_chain
= next_cu
;
11726 last_chain
= &per_cu
->cu
->read_in_chain
;
11732 /* Release all extra memory associated with OBJFILE. */
11735 dwarf2_free_objfile (struct objfile
*objfile
)
11737 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
11739 if (dwarf2_per_objfile
== NULL
)
11742 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
11743 free_cached_comp_units (NULL
);
11745 /* Everything else should be on the objfile obstack. */
11748 /* A pair of DIE offset and GDB type pointer. We store these
11749 in a hash table separate from the DIEs, and preserve them
11750 when the DIEs are flushed out of cache. */
11752 struct dwarf2_offset_and_type
11754 unsigned int offset
;
11758 /* Hash function for a dwarf2_offset_and_type. */
11761 offset_and_type_hash (const void *item
)
11763 const struct dwarf2_offset_and_type
*ofs
= item
;
11764 return ofs
->offset
;
11767 /* Equality function for a dwarf2_offset_and_type. */
11770 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
11772 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
11773 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
11774 return ofs_lhs
->offset
== ofs_rhs
->offset
;
11777 /* Set the type associated with DIE to TYPE. Save it in CU's hash
11778 table if necessary. For convenience, return TYPE. */
11780 static struct type
*
11781 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11783 struct dwarf2_offset_and_type
**slot
, ofs
;
11785 /* For Ada types, make sure that the gnat-specific data is always
11786 initialized (if not already set). There are a few types where
11787 we should not be doing so, because the type-specific area is
11788 already used to hold some other piece of info (eg: TYPE_CODE_FLT
11789 where the type-specific area is used to store the floatformat).
11790 But this is not a problem, because the gnat-specific information
11791 is actually not needed for these types. */
11792 if (need_gnat_info (cu
)
11793 && TYPE_CODE (type
) != TYPE_CODE_FUNC
11794 && TYPE_CODE (type
) != TYPE_CODE_FLT
11795 && !HAVE_GNAT_AUX_INFO (type
))
11796 INIT_GNAT_SPECIFIC (type
);
11798 if (cu
->type_hash
== NULL
)
11800 gdb_assert (cu
->per_cu
!= NULL
);
11801 cu
->per_cu
->type_hash
11802 = htab_create_alloc_ex (cu
->header
.length
/ 24,
11803 offset_and_type_hash
,
11804 offset_and_type_eq
,
11806 &cu
->objfile
->objfile_obstack
,
11807 hashtab_obstack_allocate
,
11808 dummy_obstack_deallocate
);
11809 cu
->type_hash
= cu
->per_cu
->type_hash
;
11812 ofs
.offset
= die
->offset
;
11814 slot
= (struct dwarf2_offset_and_type
**)
11815 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
11816 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
11821 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
11822 not have a saved type. */
11824 static struct type
*
11825 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11827 struct dwarf2_offset_and_type
*slot
, ofs
;
11828 htab_t type_hash
= cu
->type_hash
;
11830 if (type_hash
== NULL
)
11833 ofs
.offset
= die
->offset
;
11834 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
11841 /* Add a dependence relationship from CU to REF_PER_CU. */
11844 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
11845 struct dwarf2_per_cu_data
*ref_per_cu
)
11849 if (cu
->dependencies
== NULL
)
11851 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
11852 NULL
, &cu
->comp_unit_obstack
,
11853 hashtab_obstack_allocate
,
11854 dummy_obstack_deallocate
);
11856 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
11858 *slot
= ref_per_cu
;
11861 /* Subroutine of dwarf2_mark to pass to htab_traverse.
11862 Set the mark field in every compilation unit in the
11863 cache that we must keep because we are keeping CU. */
11866 dwarf2_mark_helper (void **slot
, void *data
)
11868 struct dwarf2_per_cu_data
*per_cu
;
11870 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
11871 if (per_cu
->cu
->mark
)
11873 per_cu
->cu
->mark
= 1;
11875 if (per_cu
->cu
->dependencies
!= NULL
)
11876 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
11881 /* Set the mark field in CU and in every other compilation unit in the
11882 cache that we must keep because we are keeping CU. */
11885 dwarf2_mark (struct dwarf2_cu
*cu
)
11890 if (cu
->dependencies
!= NULL
)
11891 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
11895 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
11899 per_cu
->cu
->mark
= 0;
11900 per_cu
= per_cu
->cu
->read_in_chain
;
11904 /* Trivial hash function for partial_die_info: the hash value of a DIE
11905 is its offset in .debug_info for this objfile. */
11908 partial_die_hash (const void *item
)
11910 const struct partial_die_info
*part_die
= item
;
11911 return part_die
->offset
;
11914 /* Trivial comparison function for partial_die_info structures: two DIEs
11915 are equal if they have the same offset. */
11918 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
11920 const struct partial_die_info
*part_die_lhs
= item_lhs
;
11921 const struct partial_die_info
*part_die_rhs
= item_rhs
;
11922 return part_die_lhs
->offset
== part_die_rhs
->offset
;
11925 static struct cmd_list_element
*set_dwarf2_cmdlist
;
11926 static struct cmd_list_element
*show_dwarf2_cmdlist
;
11929 set_dwarf2_cmd (char *args
, int from_tty
)
11931 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
11935 show_dwarf2_cmd (char *args
, int from_tty
)
11937 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
11940 /* If section described by INFO was mmapped, munmap it now. */
11943 munmap_section_buffer (struct dwarf2_section_info
*info
)
11945 if (info
->was_mmapped
)
11948 intptr_t begin
= (intptr_t) info
->buffer
;
11949 intptr_t map_begin
= begin
& ~(pagesize
- 1);
11950 size_t map_length
= info
->size
+ begin
- map_begin
;
11951 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
11953 /* Without HAVE_MMAP, we should never be here to begin with. */
11959 /* munmap debug sections for OBJFILE, if necessary. */
11962 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
11964 struct dwarf2_per_objfile
*data
= d
;
11965 munmap_section_buffer (&data
->info
);
11966 munmap_section_buffer (&data
->abbrev
);
11967 munmap_section_buffer (&data
->line
);
11968 munmap_section_buffer (&data
->str
);
11969 munmap_section_buffer (&data
->macinfo
);
11970 munmap_section_buffer (&data
->ranges
);
11971 munmap_section_buffer (&data
->loc
);
11972 munmap_section_buffer (&data
->frame
);
11973 munmap_section_buffer (&data
->eh_frame
);
11976 void _initialize_dwarf2_read (void);
11979 _initialize_dwarf2_read (void)
11981 dwarf2_objfile_data_key
11982 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
11984 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
11985 Set DWARF 2 specific variables.\n\
11986 Configure DWARF 2 variables such as the cache size"),
11987 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
11988 0/*allow-unknown*/, &maintenance_set_cmdlist
);
11990 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
11991 Show DWARF 2 specific variables\n\
11992 Show DWARF 2 variables such as the cache size"),
11993 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
11994 0/*allow-unknown*/, &maintenance_show_cmdlist
);
11996 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
11997 &dwarf2_max_cache_age
, _("\
11998 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
11999 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
12000 A higher limit means that cached compilation units will be stored\n\
12001 in memory longer, and more total memory will be used. Zero disables\n\
12002 caching, which can slow down startup."),
12004 show_dwarf2_max_cache_age
,
12005 &set_dwarf2_cmdlist
,
12006 &show_dwarf2_cmdlist
);
12008 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
12009 Set debugging of the dwarf2 DIE reader."), _("\
12010 Show debugging of the dwarf2 DIE reader."), _("\
12011 When enabled (non-zero), DIEs are dumped after they are read in.\n\
12012 The value is the maximum depth to print."),
12015 &setdebuglist
, &showdebuglist
);