1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2017 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
40 #include "gdb-demangle.h"
41 #include "expression.h"
42 #include "filenames.h" /* for DOSish file names */
45 #include "complaints.h"
47 #include "dwarf2expr.h"
48 #include "dwarf2loc.h"
49 #include "cp-support.h"
55 #include "typeprint.h"
58 #include "completer.h"
63 #include "gdbcore.h" /* for gnutarget */
64 #include "gdb/gdb-index.h"
69 #include "filestuff.h"
71 #include "namespace.h"
72 #include "common/gdb_unlinker.h"
73 #include "common/function-view.h"
74 #include "common/gdb_optional.h"
75 #include "common/underlying.h"
76 #include "common/byte-vector.h"
77 #include "common/hash_enum.h"
78 #include "filename-seen-cache.h"
81 #include <sys/types.h>
83 #include <unordered_set>
84 #include <unordered_map>
88 #include <forward_list>
90 typedef struct symbol
*symbolp
;
93 /* When == 1, print basic high level tracing messages.
94 When > 1, be more verbose.
95 This is in contrast to the low level DIE reading of dwarf_die_debug. */
96 static unsigned int dwarf_read_debug
= 0;
98 /* When non-zero, dump DIEs after they are read in. */
99 static unsigned int dwarf_die_debug
= 0;
101 /* When non-zero, dump line number entries as they are read in. */
102 static unsigned int dwarf_line_debug
= 0;
104 /* When non-zero, cross-check physname against demangler. */
105 static int check_physname
= 0;
107 /* When non-zero, do not reject deprecated .gdb_index sections. */
108 static int use_deprecated_index_sections
= 0;
110 static const struct objfile_data
*dwarf2_objfile_data_key
;
112 /* The "aclass" indices for various kinds of computed DWARF symbols. */
114 static int dwarf2_locexpr_index
;
115 static int dwarf2_loclist_index
;
116 static int dwarf2_locexpr_block_index
;
117 static int dwarf2_loclist_block_index
;
119 /* A descriptor for dwarf sections.
121 S.ASECTION, SIZE are typically initialized when the objfile is first
122 scanned. BUFFER, READIN are filled in later when the section is read.
123 If the section contained compressed data then SIZE is updated to record
124 the uncompressed size of the section.
126 DWP file format V2 introduces a wrinkle that is easiest to handle by
127 creating the concept of virtual sections contained within a real section.
128 In DWP V2 the sections of the input DWO files are concatenated together
129 into one section, but section offsets are kept relative to the original
131 If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to
132 the real section this "virtual" section is contained in, and BUFFER,SIZE
133 describe the virtual section. */
135 struct dwarf2_section_info
139 /* If this is a real section, the bfd section. */
141 /* If this is a virtual section, pointer to the containing ("real")
143 struct dwarf2_section_info
*containing_section
;
145 /* Pointer to section data, only valid if readin. */
146 const gdb_byte
*buffer
;
147 /* The size of the section, real or virtual. */
149 /* If this is a virtual section, the offset in the real section.
150 Only valid if is_virtual. */
151 bfd_size_type virtual_offset
;
152 /* True if we have tried to read this section. */
154 /* True if this is a virtual section, False otherwise.
155 This specifies which of s.section and s.containing_section to use. */
159 typedef struct dwarf2_section_info dwarf2_section_info_def
;
160 DEF_VEC_O (dwarf2_section_info_def
);
162 /* All offsets in the index are of this type. It must be
163 architecture-independent. */
164 typedef uint32_t offset_type
;
166 DEF_VEC_I (offset_type
);
168 /* Ensure only legit values are used. */
169 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
171 gdb_assert ((unsigned int) (value) <= 1); \
172 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
175 /* Ensure only legit values are used. */
176 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
178 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
179 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
180 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
183 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
184 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
186 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
187 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
192 /* Convert VALUE between big- and little-endian. */
195 byte_swap (offset_type value
)
199 result
= (value
& 0xff) << 24;
200 result
|= (value
& 0xff00) << 8;
201 result
|= (value
& 0xff0000) >> 8;
202 result
|= (value
& 0xff000000) >> 24;
206 #define MAYBE_SWAP(V) byte_swap (V)
209 #define MAYBE_SWAP(V) static_cast<offset_type> (V)
210 #endif /* WORDS_BIGENDIAN */
212 /* An index into a (C++) symbol name component in a symbol name as
213 recorded in the mapped_index's symbol table. For each C++ symbol
214 in the symbol table, we record one entry for the start of each
215 component in the symbol in a table of name components, and then
216 sort the table, in order to be able to binary search symbol names,
217 ignoring leading namespaces, both completion and regular look up.
218 For example, for symbol "A::B::C", we'll have an entry that points
219 to "A::B::C", another that points to "B::C", and another for "C".
220 Note that function symbols in GDB index have no parameter
221 information, just the function/method names. You can convert a
222 name_component to a "const char *" using the
223 'mapped_index::symbol_name_at(offset_type)' method. */
225 struct name_component
227 /* Offset in the symbol name where the component starts. Stored as
228 a (32-bit) offset instead of a pointer to save memory and improve
229 locality on 64-bit architectures. */
230 offset_type name_offset
;
232 /* The symbol's index in the symbol and constant pool tables of a
237 /* Base class containing bits shared by both .gdb_index and
238 .debug_name indexes. */
240 struct mapped_index_base
242 /* The name_component table (a sorted vector). See name_component's
243 description above. */
244 std::vector
<name_component
> name_components
;
246 /* How NAME_COMPONENTS is sorted. */
247 enum case_sensitivity name_components_casing
;
249 /* Return the number of names in the symbol table. */
250 virtual size_t symbol_name_count () const = 0;
252 /* Get the name of the symbol at IDX in the symbol table. */
253 virtual const char *symbol_name_at (offset_type idx
) const = 0;
255 /* Return whether the name at IDX in the symbol table should be
257 virtual bool symbol_name_slot_invalid (offset_type idx
) const
262 /* Build the symbol name component sorted vector, if we haven't
264 void build_name_components ();
266 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
267 possible matches for LN_NO_PARAMS in the name component
269 std::pair
<std::vector
<name_component
>::const_iterator
,
270 std::vector
<name_component
>::const_iterator
>
271 find_name_components_bounds (const lookup_name_info
&ln_no_params
) const;
273 /* Prevent deleting/destroying via a base class pointer. */
275 ~mapped_index_base() = default;
278 /* A description of the mapped index. The file format is described in
279 a comment by the code that writes the index. */
280 struct mapped_index
: public mapped_index_base
282 /* A slot/bucket in the symbol table hash. */
283 struct symbol_table_slot
285 const offset_type name
;
286 const offset_type vec
;
289 /* Index data format version. */
292 /* The total length of the buffer. */
295 /* The address table data. */
296 gdb::array_view
<const gdb_byte
> address_table
;
298 /* The symbol table, implemented as a hash table. */
299 gdb::array_view
<symbol_table_slot
> symbol_table
;
301 /* A pointer to the constant pool. */
302 const char *constant_pool
;
304 bool symbol_name_slot_invalid (offset_type idx
) const override
306 const auto &bucket
= this->symbol_table
[idx
];
307 return bucket
.name
== 0 && bucket
.vec
;
310 /* Convenience method to get at the name of the symbol at IDX in the
312 const char *symbol_name_at (offset_type idx
) const override
313 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
315 size_t symbol_name_count () const override
316 { return this->symbol_table
.size (); }
319 /* A description of the mapped .debug_names.
320 Uninitialized map has CU_COUNT 0. */
321 struct mapped_debug_names
: public mapped_index_base
323 bfd_endian dwarf5_byte_order
;
324 bool dwarf5_is_dwarf64
;
325 bool augmentation_is_gdb
;
327 uint32_t cu_count
= 0;
328 uint32_t tu_count
, bucket_count
, name_count
;
329 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
330 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
331 const gdb_byte
*name_table_string_offs_reordered
;
332 const gdb_byte
*name_table_entry_offs_reordered
;
333 const gdb_byte
*entry_pool
;
340 /* Attribute name DW_IDX_*. */
343 /* Attribute form DW_FORM_*. */
346 /* Value if FORM is DW_FORM_implicit_const. */
347 LONGEST implicit_const
;
349 std::vector
<attr
> attr_vec
;
352 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
354 const char *namei_to_name (uint32_t namei
) const;
356 /* Implementation of the mapped_index_base virtual interface, for
357 the name_components cache. */
359 const char *symbol_name_at (offset_type idx
) const override
360 { return namei_to_name (idx
); }
362 size_t symbol_name_count () const override
363 { return this->name_count
; }
366 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
367 DEF_VEC_P (dwarf2_per_cu_ptr
);
371 int nr_uniq_abbrev_tables
;
373 int nr_symtab_sharers
;
374 int nr_stmt_less_type_units
;
375 int nr_all_type_units_reallocs
;
378 /* Collection of data recorded per objfile.
379 This hangs off of dwarf2_objfile_data_key. */
381 struct dwarf2_per_objfile
383 /* Construct a dwarf2_per_objfile for OBJFILE. NAMES points to the
384 dwarf2 section names, or is NULL if the standard ELF names are
386 dwarf2_per_objfile (struct objfile
*objfile
,
387 const dwarf2_debug_sections
*names
);
389 ~dwarf2_per_objfile ();
391 DISABLE_COPY_AND_ASSIGN (dwarf2_per_objfile
);
393 /* Free all cached compilation units. */
394 void free_cached_comp_units ();
396 /* This function is mapped across the sections and remembers the
397 offset and size of each of the debugging sections we are
399 void locate_sections (bfd
*abfd
, asection
*sectp
,
400 const dwarf2_debug_sections
&names
);
403 dwarf2_section_info info
{};
404 dwarf2_section_info abbrev
{};
405 dwarf2_section_info line
{};
406 dwarf2_section_info loc
{};
407 dwarf2_section_info loclists
{};
408 dwarf2_section_info macinfo
{};
409 dwarf2_section_info macro
{};
410 dwarf2_section_info str
{};
411 dwarf2_section_info line_str
{};
412 dwarf2_section_info ranges
{};
413 dwarf2_section_info rnglists
{};
414 dwarf2_section_info addr
{};
415 dwarf2_section_info frame
{};
416 dwarf2_section_info eh_frame
{};
417 dwarf2_section_info gdb_index
{};
418 dwarf2_section_info debug_names
{};
419 dwarf2_section_info debug_aranges
{};
421 VEC (dwarf2_section_info_def
) *types
= NULL
;
424 struct objfile
*objfile
= NULL
;
426 /* Table of all the compilation units. This is used to locate
427 the target compilation unit of a particular reference. */
428 struct dwarf2_per_cu_data
**all_comp_units
= NULL
;
430 /* The number of compilation units in ALL_COMP_UNITS. */
431 int n_comp_units
= 0;
433 /* The number of .debug_types-related CUs. */
434 int n_type_units
= 0;
436 /* The number of elements allocated in all_type_units.
437 If there are skeleton-less TUs, we add them to all_type_units lazily. */
438 int n_allocated_type_units
= 0;
440 /* The .debug_types-related CUs (TUs).
441 This is stored in malloc space because we may realloc it. */
442 struct signatured_type
**all_type_units
= NULL
;
444 /* Table of struct type_unit_group objects.
445 The hash key is the DW_AT_stmt_list value. */
446 htab_t type_unit_groups
{};
448 /* A table mapping .debug_types signatures to its signatured_type entry.
449 This is NULL if the .debug_types section hasn't been read in yet. */
450 htab_t signatured_types
{};
452 /* Type unit statistics, to see how well the scaling improvements
454 struct tu_stats tu_stats
{};
456 /* A chain of compilation units that are currently read in, so that
457 they can be freed later. */
458 dwarf2_per_cu_data
*read_in_chain
= NULL
;
460 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
461 This is NULL if the table hasn't been allocated yet. */
464 /* True if we've checked for whether there is a DWP file. */
465 bool dwp_checked
= false;
467 /* The DWP file if there is one, or NULL. */
468 struct dwp_file
*dwp_file
= NULL
;
470 /* The shared '.dwz' file, if one exists. This is used when the
471 original data was compressed using 'dwz -m'. */
472 struct dwz_file
*dwz_file
= NULL
;
474 /* A flag indicating whether this objfile has a section loaded at a
476 bool has_section_at_zero
= false;
478 /* True if we are using the mapped index,
479 or we are faking it for OBJF_READNOW's sake. */
480 bool using_index
= false;
482 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
483 mapped_index
*index_table
= NULL
;
485 /* The mapped index, or NULL if .debug_names is missing or not being used. */
486 std::unique_ptr
<mapped_debug_names
> debug_names_table
;
488 /* When using index_table, this keeps track of all quick_file_names entries.
489 TUs typically share line table entries with a CU, so we maintain a
490 separate table of all line table entries to support the sharing.
491 Note that while there can be way more TUs than CUs, we've already
492 sorted all the TUs into "type unit groups", grouped by their
493 DW_AT_stmt_list value. Therefore the only sharing done here is with a
494 CU and its associated TU group if there is one. */
495 htab_t quick_file_names_table
{};
497 /* Set during partial symbol reading, to prevent queueing of full
499 bool reading_partial_symbols
= false;
501 /* Table mapping type DIEs to their struct type *.
502 This is NULL if not allocated yet.
503 The mapping is done via (CU/TU + DIE offset) -> type. */
504 htab_t die_type_hash
{};
506 /* The CUs we recently read. */
507 VEC (dwarf2_per_cu_ptr
) *just_read_cus
= NULL
;
509 /* Table containing line_header indexed by offset and offset_in_dwz. */
510 htab_t line_header_hash
{};
512 /* Table containing all filenames. This is an optional because the
513 table is lazily constructed on first access. */
514 gdb::optional
<filename_seen_cache
> filenames_cache
;
517 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
519 /* Default names of the debugging sections. */
521 /* Note that if the debugging section has been compressed, it might
522 have a name like .zdebug_info. */
524 static const struct dwarf2_debug_sections dwarf2_elf_names
=
526 { ".debug_info", ".zdebug_info" },
527 { ".debug_abbrev", ".zdebug_abbrev" },
528 { ".debug_line", ".zdebug_line" },
529 { ".debug_loc", ".zdebug_loc" },
530 { ".debug_loclists", ".zdebug_loclists" },
531 { ".debug_macinfo", ".zdebug_macinfo" },
532 { ".debug_macro", ".zdebug_macro" },
533 { ".debug_str", ".zdebug_str" },
534 { ".debug_line_str", ".zdebug_line_str" },
535 { ".debug_ranges", ".zdebug_ranges" },
536 { ".debug_rnglists", ".zdebug_rnglists" },
537 { ".debug_types", ".zdebug_types" },
538 { ".debug_addr", ".zdebug_addr" },
539 { ".debug_frame", ".zdebug_frame" },
540 { ".eh_frame", NULL
},
541 { ".gdb_index", ".zgdb_index" },
542 { ".debug_names", ".zdebug_names" },
543 { ".debug_aranges", ".zdebug_aranges" },
547 /* List of DWO/DWP sections. */
549 static const struct dwop_section_names
551 struct dwarf2_section_names abbrev_dwo
;
552 struct dwarf2_section_names info_dwo
;
553 struct dwarf2_section_names line_dwo
;
554 struct dwarf2_section_names loc_dwo
;
555 struct dwarf2_section_names loclists_dwo
;
556 struct dwarf2_section_names macinfo_dwo
;
557 struct dwarf2_section_names macro_dwo
;
558 struct dwarf2_section_names str_dwo
;
559 struct dwarf2_section_names str_offsets_dwo
;
560 struct dwarf2_section_names types_dwo
;
561 struct dwarf2_section_names cu_index
;
562 struct dwarf2_section_names tu_index
;
566 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
567 { ".debug_info.dwo", ".zdebug_info.dwo" },
568 { ".debug_line.dwo", ".zdebug_line.dwo" },
569 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
570 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
571 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
572 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
573 { ".debug_str.dwo", ".zdebug_str.dwo" },
574 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
575 { ".debug_types.dwo", ".zdebug_types.dwo" },
576 { ".debug_cu_index", ".zdebug_cu_index" },
577 { ".debug_tu_index", ".zdebug_tu_index" },
580 /* local data types */
582 /* The data in a compilation unit header, after target2host
583 translation, looks like this. */
584 struct comp_unit_head
588 unsigned char addr_size
;
589 unsigned char signed_addr_p
;
590 sect_offset abbrev_sect_off
;
592 /* Size of file offsets; either 4 or 8. */
593 unsigned int offset_size
;
595 /* Size of the length field; either 4 or 12. */
596 unsigned int initial_length_size
;
598 enum dwarf_unit_type unit_type
;
600 /* Offset to the first byte of this compilation unit header in the
601 .debug_info section, for resolving relative reference dies. */
602 sect_offset sect_off
;
604 /* Offset to first die in this cu from the start of the cu.
605 This will be the first byte following the compilation unit header. */
606 cu_offset first_die_cu_offset
;
608 /* 64-bit signature of this type unit - it is valid only for
609 UNIT_TYPE DW_UT_type. */
612 /* For types, offset in the type's DIE of the type defined by this TU. */
613 cu_offset type_cu_offset_in_tu
;
616 /* Type used for delaying computation of method physnames.
617 See comments for compute_delayed_physnames. */
618 struct delayed_method_info
620 /* The type to which the method is attached, i.e., its parent class. */
623 /* The index of the method in the type's function fieldlists. */
626 /* The index of the method in the fieldlist. */
629 /* The name of the DIE. */
632 /* The DIE associated with this method. */
633 struct die_info
*die
;
636 typedef struct delayed_method_info delayed_method_info
;
637 DEF_VEC_O (delayed_method_info
);
639 /* Internal state when decoding a particular compilation unit. */
642 /* The objfile containing this compilation unit. */
643 struct objfile
*objfile
;
645 /* The header of the compilation unit. */
646 struct comp_unit_head header
;
648 /* Base address of this compilation unit. */
649 CORE_ADDR base_address
;
651 /* Non-zero if base_address has been set. */
654 /* The language we are debugging. */
655 enum language language
;
656 const struct language_defn
*language_defn
;
658 const char *producer
;
660 /* The generic symbol table building routines have separate lists for
661 file scope symbols and all all other scopes (local scopes). So
662 we need to select the right one to pass to add_symbol_to_list().
663 We do it by keeping a pointer to the correct list in list_in_scope.
665 FIXME: The original dwarf code just treated the file scope as the
666 first local scope, and all other local scopes as nested local
667 scopes, and worked fine. Check to see if we really need to
668 distinguish these in buildsym.c. */
669 struct pending
**list_in_scope
;
671 /* The abbrev table for this CU.
672 Normally this points to the abbrev table in the objfile.
673 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
674 struct abbrev_table
*abbrev_table
;
676 /* Hash table holding all the loaded partial DIEs
677 with partial_die->offset.SECT_OFF as hash. */
680 /* Storage for things with the same lifetime as this read-in compilation
681 unit, including partial DIEs. */
682 struct obstack comp_unit_obstack
;
684 /* When multiple dwarf2_cu structures are living in memory, this field
685 chains them all together, so that they can be released efficiently.
686 We will probably also want a generation counter so that most-recently-used
687 compilation units are cached... */
688 struct dwarf2_per_cu_data
*read_in_chain
;
690 /* Backlink to our per_cu entry. */
691 struct dwarf2_per_cu_data
*per_cu
;
693 /* How many compilation units ago was this CU last referenced? */
696 /* A hash table of DIE cu_offset for following references with
697 die_info->offset.sect_off as hash. */
700 /* Full DIEs if read in. */
701 struct die_info
*dies
;
703 /* A set of pointers to dwarf2_per_cu_data objects for compilation
704 units referenced by this one. Only set during full symbol processing;
705 partial symbol tables do not have dependencies. */
708 /* Header data from the line table, during full symbol processing. */
709 struct line_header
*line_header
;
710 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
711 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
712 this is the DW_TAG_compile_unit die for this CU. We'll hold on
713 to the line header as long as this DIE is being processed. See
714 process_die_scope. */
715 die_info
*line_header_die_owner
;
717 /* A list of methods which need to have physnames computed
718 after all type information has been read. */
719 VEC (delayed_method_info
) *method_list
;
721 /* To be copied to symtab->call_site_htab. */
722 htab_t call_site_htab
;
724 /* Non-NULL if this CU came from a DWO file.
725 There is an invariant here that is important to remember:
726 Except for attributes copied from the top level DIE in the "main"
727 (or "stub") file in preparation for reading the DWO file
728 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
729 Either there isn't a DWO file (in which case this is NULL and the point
730 is moot), or there is and either we're not going to read it (in which
731 case this is NULL) or there is and we are reading it (in which case this
733 struct dwo_unit
*dwo_unit
;
735 /* The DW_AT_addr_base attribute if present, zero otherwise
736 (zero is a valid value though).
737 Note this value comes from the Fission stub CU/TU's DIE. */
740 /* The DW_AT_ranges_base attribute if present, zero otherwise
741 (zero is a valid value though).
742 Note this value comes from the Fission stub CU/TU's DIE.
743 Also note that the value is zero in the non-DWO case so this value can
744 be used without needing to know whether DWO files are in use or not.
745 N.B. This does not apply to DW_AT_ranges appearing in
746 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
747 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
748 DW_AT_ranges_base *would* have to be applied, and we'd have to care
749 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
750 ULONGEST ranges_base
;
752 /* Mark used when releasing cached dies. */
753 unsigned int mark
: 1;
755 /* This CU references .debug_loc. See the symtab->locations_valid field.
756 This test is imperfect as there may exist optimized debug code not using
757 any location list and still facing inlining issues if handled as
758 unoptimized code. For a future better test see GCC PR other/32998. */
759 unsigned int has_loclist
: 1;
761 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
762 if all the producer_is_* fields are valid. This information is cached
763 because profiling CU expansion showed excessive time spent in
764 producer_is_gxx_lt_4_6. */
765 unsigned int checked_producer
: 1;
766 unsigned int producer_is_gxx_lt_4_6
: 1;
767 unsigned int producer_is_gcc_lt_4_3
: 1;
768 unsigned int producer_is_icc_lt_14
: 1;
770 /* When set, the file that we're processing is known to have
771 debugging info for C++ namespaces. GCC 3.3.x did not produce
772 this information, but later versions do. */
774 unsigned int processing_has_namespace_info
: 1;
777 /* Persistent data held for a compilation unit, even when not
778 processing it. We put a pointer to this structure in the
779 read_symtab_private field of the psymtab. */
781 struct dwarf2_per_cu_data
783 /* The start offset and length of this compilation unit.
784 NOTE: Unlike comp_unit_head.length, this length includes
786 If the DIE refers to a DWO file, this is always of the original die,
788 sect_offset sect_off
;
791 /* DWARF standard version this data has been read from (such as 4 or 5). */
794 /* Flag indicating this compilation unit will be read in before
795 any of the current compilation units are processed. */
796 unsigned int queued
: 1;
798 /* This flag will be set when reading partial DIEs if we need to load
799 absolutely all DIEs for this compilation unit, instead of just the ones
800 we think are interesting. It gets set if we look for a DIE in the
801 hash table and don't find it. */
802 unsigned int load_all_dies
: 1;
804 /* Non-zero if this CU is from .debug_types.
805 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
807 unsigned int is_debug_types
: 1;
809 /* Non-zero if this CU is from the .dwz file. */
810 unsigned int is_dwz
: 1;
812 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
813 This flag is only valid if is_debug_types is true.
814 We can't read a CU directly from a DWO file: There are required
815 attributes in the stub. */
816 unsigned int reading_dwo_directly
: 1;
818 /* Non-zero if the TU has been read.
819 This is used to assist the "Stay in DWO Optimization" for Fission:
820 When reading a DWO, it's faster to read TUs from the DWO instead of
821 fetching them from random other DWOs (due to comdat folding).
822 If the TU has already been read, the optimization is unnecessary
823 (and unwise - we don't want to change where gdb thinks the TU lives
825 This flag is only valid if is_debug_types is true. */
826 unsigned int tu_read
: 1;
828 /* The section this CU/TU lives in.
829 If the DIE refers to a DWO file, this is always the original die,
831 struct dwarf2_section_info
*section
;
833 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
834 of the CU cache it gets reset to NULL again. This is left as NULL for
835 dummy CUs (a CU header, but nothing else). */
836 struct dwarf2_cu
*cu
;
838 /* The corresponding objfile.
839 Normally we can get the objfile from dwarf2_per_objfile.
840 However we can enter this file with just a "per_cu" handle. */
841 struct objfile
*objfile
;
843 /* When dwarf2_per_objfile->using_index is true, the 'quick' field
844 is active. Otherwise, the 'psymtab' field is active. */
847 /* The partial symbol table associated with this compilation unit,
848 or NULL for unread partial units. */
849 struct partial_symtab
*psymtab
;
851 /* Data needed by the "quick" functions. */
852 struct dwarf2_per_cu_quick_data
*quick
;
855 /* The CUs we import using DW_TAG_imported_unit. This is filled in
856 while reading psymtabs, used to compute the psymtab dependencies,
857 and then cleared. Then it is filled in again while reading full
858 symbols, and only deleted when the objfile is destroyed.
860 This is also used to work around a difference between the way gold
861 generates .gdb_index version <=7 and the way gdb does. Arguably this
862 is a gold bug. For symbols coming from TUs, gold records in the index
863 the CU that includes the TU instead of the TU itself. This breaks
864 dw2_lookup_symbol: It assumes that if the index says symbol X lives
865 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
866 will find X. Alas TUs live in their own symtab, so after expanding CU Y
867 we need to look in TU Z to find X. Fortunately, this is akin to
868 DW_TAG_imported_unit, so we just use the same mechanism: For
869 .gdb_index version <=7 this also records the TUs that the CU referred
870 to. Concurrently with this change gdb was modified to emit version 8
871 indices so we only pay a price for gold generated indices.
872 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
873 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
876 /* Entry in the signatured_types hash table. */
878 struct signatured_type
880 /* The "per_cu" object of this type.
881 This struct is used iff per_cu.is_debug_types.
882 N.B.: This is the first member so that it's easy to convert pointers
884 struct dwarf2_per_cu_data per_cu
;
886 /* The type's signature. */
889 /* Offset in the TU of the type's DIE, as read from the TU header.
890 If this TU is a DWO stub and the definition lives in a DWO file
891 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
892 cu_offset type_offset_in_tu
;
894 /* Offset in the section of the type's DIE.
895 If the definition lives in a DWO file, this is the offset in the
896 .debug_types.dwo section.
897 The value is zero until the actual value is known.
898 Zero is otherwise not a valid section offset. */
899 sect_offset type_offset_in_section
;
901 /* Type units are grouped by their DW_AT_stmt_list entry so that they
902 can share them. This points to the containing symtab. */
903 struct type_unit_group
*type_unit_group
;
906 The first time we encounter this type we fully read it in and install it
907 in the symbol tables. Subsequent times we only need the type. */
910 /* Containing DWO unit.
911 This field is valid iff per_cu.reading_dwo_directly. */
912 struct dwo_unit
*dwo_unit
;
915 typedef struct signatured_type
*sig_type_ptr
;
916 DEF_VEC_P (sig_type_ptr
);
918 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
919 This includes type_unit_group and quick_file_names. */
921 struct stmt_list_hash
923 /* The DWO unit this table is from or NULL if there is none. */
924 struct dwo_unit
*dwo_unit
;
926 /* Offset in .debug_line or .debug_line.dwo. */
927 sect_offset line_sect_off
;
930 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
931 an object of this type. */
933 struct type_unit_group
935 /* dwarf2read.c's main "handle" on a TU symtab.
936 To simplify things we create an artificial CU that "includes" all the
937 type units using this stmt_list so that the rest of the code still has
938 a "per_cu" handle on the symtab.
939 This PER_CU is recognized by having no section. */
940 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
941 struct dwarf2_per_cu_data per_cu
;
943 /* The TUs that share this DW_AT_stmt_list entry.
944 This is added to while parsing type units to build partial symtabs,
945 and is deleted afterwards and not used again. */
946 VEC (sig_type_ptr
) *tus
;
948 /* The compunit symtab.
949 Type units in a group needn't all be defined in the same source file,
950 so we create an essentially anonymous symtab as the compunit symtab. */
951 struct compunit_symtab
*compunit_symtab
;
953 /* The data used to construct the hash key. */
954 struct stmt_list_hash hash
;
956 /* The number of symtabs from the line header.
957 The value here must match line_header.num_file_names. */
958 unsigned int num_symtabs
;
960 /* The symbol tables for this TU (obtained from the files listed in
962 WARNING: The order of entries here must match the order of entries
963 in the line header. After the first TU using this type_unit_group, the
964 line header for the subsequent TUs is recreated from this. This is done
965 because we need to use the same symtabs for each TU using the same
966 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
967 there's no guarantee the line header doesn't have duplicate entries. */
968 struct symtab
**symtabs
;
971 /* These sections are what may appear in a (real or virtual) DWO file. */
975 struct dwarf2_section_info abbrev
;
976 struct dwarf2_section_info line
;
977 struct dwarf2_section_info loc
;
978 struct dwarf2_section_info loclists
;
979 struct dwarf2_section_info macinfo
;
980 struct dwarf2_section_info macro
;
981 struct dwarf2_section_info str
;
982 struct dwarf2_section_info str_offsets
;
983 /* In the case of a virtual DWO file, these two are unused. */
984 struct dwarf2_section_info info
;
985 VEC (dwarf2_section_info_def
) *types
;
988 /* CUs/TUs in DWP/DWO files. */
992 /* Backlink to the containing struct dwo_file. */
993 struct dwo_file
*dwo_file
;
995 /* The "id" that distinguishes this CU/TU.
996 .debug_info calls this "dwo_id", .debug_types calls this "signature".
997 Since signatures came first, we stick with it for consistency. */
1000 /* The section this CU/TU lives in, in the DWO file. */
1001 struct dwarf2_section_info
*section
;
1003 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
1004 sect_offset sect_off
;
1005 unsigned int length
;
1007 /* For types, offset in the type's DIE of the type defined by this TU. */
1008 cu_offset type_offset_in_tu
;
1011 /* include/dwarf2.h defines the DWP section codes.
1012 It defines a max value but it doesn't define a min value, which we
1013 use for error checking, so provide one. */
1015 enum dwp_v2_section_ids
1020 /* Data for one DWO file.
1022 This includes virtual DWO files (a virtual DWO file is a DWO file as it
1023 appears in a DWP file). DWP files don't really have DWO files per se -
1024 comdat folding of types "loses" the DWO file they came from, and from
1025 a high level view DWP files appear to contain a mass of random types.
1026 However, to maintain consistency with the non-DWP case we pretend DWP
1027 files contain virtual DWO files, and we assign each TU with one virtual
1028 DWO file (generally based on the line and abbrev section offsets -
1029 a heuristic that seems to work in practice). */
1033 /* The DW_AT_GNU_dwo_name attribute.
1034 For virtual DWO files the name is constructed from the section offsets
1035 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
1036 from related CU+TUs. */
1037 const char *dwo_name
;
1039 /* The DW_AT_comp_dir attribute. */
1040 const char *comp_dir
;
1042 /* The bfd, when the file is open. Otherwise this is NULL.
1043 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
1046 /* The sections that make up this DWO file.
1047 Remember that for virtual DWO files in DWP V2, these are virtual
1048 sections (for lack of a better name). */
1049 struct dwo_sections sections
;
1051 /* The CUs in the file.
1052 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
1053 an extension to handle LLVM's Link Time Optimization output (where
1054 multiple source files may be compiled into a single object/dwo pair). */
1057 /* Table of TUs in the file.
1058 Each element is a struct dwo_unit. */
1062 /* These sections are what may appear in a DWP file. */
1066 /* These are used by both DWP version 1 and 2. */
1067 struct dwarf2_section_info str
;
1068 struct dwarf2_section_info cu_index
;
1069 struct dwarf2_section_info tu_index
;
1071 /* These are only used by DWP version 2 files.
1072 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
1073 sections are referenced by section number, and are not recorded here.
1074 In DWP version 2 there is at most one copy of all these sections, each
1075 section being (effectively) comprised of the concatenation of all of the
1076 individual sections that exist in the version 1 format.
1077 To keep the code simple we treat each of these concatenated pieces as a
1078 section itself (a virtual section?). */
1079 struct dwarf2_section_info abbrev
;
1080 struct dwarf2_section_info info
;
1081 struct dwarf2_section_info line
;
1082 struct dwarf2_section_info loc
;
1083 struct dwarf2_section_info macinfo
;
1084 struct dwarf2_section_info macro
;
1085 struct dwarf2_section_info str_offsets
;
1086 struct dwarf2_section_info types
;
1089 /* These sections are what may appear in a virtual DWO file in DWP version 1.
1090 A virtual DWO file is a DWO file as it appears in a DWP file. */
1092 struct virtual_v1_dwo_sections
1094 struct dwarf2_section_info abbrev
;
1095 struct dwarf2_section_info line
;
1096 struct dwarf2_section_info loc
;
1097 struct dwarf2_section_info macinfo
;
1098 struct dwarf2_section_info macro
;
1099 struct dwarf2_section_info str_offsets
;
1100 /* Each DWP hash table entry records one CU or one TU.
1101 That is recorded here, and copied to dwo_unit.section. */
1102 struct dwarf2_section_info info_or_types
;
1105 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
1106 In version 2, the sections of the DWO files are concatenated together
1107 and stored in one section of that name. Thus each ELF section contains
1108 several "virtual" sections. */
1110 struct virtual_v2_dwo_sections
1112 bfd_size_type abbrev_offset
;
1113 bfd_size_type abbrev_size
;
1115 bfd_size_type line_offset
;
1116 bfd_size_type line_size
;
1118 bfd_size_type loc_offset
;
1119 bfd_size_type loc_size
;
1121 bfd_size_type macinfo_offset
;
1122 bfd_size_type macinfo_size
;
1124 bfd_size_type macro_offset
;
1125 bfd_size_type macro_size
;
1127 bfd_size_type str_offsets_offset
;
1128 bfd_size_type str_offsets_size
;
1130 /* Each DWP hash table entry records one CU or one TU.
1131 That is recorded here, and copied to dwo_unit.section. */
1132 bfd_size_type info_or_types_offset
;
1133 bfd_size_type info_or_types_size
;
1136 /* Contents of DWP hash tables. */
1138 struct dwp_hash_table
1140 uint32_t version
, nr_columns
;
1141 uint32_t nr_units
, nr_slots
;
1142 const gdb_byte
*hash_table
, *unit_table
;
1147 const gdb_byte
*indices
;
1151 /* This is indexed by column number and gives the id of the section
1153 #define MAX_NR_V2_DWO_SECTIONS \
1154 (1 /* .debug_info or .debug_types */ \
1155 + 1 /* .debug_abbrev */ \
1156 + 1 /* .debug_line */ \
1157 + 1 /* .debug_loc */ \
1158 + 1 /* .debug_str_offsets */ \
1159 + 1 /* .debug_macro or .debug_macinfo */)
1160 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
1161 const gdb_byte
*offsets
;
1162 const gdb_byte
*sizes
;
1167 /* Data for one DWP file. */
1171 /* Name of the file. */
1174 /* File format version. */
1180 /* Section info for this file. */
1181 struct dwp_sections sections
;
1183 /* Table of CUs in the file. */
1184 const struct dwp_hash_table
*cus
;
1186 /* Table of TUs in the file. */
1187 const struct dwp_hash_table
*tus
;
1189 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
1193 /* Table to map ELF section numbers to their sections.
1194 This is only needed for the DWP V1 file format. */
1195 unsigned int num_sections
;
1196 asection
**elf_sections
;
1199 /* This represents a '.dwz' file. */
1203 /* A dwz file can only contain a few sections. */
1204 struct dwarf2_section_info abbrev
;
1205 struct dwarf2_section_info info
;
1206 struct dwarf2_section_info str
;
1207 struct dwarf2_section_info line
;
1208 struct dwarf2_section_info macro
;
1209 struct dwarf2_section_info gdb_index
;
1210 struct dwarf2_section_info debug_names
;
1212 /* The dwz's BFD. */
1216 /* Struct used to pass misc. parameters to read_die_and_children, et
1217 al. which are used for both .debug_info and .debug_types dies.
1218 All parameters here are unchanging for the life of the call. This
1219 struct exists to abstract away the constant parameters of die reading. */
1221 struct die_reader_specs
1223 /* The bfd of die_section. */
1226 /* The CU of the DIE we are parsing. */
1227 struct dwarf2_cu
*cu
;
1229 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
1230 struct dwo_file
*dwo_file
;
1232 /* The section the die comes from.
1233 This is either .debug_info or .debug_types, or the .dwo variants. */
1234 struct dwarf2_section_info
*die_section
;
1236 /* die_section->buffer. */
1237 const gdb_byte
*buffer
;
1239 /* The end of the buffer. */
1240 const gdb_byte
*buffer_end
;
1242 /* The value of the DW_AT_comp_dir attribute. */
1243 const char *comp_dir
;
1246 /* Type of function passed to init_cutu_and_read_dies, et.al. */
1247 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
1248 const gdb_byte
*info_ptr
,
1249 struct die_info
*comp_unit_die
,
1253 /* A 1-based directory index. This is a strong typedef to prevent
1254 accidentally using a directory index as a 0-based index into an
1256 enum class dir_index
: unsigned int {};
1258 /* Likewise, a 1-based file name index. */
1259 enum class file_name_index
: unsigned int {};
1263 file_entry () = default;
1265 file_entry (const char *name_
, dir_index d_index_
,
1266 unsigned int mod_time_
, unsigned int length_
)
1269 mod_time (mod_time_
),
1273 /* Return the include directory at D_INDEX stored in LH. Returns
1274 NULL if D_INDEX is out of bounds. */
1275 const char *include_dir (const line_header
*lh
) const;
1277 /* The file name. Note this is an observing pointer. The memory is
1278 owned by debug_line_buffer. */
1279 const char *name
{};
1281 /* The directory index (1-based). */
1282 dir_index d_index
{};
1284 unsigned int mod_time
{};
1286 unsigned int length
{};
1288 /* True if referenced by the Line Number Program. */
1291 /* The associated symbol table, if any. */
1292 struct symtab
*symtab
{};
1295 /* The line number information for a compilation unit (found in the
1296 .debug_line section) begins with a "statement program header",
1297 which contains the following information. */
1304 /* Add an entry to the include directory table. */
1305 void add_include_dir (const char *include_dir
);
1307 /* Add an entry to the file name table. */
1308 void add_file_name (const char *name
, dir_index d_index
,
1309 unsigned int mod_time
, unsigned int length
);
1311 /* Return the include dir at INDEX (1-based). Returns NULL if INDEX
1312 is out of bounds. */
1313 const char *include_dir_at (dir_index index
) const
1315 /* Convert directory index number (1-based) to vector index
1317 size_t vec_index
= to_underlying (index
) - 1;
1319 if (vec_index
>= include_dirs
.size ())
1321 return include_dirs
[vec_index
];
1324 /* Return the file name at INDEX (1-based). Returns NULL if INDEX
1325 is out of bounds. */
1326 file_entry
*file_name_at (file_name_index index
)
1328 /* Convert file name index number (1-based) to vector index
1330 size_t vec_index
= to_underlying (index
) - 1;
1332 if (vec_index
>= file_names
.size ())
1334 return &file_names
[vec_index
];
1337 /* Const version of the above. */
1338 const file_entry
*file_name_at (unsigned int index
) const
1340 if (index
>= file_names
.size ())
1342 return &file_names
[index
];
1345 /* Offset of line number information in .debug_line section. */
1346 sect_offset sect_off
{};
1348 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1349 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1351 unsigned int total_length
{};
1352 unsigned short version
{};
1353 unsigned int header_length
{};
1354 unsigned char minimum_instruction_length
{};
1355 unsigned char maximum_ops_per_instruction
{};
1356 unsigned char default_is_stmt
{};
1358 unsigned char line_range
{};
1359 unsigned char opcode_base
{};
1361 /* standard_opcode_lengths[i] is the number of operands for the
1362 standard opcode whose value is i. This means that
1363 standard_opcode_lengths[0] is unused, and the last meaningful
1364 element is standard_opcode_lengths[opcode_base - 1]. */
1365 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1367 /* The include_directories table. Note these are observing
1368 pointers. The memory is owned by debug_line_buffer. */
1369 std::vector
<const char *> include_dirs
;
1371 /* The file_names table. */
1372 std::vector
<file_entry
> file_names
;
1374 /* The start and end of the statement program following this
1375 header. These point into dwarf2_per_objfile->line_buffer. */
1376 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1379 typedef std::unique_ptr
<line_header
> line_header_up
;
1382 file_entry::include_dir (const line_header
*lh
) const
1384 return lh
->include_dir_at (d_index
);
1387 /* When we construct a partial symbol table entry we only
1388 need this much information. */
1389 struct partial_die_info
1391 /* Offset of this DIE. */
1392 sect_offset sect_off
;
1394 /* DWARF-2 tag for this DIE. */
1395 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1397 /* Assorted flags describing the data found in this DIE. */
1398 unsigned int has_children
: 1;
1399 unsigned int is_external
: 1;
1400 unsigned int is_declaration
: 1;
1401 unsigned int has_type
: 1;
1402 unsigned int has_specification
: 1;
1403 unsigned int has_pc_info
: 1;
1404 unsigned int may_be_inlined
: 1;
1406 /* This DIE has been marked DW_AT_main_subprogram. */
1407 unsigned int main_subprogram
: 1;
1409 /* Flag set if the SCOPE field of this structure has been
1411 unsigned int scope_set
: 1;
1413 /* Flag set if the DIE has a byte_size attribute. */
1414 unsigned int has_byte_size
: 1;
1416 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1417 unsigned int has_const_value
: 1;
1419 /* Flag set if any of the DIE's children are template arguments. */
1420 unsigned int has_template_arguments
: 1;
1422 /* Flag set if fixup_partial_die has been called on this die. */
1423 unsigned int fixup_called
: 1;
1425 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1426 unsigned int is_dwz
: 1;
1428 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1429 unsigned int spec_is_dwz
: 1;
1431 /* The name of this DIE. Normally the value of DW_AT_name, but
1432 sometimes a default name for unnamed DIEs. */
1435 /* The linkage name, if present. */
1436 const char *linkage_name
;
1438 /* The scope to prepend to our children. This is generally
1439 allocated on the comp_unit_obstack, so will disappear
1440 when this compilation unit leaves the cache. */
1443 /* Some data associated with the partial DIE. The tag determines
1444 which field is live. */
1447 /* The location description associated with this DIE, if any. */
1448 struct dwarf_block
*locdesc
;
1449 /* The offset of an import, for DW_TAG_imported_unit. */
1450 sect_offset sect_off
;
1453 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1457 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1458 DW_AT_sibling, if any. */
1459 /* NOTE: This member isn't strictly necessary, read_partial_die could
1460 return DW_AT_sibling values to its caller load_partial_dies. */
1461 const gdb_byte
*sibling
;
1463 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1464 DW_AT_specification (or DW_AT_abstract_origin or
1465 DW_AT_extension). */
1466 sect_offset spec_offset
;
1468 /* Pointers to this DIE's parent, first child, and next sibling,
1470 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
1473 /* This data structure holds the information of an abbrev. */
1476 unsigned int number
; /* number identifying abbrev */
1477 enum dwarf_tag tag
; /* dwarf tag */
1478 unsigned short has_children
; /* boolean */
1479 unsigned short num_attrs
; /* number of attributes */
1480 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1481 struct abbrev_info
*next
; /* next in chain */
1486 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1487 ENUM_BITFIELD(dwarf_form
) form
: 16;
1489 /* It is valid only if FORM is DW_FORM_implicit_const. */
1490 LONGEST implicit_const
;
1493 /* Size of abbrev_table.abbrev_hash_table. */
1494 #define ABBREV_HASH_SIZE 121
1496 /* Top level data structure to contain an abbreviation table. */
1500 /* Where the abbrev table came from.
1501 This is used as a sanity check when the table is used. */
1502 sect_offset sect_off
;
1504 /* Storage for the abbrev table. */
1505 struct obstack abbrev_obstack
;
1507 /* Hash table of abbrevs.
1508 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1509 It could be statically allocated, but the previous code didn't so we
1511 struct abbrev_info
**abbrevs
;
1514 /* Attributes have a name and a value. */
1517 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1518 ENUM_BITFIELD(dwarf_form
) form
: 15;
1520 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1521 field should be in u.str (existing only for DW_STRING) but it is kept
1522 here for better struct attribute alignment. */
1523 unsigned int string_is_canonical
: 1;
1528 struct dwarf_block
*blk
;
1537 /* This data structure holds a complete die structure. */
1540 /* DWARF-2 tag for this DIE. */
1541 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1543 /* Number of attributes */
1544 unsigned char num_attrs
;
1546 /* True if we're presently building the full type name for the
1547 type derived from this DIE. */
1548 unsigned char building_fullname
: 1;
1550 /* True if this die is in process. PR 16581. */
1551 unsigned char in_process
: 1;
1554 unsigned int abbrev
;
1556 /* Offset in .debug_info or .debug_types section. */
1557 sect_offset sect_off
;
1559 /* The dies in a compilation unit form an n-ary tree. PARENT
1560 points to this die's parent; CHILD points to the first child of
1561 this node; and all the children of a given node are chained
1562 together via their SIBLING fields. */
1563 struct die_info
*child
; /* Its first child, if any. */
1564 struct die_info
*sibling
; /* Its next sibling, if any. */
1565 struct die_info
*parent
; /* Its parent, if any. */
1567 /* An array of attributes, with NUM_ATTRS elements. There may be
1568 zero, but it's not common and zero-sized arrays are not
1569 sufficiently portable C. */
1570 struct attribute attrs
[1];
1573 /* Get at parts of an attribute structure. */
1575 #define DW_STRING(attr) ((attr)->u.str)
1576 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1577 #define DW_UNSND(attr) ((attr)->u.unsnd)
1578 #define DW_BLOCK(attr) ((attr)->u.blk)
1579 #define DW_SND(attr) ((attr)->u.snd)
1580 #define DW_ADDR(attr) ((attr)->u.addr)
1581 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1583 /* Blocks are a bunch of untyped bytes. */
1588 /* Valid only if SIZE is not zero. */
1589 const gdb_byte
*data
;
1592 #ifndef ATTR_ALLOC_CHUNK
1593 #define ATTR_ALLOC_CHUNK 4
1596 /* Allocate fields for structs, unions and enums in this size. */
1597 #ifndef DW_FIELD_ALLOC_CHUNK
1598 #define DW_FIELD_ALLOC_CHUNK 4
1601 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1602 but this would require a corresponding change in unpack_field_as_long
1604 static int bits_per_byte
= 8;
1608 struct nextfield
*next
;
1616 struct nextfnfield
*next
;
1617 struct fn_field fnfield
;
1624 struct nextfnfield
*head
;
1627 struct decl_field_list
1629 struct decl_field field
;
1630 struct decl_field_list
*next
;
1633 /* The routines that read and process dies for a C struct or C++ class
1634 pass lists of data member fields and lists of member function fields
1635 in an instance of a field_info structure, as defined below. */
1638 /* List of data member and baseclasses fields. */
1639 struct nextfield
*fields
, *baseclasses
;
1641 /* Number of fields (including baseclasses). */
1644 /* Number of baseclasses. */
1647 /* Set if the accesibility of one of the fields is not public. */
1648 int non_public_fields
;
1650 /* Member function fieldlist array, contains name of possibly overloaded
1651 member function, number of overloaded member functions and a pointer
1652 to the head of the member function field chain. */
1653 struct fnfieldlist
*fnfieldlists
;
1655 /* Number of entries in the fnfieldlists array. */
1658 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1659 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1660 struct decl_field_list
*typedef_field_list
;
1661 unsigned typedef_field_list_count
;
1663 /* Nested types defined by this class and the number of elements in this
1665 struct decl_field_list
*nested_types_list
;
1666 unsigned nested_types_list_count
;
1669 /* One item on the queue of compilation units to read in full symbols
1671 struct dwarf2_queue_item
1673 struct dwarf2_per_cu_data
*per_cu
;
1674 enum language pretend_language
;
1675 struct dwarf2_queue_item
*next
;
1678 /* The current queue. */
1679 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1681 /* Loaded secondary compilation units are kept in memory until they
1682 have not been referenced for the processing of this many
1683 compilation units. Set this to zero to disable caching. Cache
1684 sizes of up to at least twenty will improve startup time for
1685 typical inter-CU-reference binaries, at an obvious memory cost. */
1686 static int dwarf_max_cache_age
= 5;
1688 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1689 struct cmd_list_element
*c
, const char *value
)
1691 fprintf_filtered (file
, _("The upper bound on the age of cached "
1692 "DWARF compilation units is %s.\n"),
1696 /* local function prototypes */
1698 static const char *get_section_name (const struct dwarf2_section_info
*);
1700 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1702 static void dwarf2_find_base_address (struct die_info
*die
,
1703 struct dwarf2_cu
*cu
);
1705 static struct partial_symtab
*create_partial_symtab
1706 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1708 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1709 const gdb_byte
*info_ptr
,
1710 struct die_info
*type_unit_die
,
1711 int has_children
, void *data
);
1713 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1715 static void scan_partial_symbols (struct partial_die_info
*,
1716 CORE_ADDR
*, CORE_ADDR
*,
1717 int, struct dwarf2_cu
*);
1719 static void add_partial_symbol (struct partial_die_info
*,
1720 struct dwarf2_cu
*);
1722 static void add_partial_namespace (struct partial_die_info
*pdi
,
1723 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1724 int set_addrmap
, struct dwarf2_cu
*cu
);
1726 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1727 CORE_ADDR
*highpc
, int set_addrmap
,
1728 struct dwarf2_cu
*cu
);
1730 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1731 struct dwarf2_cu
*cu
);
1733 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1734 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1735 int need_pc
, struct dwarf2_cu
*cu
);
1737 static void dwarf2_read_symtab (struct partial_symtab
*,
1740 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1742 static struct abbrev_info
*abbrev_table_lookup_abbrev
1743 (const struct abbrev_table
*, unsigned int);
1745 static struct abbrev_table
*abbrev_table_read_table
1746 (struct dwarf2_section_info
*, sect_offset
);
1748 static void abbrev_table_free (struct abbrev_table
*);
1750 static void abbrev_table_free_cleanup (void *);
1752 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1753 struct dwarf2_section_info
*);
1755 static void dwarf2_free_abbrev_table (void *);
1757 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1759 static struct partial_die_info
*load_partial_dies
1760 (const struct die_reader_specs
*, const gdb_byte
*, int);
1762 static const gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1763 struct partial_die_info
*,
1764 struct abbrev_info
*,
1768 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1769 struct dwarf2_cu
*);
1771 static void fixup_partial_die (struct partial_die_info
*,
1772 struct dwarf2_cu
*);
1774 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1775 struct attribute
*, struct attr_abbrev
*,
1778 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1780 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1782 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1784 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1786 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1788 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1791 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1793 static LONGEST read_checked_initial_length_and_offset
1794 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1795 unsigned int *, unsigned int *);
1797 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1798 const struct comp_unit_head
*,
1801 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1803 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1806 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1808 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1810 static const char *read_indirect_string (bfd
*, const gdb_byte
*,
1811 const struct comp_unit_head
*,
1814 static const char *read_indirect_line_string (bfd
*, const gdb_byte
*,
1815 const struct comp_unit_head
*,
1818 static const char *read_indirect_string_at_offset (bfd
*abfd
,
1819 LONGEST str_offset
);
1821 static const char *read_indirect_string_from_dwz (struct dwz_file
*, LONGEST
);
1823 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1825 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1829 static const char *read_str_index (const struct die_reader_specs
*reader
,
1830 ULONGEST str_index
);
1832 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1834 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1835 struct dwarf2_cu
*);
1837 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1840 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1841 struct dwarf2_cu
*cu
);
1843 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1844 struct dwarf2_cu
*cu
);
1846 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1848 static struct die_info
*die_specification (struct die_info
*die
,
1849 struct dwarf2_cu
**);
1851 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1852 struct dwarf2_cu
*cu
);
1854 static void dwarf_decode_lines (struct line_header
*, const char *,
1855 struct dwarf2_cu
*, struct partial_symtab
*,
1856 CORE_ADDR
, int decode_mapping
);
1858 static void dwarf2_start_subfile (const char *, const char *);
1860 static struct compunit_symtab
*dwarf2_start_symtab (struct dwarf2_cu
*,
1861 const char *, const char *,
1864 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1865 struct dwarf2_cu
*);
1867 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1868 struct dwarf2_cu
*, struct symbol
*);
1870 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1871 struct dwarf2_cu
*);
1873 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1876 struct obstack
*obstack
,
1877 struct dwarf2_cu
*cu
, LONGEST
*value
,
1878 const gdb_byte
**bytes
,
1879 struct dwarf2_locexpr_baton
**baton
);
1881 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1883 static int need_gnat_info (struct dwarf2_cu
*);
1885 static struct type
*die_descriptive_type (struct die_info
*,
1886 struct dwarf2_cu
*);
1888 static void set_descriptive_type (struct type
*, struct die_info
*,
1889 struct dwarf2_cu
*);
1891 static struct type
*die_containing_type (struct die_info
*,
1892 struct dwarf2_cu
*);
1894 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1895 struct dwarf2_cu
*);
1897 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1899 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1901 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1903 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1904 const char *suffix
, int physname
,
1905 struct dwarf2_cu
*cu
);
1907 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1909 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1911 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1913 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1915 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1917 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1919 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1920 struct dwarf2_cu
*, struct partial_symtab
*);
1922 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1923 values. Keep the items ordered with increasing constraints compliance. */
1926 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1927 PC_BOUNDS_NOT_PRESENT
,
1929 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1930 were present but they do not form a valid range of PC addresses. */
1933 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1936 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1940 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1941 CORE_ADDR
*, CORE_ADDR
*,
1943 struct partial_symtab
*);
1945 static void get_scope_pc_bounds (struct die_info
*,
1946 CORE_ADDR
*, CORE_ADDR
*,
1947 struct dwarf2_cu
*);
1949 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1950 CORE_ADDR
, struct dwarf2_cu
*);
1952 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1953 struct dwarf2_cu
*);
1955 static void dwarf2_attach_fields_to_type (struct field_info
*,
1956 struct type
*, struct dwarf2_cu
*);
1958 static void dwarf2_add_member_fn (struct field_info
*,
1959 struct die_info
*, struct type
*,
1960 struct dwarf2_cu
*);
1962 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1964 struct dwarf2_cu
*);
1966 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1968 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1970 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1972 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1974 static struct using_direct
**using_directives (enum language
);
1976 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1978 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1980 static struct type
*read_module_type (struct die_info
*die
,
1981 struct dwarf2_cu
*cu
);
1983 static const char *namespace_name (struct die_info
*die
,
1984 int *is_anonymous
, struct dwarf2_cu
*);
1986 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1988 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1990 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1991 struct dwarf2_cu
*);
1993 static struct die_info
*read_die_and_siblings_1
1994 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1997 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1998 const gdb_byte
*info_ptr
,
1999 const gdb_byte
**new_info_ptr
,
2000 struct die_info
*parent
);
2002 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
2003 struct die_info
**, const gdb_byte
*,
2006 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
2007 struct die_info
**, const gdb_byte
*,
2010 static void process_die (struct die_info
*, struct dwarf2_cu
*);
2012 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
2015 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
2017 static const char *dwarf2_full_name (const char *name
,
2018 struct die_info
*die
,
2019 struct dwarf2_cu
*cu
);
2021 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
2022 struct dwarf2_cu
*cu
);
2024 static struct die_info
*dwarf2_extension (struct die_info
*die
,
2025 struct dwarf2_cu
**);
2027 static const char *dwarf_tag_name (unsigned int);
2029 static const char *dwarf_attr_name (unsigned int);
2031 static const char *dwarf_form_name (unsigned int);
2033 static const char *dwarf_bool_name (unsigned int);
2035 static const char *dwarf_type_encoding_name (unsigned int);
2037 static struct die_info
*sibling_die (struct die_info
*);
2039 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
2041 static void dump_die_for_error (struct die_info
*);
2043 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
2046 /*static*/ void dump_die (struct die_info
*, int max_level
);
2048 static void store_in_ref_table (struct die_info
*,
2049 struct dwarf2_cu
*);
2051 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
2053 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
2055 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
2056 const struct attribute
*,
2057 struct dwarf2_cu
**);
2059 static struct die_info
*follow_die_ref (struct die_info
*,
2060 const struct attribute
*,
2061 struct dwarf2_cu
**);
2063 static struct die_info
*follow_die_sig (struct die_info
*,
2064 const struct attribute
*,
2065 struct dwarf2_cu
**);
2067 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
2068 struct dwarf2_cu
*);
2070 static struct type
*get_DW_AT_signature_type (struct die_info
*,
2071 const struct attribute
*,
2072 struct dwarf2_cu
*);
2074 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
2076 static void read_signatured_type (struct signatured_type
*);
2078 static int attr_to_dynamic_prop (const struct attribute
*attr
,
2079 struct die_info
*die
, struct dwarf2_cu
*cu
,
2080 struct dynamic_prop
*prop
);
2082 /* memory allocation interface */
2084 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
2086 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
2088 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
2090 static int attr_form_is_block (const struct attribute
*);
2092 static int attr_form_is_section_offset (const struct attribute
*);
2094 static int attr_form_is_constant (const struct attribute
*);
2096 static int attr_form_is_ref (const struct attribute
*);
2098 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
2099 struct dwarf2_loclist_baton
*baton
,
2100 const struct attribute
*attr
);
2102 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
2104 struct dwarf2_cu
*cu
,
2107 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
2108 const gdb_byte
*info_ptr
,
2109 struct abbrev_info
*abbrev
);
2111 static void free_stack_comp_unit (void *);
2113 static hashval_t
partial_die_hash (const void *item
);
2115 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
2117 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
2118 (sect_offset sect_off
, unsigned int offset_in_dwz
, struct objfile
*objfile
);
2120 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
2121 struct dwarf2_per_cu_data
*per_cu
);
2123 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
2124 struct die_info
*comp_unit_die
,
2125 enum language pretend_language
);
2127 static void free_heap_comp_unit (void *);
2129 static void free_cached_comp_units (void *);
2131 static void age_cached_comp_units (void);
2133 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
2135 static struct type
*set_die_type (struct die_info
*, struct type
*,
2136 struct dwarf2_cu
*);
2138 static void create_all_comp_units (struct objfile
*);
2140 static int create_all_type_units (struct objfile
*);
2142 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
2145 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
2148 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
2151 static void dwarf2_add_dependence (struct dwarf2_cu
*,
2152 struct dwarf2_per_cu_data
*);
2154 static void dwarf2_mark (struct dwarf2_cu
*);
2156 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
2158 static struct type
*get_die_type_at_offset (sect_offset
,
2159 struct dwarf2_per_cu_data
*);
2161 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
2163 static void dwarf2_release_queue (void *dummy
);
2165 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
2166 enum language pretend_language
);
2168 static void process_queue (void);
2170 /* The return type of find_file_and_directory. Note, the enclosed
2171 string pointers are only valid while this object is valid. */
2173 struct file_and_directory
2175 /* The filename. This is never NULL. */
2178 /* The compilation directory. NULL if not known. If we needed to
2179 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
2180 points directly to the DW_AT_comp_dir string attribute owned by
2181 the obstack that owns the DIE. */
2182 const char *comp_dir
;
2184 /* If we needed to build a new string for comp_dir, this is what
2185 owns the storage. */
2186 std::string comp_dir_storage
;
2189 static file_and_directory
find_file_and_directory (struct die_info
*die
,
2190 struct dwarf2_cu
*cu
);
2192 static char *file_full_name (int file
, struct line_header
*lh
,
2193 const char *comp_dir
);
2195 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
2196 enum class rcuh_kind
{ COMPILE
, TYPE
};
2198 static const gdb_byte
*read_and_check_comp_unit_head
2199 (struct comp_unit_head
*header
,
2200 struct dwarf2_section_info
*section
,
2201 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
2202 rcuh_kind section_kind
);
2204 static void init_cutu_and_read_dies
2205 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
2206 int use_existing_cu
, int keep
,
2207 die_reader_func_ftype
*die_reader_func
, void *data
);
2209 static void init_cutu_and_read_dies_simple
2210 (struct dwarf2_per_cu_data
*this_cu
,
2211 die_reader_func_ftype
*die_reader_func
, void *data
);
2213 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
2215 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
2217 static struct dwo_unit
*lookup_dwo_unit_in_dwp
2218 (struct dwp_file
*dwp_file
, const char *comp_dir
,
2219 ULONGEST signature
, int is_debug_types
);
2221 static struct dwp_file
*get_dwp_file (void);
2223 static struct dwo_unit
*lookup_dwo_comp_unit
2224 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2226 static struct dwo_unit
*lookup_dwo_type_unit
2227 (struct signatured_type
*, const char *, const char *);
2229 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2231 static void free_dwo_file_cleanup (void *);
2233 static void process_cu_includes (void);
2235 static void check_producer (struct dwarf2_cu
*cu
);
2237 static void free_line_header_voidp (void *arg
);
2239 /* Various complaints about symbol reading that don't abort the process. */
2242 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2244 complaint (&symfile_complaints
,
2245 _("statement list doesn't fit in .debug_line section"));
2249 dwarf2_debug_line_missing_file_complaint (void)
2251 complaint (&symfile_complaints
,
2252 _(".debug_line section has line data without a file"));
2256 dwarf2_debug_line_missing_end_sequence_complaint (void)
2258 complaint (&symfile_complaints
,
2259 _(".debug_line section has line "
2260 "program sequence without an end"));
2264 dwarf2_complex_location_expr_complaint (void)
2266 complaint (&symfile_complaints
, _("location expression too complex"));
2270 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2273 complaint (&symfile_complaints
,
2274 _("const value length mismatch for '%s', got %d, expected %d"),
2279 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2281 complaint (&symfile_complaints
,
2282 _("debug info runs off end of %s section"
2284 get_section_name (section
),
2285 get_section_file_name (section
));
2289 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2291 complaint (&symfile_complaints
,
2292 _("macro debug info contains a "
2293 "malformed macro definition:\n`%s'"),
2298 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2300 complaint (&symfile_complaints
,
2301 _("invalid attribute class or form for '%s' in '%s'"),
2305 /* Hash function for line_header_hash. */
2308 line_header_hash (const struct line_header
*ofs
)
2310 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2313 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2316 line_header_hash_voidp (const void *item
)
2318 const struct line_header
*ofs
= (const struct line_header
*) item
;
2320 return line_header_hash (ofs
);
2323 /* Equality function for line_header_hash. */
2326 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2328 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2329 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2331 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2332 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2337 /* Read the given attribute value as an address, taking the attribute's
2338 form into account. */
2341 attr_value_as_address (struct attribute
*attr
)
2345 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_GNU_addr_index
)
2347 /* Aside from a few clearly defined exceptions, attributes that
2348 contain an address must always be in DW_FORM_addr form.
2349 Unfortunately, some compilers happen to be violating this
2350 requirement by encoding addresses using other forms, such
2351 as DW_FORM_data4 for example. For those broken compilers,
2352 we try to do our best, without any guarantee of success,
2353 to interpret the address correctly. It would also be nice
2354 to generate a complaint, but that would require us to maintain
2355 a list of legitimate cases where a non-address form is allowed,
2356 as well as update callers to pass in at least the CU's DWARF
2357 version. This is more overhead than what we're willing to
2358 expand for a pretty rare case. */
2359 addr
= DW_UNSND (attr
);
2362 addr
= DW_ADDR (attr
);
2367 /* The suffix for an index file. */
2368 #define INDEX4_SUFFIX ".gdb-index"
2369 #define INDEX5_SUFFIX ".debug_names"
2370 #define DEBUG_STR_SUFFIX ".debug_str"
2372 /* See declaration. */
2374 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2375 const dwarf2_debug_sections
*names
)
2376 : objfile (objfile_
)
2379 names
= &dwarf2_elf_names
;
2381 bfd
*obfd
= objfile
->obfd
;
2383 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2384 locate_sections (obfd
, sec
, *names
);
2387 dwarf2_per_objfile::~dwarf2_per_objfile ()
2389 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2390 free_cached_comp_units ();
2392 if (quick_file_names_table
)
2393 htab_delete (quick_file_names_table
);
2395 if (line_header_hash
)
2396 htab_delete (line_header_hash
);
2398 /* Everything else should be on the objfile obstack. */
2401 /* See declaration. */
2404 dwarf2_per_objfile::free_cached_comp_units ()
2406 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2407 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2408 while (per_cu
!= NULL
)
2410 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2412 free_heap_comp_unit (per_cu
->cu
);
2413 *last_chain
= next_cu
;
2418 /* Try to locate the sections we need for DWARF 2 debugging
2419 information and return true if we have enough to do something.
2420 NAMES points to the dwarf2 section names, or is NULL if the standard
2421 ELF names are used. */
2424 dwarf2_has_info (struct objfile
*objfile
,
2425 const struct dwarf2_debug_sections
*names
)
2427 if (objfile
->flags
& OBJF_READNEVER
)
2430 dwarf2_per_objfile
= ((struct dwarf2_per_objfile
*)
2431 objfile_data (objfile
, dwarf2_objfile_data_key
));
2432 if (!dwarf2_per_objfile
)
2434 /* Initialize per-objfile state. */
2435 struct dwarf2_per_objfile
*data
2436 = XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_per_objfile
);
2438 dwarf2_per_objfile
= new (data
) struct dwarf2_per_objfile (objfile
, names
);
2439 set_objfile_data (objfile
, dwarf2_objfile_data_key
, dwarf2_per_objfile
);
2441 return (!dwarf2_per_objfile
->info
.is_virtual
2442 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2443 && !dwarf2_per_objfile
->abbrev
.is_virtual
2444 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2447 /* Return the containing section of virtual section SECTION. */
2449 static struct dwarf2_section_info
*
2450 get_containing_section (const struct dwarf2_section_info
*section
)
2452 gdb_assert (section
->is_virtual
);
2453 return section
->s
.containing_section
;
2456 /* Return the bfd owner of SECTION. */
2459 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2461 if (section
->is_virtual
)
2463 section
= get_containing_section (section
);
2464 gdb_assert (!section
->is_virtual
);
2466 return section
->s
.section
->owner
;
2469 /* Return the bfd section of SECTION.
2470 Returns NULL if the section is not present. */
2473 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2475 if (section
->is_virtual
)
2477 section
= get_containing_section (section
);
2478 gdb_assert (!section
->is_virtual
);
2480 return section
->s
.section
;
2483 /* Return the name of SECTION. */
2486 get_section_name (const struct dwarf2_section_info
*section
)
2488 asection
*sectp
= get_section_bfd_section (section
);
2490 gdb_assert (sectp
!= NULL
);
2491 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2494 /* Return the name of the file SECTION is in. */
2497 get_section_file_name (const struct dwarf2_section_info
*section
)
2499 bfd
*abfd
= get_section_bfd_owner (section
);
2501 return bfd_get_filename (abfd
);
2504 /* Return the id of SECTION.
2505 Returns 0 if SECTION doesn't exist. */
2508 get_section_id (const struct dwarf2_section_info
*section
)
2510 asection
*sectp
= get_section_bfd_section (section
);
2517 /* Return the flags of SECTION.
2518 SECTION (or containing section if this is a virtual section) must exist. */
2521 get_section_flags (const struct dwarf2_section_info
*section
)
2523 asection
*sectp
= get_section_bfd_section (section
);
2525 gdb_assert (sectp
!= NULL
);
2526 return bfd_get_section_flags (sectp
->owner
, sectp
);
2529 /* When loading sections, we look either for uncompressed section or for
2530 compressed section names. */
2533 section_is_p (const char *section_name
,
2534 const struct dwarf2_section_names
*names
)
2536 if (names
->normal
!= NULL
2537 && strcmp (section_name
, names
->normal
) == 0)
2539 if (names
->compressed
!= NULL
2540 && strcmp (section_name
, names
->compressed
) == 0)
2545 /* See declaration. */
2548 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2549 const dwarf2_debug_sections
&names
)
2551 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2553 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2556 else if (section_is_p (sectp
->name
, &names
.info
))
2558 this->info
.s
.section
= sectp
;
2559 this->info
.size
= bfd_get_section_size (sectp
);
2561 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2563 this->abbrev
.s
.section
= sectp
;
2564 this->abbrev
.size
= bfd_get_section_size (sectp
);
2566 else if (section_is_p (sectp
->name
, &names
.line
))
2568 this->line
.s
.section
= sectp
;
2569 this->line
.size
= bfd_get_section_size (sectp
);
2571 else if (section_is_p (sectp
->name
, &names
.loc
))
2573 this->loc
.s
.section
= sectp
;
2574 this->loc
.size
= bfd_get_section_size (sectp
);
2576 else if (section_is_p (sectp
->name
, &names
.loclists
))
2578 this->loclists
.s
.section
= sectp
;
2579 this->loclists
.size
= bfd_get_section_size (sectp
);
2581 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2583 this->macinfo
.s
.section
= sectp
;
2584 this->macinfo
.size
= bfd_get_section_size (sectp
);
2586 else if (section_is_p (sectp
->name
, &names
.macro
))
2588 this->macro
.s
.section
= sectp
;
2589 this->macro
.size
= bfd_get_section_size (sectp
);
2591 else if (section_is_p (sectp
->name
, &names
.str
))
2593 this->str
.s
.section
= sectp
;
2594 this->str
.size
= bfd_get_section_size (sectp
);
2596 else if (section_is_p (sectp
->name
, &names
.line_str
))
2598 this->line_str
.s
.section
= sectp
;
2599 this->line_str
.size
= bfd_get_section_size (sectp
);
2601 else if (section_is_p (sectp
->name
, &names
.addr
))
2603 this->addr
.s
.section
= sectp
;
2604 this->addr
.size
= bfd_get_section_size (sectp
);
2606 else if (section_is_p (sectp
->name
, &names
.frame
))
2608 this->frame
.s
.section
= sectp
;
2609 this->frame
.size
= bfd_get_section_size (sectp
);
2611 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2613 this->eh_frame
.s
.section
= sectp
;
2614 this->eh_frame
.size
= bfd_get_section_size (sectp
);
2616 else if (section_is_p (sectp
->name
, &names
.ranges
))
2618 this->ranges
.s
.section
= sectp
;
2619 this->ranges
.size
= bfd_get_section_size (sectp
);
2621 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2623 this->rnglists
.s
.section
= sectp
;
2624 this->rnglists
.size
= bfd_get_section_size (sectp
);
2626 else if (section_is_p (sectp
->name
, &names
.types
))
2628 struct dwarf2_section_info type_section
;
2630 memset (&type_section
, 0, sizeof (type_section
));
2631 type_section
.s
.section
= sectp
;
2632 type_section
.size
= bfd_get_section_size (sectp
);
2634 VEC_safe_push (dwarf2_section_info_def
, this->types
,
2637 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2639 this->gdb_index
.s
.section
= sectp
;
2640 this->gdb_index
.size
= bfd_get_section_size (sectp
);
2642 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2644 this->debug_names
.s
.section
= sectp
;
2645 this->debug_names
.size
= bfd_get_section_size (sectp
);
2647 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2649 this->debug_aranges
.s
.section
= sectp
;
2650 this->debug_aranges
.size
= bfd_get_section_size (sectp
);
2653 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2654 && bfd_section_vma (abfd
, sectp
) == 0)
2655 this->has_section_at_zero
= true;
2658 /* A helper function that decides whether a section is empty,
2662 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2664 if (section
->is_virtual
)
2665 return section
->size
== 0;
2666 return section
->s
.section
== NULL
|| section
->size
== 0;
2669 /* Read the contents of the section INFO.
2670 OBJFILE is the main object file, but not necessarily the file where
2671 the section comes from. E.g., for DWO files the bfd of INFO is the bfd
2673 If the section is compressed, uncompress it before returning. */
2676 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
2680 gdb_byte
*buf
, *retbuf
;
2684 info
->buffer
= NULL
;
2687 if (dwarf2_section_empty_p (info
))
2690 sectp
= get_section_bfd_section (info
);
2692 /* If this is a virtual section we need to read in the real one first. */
2693 if (info
->is_virtual
)
2695 struct dwarf2_section_info
*containing_section
=
2696 get_containing_section (info
);
2698 gdb_assert (sectp
!= NULL
);
2699 if ((sectp
->flags
& SEC_RELOC
) != 0)
2701 error (_("Dwarf Error: DWP format V2 with relocations is not"
2702 " supported in section %s [in module %s]"),
2703 get_section_name (info
), get_section_file_name (info
));
2705 dwarf2_read_section (objfile
, containing_section
);
2706 /* Other code should have already caught virtual sections that don't
2708 gdb_assert (info
->virtual_offset
+ info
->size
2709 <= containing_section
->size
);
2710 /* If the real section is empty or there was a problem reading the
2711 section we shouldn't get here. */
2712 gdb_assert (containing_section
->buffer
!= NULL
);
2713 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2717 /* If the section has relocations, we must read it ourselves.
2718 Otherwise we attach it to the BFD. */
2719 if ((sectp
->flags
& SEC_RELOC
) == 0)
2721 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2725 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2728 /* When debugging .o files, we may need to apply relocations; see
2729 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2730 We never compress sections in .o files, so we only need to
2731 try this when the section is not compressed. */
2732 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2735 info
->buffer
= retbuf
;
2739 abfd
= get_section_bfd_owner (info
);
2740 gdb_assert (abfd
!= NULL
);
2742 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2743 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2745 error (_("Dwarf Error: Can't read DWARF data"
2746 " in section %s [in module %s]"),
2747 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2751 /* A helper function that returns the size of a section in a safe way.
2752 If you are positive that the section has been read before using the
2753 size, then it is safe to refer to the dwarf2_section_info object's
2754 "size" field directly. In other cases, you must call this
2755 function, because for compressed sections the size field is not set
2756 correctly until the section has been read. */
2758 static bfd_size_type
2759 dwarf2_section_size (struct objfile
*objfile
,
2760 struct dwarf2_section_info
*info
)
2763 dwarf2_read_section (objfile
, info
);
2767 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2771 dwarf2_get_section_info (struct objfile
*objfile
,
2772 enum dwarf2_section_enum sect
,
2773 asection
**sectp
, const gdb_byte
**bufp
,
2774 bfd_size_type
*sizep
)
2776 struct dwarf2_per_objfile
*data
2777 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
2778 dwarf2_objfile_data_key
);
2779 struct dwarf2_section_info
*info
;
2781 /* We may see an objfile without any DWARF, in which case we just
2792 case DWARF2_DEBUG_FRAME
:
2793 info
= &data
->frame
;
2795 case DWARF2_EH_FRAME
:
2796 info
= &data
->eh_frame
;
2799 gdb_assert_not_reached ("unexpected section");
2802 dwarf2_read_section (objfile
, info
);
2804 *sectp
= get_section_bfd_section (info
);
2805 *bufp
= info
->buffer
;
2806 *sizep
= info
->size
;
2809 /* A helper function to find the sections for a .dwz file. */
2812 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2814 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2816 /* Note that we only support the standard ELF names, because .dwz
2817 is ELF-only (at the time of writing). */
2818 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2820 dwz_file
->abbrev
.s
.section
= sectp
;
2821 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2823 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2825 dwz_file
->info
.s
.section
= sectp
;
2826 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2828 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2830 dwz_file
->str
.s
.section
= sectp
;
2831 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2833 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2835 dwz_file
->line
.s
.section
= sectp
;
2836 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2838 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2840 dwz_file
->macro
.s
.section
= sectp
;
2841 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2843 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2845 dwz_file
->gdb_index
.s
.section
= sectp
;
2846 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2848 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2850 dwz_file
->debug_names
.s
.section
= sectp
;
2851 dwz_file
->debug_names
.size
= bfd_get_section_size (sectp
);
2855 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2856 there is no .gnu_debugaltlink section in the file. Error if there
2857 is such a section but the file cannot be found. */
2859 static struct dwz_file
*
2860 dwarf2_get_dwz_file (void)
2862 const char *filename
;
2863 struct dwz_file
*result
;
2864 bfd_size_type buildid_len_arg
;
2868 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2869 return dwarf2_per_objfile
->dwz_file
;
2871 bfd_set_error (bfd_error_no_error
);
2872 gdb::unique_xmalloc_ptr
<char> data
2873 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2874 &buildid_len_arg
, &buildid
));
2877 if (bfd_get_error () == bfd_error_no_error
)
2879 error (_("could not read '.gnu_debugaltlink' section: %s"),
2880 bfd_errmsg (bfd_get_error ()));
2883 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2885 buildid_len
= (size_t) buildid_len_arg
;
2887 filename
= data
.get ();
2889 std::string abs_storage
;
2890 if (!IS_ABSOLUTE_PATH (filename
))
2892 gdb::unique_xmalloc_ptr
<char> abs
2893 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2895 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2896 filename
= abs_storage
.c_str ();
2899 /* First try the file name given in the section. If that doesn't
2900 work, try to use the build-id instead. */
2901 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2902 if (dwz_bfd
!= NULL
)
2904 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2908 if (dwz_bfd
== NULL
)
2909 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2911 if (dwz_bfd
== NULL
)
2912 error (_("could not find '.gnu_debugaltlink' file for %s"),
2913 objfile_name (dwarf2_per_objfile
->objfile
));
2915 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2917 result
->dwz_bfd
= dwz_bfd
.release ();
2919 bfd_map_over_sections (result
->dwz_bfd
, locate_dwz_sections
, result
);
2921 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, result
->dwz_bfd
);
2922 dwarf2_per_objfile
->dwz_file
= result
;
2926 /* DWARF quick_symbols_functions support. */
2928 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2929 unique line tables, so we maintain a separate table of all .debug_line
2930 derived entries to support the sharing.
2931 All the quick functions need is the list of file names. We discard the
2932 line_header when we're done and don't need to record it here. */
2933 struct quick_file_names
2935 /* The data used to construct the hash key. */
2936 struct stmt_list_hash hash
;
2938 /* The number of entries in file_names, real_names. */
2939 unsigned int num_file_names
;
2941 /* The file names from the line table, after being run through
2943 const char **file_names
;
2945 /* The file names from the line table after being run through
2946 gdb_realpath. These are computed lazily. */
2947 const char **real_names
;
2950 /* When using the index (and thus not using psymtabs), each CU has an
2951 object of this type. This is used to hold information needed by
2952 the various "quick" methods. */
2953 struct dwarf2_per_cu_quick_data
2955 /* The file table. This can be NULL if there was no file table
2956 or it's currently not read in.
2957 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2958 struct quick_file_names
*file_names
;
2960 /* The corresponding symbol table. This is NULL if symbols for this
2961 CU have not yet been read. */
2962 struct compunit_symtab
*compunit_symtab
;
2964 /* A temporary mark bit used when iterating over all CUs in
2965 expand_symtabs_matching. */
2966 unsigned int mark
: 1;
2968 /* True if we've tried to read the file table and found there isn't one.
2969 There will be no point in trying to read it again next time. */
2970 unsigned int no_file_data
: 1;
2973 /* Utility hash function for a stmt_list_hash. */
2976 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2980 if (stmt_list_hash
->dwo_unit
!= NULL
)
2981 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2982 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2986 /* Utility equality function for a stmt_list_hash. */
2989 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2990 const struct stmt_list_hash
*rhs
)
2992 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2994 if (lhs
->dwo_unit
!= NULL
2995 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2998 return lhs
->line_sect_off
== rhs
->line_sect_off
;
3001 /* Hash function for a quick_file_names. */
3004 hash_file_name_entry (const void *e
)
3006 const struct quick_file_names
*file_data
3007 = (const struct quick_file_names
*) e
;
3009 return hash_stmt_list_entry (&file_data
->hash
);
3012 /* Equality function for a quick_file_names. */
3015 eq_file_name_entry (const void *a
, const void *b
)
3017 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
3018 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
3020 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
3023 /* Delete function for a quick_file_names. */
3026 delete_file_name_entry (void *e
)
3028 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
3031 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3033 xfree ((void*) file_data
->file_names
[i
]);
3034 if (file_data
->real_names
)
3035 xfree ((void*) file_data
->real_names
[i
]);
3038 /* The space for the struct itself lives on objfile_obstack,
3039 so we don't free it here. */
3042 /* Create a quick_file_names hash table. */
3045 create_quick_file_names_table (unsigned int nr_initial_entries
)
3047 return htab_create_alloc (nr_initial_entries
,
3048 hash_file_name_entry
, eq_file_name_entry
,
3049 delete_file_name_entry
, xcalloc
, xfree
);
3052 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
3053 have to be created afterwards. You should call age_cached_comp_units after
3054 processing PER_CU->CU. dw2_setup must have been already called. */
3057 load_cu (struct dwarf2_per_cu_data
*per_cu
)
3059 if (per_cu
->is_debug_types
)
3060 load_full_type_unit (per_cu
);
3062 load_full_comp_unit (per_cu
, language_minimal
);
3064 if (per_cu
->cu
== NULL
)
3065 return; /* Dummy CU. */
3067 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
3070 /* Read in the symbols for PER_CU. */
3073 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
3075 struct cleanup
*back_to
;
3077 /* Skip type_unit_groups, reading the type units they contain
3078 is handled elsewhere. */
3079 if (IS_TYPE_UNIT_GROUP (per_cu
))
3082 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
3084 if (dwarf2_per_objfile
->using_index
3085 ? per_cu
->v
.quick
->compunit_symtab
== NULL
3086 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
3088 queue_comp_unit (per_cu
, language_minimal
);
3091 /* If we just loaded a CU from a DWO, and we're working with an index
3092 that may badly handle TUs, load all the TUs in that DWO as well.
3093 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
3094 if (!per_cu
->is_debug_types
3095 && per_cu
->cu
!= NULL
3096 && per_cu
->cu
->dwo_unit
!= NULL
3097 && dwarf2_per_objfile
->index_table
!= NULL
3098 && dwarf2_per_objfile
->index_table
->version
<= 7
3099 /* DWP files aren't supported yet. */
3100 && get_dwp_file () == NULL
)
3101 queue_and_load_all_dwo_tus (per_cu
);
3106 /* Age the cache, releasing compilation units that have not
3107 been used recently. */
3108 age_cached_comp_units ();
3110 do_cleanups (back_to
);
3113 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
3114 the objfile from which this CU came. Returns the resulting symbol
3117 static struct compunit_symtab
*
3118 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
3120 gdb_assert (dwarf2_per_objfile
->using_index
);
3121 if (!per_cu
->v
.quick
->compunit_symtab
)
3123 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3124 scoped_restore decrementer
= increment_reading_symtab ();
3125 dw2_do_instantiate_symtab (per_cu
);
3126 process_cu_includes ();
3127 do_cleanups (back_to
);
3130 return per_cu
->v
.quick
->compunit_symtab
;
3133 /* Return the CU/TU given its index.
3135 This is intended for loops like:
3137 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
3138 + dwarf2_per_objfile->n_type_units); ++i)
3140 struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i);
3146 static struct dwarf2_per_cu_data
*
3147 dw2_get_cutu (int index
)
3149 if (index
>= dwarf2_per_objfile
->n_comp_units
)
3151 index
-= dwarf2_per_objfile
->n_comp_units
;
3152 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
3153 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
3156 return dwarf2_per_objfile
->all_comp_units
[index
];
3159 /* Return the CU given its index.
3160 This differs from dw2_get_cutu in that it's for when you know INDEX
3163 static struct dwarf2_per_cu_data
*
3164 dw2_get_cu (int index
)
3166 gdb_assert (index
>= 0 && index
< dwarf2_per_objfile
->n_comp_units
);
3168 return dwarf2_per_objfile
->all_comp_units
[index
];
3171 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
3172 objfile_obstack, and constructed with the specified field
3175 static dwarf2_per_cu_data
*
3176 create_cu_from_index_list (struct objfile
*objfile
,
3177 struct dwarf2_section_info
*section
,
3179 sect_offset sect_off
, ULONGEST length
)
3181 dwarf2_per_cu_data
*the_cu
3182 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3183 struct dwarf2_per_cu_data
);
3184 the_cu
->sect_off
= sect_off
;
3185 the_cu
->length
= length
;
3186 the_cu
->objfile
= objfile
;
3187 the_cu
->section
= section
;
3188 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3189 struct dwarf2_per_cu_quick_data
);
3190 the_cu
->is_dwz
= is_dwz
;
3194 /* A helper for create_cus_from_index that handles a given list of
3198 create_cus_from_index_list (struct objfile
*objfile
,
3199 const gdb_byte
*cu_list
, offset_type n_elements
,
3200 struct dwarf2_section_info
*section
,
3206 for (i
= 0; i
< n_elements
; i
+= 2)
3208 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3210 sect_offset sect_off
3211 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
3212 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
3215 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2]
3216 = create_cu_from_index_list (objfile
, section
, is_dwz
, sect_off
, length
);
3220 /* Read the CU list from the mapped index, and use it to create all
3221 the CU objects for this objfile. */
3224 create_cus_from_index (struct objfile
*objfile
,
3225 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3226 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3228 struct dwz_file
*dwz
;
3230 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
3231 dwarf2_per_objfile
->all_comp_units
=
3232 XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
3233 dwarf2_per_objfile
->n_comp_units
);
3235 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
3236 &dwarf2_per_objfile
->info
, 0, 0);
3238 if (dwz_elements
== 0)
3241 dwz
= dwarf2_get_dwz_file ();
3242 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
3243 cu_list_elements
/ 2);
3246 /* Create the signatured type hash table from the index. */
3249 create_signatured_type_table_from_index (struct objfile
*objfile
,
3250 struct dwarf2_section_info
*section
,
3251 const gdb_byte
*bytes
,
3252 offset_type elements
)
3255 htab_t sig_types_hash
;
3257 dwarf2_per_objfile
->n_type_units
3258 = dwarf2_per_objfile
->n_allocated_type_units
3260 dwarf2_per_objfile
->all_type_units
=
3261 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3263 sig_types_hash
= allocate_signatured_type_table (objfile
);
3265 for (i
= 0; i
< elements
; i
+= 3)
3267 struct signatured_type
*sig_type
;
3270 cu_offset type_offset_in_tu
;
3272 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3273 sect_offset sect_off
3274 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3276 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3278 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3281 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3282 struct signatured_type
);
3283 sig_type
->signature
= signature
;
3284 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3285 sig_type
->per_cu
.is_debug_types
= 1;
3286 sig_type
->per_cu
.section
= section
;
3287 sig_type
->per_cu
.sect_off
= sect_off
;
3288 sig_type
->per_cu
.objfile
= objfile
;
3289 sig_type
->per_cu
.v
.quick
3290 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3291 struct dwarf2_per_cu_quick_data
);
3293 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3296 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
3299 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3302 /* Create the signatured type hash table from .debug_names. */
3305 create_signatured_type_table_from_debug_names
3306 (struct objfile
*objfile
,
3307 const mapped_debug_names
&map
,
3308 struct dwarf2_section_info
*section
,
3309 struct dwarf2_section_info
*abbrev_section
)
3311 dwarf2_read_section (objfile
, section
);
3312 dwarf2_read_section (objfile
, abbrev_section
);
3314 dwarf2_per_objfile
->n_type_units
3315 = dwarf2_per_objfile
->n_allocated_type_units
3317 dwarf2_per_objfile
->all_type_units
3318 = XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3320 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3322 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3324 struct signatured_type
*sig_type
;
3327 cu_offset type_offset_in_tu
;
3329 sect_offset sect_off
3330 = (sect_offset
) (extract_unsigned_integer
3331 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3333 map
.dwarf5_byte_order
));
3335 comp_unit_head cu_header
;
3336 read_and_check_comp_unit_head (&cu_header
, section
, abbrev_section
,
3337 section
->buffer
+ to_underlying (sect_off
),
3340 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3341 struct signatured_type
);
3342 sig_type
->signature
= cu_header
.signature
;
3343 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3344 sig_type
->per_cu
.is_debug_types
= 1;
3345 sig_type
->per_cu
.section
= section
;
3346 sig_type
->per_cu
.sect_off
= sect_off
;
3347 sig_type
->per_cu
.objfile
= objfile
;
3348 sig_type
->per_cu
.v
.quick
3349 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3350 struct dwarf2_per_cu_quick_data
);
3352 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3355 dwarf2_per_objfile
->all_type_units
[i
] = sig_type
;
3358 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3361 /* Read the address map data from the mapped index, and use it to
3362 populate the objfile's psymtabs_addrmap. */
3365 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
3367 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3368 const gdb_byte
*iter
, *end
;
3369 struct addrmap
*mutable_map
;
3372 auto_obstack temp_obstack
;
3374 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3376 iter
= index
->address_table
.data ();
3377 end
= iter
+ index
->address_table
.size ();
3379 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3383 ULONGEST hi
, lo
, cu_index
;
3384 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3386 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3388 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3393 complaint (&symfile_complaints
,
3394 _(".gdb_index address table has invalid range (%s - %s)"),
3395 hex_string (lo
), hex_string (hi
));
3399 if (cu_index
>= dwarf2_per_objfile
->n_comp_units
)
3401 complaint (&symfile_complaints
,
3402 _(".gdb_index address table has invalid CU number %u"),
3403 (unsigned) cu_index
);
3407 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
);
3408 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
);
3409 addrmap_set_empty (mutable_map
, lo
, hi
- 1, dw2_get_cutu (cu_index
));
3412 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3413 &objfile
->objfile_obstack
);
3416 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3417 populate the objfile's psymtabs_addrmap. */
3420 create_addrmap_from_aranges (struct objfile
*objfile
,
3421 struct dwarf2_section_info
*section
)
3423 bfd
*abfd
= objfile
->obfd
;
3424 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3425 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
3426 SECT_OFF_TEXT (objfile
));
3428 auto_obstack temp_obstack
;
3429 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3431 std::unordered_map
<sect_offset
,
3432 dwarf2_per_cu_data
*,
3433 gdb::hash_enum
<sect_offset
>>
3434 debug_info_offset_to_per_cu
;
3435 for (int cui
= 0; cui
< dwarf2_per_objfile
->n_comp_units
; ++cui
)
3437 dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (cui
);
3438 const auto insertpair
3439 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3440 if (!insertpair
.second
)
3442 warning (_("Section .debug_aranges in %s has duplicate "
3443 "debug_info_offset %u, ignoring .debug_aranges."),
3444 objfile_name (objfile
), to_underlying (per_cu
->sect_off
));
3449 dwarf2_read_section (objfile
, section
);
3451 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3453 const gdb_byte
*addr
= section
->buffer
;
3455 while (addr
< section
->buffer
+ section
->size
)
3457 const gdb_byte
*const entry_addr
= addr
;
3458 unsigned int bytes_read
;
3460 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3464 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3465 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3466 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3467 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3469 warning (_("Section .debug_aranges in %s entry at offset %zu "
3470 "length %s exceeds section length %s, "
3471 "ignoring .debug_aranges."),
3472 objfile_name (objfile
), entry_addr
- section
->buffer
,
3473 plongest (bytes_read
+ entry_length
),
3474 pulongest (section
->size
));
3478 /* The version number. */
3479 const uint16_t version
= read_2_bytes (abfd
, addr
);
3483 warning (_("Section .debug_aranges in %s entry at offset %zu "
3484 "has unsupported version %d, ignoring .debug_aranges."),
3485 objfile_name (objfile
), entry_addr
- section
->buffer
,
3490 const uint64_t debug_info_offset
3491 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3492 addr
+= offset_size
;
3493 const auto per_cu_it
3494 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3495 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3497 warning (_("Section .debug_aranges in %s entry at offset %zu "
3498 "debug_info_offset %s does not exists, "
3499 "ignoring .debug_aranges."),
3500 objfile_name (objfile
), entry_addr
- section
->buffer
,
3501 pulongest (debug_info_offset
));
3504 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3506 const uint8_t address_size
= *addr
++;
3507 if (address_size
< 1 || address_size
> 8)
3509 warning (_("Section .debug_aranges in %s entry at offset %zu "
3510 "address_size %u is invalid, ignoring .debug_aranges."),
3511 objfile_name (objfile
), entry_addr
- section
->buffer
,
3516 const uint8_t segment_selector_size
= *addr
++;
3517 if (segment_selector_size
!= 0)
3519 warning (_("Section .debug_aranges in %s entry at offset %zu "
3520 "segment_selector_size %u is not supported, "
3521 "ignoring .debug_aranges."),
3522 objfile_name (objfile
), entry_addr
- section
->buffer
,
3523 segment_selector_size
);
3527 /* Must pad to an alignment boundary that is twice the address
3528 size. It is undocumented by the DWARF standard but GCC does
3530 for (size_t padding
= ((-(addr
- section
->buffer
))
3531 & (2 * address_size
- 1));
3532 padding
> 0; padding
--)
3535 warning (_("Section .debug_aranges in %s entry at offset %zu "
3536 "padding is not zero, ignoring .debug_aranges."),
3537 objfile_name (objfile
), entry_addr
- section
->buffer
);
3543 if (addr
+ 2 * address_size
> entry_end
)
3545 warning (_("Section .debug_aranges in %s entry at offset %zu "
3546 "address list is not properly terminated, "
3547 "ignoring .debug_aranges."),
3548 objfile_name (objfile
), entry_addr
- section
->buffer
);
3551 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3553 addr
+= address_size
;
3554 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3556 addr
+= address_size
;
3557 if (start
== 0 && length
== 0)
3559 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3561 /* Symbol was eliminated due to a COMDAT group. */
3564 ULONGEST end
= start
+ length
;
3565 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
);
3566 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
);
3567 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3571 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3572 &objfile
->objfile_obstack
);
3575 /* The hash function for strings in the mapped index. This is the same as
3576 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
3577 implementation. This is necessary because the hash function is tied to the
3578 format of the mapped index file. The hash values do not have to match with
3581 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
3584 mapped_index_string_hash (int index_version
, const void *p
)
3586 const unsigned char *str
= (const unsigned char *) p
;
3590 while ((c
= *str
++) != 0)
3592 if (index_version
>= 5)
3594 r
= r
* 67 + c
- 113;
3600 /* Find a slot in the mapped index INDEX for the object named NAME.
3601 If NAME is found, set *VEC_OUT to point to the CU vector in the
3602 constant pool and return true. If NAME cannot be found, return
3606 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3607 offset_type
**vec_out
)
3610 offset_type slot
, step
;
3611 int (*cmp
) (const char *, const char *);
3613 gdb::unique_xmalloc_ptr
<char> without_params
;
3614 if (current_language
->la_language
== language_cplus
3615 || current_language
->la_language
== language_fortran
3616 || current_language
->la_language
== language_d
)
3618 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3621 if (strchr (name
, '(') != NULL
)
3623 without_params
= cp_remove_params (name
);
3625 if (without_params
!= NULL
)
3626 name
= without_params
.get ();
3630 /* Index version 4 did not support case insensitive searches. But the
3631 indices for case insensitive languages are built in lowercase, therefore
3632 simulate our NAME being searched is also lowercased. */
3633 hash
= mapped_index_string_hash ((index
->version
== 4
3634 && case_sensitivity
== case_sensitive_off
3635 ? 5 : index
->version
),
3638 slot
= hash
& (index
->symbol_table
.size () - 1);
3639 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3640 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3646 const auto &bucket
= index
->symbol_table
[slot
];
3647 if (bucket
.name
== 0 && bucket
.vec
== 0)
3650 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3651 if (!cmp (name
, str
))
3653 *vec_out
= (offset_type
*) (index
->constant_pool
3654 + MAYBE_SWAP (bucket
.vec
));
3658 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3662 /* A helper function that reads the .gdb_index from SECTION and fills
3663 in MAP. FILENAME is the name of the file containing the section;
3664 it is used for error reporting. DEPRECATED_OK is nonzero if it is
3665 ok to use deprecated sections.
3667 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3668 out parameters that are filled in with information about the CU and
3669 TU lists in the section.
3671 Returns 1 if all went well, 0 otherwise. */
3674 read_index_from_section (struct objfile
*objfile
,
3675 const char *filename
,
3677 struct dwarf2_section_info
*section
,
3678 struct mapped_index
*map
,
3679 const gdb_byte
**cu_list
,
3680 offset_type
*cu_list_elements
,
3681 const gdb_byte
**types_list
,
3682 offset_type
*types_list_elements
)
3684 const gdb_byte
*addr
;
3685 offset_type version
;
3686 offset_type
*metadata
;
3689 if (dwarf2_section_empty_p (section
))
3692 /* Older elfutils strip versions could keep the section in the main
3693 executable while splitting it for the separate debug info file. */
3694 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
3697 dwarf2_read_section (objfile
, section
);
3699 addr
= section
->buffer
;
3700 /* Version check. */
3701 version
= MAYBE_SWAP (*(offset_type
*) addr
);
3702 /* Versions earlier than 3 emitted every copy of a psymbol. This
3703 causes the index to behave very poorly for certain requests. Version 3
3704 contained incomplete addrmap. So, it seems better to just ignore such
3708 static int warning_printed
= 0;
3709 if (!warning_printed
)
3711 warning (_("Skipping obsolete .gdb_index section in %s."),
3713 warning_printed
= 1;
3717 /* Index version 4 uses a different hash function than index version
3720 Versions earlier than 6 did not emit psymbols for inlined
3721 functions. Using these files will cause GDB not to be able to
3722 set breakpoints on inlined functions by name, so we ignore these
3723 indices unless the user has done
3724 "set use-deprecated-index-sections on". */
3725 if (version
< 6 && !deprecated_ok
)
3727 static int warning_printed
= 0;
3728 if (!warning_printed
)
3731 Skipping deprecated .gdb_index section in %s.\n\
3732 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3733 to use the section anyway."),
3735 warning_printed
= 1;
3739 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3740 of the TU (for symbols coming from TUs),
3741 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3742 Plus gold-generated indices can have duplicate entries for global symbols,
3743 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3744 These are just performance bugs, and we can't distinguish gdb-generated
3745 indices from gold-generated ones, so issue no warning here. */
3747 /* Indexes with higher version than the one supported by GDB may be no
3748 longer backward compatible. */
3752 map
->version
= version
;
3753 map
->total_size
= section
->size
;
3755 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3758 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3759 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3763 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3764 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3765 - MAYBE_SWAP (metadata
[i
]))
3769 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3770 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3772 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3775 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3776 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3778 = gdb::array_view
<mapped_index::symbol_table_slot
>
3779 ((mapped_index::symbol_table_slot
*) symbol_table
,
3780 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3783 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3788 /* Read .gdb_index. If everything went ok, initialize the "quick"
3789 elements of all the CUs and return 1. Otherwise, return 0. */
3792 dwarf2_read_index (struct objfile
*objfile
)
3794 struct mapped_index local_map
, *map
;
3795 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3796 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3797 struct dwz_file
*dwz
;
3799 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3800 use_deprecated_index_sections
,
3801 &dwarf2_per_objfile
->gdb_index
, &local_map
,
3802 &cu_list
, &cu_list_elements
,
3803 &types_list
, &types_list_elements
))
3806 /* Don't use the index if it's empty. */
3807 if (local_map
.symbol_table
.empty ())
3810 /* If there is a .dwz file, read it so we can get its CU list as
3812 dwz
= dwarf2_get_dwz_file ();
3815 struct mapped_index dwz_map
;
3816 const gdb_byte
*dwz_types_ignore
;
3817 offset_type dwz_types_elements_ignore
;
3819 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3821 &dwz
->gdb_index
, &dwz_map
,
3822 &dwz_list
, &dwz_list_elements
,
3824 &dwz_types_elements_ignore
))
3826 warning (_("could not read '.gdb_index' section from %s; skipping"),
3827 bfd_get_filename (dwz
->dwz_bfd
));
3832 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
3835 if (types_list_elements
)
3837 struct dwarf2_section_info
*section
;
3839 /* We can only handle a single .debug_types when we have an
3841 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
3844 section
= VEC_index (dwarf2_section_info_def
,
3845 dwarf2_per_objfile
->types
, 0);
3847 create_signatured_type_table_from_index (objfile
, section
, types_list
,
3848 types_list_elements
);
3851 create_addrmap_from_index (objfile
, &local_map
);
3853 map
= XOBNEW (&objfile
->objfile_obstack
, struct mapped_index
);
3854 map
= new (map
) mapped_index ();
3857 dwarf2_per_objfile
->index_table
= map
;
3858 dwarf2_per_objfile
->using_index
= 1;
3859 dwarf2_per_objfile
->quick_file_names_table
=
3860 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3865 /* A helper for the "quick" functions which sets the global
3866 dwarf2_per_objfile according to OBJFILE. */
3869 dw2_setup (struct objfile
*objfile
)
3871 dwarf2_per_objfile
= ((struct dwarf2_per_objfile
*)
3872 objfile_data (objfile
, dwarf2_objfile_data_key
));
3873 gdb_assert (dwarf2_per_objfile
);
3876 /* die_reader_func for dw2_get_file_names. */
3879 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3880 const gdb_byte
*info_ptr
,
3881 struct die_info
*comp_unit_die
,
3885 struct dwarf2_cu
*cu
= reader
->cu
;
3886 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3887 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3888 struct dwarf2_per_cu_data
*lh_cu
;
3889 struct attribute
*attr
;
3892 struct quick_file_names
*qfn
;
3894 gdb_assert (! this_cu
->is_debug_types
);
3896 /* Our callers never want to match partial units -- instead they
3897 will match the enclosing full CU. */
3898 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3900 this_cu
->v
.quick
->no_file_data
= 1;
3908 sect_offset line_offset
{};
3910 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3913 struct quick_file_names find_entry
;
3915 line_offset
= (sect_offset
) DW_UNSND (attr
);
3917 /* We may have already read in this line header (TU line header sharing).
3918 If we have we're done. */
3919 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3920 find_entry
.hash
.line_sect_off
= line_offset
;
3921 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3922 &find_entry
, INSERT
);
3925 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3929 lh
= dwarf_decode_line_header (line_offset
, cu
);
3933 lh_cu
->v
.quick
->no_file_data
= 1;
3937 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3938 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3939 qfn
->hash
.line_sect_off
= line_offset
;
3940 gdb_assert (slot
!= NULL
);
3943 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3945 qfn
->num_file_names
= lh
->file_names
.size ();
3947 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->file_names
.size ());
3948 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
3949 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3950 qfn
->real_names
= NULL
;
3952 lh_cu
->v
.quick
->file_names
= qfn
;
3955 /* A helper for the "quick" functions which attempts to read the line
3956 table for THIS_CU. */
3958 static struct quick_file_names
*
3959 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3961 /* This should never be called for TUs. */
3962 gdb_assert (! this_cu
->is_debug_types
);
3963 /* Nor type unit groups. */
3964 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3966 if (this_cu
->v
.quick
->file_names
!= NULL
)
3967 return this_cu
->v
.quick
->file_names
;
3968 /* If we know there is no line data, no point in looking again. */
3969 if (this_cu
->v
.quick
->no_file_data
)
3972 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3974 if (this_cu
->v
.quick
->no_file_data
)
3976 return this_cu
->v
.quick
->file_names
;
3979 /* A helper for the "quick" functions which computes and caches the
3980 real path for a given file name from the line table. */
3983 dw2_get_real_path (struct objfile
*objfile
,
3984 struct quick_file_names
*qfn
, int index
)
3986 if (qfn
->real_names
== NULL
)
3987 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3988 qfn
->num_file_names
, const char *);
3990 if (qfn
->real_names
[index
] == NULL
)
3991 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3993 return qfn
->real_names
[index
];
3996 static struct symtab
*
3997 dw2_find_last_source_symtab (struct objfile
*objfile
)
3999 struct compunit_symtab
*cust
;
4002 dw2_setup (objfile
);
4003 index
= dwarf2_per_objfile
->n_comp_units
- 1;
4004 cust
= dw2_instantiate_symtab (dw2_get_cutu (index
));
4007 return compunit_primary_filetab (cust
);
4010 /* Traversal function for dw2_forget_cached_source_info. */
4013 dw2_free_cached_file_names (void **slot
, void *info
)
4015 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
4017 if (file_data
->real_names
)
4021 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
4023 xfree ((void*) file_data
->real_names
[i
]);
4024 file_data
->real_names
[i
] = NULL
;
4032 dw2_forget_cached_source_info (struct objfile
*objfile
)
4034 dw2_setup (objfile
);
4036 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
4037 dw2_free_cached_file_names
, NULL
);
4040 /* Helper function for dw2_map_symtabs_matching_filename that expands
4041 the symtabs and calls the iterator. */
4044 dw2_map_expand_apply (struct objfile
*objfile
,
4045 struct dwarf2_per_cu_data
*per_cu
,
4046 const char *name
, const char *real_path
,
4047 gdb::function_view
<bool (symtab
*)> callback
)
4049 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
4051 /* Don't visit already-expanded CUs. */
4052 if (per_cu
->v
.quick
->compunit_symtab
)
4055 /* This may expand more than one symtab, and we want to iterate over
4057 dw2_instantiate_symtab (per_cu
);
4059 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
4060 last_made
, callback
);
4063 /* Implementation of the map_symtabs_matching_filename method. */
4066 dw2_map_symtabs_matching_filename
4067 (struct objfile
*objfile
, const char *name
, const char *real_path
,
4068 gdb::function_view
<bool (symtab
*)> callback
)
4071 const char *name_basename
= lbasename (name
);
4073 dw2_setup (objfile
);
4075 /* The rule is CUs specify all the files, including those used by
4076 any TU, so there's no need to scan TUs here. */
4078 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4081 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4082 struct quick_file_names
*file_data
;
4084 /* We only need to look at symtabs not already expanded. */
4085 if (per_cu
->v
.quick
->compunit_symtab
)
4088 file_data
= dw2_get_file_names (per_cu
);
4089 if (file_data
== NULL
)
4092 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4094 const char *this_name
= file_data
->file_names
[j
];
4095 const char *this_real_name
;
4097 if (compare_filenames_for_search (this_name
, name
))
4099 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
4105 /* Before we invoke realpath, which can get expensive when many
4106 files are involved, do a quick comparison of the basenames. */
4107 if (! basenames_may_differ
4108 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
4111 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4112 if (compare_filenames_for_search (this_real_name
, name
))
4114 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
4120 if (real_path
!= NULL
)
4122 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
4123 gdb_assert (IS_ABSOLUTE_PATH (name
));
4124 if (this_real_name
!= NULL
4125 && FILENAME_CMP (real_path
, this_real_name
) == 0)
4127 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
4139 /* Struct used to manage iterating over all CUs looking for a symbol. */
4141 struct dw2_symtab_iterator
4143 /* The internalized form of .gdb_index. */
4144 struct mapped_index
*index
;
4145 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
4146 int want_specific_block
;
4147 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
4148 Unused if !WANT_SPECIFIC_BLOCK. */
4150 /* The kind of symbol we're looking for. */
4152 /* The list of CUs from the index entry of the symbol,
4153 or NULL if not found. */
4155 /* The next element in VEC to look at. */
4157 /* The number of elements in VEC, or zero if there is no match. */
4159 /* Have we seen a global version of the symbol?
4160 If so we can ignore all further global instances.
4161 This is to work around gold/15646, inefficient gold-generated
4166 /* Initialize the index symtab iterator ITER.
4167 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
4168 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
4171 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
4172 struct mapped_index
*index
,
4173 int want_specific_block
,
4178 iter
->index
= index
;
4179 iter
->want_specific_block
= want_specific_block
;
4180 iter
->block_index
= block_index
;
4181 iter
->domain
= domain
;
4183 iter
->global_seen
= 0;
4185 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
4186 iter
->length
= MAYBE_SWAP (*iter
->vec
);
4194 /* Return the next matching CU or NULL if there are no more. */
4196 static struct dwarf2_per_cu_data
*
4197 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
4199 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
4201 offset_type cu_index_and_attrs
=
4202 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
4203 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4204 struct dwarf2_per_cu_data
*per_cu
;
4205 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
4206 /* This value is only valid for index versions >= 7. */
4207 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4208 gdb_index_symbol_kind symbol_kind
=
4209 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4210 /* Only check the symbol attributes if they're present.
4211 Indices prior to version 7 don't record them,
4212 and indices >= 7 may elide them for certain symbols
4213 (gold does this). */
4215 (iter
->index
->version
>= 7
4216 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4218 /* Don't crash on bad data. */
4219 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
4220 + dwarf2_per_objfile
->n_type_units
))
4222 complaint (&symfile_complaints
,
4223 _(".gdb_index entry has bad CU index"
4225 objfile_name (dwarf2_per_objfile
->objfile
));
4229 per_cu
= dw2_get_cutu (cu_index
);
4231 /* Skip if already read in. */
4232 if (per_cu
->v
.quick
->compunit_symtab
)
4235 /* Check static vs global. */
4238 if (iter
->want_specific_block
4239 && want_static
!= is_static
)
4241 /* Work around gold/15646. */
4242 if (!is_static
&& iter
->global_seen
)
4245 iter
->global_seen
= 1;
4248 /* Only check the symbol's kind if it has one. */
4251 switch (iter
->domain
)
4254 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4255 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4256 /* Some types are also in VAR_DOMAIN. */
4257 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4261 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4265 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4280 static struct compunit_symtab
*
4281 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
4282 const char *name
, domain_enum domain
)
4284 struct compunit_symtab
*stab_best
= NULL
;
4285 struct mapped_index
*index
;
4287 dw2_setup (objfile
);
4289 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4291 index
= dwarf2_per_objfile
->index_table
;
4293 /* index is NULL if OBJF_READNOW. */
4296 struct dw2_symtab_iterator iter
;
4297 struct dwarf2_per_cu_data
*per_cu
;
4299 dw2_symtab_iter_init (&iter
, index
, 1, block_index
, domain
, name
);
4301 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4303 struct symbol
*sym
, *with_opaque
= NULL
;
4304 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
4305 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4306 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4308 sym
= block_find_symbol (block
, name
, domain
,
4309 block_find_non_opaque_type_preferred
,
4312 /* Some caution must be observed with overloaded functions
4313 and methods, since the index will not contain any overload
4314 information (but NAME might contain it). */
4317 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4319 if (with_opaque
!= NULL
4320 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4323 /* Keep looking through other CUs. */
4331 dw2_print_stats (struct objfile
*objfile
)
4333 int i
, total
, count
;
4335 dw2_setup (objfile
);
4336 total
= dwarf2_per_objfile
->n_comp_units
+ dwarf2_per_objfile
->n_type_units
;
4338 for (i
= 0; i
< total
; ++i
)
4340 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4342 if (!per_cu
->v
.quick
->compunit_symtab
)
4345 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4346 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4349 /* This dumps minimal information about the index.
4350 It is called via "mt print objfiles".
4351 One use is to verify .gdb_index has been loaded by the
4352 gdb.dwarf2/gdb-index.exp testcase. */
4355 dw2_dump (struct objfile
*objfile
)
4357 dw2_setup (objfile
);
4358 gdb_assert (dwarf2_per_objfile
->using_index
);
4359 printf_filtered (".gdb_index:");
4360 if (dwarf2_per_objfile
->index_table
!= NULL
)
4362 printf_filtered (" version %d\n",
4363 dwarf2_per_objfile
->index_table
->version
);
4366 printf_filtered (" faked for \"readnow\"\n");
4367 printf_filtered ("\n");
4371 dw2_relocate (struct objfile
*objfile
,
4372 const struct section_offsets
*new_offsets
,
4373 const struct section_offsets
*delta
)
4375 /* There's nothing to relocate here. */
4379 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4380 const char *func_name
)
4382 struct mapped_index
*index
;
4384 dw2_setup (objfile
);
4386 index
= dwarf2_per_objfile
->index_table
;
4388 /* index is NULL if OBJF_READNOW. */
4391 struct dw2_symtab_iterator iter
;
4392 struct dwarf2_per_cu_data
*per_cu
;
4394 /* Note: It doesn't matter what we pass for block_index here. */
4395 dw2_symtab_iter_init (&iter
, index
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
4398 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4399 dw2_instantiate_symtab (per_cu
);
4404 dw2_expand_all_symtabs (struct objfile
*objfile
)
4408 dw2_setup (objfile
);
4410 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
4411 + dwarf2_per_objfile
->n_type_units
); ++i
)
4413 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4415 dw2_instantiate_symtab (per_cu
);
4420 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4421 const char *fullname
)
4425 dw2_setup (objfile
);
4427 /* We don't need to consider type units here.
4428 This is only called for examining code, e.g. expand_line_sal.
4429 There can be an order of magnitude (or more) more type units
4430 than comp units, and we avoid them if we can. */
4432 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4435 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4436 struct quick_file_names
*file_data
;
4438 /* We only need to look at symtabs not already expanded. */
4439 if (per_cu
->v
.quick
->compunit_symtab
)
4442 file_data
= dw2_get_file_names (per_cu
);
4443 if (file_data
== NULL
)
4446 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4448 const char *this_fullname
= file_data
->file_names
[j
];
4450 if (filename_cmp (this_fullname
, fullname
) == 0)
4452 dw2_instantiate_symtab (per_cu
);
4460 dw2_map_matching_symbols (struct objfile
*objfile
,
4461 const char * name
, domain_enum domain
,
4463 int (*callback
) (struct block
*,
4464 struct symbol
*, void *),
4465 void *data
, symbol_name_match_type match
,
4466 symbol_compare_ftype
*ordered_compare
)
4468 /* Currently unimplemented; used for Ada. The function can be called if the
4469 current language is Ada for a non-Ada objfile using GNU index. As Ada
4470 does not look for non-Ada symbols this function should just return. */
4473 /* Symbol name matcher for .gdb_index names.
4475 Symbol names in .gdb_index have a few particularities:
4477 - There's no indication of which is the language of each symbol.
4479 Since each language has its own symbol name matching algorithm,
4480 and we don't know which language is the right one, we must match
4481 each symbol against all languages. This would be a potential
4482 performance problem if it were not mitigated by the
4483 mapped_index::name_components lookup table, which significantly
4484 reduces the number of times we need to call into this matcher,
4485 making it a non-issue.
4487 - Symbol names in the index have no overload (parameter)
4488 information. I.e., in C++, "foo(int)" and "foo(long)" both
4489 appear as "foo" in the index, for example.
4491 This means that the lookup names passed to the symbol name
4492 matcher functions must have no parameter information either
4493 because (e.g.) symbol search name "foo" does not match
4494 lookup-name "foo(int)" [while swapping search name for lookup
4497 class gdb_index_symbol_name_matcher
4500 /* Prepares the vector of comparison functions for LOOKUP_NAME. */
4501 gdb_index_symbol_name_matcher (const lookup_name_info
&lookup_name
);
4503 /* Walk all the matcher routines and match SYMBOL_NAME against them.
4504 Returns true if any matcher matches. */
4505 bool matches (const char *symbol_name
);
4508 /* A reference to the lookup name we're matching against. */
4509 const lookup_name_info
&m_lookup_name
;
4511 /* A vector holding all the different symbol name matchers, for all
4513 std::vector
<symbol_name_matcher_ftype
*> m_symbol_name_matcher_funcs
;
4516 gdb_index_symbol_name_matcher::gdb_index_symbol_name_matcher
4517 (const lookup_name_info
&lookup_name
)
4518 : m_lookup_name (lookup_name
)
4520 /* Prepare the vector of comparison functions upfront, to avoid
4521 doing the same work for each symbol. Care is taken to avoid
4522 matching with the same matcher more than once if/when multiple
4523 languages use the same matcher function. */
4524 auto &matchers
= m_symbol_name_matcher_funcs
;
4525 matchers
.reserve (nr_languages
);
4527 matchers
.push_back (default_symbol_name_matcher
);
4529 for (int i
= 0; i
< nr_languages
; i
++)
4531 const language_defn
*lang
= language_def ((enum language
) i
);
4532 if (lang
->la_get_symbol_name_matcher
!= NULL
)
4534 symbol_name_matcher_ftype
*name_matcher
4535 = lang
->la_get_symbol_name_matcher (m_lookup_name
);
4537 /* Don't insert the same comparison routine more than once.
4538 Note that we do this linear walk instead of a cheaper
4539 sorted insert, or use a std::set or something like that,
4540 because relative order of function addresses is not
4541 stable. This is not a problem in practice because the
4542 number of supported languages is low, and the cost here
4543 is tiny compared to the number of searches we'll do
4544 afterwards using this object. */
4545 if (std::find (matchers
.begin (), matchers
.end (), name_matcher
)
4547 matchers
.push_back (name_matcher
);
4553 gdb_index_symbol_name_matcher::matches (const char *symbol_name
)
4555 for (auto matches_name
: m_symbol_name_matcher_funcs
)
4556 if (matches_name (symbol_name
, m_lookup_name
, NULL
))
4562 /* Starting from a search name, return the string that finds the upper
4563 bound of all strings that start with SEARCH_NAME in a sorted name
4564 list. Returns the empty string to indicate that the upper bound is
4565 the end of the list. */
4568 make_sort_after_prefix_name (const char *search_name
)
4570 /* When looking to complete "func", we find the upper bound of all
4571 symbols that start with "func" by looking for where we'd insert
4572 the closest string that would follow "func" in lexicographical
4573 order. Usually, that's "func"-with-last-character-incremented,
4574 i.e. "fund". Mind non-ASCII characters, though. Usually those
4575 will be UTF-8 multi-byte sequences, but we can't be certain.
4576 Especially mind the 0xff character, which is a valid character in
4577 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4578 rule out compilers allowing it in identifiers. Note that
4579 conveniently, strcmp/strcasecmp are specified to compare
4580 characters interpreted as unsigned char. So what we do is treat
4581 the whole string as a base 256 number composed of a sequence of
4582 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4583 to 0, and carries 1 to the following more-significant position.
4584 If the very first character in SEARCH_NAME ends up incremented
4585 and carries/overflows, then the upper bound is the end of the
4586 list. The string after the empty string is also the empty
4589 Some examples of this operation:
4591 SEARCH_NAME => "+1" RESULT
4595 "\xff" "a" "\xff" => "\xff" "b"
4600 Then, with these symbols for example:
4606 completing "func" looks for symbols between "func" and
4607 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4608 which finds "func" and "func1", but not "fund".
4612 funcÿ (Latin1 'ÿ' [0xff])
4616 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4617 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4621 ÿÿ (Latin1 'ÿ' [0xff])
4624 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4625 the end of the list.
4627 std::string after
= search_name
;
4628 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4630 if (!after
.empty ())
4631 after
.back () = (unsigned char) after
.back () + 1;
4635 /* See declaration. */
4637 std::pair
<std::vector
<name_component
>::const_iterator
,
4638 std::vector
<name_component
>::const_iterator
>
4639 mapped_index_base::find_name_components_bounds
4640 (const lookup_name_info
&lookup_name_without_params
) const
4643 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4646 = lookup_name_without_params
.cplus ().lookup_name ().c_str ();
4648 /* Comparison function object for lower_bound that matches against a
4649 given symbol name. */
4650 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4653 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4654 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4655 return name_cmp (elem_name
, name
) < 0;
4658 /* Comparison function object for upper_bound that matches against a
4659 given symbol name. */
4660 auto lookup_compare_upper
= [&] (const char *name
,
4661 const name_component
&elem
)
4663 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4664 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4665 return name_cmp (name
, elem_name
) < 0;
4668 auto begin
= this->name_components
.begin ();
4669 auto end
= this->name_components
.end ();
4671 /* Find the lower bound. */
4674 if (lookup_name_without_params
.completion_mode () && cplus
[0] == '\0')
4677 return std::lower_bound (begin
, end
, cplus
, lookup_compare_lower
);
4680 /* Find the upper bound. */
4683 if (lookup_name_without_params
.completion_mode ())
4685 /* In completion mode, we want UPPER to point past all
4686 symbols names that have the same prefix. I.e., with
4687 these symbols, and completing "func":
4689 function << lower bound
4691 other_function << upper bound
4693 We find the upper bound by looking for the insertion
4694 point of "func"-with-last-character-incremented,
4696 std::string after
= make_sort_after_prefix_name (cplus
);
4699 return std::lower_bound (lower
, end
, after
.c_str (),
4700 lookup_compare_lower
);
4703 return std::upper_bound (lower
, end
, cplus
, lookup_compare_upper
);
4706 return {lower
, upper
};
4709 /* See declaration. */
4712 mapped_index_base::build_name_components ()
4714 if (!this->name_components
.empty ())
4717 this->name_components_casing
= case_sensitivity
;
4719 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4721 /* The code below only knows how to break apart components of C++
4722 symbol names (and other languages that use '::' as
4723 namespace/module separator). If we add support for wild matching
4724 to some language that uses some other operator (E.g., Ada, Go and
4725 D use '.'), then we'll need to try splitting the symbol name
4726 according to that language too. Note that Ada does support wild
4727 matching, but doesn't currently support .gdb_index. */
4728 auto count
= this->symbol_name_count ();
4729 for (offset_type idx
= 0; idx
< count
; idx
++)
4731 if (this->symbol_name_slot_invalid (idx
))
4734 const char *name
= this->symbol_name_at (idx
);
4736 /* Add each name component to the name component table. */
4737 unsigned int previous_len
= 0;
4738 for (unsigned int current_len
= cp_find_first_component (name
);
4739 name
[current_len
] != '\0';
4740 current_len
+= cp_find_first_component (name
+ current_len
))
4742 gdb_assert (name
[current_len
] == ':');
4743 this->name_components
.push_back ({previous_len
, idx
});
4744 /* Skip the '::'. */
4746 previous_len
= current_len
;
4748 this->name_components
.push_back ({previous_len
, idx
});
4751 /* Sort name_components elements by name. */
4752 auto name_comp_compare
= [&] (const name_component
&left
,
4753 const name_component
&right
)
4755 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4756 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4758 const char *left_name
= left_qualified
+ left
.name_offset
;
4759 const char *right_name
= right_qualified
+ right
.name_offset
;
4761 return name_cmp (left_name
, right_name
) < 0;
4764 std::sort (this->name_components
.begin (),
4765 this->name_components
.end (),
4769 /* Helper for dw2_expand_symtabs_matching that works with a
4770 mapped_index_base instead of the containing objfile. This is split
4771 to a separate function in order to be able to unit test the
4772 name_components matching using a mock mapped_index_base. For each
4773 symbol name that matches, calls MATCH_CALLBACK, passing it the
4774 symbol's index in the mapped_index_base symbol table. */
4777 dw2_expand_symtabs_matching_symbol
4778 (mapped_index_base
&index
,
4779 const lookup_name_info
&lookup_name_in
,
4780 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4781 enum search_domain kind
,
4782 gdb::function_view
<void (offset_type
)> match_callback
)
4784 lookup_name_info lookup_name_without_params
4785 = lookup_name_in
.make_ignore_params ();
4786 gdb_index_symbol_name_matcher lookup_name_matcher
4787 (lookup_name_without_params
);
4789 /* Build the symbol name component sorted vector, if we haven't
4791 index
.build_name_components ();
4793 auto bounds
= index
.find_name_components_bounds (lookup_name_without_params
);
4795 /* Now for each symbol name in range, check to see if we have a name
4796 match, and if so, call the MATCH_CALLBACK callback. */
4798 /* The same symbol may appear more than once in the range though.
4799 E.g., if we're looking for symbols that complete "w", and we have
4800 a symbol named "w1::w2", we'll find the two name components for
4801 that same symbol in the range. To be sure we only call the
4802 callback once per symbol, we first collect the symbol name
4803 indexes that matched in a temporary vector and ignore
4805 std::vector
<offset_type
> matches
;
4806 matches
.reserve (std::distance (bounds
.first
, bounds
.second
));
4808 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4810 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4812 if (!lookup_name_matcher
.matches (qualified
)
4813 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4816 matches
.push_back (bounds
.first
->idx
);
4819 std::sort (matches
.begin (), matches
.end ());
4821 /* Finally call the callback, once per match. */
4823 for (offset_type idx
: matches
)
4827 match_callback (idx
);
4832 /* Above we use a type wider than idx's for 'prev', since 0 and
4833 (offset_type)-1 are both possible values. */
4834 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4839 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4841 /* A mock .gdb_index/.debug_names-like name index table, enough to
4842 exercise dw2_expand_symtabs_matching_symbol, which works with the
4843 mapped_index_base interface. Builds an index from the symbol list
4844 passed as parameter to the constructor. */
4845 class mock_mapped_index
: public mapped_index_base
4848 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4849 : m_symbol_table (symbols
)
4852 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4854 /* Return the number of names in the symbol table. */
4855 virtual size_t symbol_name_count () const
4857 return m_symbol_table
.size ();
4860 /* Get the name of the symbol at IDX in the symbol table. */
4861 virtual const char *symbol_name_at (offset_type idx
) const
4863 return m_symbol_table
[idx
];
4867 gdb::array_view
<const char *> m_symbol_table
;
4870 /* Convenience function that converts a NULL pointer to a "<null>"
4871 string, to pass to print routines. */
4874 string_or_null (const char *str
)
4876 return str
!= NULL
? str
: "<null>";
4879 /* Check if a lookup_name_info built from
4880 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4881 index. EXPECTED_LIST is the list of expected matches, in expected
4882 matching order. If no match expected, then an empty list is
4883 specified. Returns true on success. On failure prints a warning
4884 indicating the file:line that failed, and returns false. */
4887 check_match (const char *file
, int line
,
4888 mock_mapped_index
&mock_index
,
4889 const char *name
, symbol_name_match_type match_type
,
4890 bool completion_mode
,
4891 std::initializer_list
<const char *> expected_list
)
4893 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4895 bool matched
= true;
4897 auto mismatch
= [&] (const char *expected_str
,
4900 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4901 "expected=\"%s\", got=\"%s\"\n"),
4903 (match_type
== symbol_name_match_type::FULL
4905 name
, string_or_null (expected_str
), string_or_null (got
));
4909 auto expected_it
= expected_list
.begin ();
4910 auto expected_end
= expected_list
.end ();
4912 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4914 [&] (offset_type idx
)
4916 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4917 const char *expected_str
4918 = expected_it
== expected_end
? NULL
: *expected_it
++;
4920 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4921 mismatch (expected_str
, matched_name
);
4924 const char *expected_str
4925 = expected_it
== expected_end
? NULL
: *expected_it
++;
4926 if (expected_str
!= NULL
)
4927 mismatch (expected_str
, NULL
);
4932 /* The symbols added to the mock mapped_index for testing (in
4934 static const char *test_symbols
[] = {
4943 "ns2::tmpl<int>::foo2",
4944 "(anonymous namespace)::A::B::C",
4946 /* These are used to check that the increment-last-char in the
4947 matching algorithm for completion doesn't match "t1_fund" when
4948 completing "t1_func". */
4954 /* A UTF-8 name with multi-byte sequences to make sure that
4955 cp-name-parser understands this as a single identifier ("função"
4956 is "function" in PT). */
4959 /* \377 (0xff) is Latin1 'ÿ'. */
4962 /* \377 (0xff) is Latin1 'ÿ'. */
4966 /* A name with all sorts of complications. Starts with "z" to make
4967 it easier for the completion tests below. */
4968 #define Z_SYM_NAME \
4969 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4970 "::tuple<(anonymous namespace)::ui*, " \
4971 "std::default_delete<(anonymous namespace)::ui>, void>"
4976 /* Returns true if the mapped_index_base::find_name_component_bounds
4977 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4978 in completion mode. */
4981 check_find_bounds_finds (mapped_index_base
&index
,
4982 const char *search_name
,
4983 gdb::array_view
<const char *> expected_syms
)
4985 lookup_name_info
lookup_name (search_name
,
4986 symbol_name_match_type::FULL
, true);
4988 auto bounds
= index
.find_name_components_bounds (lookup_name
);
4990 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4991 if (distance
!= expected_syms
.size ())
4994 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4996 auto nc_elem
= bounds
.first
+ exp_elem
;
4997 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4998 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
5005 /* Test the lower-level mapped_index::find_name_component_bounds
5009 test_mapped_index_find_name_component_bounds ()
5011 mock_mapped_index
mock_index (test_symbols
);
5013 mock_index
.build_name_components ();
5015 /* Test the lower-level mapped_index::find_name_component_bounds
5016 method in completion mode. */
5018 static const char *expected_syms
[] = {
5023 SELF_CHECK (check_find_bounds_finds (mock_index
,
5024 "t1_func", expected_syms
));
5027 /* Check that the increment-last-char in the name matching algorithm
5028 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
5030 static const char *expected_syms1
[] = {
5034 SELF_CHECK (check_find_bounds_finds (mock_index
,
5035 "\377", expected_syms1
));
5037 static const char *expected_syms2
[] = {
5040 SELF_CHECK (check_find_bounds_finds (mock_index
,
5041 "\377\377", expected_syms2
));
5045 /* Test dw2_expand_symtabs_matching_symbol. */
5048 test_dw2_expand_symtabs_matching_symbol ()
5050 mock_mapped_index
mock_index (test_symbols
);
5052 /* We let all tests run until the end even if some fails, for debug
5054 bool any_mismatch
= false;
5056 /* Create the expected symbols list (an initializer_list). Needed
5057 because lists have commas, and we need to pass them to CHECK,
5058 which is a macro. */
5059 #define EXPECT(...) { __VA_ARGS__ }
5061 /* Wrapper for check_match that passes down the current
5062 __FILE__/__LINE__. */
5063 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
5064 any_mismatch |= !check_match (__FILE__, __LINE__, \
5066 NAME, MATCH_TYPE, COMPLETION_MODE, \
5069 /* Identity checks. */
5070 for (const char *sym
: test_symbols
)
5072 /* Should be able to match all existing symbols. */
5073 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
5076 /* Should be able to match all existing symbols with
5078 std::string with_params
= std::string (sym
) + "(int)";
5079 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
5082 /* Should be able to match all existing symbols with
5083 parameters and qualifiers. */
5084 with_params
= std::string (sym
) + " ( int ) const";
5085 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
5088 /* This should really find sym, but cp-name-parser.y doesn't
5089 know about lvalue/rvalue qualifiers yet. */
5090 with_params
= std::string (sym
) + " ( int ) &&";
5091 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
5095 /* Check that the name matching algorithm for completion doesn't get
5096 confused with Latin1 'ÿ' / 0xff. */
5098 static const char str
[] = "\377";
5099 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
5100 EXPECT ("\377", "\377\377123"));
5103 /* Check that the increment-last-char in the matching algorithm for
5104 completion doesn't match "t1_fund" when completing "t1_func". */
5106 static const char str
[] = "t1_func";
5107 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
5108 EXPECT ("t1_func", "t1_func1"));
5111 /* Check that completion mode works at each prefix of the expected
5114 static const char str
[] = "function(int)";
5115 size_t len
= strlen (str
);
5118 for (size_t i
= 1; i
< len
; i
++)
5120 lookup
.assign (str
, i
);
5121 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
5122 EXPECT ("function"));
5126 /* While "w" is a prefix of both components, the match function
5127 should still only be called once. */
5129 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
5131 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
5135 /* Same, with a "complicated" symbol. */
5137 static const char str
[] = Z_SYM_NAME
;
5138 size_t len
= strlen (str
);
5141 for (size_t i
= 1; i
< len
; i
++)
5143 lookup
.assign (str
, i
);
5144 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
5145 EXPECT (Z_SYM_NAME
));
5149 /* In FULL mode, an incomplete symbol doesn't match. */
5151 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
5155 /* A complete symbol with parameters matches any overload, since the
5156 index has no overload info. */
5158 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
5159 EXPECT ("std::zfunction", "std::zfunction2"));
5160 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
5161 EXPECT ("std::zfunction", "std::zfunction2"));
5162 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
5163 EXPECT ("std::zfunction", "std::zfunction2"));
5166 /* Check that whitespace is ignored appropriately. A symbol with a
5167 template argument list. */
5169 static const char expected
[] = "ns::foo<int>";
5170 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
5172 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
5176 /* Check that whitespace is ignored appropriately. A symbol with a
5177 template argument list that includes a pointer. */
5179 static const char expected
[] = "ns::foo<char*>";
5180 /* Try both completion and non-completion modes. */
5181 static const bool completion_mode
[2] = {false, true};
5182 for (size_t i
= 0; i
< 2; i
++)
5184 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
5185 completion_mode
[i
], EXPECT (expected
));
5186 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
5187 completion_mode
[i
], EXPECT (expected
));
5189 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
5190 completion_mode
[i
], EXPECT (expected
));
5191 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
5192 completion_mode
[i
], EXPECT (expected
));
5197 /* Check method qualifiers are ignored. */
5198 static const char expected
[] = "ns::foo<char*>";
5199 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
5200 symbol_name_match_type::FULL
, true, EXPECT (expected
));
5201 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
5202 symbol_name_match_type::FULL
, true, EXPECT (expected
));
5203 CHECK_MATCH ("foo < char * > ( int ) const",
5204 symbol_name_match_type::WILD
, true, EXPECT (expected
));
5205 CHECK_MATCH ("foo < char * > ( int ) &&",
5206 symbol_name_match_type::WILD
, true, EXPECT (expected
));
5209 /* Test lookup names that don't match anything. */
5211 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
5214 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
5218 /* Some wild matching tests, exercising "(anonymous namespace)",
5219 which should not be confused with a parameter list. */
5221 static const char *syms
[] = {
5225 "A :: B :: C ( int )",
5230 for (const char *s
: syms
)
5232 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
5233 EXPECT ("(anonymous namespace)::A::B::C"));
5238 static const char expected
[] = "ns2::tmpl<int>::foo2";
5239 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
5241 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
5245 SELF_CHECK (!any_mismatch
);
5254 test_mapped_index_find_name_component_bounds ();
5255 test_dw2_expand_symtabs_matching_symbol ();
5258 }} // namespace selftests::dw2_expand_symtabs_matching
5260 #endif /* GDB_SELF_TEST */
5262 /* If FILE_MATCHER is NULL or if PER_CU has
5263 dwarf2_per_cu_quick_data::MARK set (see
5264 dw_expand_symtabs_matching_file_matcher), expand the CU and call
5265 EXPANSION_NOTIFY on it. */
5268 dw2_expand_symtabs_matching_one
5269 (struct dwarf2_per_cu_data
*per_cu
,
5270 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5271 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
5273 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
5275 bool symtab_was_null
5276 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
5278 dw2_instantiate_symtab (per_cu
);
5280 if (expansion_notify
!= NULL
5282 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5283 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5287 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5288 matched, to expand corresponding CUs that were marked. IDX is the
5289 index of the symbol name that matched. */
5292 dw2_expand_marked_cus
5293 (mapped_index
&index
, offset_type idx
,
5294 struct objfile
*objfile
,
5295 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5296 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5299 offset_type
*vec
, vec_len
, vec_idx
;
5300 bool global_seen
= false;
5302 vec
= (offset_type
*) (index
.constant_pool
5303 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5304 vec_len
= MAYBE_SWAP (vec
[0]);
5305 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5307 struct dwarf2_per_cu_data
*per_cu
;
5308 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5309 /* This value is only valid for index versions >= 7. */
5310 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5311 gdb_index_symbol_kind symbol_kind
=
5312 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5313 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5314 /* Only check the symbol attributes if they're present.
5315 Indices prior to version 7 don't record them,
5316 and indices >= 7 may elide them for certain symbols
5317 (gold does this). */
5320 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5322 /* Work around gold/15646. */
5325 if (!is_static
&& global_seen
)
5331 /* Only check the symbol's kind if it has one. */
5336 case VARIABLES_DOMAIN
:
5337 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5340 case FUNCTIONS_DOMAIN
:
5341 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5345 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5353 /* Don't crash on bad data. */
5354 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
5355 + dwarf2_per_objfile
->n_type_units
))
5357 complaint (&symfile_complaints
,
5358 _(".gdb_index entry has bad CU index"
5359 " [in module %s]"), objfile_name (objfile
));
5363 per_cu
= dw2_get_cutu (cu_index
);
5364 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5369 /* If FILE_MATCHER is non-NULL, set all the
5370 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5371 that match FILE_MATCHER. */
5374 dw_expand_symtabs_matching_file_matcher
5375 (gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5377 if (file_matcher
== NULL
)
5380 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5382 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5384 NULL
, xcalloc
, xfree
));
5385 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5387 NULL
, xcalloc
, xfree
));
5389 /* The rule is CUs specify all the files, including those used by
5390 any TU, so there's no need to scan TUs here. */
5392 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5395 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5396 struct quick_file_names
*file_data
;
5401 per_cu
->v
.quick
->mark
= 0;
5403 /* We only need to look at symtabs not already expanded. */
5404 if (per_cu
->v
.quick
->compunit_symtab
)
5407 file_data
= dw2_get_file_names (per_cu
);
5408 if (file_data
== NULL
)
5411 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5413 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5415 per_cu
->v
.quick
->mark
= 1;
5419 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
5421 const char *this_real_name
;
5423 if (file_matcher (file_data
->file_names
[j
], false))
5425 per_cu
->v
.quick
->mark
= 1;
5429 /* Before we invoke realpath, which can get expensive when many
5430 files are involved, do a quick comparison of the basenames. */
5431 if (!basenames_may_differ
5432 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5436 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5437 if (file_matcher (this_real_name
, false))
5439 per_cu
->v
.quick
->mark
= 1;
5444 slot
= htab_find_slot (per_cu
->v
.quick
->mark
5445 ? visited_found
.get ()
5446 : visited_not_found
.get (),
5453 dw2_expand_symtabs_matching
5454 (struct objfile
*objfile
,
5455 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5456 const lookup_name_info
&lookup_name
,
5457 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5458 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5459 enum search_domain kind
)
5461 dw2_setup (objfile
);
5463 /* index_table is NULL if OBJF_READNOW. */
5464 if (!dwarf2_per_objfile
->index_table
)
5467 dw_expand_symtabs_matching_file_matcher (file_matcher
);
5469 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5471 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5473 kind
, [&] (offset_type idx
)
5475 dw2_expand_marked_cus (index
, idx
, objfile
, file_matcher
,
5476 expansion_notify
, kind
);
5480 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5483 static struct compunit_symtab
*
5484 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5489 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5490 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5493 if (cust
->includes
== NULL
)
5496 for (i
= 0; cust
->includes
[i
]; ++i
)
5498 struct compunit_symtab
*s
= cust
->includes
[i
];
5500 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5508 static struct compunit_symtab
*
5509 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5510 struct bound_minimal_symbol msymbol
,
5512 struct obj_section
*section
,
5515 struct dwarf2_per_cu_data
*data
;
5516 struct compunit_symtab
*result
;
5518 dw2_setup (objfile
);
5520 if (!objfile
->psymtabs_addrmap
)
5523 data
= (struct dwarf2_per_cu_data
*) addrmap_find (objfile
->psymtabs_addrmap
,
5528 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5529 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5530 paddress (get_objfile_arch (objfile
), pc
));
5533 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
),
5535 gdb_assert (result
!= NULL
);
5540 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5541 void *data
, int need_fullname
)
5543 dw2_setup (objfile
);
5545 if (!dwarf2_per_objfile
->filenames_cache
)
5547 dwarf2_per_objfile
->filenames_cache
.emplace ();
5549 htab_up
visited (htab_create_alloc (10,
5550 htab_hash_pointer
, htab_eq_pointer
,
5551 NULL
, xcalloc
, xfree
));
5553 /* The rule is CUs specify all the files, including those used
5554 by any TU, so there's no need to scan TUs here. We can
5555 ignore file names coming from already-expanded CUs. */
5557 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5559 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
5561 if (per_cu
->v
.quick
->compunit_symtab
)
5563 void **slot
= htab_find_slot (visited
.get (),
5564 per_cu
->v
.quick
->file_names
,
5567 *slot
= per_cu
->v
.quick
->file_names
;
5571 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5573 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5574 struct quick_file_names
*file_data
;
5577 /* We only need to look at symtabs not already expanded. */
5578 if (per_cu
->v
.quick
->compunit_symtab
)
5581 file_data
= dw2_get_file_names (per_cu
);
5582 if (file_data
== NULL
)
5585 slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5588 /* Already visited. */
5593 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5595 const char *filename
= file_data
->file_names
[j
];
5596 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5601 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5603 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5606 this_real_name
= gdb_realpath (filename
);
5607 (*fun
) (filename
, this_real_name
.get (), data
);
5612 dw2_has_symbols (struct objfile
*objfile
)
5617 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5620 dw2_find_last_source_symtab
,
5621 dw2_forget_cached_source_info
,
5622 dw2_map_symtabs_matching_filename
,
5627 dw2_expand_symtabs_for_function
,
5628 dw2_expand_all_symtabs
,
5629 dw2_expand_symtabs_with_fullname
,
5630 dw2_map_matching_symbols
,
5631 dw2_expand_symtabs_matching
,
5632 dw2_find_pc_sect_compunit_symtab
,
5634 dw2_map_symbol_filenames
5637 /* DWARF-5 debug_names reader. */
5639 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5640 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5642 /* A helper function that reads the .debug_names section in SECTION
5643 and fills in MAP. FILENAME is the name of the file containing the
5644 section; it is used for error reporting.
5646 Returns true if all went well, false otherwise. */
5649 read_debug_names_from_section (struct objfile
*objfile
,
5650 const char *filename
,
5651 struct dwarf2_section_info
*section
,
5652 mapped_debug_names
&map
)
5654 if (dwarf2_section_empty_p (section
))
5657 /* Older elfutils strip versions could keep the section in the main
5658 executable while splitting it for the separate debug info file. */
5659 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5662 dwarf2_read_section (objfile
, section
);
5664 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5666 const gdb_byte
*addr
= section
->buffer
;
5668 bfd
*const abfd
= get_section_bfd_owner (section
);
5670 unsigned int bytes_read
;
5671 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5674 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5675 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5676 if (bytes_read
+ length
!= section
->size
)
5678 /* There may be multiple per-CU indices. */
5679 warning (_("Section .debug_names in %s length %s does not match "
5680 "section length %s, ignoring .debug_names."),
5681 filename
, plongest (bytes_read
+ length
),
5682 pulongest (section
->size
));
5686 /* The version number. */
5687 uint16_t version
= read_2_bytes (abfd
, addr
);
5691 warning (_("Section .debug_names in %s has unsupported version %d, "
5692 "ignoring .debug_names."),
5698 uint16_t padding
= read_2_bytes (abfd
, addr
);
5702 warning (_("Section .debug_names in %s has unsupported padding %d, "
5703 "ignoring .debug_names."),
5708 /* comp_unit_count - The number of CUs in the CU list. */
5709 map
.cu_count
= read_4_bytes (abfd
, addr
);
5712 /* local_type_unit_count - The number of TUs in the local TU
5714 map
.tu_count
= read_4_bytes (abfd
, addr
);
5717 /* foreign_type_unit_count - The number of TUs in the foreign TU
5719 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5721 if (foreign_tu_count
!= 0)
5723 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5724 "ignoring .debug_names."),
5725 filename
, static_cast<unsigned long> (foreign_tu_count
));
5729 /* bucket_count - The number of hash buckets in the hash lookup
5731 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5734 /* name_count - The number of unique names in the index. */
5735 map
.name_count
= read_4_bytes (abfd
, addr
);
5738 /* abbrev_table_size - The size in bytes of the abbreviations
5740 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5743 /* augmentation_string_size - The size in bytes of the augmentation
5744 string. This value is rounded up to a multiple of 4. */
5745 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5747 map
.augmentation_is_gdb
= ((augmentation_string_size
5748 == sizeof (dwarf5_augmentation
))
5749 && memcmp (addr
, dwarf5_augmentation
,
5750 sizeof (dwarf5_augmentation
)) == 0);
5751 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5752 addr
+= augmentation_string_size
;
5755 map
.cu_table_reordered
= addr
;
5756 addr
+= map
.cu_count
* map
.offset_size
;
5758 /* List of Local TUs */
5759 map
.tu_table_reordered
= addr
;
5760 addr
+= map
.tu_count
* map
.offset_size
;
5762 /* Hash Lookup Table */
5763 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5764 addr
+= map
.bucket_count
* 4;
5765 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5766 addr
+= map
.name_count
* 4;
5769 map
.name_table_string_offs_reordered
= addr
;
5770 addr
+= map
.name_count
* map
.offset_size
;
5771 map
.name_table_entry_offs_reordered
= addr
;
5772 addr
+= map
.name_count
* map
.offset_size
;
5774 const gdb_byte
*abbrev_table_start
= addr
;
5777 unsigned int bytes_read
;
5778 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5783 const auto insertpair
5784 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5785 if (!insertpair
.second
)
5787 warning (_("Section .debug_names in %s has duplicate index %s, "
5788 "ignoring .debug_names."),
5789 filename
, pulongest (index_num
));
5792 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5793 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5798 mapped_debug_names::index_val::attr attr
;
5799 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5801 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5803 if (attr
.form
== DW_FORM_implicit_const
)
5805 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5809 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5811 indexval
.attr_vec
.push_back (std::move (attr
));
5814 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5816 warning (_("Section .debug_names in %s has abbreviation_table "
5817 "of size %zu vs. written as %u, ignoring .debug_names."),
5818 filename
, addr
- abbrev_table_start
, abbrev_table_size
);
5821 map
.entry_pool
= addr
;
5826 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5830 create_cus_from_debug_names_list (struct objfile
*objfile
,
5831 const mapped_debug_names
&map
,
5832 dwarf2_section_info
§ion
,
5833 bool is_dwz
, int base_offset
)
5835 sect_offset sect_off_prev
;
5836 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5838 sect_offset sect_off_next
;
5839 if (i
< map
.cu_count
)
5842 = (sect_offset
) (extract_unsigned_integer
5843 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5845 map
.dwarf5_byte_order
));
5848 sect_off_next
= (sect_offset
) section
.size
;
5851 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5852 dwarf2_per_objfile
->all_comp_units
[base_offset
+ (i
- 1)]
5853 = create_cu_from_index_list (objfile
, §ion
, is_dwz
,
5854 sect_off_prev
, length
);
5856 sect_off_prev
= sect_off_next
;
5860 /* Read the CU list from the mapped index, and use it to create all
5861 the CU objects for this objfile. */
5864 create_cus_from_debug_names (struct objfile
*objfile
,
5865 const mapped_debug_names
&map
,
5866 const mapped_debug_names
&dwz_map
)
5869 dwarf2_per_objfile
->n_comp_units
= map
.cu_count
+ dwz_map
.cu_count
;
5870 dwarf2_per_objfile
->all_comp_units
5871 = XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
5872 dwarf2_per_objfile
->n_comp_units
);
5874 create_cus_from_debug_names_list (objfile
, map
, dwarf2_per_objfile
->info
,
5876 0 /* base_offset */);
5878 if (dwz_map
.cu_count
== 0)
5881 dwz_file
*dwz
= dwarf2_get_dwz_file ();
5882 create_cus_from_debug_names_list (objfile
, dwz_map
, dwz
->info
,
5884 map
.cu_count
/* base_offset */);
5887 /* Read .debug_names. If everything went ok, initialize the "quick"
5888 elements of all the CUs and return true. Otherwise, return false. */
5891 dwarf2_read_debug_names (struct objfile
*objfile
)
5893 mapped_debug_names local_map
, dwz_map
;
5895 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5896 &dwarf2_per_objfile
->debug_names
,
5900 /* Don't use the index if it's empty. */
5901 if (local_map
.name_count
== 0)
5904 /* If there is a .dwz file, read it so we can get its CU list as
5906 dwz_file
*dwz
= dwarf2_get_dwz_file ();
5909 if (!read_debug_names_from_section (objfile
,
5910 bfd_get_filename (dwz
->dwz_bfd
),
5911 &dwz
->debug_names
, dwz_map
))
5913 warning (_("could not read '.debug_names' section from %s; skipping"),
5914 bfd_get_filename (dwz
->dwz_bfd
));
5919 create_cus_from_debug_names (objfile
, local_map
, dwz_map
);
5921 if (local_map
.tu_count
!= 0)
5923 /* We can only handle a single .debug_types when we have an
5925 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
5928 dwarf2_section_info
*section
= VEC_index (dwarf2_section_info_def
,
5929 dwarf2_per_objfile
->types
, 0);
5931 create_signatured_type_table_from_debug_names
5932 (objfile
, local_map
, section
, &dwarf2_per_objfile
->abbrev
);
5935 create_addrmap_from_aranges (objfile
, &dwarf2_per_objfile
->debug_aranges
);
5937 dwarf2_per_objfile
->debug_names_table
.reset (new mapped_debug_names
);
5938 *dwarf2_per_objfile
->debug_names_table
= std::move (local_map
);
5939 dwarf2_per_objfile
->using_index
= 1;
5940 dwarf2_per_objfile
->quick_file_names_table
=
5941 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
5946 /* Symbol name hashing function as specified by DWARF-5. */
5949 dwarf5_djb_hash (const char *str_
)
5951 const unsigned char *str
= (const unsigned char *) str_
;
5953 /* Note: tolower here ignores UTF-8, which isn't fully compliant.
5954 See http://dwarfstd.org/ShowIssue.php?issue=161027.1. */
5956 uint32_t hash
= 5381;
5957 while (int c
= *str
++)
5958 hash
= hash
* 33 + tolower (c
);
5962 /* Type used to manage iterating over all CUs looking for a symbol for
5965 class dw2_debug_names_iterator
5968 /* If WANT_SPECIFIC_BLOCK is true, only look for symbols in block
5969 BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
5970 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5971 bool want_specific_block
,
5972 block_enum block_index
, domain_enum domain
,
5974 : m_map (map
), m_want_specific_block (want_specific_block
),
5975 m_block_index (block_index
), m_domain (domain
),
5976 m_addr (find_vec_in_debug_names (map
, name
))
5979 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5980 search_domain search
, uint32_t namei
)
5983 m_addr (find_vec_in_debug_names (map
, namei
))
5986 /* Return the next matching CU or NULL if there are no more. */
5987 dwarf2_per_cu_data
*next ();
5990 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5992 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5995 /* The internalized form of .debug_names. */
5996 const mapped_debug_names
&m_map
;
5998 /* If true, only look for symbols that match BLOCK_INDEX. */
5999 const bool m_want_specific_block
= false;
6001 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
6002 Unused if !WANT_SPECIFIC_BLOCK - FIRST_LOCAL_BLOCK is an invalid
6004 const block_enum m_block_index
= FIRST_LOCAL_BLOCK
;
6006 /* The kind of symbol we're looking for. */
6007 const domain_enum m_domain
= UNDEF_DOMAIN
;
6008 const search_domain m_search
= ALL_DOMAIN
;
6010 /* The list of CUs from the index entry of the symbol, or NULL if
6012 const gdb_byte
*m_addr
;
6016 mapped_debug_names::namei_to_name (uint32_t namei
) const
6018 const ULONGEST namei_string_offs
6019 = extract_unsigned_integer ((name_table_string_offs_reordered
6020 + namei
* offset_size
),
6023 return read_indirect_string_at_offset
6024 (dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
6027 /* Find a slot in .debug_names for the object named NAME. If NAME is
6028 found, return pointer to its pool data. If NAME cannot be found,
6032 dw2_debug_names_iterator::find_vec_in_debug_names
6033 (const mapped_debug_names
&map
, const char *name
)
6035 int (*cmp
) (const char *, const char *);
6037 if (current_language
->la_language
== language_cplus
6038 || current_language
->la_language
== language_fortran
6039 || current_language
->la_language
== language_d
)
6041 /* NAME is already canonical. Drop any qualifiers as
6042 .debug_names does not contain any. */
6044 if (strchr (name
, '(') != NULL
)
6046 gdb::unique_xmalloc_ptr
<char> without_params
6047 = cp_remove_params (name
);
6049 if (without_params
!= NULL
)
6051 name
= without_params
.get();
6056 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
6058 const uint32_t full_hash
= dwarf5_djb_hash (name
);
6060 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
6061 (map
.bucket_table_reordered
6062 + (full_hash
% map
.bucket_count
)), 4,
6063 map
.dwarf5_byte_order
);
6067 if (namei
>= map
.name_count
)
6069 complaint (&symfile_complaints
,
6070 _("Wrong .debug_names with name index %u but name_count=%u "
6072 namei
, map
.name_count
,
6073 objfile_name (dwarf2_per_objfile
->objfile
));
6079 const uint32_t namei_full_hash
6080 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
6081 (map
.hash_table_reordered
+ namei
), 4,
6082 map
.dwarf5_byte_order
);
6083 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
6086 if (full_hash
== namei_full_hash
)
6088 const char *const namei_string
= map
.namei_to_name (namei
);
6090 #if 0 /* An expensive sanity check. */
6091 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
6093 complaint (&symfile_complaints
,
6094 _("Wrong .debug_names hash for string at index %u "
6096 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
6101 if (cmp (namei_string
, name
) == 0)
6103 const ULONGEST namei_entry_offs
6104 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
6105 + namei
* map
.offset_size
),
6106 map
.offset_size
, map
.dwarf5_byte_order
);
6107 return map
.entry_pool
+ namei_entry_offs
;
6112 if (namei
>= map
.name_count
)
6118 dw2_debug_names_iterator::find_vec_in_debug_names
6119 (const mapped_debug_names
&map
, uint32_t namei
)
6121 if (namei
>= map
.name_count
)
6123 complaint (&symfile_complaints
,
6124 _("Wrong .debug_names with name index %u but name_count=%u "
6126 namei
, map
.name_count
,
6127 objfile_name (dwarf2_per_objfile
->objfile
));
6131 const ULONGEST namei_entry_offs
6132 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
6133 + namei
* map
.offset_size
),
6134 map
.offset_size
, map
.dwarf5_byte_order
);
6135 return map
.entry_pool
+ namei_entry_offs
;
6138 /* See dw2_debug_names_iterator. */
6140 dwarf2_per_cu_data
*
6141 dw2_debug_names_iterator::next ()
6146 bfd
*const abfd
= dwarf2_per_objfile
->objfile
->obfd
;
6150 unsigned int bytes_read
;
6151 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
6152 m_addr
+= bytes_read
;
6156 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
6157 if (indexval_it
== m_map
.abbrev_map
.cend ())
6159 complaint (&symfile_complaints
,
6160 _("Wrong .debug_names undefined abbrev code %s "
6162 pulongest (abbrev
), objfile_name (dwarf2_per_objfile
->objfile
));
6165 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
6166 bool have_is_static
= false;
6168 dwarf2_per_cu_data
*per_cu
= NULL
;
6169 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
6174 case DW_FORM_implicit_const
:
6175 ull
= attr
.implicit_const
;
6177 case DW_FORM_flag_present
:
6181 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
6182 m_addr
+= bytes_read
;
6185 complaint (&symfile_complaints
,
6186 _("Unsupported .debug_names form %s [in module %s]"),
6187 dwarf_form_name (attr
.form
),
6188 objfile_name (dwarf2_per_objfile
->objfile
));
6191 switch (attr
.dw_idx
)
6193 case DW_IDX_compile_unit
:
6194 /* Don't crash on bad data. */
6195 if (ull
>= (dwarf2_per_objfile
->n_comp_units
6196 + dwarf2_per_objfile
->n_type_units
))
6198 complaint (&symfile_complaints
,
6199 _(".debug_names entry has bad CU index %s"
6202 objfile_name (dwarf2_per_objfile
->objfile
));
6205 per_cu
= dw2_get_cutu (ull
);
6207 case DW_IDX_GNU_internal
:
6208 if (!m_map
.augmentation_is_gdb
)
6210 have_is_static
= true;
6213 case DW_IDX_GNU_external
:
6214 if (!m_map
.augmentation_is_gdb
)
6216 have_is_static
= true;
6222 /* Skip if already read in. */
6223 if (per_cu
->v
.quick
->compunit_symtab
)
6226 /* Check static vs global. */
6229 const bool want_static
= m_block_index
!= GLOBAL_BLOCK
;
6230 if (m_want_specific_block
&& want_static
!= is_static
)
6234 /* Match dw2_symtab_iter_next, symbol_kind
6235 and debug_names::psymbol_tag. */
6239 switch (indexval
.dwarf_tag
)
6241 case DW_TAG_variable
:
6242 case DW_TAG_subprogram
:
6243 /* Some types are also in VAR_DOMAIN. */
6244 case DW_TAG_typedef
:
6245 case DW_TAG_structure_type
:
6252 switch (indexval
.dwarf_tag
)
6254 case DW_TAG_typedef
:
6255 case DW_TAG_structure_type
:
6262 switch (indexval
.dwarf_tag
)
6265 case DW_TAG_variable
:
6275 /* Match dw2_expand_symtabs_matching, symbol_kind and
6276 debug_names::psymbol_tag. */
6279 case VARIABLES_DOMAIN
:
6280 switch (indexval
.dwarf_tag
)
6282 case DW_TAG_variable
:
6288 case FUNCTIONS_DOMAIN
:
6289 switch (indexval
.dwarf_tag
)
6291 case DW_TAG_subprogram
:
6298 switch (indexval
.dwarf_tag
)
6300 case DW_TAG_typedef
:
6301 case DW_TAG_structure_type
:
6314 static struct compunit_symtab
*
6315 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, int block_index_int
,
6316 const char *name
, domain_enum domain
)
6318 const block_enum block_index
= static_cast<block_enum
> (block_index_int
);
6319 dw2_setup (objfile
);
6321 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6324 /* index is NULL if OBJF_READNOW. */
6327 const auto &map
= *mapp
;
6329 dw2_debug_names_iterator
iter (map
, true /* want_specific_block */,
6330 block_index
, domain
, name
);
6332 struct compunit_symtab
*stab_best
= NULL
;
6333 struct dwarf2_per_cu_data
*per_cu
;
6334 while ((per_cu
= iter
.next ()) != NULL
)
6336 struct symbol
*sym
, *with_opaque
= NULL
;
6337 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
6338 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6339 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6341 sym
= block_find_symbol (block
, name
, domain
,
6342 block_find_non_opaque_type_preferred
,
6345 /* Some caution must be observed with overloaded functions and
6346 methods, since the index will not contain any overload
6347 information (but NAME might contain it). */
6350 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
6352 if (with_opaque
!= NULL
6353 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
6356 /* Keep looking through other CUs. */
6362 /* This dumps minimal information about .debug_names. It is called
6363 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6364 uses this to verify that .debug_names has been loaded. */
6367 dw2_debug_names_dump (struct objfile
*objfile
)
6369 dw2_setup (objfile
);
6370 gdb_assert (dwarf2_per_objfile
->using_index
);
6371 printf_filtered (".debug_names:");
6372 if (dwarf2_per_objfile
->debug_names_table
)
6373 printf_filtered (" exists\n");
6375 printf_filtered (" faked for \"readnow\"\n");
6376 printf_filtered ("\n");
6380 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6381 const char *func_name
)
6383 dw2_setup (objfile
);
6385 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6386 if (dwarf2_per_objfile
->debug_names_table
)
6388 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6390 /* Note: It doesn't matter what we pass for block_index here. */
6391 dw2_debug_names_iterator
iter (map
, false /* want_specific_block */,
6392 GLOBAL_BLOCK
, VAR_DOMAIN
, func_name
);
6394 struct dwarf2_per_cu_data
*per_cu
;
6395 while ((per_cu
= iter
.next ()) != NULL
)
6396 dw2_instantiate_symtab (per_cu
);
6401 dw2_debug_names_expand_symtabs_matching
6402 (struct objfile
*objfile
,
6403 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6404 const lookup_name_info
&lookup_name
,
6405 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6406 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6407 enum search_domain kind
)
6409 dw2_setup (objfile
);
6411 /* debug_names_table is NULL if OBJF_READNOW. */
6412 if (!dwarf2_per_objfile
->debug_names_table
)
6415 dw_expand_symtabs_matching_file_matcher (file_matcher
);
6417 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6419 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6421 kind
, [&] (offset_type namei
)
6423 /* The name was matched, now expand corresponding CUs that were
6425 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6427 struct dwarf2_per_cu_data
*per_cu
;
6428 while ((per_cu
= iter
.next ()) != NULL
)
6429 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6434 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6437 dw2_find_last_source_symtab
,
6438 dw2_forget_cached_source_info
,
6439 dw2_map_symtabs_matching_filename
,
6440 dw2_debug_names_lookup_symbol
,
6442 dw2_debug_names_dump
,
6444 dw2_debug_names_expand_symtabs_for_function
,
6445 dw2_expand_all_symtabs
,
6446 dw2_expand_symtabs_with_fullname
,
6447 dw2_map_matching_symbols
,
6448 dw2_debug_names_expand_symtabs_matching
,
6449 dw2_find_pc_sect_compunit_symtab
,
6451 dw2_map_symbol_filenames
6454 /* Initialize for reading DWARF for this objfile. Return 0 if this
6455 file will use psymtabs, or 1 if using the GNU index. */
6458 dwarf2_initialize_objfile (struct objfile
*objfile
)
6460 /* If we're about to read full symbols, don't bother with the
6461 indices. In this case we also don't care if some other debug
6462 format is making psymtabs, because they are all about to be
6464 if ((objfile
->flags
& OBJF_READNOW
))
6468 dwarf2_per_objfile
->using_index
= 1;
6469 create_all_comp_units (objfile
);
6470 create_all_type_units (objfile
);
6471 dwarf2_per_objfile
->quick_file_names_table
=
6472 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
6474 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
6475 + dwarf2_per_objfile
->n_type_units
); ++i
)
6477 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
6479 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6480 struct dwarf2_per_cu_quick_data
);
6483 /* Return 1 so that gdb sees the "quick" functions. However,
6484 these functions will be no-ops because we will have expanded
6486 return elf_sym_fns_gdb_index
;
6489 if (dwarf2_read_debug_names (objfile
))
6490 return elf_sym_fns_debug_names
;
6492 if (dwarf2_read_index (objfile
))
6493 return elf_sym_fns_gdb_index
;
6495 return elf_sym_fns_lazy_psyms
;
6500 /* Build a partial symbol table. */
6503 dwarf2_build_psymtabs (struct objfile
*objfile
)
6506 if (objfile
->global_psymbols
.capacity () == 0
6507 && objfile
->static_psymbols
.capacity () == 0)
6508 init_psymbol_list (objfile
, 1024);
6512 /* This isn't really ideal: all the data we allocate on the
6513 objfile's obstack is still uselessly kept around. However,
6514 freeing it seems unsafe. */
6515 psymtab_discarder
psymtabs (objfile
);
6516 dwarf2_build_psymtabs_hard (objfile
);
6519 CATCH (except
, RETURN_MASK_ERROR
)
6521 exception_print (gdb_stderr
, except
);
6526 /* Return the total length of the CU described by HEADER. */
6529 get_cu_length (const struct comp_unit_head
*header
)
6531 return header
->initial_length_size
+ header
->length
;
6534 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6537 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6539 sect_offset bottom
= cu_header
->sect_off
;
6540 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6542 return sect_off
>= bottom
&& sect_off
< top
;
6545 /* Find the base address of the compilation unit for range lists and
6546 location lists. It will normally be specified by DW_AT_low_pc.
6547 In DWARF-3 draft 4, the base address could be overridden by
6548 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6549 compilation units with discontinuous ranges. */
6552 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6554 struct attribute
*attr
;
6557 cu
->base_address
= 0;
6559 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6562 cu
->base_address
= attr_value_as_address (attr
);
6567 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6570 cu
->base_address
= attr_value_as_address (attr
);
6576 /* Read in the comp unit header information from the debug_info at info_ptr.
6577 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6578 NOTE: This leaves members offset, first_die_offset to be filled in
6581 static const gdb_byte
*
6582 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6583 const gdb_byte
*info_ptr
,
6584 struct dwarf2_section_info
*section
,
6585 rcuh_kind section_kind
)
6588 unsigned int bytes_read
;
6589 const char *filename
= get_section_file_name (section
);
6590 bfd
*abfd
= get_section_bfd_owner (section
);
6592 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6593 cu_header
->initial_length_size
= bytes_read
;
6594 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6595 info_ptr
+= bytes_read
;
6596 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6598 if (cu_header
->version
< 5)
6599 switch (section_kind
)
6601 case rcuh_kind::COMPILE
:
6602 cu_header
->unit_type
= DW_UT_compile
;
6604 case rcuh_kind::TYPE
:
6605 cu_header
->unit_type
= DW_UT_type
;
6608 internal_error (__FILE__
, __LINE__
,
6609 _("read_comp_unit_head: invalid section_kind"));
6613 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6614 (read_1_byte (abfd
, info_ptr
));
6616 switch (cu_header
->unit_type
)
6619 if (section_kind
!= rcuh_kind::COMPILE
)
6620 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6621 "(is DW_UT_compile, should be DW_UT_type) [in module %s]"),
6625 section_kind
= rcuh_kind::TYPE
;
6628 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6629 "(is %d, should be %d or %d) [in module %s]"),
6630 cu_header
->unit_type
, DW_UT_compile
, DW_UT_type
, filename
);
6633 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6636 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6639 info_ptr
+= bytes_read
;
6640 if (cu_header
->version
< 5)
6642 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6645 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6646 if (signed_addr
< 0)
6647 internal_error (__FILE__
, __LINE__
,
6648 _("read_comp_unit_head: dwarf from non elf file"));
6649 cu_header
->signed_addr_p
= signed_addr
;
6651 if (section_kind
== rcuh_kind::TYPE
)
6653 LONGEST type_offset
;
6655 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6658 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6659 info_ptr
+= bytes_read
;
6660 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6661 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6662 error (_("Dwarf Error: Too big type_offset in compilation unit "
6663 "header (is %s) [in module %s]"), plongest (type_offset
),
6670 /* Helper function that returns the proper abbrev section for
6673 static struct dwarf2_section_info
*
6674 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6676 struct dwarf2_section_info
*abbrev
;
6678 if (this_cu
->is_dwz
)
6679 abbrev
= &dwarf2_get_dwz_file ()->abbrev
;
6681 abbrev
= &dwarf2_per_objfile
->abbrev
;
6686 /* Subroutine of read_and_check_comp_unit_head and
6687 read_and_check_type_unit_head to simplify them.
6688 Perform various error checking on the header. */
6691 error_check_comp_unit_head (struct comp_unit_head
*header
,
6692 struct dwarf2_section_info
*section
,
6693 struct dwarf2_section_info
*abbrev_section
)
6695 const char *filename
= get_section_file_name (section
);
6697 if (header
->version
< 2 || header
->version
> 5)
6698 error (_("Dwarf Error: wrong version in compilation unit header "
6699 "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header
->version
,
6702 if (to_underlying (header
->abbrev_sect_off
)
6703 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6704 error (_("Dwarf Error: bad offset (0x%x) in compilation unit header "
6705 "(offset 0x%x + 6) [in module %s]"),
6706 to_underlying (header
->abbrev_sect_off
),
6707 to_underlying (header
->sect_off
),
6710 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6711 avoid potential 32-bit overflow. */
6712 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6714 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6715 "(offset 0x%x + 0) [in module %s]"),
6716 header
->length
, to_underlying (header
->sect_off
),
6720 /* Read in a CU/TU header and perform some basic error checking.
6721 The contents of the header are stored in HEADER.
6722 The result is a pointer to the start of the first DIE. */
6724 static const gdb_byte
*
6725 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
6726 struct dwarf2_section_info
*section
,
6727 struct dwarf2_section_info
*abbrev_section
,
6728 const gdb_byte
*info_ptr
,
6729 rcuh_kind section_kind
)
6731 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6733 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6735 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6737 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6739 error_check_comp_unit_head (header
, section
, abbrev_section
);
6744 /* Fetch the abbreviation table offset from a comp or type unit header. */
6747 read_abbrev_offset (struct dwarf2_section_info
*section
,
6748 sect_offset sect_off
)
6750 bfd
*abfd
= get_section_bfd_owner (section
);
6751 const gdb_byte
*info_ptr
;
6752 unsigned int initial_length_size
, offset_size
;
6755 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6756 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6757 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6758 offset_size
= initial_length_size
== 4 ? 4 : 8;
6759 info_ptr
+= initial_length_size
;
6761 version
= read_2_bytes (abfd
, info_ptr
);
6765 /* Skip unit type and address size. */
6769 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6772 /* Allocate a new partial symtab for file named NAME and mark this new
6773 partial symtab as being an include of PST. */
6776 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6777 struct objfile
*objfile
)
6779 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6781 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6783 /* It shares objfile->objfile_obstack. */
6784 subpst
->dirname
= pst
->dirname
;
6787 subpst
->textlow
= 0;
6788 subpst
->texthigh
= 0;
6790 subpst
->dependencies
6791 = XOBNEW (&objfile
->objfile_obstack
, struct partial_symtab
*);
6792 subpst
->dependencies
[0] = pst
;
6793 subpst
->number_of_dependencies
= 1;
6795 subpst
->globals_offset
= 0;
6796 subpst
->n_global_syms
= 0;
6797 subpst
->statics_offset
= 0;
6798 subpst
->n_static_syms
= 0;
6799 subpst
->compunit_symtab
= NULL
;
6800 subpst
->read_symtab
= pst
->read_symtab
;
6803 /* No private part is necessary for include psymtabs. This property
6804 can be used to differentiate between such include psymtabs and
6805 the regular ones. */
6806 subpst
->read_symtab_private
= NULL
;
6809 /* Read the Line Number Program data and extract the list of files
6810 included by the source file represented by PST. Build an include
6811 partial symtab for each of these included files. */
6814 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6815 struct die_info
*die
,
6816 struct partial_symtab
*pst
)
6819 struct attribute
*attr
;
6821 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6823 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6825 return; /* No linetable, so no includes. */
6827 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
6828 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
, pst
->textlow
, 1);
6832 hash_signatured_type (const void *item
)
6834 const struct signatured_type
*sig_type
6835 = (const struct signatured_type
*) item
;
6837 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6838 return sig_type
->signature
;
6842 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6844 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6845 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6847 return lhs
->signature
== rhs
->signature
;
6850 /* Allocate a hash table for signatured types. */
6853 allocate_signatured_type_table (struct objfile
*objfile
)
6855 return htab_create_alloc_ex (41,
6856 hash_signatured_type
,
6859 &objfile
->objfile_obstack
,
6860 hashtab_obstack_allocate
,
6861 dummy_obstack_deallocate
);
6864 /* A helper function to add a signatured type CU to a table. */
6867 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6869 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6870 struct signatured_type
***datap
= (struct signatured_type
***) datum
;
6878 /* A helper for create_debug_types_hash_table. Read types from SECTION
6879 and fill them into TYPES_HTAB. It will process only type units,
6880 therefore DW_UT_type. */
6883 create_debug_type_hash_table (struct dwo_file
*dwo_file
,
6884 dwarf2_section_info
*section
, htab_t
&types_htab
,
6885 rcuh_kind section_kind
)
6887 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6888 struct dwarf2_section_info
*abbrev_section
;
6890 const gdb_byte
*info_ptr
, *end_ptr
;
6892 abbrev_section
= (dwo_file
!= NULL
6893 ? &dwo_file
->sections
.abbrev
6894 : &dwarf2_per_objfile
->abbrev
);
6896 if (dwarf_read_debug
)
6897 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6898 get_section_name (section
),
6899 get_section_file_name (abbrev_section
));
6901 dwarf2_read_section (objfile
, section
);
6902 info_ptr
= section
->buffer
;
6904 if (info_ptr
== NULL
)
6907 /* We can't set abfd until now because the section may be empty or
6908 not present, in which case the bfd is unknown. */
6909 abfd
= get_section_bfd_owner (section
);
6911 /* We don't use init_cutu_and_read_dies_simple, or some such, here
6912 because we don't need to read any dies: the signature is in the
6915 end_ptr
= info_ptr
+ section
->size
;
6916 while (info_ptr
< end_ptr
)
6918 struct signatured_type
*sig_type
;
6919 struct dwo_unit
*dwo_tu
;
6921 const gdb_byte
*ptr
= info_ptr
;
6922 struct comp_unit_head header
;
6923 unsigned int length
;
6925 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6927 /* Initialize it due to a false compiler warning. */
6928 header
.signature
= -1;
6929 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6931 /* We need to read the type's signature in order to build the hash
6932 table, but we don't need anything else just yet. */
6934 ptr
= read_and_check_comp_unit_head (&header
, section
,
6935 abbrev_section
, ptr
, section_kind
);
6937 length
= get_cu_length (&header
);
6939 /* Skip dummy type units. */
6940 if (ptr
>= info_ptr
+ length
6941 || peek_abbrev_code (abfd
, ptr
) == 0
6942 || header
.unit_type
!= DW_UT_type
)
6948 if (types_htab
== NULL
)
6951 types_htab
= allocate_dwo_unit_table (objfile
);
6953 types_htab
= allocate_signatured_type_table (objfile
);
6959 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6961 dwo_tu
->dwo_file
= dwo_file
;
6962 dwo_tu
->signature
= header
.signature
;
6963 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6964 dwo_tu
->section
= section
;
6965 dwo_tu
->sect_off
= sect_off
;
6966 dwo_tu
->length
= length
;
6970 /* N.B.: type_offset is not usable if this type uses a DWO file.
6971 The real type_offset is in the DWO file. */
6973 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6974 struct signatured_type
);
6975 sig_type
->signature
= header
.signature
;
6976 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6977 sig_type
->per_cu
.objfile
= objfile
;
6978 sig_type
->per_cu
.is_debug_types
= 1;
6979 sig_type
->per_cu
.section
= section
;
6980 sig_type
->per_cu
.sect_off
= sect_off
;
6981 sig_type
->per_cu
.length
= length
;
6984 slot
= htab_find_slot (types_htab
,
6985 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6987 gdb_assert (slot
!= NULL
);
6990 sect_offset dup_sect_off
;
6994 const struct dwo_unit
*dup_tu
6995 = (const struct dwo_unit
*) *slot
;
6997 dup_sect_off
= dup_tu
->sect_off
;
7001 const struct signatured_type
*dup_tu
7002 = (const struct signatured_type
*) *slot
;
7004 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
7007 complaint (&symfile_complaints
,
7008 _("debug type entry at offset 0x%x is duplicate to"
7009 " the entry at offset 0x%x, signature %s"),
7010 to_underlying (sect_off
), to_underlying (dup_sect_off
),
7011 hex_string (header
.signature
));
7013 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
7015 if (dwarf_read_debug
> 1)
7016 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature %s\n",
7017 to_underlying (sect_off
),
7018 hex_string (header
.signature
));
7024 /* Create the hash table of all entries in the .debug_types
7025 (or .debug_types.dwo) section(s).
7026 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
7027 otherwise it is NULL.
7029 The result is a pointer to the hash table or NULL if there are no types.
7031 Note: This function processes DWO files only, not DWP files. */
7034 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
7035 VEC (dwarf2_section_info_def
) *types
,
7039 struct dwarf2_section_info
*section
;
7041 if (VEC_empty (dwarf2_section_info_def
, types
))
7045 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
7047 create_debug_type_hash_table (dwo_file
, section
, types_htab
,
7051 /* Create the hash table of all entries in the .debug_types section,
7052 and initialize all_type_units.
7053 The result is zero if there is an error (e.g. missing .debug_types section),
7054 otherwise non-zero. */
7057 create_all_type_units (struct objfile
*objfile
)
7059 htab_t types_htab
= NULL
;
7060 struct signatured_type
**iter
;
7062 create_debug_type_hash_table (NULL
, &dwarf2_per_objfile
->info
, types_htab
,
7063 rcuh_kind::COMPILE
);
7064 create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
, types_htab
);
7065 if (types_htab
== NULL
)
7067 dwarf2_per_objfile
->signatured_types
= NULL
;
7071 dwarf2_per_objfile
->signatured_types
= types_htab
;
7073 dwarf2_per_objfile
->n_type_units
7074 = dwarf2_per_objfile
->n_allocated_type_units
7075 = htab_elements (types_htab
);
7076 dwarf2_per_objfile
->all_type_units
=
7077 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
7078 iter
= &dwarf2_per_objfile
->all_type_units
[0];
7079 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
7080 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
7081 == dwarf2_per_objfile
->n_type_units
);
7086 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
7087 If SLOT is non-NULL, it is the entry to use in the hash table.
7088 Otherwise we find one. */
7090 static struct signatured_type
*
7091 add_type_unit (ULONGEST sig
, void **slot
)
7093 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7094 int n_type_units
= dwarf2_per_objfile
->n_type_units
;
7095 struct signatured_type
*sig_type
;
7097 gdb_assert (n_type_units
<= dwarf2_per_objfile
->n_allocated_type_units
);
7099 if (n_type_units
> dwarf2_per_objfile
->n_allocated_type_units
)
7101 if (dwarf2_per_objfile
->n_allocated_type_units
== 0)
7102 dwarf2_per_objfile
->n_allocated_type_units
= 1;
7103 dwarf2_per_objfile
->n_allocated_type_units
*= 2;
7104 dwarf2_per_objfile
->all_type_units
7105 = XRESIZEVEC (struct signatured_type
*,
7106 dwarf2_per_objfile
->all_type_units
,
7107 dwarf2_per_objfile
->n_allocated_type_units
);
7108 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
7110 dwarf2_per_objfile
->n_type_units
= n_type_units
;
7112 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7113 struct signatured_type
);
7114 dwarf2_per_objfile
->all_type_units
[n_type_units
- 1] = sig_type
;
7115 sig_type
->signature
= sig
;
7116 sig_type
->per_cu
.is_debug_types
= 1;
7117 if (dwarf2_per_objfile
->using_index
)
7119 sig_type
->per_cu
.v
.quick
=
7120 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7121 struct dwarf2_per_cu_quick_data
);
7126 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7129 gdb_assert (*slot
== NULL
);
7131 /* The rest of sig_type must be filled in by the caller. */
7135 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
7136 Fill in SIG_ENTRY with DWO_ENTRY. */
7139 fill_in_sig_entry_from_dwo_entry (struct objfile
*objfile
,
7140 struct signatured_type
*sig_entry
,
7141 struct dwo_unit
*dwo_entry
)
7143 /* Make sure we're not clobbering something we don't expect to. */
7144 gdb_assert (! sig_entry
->per_cu
.queued
);
7145 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
7146 if (dwarf2_per_objfile
->using_index
)
7148 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
7149 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
7152 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
7153 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
7154 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
7155 gdb_assert (sig_entry
->type_unit_group
== NULL
);
7156 gdb_assert (sig_entry
->dwo_unit
== NULL
);
7158 sig_entry
->per_cu
.section
= dwo_entry
->section
;
7159 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
7160 sig_entry
->per_cu
.length
= dwo_entry
->length
;
7161 sig_entry
->per_cu
.reading_dwo_directly
= 1;
7162 sig_entry
->per_cu
.objfile
= objfile
;
7163 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
7164 sig_entry
->dwo_unit
= dwo_entry
;
7167 /* Subroutine of lookup_signatured_type.
7168 If we haven't read the TU yet, create the signatured_type data structure
7169 for a TU to be read in directly from a DWO file, bypassing the stub.
7170 This is the "Stay in DWO Optimization": When there is no DWP file and we're
7171 using .gdb_index, then when reading a CU we want to stay in the DWO file
7172 containing that CU. Otherwise we could end up reading several other DWO
7173 files (due to comdat folding) to process the transitive closure of all the
7174 mentioned TUs, and that can be slow. The current DWO file will have every
7175 type signature that it needs.
7176 We only do this for .gdb_index because in the psymtab case we already have
7177 to read all the DWOs to build the type unit groups. */
7179 static struct signatured_type
*
7180 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7182 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7183 struct dwo_file
*dwo_file
;
7184 struct dwo_unit find_dwo_entry
, *dwo_entry
;
7185 struct signatured_type find_sig_entry
, *sig_entry
;
7188 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7190 /* If TU skeletons have been removed then we may not have read in any
7192 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7194 dwarf2_per_objfile
->signatured_types
7195 = allocate_signatured_type_table (objfile
);
7198 /* We only ever need to read in one copy of a signatured type.
7199 Use the global signatured_types array to do our own comdat-folding
7200 of types. If this is the first time we're reading this TU, and
7201 the TU has an entry in .gdb_index, replace the recorded data from
7202 .gdb_index with this TU. */
7204 find_sig_entry
.signature
= sig
;
7205 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7206 &find_sig_entry
, INSERT
);
7207 sig_entry
= (struct signatured_type
*) *slot
;
7209 /* We can get here with the TU already read, *or* in the process of being
7210 read. Don't reassign the global entry to point to this DWO if that's
7211 the case. Also note that if the TU is already being read, it may not
7212 have come from a DWO, the program may be a mix of Fission-compiled
7213 code and non-Fission-compiled code. */
7215 /* Have we already tried to read this TU?
7216 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7217 needn't exist in the global table yet). */
7218 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7221 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7222 dwo_unit of the TU itself. */
7223 dwo_file
= cu
->dwo_unit
->dwo_file
;
7225 /* Ok, this is the first time we're reading this TU. */
7226 if (dwo_file
->tus
== NULL
)
7228 find_dwo_entry
.signature
= sig
;
7229 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7230 if (dwo_entry
== NULL
)
7233 /* If the global table doesn't have an entry for this TU, add one. */
7234 if (sig_entry
== NULL
)
7235 sig_entry
= add_type_unit (sig
, slot
);
7237 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
7238 sig_entry
->per_cu
.tu_read
= 1;
7242 /* Subroutine of lookup_signatured_type.
7243 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7244 then try the DWP file. If the TU stub (skeleton) has been removed then
7245 it won't be in .gdb_index. */
7247 static struct signatured_type
*
7248 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7250 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7251 struct dwp_file
*dwp_file
= get_dwp_file ();
7252 struct dwo_unit
*dwo_entry
;
7253 struct signatured_type find_sig_entry
, *sig_entry
;
7256 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7257 gdb_assert (dwp_file
!= NULL
);
7259 /* If TU skeletons have been removed then we may not have read in any
7261 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7263 dwarf2_per_objfile
->signatured_types
7264 = allocate_signatured_type_table (objfile
);
7267 find_sig_entry
.signature
= sig
;
7268 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7269 &find_sig_entry
, INSERT
);
7270 sig_entry
= (struct signatured_type
*) *slot
;
7272 /* Have we already tried to read this TU?
7273 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7274 needn't exist in the global table yet). */
7275 if (sig_entry
!= NULL
)
7278 if (dwp_file
->tus
== NULL
)
7280 dwo_entry
= lookup_dwo_unit_in_dwp (dwp_file
, NULL
,
7281 sig
, 1 /* is_debug_types */);
7282 if (dwo_entry
== NULL
)
7285 sig_entry
= add_type_unit (sig
, slot
);
7286 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
7291 /* Lookup a signature based type for DW_FORM_ref_sig8.
7292 Returns NULL if signature SIG is not present in the table.
7293 It is up to the caller to complain about this. */
7295 static struct signatured_type
*
7296 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7299 && dwarf2_per_objfile
->using_index
)
7301 /* We're in a DWO/DWP file, and we're using .gdb_index.
7302 These cases require special processing. */
7303 if (get_dwp_file () == NULL
)
7304 return lookup_dwo_signatured_type (cu
, sig
);
7306 return lookup_dwp_signatured_type (cu
, sig
);
7310 struct signatured_type find_entry
, *entry
;
7312 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7314 find_entry
.signature
= sig
;
7315 entry
= ((struct signatured_type
*)
7316 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7321 /* Low level DIE reading support. */
7323 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7326 init_cu_die_reader (struct die_reader_specs
*reader
,
7327 struct dwarf2_cu
*cu
,
7328 struct dwarf2_section_info
*section
,
7329 struct dwo_file
*dwo_file
)
7331 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7332 reader
->abfd
= get_section_bfd_owner (section
);
7334 reader
->dwo_file
= dwo_file
;
7335 reader
->die_section
= section
;
7336 reader
->buffer
= section
->buffer
;
7337 reader
->buffer_end
= section
->buffer
+ section
->size
;
7338 reader
->comp_dir
= NULL
;
7341 /* Subroutine of init_cutu_and_read_dies to simplify it.
7342 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7343 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7346 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7347 from it to the DIE in the DWO. If NULL we are skipping the stub.
7348 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7349 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7350 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7351 STUB_COMP_DIR may be non-NULL.
7352 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7353 are filled in with the info of the DIE from the DWO file.
7354 ABBREV_TABLE_PROVIDED is non-zero if the caller of init_cutu_and_read_dies
7355 provided an abbrev table to use.
7356 The result is non-zero if a valid (non-dummy) DIE was found. */
7359 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7360 struct dwo_unit
*dwo_unit
,
7361 int abbrev_table_provided
,
7362 struct die_info
*stub_comp_unit_die
,
7363 const char *stub_comp_dir
,
7364 struct die_reader_specs
*result_reader
,
7365 const gdb_byte
**result_info_ptr
,
7366 struct die_info
**result_comp_unit_die
,
7367 int *result_has_children
)
7369 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7370 struct dwarf2_cu
*cu
= this_cu
->cu
;
7371 struct dwarf2_section_info
*section
;
7373 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7374 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7375 int i
,num_extra_attrs
;
7376 struct dwarf2_section_info
*dwo_abbrev_section
;
7377 struct attribute
*attr
;
7378 struct die_info
*comp_unit_die
;
7380 /* At most one of these may be provided. */
7381 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7383 /* These attributes aren't processed until later:
7384 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7385 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7386 referenced later. However, these attributes are found in the stub
7387 which we won't have later. In order to not impose this complication
7388 on the rest of the code, we read them here and copy them to the
7397 if (stub_comp_unit_die
!= NULL
)
7399 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7401 if (! this_cu
->is_debug_types
)
7402 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7403 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7404 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7405 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7406 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7408 /* There should be a DW_AT_addr_base attribute here (if needed).
7409 We need the value before we can process DW_FORM_GNU_addr_index. */
7411 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
7413 cu
->addr_base
= DW_UNSND (attr
);
7415 /* There should be a DW_AT_ranges_base attribute here (if needed).
7416 We need the value before we can process DW_AT_ranges. */
7417 cu
->ranges_base
= 0;
7418 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
7420 cu
->ranges_base
= DW_UNSND (attr
);
7422 else if (stub_comp_dir
!= NULL
)
7424 /* Reconstruct the comp_dir attribute to simplify the code below. */
7425 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7426 comp_dir
->name
= DW_AT_comp_dir
;
7427 comp_dir
->form
= DW_FORM_string
;
7428 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7429 DW_STRING (comp_dir
) = stub_comp_dir
;
7432 /* Set up for reading the DWO CU/TU. */
7433 cu
->dwo_unit
= dwo_unit
;
7434 section
= dwo_unit
->section
;
7435 dwarf2_read_section (objfile
, section
);
7436 abfd
= get_section_bfd_owner (section
);
7437 begin_info_ptr
= info_ptr
= (section
->buffer
7438 + to_underlying (dwo_unit
->sect_off
));
7439 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7440 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
);
7442 if (this_cu
->is_debug_types
)
7444 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7446 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
7448 info_ptr
, rcuh_kind::TYPE
);
7449 /* This is not an assert because it can be caused by bad debug info. */
7450 if (sig_type
->signature
!= cu
->header
.signature
)
7452 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7453 " TU at offset 0x%x [in module %s]"),
7454 hex_string (sig_type
->signature
),
7455 hex_string (cu
->header
.signature
),
7456 to_underlying (dwo_unit
->sect_off
),
7457 bfd_get_filename (abfd
));
7459 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7460 /* For DWOs coming from DWP files, we don't know the CU length
7461 nor the type's offset in the TU until now. */
7462 dwo_unit
->length
= get_cu_length (&cu
->header
);
7463 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7465 /* Establish the type offset that can be used to lookup the type.
7466 For DWO files, we don't know it until now. */
7467 sig_type
->type_offset_in_section
7468 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7472 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
7474 info_ptr
, rcuh_kind::COMPILE
);
7475 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7476 /* For DWOs coming from DWP files, we don't know the CU length
7478 dwo_unit
->length
= get_cu_length (&cu
->header
);
7481 /* Replace the CU's original abbrev table with the DWO's.
7482 Reminder: We can't read the abbrev table until we've read the header. */
7483 if (abbrev_table_provided
)
7485 /* Don't free the provided abbrev table, the caller of
7486 init_cutu_and_read_dies owns it. */
7487 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
7488 /* Ensure the DWO abbrev table gets freed. */
7489 make_cleanup (dwarf2_free_abbrev_table
, cu
);
7493 dwarf2_free_abbrev_table (cu
);
7494 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
7495 /* Leave any existing abbrev table cleanup as is. */
7498 /* Read in the die, but leave space to copy over the attributes
7499 from the stub. This has the benefit of simplifying the rest of
7500 the code - all the work to maintain the illusion of a single
7501 DW_TAG_{compile,type}_unit DIE is done here. */
7502 num_extra_attrs
= ((stmt_list
!= NULL
)
7506 + (comp_dir
!= NULL
));
7507 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7508 result_has_children
, num_extra_attrs
);
7510 /* Copy over the attributes from the stub to the DIE we just read in. */
7511 comp_unit_die
= *result_comp_unit_die
;
7512 i
= comp_unit_die
->num_attrs
;
7513 if (stmt_list
!= NULL
)
7514 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7516 comp_unit_die
->attrs
[i
++] = *low_pc
;
7517 if (high_pc
!= NULL
)
7518 comp_unit_die
->attrs
[i
++] = *high_pc
;
7520 comp_unit_die
->attrs
[i
++] = *ranges
;
7521 if (comp_dir
!= NULL
)
7522 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7523 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7525 if (dwarf_die_debug
)
7527 fprintf_unfiltered (gdb_stdlog
,
7528 "Read die from %s@0x%x of %s:\n",
7529 get_section_name (section
),
7530 (unsigned) (begin_info_ptr
- section
->buffer
),
7531 bfd_get_filename (abfd
));
7532 dump_die (comp_unit_die
, dwarf_die_debug
);
7535 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7536 TUs by skipping the stub and going directly to the entry in the DWO file.
7537 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7538 to get it via circuitous means. Blech. */
7539 if (comp_dir
!= NULL
)
7540 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7542 /* Skip dummy compilation units. */
7543 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7544 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7547 *result_info_ptr
= info_ptr
;
7551 /* Subroutine of init_cutu_and_read_dies to simplify it.
7552 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7553 Returns NULL if the specified DWO unit cannot be found. */
7555 static struct dwo_unit
*
7556 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7557 struct die_info
*comp_unit_die
)
7559 struct dwarf2_cu
*cu
= this_cu
->cu
;
7561 struct dwo_unit
*dwo_unit
;
7562 const char *comp_dir
, *dwo_name
;
7564 gdb_assert (cu
!= NULL
);
7566 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7567 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7568 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7570 if (this_cu
->is_debug_types
)
7572 struct signatured_type
*sig_type
;
7574 /* Since this_cu is the first member of struct signatured_type,
7575 we can go from a pointer to one to a pointer to the other. */
7576 sig_type
= (struct signatured_type
*) this_cu
;
7577 signature
= sig_type
->signature
;
7578 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7582 struct attribute
*attr
;
7584 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7586 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7588 dwo_name
, objfile_name (this_cu
->objfile
));
7589 signature
= DW_UNSND (attr
);
7590 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7597 /* Subroutine of init_cutu_and_read_dies to simplify it.
7598 See it for a description of the parameters.
7599 Read a TU directly from a DWO file, bypassing the stub.
7601 Note: This function could be a little bit simpler if we shared cleanups
7602 with our caller, init_cutu_and_read_dies. That's generally a fragile thing
7603 to do, so we keep this function self-contained. Or we could move this
7604 into our caller, but it's complex enough already. */
7607 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7608 int use_existing_cu
, int keep
,
7609 die_reader_func_ftype
*die_reader_func
,
7612 struct dwarf2_cu
*cu
;
7613 struct signatured_type
*sig_type
;
7614 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
7615 struct die_reader_specs reader
;
7616 const gdb_byte
*info_ptr
;
7617 struct die_info
*comp_unit_die
;
7620 /* Verify we can do the following downcast, and that we have the
7622 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7623 sig_type
= (struct signatured_type
*) this_cu
;
7624 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7626 cleanups
= make_cleanup (null_cleanup
, NULL
);
7628 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7630 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7632 /* There's no need to do the rereading_dwo_cu handling that
7633 init_cutu_and_read_dies does since we don't read the stub. */
7637 /* If !use_existing_cu, this_cu->cu must be NULL. */
7638 gdb_assert (this_cu
->cu
== NULL
);
7639 cu
= XNEW (struct dwarf2_cu
);
7640 init_one_comp_unit (cu
, this_cu
);
7641 /* If an error occurs while loading, release our storage. */
7642 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
7645 /* A future optimization, if needed, would be to use an existing
7646 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7647 could share abbrev tables. */
7649 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7650 0 /* abbrev_table_provided */,
7651 NULL
/* stub_comp_unit_die */,
7652 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7654 &comp_unit_die
, &has_children
) == 0)
7657 do_cleanups (cleanups
);
7661 /* All the "real" work is done here. */
7662 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7664 /* This duplicates the code in init_cutu_and_read_dies,
7665 but the alternative is making the latter more complex.
7666 This function is only for the special case of using DWO files directly:
7667 no point in overly complicating the general case just to handle this. */
7668 if (free_cu_cleanup
!= NULL
)
7672 /* We've successfully allocated this compilation unit. Let our
7673 caller clean it up when finished with it. */
7674 discard_cleanups (free_cu_cleanup
);
7676 /* We can only discard free_cu_cleanup and all subsequent cleanups.
7677 So we have to manually free the abbrev table. */
7678 dwarf2_free_abbrev_table (cu
);
7680 /* Link this CU into read_in_chain. */
7681 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7682 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7685 do_cleanups (free_cu_cleanup
);
7688 do_cleanups (cleanups
);
7691 /* Initialize a CU (or TU) and read its DIEs.
7692 If the CU defers to a DWO file, read the DWO file as well.
7694 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7695 Otherwise the table specified in the comp unit header is read in and used.
7696 This is an optimization for when we already have the abbrev table.
7698 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7699 Otherwise, a new CU is allocated with xmalloc.
7701 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7702 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7704 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7705 linker) then DIE_READER_FUNC will not get called. */
7708 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7709 struct abbrev_table
*abbrev_table
,
7710 int use_existing_cu
, int keep
,
7711 die_reader_func_ftype
*die_reader_func
,
7714 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7715 struct dwarf2_section_info
*section
= this_cu
->section
;
7716 bfd
*abfd
= get_section_bfd_owner (section
);
7717 struct dwarf2_cu
*cu
;
7718 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7719 struct die_reader_specs reader
;
7720 struct die_info
*comp_unit_die
;
7722 struct attribute
*attr
;
7723 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
7724 struct signatured_type
*sig_type
= NULL
;
7725 struct dwarf2_section_info
*abbrev_section
;
7726 /* Non-zero if CU currently points to a DWO file and we need to
7727 reread it. When this happens we need to reread the skeleton die
7728 before we can reread the DWO file (this only applies to CUs, not TUs). */
7729 int rereading_dwo_cu
= 0;
7731 if (dwarf_die_debug
)
7732 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
7733 this_cu
->is_debug_types
? "type" : "comp",
7734 to_underlying (this_cu
->sect_off
));
7736 if (use_existing_cu
)
7739 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7740 file (instead of going through the stub), short-circuit all of this. */
7741 if (this_cu
->reading_dwo_directly
)
7743 /* Narrow down the scope of possibilities to have to understand. */
7744 gdb_assert (this_cu
->is_debug_types
);
7745 gdb_assert (abbrev_table
== NULL
);
7746 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7747 die_reader_func
, data
);
7751 cleanups
= make_cleanup (null_cleanup
, NULL
);
7753 /* This is cheap if the section is already read in. */
7754 dwarf2_read_section (objfile
, section
);
7756 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7758 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7760 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7763 /* If this CU is from a DWO file we need to start over, we need to
7764 refetch the attributes from the skeleton CU.
7765 This could be optimized by retrieving those attributes from when we
7766 were here the first time: the previous comp_unit_die was stored in
7767 comp_unit_obstack. But there's no data yet that we need this
7769 if (cu
->dwo_unit
!= NULL
)
7770 rereading_dwo_cu
= 1;
7774 /* If !use_existing_cu, this_cu->cu must be NULL. */
7775 gdb_assert (this_cu
->cu
== NULL
);
7776 cu
= XNEW (struct dwarf2_cu
);
7777 init_one_comp_unit (cu
, this_cu
);
7778 /* If an error occurs while loading, release our storage. */
7779 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
7782 /* Get the header. */
7783 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7785 /* We already have the header, there's no need to read it in again. */
7786 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7790 if (this_cu
->is_debug_types
)
7792 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
7793 abbrev_section
, info_ptr
,
7796 /* Since per_cu is the first member of struct signatured_type,
7797 we can go from a pointer to one to a pointer to the other. */
7798 sig_type
= (struct signatured_type
*) this_cu
;
7799 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7800 gdb_assert (sig_type
->type_offset_in_tu
7801 == cu
->header
.type_cu_offset_in_tu
);
7802 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7804 /* LENGTH has not been set yet for type units if we're
7805 using .gdb_index. */
7806 this_cu
->length
= get_cu_length (&cu
->header
);
7808 /* Establish the type offset that can be used to lookup the type. */
7809 sig_type
->type_offset_in_section
=
7810 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7812 this_cu
->dwarf_version
= cu
->header
.version
;
7816 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
7819 rcuh_kind::COMPILE
);
7821 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7822 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7823 this_cu
->dwarf_version
= cu
->header
.version
;
7827 /* Skip dummy compilation units. */
7828 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7829 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7831 do_cleanups (cleanups
);
7835 /* If we don't have them yet, read the abbrevs for this compilation unit.
7836 And if we need to read them now, make sure they're freed when we're
7837 done. Note that it's important that if the CU had an abbrev table
7838 on entry we don't free it when we're done: Somewhere up the call stack
7839 it may be in use. */
7840 if (abbrev_table
!= NULL
)
7842 gdb_assert (cu
->abbrev_table
== NULL
);
7843 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7844 cu
->abbrev_table
= abbrev_table
;
7846 else if (cu
->abbrev_table
== NULL
)
7848 dwarf2_read_abbrevs (cu
, abbrev_section
);
7849 make_cleanup (dwarf2_free_abbrev_table
, cu
);
7851 else if (rereading_dwo_cu
)
7853 dwarf2_free_abbrev_table (cu
);
7854 dwarf2_read_abbrevs (cu
, abbrev_section
);
7857 /* Read the top level CU/TU die. */
7858 init_cu_die_reader (&reader
, cu
, section
, NULL
);
7859 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7861 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7863 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7864 DWO CU, that this test will fail (the attribute will not be present). */
7865 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7868 struct dwo_unit
*dwo_unit
;
7869 struct die_info
*dwo_comp_unit_die
;
7873 complaint (&symfile_complaints
,
7874 _("compilation unit with DW_AT_GNU_dwo_name"
7875 " has children (offset 0x%x) [in module %s]"),
7876 to_underlying (this_cu
->sect_off
), bfd_get_filename (abfd
));
7878 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
7879 if (dwo_unit
!= NULL
)
7881 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7882 abbrev_table
!= NULL
,
7883 comp_unit_die
, NULL
,
7885 &dwo_comp_unit_die
, &has_children
) == 0)
7888 do_cleanups (cleanups
);
7891 comp_unit_die
= dwo_comp_unit_die
;
7895 /* Yikes, we couldn't find the rest of the DIE, we only have
7896 the stub. A complaint has already been logged. There's
7897 not much more we can do except pass on the stub DIE to
7898 die_reader_func. We don't want to throw an error on bad
7903 /* All of the above is setup for this call. Yikes. */
7904 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7906 /* Done, clean up. */
7907 if (free_cu_cleanup
!= NULL
)
7911 /* We've successfully allocated this compilation unit. Let our
7912 caller clean it up when finished with it. */
7913 discard_cleanups (free_cu_cleanup
);
7915 /* We can only discard free_cu_cleanup and all subsequent cleanups.
7916 So we have to manually free the abbrev table. */
7917 dwarf2_free_abbrev_table (cu
);
7919 /* Link this CU into read_in_chain. */
7920 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7921 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7924 do_cleanups (free_cu_cleanup
);
7927 do_cleanups (cleanups
);
7930 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
7931 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
7932 to have already done the lookup to find the DWO file).
7934 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7935 THIS_CU->is_debug_types, but nothing else.
7937 We fill in THIS_CU->length.
7939 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7940 linker) then DIE_READER_FUNC will not get called.
7942 THIS_CU->cu is always freed when done.
7943 This is done in order to not leave THIS_CU->cu in a state where we have
7944 to care whether it refers to the "main" CU or the DWO CU. */
7947 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
7948 struct dwo_file
*dwo_file
,
7949 die_reader_func_ftype
*die_reader_func
,
7952 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7953 struct dwarf2_section_info
*section
= this_cu
->section
;
7954 bfd
*abfd
= get_section_bfd_owner (section
);
7955 struct dwarf2_section_info
*abbrev_section
;
7956 struct dwarf2_cu cu
;
7957 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7958 struct die_reader_specs reader
;
7959 struct cleanup
*cleanups
;
7960 struct die_info
*comp_unit_die
;
7963 if (dwarf_die_debug
)
7964 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
7965 this_cu
->is_debug_types
? "type" : "comp",
7966 to_underlying (this_cu
->sect_off
));
7968 gdb_assert (this_cu
->cu
== NULL
);
7970 abbrev_section
= (dwo_file
!= NULL
7971 ? &dwo_file
->sections
.abbrev
7972 : get_abbrev_section_for_cu (this_cu
));
7974 /* This is cheap if the section is already read in. */
7975 dwarf2_read_section (objfile
, section
);
7977 init_one_comp_unit (&cu
, this_cu
);
7979 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
7981 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7982 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
7983 abbrev_section
, info_ptr
,
7984 (this_cu
->is_debug_types
7986 : rcuh_kind::COMPILE
));
7988 this_cu
->length
= get_cu_length (&cu
.header
);
7990 /* Skip dummy compilation units. */
7991 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7992 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7994 do_cleanups (cleanups
);
7998 dwarf2_read_abbrevs (&cu
, abbrev_section
);
7999 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
8001 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
8002 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
8004 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
8006 do_cleanups (cleanups
);
8009 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
8010 does not lookup the specified DWO file.
8011 This cannot be used to read DWO files.
8013 THIS_CU->cu is always freed when done.
8014 This is done in order to not leave THIS_CU->cu in a state where we have
8015 to care whether it refers to the "main" CU or the DWO CU.
8016 We can revisit this if the data shows there's a performance issue. */
8019 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
8020 die_reader_func_ftype
*die_reader_func
,
8023 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
8026 /* Type Unit Groups.
8028 Type Unit Groups are a way to collapse the set of all TUs (type units) into
8029 a more manageable set. The grouping is done by DW_AT_stmt_list entry
8030 so that all types coming from the same compilation (.o file) are grouped
8031 together. A future step could be to put the types in the same symtab as
8032 the CU the types ultimately came from. */
8035 hash_type_unit_group (const void *item
)
8037 const struct type_unit_group
*tu_group
8038 = (const struct type_unit_group
*) item
;
8040 return hash_stmt_list_entry (&tu_group
->hash
);
8044 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
8046 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
8047 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
8049 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
8052 /* Allocate a hash table for type unit groups. */
8055 allocate_type_unit_groups_table (void)
8057 return htab_create_alloc_ex (3,
8058 hash_type_unit_group
,
8061 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
8062 hashtab_obstack_allocate
,
8063 dummy_obstack_deallocate
);
8066 /* Type units that don't have DW_AT_stmt_list are grouped into their own
8067 partial symtabs. We combine several TUs per psymtab to not let the size
8068 of any one psymtab grow too big. */
8069 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
8070 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
8072 /* Helper routine for get_type_unit_group.
8073 Create the type_unit_group object used to hold one or more TUs. */
8075 static struct type_unit_group
*
8076 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
8078 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8079 struct dwarf2_per_cu_data
*per_cu
;
8080 struct type_unit_group
*tu_group
;
8082 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8083 struct type_unit_group
);
8084 per_cu
= &tu_group
->per_cu
;
8085 per_cu
->objfile
= objfile
;
8087 if (dwarf2_per_objfile
->using_index
)
8089 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8090 struct dwarf2_per_cu_quick_data
);
8094 unsigned int line_offset
= to_underlying (line_offset_struct
);
8095 struct partial_symtab
*pst
;
8098 /* Give the symtab a useful name for debug purposes. */
8099 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
8100 name
= xstrprintf ("<type_units_%d>",
8101 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
8103 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
8105 pst
= create_partial_symtab (per_cu
, name
);
8111 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
8112 tu_group
->hash
.line_sect_off
= line_offset_struct
;
8117 /* Look up the type_unit_group for type unit CU, and create it if necessary.
8118 STMT_LIST is a DW_AT_stmt_list attribute. */
8120 static struct type_unit_group
*
8121 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
8123 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8124 struct type_unit_group
*tu_group
;
8126 unsigned int line_offset
;
8127 struct type_unit_group type_unit_group_for_lookup
;
8129 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
8131 dwarf2_per_objfile
->type_unit_groups
=
8132 allocate_type_unit_groups_table ();
8135 /* Do we need to create a new group, or can we use an existing one? */
8139 line_offset
= DW_UNSND (stmt_list
);
8140 ++tu_stats
->nr_symtab_sharers
;
8144 /* Ugh, no stmt_list. Rare, but we have to handle it.
8145 We can do various things here like create one group per TU or
8146 spread them over multiple groups to split up the expansion work.
8147 To avoid worst case scenarios (too many groups or too large groups)
8148 we, umm, group them in bunches. */
8149 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
8150 | (tu_stats
->nr_stmt_less_type_units
8151 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
8152 ++tu_stats
->nr_stmt_less_type_units
;
8155 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
8156 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
8157 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
8158 &type_unit_group_for_lookup
, INSERT
);
8161 tu_group
= (struct type_unit_group
*) *slot
;
8162 gdb_assert (tu_group
!= NULL
);
8166 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
8167 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
8169 ++tu_stats
->nr_symtabs
;
8175 /* Partial symbol tables. */
8177 /* Create a psymtab named NAME and assign it to PER_CU.
8179 The caller must fill in the following details:
8180 dirname, textlow, texthigh. */
8182 static struct partial_symtab
*
8183 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
8185 struct objfile
*objfile
= per_cu
->objfile
;
8186 struct partial_symtab
*pst
;
8188 pst
= start_psymtab_common (objfile
, name
, 0,
8189 objfile
->global_psymbols
,
8190 objfile
->static_psymbols
);
8192 pst
->psymtabs_addrmap_supported
= 1;
8194 /* This is the glue that links PST into GDB's symbol API. */
8195 pst
->read_symtab_private
= per_cu
;
8196 pst
->read_symtab
= dwarf2_read_symtab
;
8197 per_cu
->v
.psymtab
= pst
;
8202 /* The DATA object passed to process_psymtab_comp_unit_reader has this
8205 struct process_psymtab_comp_unit_data
8207 /* True if we are reading a DW_TAG_partial_unit. */
8209 int want_partial_unit
;
8211 /* The "pretend" language that is used if the CU doesn't declare a
8214 enum language pretend_language
;
8217 /* die_reader_func for process_psymtab_comp_unit. */
8220 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
8221 const gdb_byte
*info_ptr
,
8222 struct die_info
*comp_unit_die
,
8226 struct dwarf2_cu
*cu
= reader
->cu
;
8227 struct objfile
*objfile
= cu
->objfile
;
8228 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8229 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8231 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
8232 struct partial_symtab
*pst
;
8233 enum pc_bounds_kind cu_bounds_kind
;
8234 const char *filename
;
8235 struct process_psymtab_comp_unit_data
*info
8236 = (struct process_psymtab_comp_unit_data
*) data
;
8238 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
8241 gdb_assert (! per_cu
->is_debug_types
);
8243 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
8245 cu
->list_in_scope
= &file_symbols
;
8247 /* Allocate a new partial symbol table structure. */
8248 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
8249 if (filename
== NULL
)
8252 pst
= create_partial_symtab (per_cu
, filename
);
8254 /* This must be done before calling dwarf2_build_include_psymtabs. */
8255 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8257 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8259 dwarf2_find_base_address (comp_unit_die
, cu
);
8261 /* Possibly set the default values of LOWPC and HIGHPC from
8263 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8264 &best_highpc
, cu
, pst
);
8265 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8266 /* Store the contiguous range if it is not empty; it can be empty for
8267 CUs with no code. */
8268 addrmap_set_empty (objfile
->psymtabs_addrmap
,
8269 gdbarch_adjust_dwarf2_addr (gdbarch
,
8270 best_lowpc
+ baseaddr
),
8271 gdbarch_adjust_dwarf2_addr (gdbarch
,
8272 best_highpc
+ baseaddr
) - 1,
8275 /* Check if comp unit has_children.
8276 If so, read the rest of the partial symbols from this comp unit.
8277 If not, there's no more debug_info for this comp unit. */
8280 struct partial_die_info
*first_die
;
8281 CORE_ADDR lowpc
, highpc
;
8283 lowpc
= ((CORE_ADDR
) -1);
8284 highpc
= ((CORE_ADDR
) 0);
8286 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8288 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8289 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8291 /* If we didn't find a lowpc, set it to highpc to avoid
8292 complaints from `maint check'. */
8293 if (lowpc
== ((CORE_ADDR
) -1))
8296 /* If the compilation unit didn't have an explicit address range,
8297 then use the information extracted from its child dies. */
8298 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8301 best_highpc
= highpc
;
8304 pst
->textlow
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
);
8305 pst
->texthigh
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
);
8307 end_psymtab_common (objfile
, pst
);
8309 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
8312 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8313 struct dwarf2_per_cu_data
*iter
;
8315 /* Fill in 'dependencies' here; we fill in 'users' in a
8317 pst
->number_of_dependencies
= len
;
8319 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8321 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8324 pst
->dependencies
[i
] = iter
->v
.psymtab
;
8326 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8329 /* Get the list of files included in the current compilation unit,
8330 and build a psymtab for each of them. */
8331 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8333 if (dwarf_read_debug
)
8335 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8337 fprintf_unfiltered (gdb_stdlog
,
8338 "Psymtab for %s unit @0x%x: %s - %s"
8339 ", %d global, %d static syms\n",
8340 per_cu
->is_debug_types
? "type" : "comp",
8341 to_underlying (per_cu
->sect_off
),
8342 paddress (gdbarch
, pst
->textlow
),
8343 paddress (gdbarch
, pst
->texthigh
),
8344 pst
->n_global_syms
, pst
->n_static_syms
);
8348 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8349 Process compilation unit THIS_CU for a psymtab. */
8352 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8353 int want_partial_unit
,
8354 enum language pretend_language
)
8356 /* If this compilation unit was already read in, free the
8357 cached copy in order to read it in again. This is
8358 necessary because we skipped some symbols when we first
8359 read in the compilation unit (see load_partial_dies).
8360 This problem could be avoided, but the benefit is unclear. */
8361 if (this_cu
->cu
!= NULL
)
8362 free_one_cached_comp_unit (this_cu
);
8364 if (this_cu
->is_debug_types
)
8365 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, build_type_psymtabs_reader
,
8369 process_psymtab_comp_unit_data info
;
8370 info
.want_partial_unit
= want_partial_unit
;
8371 info
.pretend_language
= pretend_language
;
8372 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
8373 process_psymtab_comp_unit_reader
, &info
);
8376 /* Age out any secondary CUs. */
8377 age_cached_comp_units ();
8380 /* Reader function for build_type_psymtabs. */
8383 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8384 const gdb_byte
*info_ptr
,
8385 struct die_info
*type_unit_die
,
8389 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8390 struct dwarf2_cu
*cu
= reader
->cu
;
8391 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8392 struct signatured_type
*sig_type
;
8393 struct type_unit_group
*tu_group
;
8394 struct attribute
*attr
;
8395 struct partial_die_info
*first_die
;
8396 CORE_ADDR lowpc
, highpc
;
8397 struct partial_symtab
*pst
;
8399 gdb_assert (data
== NULL
);
8400 gdb_assert (per_cu
->is_debug_types
);
8401 sig_type
= (struct signatured_type
*) per_cu
;
8406 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8407 tu_group
= get_type_unit_group (cu
, attr
);
8409 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
8411 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8412 cu
->list_in_scope
= &file_symbols
;
8413 pst
= create_partial_symtab (per_cu
, "");
8416 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8418 lowpc
= (CORE_ADDR
) -1;
8419 highpc
= (CORE_ADDR
) 0;
8420 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8422 end_psymtab_common (objfile
, pst
);
8425 /* Struct used to sort TUs by their abbreviation table offset. */
8427 struct tu_abbrev_offset
8429 struct signatured_type
*sig_type
;
8430 sect_offset abbrev_offset
;
8433 /* Helper routine for build_type_psymtabs_1, passed to qsort. */
8436 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
8438 const struct tu_abbrev_offset
* const *a
8439 = (const struct tu_abbrev_offset
* const*) ap
;
8440 const struct tu_abbrev_offset
* const *b
8441 = (const struct tu_abbrev_offset
* const*) bp
;
8442 sect_offset aoff
= (*a
)->abbrev_offset
;
8443 sect_offset boff
= (*b
)->abbrev_offset
;
8445 return (aoff
> boff
) - (aoff
< boff
);
8448 /* Efficiently read all the type units.
8449 This does the bulk of the work for build_type_psymtabs.
8451 The efficiency is because we sort TUs by the abbrev table they use and
8452 only read each abbrev table once. In one program there are 200K TUs
8453 sharing 8K abbrev tables.
8455 The main purpose of this function is to support building the
8456 dwarf2_per_objfile->type_unit_groups table.
8457 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8458 can collapse the search space by grouping them by stmt_list.
8459 The savings can be significant, in the same program from above the 200K TUs
8460 share 8K stmt_list tables.
8462 FUNC is expected to call get_type_unit_group, which will create the
8463 struct type_unit_group if necessary and add it to
8464 dwarf2_per_objfile->type_unit_groups. */
8467 build_type_psymtabs_1 (void)
8469 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8470 struct cleanup
*cleanups
;
8471 struct abbrev_table
*abbrev_table
;
8472 sect_offset abbrev_offset
;
8473 struct tu_abbrev_offset
*sorted_by_abbrev
;
8476 /* It's up to the caller to not call us multiple times. */
8477 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8479 if (dwarf2_per_objfile
->n_type_units
== 0)
8482 /* TUs typically share abbrev tables, and there can be way more TUs than
8483 abbrev tables. Sort by abbrev table to reduce the number of times we
8484 read each abbrev table in.
8485 Alternatives are to punt or to maintain a cache of abbrev tables.
8486 This is simpler and efficient enough for now.
8488 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8489 symtab to use). Typically TUs with the same abbrev offset have the same
8490 stmt_list value too so in practice this should work well.
8492 The basic algorithm here is:
8494 sort TUs by abbrev table
8495 for each TU with same abbrev table:
8496 read abbrev table if first user
8497 read TU top level DIE
8498 [IWBN if DWO skeletons had DW_AT_stmt_list]
8501 if (dwarf_read_debug
)
8502 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8504 /* Sort in a separate table to maintain the order of all_type_units
8505 for .gdb_index: TU indices directly index all_type_units. */
8506 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
8507 dwarf2_per_objfile
->n_type_units
);
8508 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
8510 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
8512 sorted_by_abbrev
[i
].sig_type
= sig_type
;
8513 sorted_by_abbrev
[i
].abbrev_offset
=
8514 read_abbrev_offset (sig_type
->per_cu
.section
,
8515 sig_type
->per_cu
.sect_off
);
8517 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
8518 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
8519 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
8521 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8522 abbrev_table
= NULL
;
8523 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
8525 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
8527 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
8529 /* Switch to the next abbrev table if necessary. */
8530 if (abbrev_table
== NULL
8531 || tu
->abbrev_offset
!= abbrev_offset
)
8533 if (abbrev_table
!= NULL
)
8535 abbrev_table_free (abbrev_table
);
8536 /* Reset to NULL in case abbrev_table_read_table throws
8537 an error: abbrev_table_free_cleanup will get called. */
8538 abbrev_table
= NULL
;
8540 abbrev_offset
= tu
->abbrev_offset
;
8542 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
8544 ++tu_stats
->nr_uniq_abbrev_tables
;
8547 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
8548 build_type_psymtabs_reader
, NULL
);
8551 do_cleanups (cleanups
);
8554 /* Print collected type unit statistics. */
8557 print_tu_stats (void)
8559 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8561 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8562 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
8563 dwarf2_per_objfile
->n_type_units
);
8564 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8565 tu_stats
->nr_uniq_abbrev_tables
);
8566 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8567 tu_stats
->nr_symtabs
);
8568 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8569 tu_stats
->nr_symtab_sharers
);
8570 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8571 tu_stats
->nr_stmt_less_type_units
);
8572 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8573 tu_stats
->nr_all_type_units_reallocs
);
8576 /* Traversal function for build_type_psymtabs. */
8579 build_type_psymtab_dependencies (void **slot
, void *info
)
8581 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8582 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8583 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8584 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8585 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
8586 struct signatured_type
*iter
;
8589 gdb_assert (len
> 0);
8590 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8592 pst
->number_of_dependencies
= len
;
8594 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8596 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
8599 gdb_assert (iter
->per_cu
.is_debug_types
);
8600 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8601 iter
->type_unit_group
= tu_group
;
8604 VEC_free (sig_type_ptr
, tu_group
->tus
);
8609 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8610 Build partial symbol tables for the .debug_types comp-units. */
8613 build_type_psymtabs (struct objfile
*objfile
)
8615 if (! create_all_type_units (objfile
))
8618 build_type_psymtabs_1 ();
8621 /* Traversal function for process_skeletonless_type_unit.
8622 Read a TU in a DWO file and build partial symbols for it. */
8625 process_skeletonless_type_unit (void **slot
, void *info
)
8627 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8628 struct objfile
*objfile
= (struct objfile
*) info
;
8629 struct signatured_type find_entry
, *entry
;
8631 /* If this TU doesn't exist in the global table, add it and read it in. */
8633 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8635 dwarf2_per_objfile
->signatured_types
8636 = allocate_signatured_type_table (objfile
);
8639 find_entry
.signature
= dwo_unit
->signature
;
8640 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8642 /* If we've already seen this type there's nothing to do. What's happening
8643 is we're doing our own version of comdat-folding here. */
8647 /* This does the job that create_all_type_units would have done for
8649 entry
= add_type_unit (dwo_unit
->signature
, slot
);
8650 fill_in_sig_entry_from_dwo_entry (objfile
, entry
, dwo_unit
);
8653 /* This does the job that build_type_psymtabs_1 would have done. */
8654 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0,
8655 build_type_psymtabs_reader
, NULL
);
8660 /* Traversal function for process_skeletonless_type_units. */
8663 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8665 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8667 if (dwo_file
->tus
!= NULL
)
8669 htab_traverse_noresize (dwo_file
->tus
,
8670 process_skeletonless_type_unit
, info
);
8676 /* Scan all TUs of DWO files, verifying we've processed them.
8677 This is needed in case a TU was emitted without its skeleton.
8678 Note: This can't be done until we know what all the DWO files are. */
8681 process_skeletonless_type_units (struct objfile
*objfile
)
8683 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8684 if (get_dwp_file () == NULL
8685 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8687 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
8688 process_dwo_file_for_skeletonless_type_units
,
8693 /* Compute the 'user' field for each psymtab in OBJFILE. */
8696 set_partial_user (struct objfile
*objfile
)
8700 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
8702 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
8703 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8709 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8711 /* Set the 'user' field only if it is not already set. */
8712 if (pst
->dependencies
[j
]->user
== NULL
)
8713 pst
->dependencies
[j
]->user
= pst
;
8718 /* Build the partial symbol table by doing a quick pass through the
8719 .debug_info and .debug_abbrev sections. */
8722 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
8724 struct cleanup
*back_to
;
8727 if (dwarf_read_debug
)
8729 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8730 objfile_name (objfile
));
8733 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8735 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8737 /* Any cached compilation units will be linked by the per-objfile
8738 read_in_chain. Make sure to free them when we're done. */
8739 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
8741 build_type_psymtabs (objfile
);
8743 create_all_comp_units (objfile
);
8745 /* Create a temporary address map on a temporary obstack. We later
8746 copy this to the final obstack. */
8747 auto_obstack temp_obstack
;
8749 scoped_restore save_psymtabs_addrmap
8750 = make_scoped_restore (&objfile
->psymtabs_addrmap
,
8751 addrmap_create_mutable (&temp_obstack
));
8753 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
8755 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
8757 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8760 /* This has to wait until we read the CUs, we need the list of DWOs. */
8761 process_skeletonless_type_units (objfile
);
8763 /* Now that all TUs have been processed we can fill in the dependencies. */
8764 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8766 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8767 build_type_psymtab_dependencies
, NULL
);
8770 if (dwarf_read_debug
)
8773 set_partial_user (objfile
);
8775 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
8776 &objfile
->objfile_obstack
);
8777 /* At this point we want to keep the address map. */
8778 save_psymtabs_addrmap
.release ();
8780 do_cleanups (back_to
);
8782 if (dwarf_read_debug
)
8783 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8784 objfile_name (objfile
));
8787 /* die_reader_func for load_partial_comp_unit. */
8790 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8791 const gdb_byte
*info_ptr
,
8792 struct die_info
*comp_unit_die
,
8796 struct dwarf2_cu
*cu
= reader
->cu
;
8798 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8800 /* Check if comp unit has_children.
8801 If so, read the rest of the partial symbols from this comp unit.
8802 If not, there's no more debug_info for this comp unit. */
8804 load_partial_dies (reader
, info_ptr
, 0);
8807 /* Load the partial DIEs for a secondary CU into memory.
8808 This is also used when rereading a primary CU with load_all_dies. */
8811 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8813 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
8814 load_partial_comp_unit_reader
, NULL
);
8818 read_comp_units_from_section (struct objfile
*objfile
,
8819 struct dwarf2_section_info
*section
,
8820 struct dwarf2_section_info
*abbrev_section
,
8821 unsigned int is_dwz
,
8824 struct dwarf2_per_cu_data
***all_comp_units
)
8826 const gdb_byte
*info_ptr
;
8828 if (dwarf_read_debug
)
8829 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8830 get_section_name (section
),
8831 get_section_file_name (section
));
8833 dwarf2_read_section (objfile
, section
);
8835 info_ptr
= section
->buffer
;
8837 while (info_ptr
< section
->buffer
+ section
->size
)
8839 struct dwarf2_per_cu_data
*this_cu
;
8841 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8843 comp_unit_head cu_header
;
8844 read_and_check_comp_unit_head (&cu_header
, section
, abbrev_section
,
8845 info_ptr
, rcuh_kind::COMPILE
);
8847 /* Save the compilation unit for later lookup. */
8848 if (cu_header
.unit_type
!= DW_UT_type
)
8850 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8851 struct dwarf2_per_cu_data
);
8852 memset (this_cu
, 0, sizeof (*this_cu
));
8856 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8857 struct signatured_type
);
8858 memset (sig_type
, 0, sizeof (*sig_type
));
8859 sig_type
->signature
= cu_header
.signature
;
8860 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8861 this_cu
= &sig_type
->per_cu
;
8863 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8864 this_cu
->sect_off
= sect_off
;
8865 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8866 this_cu
->is_dwz
= is_dwz
;
8867 this_cu
->objfile
= objfile
;
8868 this_cu
->section
= section
;
8870 if (*n_comp_units
== *n_allocated
)
8873 *all_comp_units
= XRESIZEVEC (struct dwarf2_per_cu_data
*,
8874 *all_comp_units
, *n_allocated
);
8876 (*all_comp_units
)[*n_comp_units
] = this_cu
;
8879 info_ptr
= info_ptr
+ this_cu
->length
;
8883 /* Create a list of all compilation units in OBJFILE.
8884 This is only done for -readnow and building partial symtabs. */
8887 create_all_comp_units (struct objfile
*objfile
)
8891 struct dwarf2_per_cu_data
**all_comp_units
;
8892 struct dwz_file
*dwz
;
8896 all_comp_units
= XNEWVEC (struct dwarf2_per_cu_data
*, n_allocated
);
8898 read_comp_units_from_section (objfile
, &dwarf2_per_objfile
->info
,
8899 &dwarf2_per_objfile
->abbrev
, 0,
8900 &n_allocated
, &n_comp_units
, &all_comp_units
);
8902 dwz
= dwarf2_get_dwz_file ();
8904 read_comp_units_from_section (objfile
, &dwz
->info
, &dwz
->abbrev
, 1,
8905 &n_allocated
, &n_comp_units
,
8908 dwarf2_per_objfile
->all_comp_units
= XOBNEWVEC (&objfile
->objfile_obstack
,
8909 struct dwarf2_per_cu_data
*,
8911 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
8912 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
8913 xfree (all_comp_units
);
8914 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
8917 /* Process all loaded DIEs for compilation unit CU, starting at
8918 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8919 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8920 DW_AT_ranges). See the comments of add_partial_subprogram on how
8921 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8924 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8925 CORE_ADDR
*highpc
, int set_addrmap
,
8926 struct dwarf2_cu
*cu
)
8928 struct partial_die_info
*pdi
;
8930 /* Now, march along the PDI's, descending into ones which have
8931 interesting children but skipping the children of the other ones,
8932 until we reach the end of the compilation unit. */
8938 fixup_partial_die (pdi
, cu
);
8940 /* Anonymous namespaces or modules have no name but have interesting
8941 children, so we need to look at them. Ditto for anonymous
8944 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8945 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8946 || pdi
->tag
== DW_TAG_imported_unit
)
8950 case DW_TAG_subprogram
:
8951 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8953 case DW_TAG_constant
:
8954 case DW_TAG_variable
:
8955 case DW_TAG_typedef
:
8956 case DW_TAG_union_type
:
8957 if (!pdi
->is_declaration
)
8959 add_partial_symbol (pdi
, cu
);
8962 case DW_TAG_class_type
:
8963 case DW_TAG_interface_type
:
8964 case DW_TAG_structure_type
:
8965 if (!pdi
->is_declaration
)
8967 add_partial_symbol (pdi
, cu
);
8969 if (cu
->language
== language_rust
&& pdi
->has_children
)
8970 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8973 case DW_TAG_enumeration_type
:
8974 if (!pdi
->is_declaration
)
8975 add_partial_enumeration (pdi
, cu
);
8977 case DW_TAG_base_type
:
8978 case DW_TAG_subrange_type
:
8979 /* File scope base type definitions are added to the partial
8981 add_partial_symbol (pdi
, cu
);
8983 case DW_TAG_namespace
:
8984 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8987 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8989 case DW_TAG_imported_unit
:
8991 struct dwarf2_per_cu_data
*per_cu
;
8993 /* For now we don't handle imported units in type units. */
8994 if (cu
->per_cu
->is_debug_types
)
8996 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8997 " supported in type units [in module %s]"),
8998 objfile_name (cu
->objfile
));
9001 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.sect_off
,
9005 /* Go read the partial unit, if needed. */
9006 if (per_cu
->v
.psymtab
== NULL
)
9007 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
9009 VEC_safe_push (dwarf2_per_cu_ptr
,
9010 cu
->per_cu
->imported_symtabs
, per_cu
);
9013 case DW_TAG_imported_declaration
:
9014 add_partial_symbol (pdi
, cu
);
9021 /* If the die has a sibling, skip to the sibling. */
9023 pdi
= pdi
->die_sibling
;
9027 /* Functions used to compute the fully scoped name of a partial DIE.
9029 Normally, this is simple. For C++, the parent DIE's fully scoped
9030 name is concatenated with "::" and the partial DIE's name.
9031 Enumerators are an exception; they use the scope of their parent
9032 enumeration type, i.e. the name of the enumeration type is not
9033 prepended to the enumerator.
9035 There are two complexities. One is DW_AT_specification; in this
9036 case "parent" means the parent of the target of the specification,
9037 instead of the direct parent of the DIE. The other is compilers
9038 which do not emit DW_TAG_namespace; in this case we try to guess
9039 the fully qualified name of structure types from their members'
9040 linkage names. This must be done using the DIE's children rather
9041 than the children of any DW_AT_specification target. We only need
9042 to do this for structures at the top level, i.e. if the target of
9043 any DW_AT_specification (if any; otherwise the DIE itself) does not
9046 /* Compute the scope prefix associated with PDI's parent, in
9047 compilation unit CU. The result will be allocated on CU's
9048 comp_unit_obstack, or a copy of the already allocated PDI->NAME
9049 field. NULL is returned if no prefix is necessary. */
9051 partial_die_parent_scope (struct partial_die_info
*pdi
,
9052 struct dwarf2_cu
*cu
)
9054 const char *grandparent_scope
;
9055 struct partial_die_info
*parent
, *real_pdi
;
9057 /* We need to look at our parent DIE; if we have a DW_AT_specification,
9058 then this means the parent of the specification DIE. */
9061 while (real_pdi
->has_specification
)
9062 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
9063 real_pdi
->spec_is_dwz
, cu
);
9065 parent
= real_pdi
->die_parent
;
9069 if (parent
->scope_set
)
9070 return parent
->scope
;
9072 fixup_partial_die (parent
, cu
);
9074 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
9076 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
9077 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
9078 Work around this problem here. */
9079 if (cu
->language
== language_cplus
9080 && parent
->tag
== DW_TAG_namespace
9081 && strcmp (parent
->name
, "::") == 0
9082 && grandparent_scope
== NULL
)
9084 parent
->scope
= NULL
;
9085 parent
->scope_set
= 1;
9089 if (pdi
->tag
== DW_TAG_enumerator
)
9090 /* Enumerators should not get the name of the enumeration as a prefix. */
9091 parent
->scope
= grandparent_scope
;
9092 else if (parent
->tag
== DW_TAG_namespace
9093 || parent
->tag
== DW_TAG_module
9094 || parent
->tag
== DW_TAG_structure_type
9095 || parent
->tag
== DW_TAG_class_type
9096 || parent
->tag
== DW_TAG_interface_type
9097 || parent
->tag
== DW_TAG_union_type
9098 || parent
->tag
== DW_TAG_enumeration_type
)
9100 if (grandparent_scope
== NULL
)
9101 parent
->scope
= parent
->name
;
9103 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
9105 parent
->name
, 0, cu
);
9109 /* FIXME drow/2004-04-01: What should we be doing with
9110 function-local names? For partial symbols, we should probably be
9112 complaint (&symfile_complaints
,
9113 _("unhandled containing DIE tag %d for DIE at %d"),
9114 parent
->tag
, to_underlying (pdi
->sect_off
));
9115 parent
->scope
= grandparent_scope
;
9118 parent
->scope_set
= 1;
9119 return parent
->scope
;
9122 /* Return the fully scoped name associated with PDI, from compilation unit
9123 CU. The result will be allocated with malloc. */
9126 partial_die_full_name (struct partial_die_info
*pdi
,
9127 struct dwarf2_cu
*cu
)
9129 const char *parent_scope
;
9131 /* If this is a template instantiation, we can not work out the
9132 template arguments from partial DIEs. So, unfortunately, we have
9133 to go through the full DIEs. At least any work we do building
9134 types here will be reused if full symbols are loaded later. */
9135 if (pdi
->has_template_arguments
)
9137 fixup_partial_die (pdi
, cu
);
9139 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
9141 struct die_info
*die
;
9142 struct attribute attr
;
9143 struct dwarf2_cu
*ref_cu
= cu
;
9145 /* DW_FORM_ref_addr is using section offset. */
9146 attr
.name
= (enum dwarf_attribute
) 0;
9147 attr
.form
= DW_FORM_ref_addr
;
9148 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
9149 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
9151 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
9155 parent_scope
= partial_die_parent_scope (pdi
, cu
);
9156 if (parent_scope
== NULL
)
9159 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
9163 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
9165 struct objfile
*objfile
= cu
->objfile
;
9166 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9168 const char *actual_name
= NULL
;
9170 char *built_actual_name
;
9172 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9174 built_actual_name
= partial_die_full_name (pdi
, cu
);
9175 if (built_actual_name
!= NULL
)
9176 actual_name
= built_actual_name
;
9178 if (actual_name
== NULL
)
9179 actual_name
= pdi
->name
;
9183 case DW_TAG_subprogram
:
9184 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
);
9185 if (pdi
->is_external
|| cu
->language
== language_ada
)
9187 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
9188 of the global scope. But in Ada, we want to be able to access
9189 nested procedures globally. So all Ada subprograms are stored
9190 in the global scope. */
9191 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9192 built_actual_name
!= NULL
,
9193 VAR_DOMAIN
, LOC_BLOCK
,
9194 &objfile
->global_psymbols
,
9195 addr
, cu
->language
, objfile
);
9199 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9200 built_actual_name
!= NULL
,
9201 VAR_DOMAIN
, LOC_BLOCK
,
9202 &objfile
->static_psymbols
,
9203 addr
, cu
->language
, objfile
);
9206 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
9207 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
9209 case DW_TAG_constant
:
9211 std::vector
<partial_symbol
*> *list
;
9213 if (pdi
->is_external
)
9214 list
= &objfile
->global_psymbols
;
9216 list
= &objfile
->static_psymbols
;
9217 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9218 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
9219 list
, 0, cu
->language
, objfile
);
9222 case DW_TAG_variable
:
9224 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
9228 && !dwarf2_per_objfile
->has_section_at_zero
)
9230 /* A global or static variable may also have been stripped
9231 out by the linker if unused, in which case its address
9232 will be nullified; do not add such variables into partial
9233 symbol table then. */
9235 else if (pdi
->is_external
)
9238 Don't enter into the minimal symbol tables as there is
9239 a minimal symbol table entry from the ELF symbols already.
9240 Enter into partial symbol table if it has a location
9241 descriptor or a type.
9242 If the location descriptor is missing, new_symbol will create
9243 a LOC_UNRESOLVED symbol, the address of the variable will then
9244 be determined from the minimal symbol table whenever the variable
9246 The address for the partial symbol table entry is not
9247 used by GDB, but it comes in handy for debugging partial symbol
9250 if (pdi
->d
.locdesc
|| pdi
->has_type
)
9251 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9252 built_actual_name
!= NULL
,
9253 VAR_DOMAIN
, LOC_STATIC
,
9254 &objfile
->global_psymbols
,
9256 cu
->language
, objfile
);
9260 int has_loc
= pdi
->d
.locdesc
!= NULL
;
9262 /* Static Variable. Skip symbols whose value we cannot know (those
9263 without location descriptors or constant values). */
9264 if (!has_loc
&& !pdi
->has_const_value
)
9266 xfree (built_actual_name
);
9270 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9271 built_actual_name
!= NULL
,
9272 VAR_DOMAIN
, LOC_STATIC
,
9273 &objfile
->static_psymbols
,
9274 has_loc
? addr
+ baseaddr
: (CORE_ADDR
) 0,
9275 cu
->language
, objfile
);
9278 case DW_TAG_typedef
:
9279 case DW_TAG_base_type
:
9280 case DW_TAG_subrange_type
:
9281 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9282 built_actual_name
!= NULL
,
9283 VAR_DOMAIN
, LOC_TYPEDEF
,
9284 &objfile
->static_psymbols
,
9285 0, cu
->language
, objfile
);
9287 case DW_TAG_imported_declaration
:
9288 case DW_TAG_namespace
:
9289 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9290 built_actual_name
!= NULL
,
9291 VAR_DOMAIN
, LOC_TYPEDEF
,
9292 &objfile
->global_psymbols
,
9293 0, cu
->language
, objfile
);
9296 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9297 built_actual_name
!= NULL
,
9298 MODULE_DOMAIN
, LOC_TYPEDEF
,
9299 &objfile
->global_psymbols
,
9300 0, cu
->language
, objfile
);
9302 case DW_TAG_class_type
:
9303 case DW_TAG_interface_type
:
9304 case DW_TAG_structure_type
:
9305 case DW_TAG_union_type
:
9306 case DW_TAG_enumeration_type
:
9307 /* Skip external references. The DWARF standard says in the section
9308 about "Structure, Union, and Class Type Entries": "An incomplete
9309 structure, union or class type is represented by a structure,
9310 union or class entry that does not have a byte size attribute
9311 and that has a DW_AT_declaration attribute." */
9312 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9314 xfree (built_actual_name
);
9318 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9319 static vs. global. */
9320 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9321 built_actual_name
!= NULL
,
9322 STRUCT_DOMAIN
, LOC_TYPEDEF
,
9323 cu
->language
== language_cplus
9324 ? &objfile
->global_psymbols
9325 : &objfile
->static_psymbols
,
9326 0, cu
->language
, objfile
);
9329 case DW_TAG_enumerator
:
9330 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9331 built_actual_name
!= NULL
,
9332 VAR_DOMAIN
, LOC_CONST
,
9333 cu
->language
== language_cplus
9334 ? &objfile
->global_psymbols
9335 : &objfile
->static_psymbols
,
9336 0, cu
->language
, objfile
);
9342 xfree (built_actual_name
);
9345 /* Read a partial die corresponding to a namespace; also, add a symbol
9346 corresponding to that namespace to the symbol table. NAMESPACE is
9347 the name of the enclosing namespace. */
9350 add_partial_namespace (struct partial_die_info
*pdi
,
9351 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9352 int set_addrmap
, struct dwarf2_cu
*cu
)
9354 /* Add a symbol for the namespace. */
9356 add_partial_symbol (pdi
, cu
);
9358 /* Now scan partial symbols in that namespace. */
9360 if (pdi
->has_children
)
9361 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9364 /* Read a partial die corresponding to a Fortran module. */
9367 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9368 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9370 /* Add a symbol for the namespace. */
9372 add_partial_symbol (pdi
, cu
);
9374 /* Now scan partial symbols in that module. */
9376 if (pdi
->has_children
)
9377 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9380 /* Read a partial die corresponding to a subprogram and create a partial
9381 symbol for that subprogram. When the CU language allows it, this
9382 routine also defines a partial symbol for each nested subprogram
9383 that this subprogram contains. If SET_ADDRMAP is true, record the
9384 covered ranges in the addrmap. Set *LOWPC and *HIGHPC to the lowest
9385 and highest PC values found in PDI.
9387 PDI may also be a lexical block, in which case we simply search
9388 recursively for subprograms defined inside that lexical block.
9389 Again, this is only performed when the CU language allows this
9390 type of definitions. */
9393 add_partial_subprogram (struct partial_die_info
*pdi
,
9394 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9395 int set_addrmap
, struct dwarf2_cu
*cu
)
9397 if (pdi
->tag
== DW_TAG_subprogram
)
9399 if (pdi
->has_pc_info
)
9401 if (pdi
->lowpc
< *lowpc
)
9402 *lowpc
= pdi
->lowpc
;
9403 if (pdi
->highpc
> *highpc
)
9404 *highpc
= pdi
->highpc
;
9407 struct objfile
*objfile
= cu
->objfile
;
9408 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9413 baseaddr
= ANOFFSET (objfile
->section_offsets
,
9414 SECT_OFF_TEXT (objfile
));
9415 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9416 pdi
->lowpc
+ baseaddr
);
9417 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9418 pdi
->highpc
+ baseaddr
);
9419 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
9420 cu
->per_cu
->v
.psymtab
);
9424 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9426 if (!pdi
->is_declaration
)
9427 /* Ignore subprogram DIEs that do not have a name, they are
9428 illegal. Do not emit a complaint at this point, we will
9429 do so when we convert this psymtab into a symtab. */
9431 add_partial_symbol (pdi
, cu
);
9435 if (! pdi
->has_children
)
9438 if (cu
->language
== language_ada
)
9440 pdi
= pdi
->die_child
;
9443 fixup_partial_die (pdi
, cu
);
9444 if (pdi
->tag
== DW_TAG_subprogram
9445 || pdi
->tag
== DW_TAG_lexical_block
)
9446 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9447 pdi
= pdi
->die_sibling
;
9452 /* Read a partial die corresponding to an enumeration type. */
9455 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9456 struct dwarf2_cu
*cu
)
9458 struct partial_die_info
*pdi
;
9460 if (enum_pdi
->name
!= NULL
)
9461 add_partial_symbol (enum_pdi
, cu
);
9463 pdi
= enum_pdi
->die_child
;
9466 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9467 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
9469 add_partial_symbol (pdi
, cu
);
9470 pdi
= pdi
->die_sibling
;
9474 /* Return the initial uleb128 in the die at INFO_PTR. */
9477 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9479 unsigned int bytes_read
;
9481 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9484 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
9485 Return the corresponding abbrev, or NULL if the number is zero (indicating
9486 an empty DIE). In either case *BYTES_READ will be set to the length of
9487 the initial number. */
9489 static struct abbrev_info
*
9490 peek_die_abbrev (const gdb_byte
*info_ptr
, unsigned int *bytes_read
,
9491 struct dwarf2_cu
*cu
)
9493 bfd
*abfd
= cu
->objfile
->obfd
;
9494 unsigned int abbrev_number
;
9495 struct abbrev_info
*abbrev
;
9497 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9499 if (abbrev_number
== 0)
9502 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
9505 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9506 " at offset 0x%x [in module %s]"),
9507 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9508 to_underlying (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9514 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9515 Returns a pointer to the end of a series of DIEs, terminated by an empty
9516 DIE. Any children of the skipped DIEs will also be skipped. */
9518 static const gdb_byte
*
9519 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9521 struct dwarf2_cu
*cu
= reader
->cu
;
9522 struct abbrev_info
*abbrev
;
9523 unsigned int bytes_read
;
9527 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
9529 return info_ptr
+ bytes_read
;
9531 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9535 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9536 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9537 abbrev corresponding to that skipped uleb128 should be passed in
9538 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9541 static const gdb_byte
*
9542 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9543 struct abbrev_info
*abbrev
)
9545 unsigned int bytes_read
;
9546 struct attribute attr
;
9547 bfd
*abfd
= reader
->abfd
;
9548 struct dwarf2_cu
*cu
= reader
->cu
;
9549 const gdb_byte
*buffer
= reader
->buffer
;
9550 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9551 unsigned int form
, i
;
9553 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9555 /* The only abbrev we care about is DW_AT_sibling. */
9556 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9558 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
9559 if (attr
.form
== DW_FORM_ref_addr
)
9560 complaint (&symfile_complaints
,
9561 _("ignoring absolute DW_AT_sibling"));
9564 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9565 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9567 if (sibling_ptr
< info_ptr
)
9568 complaint (&symfile_complaints
,
9569 _("DW_AT_sibling points backwards"));
9570 else if (sibling_ptr
> reader
->buffer_end
)
9571 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9577 /* If it isn't DW_AT_sibling, skip this attribute. */
9578 form
= abbrev
->attrs
[i
].form
;
9582 case DW_FORM_ref_addr
:
9583 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9584 and later it is offset sized. */
9585 if (cu
->header
.version
== 2)
9586 info_ptr
+= cu
->header
.addr_size
;
9588 info_ptr
+= cu
->header
.offset_size
;
9590 case DW_FORM_GNU_ref_alt
:
9591 info_ptr
+= cu
->header
.offset_size
;
9594 info_ptr
+= cu
->header
.addr_size
;
9601 case DW_FORM_flag_present
:
9602 case DW_FORM_implicit_const
:
9614 case DW_FORM_ref_sig8
:
9617 case DW_FORM_data16
:
9620 case DW_FORM_string
:
9621 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9622 info_ptr
+= bytes_read
;
9624 case DW_FORM_sec_offset
:
9626 case DW_FORM_GNU_strp_alt
:
9627 info_ptr
+= cu
->header
.offset_size
;
9629 case DW_FORM_exprloc
:
9631 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9632 info_ptr
+= bytes_read
;
9634 case DW_FORM_block1
:
9635 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9637 case DW_FORM_block2
:
9638 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9640 case DW_FORM_block4
:
9641 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9645 case DW_FORM_ref_udata
:
9646 case DW_FORM_GNU_addr_index
:
9647 case DW_FORM_GNU_str_index
:
9648 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9650 case DW_FORM_indirect
:
9651 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9652 info_ptr
+= bytes_read
;
9653 /* We need to continue parsing from here, so just go back to
9655 goto skip_attribute
;
9658 error (_("Dwarf Error: Cannot handle %s "
9659 "in DWARF reader [in module %s]"),
9660 dwarf_form_name (form
),
9661 bfd_get_filename (abfd
));
9665 if (abbrev
->has_children
)
9666 return skip_children (reader
, info_ptr
);
9671 /* Locate ORIG_PDI's sibling.
9672 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9674 static const gdb_byte
*
9675 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9676 struct partial_die_info
*orig_pdi
,
9677 const gdb_byte
*info_ptr
)
9679 /* Do we know the sibling already? */
9681 if (orig_pdi
->sibling
)
9682 return orig_pdi
->sibling
;
9684 /* Are there any children to deal with? */
9686 if (!orig_pdi
->has_children
)
9689 /* Skip the children the long way. */
9691 return skip_children (reader
, info_ptr
);
9694 /* Expand this partial symbol table into a full symbol table. SELF is
9698 dwarf2_read_symtab (struct partial_symtab
*self
,
9699 struct objfile
*objfile
)
9703 warning (_("bug: psymtab for %s is already read in."),
9710 printf_filtered (_("Reading in symbols for %s..."),
9712 gdb_flush (gdb_stdout
);
9715 /* Restore our global data. */
9717 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
9718 dwarf2_objfile_data_key
);
9720 /* If this psymtab is constructed from a debug-only objfile, the
9721 has_section_at_zero flag will not necessarily be correct. We
9722 can get the correct value for this flag by looking at the data
9723 associated with the (presumably stripped) associated objfile. */
9724 if (objfile
->separate_debug_objfile_backlink
)
9726 struct dwarf2_per_objfile
*dpo_backlink
9727 = ((struct dwarf2_per_objfile
*)
9728 objfile_data (objfile
->separate_debug_objfile_backlink
,
9729 dwarf2_objfile_data_key
));
9731 dwarf2_per_objfile
->has_section_at_zero
9732 = dpo_backlink
->has_section_at_zero
;
9735 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9737 psymtab_to_symtab_1 (self
);
9739 /* Finish up the debug error message. */
9741 printf_filtered (_("done.\n"));
9744 process_cu_includes ();
9747 /* Reading in full CUs. */
9749 /* Add PER_CU to the queue. */
9752 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9753 enum language pretend_language
)
9755 struct dwarf2_queue_item
*item
;
9758 item
= XNEW (struct dwarf2_queue_item
);
9759 item
->per_cu
= per_cu
;
9760 item
->pretend_language
= pretend_language
;
9763 if (dwarf2_queue
== NULL
)
9764 dwarf2_queue
= item
;
9766 dwarf2_queue_tail
->next
= item
;
9768 dwarf2_queue_tail
= item
;
9771 /* If PER_CU is not yet queued, add it to the queue.
9772 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9774 The result is non-zero if PER_CU was queued, otherwise the result is zero
9775 meaning either PER_CU is already queued or it is already loaded.
9777 N.B. There is an invariant here that if a CU is queued then it is loaded.
9778 The caller is required to load PER_CU if we return non-zero. */
9781 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9782 struct dwarf2_per_cu_data
*per_cu
,
9783 enum language pretend_language
)
9785 /* We may arrive here during partial symbol reading, if we need full
9786 DIEs to process an unusual case (e.g. template arguments). Do
9787 not queue PER_CU, just tell our caller to load its DIEs. */
9788 if (dwarf2_per_objfile
->reading_partial_symbols
)
9790 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9795 /* Mark the dependence relation so that we don't flush PER_CU
9797 if (dependent_cu
!= NULL
)
9798 dwarf2_add_dependence (dependent_cu
, per_cu
);
9800 /* If it's already on the queue, we have nothing to do. */
9804 /* If the compilation unit is already loaded, just mark it as
9806 if (per_cu
->cu
!= NULL
)
9808 per_cu
->cu
->last_used
= 0;
9812 /* Add it to the queue. */
9813 queue_comp_unit (per_cu
, pretend_language
);
9818 /* Process the queue. */
9821 process_queue (void)
9823 struct dwarf2_queue_item
*item
, *next_item
;
9825 if (dwarf_read_debug
)
9827 fprintf_unfiltered (gdb_stdlog
,
9828 "Expanding one or more symtabs of objfile %s ...\n",
9829 objfile_name (dwarf2_per_objfile
->objfile
));
9832 /* The queue starts out with one item, but following a DIE reference
9833 may load a new CU, adding it to the end of the queue. */
9834 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9836 if ((dwarf2_per_objfile
->using_index
9837 ? !item
->per_cu
->v
.quick
->compunit_symtab
9838 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9839 /* Skip dummy CUs. */
9840 && item
->per_cu
->cu
!= NULL
)
9842 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9843 unsigned int debug_print_threshold
;
9846 if (per_cu
->is_debug_types
)
9848 struct signatured_type
*sig_type
=
9849 (struct signatured_type
*) per_cu
;
9851 sprintf (buf
, "TU %s at offset 0x%x",
9852 hex_string (sig_type
->signature
),
9853 to_underlying (per_cu
->sect_off
));
9854 /* There can be 100s of TUs.
9855 Only print them in verbose mode. */
9856 debug_print_threshold
= 2;
9860 sprintf (buf
, "CU at offset 0x%x",
9861 to_underlying (per_cu
->sect_off
));
9862 debug_print_threshold
= 1;
9865 if (dwarf_read_debug
>= debug_print_threshold
)
9866 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9868 if (per_cu
->is_debug_types
)
9869 process_full_type_unit (per_cu
, item
->pretend_language
);
9871 process_full_comp_unit (per_cu
, item
->pretend_language
);
9873 if (dwarf_read_debug
>= debug_print_threshold
)
9874 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9877 item
->per_cu
->queued
= 0;
9878 next_item
= item
->next
;
9882 dwarf2_queue_tail
= NULL
;
9884 if (dwarf_read_debug
)
9886 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9887 objfile_name (dwarf2_per_objfile
->objfile
));
9891 /* Free all allocated queue entries. This function only releases anything if
9892 an error was thrown; if the queue was processed then it would have been
9893 freed as we went along. */
9896 dwarf2_release_queue (void *dummy
)
9898 struct dwarf2_queue_item
*item
, *last
;
9900 item
= dwarf2_queue
;
9903 /* Anything still marked queued is likely to be in an
9904 inconsistent state, so discard it. */
9905 if (item
->per_cu
->queued
)
9907 if (item
->per_cu
->cu
!= NULL
)
9908 free_one_cached_comp_unit (item
->per_cu
);
9909 item
->per_cu
->queued
= 0;
9917 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
9920 /* Read in full symbols for PST, and anything it depends on. */
9923 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
9925 struct dwarf2_per_cu_data
*per_cu
;
9931 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
9932 if (!pst
->dependencies
[i
]->readin
9933 && pst
->dependencies
[i
]->user
== NULL
)
9935 /* Inform about additional files that need to be read in. */
9938 /* FIXME: i18n: Need to make this a single string. */
9939 fputs_filtered (" ", gdb_stdout
);
9941 fputs_filtered ("and ", gdb_stdout
);
9943 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
9944 wrap_here (""); /* Flush output. */
9945 gdb_flush (gdb_stdout
);
9947 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
9950 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
9954 /* It's an include file, no symbols to read for it.
9955 Everything is in the parent symtab. */
9960 dw2_do_instantiate_symtab (per_cu
);
9963 /* Trivial hash function for die_info: the hash value of a DIE
9964 is its offset in .debug_info for this objfile. */
9967 die_hash (const void *item
)
9969 const struct die_info
*die
= (const struct die_info
*) item
;
9971 return to_underlying (die
->sect_off
);
9974 /* Trivial comparison function for die_info structures: two DIEs
9975 are equal if they have the same offset. */
9978 die_eq (const void *item_lhs
, const void *item_rhs
)
9980 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9981 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9983 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9986 /* die_reader_func for load_full_comp_unit.
9987 This is identical to read_signatured_type_reader,
9988 but is kept separate for now. */
9991 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
9992 const gdb_byte
*info_ptr
,
9993 struct die_info
*comp_unit_die
,
9997 struct dwarf2_cu
*cu
= reader
->cu
;
9998 enum language
*language_ptr
= (enum language
*) data
;
10000 gdb_assert (cu
->die_hash
== NULL
);
10002 htab_create_alloc_ex (cu
->header
.length
/ 12,
10006 &cu
->comp_unit_obstack
,
10007 hashtab_obstack_allocate
,
10008 dummy_obstack_deallocate
);
10011 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
10012 &info_ptr
, comp_unit_die
);
10013 cu
->dies
= comp_unit_die
;
10014 /* comp_unit_die is not stored in die_hash, no need. */
10016 /* We try not to read any attributes in this function, because not
10017 all CUs needed for references have been loaded yet, and symbol
10018 table processing isn't initialized. But we have to set the CU language,
10019 or we won't be able to build types correctly.
10020 Similarly, if we do not read the producer, we can not apply
10021 producer-specific interpretation. */
10022 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
10025 /* Load the DIEs associated with PER_CU into memory. */
10028 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
10029 enum language pretend_language
)
10031 gdb_assert (! this_cu
->is_debug_types
);
10033 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
10034 load_full_comp_unit_reader
, &pretend_language
);
10037 /* Add a DIE to the delayed physname list. */
10040 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
10041 const char *name
, struct die_info
*die
,
10042 struct dwarf2_cu
*cu
)
10044 struct delayed_method_info mi
;
10046 mi
.fnfield_index
= fnfield_index
;
10050 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
10053 /* A cleanup for freeing the delayed method list. */
10056 free_delayed_list (void *ptr
)
10058 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
10059 if (cu
->method_list
!= NULL
)
10061 VEC_free (delayed_method_info
, cu
->method_list
);
10062 cu
->method_list
= NULL
;
10066 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
10067 "const" / "volatile". If so, decrements LEN by the length of the
10068 modifier and return true. Otherwise return false. */
10072 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
10074 size_t mod_len
= sizeof (mod
) - 1;
10075 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
10083 /* Compute the physnames of any methods on the CU's method list.
10085 The computation of method physnames is delayed in order to avoid the
10086 (bad) condition that one of the method's formal parameters is of an as yet
10087 incomplete type. */
10090 compute_delayed_physnames (struct dwarf2_cu
*cu
)
10093 struct delayed_method_info
*mi
;
10095 /* Only C++ delays computing physnames. */
10096 if (VEC_empty (delayed_method_info
, cu
->method_list
))
10098 gdb_assert (cu
->language
== language_cplus
);
10100 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
10102 const char *physname
;
10103 struct fn_fieldlist
*fn_flp
10104 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
10105 physname
= dwarf2_physname (mi
->name
, mi
->die
, cu
);
10106 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
->index
)
10107 = physname
? physname
: "";
10109 /* Since there's no tag to indicate whether a method is a
10110 const/volatile overload, extract that information out of the
10112 if (physname
!= NULL
)
10114 size_t len
= strlen (physname
);
10118 if (physname
[len
] == ')') /* shortcut */
10120 else if (check_modifier (physname
, len
, " const"))
10121 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
->index
) = 1;
10122 else if (check_modifier (physname
, len
, " volatile"))
10123 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
->index
) = 1;
10131 /* Go objects should be embedded in a DW_TAG_module DIE,
10132 and it's not clear if/how imported objects will appear.
10133 To keep Go support simple until that's worked out,
10134 go back through what we've read and create something usable.
10135 We could do this while processing each DIE, and feels kinda cleaner,
10136 but that way is more invasive.
10137 This is to, for example, allow the user to type "p var" or "b main"
10138 without having to specify the package name, and allow lookups
10139 of module.object to work in contexts that use the expression
10143 fixup_go_packaging (struct dwarf2_cu
*cu
)
10145 char *package_name
= NULL
;
10146 struct pending
*list
;
10149 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
10151 for (i
= 0; i
< list
->nsyms
; ++i
)
10153 struct symbol
*sym
= list
->symbol
[i
];
10155 if (SYMBOL_LANGUAGE (sym
) == language_go
10156 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
10158 char *this_package_name
= go_symbol_package_name (sym
);
10160 if (this_package_name
== NULL
)
10162 if (package_name
== NULL
)
10163 package_name
= this_package_name
;
10166 if (strcmp (package_name
, this_package_name
) != 0)
10167 complaint (&symfile_complaints
,
10168 _("Symtab %s has objects from two different Go packages: %s and %s"),
10169 (symbol_symtab (sym
) != NULL
10170 ? symtab_to_filename_for_display
10171 (symbol_symtab (sym
))
10172 : objfile_name (cu
->objfile
)),
10173 this_package_name
, package_name
);
10174 xfree (this_package_name
);
10180 if (package_name
!= NULL
)
10182 struct objfile
*objfile
= cu
->objfile
;
10183 const char *saved_package_name
10184 = (const char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
10186 strlen (package_name
));
10187 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
10188 saved_package_name
);
10189 struct symbol
*sym
;
10191 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
10193 sym
= allocate_symbol (objfile
);
10194 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
10195 SYMBOL_SET_NAMES (sym
, saved_package_name
,
10196 strlen (saved_package_name
), 0, objfile
);
10197 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
10198 e.g., "main" finds the "main" module and not C's main(). */
10199 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
10200 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
10201 SYMBOL_TYPE (sym
) = type
;
10203 add_symbol_to_list (sym
, &global_symbols
);
10205 xfree (package_name
);
10209 /* Return the symtab for PER_CU. This works properly regardless of
10210 whether we're using the index or psymtabs. */
10212 static struct compunit_symtab
*
10213 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10215 return (dwarf2_per_objfile
->using_index
10216 ? per_cu
->v
.quick
->compunit_symtab
10217 : per_cu
->v
.psymtab
->compunit_symtab
);
10220 /* A helper function for computing the list of all symbol tables
10221 included by PER_CU. */
10224 recursively_compute_inclusions (VEC (compunit_symtab_ptr
) **result
,
10225 htab_t all_children
, htab_t all_type_symtabs
,
10226 struct dwarf2_per_cu_data
*per_cu
,
10227 struct compunit_symtab
*immediate_parent
)
10231 struct compunit_symtab
*cust
;
10232 struct dwarf2_per_cu_data
*iter
;
10234 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10237 /* This inclusion and its children have been processed. */
10242 /* Only add a CU if it has a symbol table. */
10243 cust
= get_compunit_symtab (per_cu
);
10246 /* If this is a type unit only add its symbol table if we haven't
10247 seen it yet (type unit per_cu's can share symtabs). */
10248 if (per_cu
->is_debug_types
)
10250 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10254 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10255 if (cust
->user
== NULL
)
10256 cust
->user
= immediate_parent
;
10261 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10262 if (cust
->user
== NULL
)
10263 cust
->user
= immediate_parent
;
10268 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
10271 recursively_compute_inclusions (result
, all_children
,
10272 all_type_symtabs
, iter
, cust
);
10276 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10280 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10282 gdb_assert (! per_cu
->is_debug_types
);
10284 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
10287 struct dwarf2_per_cu_data
*per_cu_iter
;
10288 struct compunit_symtab
*compunit_symtab_iter
;
10289 VEC (compunit_symtab_ptr
) *result_symtabs
= NULL
;
10290 htab_t all_children
, all_type_symtabs
;
10291 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10293 /* If we don't have a symtab, we can just skip this case. */
10297 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10298 NULL
, xcalloc
, xfree
);
10299 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10300 NULL
, xcalloc
, xfree
);
10303 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
10307 recursively_compute_inclusions (&result_symtabs
, all_children
,
10308 all_type_symtabs
, per_cu_iter
,
10312 /* Now we have a transitive closure of all the included symtabs. */
10313 len
= VEC_length (compunit_symtab_ptr
, result_symtabs
);
10315 = XOBNEWVEC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
10316 struct compunit_symtab
*, len
+ 1);
10318 VEC_iterate (compunit_symtab_ptr
, result_symtabs
, ix
,
10319 compunit_symtab_iter
);
10321 cust
->includes
[ix
] = compunit_symtab_iter
;
10322 cust
->includes
[len
] = NULL
;
10324 VEC_free (compunit_symtab_ptr
, result_symtabs
);
10325 htab_delete (all_children
);
10326 htab_delete (all_type_symtabs
);
10330 /* Compute the 'includes' field for the symtabs of all the CUs we just
10334 process_cu_includes (void)
10337 struct dwarf2_per_cu_data
*iter
;
10340 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
10344 if (! iter
->is_debug_types
)
10345 compute_compunit_symtab_includes (iter
);
10348 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
10351 /* Generate full symbol information for PER_CU, whose DIEs have
10352 already been loaded into memory. */
10355 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10356 enum language pretend_language
)
10358 struct dwarf2_cu
*cu
= per_cu
->cu
;
10359 struct objfile
*objfile
= per_cu
->objfile
;
10360 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10361 CORE_ADDR lowpc
, highpc
;
10362 struct compunit_symtab
*cust
;
10363 struct cleanup
*delayed_list_cleanup
;
10364 CORE_ADDR baseaddr
;
10365 struct block
*static_block
;
10368 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10371 scoped_free_pendings free_pending
;
10372 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
10374 cu
->list_in_scope
= &file_symbols
;
10376 cu
->language
= pretend_language
;
10377 cu
->language_defn
= language_def (cu
->language
);
10379 /* Do line number decoding in read_file_scope () */
10380 process_die (cu
->dies
, cu
);
10382 /* For now fudge the Go package. */
10383 if (cu
->language
== language_go
)
10384 fixup_go_packaging (cu
);
10386 /* Now that we have processed all the DIEs in the CU, all the types
10387 should be complete, and it should now be safe to compute all of the
10389 compute_delayed_physnames (cu
);
10390 do_cleanups (delayed_list_cleanup
);
10392 /* Some compilers don't define a DW_AT_high_pc attribute for the
10393 compilation unit. If the DW_AT_high_pc is missing, synthesize
10394 it, by scanning the DIE's below the compilation unit. */
10395 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10397 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10398 static_block
= end_symtab_get_static_block (addr
, 0, 1);
10400 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10401 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10402 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10403 addrmap to help ensure it has an accurate map of pc values belonging to
10405 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10407 cust
= end_symtab_from_static_block (static_block
,
10408 SECT_OFF_TEXT (objfile
), 0);
10412 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10414 /* Set symtab language to language from DW_AT_language. If the
10415 compilation is from a C file generated by language preprocessors, do
10416 not set the language if it was already deduced by start_subfile. */
10417 if (!(cu
->language
== language_c
10418 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10419 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10421 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10422 produce DW_AT_location with location lists but it can be possibly
10423 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10424 there were bugs in prologue debug info, fixed later in GCC-4.5
10425 by "unwind info for epilogues" patch (which is not directly related).
10427 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10428 needed, it would be wrong due to missing DW_AT_producer there.
10430 Still one can confuse GDB by using non-standard GCC compilation
10431 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10433 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10434 cust
->locations_valid
= 1;
10436 if (gcc_4_minor
>= 5)
10437 cust
->epilogue_unwind_valid
= 1;
10439 cust
->call_site_htab
= cu
->call_site_htab
;
10442 if (dwarf2_per_objfile
->using_index
)
10443 per_cu
->v
.quick
->compunit_symtab
= cust
;
10446 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10447 pst
->compunit_symtab
= cust
;
10451 /* Push it for inclusion processing later. */
10452 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
10455 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10456 already been loaded into memory. */
10459 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10460 enum language pretend_language
)
10462 struct dwarf2_cu
*cu
= per_cu
->cu
;
10463 struct objfile
*objfile
= per_cu
->objfile
;
10464 struct compunit_symtab
*cust
;
10465 struct cleanup
*delayed_list_cleanup
;
10466 struct signatured_type
*sig_type
;
10468 gdb_assert (per_cu
->is_debug_types
);
10469 sig_type
= (struct signatured_type
*) per_cu
;
10472 scoped_free_pendings free_pending
;
10473 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
10475 cu
->list_in_scope
= &file_symbols
;
10477 cu
->language
= pretend_language
;
10478 cu
->language_defn
= language_def (cu
->language
);
10480 /* The symbol tables are set up in read_type_unit_scope. */
10481 process_die (cu
->dies
, cu
);
10483 /* For now fudge the Go package. */
10484 if (cu
->language
== language_go
)
10485 fixup_go_packaging (cu
);
10487 /* Now that we have processed all the DIEs in the CU, all the types
10488 should be complete, and it should now be safe to compute all of the
10490 compute_delayed_physnames (cu
);
10491 do_cleanups (delayed_list_cleanup
);
10493 /* TUs share symbol tables.
10494 If this is the first TU to use this symtab, complete the construction
10495 of it with end_expandable_symtab. Otherwise, complete the addition of
10496 this TU's symbols to the existing symtab. */
10497 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10499 cust
= end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10500 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10504 /* Set symtab language to language from DW_AT_language. If the
10505 compilation is from a C file generated by language preprocessors,
10506 do not set the language if it was already deduced by
10508 if (!(cu
->language
== language_c
10509 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10510 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10515 augment_type_symtab ();
10516 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10519 if (dwarf2_per_objfile
->using_index
)
10520 per_cu
->v
.quick
->compunit_symtab
= cust
;
10523 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10524 pst
->compunit_symtab
= cust
;
10529 /* Process an imported unit DIE. */
10532 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10534 struct attribute
*attr
;
10536 /* For now we don't handle imported units in type units. */
10537 if (cu
->per_cu
->is_debug_types
)
10539 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10540 " supported in type units [in module %s]"),
10541 objfile_name (cu
->objfile
));
10544 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10547 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10548 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10549 dwarf2_per_cu_data
*per_cu
10550 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, cu
->objfile
);
10552 /* If necessary, add it to the queue and load its DIEs. */
10553 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10554 load_full_comp_unit (per_cu
, cu
->language
);
10556 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
10561 /* RAII object that represents a process_die scope: i.e.,
10562 starts/finishes processing a DIE. */
10563 class process_die_scope
10566 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10567 : m_die (die
), m_cu (cu
)
10569 /* We should only be processing DIEs not already in process. */
10570 gdb_assert (!m_die
->in_process
);
10571 m_die
->in_process
= true;
10574 ~process_die_scope ()
10576 m_die
->in_process
= false;
10578 /* If we're done processing the DIE for the CU that owns the line
10579 header, we don't need the line header anymore. */
10580 if (m_cu
->line_header_die_owner
== m_die
)
10582 delete m_cu
->line_header
;
10583 m_cu
->line_header
= NULL
;
10584 m_cu
->line_header_die_owner
= NULL
;
10593 /* Process a die and its children. */
10596 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10598 process_die_scope
scope (die
, cu
);
10602 case DW_TAG_padding
:
10604 case DW_TAG_compile_unit
:
10605 case DW_TAG_partial_unit
:
10606 read_file_scope (die
, cu
);
10608 case DW_TAG_type_unit
:
10609 read_type_unit_scope (die
, cu
);
10611 case DW_TAG_subprogram
:
10612 case DW_TAG_inlined_subroutine
:
10613 read_func_scope (die
, cu
);
10615 case DW_TAG_lexical_block
:
10616 case DW_TAG_try_block
:
10617 case DW_TAG_catch_block
:
10618 read_lexical_block_scope (die
, cu
);
10620 case DW_TAG_call_site
:
10621 case DW_TAG_GNU_call_site
:
10622 read_call_site_scope (die
, cu
);
10624 case DW_TAG_class_type
:
10625 case DW_TAG_interface_type
:
10626 case DW_TAG_structure_type
:
10627 case DW_TAG_union_type
:
10628 process_structure_scope (die
, cu
);
10630 case DW_TAG_enumeration_type
:
10631 process_enumeration_scope (die
, cu
);
10634 /* These dies have a type, but processing them does not create
10635 a symbol or recurse to process the children. Therefore we can
10636 read them on-demand through read_type_die. */
10637 case DW_TAG_subroutine_type
:
10638 case DW_TAG_set_type
:
10639 case DW_TAG_array_type
:
10640 case DW_TAG_pointer_type
:
10641 case DW_TAG_ptr_to_member_type
:
10642 case DW_TAG_reference_type
:
10643 case DW_TAG_rvalue_reference_type
:
10644 case DW_TAG_string_type
:
10647 case DW_TAG_base_type
:
10648 case DW_TAG_subrange_type
:
10649 case DW_TAG_typedef
:
10650 /* Add a typedef symbol for the type definition, if it has a
10652 new_symbol (die
, read_type_die (die
, cu
), cu
);
10654 case DW_TAG_common_block
:
10655 read_common_block (die
, cu
);
10657 case DW_TAG_common_inclusion
:
10659 case DW_TAG_namespace
:
10660 cu
->processing_has_namespace_info
= 1;
10661 read_namespace (die
, cu
);
10663 case DW_TAG_module
:
10664 cu
->processing_has_namespace_info
= 1;
10665 read_module (die
, cu
);
10667 case DW_TAG_imported_declaration
:
10668 cu
->processing_has_namespace_info
= 1;
10669 if (read_namespace_alias (die
, cu
))
10671 /* The declaration is not a global namespace alias: fall through. */
10672 case DW_TAG_imported_module
:
10673 cu
->processing_has_namespace_info
= 1;
10674 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10675 || cu
->language
!= language_fortran
))
10676 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
10677 dwarf_tag_name (die
->tag
));
10678 read_import_statement (die
, cu
);
10681 case DW_TAG_imported_unit
:
10682 process_imported_unit_die (die
, cu
);
10685 case DW_TAG_variable
:
10686 read_variable (die
, cu
);
10690 new_symbol (die
, NULL
, cu
);
10695 /* DWARF name computation. */
10697 /* A helper function for dwarf2_compute_name which determines whether DIE
10698 needs to have the name of the scope prepended to the name listed in the
10702 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10704 struct attribute
*attr
;
10708 case DW_TAG_namespace
:
10709 case DW_TAG_typedef
:
10710 case DW_TAG_class_type
:
10711 case DW_TAG_interface_type
:
10712 case DW_TAG_structure_type
:
10713 case DW_TAG_union_type
:
10714 case DW_TAG_enumeration_type
:
10715 case DW_TAG_enumerator
:
10716 case DW_TAG_subprogram
:
10717 case DW_TAG_inlined_subroutine
:
10718 case DW_TAG_member
:
10719 case DW_TAG_imported_declaration
:
10722 case DW_TAG_variable
:
10723 case DW_TAG_constant
:
10724 /* We only need to prefix "globally" visible variables. These include
10725 any variable marked with DW_AT_external or any variable that
10726 lives in a namespace. [Variables in anonymous namespaces
10727 require prefixing, but they are not DW_AT_external.] */
10729 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10731 struct dwarf2_cu
*spec_cu
= cu
;
10733 return die_needs_namespace (die_specification (die
, &spec_cu
),
10737 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10738 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10739 && die
->parent
->tag
!= DW_TAG_module
)
10741 /* A variable in a lexical block of some kind does not need a
10742 namespace, even though in C++ such variables may be external
10743 and have a mangled name. */
10744 if (die
->parent
->tag
== DW_TAG_lexical_block
10745 || die
->parent
->tag
== DW_TAG_try_block
10746 || die
->parent
->tag
== DW_TAG_catch_block
10747 || die
->parent
->tag
== DW_TAG_subprogram
)
10756 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10757 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10758 defined for the given DIE. */
10760 static struct attribute
*
10761 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10763 struct attribute
*attr
;
10765 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10767 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10772 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10773 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10774 defined for the given DIE. */
10776 static const char *
10777 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10779 const char *linkage_name
;
10781 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10782 if (linkage_name
== NULL
)
10783 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10785 return linkage_name
;
10788 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10789 compute the physname for the object, which include a method's:
10790 - formal parameters (C++),
10791 - receiver type (Go),
10793 The term "physname" is a bit confusing.
10794 For C++, for example, it is the demangled name.
10795 For Go, for example, it's the mangled name.
10797 For Ada, return the DIE's linkage name rather than the fully qualified
10798 name. PHYSNAME is ignored..
10800 The result is allocated on the objfile_obstack and canonicalized. */
10802 static const char *
10803 dwarf2_compute_name (const char *name
,
10804 struct die_info
*die
, struct dwarf2_cu
*cu
,
10807 struct objfile
*objfile
= cu
->objfile
;
10810 name
= dwarf2_name (die
, cu
);
10812 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10813 but otherwise compute it by typename_concat inside GDB.
10814 FIXME: Actually this is not really true, or at least not always true.
10815 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
10816 Fortran names because there is no mangling standard. So new_symbol_full
10817 will set the demangled name to the result of dwarf2_full_name, and it is
10818 the demangled name that GDB uses if it exists. */
10819 if (cu
->language
== language_ada
10820 || (cu
->language
== language_fortran
&& physname
))
10822 /* For Ada unit, we prefer the linkage name over the name, as
10823 the former contains the exported name, which the user expects
10824 to be able to reference. Ideally, we want the user to be able
10825 to reference this entity using either natural or linkage name,
10826 but we haven't started looking at this enhancement yet. */
10827 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10829 if (linkage_name
!= NULL
)
10830 return linkage_name
;
10833 /* These are the only languages we know how to qualify names in. */
10835 && (cu
->language
== language_cplus
10836 || cu
->language
== language_fortran
|| cu
->language
== language_d
10837 || cu
->language
== language_rust
))
10839 if (die_needs_namespace (die
, cu
))
10841 const char *prefix
;
10842 const char *canonical_name
= NULL
;
10846 prefix
= determine_prefix (die
, cu
);
10847 if (*prefix
!= '\0')
10849 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
10852 buf
.puts (prefixed_name
);
10853 xfree (prefixed_name
);
10858 /* Template parameters may be specified in the DIE's DW_AT_name, or
10859 as children with DW_TAG_template_type_param or
10860 DW_TAG_value_type_param. If the latter, add them to the name
10861 here. If the name already has template parameters, then
10862 skip this step; some versions of GCC emit both, and
10863 it is more efficient to use the pre-computed name.
10865 Something to keep in mind about this process: it is very
10866 unlikely, or in some cases downright impossible, to produce
10867 something that will match the mangled name of a function.
10868 If the definition of the function has the same debug info,
10869 we should be able to match up with it anyway. But fallbacks
10870 using the minimal symbol, for instance to find a method
10871 implemented in a stripped copy of libstdc++, will not work.
10872 If we do not have debug info for the definition, we will have to
10873 match them up some other way.
10875 When we do name matching there is a related problem with function
10876 templates; two instantiated function templates are allowed to
10877 differ only by their return types, which we do not add here. */
10879 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10881 struct attribute
*attr
;
10882 struct die_info
*child
;
10885 die
->building_fullname
= 1;
10887 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10891 const gdb_byte
*bytes
;
10892 struct dwarf2_locexpr_baton
*baton
;
10895 if (child
->tag
!= DW_TAG_template_type_param
10896 && child
->tag
!= DW_TAG_template_value_param
)
10907 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10910 complaint (&symfile_complaints
,
10911 _("template parameter missing DW_AT_type"));
10912 buf
.puts ("UNKNOWN_TYPE");
10915 type
= die_type (child
, cu
);
10917 if (child
->tag
== DW_TAG_template_type_param
)
10919 c_print_type (type
, "", &buf
, -1, 0, &type_print_raw_options
);
10923 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10926 complaint (&symfile_complaints
,
10927 _("template parameter missing "
10928 "DW_AT_const_value"));
10929 buf
.puts ("UNKNOWN_VALUE");
10933 dwarf2_const_value_attr (attr
, type
, name
,
10934 &cu
->comp_unit_obstack
, cu
,
10935 &value
, &bytes
, &baton
);
10937 if (TYPE_NOSIGN (type
))
10938 /* GDB prints characters as NUMBER 'CHAR'. If that's
10939 changed, this can use value_print instead. */
10940 c_printchar (value
, type
, &buf
);
10943 struct value_print_options opts
;
10946 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10950 else if (bytes
!= NULL
)
10952 v
= allocate_value (type
);
10953 memcpy (value_contents_writeable (v
), bytes
,
10954 TYPE_LENGTH (type
));
10957 v
= value_from_longest (type
, value
);
10959 /* Specify decimal so that we do not depend on
10961 get_formatted_print_options (&opts
, 'd');
10963 value_print (v
, &buf
, &opts
);
10969 die
->building_fullname
= 0;
10973 /* Close the argument list, with a space if necessary
10974 (nested templates). */
10975 if (!buf
.empty () && buf
.string ().back () == '>')
10982 /* For C++ methods, append formal parameter type
10983 information, if PHYSNAME. */
10985 if (physname
&& die
->tag
== DW_TAG_subprogram
10986 && cu
->language
== language_cplus
)
10988 struct type
*type
= read_type_die (die
, cu
);
10990 c_type_print_args (type
, &buf
, 1, cu
->language
,
10991 &type_print_raw_options
);
10993 if (cu
->language
== language_cplus
)
10995 /* Assume that an artificial first parameter is
10996 "this", but do not crash if it is not. RealView
10997 marks unnamed (and thus unused) parameters as
10998 artificial; there is no way to differentiate
11000 if (TYPE_NFIELDS (type
) > 0
11001 && TYPE_FIELD_ARTIFICIAL (type
, 0)
11002 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
11003 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
11005 buf
.puts (" const");
11009 const std::string
&intermediate_name
= buf
.string ();
11011 if (cu
->language
== language_cplus
)
11013 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
11014 &objfile
->per_bfd
->storage_obstack
);
11016 /* If we only computed INTERMEDIATE_NAME, or if
11017 INTERMEDIATE_NAME is already canonical, then we need to
11018 copy it to the appropriate obstack. */
11019 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11020 name
= ((const char *)
11021 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11022 intermediate_name
.c_str (),
11023 intermediate_name
.length ()));
11025 name
= canonical_name
;
11032 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11033 If scope qualifiers are appropriate they will be added. The result
11034 will be allocated on the storage_obstack, or NULL if the DIE does
11035 not have a name. NAME may either be from a previous call to
11036 dwarf2_name or NULL.
11038 The output string will be canonicalized (if C++). */
11040 static const char *
11041 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11043 return dwarf2_compute_name (name
, die
, cu
, 0);
11046 /* Construct a physname for the given DIE in CU. NAME may either be
11047 from a previous call to dwarf2_name or NULL. The result will be
11048 allocated on the objfile_objstack or NULL if the DIE does not have a
11051 The output string will be canonicalized (if C++). */
11053 static const char *
11054 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11056 struct objfile
*objfile
= cu
->objfile
;
11057 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11060 /* In this case dwarf2_compute_name is just a shortcut not building anything
11062 if (!die_needs_namespace (die
, cu
))
11063 return dwarf2_compute_name (name
, die
, cu
, 1);
11065 mangled
= dw2_linkage_name (die
, cu
);
11067 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11068 See https://github.com/rust-lang/rust/issues/32925. */
11069 if (cu
->language
== language_rust
&& mangled
!= NULL
11070 && strchr (mangled
, '{') != NULL
)
11073 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11075 gdb::unique_xmalloc_ptr
<char> demangled
;
11076 if (mangled
!= NULL
)
11078 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
11079 type. It is easier for GDB users to search for such functions as
11080 `name(params)' than `long name(params)'. In such case the minimal
11081 symbol names do not match the full symbol names but for template
11082 functions there is never a need to look up their definition from their
11083 declaration so the only disadvantage remains the minimal symbol
11084 variant `long name(params)' does not have the proper inferior type.
11087 if (cu
->language
== language_go
)
11089 /* This is a lie, but we already lie to the caller new_symbol_full.
11090 new_symbol_full assumes we return the mangled name.
11091 This just undoes that lie until things are cleaned up. */
11095 demangled
.reset (gdb_demangle (mangled
,
11096 (DMGL_PARAMS
| DMGL_ANSI
11097 | DMGL_RET_DROP
)));
11100 canon
= demangled
.get ();
11108 if (canon
== NULL
|| check_physname
)
11110 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11112 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11114 /* It may not mean a bug in GDB. The compiler could also
11115 compute DW_AT_linkage_name incorrectly. But in such case
11116 GDB would need to be bug-to-bug compatible. */
11118 complaint (&symfile_complaints
,
11119 _("Computed physname <%s> does not match demangled <%s> "
11120 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
11121 physname
, canon
, mangled
, to_underlying (die
->sect_off
),
11122 objfile_name (objfile
));
11124 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11125 is available here - over computed PHYSNAME. It is safer
11126 against both buggy GDB and buggy compilers. */
11140 retval
= ((const char *)
11141 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11142 retval
, strlen (retval
)));
11147 /* Inspect DIE in CU for a namespace alias. If one exists, record
11148 a new symbol for it.
11150 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11153 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11155 struct attribute
*attr
;
11157 /* If the die does not have a name, this is not a namespace
11159 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11163 struct die_info
*d
= die
;
11164 struct dwarf2_cu
*imported_cu
= cu
;
11166 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11167 keep inspecting DIEs until we hit the underlying import. */
11168 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11169 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11171 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11175 d
= follow_die_ref (d
, attr
, &imported_cu
);
11176 if (d
->tag
!= DW_TAG_imported_declaration
)
11180 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11182 complaint (&symfile_complaints
,
11183 _("DIE at 0x%x has too many recursively imported "
11184 "declarations"), to_underlying (d
->sect_off
));
11191 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11193 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11194 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11196 /* This declaration is a global namespace alias. Add
11197 a symbol for it whose type is the aliased namespace. */
11198 new_symbol (die
, type
, cu
);
11207 /* Return the using directives repository (global or local?) to use in the
11208 current context for LANGUAGE.
11210 For Ada, imported declarations can materialize renamings, which *may* be
11211 global. However it is impossible (for now?) in DWARF to distinguish
11212 "external" imported declarations and "static" ones. As all imported
11213 declarations seem to be static in all other languages, make them all CU-wide
11214 global only in Ada. */
11216 static struct using_direct
**
11217 using_directives (enum language language
)
11219 if (language
== language_ada
&& context_stack_depth
== 0)
11220 return &global_using_directives
;
11222 return &local_using_directives
;
11225 /* Read the import statement specified by the given die and record it. */
11228 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11230 struct objfile
*objfile
= cu
->objfile
;
11231 struct attribute
*import_attr
;
11232 struct die_info
*imported_die
, *child_die
;
11233 struct dwarf2_cu
*imported_cu
;
11234 const char *imported_name
;
11235 const char *imported_name_prefix
;
11236 const char *canonical_name
;
11237 const char *import_alias
;
11238 const char *imported_declaration
= NULL
;
11239 const char *import_prefix
;
11240 std::vector
<const char *> excludes
;
11242 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11243 if (import_attr
== NULL
)
11245 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11246 dwarf_tag_name (die
->tag
));
11251 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11252 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11253 if (imported_name
== NULL
)
11255 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11257 The import in the following code:
11271 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11272 <52> DW_AT_decl_file : 1
11273 <53> DW_AT_decl_line : 6
11274 <54> DW_AT_import : <0x75>
11275 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11276 <59> DW_AT_name : B
11277 <5b> DW_AT_decl_file : 1
11278 <5c> DW_AT_decl_line : 2
11279 <5d> DW_AT_type : <0x6e>
11281 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11282 <76> DW_AT_byte_size : 4
11283 <77> DW_AT_encoding : 5 (signed)
11285 imports the wrong die ( 0x75 instead of 0x58 ).
11286 This case will be ignored until the gcc bug is fixed. */
11290 /* Figure out the local name after import. */
11291 import_alias
= dwarf2_name (die
, cu
);
11293 /* Figure out where the statement is being imported to. */
11294 import_prefix
= determine_prefix (die
, cu
);
11296 /* Figure out what the scope of the imported die is and prepend it
11297 to the name of the imported die. */
11298 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11300 if (imported_die
->tag
!= DW_TAG_namespace
11301 && imported_die
->tag
!= DW_TAG_module
)
11303 imported_declaration
= imported_name
;
11304 canonical_name
= imported_name_prefix
;
11306 else if (strlen (imported_name_prefix
) > 0)
11307 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11308 imported_name_prefix
,
11309 (cu
->language
== language_d
? "." : "::"),
11310 imported_name
, (char *) NULL
);
11312 canonical_name
= imported_name
;
11314 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11315 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11316 child_die
= sibling_die (child_die
))
11318 /* DWARF-4: A Fortran use statement with a “rename list” may be
11319 represented by an imported module entry with an import attribute
11320 referring to the module and owned entries corresponding to those
11321 entities that are renamed as part of being imported. */
11323 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11325 complaint (&symfile_complaints
,
11326 _("child DW_TAG_imported_declaration expected "
11327 "- DIE at 0x%x [in module %s]"),
11328 to_underlying (child_die
->sect_off
), objfile_name (objfile
));
11332 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11333 if (import_attr
== NULL
)
11335 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11336 dwarf_tag_name (child_die
->tag
));
11341 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11343 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11344 if (imported_name
== NULL
)
11346 complaint (&symfile_complaints
,
11347 _("child DW_TAG_imported_declaration has unknown "
11348 "imported name - DIE at 0x%x [in module %s]"),
11349 to_underlying (child_die
->sect_off
), objfile_name (objfile
));
11353 excludes
.push_back (imported_name
);
11355 process_die (child_die
, cu
);
11358 add_using_directive (using_directives (cu
->language
),
11362 imported_declaration
,
11365 &objfile
->objfile_obstack
);
11368 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11369 types, but gives them a size of zero. Starting with version 14,
11370 ICC is compatible with GCC. */
11373 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11375 if (!cu
->checked_producer
)
11376 check_producer (cu
);
11378 return cu
->producer_is_icc_lt_14
;
11381 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11382 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11383 this, it was first present in GCC release 4.3.0. */
11386 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11388 if (!cu
->checked_producer
)
11389 check_producer (cu
);
11391 return cu
->producer_is_gcc_lt_4_3
;
11394 static file_and_directory
11395 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11397 file_and_directory res
;
11399 /* Find the filename. Do not use dwarf2_name here, since the filename
11400 is not a source language identifier. */
11401 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11402 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11404 if (res
.comp_dir
== NULL
11405 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11406 && IS_ABSOLUTE_PATH (res
.name
))
11408 res
.comp_dir_storage
= ldirname (res
.name
);
11409 if (!res
.comp_dir_storage
.empty ())
11410 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11412 if (res
.comp_dir
!= NULL
)
11414 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11415 directory, get rid of it. */
11416 const char *cp
= strchr (res
.comp_dir
, ':');
11418 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11419 res
.comp_dir
= cp
+ 1;
11422 if (res
.name
== NULL
)
11423 res
.name
= "<unknown>";
11428 /* Handle DW_AT_stmt_list for a compilation unit.
11429 DIE is the DW_TAG_compile_unit die for CU.
11430 COMP_DIR is the compilation directory. LOWPC is passed to
11431 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11434 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11435 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11437 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11438 struct attribute
*attr
;
11439 struct line_header line_header_local
;
11440 hashval_t line_header_local_hash
;
11442 int decode_mapping
;
11444 gdb_assert (! cu
->per_cu
->is_debug_types
);
11446 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11450 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11452 /* The line header hash table is only created if needed (it exists to
11453 prevent redundant reading of the line table for partial_units).
11454 If we're given a partial_unit, we'll need it. If we're given a
11455 compile_unit, then use the line header hash table if it's already
11456 created, but don't create one just yet. */
11458 if (dwarf2_per_objfile
->line_header_hash
== NULL
11459 && die
->tag
== DW_TAG_partial_unit
)
11461 dwarf2_per_objfile
->line_header_hash
11462 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11463 line_header_eq_voidp
,
11464 free_line_header_voidp
,
11465 &objfile
->objfile_obstack
,
11466 hashtab_obstack_allocate
,
11467 dummy_obstack_deallocate
);
11470 line_header_local
.sect_off
= line_offset
;
11471 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11472 line_header_local_hash
= line_header_hash (&line_header_local
);
11473 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11475 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11476 &line_header_local
,
11477 line_header_local_hash
, NO_INSERT
);
11479 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11480 is not present in *SLOT (since if there is something in *SLOT then
11481 it will be for a partial_unit). */
11482 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11484 gdb_assert (*slot
!= NULL
);
11485 cu
->line_header
= (struct line_header
*) *slot
;
11490 /* dwarf_decode_line_header does not yet provide sufficient information.
11491 We always have to call also dwarf_decode_lines for it. */
11492 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11496 cu
->line_header
= lh
.release ();
11497 cu
->line_header_die_owner
= die
;
11499 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11503 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11504 &line_header_local
,
11505 line_header_local_hash
, INSERT
);
11506 gdb_assert (slot
!= NULL
);
11508 if (slot
!= NULL
&& *slot
== NULL
)
11510 /* This newly decoded line number information unit will be owned
11511 by line_header_hash hash table. */
11512 *slot
= cu
->line_header
;
11513 cu
->line_header_die_owner
= NULL
;
11517 /* We cannot free any current entry in (*slot) as that struct line_header
11518 may be already used by multiple CUs. Create only temporary decoded
11519 line_header for this CU - it may happen at most once for each line
11520 number information unit. And if we're not using line_header_hash
11521 then this is what we want as well. */
11522 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11524 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11525 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11530 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11533 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11535 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11536 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11537 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11538 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11539 struct attribute
*attr
;
11540 struct die_info
*child_die
;
11541 CORE_ADDR baseaddr
;
11543 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11545 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11547 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11548 from finish_block. */
11549 if (lowpc
== ((CORE_ADDR
) -1))
11551 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11553 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11555 prepare_one_comp_unit (cu
, die
, cu
->language
);
11557 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11558 standardised yet. As a workaround for the language detection we fall
11559 back to the DW_AT_producer string. */
11560 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11561 cu
->language
= language_opencl
;
11563 /* Similar hack for Go. */
11564 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11565 set_cu_language (DW_LANG_Go
, cu
);
11567 dwarf2_start_symtab (cu
, fnd
.name
, fnd
.comp_dir
, lowpc
);
11569 /* Decode line number information if present. We do this before
11570 processing child DIEs, so that the line header table is available
11571 for DW_AT_decl_file. */
11572 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11574 /* Process all dies in compilation unit. */
11575 if (die
->child
!= NULL
)
11577 child_die
= die
->child
;
11578 while (child_die
&& child_die
->tag
)
11580 process_die (child_die
, cu
);
11581 child_die
= sibling_die (child_die
);
11585 /* Decode macro information, if present. Dwarf 2 macro information
11586 refers to information in the line number info statement program
11587 header, so we can only read it if we've read the header
11589 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11591 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11592 if (attr
&& cu
->line_header
)
11594 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11595 complaint (&symfile_complaints
,
11596 _("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11598 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11602 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11603 if (attr
&& cu
->line_header
)
11605 unsigned int macro_offset
= DW_UNSND (attr
);
11607 dwarf_decode_macros (cu
, macro_offset
, 0);
11612 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
11613 Create the set of symtabs used by this TU, or if this TU is sharing
11614 symtabs with another TU and the symtabs have already been created
11615 then restore those symtabs in the line header.
11616 We don't need the pc/line-number mapping for type units. */
11619 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
11621 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
11622 struct type_unit_group
*tu_group
;
11624 struct attribute
*attr
;
11626 struct signatured_type
*sig_type
;
11628 gdb_assert (per_cu
->is_debug_types
);
11629 sig_type
= (struct signatured_type
*) per_cu
;
11631 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11633 /* If we're using .gdb_index (includes -readnow) then
11634 per_cu->type_unit_group may not have been set up yet. */
11635 if (sig_type
->type_unit_group
== NULL
)
11636 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
11637 tu_group
= sig_type
->type_unit_group
;
11639 /* If we've already processed this stmt_list there's no real need to
11640 do it again, we could fake it and just recreate the part we need
11641 (file name,index -> symtab mapping). If data shows this optimization
11642 is useful we can do it then. */
11643 first_time
= tu_group
->compunit_symtab
== NULL
;
11645 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11650 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11651 lh
= dwarf_decode_line_header (line_offset
, cu
);
11656 dwarf2_start_symtab (cu
, "", NULL
, 0);
11659 gdb_assert (tu_group
->symtabs
== NULL
);
11660 restart_symtab (tu_group
->compunit_symtab
, "", 0);
11665 cu
->line_header
= lh
.release ();
11666 cu
->line_header_die_owner
= die
;
11670 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
11672 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11673 still initializing it, and our caller (a few levels up)
11674 process_full_type_unit still needs to know if this is the first
11677 tu_group
->num_symtabs
= cu
->line_header
->file_names
.size ();
11678 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11679 cu
->line_header
->file_names
.size ());
11681 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
11683 file_entry
&fe
= cu
->line_header
->file_names
[i
];
11685 dwarf2_start_subfile (fe
.name
, fe
.include_dir (cu
->line_header
));
11687 if (current_subfile
->symtab
== NULL
)
11689 /* NOTE: start_subfile will recognize when it's been
11690 passed a file it has already seen. So we can't
11691 assume there's a simple mapping from
11692 cu->line_header->file_names to subfiles, plus
11693 cu->line_header->file_names may contain dups. */
11694 current_subfile
->symtab
11695 = allocate_symtab (cust
, current_subfile
->name
);
11698 fe
.symtab
= current_subfile
->symtab
;
11699 tu_group
->symtabs
[i
] = fe
.symtab
;
11704 restart_symtab (tu_group
->compunit_symtab
, "", 0);
11706 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
11708 file_entry
&fe
= cu
->line_header
->file_names
[i
];
11710 fe
.symtab
= tu_group
->symtabs
[i
];
11714 /* The main symtab is allocated last. Type units don't have DW_AT_name
11715 so they don't have a "real" (so to speak) symtab anyway.
11716 There is later code that will assign the main symtab to all symbols
11717 that don't have one. We need to handle the case of a symbol with a
11718 missing symtab (DW_AT_decl_file) anyway. */
11721 /* Process DW_TAG_type_unit.
11722 For TUs we want to skip the first top level sibling if it's not the
11723 actual type being defined by this TU. In this case the first top
11724 level sibling is there to provide context only. */
11727 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11729 struct die_info
*child_die
;
11731 prepare_one_comp_unit (cu
, die
, language_minimal
);
11733 /* Initialize (or reinitialize) the machinery for building symtabs.
11734 We do this before processing child DIEs, so that the line header table
11735 is available for DW_AT_decl_file. */
11736 setup_type_unit_groups (die
, cu
);
11738 if (die
->child
!= NULL
)
11740 child_die
= die
->child
;
11741 while (child_die
&& child_die
->tag
)
11743 process_die (child_die
, cu
);
11744 child_die
= sibling_die (child_die
);
11751 http://gcc.gnu.org/wiki/DebugFission
11752 http://gcc.gnu.org/wiki/DebugFissionDWP
11754 To simplify handling of both DWO files ("object" files with the DWARF info)
11755 and DWP files (a file with the DWOs packaged up into one file), we treat
11756 DWP files as having a collection of virtual DWO files. */
11759 hash_dwo_file (const void *item
)
11761 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11764 hash
= htab_hash_string (dwo_file
->dwo_name
);
11765 if (dwo_file
->comp_dir
!= NULL
)
11766 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11771 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11773 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11774 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11776 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11778 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11779 return lhs
->comp_dir
== rhs
->comp_dir
;
11780 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11783 /* Allocate a hash table for DWO files. */
11786 allocate_dwo_file_hash_table (void)
11788 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11790 return htab_create_alloc_ex (41,
11794 &objfile
->objfile_obstack
,
11795 hashtab_obstack_allocate
,
11796 dummy_obstack_deallocate
);
11799 /* Lookup DWO file DWO_NAME. */
11802 lookup_dwo_file_slot (const char *dwo_name
, const char *comp_dir
)
11804 struct dwo_file find_entry
;
11807 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11808 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
11810 memset (&find_entry
, 0, sizeof (find_entry
));
11811 find_entry
.dwo_name
= dwo_name
;
11812 find_entry
.comp_dir
= comp_dir
;
11813 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
11819 hash_dwo_unit (const void *item
)
11821 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11823 /* This drops the top 32 bits of the id, but is ok for a hash. */
11824 return dwo_unit
->signature
;
11828 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11830 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11831 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11833 /* The signature is assumed to be unique within the DWO file.
11834 So while object file CU dwo_id's always have the value zero,
11835 that's OK, assuming each object file DWO file has only one CU,
11836 and that's the rule for now. */
11837 return lhs
->signature
== rhs
->signature
;
11840 /* Allocate a hash table for DWO CUs,TUs.
11841 There is one of these tables for each of CUs,TUs for each DWO file. */
11844 allocate_dwo_unit_table (struct objfile
*objfile
)
11846 /* Start out with a pretty small number.
11847 Generally DWO files contain only one CU and maybe some TUs. */
11848 return htab_create_alloc_ex (3,
11852 &objfile
->objfile_obstack
,
11853 hashtab_obstack_allocate
,
11854 dummy_obstack_deallocate
);
11857 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
11859 struct create_dwo_cu_data
11861 struct dwo_file
*dwo_file
;
11862 struct dwo_unit dwo_unit
;
11865 /* die_reader_func for create_dwo_cu. */
11868 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11869 const gdb_byte
*info_ptr
,
11870 struct die_info
*comp_unit_die
,
11874 struct dwarf2_cu
*cu
= reader
->cu
;
11875 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11876 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11877 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
11878 struct dwo_file
*dwo_file
= data
->dwo_file
;
11879 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
11880 struct attribute
*attr
;
11882 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
11885 complaint (&symfile_complaints
,
11886 _("Dwarf Error: debug entry at offset 0x%x is missing"
11887 " its dwo_id [in module %s]"),
11888 to_underlying (sect_off
), dwo_file
->dwo_name
);
11892 dwo_unit
->dwo_file
= dwo_file
;
11893 dwo_unit
->signature
= DW_UNSND (attr
);
11894 dwo_unit
->section
= section
;
11895 dwo_unit
->sect_off
= sect_off
;
11896 dwo_unit
->length
= cu
->per_cu
->length
;
11898 if (dwarf_read_debug
)
11899 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id %s\n",
11900 to_underlying (sect_off
),
11901 hex_string (dwo_unit
->signature
));
11904 /* Create the dwo_units for the CUs in a DWO_FILE.
11905 Note: This function processes DWO files only, not DWP files. */
11908 create_cus_hash_table (struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
11911 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11912 const gdb_byte
*info_ptr
, *end_ptr
;
11914 dwarf2_read_section (objfile
, §ion
);
11915 info_ptr
= section
.buffer
;
11917 if (info_ptr
== NULL
)
11920 if (dwarf_read_debug
)
11922 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11923 get_section_name (§ion
),
11924 get_section_file_name (§ion
));
11927 end_ptr
= info_ptr
+ section
.size
;
11928 while (info_ptr
< end_ptr
)
11930 struct dwarf2_per_cu_data per_cu
;
11931 struct create_dwo_cu_data create_dwo_cu_data
;
11932 struct dwo_unit
*dwo_unit
;
11934 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11936 memset (&create_dwo_cu_data
.dwo_unit
, 0,
11937 sizeof (create_dwo_cu_data
.dwo_unit
));
11938 memset (&per_cu
, 0, sizeof (per_cu
));
11939 per_cu
.objfile
= objfile
;
11940 per_cu
.is_debug_types
= 0;
11941 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11942 per_cu
.section
= §ion
;
11943 create_dwo_cu_data
.dwo_file
= &dwo_file
;
11945 init_cutu_and_read_dies_no_follow (
11946 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
11947 info_ptr
+= per_cu
.length
;
11949 // If the unit could not be parsed, skip it.
11950 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
11953 if (cus_htab
== NULL
)
11954 cus_htab
= allocate_dwo_unit_table (objfile
);
11956 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11957 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
11958 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
11959 gdb_assert (slot
!= NULL
);
11962 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11963 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11965 complaint (&symfile_complaints
,
11966 _("debug cu entry at offset 0x%x is duplicate to"
11967 " the entry at offset 0x%x, signature %s"),
11968 to_underlying (sect_off
), to_underlying (dup_sect_off
),
11969 hex_string (dwo_unit
->signature
));
11971 *slot
= (void *)dwo_unit
;
11975 /* DWP file .debug_{cu,tu}_index section format:
11976 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11980 Both index sections have the same format, and serve to map a 64-bit
11981 signature to a set of section numbers. Each section begins with a header,
11982 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11983 indexes, and a pool of 32-bit section numbers. The index sections will be
11984 aligned at 8-byte boundaries in the file.
11986 The index section header consists of:
11988 V, 32 bit version number
11990 N, 32 bit number of compilation units or type units in the index
11991 M, 32 bit number of slots in the hash table
11993 Numbers are recorded using the byte order of the application binary.
11995 The hash table begins at offset 16 in the section, and consists of an array
11996 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11997 order of the application binary). Unused slots in the hash table are 0.
11998 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12000 The parallel table begins immediately after the hash table
12001 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12002 array of 32-bit indexes (using the byte order of the application binary),
12003 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12004 table contains a 32-bit index into the pool of section numbers. For unused
12005 hash table slots, the corresponding entry in the parallel table will be 0.
12007 The pool of section numbers begins immediately following the hash table
12008 (at offset 16 + 12 * M from the beginning of the section). The pool of
12009 section numbers consists of an array of 32-bit words (using the byte order
12010 of the application binary). Each item in the array is indexed starting
12011 from 0. The hash table entry provides the index of the first section
12012 number in the set. Additional section numbers in the set follow, and the
12013 set is terminated by a 0 entry (section number 0 is not used in ELF).
12015 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12016 section must be the first entry in the set, and the .debug_abbrev.dwo must
12017 be the second entry. Other members of the set may follow in any order.
12023 DWP Version 2 combines all the .debug_info, etc. sections into one,
12024 and the entries in the index tables are now offsets into these sections.
12025 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12028 Index Section Contents:
12030 Hash Table of Signatures dwp_hash_table.hash_table
12031 Parallel Table of Indices dwp_hash_table.unit_table
12032 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12033 Table of Section Sizes dwp_hash_table.v2.sizes
12035 The index section header consists of:
12037 V, 32 bit version number
12038 L, 32 bit number of columns in the table of section offsets
12039 N, 32 bit number of compilation units or type units in the index
12040 M, 32 bit number of slots in the hash table
12042 Numbers are recorded using the byte order of the application binary.
12044 The hash table has the same format as version 1.
12045 The parallel table of indices has the same format as version 1,
12046 except that the entries are origin-1 indices into the table of sections
12047 offsets and the table of section sizes.
12049 The table of offsets begins immediately following the parallel table
12050 (at offset 16 + 12 * M from the beginning of the section). The table is
12051 a two-dimensional array of 32-bit words (using the byte order of the
12052 application binary), with L columns and N+1 rows, in row-major order.
12053 Each row in the array is indexed starting from 0. The first row provides
12054 a key to the remaining rows: each column in this row provides an identifier
12055 for a debug section, and the offsets in the same column of subsequent rows
12056 refer to that section. The section identifiers are:
12058 DW_SECT_INFO 1 .debug_info.dwo
12059 DW_SECT_TYPES 2 .debug_types.dwo
12060 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12061 DW_SECT_LINE 4 .debug_line.dwo
12062 DW_SECT_LOC 5 .debug_loc.dwo
12063 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12064 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12065 DW_SECT_MACRO 8 .debug_macro.dwo
12067 The offsets provided by the CU and TU index sections are the base offsets
12068 for the contributions made by each CU or TU to the corresponding section
12069 in the package file. Each CU and TU header contains an abbrev_offset
12070 field, used to find the abbreviations table for that CU or TU within the
12071 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12072 be interpreted as relative to the base offset given in the index section.
12073 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12074 should be interpreted as relative to the base offset for .debug_line.dwo,
12075 and offsets into other debug sections obtained from DWARF attributes should
12076 also be interpreted as relative to the corresponding base offset.
12078 The table of sizes begins immediately following the table of offsets.
12079 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12080 with L columns and N rows, in row-major order. Each row in the array is
12081 indexed starting from 1 (row 0 is shared by the two tables).
12085 Hash table lookup is handled the same in version 1 and 2:
12087 We assume that N and M will not exceed 2^32 - 1.
12088 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12090 Given a 64-bit compilation unit signature or a type signature S, an entry
12091 in the hash table is located as follows:
12093 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12094 the low-order k bits all set to 1.
12096 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12098 3) If the hash table entry at index H matches the signature, use that
12099 entry. If the hash table entry at index H is unused (all zeroes),
12100 terminate the search: the signature is not present in the table.
12102 4) Let H = (H + H') modulo M. Repeat at Step 3.
12104 Because M > N and H' and M are relatively prime, the search is guaranteed
12105 to stop at an unused slot or find the match. */
12107 /* Create a hash table to map DWO IDs to their CU/TU entry in
12108 .debug_{info,types}.dwo in DWP_FILE.
12109 Returns NULL if there isn't one.
12110 Note: This function processes DWP files only, not DWO files. */
12112 static struct dwp_hash_table
*
12113 create_dwp_hash_table (struct dwp_file
*dwp_file
, int is_debug_types
)
12115 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12116 bfd
*dbfd
= dwp_file
->dbfd
;
12117 const gdb_byte
*index_ptr
, *index_end
;
12118 struct dwarf2_section_info
*index
;
12119 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12120 struct dwp_hash_table
*htab
;
12122 if (is_debug_types
)
12123 index
= &dwp_file
->sections
.tu_index
;
12125 index
= &dwp_file
->sections
.cu_index
;
12127 if (dwarf2_section_empty_p (index
))
12129 dwarf2_read_section (objfile
, index
);
12131 index_ptr
= index
->buffer
;
12132 index_end
= index_ptr
+ index
->size
;
12134 version
= read_4_bytes (dbfd
, index_ptr
);
12137 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12141 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12143 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12146 if (version
!= 1 && version
!= 2)
12148 error (_("Dwarf Error: unsupported DWP file version (%s)"
12149 " [in module %s]"),
12150 pulongest (version
), dwp_file
->name
);
12152 if (nr_slots
!= (nr_slots
& -nr_slots
))
12154 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12155 " is not power of 2 [in module %s]"),
12156 pulongest (nr_slots
), dwp_file
->name
);
12159 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12160 htab
->version
= version
;
12161 htab
->nr_columns
= nr_columns
;
12162 htab
->nr_units
= nr_units
;
12163 htab
->nr_slots
= nr_slots
;
12164 htab
->hash_table
= index_ptr
;
12165 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12167 /* Exit early if the table is empty. */
12168 if (nr_slots
== 0 || nr_units
== 0
12169 || (version
== 2 && nr_columns
== 0))
12171 /* All must be zero. */
12172 if (nr_slots
!= 0 || nr_units
!= 0
12173 || (version
== 2 && nr_columns
!= 0))
12175 complaint (&symfile_complaints
,
12176 _("Empty DWP but nr_slots,nr_units,nr_columns not"
12177 " all zero [in modules %s]"),
12185 htab
->section_pool
.v1
.indices
=
12186 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12187 /* It's harder to decide whether the section is too small in v1.
12188 V1 is deprecated anyway so we punt. */
12192 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12193 int *ids
= htab
->section_pool
.v2
.section_ids
;
12194 /* Reverse map for error checking. */
12195 int ids_seen
[DW_SECT_MAX
+ 1];
12198 if (nr_columns
< 2)
12200 error (_("Dwarf Error: bad DWP hash table, too few columns"
12201 " in section table [in module %s]"),
12204 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12206 error (_("Dwarf Error: bad DWP hash table, too many columns"
12207 " in section table [in module %s]"),
12210 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12211 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12212 for (i
= 0; i
< nr_columns
; ++i
)
12214 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12216 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12218 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12219 " in section table [in module %s]"),
12220 id
, dwp_file
->name
);
12222 if (ids_seen
[id
] != -1)
12224 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12225 " id %d in section table [in module %s]"),
12226 id
, dwp_file
->name
);
12231 /* Must have exactly one info or types section. */
12232 if (((ids_seen
[DW_SECT_INFO
] != -1)
12233 + (ids_seen
[DW_SECT_TYPES
] != -1))
12236 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12237 " DWO info/types section [in module %s]"),
12240 /* Must have an abbrev section. */
12241 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12243 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12244 " section [in module %s]"),
12247 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12248 htab
->section_pool
.v2
.sizes
=
12249 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12250 * nr_units
* nr_columns
);
12251 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12252 * nr_units
* nr_columns
))
12255 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12256 " [in module %s]"),
12264 /* Update SECTIONS with the data from SECTP.
12266 This function is like the other "locate" section routines that are
12267 passed to bfd_map_over_sections, but in this context the sections to
12268 read comes from the DWP V1 hash table, not the full ELF section table.
12270 The result is non-zero for success, or zero if an error was found. */
12273 locate_v1_virtual_dwo_sections (asection
*sectp
,
12274 struct virtual_v1_dwo_sections
*sections
)
12276 const struct dwop_section_names
*names
= &dwop_section_names
;
12278 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12280 /* There can be only one. */
12281 if (sections
->abbrev
.s
.section
!= NULL
)
12283 sections
->abbrev
.s
.section
= sectp
;
12284 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12286 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12287 || section_is_p (sectp
->name
, &names
->types_dwo
))
12289 /* There can be only one. */
12290 if (sections
->info_or_types
.s
.section
!= NULL
)
12292 sections
->info_or_types
.s
.section
= sectp
;
12293 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
12295 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12297 /* There can be only one. */
12298 if (sections
->line
.s
.section
!= NULL
)
12300 sections
->line
.s
.section
= sectp
;
12301 sections
->line
.size
= bfd_get_section_size (sectp
);
12303 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12305 /* There can be only one. */
12306 if (sections
->loc
.s
.section
!= NULL
)
12308 sections
->loc
.s
.section
= sectp
;
12309 sections
->loc
.size
= bfd_get_section_size (sectp
);
12311 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12313 /* There can be only one. */
12314 if (sections
->macinfo
.s
.section
!= NULL
)
12316 sections
->macinfo
.s
.section
= sectp
;
12317 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12319 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12321 /* There can be only one. */
12322 if (sections
->macro
.s
.section
!= NULL
)
12324 sections
->macro
.s
.section
= sectp
;
12325 sections
->macro
.size
= bfd_get_section_size (sectp
);
12327 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12329 /* There can be only one. */
12330 if (sections
->str_offsets
.s
.section
!= NULL
)
12332 sections
->str_offsets
.s
.section
= sectp
;
12333 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12337 /* No other kind of section is valid. */
12344 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12345 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12346 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12347 This is for DWP version 1 files. */
12349 static struct dwo_unit
*
12350 create_dwo_unit_in_dwp_v1 (struct dwp_file
*dwp_file
,
12351 uint32_t unit_index
,
12352 const char *comp_dir
,
12353 ULONGEST signature
, int is_debug_types
)
12355 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12356 const struct dwp_hash_table
*dwp_htab
=
12357 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12358 bfd
*dbfd
= dwp_file
->dbfd
;
12359 const char *kind
= is_debug_types
? "TU" : "CU";
12360 struct dwo_file
*dwo_file
;
12361 struct dwo_unit
*dwo_unit
;
12362 struct virtual_v1_dwo_sections sections
;
12363 void **dwo_file_slot
;
12366 gdb_assert (dwp_file
->version
== 1);
12368 if (dwarf_read_debug
)
12370 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12372 pulongest (unit_index
), hex_string (signature
),
12376 /* Fetch the sections of this DWO unit.
12377 Put a limit on the number of sections we look for so that bad data
12378 doesn't cause us to loop forever. */
12380 #define MAX_NR_V1_DWO_SECTIONS \
12381 (1 /* .debug_info or .debug_types */ \
12382 + 1 /* .debug_abbrev */ \
12383 + 1 /* .debug_line */ \
12384 + 1 /* .debug_loc */ \
12385 + 1 /* .debug_str_offsets */ \
12386 + 1 /* .debug_macro or .debug_macinfo */ \
12387 + 1 /* trailing zero */)
12389 memset (§ions
, 0, sizeof (sections
));
12391 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12394 uint32_t section_nr
=
12395 read_4_bytes (dbfd
,
12396 dwp_htab
->section_pool
.v1
.indices
12397 + (unit_index
+ i
) * sizeof (uint32_t));
12399 if (section_nr
== 0)
12401 if (section_nr
>= dwp_file
->num_sections
)
12403 error (_("Dwarf Error: bad DWP hash table, section number too large"
12404 " [in module %s]"),
12408 sectp
= dwp_file
->elf_sections
[section_nr
];
12409 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12411 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12412 " [in module %s]"),
12418 || dwarf2_section_empty_p (§ions
.info_or_types
)
12419 || dwarf2_section_empty_p (§ions
.abbrev
))
12421 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12422 " [in module %s]"),
12425 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12427 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12428 " [in module %s]"),
12432 /* It's easier for the rest of the code if we fake a struct dwo_file and
12433 have dwo_unit "live" in that. At least for now.
12435 The DWP file can be made up of a random collection of CUs and TUs.
12436 However, for each CU + set of TUs that came from the same original DWO
12437 file, we can combine them back into a virtual DWO file to save space
12438 (fewer struct dwo_file objects to allocate). Remember that for really
12439 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12441 std::string virtual_dwo_name
=
12442 string_printf ("virtual-dwo/%d-%d-%d-%d",
12443 get_section_id (§ions
.abbrev
),
12444 get_section_id (§ions
.line
),
12445 get_section_id (§ions
.loc
),
12446 get_section_id (§ions
.str_offsets
));
12447 /* Can we use an existing virtual DWO file? */
12448 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
.c_str (), comp_dir
);
12449 /* Create one if necessary. */
12450 if (*dwo_file_slot
== NULL
)
12452 if (dwarf_read_debug
)
12454 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12455 virtual_dwo_name
.c_str ());
12457 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12459 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12460 virtual_dwo_name
.c_str (),
12461 virtual_dwo_name
.size ());
12462 dwo_file
->comp_dir
= comp_dir
;
12463 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12464 dwo_file
->sections
.line
= sections
.line
;
12465 dwo_file
->sections
.loc
= sections
.loc
;
12466 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12467 dwo_file
->sections
.macro
= sections
.macro
;
12468 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12469 /* The "str" section is global to the entire DWP file. */
12470 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12471 /* The info or types section is assigned below to dwo_unit,
12472 there's no need to record it in dwo_file.
12473 Also, we can't simply record type sections in dwo_file because
12474 we record a pointer into the vector in dwo_unit. As we collect more
12475 types we'll grow the vector and eventually have to reallocate space
12476 for it, invalidating all copies of pointers into the previous
12478 *dwo_file_slot
= dwo_file
;
12482 if (dwarf_read_debug
)
12484 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12485 virtual_dwo_name
.c_str ());
12487 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12490 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12491 dwo_unit
->dwo_file
= dwo_file
;
12492 dwo_unit
->signature
= signature
;
12493 dwo_unit
->section
=
12494 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12495 *dwo_unit
->section
= sections
.info_or_types
;
12496 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12501 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12502 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12503 piece within that section used by a TU/CU, return a virtual section
12504 of just that piece. */
12506 static struct dwarf2_section_info
12507 create_dwp_v2_section (struct dwarf2_section_info
*section
,
12508 bfd_size_type offset
, bfd_size_type size
)
12510 struct dwarf2_section_info result
;
12513 gdb_assert (section
!= NULL
);
12514 gdb_assert (!section
->is_virtual
);
12516 memset (&result
, 0, sizeof (result
));
12517 result
.s
.containing_section
= section
;
12518 result
.is_virtual
= 1;
12523 sectp
= get_section_bfd_section (section
);
12525 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12526 bounds of the real section. This is a pretty-rare event, so just
12527 flag an error (easier) instead of a warning and trying to cope. */
12529 || offset
+ size
> bfd_get_section_size (sectp
))
12531 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12532 " in section %s [in module %s]"),
12533 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
12534 objfile_name (dwarf2_per_objfile
->objfile
));
12537 result
.virtual_offset
= offset
;
12538 result
.size
= size
;
12542 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12543 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12544 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12545 This is for DWP version 2 files. */
12547 static struct dwo_unit
*
12548 create_dwo_unit_in_dwp_v2 (struct dwp_file
*dwp_file
,
12549 uint32_t unit_index
,
12550 const char *comp_dir
,
12551 ULONGEST signature
, int is_debug_types
)
12553 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12554 const struct dwp_hash_table
*dwp_htab
=
12555 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12556 bfd
*dbfd
= dwp_file
->dbfd
;
12557 const char *kind
= is_debug_types
? "TU" : "CU";
12558 struct dwo_file
*dwo_file
;
12559 struct dwo_unit
*dwo_unit
;
12560 struct virtual_v2_dwo_sections sections
;
12561 void **dwo_file_slot
;
12564 gdb_assert (dwp_file
->version
== 2);
12566 if (dwarf_read_debug
)
12568 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12570 pulongest (unit_index
), hex_string (signature
),
12574 /* Fetch the section offsets of this DWO unit. */
12576 memset (§ions
, 0, sizeof (sections
));
12578 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12580 uint32_t offset
= read_4_bytes (dbfd
,
12581 dwp_htab
->section_pool
.v2
.offsets
12582 + (((unit_index
- 1) * dwp_htab
->nr_columns
12584 * sizeof (uint32_t)));
12585 uint32_t size
= read_4_bytes (dbfd
,
12586 dwp_htab
->section_pool
.v2
.sizes
12587 + (((unit_index
- 1) * dwp_htab
->nr_columns
12589 * sizeof (uint32_t)));
12591 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12594 case DW_SECT_TYPES
:
12595 sections
.info_or_types_offset
= offset
;
12596 sections
.info_or_types_size
= size
;
12598 case DW_SECT_ABBREV
:
12599 sections
.abbrev_offset
= offset
;
12600 sections
.abbrev_size
= size
;
12603 sections
.line_offset
= offset
;
12604 sections
.line_size
= size
;
12607 sections
.loc_offset
= offset
;
12608 sections
.loc_size
= size
;
12610 case DW_SECT_STR_OFFSETS
:
12611 sections
.str_offsets_offset
= offset
;
12612 sections
.str_offsets_size
= size
;
12614 case DW_SECT_MACINFO
:
12615 sections
.macinfo_offset
= offset
;
12616 sections
.macinfo_size
= size
;
12618 case DW_SECT_MACRO
:
12619 sections
.macro_offset
= offset
;
12620 sections
.macro_size
= size
;
12625 /* It's easier for the rest of the code if we fake a struct dwo_file and
12626 have dwo_unit "live" in that. At least for now.
12628 The DWP file can be made up of a random collection of CUs and TUs.
12629 However, for each CU + set of TUs that came from the same original DWO
12630 file, we can combine them back into a virtual DWO file to save space
12631 (fewer struct dwo_file objects to allocate). Remember that for really
12632 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12634 std::string virtual_dwo_name
=
12635 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12636 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12637 (long) (sections
.line_size
? sections
.line_offset
: 0),
12638 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12639 (long) (sections
.str_offsets_size
12640 ? sections
.str_offsets_offset
: 0));
12641 /* Can we use an existing virtual DWO file? */
12642 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
.c_str (), comp_dir
);
12643 /* Create one if necessary. */
12644 if (*dwo_file_slot
== NULL
)
12646 if (dwarf_read_debug
)
12648 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12649 virtual_dwo_name
.c_str ());
12651 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12653 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12654 virtual_dwo_name
.c_str (),
12655 virtual_dwo_name
.size ());
12656 dwo_file
->comp_dir
= comp_dir
;
12657 dwo_file
->sections
.abbrev
=
12658 create_dwp_v2_section (&dwp_file
->sections
.abbrev
,
12659 sections
.abbrev_offset
, sections
.abbrev_size
);
12660 dwo_file
->sections
.line
=
12661 create_dwp_v2_section (&dwp_file
->sections
.line
,
12662 sections
.line_offset
, sections
.line_size
);
12663 dwo_file
->sections
.loc
=
12664 create_dwp_v2_section (&dwp_file
->sections
.loc
,
12665 sections
.loc_offset
, sections
.loc_size
);
12666 dwo_file
->sections
.macinfo
=
12667 create_dwp_v2_section (&dwp_file
->sections
.macinfo
,
12668 sections
.macinfo_offset
, sections
.macinfo_size
);
12669 dwo_file
->sections
.macro
=
12670 create_dwp_v2_section (&dwp_file
->sections
.macro
,
12671 sections
.macro_offset
, sections
.macro_size
);
12672 dwo_file
->sections
.str_offsets
=
12673 create_dwp_v2_section (&dwp_file
->sections
.str_offsets
,
12674 sections
.str_offsets_offset
,
12675 sections
.str_offsets_size
);
12676 /* The "str" section is global to the entire DWP file. */
12677 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12678 /* The info or types section is assigned below to dwo_unit,
12679 there's no need to record it in dwo_file.
12680 Also, we can't simply record type sections in dwo_file because
12681 we record a pointer into the vector in dwo_unit. As we collect more
12682 types we'll grow the vector and eventually have to reallocate space
12683 for it, invalidating all copies of pointers into the previous
12685 *dwo_file_slot
= dwo_file
;
12689 if (dwarf_read_debug
)
12691 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12692 virtual_dwo_name
.c_str ());
12694 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12697 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12698 dwo_unit
->dwo_file
= dwo_file
;
12699 dwo_unit
->signature
= signature
;
12700 dwo_unit
->section
=
12701 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12702 *dwo_unit
->section
= create_dwp_v2_section (is_debug_types
12703 ? &dwp_file
->sections
.types
12704 : &dwp_file
->sections
.info
,
12705 sections
.info_or_types_offset
,
12706 sections
.info_or_types_size
);
12707 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12712 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12713 Returns NULL if the signature isn't found. */
12715 static struct dwo_unit
*
12716 lookup_dwo_unit_in_dwp (struct dwp_file
*dwp_file
, const char *comp_dir
,
12717 ULONGEST signature
, int is_debug_types
)
12719 const struct dwp_hash_table
*dwp_htab
=
12720 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12721 bfd
*dbfd
= dwp_file
->dbfd
;
12722 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12723 uint32_t hash
= signature
& mask
;
12724 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12727 struct dwo_unit find_dwo_cu
;
12729 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12730 find_dwo_cu
.signature
= signature
;
12731 slot
= htab_find_slot (is_debug_types
12732 ? dwp_file
->loaded_tus
12733 : dwp_file
->loaded_cus
,
12734 &find_dwo_cu
, INSERT
);
12737 return (struct dwo_unit
*) *slot
;
12739 /* Use a for loop so that we don't loop forever on bad debug info. */
12740 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12742 ULONGEST signature_in_table
;
12744 signature_in_table
=
12745 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12746 if (signature_in_table
== signature
)
12748 uint32_t unit_index
=
12749 read_4_bytes (dbfd
,
12750 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12752 if (dwp_file
->version
== 1)
12754 *slot
= create_dwo_unit_in_dwp_v1 (dwp_file
, unit_index
,
12755 comp_dir
, signature
,
12760 *slot
= create_dwo_unit_in_dwp_v2 (dwp_file
, unit_index
,
12761 comp_dir
, signature
,
12764 return (struct dwo_unit
*) *slot
;
12766 if (signature_in_table
== 0)
12768 hash
= (hash
+ hash2
) & mask
;
12771 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12772 " [in module %s]"),
12776 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12777 Open the file specified by FILE_NAME and hand it off to BFD for
12778 preliminary analysis. Return a newly initialized bfd *, which
12779 includes a canonicalized copy of FILE_NAME.
12780 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12781 SEARCH_CWD is true if the current directory is to be searched.
12782 It will be searched before debug-file-directory.
12783 If successful, the file is added to the bfd include table of the
12784 objfile's bfd (see gdb_bfd_record_inclusion).
12785 If unable to find/open the file, return NULL.
12786 NOTE: This function is derived from symfile_bfd_open. */
12788 static gdb_bfd_ref_ptr
12789 try_open_dwop_file (const char *file_name
, int is_dwp
, int search_cwd
)
12792 char *absolute_name
;
12793 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12794 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12795 to debug_file_directory. */
12797 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12801 if (*debug_file_directory
!= '\0')
12802 search_path
= concat (".", dirname_separator_string
,
12803 debug_file_directory
, (char *) NULL
);
12805 search_path
= xstrdup (".");
12808 search_path
= xstrdup (debug_file_directory
);
12810 flags
= OPF_RETURN_REALPATH
;
12812 flags
|= OPF_SEARCH_IN_PATH
;
12813 desc
= openp (search_path
, flags
, file_name
,
12814 O_RDONLY
| O_BINARY
, &absolute_name
);
12815 xfree (search_path
);
12819 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
, gnutarget
, desc
));
12820 xfree (absolute_name
);
12821 if (sym_bfd
== NULL
)
12823 bfd_set_cacheable (sym_bfd
.get (), 1);
12825 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12828 /* Success. Record the bfd as having been included by the objfile's bfd.
12829 This is important because things like demangled_names_hash lives in the
12830 objfile's per_bfd space and may have references to things like symbol
12831 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12832 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12837 /* Try to open DWO file FILE_NAME.
12838 COMP_DIR is the DW_AT_comp_dir attribute.
12839 The result is the bfd handle of the file.
12840 If there is a problem finding or opening the file, return NULL.
12841 Upon success, the canonicalized path of the file is stored in the bfd,
12842 same as symfile_bfd_open. */
12844 static gdb_bfd_ref_ptr
12845 open_dwo_file (const char *file_name
, const char *comp_dir
)
12847 if (IS_ABSOLUTE_PATH (file_name
))
12848 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 0 /*search_cwd*/);
12850 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12852 if (comp_dir
!= NULL
)
12854 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
12855 file_name
, (char *) NULL
);
12857 /* NOTE: If comp_dir is a relative path, this will also try the
12858 search path, which seems useful. */
12859 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (path_to_try
, 0 /*is_dwp*/,
12860 1 /*search_cwd*/));
12861 xfree (path_to_try
);
12866 /* That didn't work, try debug-file-directory, which, despite its name,
12867 is a list of paths. */
12869 if (*debug_file_directory
== '\0')
12872 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 1 /*search_cwd*/);
12875 /* This function is mapped across the sections and remembers the offset and
12876 size of each of the DWO debugging sections we are interested in. */
12879 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12881 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12882 const struct dwop_section_names
*names
= &dwop_section_names
;
12884 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12886 dwo_sections
->abbrev
.s
.section
= sectp
;
12887 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12889 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12891 dwo_sections
->info
.s
.section
= sectp
;
12892 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
12894 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12896 dwo_sections
->line
.s
.section
= sectp
;
12897 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
12899 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12901 dwo_sections
->loc
.s
.section
= sectp
;
12902 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
12904 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12906 dwo_sections
->macinfo
.s
.section
= sectp
;
12907 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12909 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12911 dwo_sections
->macro
.s
.section
= sectp
;
12912 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
12914 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12916 dwo_sections
->str
.s
.section
= sectp
;
12917 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
12919 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12921 dwo_sections
->str_offsets
.s
.section
= sectp
;
12922 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12924 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12926 struct dwarf2_section_info type_section
;
12928 memset (&type_section
, 0, sizeof (type_section
));
12929 type_section
.s
.section
= sectp
;
12930 type_section
.size
= bfd_get_section_size (sectp
);
12931 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
12936 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12937 by PER_CU. This is for the non-DWP case.
12938 The result is NULL if DWO_NAME can't be found. */
12940 static struct dwo_file
*
12941 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12942 const char *dwo_name
, const char *comp_dir
)
12944 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12945 struct dwo_file
*dwo_file
;
12946 struct cleanup
*cleanups
;
12948 gdb_bfd_ref_ptr
dbfd (open_dwo_file (dwo_name
, comp_dir
));
12951 if (dwarf_read_debug
)
12952 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12955 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12956 dwo_file
->dwo_name
= dwo_name
;
12957 dwo_file
->comp_dir
= comp_dir
;
12958 dwo_file
->dbfd
= dbfd
.release ();
12960 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
12962 bfd_map_over_sections (dwo_file
->dbfd
, dwarf2_locate_dwo_sections
,
12963 &dwo_file
->sections
);
12965 create_cus_hash_table (*dwo_file
, dwo_file
->sections
.info
, dwo_file
->cus
);
12967 create_debug_types_hash_table (dwo_file
, dwo_file
->sections
.types
,
12970 discard_cleanups (cleanups
);
12972 if (dwarf_read_debug
)
12973 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12978 /* This function is mapped across the sections and remembers the offset and
12979 size of each of the DWP debugging sections common to version 1 and 2 that
12980 we are interested in. */
12983 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12984 void *dwp_file_ptr
)
12986 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12987 const struct dwop_section_names
*names
= &dwop_section_names
;
12988 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12990 /* Record the ELF section number for later lookup: this is what the
12991 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12992 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12993 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12995 /* Look for specific sections that we need. */
12996 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12998 dwp_file
->sections
.str
.s
.section
= sectp
;
12999 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
13001 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13003 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13004 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
13006 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13008 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13009 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
13013 /* This function is mapped across the sections and remembers the offset and
13014 size of each of the DWP version 2 debugging sections that we are interested
13015 in. This is split into a separate function because we don't know if we
13016 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13019 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13021 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13022 const struct dwop_section_names
*names
= &dwop_section_names
;
13023 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13025 /* Record the ELF section number for later lookup: this is what the
13026 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13027 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13028 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13030 /* Look for specific sections that we need. */
13031 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13033 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13034 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
13036 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13038 dwp_file
->sections
.info
.s
.section
= sectp
;
13039 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
13041 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13043 dwp_file
->sections
.line
.s
.section
= sectp
;
13044 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
13046 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13048 dwp_file
->sections
.loc
.s
.section
= sectp
;
13049 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
13051 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13053 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13054 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
13056 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13058 dwp_file
->sections
.macro
.s
.section
= sectp
;
13059 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
13061 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13063 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13064 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
13066 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13068 dwp_file
->sections
.types
.s
.section
= sectp
;
13069 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
13073 /* Hash function for dwp_file loaded CUs/TUs. */
13076 hash_dwp_loaded_cutus (const void *item
)
13078 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13080 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13081 return dwo_unit
->signature
;
13084 /* Equality function for dwp_file loaded CUs/TUs. */
13087 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13089 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13090 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13092 return dua
->signature
== dub
->signature
;
13095 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13098 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13100 return htab_create_alloc_ex (3,
13101 hash_dwp_loaded_cutus
,
13102 eq_dwp_loaded_cutus
,
13104 &objfile
->objfile_obstack
,
13105 hashtab_obstack_allocate
,
13106 dummy_obstack_deallocate
);
13109 /* Try to open DWP file FILE_NAME.
13110 The result is the bfd handle of the file.
13111 If there is a problem finding or opening the file, return NULL.
13112 Upon success, the canonicalized path of the file is stored in the bfd,
13113 same as symfile_bfd_open. */
13115 static gdb_bfd_ref_ptr
13116 open_dwp_file (const char *file_name
)
13118 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (file_name
, 1 /*is_dwp*/,
13119 1 /*search_cwd*/));
13123 /* Work around upstream bug 15652.
13124 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13125 [Whether that's a "bug" is debatable, but it is getting in our way.]
13126 We have no real idea where the dwp file is, because gdb's realpath-ing
13127 of the executable's path may have discarded the needed info.
13128 [IWBN if the dwp file name was recorded in the executable, akin to
13129 .gnu_debuglink, but that doesn't exist yet.]
13130 Strip the directory from FILE_NAME and search again. */
13131 if (*debug_file_directory
!= '\0')
13133 /* Don't implicitly search the current directory here.
13134 If the user wants to search "." to handle this case,
13135 it must be added to debug-file-directory. */
13136 return try_open_dwop_file (lbasename (file_name
), 1 /*is_dwp*/,
13143 /* Initialize the use of the DWP file for the current objfile.
13144 By convention the name of the DWP file is ${objfile}.dwp.
13145 The result is NULL if it can't be found. */
13147 static struct dwp_file
*
13148 open_and_init_dwp_file (void)
13150 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13151 struct dwp_file
*dwp_file
;
13153 /* Try to find first .dwp for the binary file before any symbolic links
13156 /* If the objfile is a debug file, find the name of the real binary
13157 file and get the name of dwp file from there. */
13158 std::string dwp_name
;
13159 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13161 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13162 const char *backlink_basename
= lbasename (backlink
->original_name
);
13164 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13167 dwp_name
= objfile
->original_name
;
13169 dwp_name
+= ".dwp";
13171 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwp_name
.c_str ()));
13173 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13175 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13176 dwp_name
= objfile_name (objfile
);
13177 dwp_name
+= ".dwp";
13178 dbfd
= open_dwp_file (dwp_name
.c_str ());
13183 if (dwarf_read_debug
)
13184 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13187 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
13188 dwp_file
->name
= bfd_get_filename (dbfd
.get ());
13189 dwp_file
->dbfd
= dbfd
.release ();
13191 /* +1: section 0 is unused */
13192 dwp_file
->num_sections
= bfd_count_sections (dwp_file
->dbfd
) + 1;
13193 dwp_file
->elf_sections
=
13194 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13195 dwp_file
->num_sections
, asection
*);
13197 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_common_dwp_sections
,
13200 dwp_file
->cus
= create_dwp_hash_table (dwp_file
, 0);
13202 dwp_file
->tus
= create_dwp_hash_table (dwp_file
, 1);
13204 /* The DWP file version is stored in the hash table. Oh well. */
13205 if (dwp_file
->cus
&& dwp_file
->tus
13206 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13208 /* Technically speaking, we should try to limp along, but this is
13209 pretty bizarre. We use pulongest here because that's the established
13210 portability solution (e.g, we cannot use %u for uint32_t). */
13211 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13212 " TU version %s [in DWP file %s]"),
13213 pulongest (dwp_file
->cus
->version
),
13214 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13218 dwp_file
->version
= dwp_file
->cus
->version
;
13219 else if (dwp_file
->tus
)
13220 dwp_file
->version
= dwp_file
->tus
->version
;
13222 dwp_file
->version
= 2;
13224 if (dwp_file
->version
== 2)
13225 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_v2_dwp_sections
,
13228 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13229 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13231 if (dwarf_read_debug
)
13233 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13234 fprintf_unfiltered (gdb_stdlog
,
13235 " %s CUs, %s TUs\n",
13236 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13237 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13243 /* Wrapper around open_and_init_dwp_file, only open it once. */
13245 static struct dwp_file
*
13246 get_dwp_file (void)
13248 if (! dwarf2_per_objfile
->dwp_checked
)
13250 dwarf2_per_objfile
->dwp_file
= open_and_init_dwp_file ();
13251 dwarf2_per_objfile
->dwp_checked
= 1;
13253 return dwarf2_per_objfile
->dwp_file
;
13256 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13257 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13258 or in the DWP file for the objfile, referenced by THIS_UNIT.
13259 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13260 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13262 This is called, for example, when wanting to read a variable with a
13263 complex location. Therefore we don't want to do file i/o for every call.
13264 Therefore we don't want to look for a DWO file on every call.
13265 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13266 then we check if we've already seen DWO_NAME, and only THEN do we check
13269 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13270 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13272 static struct dwo_unit
*
13273 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13274 const char *dwo_name
, const char *comp_dir
,
13275 ULONGEST signature
, int is_debug_types
)
13277 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13278 const char *kind
= is_debug_types
? "TU" : "CU";
13279 void **dwo_file_slot
;
13280 struct dwo_file
*dwo_file
;
13281 struct dwp_file
*dwp_file
;
13283 /* First see if there's a DWP file.
13284 If we have a DWP file but didn't find the DWO inside it, don't
13285 look for the original DWO file. It makes gdb behave differently
13286 depending on whether one is debugging in the build tree. */
13288 dwp_file
= get_dwp_file ();
13289 if (dwp_file
!= NULL
)
13291 const struct dwp_hash_table
*dwp_htab
=
13292 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13294 if (dwp_htab
!= NULL
)
13296 struct dwo_unit
*dwo_cutu
=
13297 lookup_dwo_unit_in_dwp (dwp_file
, comp_dir
,
13298 signature
, is_debug_types
);
13300 if (dwo_cutu
!= NULL
)
13302 if (dwarf_read_debug
)
13304 fprintf_unfiltered (gdb_stdlog
,
13305 "Virtual DWO %s %s found: @%s\n",
13306 kind
, hex_string (signature
),
13307 host_address_to_string (dwo_cutu
));
13315 /* No DWP file, look for the DWO file. */
13317 dwo_file_slot
= lookup_dwo_file_slot (dwo_name
, comp_dir
);
13318 if (*dwo_file_slot
== NULL
)
13320 /* Read in the file and build a table of the CUs/TUs it contains. */
13321 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13323 /* NOTE: This will be NULL if unable to open the file. */
13324 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13326 if (dwo_file
!= NULL
)
13328 struct dwo_unit
*dwo_cutu
= NULL
;
13330 if (is_debug_types
&& dwo_file
->tus
)
13332 struct dwo_unit find_dwo_cutu
;
13334 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13335 find_dwo_cutu
.signature
= signature
;
13337 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13339 else if (!is_debug_types
&& dwo_file
->cus
)
13341 struct dwo_unit find_dwo_cutu
;
13343 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13344 find_dwo_cutu
.signature
= signature
;
13345 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13349 if (dwo_cutu
!= NULL
)
13351 if (dwarf_read_debug
)
13353 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13354 kind
, dwo_name
, hex_string (signature
),
13355 host_address_to_string (dwo_cutu
));
13362 /* We didn't find it. This could mean a dwo_id mismatch, or
13363 someone deleted the DWO/DWP file, or the search path isn't set up
13364 correctly to find the file. */
13366 if (dwarf_read_debug
)
13368 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13369 kind
, dwo_name
, hex_string (signature
));
13372 /* This is a warning and not a complaint because it can be caused by
13373 pilot error (e.g., user accidentally deleting the DWO). */
13375 /* Print the name of the DWP file if we looked there, helps the user
13376 better diagnose the problem. */
13377 std::string dwp_text
;
13379 if (dwp_file
!= NULL
)
13380 dwp_text
= string_printf (" [in DWP file %s]",
13381 lbasename (dwp_file
->name
));
13383 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset 0x%x"
13384 " [in module %s]"),
13385 kind
, dwo_name
, hex_string (signature
),
13387 this_unit
->is_debug_types
? "TU" : "CU",
13388 to_underlying (this_unit
->sect_off
), objfile_name (objfile
));
13393 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13394 See lookup_dwo_cutu_unit for details. */
13396 static struct dwo_unit
*
13397 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13398 const char *dwo_name
, const char *comp_dir
,
13399 ULONGEST signature
)
13401 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13404 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13405 See lookup_dwo_cutu_unit for details. */
13407 static struct dwo_unit
*
13408 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13409 const char *dwo_name
, const char *comp_dir
)
13411 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13414 /* Traversal function for queue_and_load_all_dwo_tus. */
13417 queue_and_load_dwo_tu (void **slot
, void *info
)
13419 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13420 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13421 ULONGEST signature
= dwo_unit
->signature
;
13422 struct signatured_type
*sig_type
=
13423 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13425 if (sig_type
!= NULL
)
13427 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13429 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13430 a real dependency of PER_CU on SIG_TYPE. That is detected later
13431 while processing PER_CU. */
13432 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13433 load_full_type_unit (sig_cu
);
13434 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
13440 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13441 The DWO may have the only definition of the type, though it may not be
13442 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13443 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13446 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13448 struct dwo_unit
*dwo_unit
;
13449 struct dwo_file
*dwo_file
;
13451 gdb_assert (!per_cu
->is_debug_types
);
13452 gdb_assert (get_dwp_file () == NULL
);
13453 gdb_assert (per_cu
->cu
!= NULL
);
13455 dwo_unit
= per_cu
->cu
->dwo_unit
;
13456 gdb_assert (dwo_unit
!= NULL
);
13458 dwo_file
= dwo_unit
->dwo_file
;
13459 if (dwo_file
->tus
!= NULL
)
13460 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13463 /* Free all resources associated with DWO_FILE.
13464 Close the DWO file and munmap the sections.
13465 All memory should be on the objfile obstack. */
13468 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
13471 /* Note: dbfd is NULL for virtual DWO files. */
13472 gdb_bfd_unref (dwo_file
->dbfd
);
13474 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
13477 /* Wrapper for free_dwo_file for use in cleanups. */
13480 free_dwo_file_cleanup (void *arg
)
13482 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
13483 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13485 free_dwo_file (dwo_file
, objfile
);
13488 /* Traversal function for free_dwo_files. */
13491 free_dwo_file_from_slot (void **slot
, void *info
)
13493 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
13494 struct objfile
*objfile
= (struct objfile
*) info
;
13496 free_dwo_file (dwo_file
, objfile
);
13501 /* Free all resources associated with DWO_FILES. */
13504 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
13506 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
13509 /* Read in various DIEs. */
13511 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13512 Inherit only the children of the DW_AT_abstract_origin DIE not being
13513 already referenced by DW_AT_abstract_origin from the children of the
13517 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13519 struct die_info
*child_die
;
13520 sect_offset
*offsetp
;
13521 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13522 struct die_info
*origin_die
;
13523 /* Iterator of the ORIGIN_DIE children. */
13524 struct die_info
*origin_child_die
;
13525 struct attribute
*attr
;
13526 struct dwarf2_cu
*origin_cu
;
13527 struct pending
**origin_previous_list_in_scope
;
13529 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13533 /* Note that following die references may follow to a die in a
13537 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13539 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13541 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13542 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13544 if (die
->tag
!= origin_die
->tag
13545 && !(die
->tag
== DW_TAG_inlined_subroutine
13546 && origin_die
->tag
== DW_TAG_subprogram
))
13547 complaint (&symfile_complaints
,
13548 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
13549 to_underlying (die
->sect_off
),
13550 to_underlying (origin_die
->sect_off
));
13552 std::vector
<sect_offset
> offsets
;
13554 for (child_die
= die
->child
;
13555 child_die
&& child_die
->tag
;
13556 child_die
= sibling_die (child_die
))
13558 struct die_info
*child_origin_die
;
13559 struct dwarf2_cu
*child_origin_cu
;
13561 /* We are trying to process concrete instance entries:
13562 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13563 it's not relevant to our analysis here. i.e. detecting DIEs that are
13564 present in the abstract instance but not referenced in the concrete
13566 if (child_die
->tag
== DW_TAG_call_site
13567 || child_die
->tag
== DW_TAG_GNU_call_site
)
13570 /* For each CHILD_DIE, find the corresponding child of
13571 ORIGIN_DIE. If there is more than one layer of
13572 DW_AT_abstract_origin, follow them all; there shouldn't be,
13573 but GCC versions at least through 4.4 generate this (GCC PR
13575 child_origin_die
= child_die
;
13576 child_origin_cu
= cu
;
13579 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13583 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13587 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13588 counterpart may exist. */
13589 if (child_origin_die
!= child_die
)
13591 if (child_die
->tag
!= child_origin_die
->tag
13592 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13593 && child_origin_die
->tag
== DW_TAG_subprogram
))
13594 complaint (&symfile_complaints
,
13595 _("Child DIE 0x%x and its abstract origin 0x%x have "
13597 to_underlying (child_die
->sect_off
),
13598 to_underlying (child_origin_die
->sect_off
));
13599 if (child_origin_die
->parent
!= origin_die
)
13600 complaint (&symfile_complaints
,
13601 _("Child DIE 0x%x and its abstract origin 0x%x have "
13602 "different parents"),
13603 to_underlying (child_die
->sect_off
),
13604 to_underlying (child_origin_die
->sect_off
));
13606 offsets
.push_back (child_origin_die
->sect_off
);
13609 std::sort (offsets
.begin (), offsets
.end ());
13610 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13611 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13612 if (offsetp
[-1] == *offsetp
)
13613 complaint (&symfile_complaints
,
13614 _("Multiple children of DIE 0x%x refer "
13615 "to DIE 0x%x as their abstract origin"),
13616 to_underlying (die
->sect_off
), to_underlying (*offsetp
));
13618 offsetp
= offsets
.data ();
13619 origin_child_die
= origin_die
->child
;
13620 while (origin_child_die
&& origin_child_die
->tag
)
13622 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13623 while (offsetp
< offsets_end
13624 && *offsetp
< origin_child_die
->sect_off
)
13626 if (offsetp
>= offsets_end
13627 || *offsetp
> origin_child_die
->sect_off
)
13629 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13630 Check whether we're already processing ORIGIN_CHILD_DIE.
13631 This can happen with mutually referenced abstract_origins.
13633 if (!origin_child_die
->in_process
)
13634 process_die (origin_child_die
, origin_cu
);
13636 origin_child_die
= sibling_die (origin_child_die
);
13638 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13642 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13644 struct objfile
*objfile
= cu
->objfile
;
13645 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13646 struct context_stack
*newobj
;
13649 struct die_info
*child_die
;
13650 struct attribute
*attr
, *call_line
, *call_file
;
13652 CORE_ADDR baseaddr
;
13653 struct block
*block
;
13654 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13655 std::vector
<struct symbol
*> template_args
;
13656 struct template_symbol
*templ_func
= NULL
;
13660 /* If we do not have call site information, we can't show the
13661 caller of this inlined function. That's too confusing, so
13662 only use the scope for local variables. */
13663 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13664 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13665 if (call_line
== NULL
|| call_file
== NULL
)
13667 read_lexical_block_scope (die
, cu
);
13672 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13674 name
= dwarf2_name (die
, cu
);
13676 /* Ignore functions with missing or empty names. These are actually
13677 illegal according to the DWARF standard. */
13680 complaint (&symfile_complaints
,
13681 _("missing name for subprogram DIE at %d"),
13682 to_underlying (die
->sect_off
));
13686 /* Ignore functions with missing or invalid low and high pc attributes. */
13687 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13688 <= PC_BOUNDS_INVALID
)
13690 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13691 if (!attr
|| !DW_UNSND (attr
))
13692 complaint (&symfile_complaints
,
13693 _("cannot get low and high bounds "
13694 "for subprogram DIE at %d"),
13695 to_underlying (die
->sect_off
));
13699 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13700 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13702 /* If we have any template arguments, then we must allocate a
13703 different sort of symbol. */
13704 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13706 if (child_die
->tag
== DW_TAG_template_type_param
13707 || child_die
->tag
== DW_TAG_template_value_param
)
13709 templ_func
= allocate_template_symbol (objfile
);
13710 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13715 newobj
= push_context (0, lowpc
);
13716 newobj
->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
13717 (struct symbol
*) templ_func
);
13719 /* If there is a location expression for DW_AT_frame_base, record
13721 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13723 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13725 /* If there is a location for the static link, record it. */
13726 newobj
->static_link
= NULL
;
13727 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13730 newobj
->static_link
13731 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13732 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
13735 cu
->list_in_scope
= &local_symbols
;
13737 if (die
->child
!= NULL
)
13739 child_die
= die
->child
;
13740 while (child_die
&& child_die
->tag
)
13742 if (child_die
->tag
== DW_TAG_template_type_param
13743 || child_die
->tag
== DW_TAG_template_value_param
)
13745 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13748 template_args
.push_back (arg
);
13751 process_die (child_die
, cu
);
13752 child_die
= sibling_die (child_die
);
13756 inherit_abstract_dies (die
, cu
);
13758 /* If we have a DW_AT_specification, we might need to import using
13759 directives from the context of the specification DIE. See the
13760 comment in determine_prefix. */
13761 if (cu
->language
== language_cplus
13762 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13764 struct dwarf2_cu
*spec_cu
= cu
;
13765 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13769 child_die
= spec_die
->child
;
13770 while (child_die
&& child_die
->tag
)
13772 if (child_die
->tag
== DW_TAG_imported_module
)
13773 process_die (child_die
, spec_cu
);
13774 child_die
= sibling_die (child_die
);
13777 /* In some cases, GCC generates specification DIEs that
13778 themselves contain DW_AT_specification attributes. */
13779 spec_die
= die_specification (spec_die
, &spec_cu
);
13783 newobj
= pop_context ();
13784 /* Make a block for the local symbols within. */
13785 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
13786 newobj
->static_link
, lowpc
, highpc
);
13788 /* For C++, set the block's scope. */
13789 if ((cu
->language
== language_cplus
13790 || cu
->language
== language_fortran
13791 || cu
->language
== language_d
13792 || cu
->language
== language_rust
)
13793 && cu
->processing_has_namespace_info
)
13794 block_set_scope (block
, determine_prefix (die
, cu
),
13795 &objfile
->objfile_obstack
);
13797 /* If we have address ranges, record them. */
13798 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13800 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
13802 /* Attach template arguments to function. */
13803 if (!template_args
.empty ())
13805 gdb_assert (templ_func
!= NULL
);
13807 templ_func
->n_template_arguments
= template_args
.size ();
13808 templ_func
->template_arguments
13809 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13810 templ_func
->n_template_arguments
);
13811 memcpy (templ_func
->template_arguments
,
13812 template_args
.data (),
13813 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13816 /* In C++, we can have functions nested inside functions (e.g., when
13817 a function declares a class that has methods). This means that
13818 when we finish processing a function scope, we may need to go
13819 back to building a containing block's symbol lists. */
13820 local_symbols
= newobj
->locals
;
13821 local_using_directives
= newobj
->local_using_directives
;
13823 /* If we've finished processing a top-level function, subsequent
13824 symbols go in the file symbol list. */
13825 if (outermost_context_p ())
13826 cu
->list_in_scope
= &file_symbols
;
13829 /* Process all the DIES contained within a lexical block scope. Start
13830 a new scope, process the dies, and then close the scope. */
13833 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13835 struct objfile
*objfile
= cu
->objfile
;
13836 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13837 struct context_stack
*newobj
;
13838 CORE_ADDR lowpc
, highpc
;
13839 struct die_info
*child_die
;
13840 CORE_ADDR baseaddr
;
13842 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13844 /* Ignore blocks with missing or invalid low and high pc attributes. */
13845 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13846 as multiple lexical blocks? Handling children in a sane way would
13847 be nasty. Might be easier to properly extend generic blocks to
13848 describe ranges. */
13849 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13851 case PC_BOUNDS_NOT_PRESENT
:
13852 /* DW_TAG_lexical_block has no attributes, process its children as if
13853 there was no wrapping by that DW_TAG_lexical_block.
13854 GCC does no longer produces such DWARF since GCC r224161. */
13855 for (child_die
= die
->child
;
13856 child_die
!= NULL
&& child_die
->tag
;
13857 child_die
= sibling_die (child_die
))
13858 process_die (child_die
, cu
);
13860 case PC_BOUNDS_INVALID
:
13863 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13864 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13866 push_context (0, lowpc
);
13867 if (die
->child
!= NULL
)
13869 child_die
= die
->child
;
13870 while (child_die
&& child_die
->tag
)
13872 process_die (child_die
, cu
);
13873 child_die
= sibling_die (child_die
);
13876 inherit_abstract_dies (die
, cu
);
13877 newobj
= pop_context ();
13879 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
13881 struct block
*block
13882 = finish_block (0, &local_symbols
, newobj
->old_blocks
, NULL
,
13883 newobj
->start_addr
, highpc
);
13885 /* Note that recording ranges after traversing children, as we
13886 do here, means that recording a parent's ranges entails
13887 walking across all its children's ranges as they appear in
13888 the address map, which is quadratic behavior.
13890 It would be nicer to record the parent's ranges before
13891 traversing its children, simply overriding whatever you find
13892 there. But since we don't even decide whether to create a
13893 block until after we've traversed its children, that's hard
13895 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13897 local_symbols
= newobj
->locals
;
13898 local_using_directives
= newobj
->local_using_directives
;
13901 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13904 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13906 struct objfile
*objfile
= cu
->objfile
;
13907 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13908 CORE_ADDR pc
, baseaddr
;
13909 struct attribute
*attr
;
13910 struct call_site
*call_site
, call_site_local
;
13913 struct die_info
*child_die
;
13915 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13917 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13920 /* This was a pre-DWARF-5 GNU extension alias
13921 for DW_AT_call_return_pc. */
13922 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13926 complaint (&symfile_complaints
,
13927 _("missing DW_AT_call_return_pc for DW_TAG_call_site "
13928 "DIE 0x%x [in module %s]"),
13929 to_underlying (die
->sect_off
), objfile_name (objfile
));
13932 pc
= attr_value_as_address (attr
) + baseaddr
;
13933 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13935 if (cu
->call_site_htab
== NULL
)
13936 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13937 NULL
, &objfile
->objfile_obstack
,
13938 hashtab_obstack_allocate
, NULL
);
13939 call_site_local
.pc
= pc
;
13940 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13943 complaint (&symfile_complaints
,
13944 _("Duplicate PC %s for DW_TAG_call_site "
13945 "DIE 0x%x [in module %s]"),
13946 paddress (gdbarch
, pc
), to_underlying (die
->sect_off
),
13947 objfile_name (objfile
));
13951 /* Count parameters at the caller. */
13954 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13955 child_die
= sibling_die (child_die
))
13957 if (child_die
->tag
!= DW_TAG_call_site_parameter
13958 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13960 complaint (&symfile_complaints
,
13961 _("Tag %d is not DW_TAG_call_site_parameter in "
13962 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
13963 child_die
->tag
, to_underlying (child_die
->sect_off
),
13964 objfile_name (objfile
));
13972 = ((struct call_site
*)
13973 obstack_alloc (&objfile
->objfile_obstack
,
13974 sizeof (*call_site
)
13975 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13977 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13978 call_site
->pc
= pc
;
13980 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13981 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13983 struct die_info
*func_die
;
13985 /* Skip also over DW_TAG_inlined_subroutine. */
13986 for (func_die
= die
->parent
;
13987 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13988 && func_die
->tag
!= DW_TAG_subroutine_type
;
13989 func_die
= func_die
->parent
);
13991 /* DW_AT_call_all_calls is a superset
13992 of DW_AT_call_all_tail_calls. */
13994 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13995 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13996 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13997 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13999 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14000 not complete. But keep CALL_SITE for look ups via call_site_htab,
14001 both the initial caller containing the real return address PC and
14002 the final callee containing the current PC of a chain of tail
14003 calls do not need to have the tail call list complete. But any
14004 function candidate for a virtual tail call frame searched via
14005 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14006 determined unambiguously. */
14010 struct type
*func_type
= NULL
;
14013 func_type
= get_die_type (func_die
, cu
);
14014 if (func_type
!= NULL
)
14016 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14018 /* Enlist this call site to the function. */
14019 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14020 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14023 complaint (&symfile_complaints
,
14024 _("Cannot find function owning DW_TAG_call_site "
14025 "DIE 0x%x [in module %s]"),
14026 to_underlying (die
->sect_off
), objfile_name (objfile
));
14030 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14032 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14034 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14037 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14038 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14040 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14041 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14042 /* Keep NULL DWARF_BLOCK. */;
14043 else if (attr_form_is_block (attr
))
14045 struct dwarf2_locexpr_baton
*dlbaton
;
14047 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14048 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14049 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14050 dlbaton
->per_cu
= cu
->per_cu
;
14052 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14054 else if (attr_form_is_ref (attr
))
14056 struct dwarf2_cu
*target_cu
= cu
;
14057 struct die_info
*target_die
;
14059 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14060 gdb_assert (target_cu
->objfile
== objfile
);
14061 if (die_is_declaration (target_die
, target_cu
))
14063 const char *target_physname
;
14065 /* Prefer the mangled name; otherwise compute the demangled one. */
14066 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14067 if (target_physname
== NULL
)
14068 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14069 if (target_physname
== NULL
)
14070 complaint (&symfile_complaints
,
14071 _("DW_AT_call_target target DIE has invalid "
14072 "physname, for referencing DIE 0x%x [in module %s]"),
14073 to_underlying (die
->sect_off
), objfile_name (objfile
));
14075 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14081 /* DW_AT_entry_pc should be preferred. */
14082 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14083 <= PC_BOUNDS_INVALID
)
14084 complaint (&symfile_complaints
,
14085 _("DW_AT_call_target target DIE has invalid "
14086 "low pc, for referencing DIE 0x%x [in module %s]"),
14087 to_underlying (die
->sect_off
), objfile_name (objfile
));
14090 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14091 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14096 complaint (&symfile_complaints
,
14097 _("DW_TAG_call_site DW_AT_call_target is neither "
14098 "block nor reference, for DIE 0x%x [in module %s]"),
14099 to_underlying (die
->sect_off
), objfile_name (objfile
));
14101 call_site
->per_cu
= cu
->per_cu
;
14103 for (child_die
= die
->child
;
14104 child_die
&& child_die
->tag
;
14105 child_die
= sibling_die (child_die
))
14107 struct call_site_parameter
*parameter
;
14108 struct attribute
*loc
, *origin
;
14110 if (child_die
->tag
!= DW_TAG_call_site_parameter
14111 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14113 /* Already printed the complaint above. */
14117 gdb_assert (call_site
->parameter_count
< nparams
);
14118 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14120 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14121 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14122 register is contained in DW_AT_call_value. */
14124 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14125 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14126 if (origin
== NULL
)
14128 /* This was a pre-DWARF-5 GNU extension alias
14129 for DW_AT_call_parameter. */
14130 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14132 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14134 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14136 sect_offset sect_off
14137 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14138 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14140 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14141 binding can be done only inside one CU. Such referenced DIE
14142 therefore cannot be even moved to DW_TAG_partial_unit. */
14143 complaint (&symfile_complaints
,
14144 _("DW_AT_call_parameter offset is not in CU for "
14145 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
14146 to_underlying (child_die
->sect_off
),
14147 objfile_name (objfile
));
14150 parameter
->u
.param_cu_off
14151 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14153 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14155 complaint (&symfile_complaints
,
14156 _("No DW_FORM_block* DW_AT_location for "
14157 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
14158 to_underlying (child_die
->sect_off
), objfile_name (objfile
));
14163 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14164 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14165 if (parameter
->u
.dwarf_reg
!= -1)
14166 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14167 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14168 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14169 ¶meter
->u
.fb_offset
))
14170 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14173 complaint (&symfile_complaints
,
14174 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
14175 "for DW_FORM_block* DW_AT_location is supported for "
14176 "DW_TAG_call_site child DIE 0x%x "
14178 to_underlying (child_die
->sect_off
),
14179 objfile_name (objfile
));
14184 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14186 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14187 if (!attr_form_is_block (attr
))
14189 complaint (&symfile_complaints
,
14190 _("No DW_FORM_block* DW_AT_call_value for "
14191 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
14192 to_underlying (child_die
->sect_off
),
14193 objfile_name (objfile
));
14196 parameter
->value
= DW_BLOCK (attr
)->data
;
14197 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14199 /* Parameters are not pre-cleared by memset above. */
14200 parameter
->data_value
= NULL
;
14201 parameter
->data_value_size
= 0;
14202 call_site
->parameter_count
++;
14204 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14206 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14209 if (!attr_form_is_block (attr
))
14210 complaint (&symfile_complaints
,
14211 _("No DW_FORM_block* DW_AT_call_data_value for "
14212 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
14213 to_underlying (child_die
->sect_off
),
14214 objfile_name (objfile
));
14217 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14218 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14224 /* Helper function for read_variable. If DIE represents a virtual
14225 table, then return the type of the concrete object that is
14226 associated with the virtual table. Otherwise, return NULL. */
14228 static struct type
*
14229 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14231 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14235 /* Find the type DIE. */
14236 struct die_info
*type_die
= NULL
;
14237 struct dwarf2_cu
*type_cu
= cu
;
14239 if (attr_form_is_ref (attr
))
14240 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14241 if (type_die
== NULL
)
14244 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14246 return die_containing_type (type_die
, type_cu
);
14249 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14252 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14254 struct rust_vtable_symbol
*storage
= NULL
;
14256 if (cu
->language
== language_rust
)
14258 struct type
*containing_type
= rust_containing_type (die
, cu
);
14260 if (containing_type
!= NULL
)
14262 struct objfile
*objfile
= cu
->objfile
;
14264 storage
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
14265 struct rust_vtable_symbol
);
14266 initialize_objfile_symbol (storage
);
14267 storage
->concrete_type
= containing_type
;
14268 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14272 new_symbol_full (die
, NULL
, cu
, storage
);
14275 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14276 reading .debug_rnglists.
14277 Callback's type should be:
14278 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14279 Return true if the attributes are present and valid, otherwise,
14282 template <typename Callback
>
14284 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14285 Callback
&&callback
)
14287 struct objfile
*objfile
= cu
->objfile
;
14288 bfd
*obfd
= objfile
->obfd
;
14289 /* Base address selection entry. */
14292 const gdb_byte
*buffer
;
14293 CORE_ADDR baseaddr
;
14294 bool overflow
= false;
14296 found_base
= cu
->base_known
;
14297 base
= cu
->base_address
;
14299 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14300 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14302 complaint (&symfile_complaints
,
14303 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14307 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14309 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14313 /* Initialize it due to a false compiler warning. */
14314 CORE_ADDR range_beginning
= 0, range_end
= 0;
14315 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14316 + dwarf2_per_objfile
->rnglists
.size
);
14317 unsigned int bytes_read
;
14319 if (buffer
== buf_end
)
14324 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14327 case DW_RLE_end_of_list
:
14329 case DW_RLE_base_address
:
14330 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14335 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14337 buffer
+= bytes_read
;
14339 case DW_RLE_start_length
:
14340 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14345 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14346 buffer
+= bytes_read
;
14347 range_end
= (range_beginning
14348 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14349 buffer
+= bytes_read
;
14350 if (buffer
> buf_end
)
14356 case DW_RLE_offset_pair
:
14357 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14358 buffer
+= bytes_read
;
14359 if (buffer
> buf_end
)
14364 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14365 buffer
+= bytes_read
;
14366 if (buffer
> buf_end
)
14372 case DW_RLE_start_end
:
14373 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14378 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14379 buffer
+= bytes_read
;
14380 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14381 buffer
+= bytes_read
;
14384 complaint (&symfile_complaints
,
14385 _("Invalid .debug_rnglists data (no base address)"));
14388 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14390 if (rlet
== DW_RLE_base_address
)
14395 /* We have no valid base address for the ranges
14397 complaint (&symfile_complaints
,
14398 _("Invalid .debug_rnglists data (no base address)"));
14402 if (range_beginning
> range_end
)
14404 /* Inverted range entries are invalid. */
14405 complaint (&symfile_complaints
,
14406 _("Invalid .debug_rnglists data (inverted range)"));
14410 /* Empty range entries have no effect. */
14411 if (range_beginning
== range_end
)
14414 range_beginning
+= base
;
14417 /* A not-uncommon case of bad debug info.
14418 Don't pollute the addrmap with bad data. */
14419 if (range_beginning
+ baseaddr
== 0
14420 && !dwarf2_per_objfile
->has_section_at_zero
)
14422 complaint (&symfile_complaints
,
14423 _(".debug_rnglists entry has start address of zero"
14424 " [in module %s]"), objfile_name (objfile
));
14428 callback (range_beginning
, range_end
);
14433 complaint (&symfile_complaints
,
14434 _("Offset %d is not terminated "
14435 "for DW_AT_ranges attribute"),
14443 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14444 Callback's type should be:
14445 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14446 Return 1 if the attributes are present and valid, otherwise, return 0. */
14448 template <typename Callback
>
14450 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14451 Callback
&&callback
)
14453 struct objfile
*objfile
= cu
->objfile
;
14454 struct comp_unit_head
*cu_header
= &cu
->header
;
14455 bfd
*obfd
= objfile
->obfd
;
14456 unsigned int addr_size
= cu_header
->addr_size
;
14457 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14458 /* Base address selection entry. */
14461 unsigned int dummy
;
14462 const gdb_byte
*buffer
;
14463 CORE_ADDR baseaddr
;
14465 if (cu_header
->version
>= 5)
14466 return dwarf2_rnglists_process (offset
, cu
, callback
);
14468 found_base
= cu
->base_known
;
14469 base
= cu
->base_address
;
14471 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14472 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14474 complaint (&symfile_complaints
,
14475 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14479 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14481 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14485 CORE_ADDR range_beginning
, range_end
;
14487 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14488 buffer
+= addr_size
;
14489 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14490 buffer
+= addr_size
;
14491 offset
+= 2 * addr_size
;
14493 /* An end of list marker is a pair of zero addresses. */
14494 if (range_beginning
== 0 && range_end
== 0)
14495 /* Found the end of list entry. */
14498 /* Each base address selection entry is a pair of 2 values.
14499 The first is the largest possible address, the second is
14500 the base address. Check for a base address here. */
14501 if ((range_beginning
& mask
) == mask
)
14503 /* If we found the largest possible address, then we already
14504 have the base address in range_end. */
14512 /* We have no valid base address for the ranges
14514 complaint (&symfile_complaints
,
14515 _("Invalid .debug_ranges data (no base address)"));
14519 if (range_beginning
> range_end
)
14521 /* Inverted range entries are invalid. */
14522 complaint (&symfile_complaints
,
14523 _("Invalid .debug_ranges data (inverted range)"));
14527 /* Empty range entries have no effect. */
14528 if (range_beginning
== range_end
)
14531 range_beginning
+= base
;
14534 /* A not-uncommon case of bad debug info.
14535 Don't pollute the addrmap with bad data. */
14536 if (range_beginning
+ baseaddr
== 0
14537 && !dwarf2_per_objfile
->has_section_at_zero
)
14539 complaint (&symfile_complaints
,
14540 _(".debug_ranges entry has start address of zero"
14541 " [in module %s]"), objfile_name (objfile
));
14545 callback (range_beginning
, range_end
);
14551 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14552 Return 1 if the attributes are present and valid, otherwise, return 0.
14553 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14556 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14557 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14558 struct partial_symtab
*ranges_pst
)
14560 struct objfile
*objfile
= cu
->objfile
;
14561 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14562 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
14563 SECT_OFF_TEXT (objfile
));
14566 CORE_ADDR high
= 0;
14569 retval
= dwarf2_ranges_process (offset
, cu
,
14570 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14572 if (ranges_pst
!= NULL
)
14577 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
14578 range_beginning
+ baseaddr
);
14579 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
14580 range_end
+ baseaddr
);
14581 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
14585 /* FIXME: This is recording everything as a low-high
14586 segment of consecutive addresses. We should have a
14587 data structure for discontiguous block ranges
14591 low
= range_beginning
;
14597 if (range_beginning
< low
)
14598 low
= range_beginning
;
14599 if (range_end
> high
)
14607 /* If the first entry is an end-of-list marker, the range
14608 describes an empty scope, i.e. no instructions. */
14614 *high_return
= high
;
14618 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14619 definition for the return value. *LOWPC and *HIGHPC are set iff
14620 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14622 static enum pc_bounds_kind
14623 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14624 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14625 struct partial_symtab
*pst
)
14627 struct attribute
*attr
;
14628 struct attribute
*attr_high
;
14630 CORE_ADDR high
= 0;
14631 enum pc_bounds_kind ret
;
14633 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14636 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14639 low
= attr_value_as_address (attr
);
14640 high
= attr_value_as_address (attr_high
);
14641 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14645 /* Found high w/o low attribute. */
14646 return PC_BOUNDS_INVALID
;
14648 /* Found consecutive range of addresses. */
14649 ret
= PC_BOUNDS_HIGH_LOW
;
14653 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14656 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14657 We take advantage of the fact that DW_AT_ranges does not appear
14658 in DW_TAG_compile_unit of DWO files. */
14659 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14660 unsigned int ranges_offset
= (DW_UNSND (attr
)
14661 + (need_ranges_base
14665 /* Value of the DW_AT_ranges attribute is the offset in the
14666 .debug_ranges section. */
14667 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14668 return PC_BOUNDS_INVALID
;
14669 /* Found discontinuous range of addresses. */
14670 ret
= PC_BOUNDS_RANGES
;
14673 return PC_BOUNDS_NOT_PRESENT
;
14676 /* read_partial_die has also the strict LOW < HIGH requirement. */
14678 return PC_BOUNDS_INVALID
;
14680 /* When using the GNU linker, .gnu.linkonce. sections are used to
14681 eliminate duplicate copies of functions and vtables and such.
14682 The linker will arbitrarily choose one and discard the others.
14683 The AT_*_pc values for such functions refer to local labels in
14684 these sections. If the section from that file was discarded, the
14685 labels are not in the output, so the relocs get a value of 0.
14686 If this is a discarded function, mark the pc bounds as invalid,
14687 so that GDB will ignore it. */
14688 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14689 return PC_BOUNDS_INVALID
;
14697 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14698 its low and high PC addresses. Do nothing if these addresses could not
14699 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14700 and HIGHPC to the high address if greater than HIGHPC. */
14703 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14704 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14705 struct dwarf2_cu
*cu
)
14707 CORE_ADDR low
, high
;
14708 struct die_info
*child
= die
->child
;
14710 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14712 *lowpc
= std::min (*lowpc
, low
);
14713 *highpc
= std::max (*highpc
, high
);
14716 /* If the language does not allow nested subprograms (either inside
14717 subprograms or lexical blocks), we're done. */
14718 if (cu
->language
!= language_ada
)
14721 /* Check all the children of the given DIE. If it contains nested
14722 subprograms, then check their pc bounds. Likewise, we need to
14723 check lexical blocks as well, as they may also contain subprogram
14725 while (child
&& child
->tag
)
14727 if (child
->tag
== DW_TAG_subprogram
14728 || child
->tag
== DW_TAG_lexical_block
)
14729 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14730 child
= sibling_die (child
);
14734 /* Get the low and high pc's represented by the scope DIE, and store
14735 them in *LOWPC and *HIGHPC. If the correct values can't be
14736 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14739 get_scope_pc_bounds (struct die_info
*die
,
14740 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14741 struct dwarf2_cu
*cu
)
14743 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14744 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14745 CORE_ADDR current_low
, current_high
;
14747 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14748 >= PC_BOUNDS_RANGES
)
14750 best_low
= current_low
;
14751 best_high
= current_high
;
14755 struct die_info
*child
= die
->child
;
14757 while (child
&& child
->tag
)
14759 switch (child
->tag
) {
14760 case DW_TAG_subprogram
:
14761 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14763 case DW_TAG_namespace
:
14764 case DW_TAG_module
:
14765 /* FIXME: carlton/2004-01-16: Should we do this for
14766 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14767 that current GCC's always emit the DIEs corresponding
14768 to definitions of methods of classes as children of a
14769 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14770 the DIEs giving the declarations, which could be
14771 anywhere). But I don't see any reason why the
14772 standards says that they have to be there. */
14773 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14775 if (current_low
!= ((CORE_ADDR
) -1))
14777 best_low
= std::min (best_low
, current_low
);
14778 best_high
= std::max (best_high
, current_high
);
14786 child
= sibling_die (child
);
14791 *highpc
= best_high
;
14794 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14798 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14799 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14801 struct objfile
*objfile
= cu
->objfile
;
14802 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14803 struct attribute
*attr
;
14804 struct attribute
*attr_high
;
14806 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14809 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14812 CORE_ADDR low
= attr_value_as_address (attr
);
14813 CORE_ADDR high
= attr_value_as_address (attr_high
);
14815 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14818 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14819 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14820 record_block_range (block
, low
, high
- 1);
14824 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14827 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14828 We take advantage of the fact that DW_AT_ranges does not appear
14829 in DW_TAG_compile_unit of DWO files. */
14830 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14832 /* The value of the DW_AT_ranges attribute is the offset of the
14833 address range list in the .debug_ranges section. */
14834 unsigned long offset
= (DW_UNSND (attr
)
14835 + (need_ranges_base
? cu
->ranges_base
: 0));
14836 const gdb_byte
*buffer
;
14838 /* For some target architectures, but not others, the
14839 read_address function sign-extends the addresses it returns.
14840 To recognize base address selection entries, we need a
14842 unsigned int addr_size
= cu
->header
.addr_size
;
14843 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14845 /* The base address, to which the next pair is relative. Note
14846 that this 'base' is a DWARF concept: most entries in a range
14847 list are relative, to reduce the number of relocs against the
14848 debugging information. This is separate from this function's
14849 'baseaddr' argument, which GDB uses to relocate debugging
14850 information from a shared library based on the address at
14851 which the library was loaded. */
14852 CORE_ADDR base
= cu
->base_address
;
14853 int base_known
= cu
->base_known
;
14855 dwarf2_ranges_process (offset
, cu
,
14856 [&] (CORE_ADDR start
, CORE_ADDR end
)
14860 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14861 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14862 record_block_range (block
, start
, end
- 1);
14867 /* Check whether the producer field indicates either of GCC < 4.6, or the
14868 Intel C/C++ compiler, and cache the result in CU. */
14871 check_producer (struct dwarf2_cu
*cu
)
14875 if (cu
->producer
== NULL
)
14877 /* For unknown compilers expect their behavior is DWARF version
14880 GCC started to support .debug_types sections by -gdwarf-4 since
14881 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14882 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14883 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14884 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14886 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14888 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14889 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14891 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14892 cu
->producer_is_icc_lt_14
= major
< 14;
14895 /* For other non-GCC compilers, expect their behavior is DWARF version
14899 cu
->checked_producer
= 1;
14902 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14903 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14904 during 4.6.0 experimental. */
14907 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14909 if (!cu
->checked_producer
)
14910 check_producer (cu
);
14912 return cu
->producer_is_gxx_lt_4_6
;
14915 /* Return the default accessibility type if it is not overriden by
14916 DW_AT_accessibility. */
14918 static enum dwarf_access_attribute
14919 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14921 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14923 /* The default DWARF 2 accessibility for members is public, the default
14924 accessibility for inheritance is private. */
14926 if (die
->tag
!= DW_TAG_inheritance
)
14927 return DW_ACCESS_public
;
14929 return DW_ACCESS_private
;
14933 /* DWARF 3+ defines the default accessibility a different way. The same
14934 rules apply now for DW_TAG_inheritance as for the members and it only
14935 depends on the container kind. */
14937 if (die
->parent
->tag
== DW_TAG_class_type
)
14938 return DW_ACCESS_private
;
14940 return DW_ACCESS_public
;
14944 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14945 offset. If the attribute was not found return 0, otherwise return
14946 1. If it was found but could not properly be handled, set *OFFSET
14950 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14953 struct attribute
*attr
;
14955 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14960 /* Note that we do not check for a section offset first here.
14961 This is because DW_AT_data_member_location is new in DWARF 4,
14962 so if we see it, we can assume that a constant form is really
14963 a constant and not a section offset. */
14964 if (attr_form_is_constant (attr
))
14965 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14966 else if (attr_form_is_section_offset (attr
))
14967 dwarf2_complex_location_expr_complaint ();
14968 else if (attr_form_is_block (attr
))
14969 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14971 dwarf2_complex_location_expr_complaint ();
14979 /* Add an aggregate field to the field list. */
14982 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14983 struct dwarf2_cu
*cu
)
14985 struct objfile
*objfile
= cu
->objfile
;
14986 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14987 struct nextfield
*new_field
;
14988 struct attribute
*attr
;
14990 const char *fieldname
= "";
14992 /* Allocate a new field list entry and link it in. */
14993 new_field
= XNEW (struct nextfield
);
14994 make_cleanup (xfree
, new_field
);
14995 memset (new_field
, 0, sizeof (struct nextfield
));
14997 if (die
->tag
== DW_TAG_inheritance
)
14999 new_field
->next
= fip
->baseclasses
;
15000 fip
->baseclasses
= new_field
;
15004 new_field
->next
= fip
->fields
;
15005 fip
->fields
= new_field
;
15009 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15011 new_field
->accessibility
= DW_UNSND (attr
);
15013 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15014 if (new_field
->accessibility
!= DW_ACCESS_public
)
15015 fip
->non_public_fields
= 1;
15017 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15019 new_field
->virtuality
= DW_UNSND (attr
);
15021 new_field
->virtuality
= DW_VIRTUALITY_none
;
15023 fp
= &new_field
->field
;
15025 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15029 /* Data member other than a C++ static data member. */
15031 /* Get type of field. */
15032 fp
->type
= die_type (die
, cu
);
15034 SET_FIELD_BITPOS (*fp
, 0);
15036 /* Get bit size of field (zero if none). */
15037 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15040 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15044 FIELD_BITSIZE (*fp
) = 0;
15047 /* Get bit offset of field. */
15048 if (handle_data_member_location (die
, cu
, &offset
))
15049 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15050 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15053 if (gdbarch_bits_big_endian (gdbarch
))
15055 /* For big endian bits, the DW_AT_bit_offset gives the
15056 additional bit offset from the MSB of the containing
15057 anonymous object to the MSB of the field. We don't
15058 have to do anything special since we don't need to
15059 know the size of the anonymous object. */
15060 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15064 /* For little endian bits, compute the bit offset to the
15065 MSB of the anonymous object, subtract off the number of
15066 bits from the MSB of the field to the MSB of the
15067 object, and then subtract off the number of bits of
15068 the field itself. The result is the bit offset of
15069 the LSB of the field. */
15070 int anonymous_size
;
15071 int bit_offset
= DW_UNSND (attr
);
15073 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15076 /* The size of the anonymous object containing
15077 the bit field is explicit, so use the
15078 indicated size (in bytes). */
15079 anonymous_size
= DW_UNSND (attr
);
15083 /* The size of the anonymous object containing
15084 the bit field must be inferred from the type
15085 attribute of the data member containing the
15087 anonymous_size
= TYPE_LENGTH (fp
->type
);
15089 SET_FIELD_BITPOS (*fp
,
15090 (FIELD_BITPOS (*fp
)
15091 + anonymous_size
* bits_per_byte
15092 - bit_offset
- FIELD_BITSIZE (*fp
)));
15095 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15097 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15098 + dwarf2_get_attr_constant_value (attr
, 0)));
15100 /* Get name of field. */
15101 fieldname
= dwarf2_name (die
, cu
);
15102 if (fieldname
== NULL
)
15105 /* The name is already allocated along with this objfile, so we don't
15106 need to duplicate it for the type. */
15107 fp
->name
= fieldname
;
15109 /* Change accessibility for artificial fields (e.g. virtual table
15110 pointer or virtual base class pointer) to private. */
15111 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15113 FIELD_ARTIFICIAL (*fp
) = 1;
15114 new_field
->accessibility
= DW_ACCESS_private
;
15115 fip
->non_public_fields
= 1;
15118 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15120 /* C++ static member. */
15122 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15123 is a declaration, but all versions of G++ as of this writing
15124 (so through at least 3.2.1) incorrectly generate
15125 DW_TAG_variable tags. */
15127 const char *physname
;
15129 /* Get name of field. */
15130 fieldname
= dwarf2_name (die
, cu
);
15131 if (fieldname
== NULL
)
15134 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15136 /* Only create a symbol if this is an external value.
15137 new_symbol checks this and puts the value in the global symbol
15138 table, which we want. If it is not external, new_symbol
15139 will try to put the value in cu->list_in_scope which is wrong. */
15140 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15142 /* A static const member, not much different than an enum as far as
15143 we're concerned, except that we can support more types. */
15144 new_symbol (die
, NULL
, cu
);
15147 /* Get physical name. */
15148 physname
= dwarf2_physname (fieldname
, die
, cu
);
15150 /* The name is already allocated along with this objfile, so we don't
15151 need to duplicate it for the type. */
15152 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15153 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15154 FIELD_NAME (*fp
) = fieldname
;
15156 else if (die
->tag
== DW_TAG_inheritance
)
15160 /* C++ base class field. */
15161 if (handle_data_member_location (die
, cu
, &offset
))
15162 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15163 FIELD_BITSIZE (*fp
) = 0;
15164 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15165 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
15166 fip
->nbaseclasses
++;
15170 /* Can the type given by DIE define another type? */
15173 type_can_define_types (const struct die_info
*die
)
15177 case DW_TAG_typedef
:
15178 case DW_TAG_class_type
:
15179 case DW_TAG_structure_type
:
15180 case DW_TAG_union_type
:
15181 case DW_TAG_enumeration_type
:
15189 /* Add a type definition defined in the scope of the FIP's class. */
15192 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15193 struct dwarf2_cu
*cu
)
15195 struct decl_field_list
*new_field
;
15196 struct decl_field
*fp
;
15198 /* Allocate a new field list entry and link it in. */
15199 new_field
= XCNEW (struct decl_field_list
);
15200 make_cleanup (xfree
, new_field
);
15202 gdb_assert (type_can_define_types (die
));
15204 fp
= &new_field
->field
;
15206 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15207 fp
->name
= dwarf2_name (die
, cu
);
15208 fp
->type
= read_type_die (die
, cu
);
15210 /* Save accessibility. */
15211 enum dwarf_access_attribute accessibility
;
15212 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15214 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15216 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15217 switch (accessibility
)
15219 case DW_ACCESS_public
:
15220 /* The assumed value if neither private nor protected. */
15222 case DW_ACCESS_private
:
15223 fp
->is_private
= 1;
15225 case DW_ACCESS_protected
:
15226 fp
->is_protected
= 1;
15229 complaint (&symfile_complaints
,
15230 _("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15233 if (die
->tag
== DW_TAG_typedef
)
15235 new_field
->next
= fip
->typedef_field_list
;
15236 fip
->typedef_field_list
= new_field
;
15237 fip
->typedef_field_list_count
++;
15241 new_field
->next
= fip
->nested_types_list
;
15242 fip
->nested_types_list
= new_field
;
15243 fip
->nested_types_list_count
++;
15247 /* Create the vector of fields, and attach it to the type. */
15250 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15251 struct dwarf2_cu
*cu
)
15253 int nfields
= fip
->nfields
;
15255 /* Record the field count, allocate space for the array of fields,
15256 and create blank accessibility bitfields if necessary. */
15257 TYPE_NFIELDS (type
) = nfields
;
15258 TYPE_FIELDS (type
) = (struct field
*)
15259 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
15260 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
15262 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15264 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15266 TYPE_FIELD_PRIVATE_BITS (type
) =
15267 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15268 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15270 TYPE_FIELD_PROTECTED_BITS (type
) =
15271 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15272 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15274 TYPE_FIELD_IGNORE_BITS (type
) =
15275 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15276 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15279 /* If the type has baseclasses, allocate and clear a bit vector for
15280 TYPE_FIELD_VIRTUAL_BITS. */
15281 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
15283 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
15284 unsigned char *pointer
;
15286 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15287 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15288 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15289 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
15290 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
15293 /* Copy the saved-up fields into the field vector. Start from the head of
15294 the list, adding to the tail of the field array, so that they end up in
15295 the same order in the array in which they were added to the list. */
15296 while (nfields
-- > 0)
15298 struct nextfield
*fieldp
;
15302 fieldp
= fip
->fields
;
15303 fip
->fields
= fieldp
->next
;
15307 fieldp
= fip
->baseclasses
;
15308 fip
->baseclasses
= fieldp
->next
;
15311 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
15312 switch (fieldp
->accessibility
)
15314 case DW_ACCESS_private
:
15315 if (cu
->language
!= language_ada
)
15316 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
15319 case DW_ACCESS_protected
:
15320 if (cu
->language
!= language_ada
)
15321 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
15324 case DW_ACCESS_public
:
15328 /* Unknown accessibility. Complain and treat it as public. */
15330 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
15331 fieldp
->accessibility
);
15335 if (nfields
< fip
->nbaseclasses
)
15337 switch (fieldp
->virtuality
)
15339 case DW_VIRTUALITY_virtual
:
15340 case DW_VIRTUALITY_pure_virtual
:
15341 if (cu
->language
== language_ada
)
15342 error (_("unexpected virtuality in component of Ada type"));
15343 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
15350 /* Return true if this member function is a constructor, false
15354 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15356 const char *fieldname
;
15357 const char *type_name
;
15360 if (die
->parent
== NULL
)
15363 if (die
->parent
->tag
!= DW_TAG_structure_type
15364 && die
->parent
->tag
!= DW_TAG_union_type
15365 && die
->parent
->tag
!= DW_TAG_class_type
)
15368 fieldname
= dwarf2_name (die
, cu
);
15369 type_name
= dwarf2_name (die
->parent
, cu
);
15370 if (fieldname
== NULL
|| type_name
== NULL
)
15373 len
= strlen (fieldname
);
15374 return (strncmp (fieldname
, type_name
, len
) == 0
15375 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15378 /* Add a member function to the proper fieldlist. */
15381 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15382 struct type
*type
, struct dwarf2_cu
*cu
)
15384 struct objfile
*objfile
= cu
->objfile
;
15385 struct attribute
*attr
;
15386 struct fnfieldlist
*flp
;
15388 struct fn_field
*fnp
;
15389 const char *fieldname
;
15390 struct nextfnfield
*new_fnfield
;
15391 struct type
*this_type
;
15392 enum dwarf_access_attribute accessibility
;
15394 if (cu
->language
== language_ada
)
15395 error (_("unexpected member function in Ada type"));
15397 /* Get name of member function. */
15398 fieldname
= dwarf2_name (die
, cu
);
15399 if (fieldname
== NULL
)
15402 /* Look up member function name in fieldlist. */
15403 for (i
= 0; i
< fip
->nfnfields
; i
++)
15405 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15409 /* Create new list element if necessary. */
15410 if (i
< fip
->nfnfields
)
15411 flp
= &fip
->fnfieldlists
[i
];
15414 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
15416 fip
->fnfieldlists
= (struct fnfieldlist
*)
15417 xrealloc (fip
->fnfieldlists
,
15418 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
15419 * sizeof (struct fnfieldlist
));
15420 if (fip
->nfnfields
== 0)
15421 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
15423 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
15424 flp
->name
= fieldname
;
15427 i
= fip
->nfnfields
++;
15430 /* Create a new member function field and chain it to the field list
15432 new_fnfield
= XNEW (struct nextfnfield
);
15433 make_cleanup (xfree
, new_fnfield
);
15434 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
15435 new_fnfield
->next
= flp
->head
;
15436 flp
->head
= new_fnfield
;
15439 /* Fill in the member function field info. */
15440 fnp
= &new_fnfield
->fnfield
;
15442 /* Delay processing of the physname until later. */
15443 if (cu
->language
== language_cplus
)
15445 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
15450 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15451 fnp
->physname
= physname
? physname
: "";
15454 fnp
->type
= alloc_type (objfile
);
15455 this_type
= read_type_die (die
, cu
);
15456 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15458 int nparams
= TYPE_NFIELDS (this_type
);
15460 /* TYPE is the domain of this method, and THIS_TYPE is the type
15461 of the method itself (TYPE_CODE_METHOD). */
15462 smash_to_method_type (fnp
->type
, type
,
15463 TYPE_TARGET_TYPE (this_type
),
15464 TYPE_FIELDS (this_type
),
15465 TYPE_NFIELDS (this_type
),
15466 TYPE_VARARGS (this_type
));
15468 /* Handle static member functions.
15469 Dwarf2 has no clean way to discern C++ static and non-static
15470 member functions. G++ helps GDB by marking the first
15471 parameter for non-static member functions (which is the this
15472 pointer) as artificial. We obtain this information from
15473 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15474 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15475 fnp
->voffset
= VOFFSET_STATIC
;
15478 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
15479 dwarf2_full_name (fieldname
, die
, cu
));
15481 /* Get fcontext from DW_AT_containing_type if present. */
15482 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15483 fnp
->fcontext
= die_containing_type (die
, cu
);
15485 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15486 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15488 /* Get accessibility. */
15489 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15491 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15493 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15494 switch (accessibility
)
15496 case DW_ACCESS_private
:
15497 fnp
->is_private
= 1;
15499 case DW_ACCESS_protected
:
15500 fnp
->is_protected
= 1;
15504 /* Check for artificial methods. */
15505 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15506 if (attr
&& DW_UNSND (attr
) != 0)
15507 fnp
->is_artificial
= 1;
15509 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15511 /* Get index in virtual function table if it is a virtual member
15512 function. For older versions of GCC, this is an offset in the
15513 appropriate virtual table, as specified by DW_AT_containing_type.
15514 For everyone else, it is an expression to be evaluated relative
15515 to the object address. */
15517 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15520 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15522 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15524 /* Old-style GCC. */
15525 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15527 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15528 || (DW_BLOCK (attr
)->size
> 1
15529 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15530 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15532 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15533 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15534 dwarf2_complex_location_expr_complaint ();
15536 fnp
->voffset
/= cu
->header
.addr_size
;
15540 dwarf2_complex_location_expr_complaint ();
15542 if (!fnp
->fcontext
)
15544 /* If there is no `this' field and no DW_AT_containing_type,
15545 we cannot actually find a base class context for the
15547 if (TYPE_NFIELDS (this_type
) == 0
15548 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15550 complaint (&symfile_complaints
,
15551 _("cannot determine context for virtual member "
15552 "function \"%s\" (offset %d)"),
15553 fieldname
, to_underlying (die
->sect_off
));
15558 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15562 else if (attr_form_is_section_offset (attr
))
15564 dwarf2_complex_location_expr_complaint ();
15568 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15574 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15575 if (attr
&& DW_UNSND (attr
))
15577 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15578 complaint (&symfile_complaints
,
15579 _("Member function \"%s\" (offset %d) is virtual "
15580 "but the vtable offset is not specified"),
15581 fieldname
, to_underlying (die
->sect_off
));
15582 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15583 TYPE_CPLUS_DYNAMIC (type
) = 1;
15588 /* Create the vector of member function fields, and attach it to the type. */
15591 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15592 struct dwarf2_cu
*cu
)
15594 struct fnfieldlist
*flp
;
15597 if (cu
->language
== language_ada
)
15598 error (_("unexpected member functions in Ada type"));
15600 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15601 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15602 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
15604 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
15606 struct nextfnfield
*nfp
= flp
->head
;
15607 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15610 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
15611 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
15612 fn_flp
->fn_fields
= (struct fn_field
*)
15613 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
15614 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
15615 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
15618 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
15621 /* Returns non-zero if NAME is the name of a vtable member in CU's
15622 language, zero otherwise. */
15624 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15626 static const char vptr
[] = "_vptr";
15628 /* Look for the C++ form of the vtable. */
15629 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15635 /* GCC outputs unnamed structures that are really pointers to member
15636 functions, with the ABI-specified layout. If TYPE describes
15637 such a structure, smash it into a member function type.
15639 GCC shouldn't do this; it should just output pointer to member DIEs.
15640 This is GCC PR debug/28767. */
15643 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15645 struct type
*pfn_type
, *self_type
, *new_type
;
15647 /* Check for a structure with no name and two children. */
15648 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15651 /* Check for __pfn and __delta members. */
15652 if (TYPE_FIELD_NAME (type
, 0) == NULL
15653 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15654 || TYPE_FIELD_NAME (type
, 1) == NULL
15655 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15658 /* Find the type of the method. */
15659 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15660 if (pfn_type
== NULL
15661 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15662 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15665 /* Look for the "this" argument. */
15666 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15667 if (TYPE_NFIELDS (pfn_type
) == 0
15668 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15669 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15672 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15673 new_type
= alloc_type (objfile
);
15674 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15675 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15676 TYPE_VARARGS (pfn_type
));
15677 smash_to_methodptr_type (type
, new_type
);
15681 /* Called when we find the DIE that starts a structure or union scope
15682 (definition) to create a type for the structure or union. Fill in
15683 the type's name and general properties; the members will not be
15684 processed until process_structure_scope. A symbol table entry for
15685 the type will also not be done until process_structure_scope (assuming
15686 the type has a name).
15688 NOTE: we need to call these functions regardless of whether or not the
15689 DIE has a DW_AT_name attribute, since it might be an anonymous
15690 structure or union. This gets the type entered into our set of
15691 user defined types. */
15693 static struct type
*
15694 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15696 struct objfile
*objfile
= cu
->objfile
;
15698 struct attribute
*attr
;
15701 /* If the definition of this type lives in .debug_types, read that type.
15702 Don't follow DW_AT_specification though, that will take us back up
15703 the chain and we want to go down. */
15704 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15707 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15709 /* The type's CU may not be the same as CU.
15710 Ensure TYPE is recorded with CU in die_type_hash. */
15711 return set_die_type (die
, type
, cu
);
15714 type
= alloc_type (objfile
);
15715 INIT_CPLUS_SPECIFIC (type
);
15717 name
= dwarf2_name (die
, cu
);
15720 if (cu
->language
== language_cplus
15721 || cu
->language
== language_d
15722 || cu
->language
== language_rust
)
15724 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15726 /* dwarf2_full_name might have already finished building the DIE's
15727 type. If so, there is no need to continue. */
15728 if (get_die_type (die
, cu
) != NULL
)
15729 return get_die_type (die
, cu
);
15731 TYPE_TAG_NAME (type
) = full_name
;
15732 if (die
->tag
== DW_TAG_structure_type
15733 || die
->tag
== DW_TAG_class_type
)
15734 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
15738 /* The name is already allocated along with this objfile, so
15739 we don't need to duplicate it for the type. */
15740 TYPE_TAG_NAME (type
) = name
;
15741 if (die
->tag
== DW_TAG_class_type
)
15742 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
15746 if (die
->tag
== DW_TAG_structure_type
)
15748 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15750 else if (die
->tag
== DW_TAG_union_type
)
15752 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15756 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15759 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15760 TYPE_DECLARED_CLASS (type
) = 1;
15762 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15765 if (attr_form_is_constant (attr
))
15766 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15769 /* For the moment, dynamic type sizes are not supported
15770 by GDB's struct type. The actual size is determined
15771 on-demand when resolving the type of a given object,
15772 so set the type's length to zero for now. Otherwise,
15773 we record an expression as the length, and that expression
15774 could lead to a very large value, which could eventually
15775 lead to us trying to allocate that much memory when creating
15776 a value of that type. */
15777 TYPE_LENGTH (type
) = 0;
15782 TYPE_LENGTH (type
) = 0;
15785 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15787 /* ICC<14 does not output the required DW_AT_declaration on
15788 incomplete types, but gives them a size of zero. */
15789 TYPE_STUB (type
) = 1;
15792 TYPE_STUB_SUPPORTED (type
) = 1;
15794 if (die_is_declaration (die
, cu
))
15795 TYPE_STUB (type
) = 1;
15796 else if (attr
== NULL
&& die
->child
== NULL
15797 && producer_is_realview (cu
->producer
))
15798 /* RealView does not output the required DW_AT_declaration
15799 on incomplete types. */
15800 TYPE_STUB (type
) = 1;
15802 /* We need to add the type field to the die immediately so we don't
15803 infinitely recurse when dealing with pointers to the structure
15804 type within the structure itself. */
15805 set_die_type (die
, type
, cu
);
15807 /* set_die_type should be already done. */
15808 set_descriptive_type (type
, die
, cu
);
15813 /* Finish creating a structure or union type, including filling in
15814 its members and creating a symbol for it. */
15817 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15819 struct objfile
*objfile
= cu
->objfile
;
15820 struct die_info
*child_die
;
15823 type
= get_die_type (die
, cu
);
15825 type
= read_structure_type (die
, cu
);
15827 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15829 struct field_info fi
;
15830 std::vector
<struct symbol
*> template_args
;
15831 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
15833 memset (&fi
, 0, sizeof (struct field_info
));
15835 child_die
= die
->child
;
15837 while (child_die
&& child_die
->tag
)
15839 if (child_die
->tag
== DW_TAG_member
15840 || child_die
->tag
== DW_TAG_variable
)
15842 /* NOTE: carlton/2002-11-05: A C++ static data member
15843 should be a DW_TAG_member that is a declaration, but
15844 all versions of G++ as of this writing (so through at
15845 least 3.2.1) incorrectly generate DW_TAG_variable
15846 tags for them instead. */
15847 dwarf2_add_field (&fi
, child_die
, cu
);
15849 else if (child_die
->tag
== DW_TAG_subprogram
)
15851 /* Rust doesn't have member functions in the C++ sense.
15852 However, it does emit ordinary functions as children
15853 of a struct DIE. */
15854 if (cu
->language
== language_rust
)
15855 read_func_scope (child_die
, cu
);
15858 /* C++ member function. */
15859 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
15862 else if (child_die
->tag
== DW_TAG_inheritance
)
15864 /* C++ base class field. */
15865 dwarf2_add_field (&fi
, child_die
, cu
);
15867 else if (type_can_define_types (child_die
))
15868 dwarf2_add_type_defn (&fi
, child_die
, cu
);
15869 else if (child_die
->tag
== DW_TAG_template_type_param
15870 || child_die
->tag
== DW_TAG_template_value_param
)
15872 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15875 template_args
.push_back (arg
);
15878 child_die
= sibling_die (child_die
);
15881 /* Attach template arguments to type. */
15882 if (!template_args
.empty ())
15884 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15885 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15886 TYPE_TEMPLATE_ARGUMENTS (type
)
15887 = XOBNEWVEC (&objfile
->objfile_obstack
,
15889 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15890 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15891 template_args
.data (),
15892 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15893 * sizeof (struct symbol
*)));
15896 /* Attach fields and member functions to the type. */
15898 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15901 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15903 /* Get the type which refers to the base class (possibly this
15904 class itself) which contains the vtable pointer for the current
15905 class from the DW_AT_containing_type attribute. This use of
15906 DW_AT_containing_type is a GNU extension. */
15908 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15910 struct type
*t
= die_containing_type (die
, cu
);
15912 set_type_vptr_basetype (type
, t
);
15917 /* Our own class provides vtbl ptr. */
15918 for (i
= TYPE_NFIELDS (t
) - 1;
15919 i
>= TYPE_N_BASECLASSES (t
);
15922 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15924 if (is_vtable_name (fieldname
, cu
))
15926 set_type_vptr_fieldno (type
, i
);
15931 /* Complain if virtual function table field not found. */
15932 if (i
< TYPE_N_BASECLASSES (t
))
15933 complaint (&symfile_complaints
,
15934 _("virtual function table pointer "
15935 "not found when defining class '%s'"),
15936 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
15941 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15944 else if (cu
->producer
15945 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15947 /* The IBM XLC compiler does not provide direct indication
15948 of the containing type, but the vtable pointer is
15949 always named __vfp. */
15953 for (i
= TYPE_NFIELDS (type
) - 1;
15954 i
>= TYPE_N_BASECLASSES (type
);
15957 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15959 set_type_vptr_fieldno (type
, i
);
15960 set_type_vptr_basetype (type
, type
);
15967 /* Copy fi.typedef_field_list linked list elements content into the
15968 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15969 if (fi
.typedef_field_list
)
15971 int i
= fi
.typedef_field_list_count
;
15973 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15974 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15975 = ((struct decl_field
*)
15976 TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
));
15977 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
15979 /* Reverse the list order to keep the debug info elements order. */
15982 struct decl_field
*dest
, *src
;
15984 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
15985 src
= &fi
.typedef_field_list
->field
;
15986 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
15991 /* Copy fi.nested_types_list linked list elements content into the
15992 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15993 if (fi
.nested_types_list
!= NULL
&& cu
->language
!= language_ada
)
15995 int i
= fi
.nested_types_list_count
;
15997 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15998 TYPE_NESTED_TYPES_ARRAY (type
)
15999 = ((struct decl_field
*)
16000 TYPE_ALLOC (type
, sizeof (struct decl_field
) * i
));
16001 TYPE_NESTED_TYPES_COUNT (type
) = i
;
16003 /* Reverse the list order to keep the debug info elements order. */
16006 struct decl_field
*dest
, *src
;
16008 dest
= &TYPE_NESTED_TYPES_FIELD (type
, i
);
16009 src
= &fi
.nested_types_list
->field
;
16010 fi
.nested_types_list
= fi
.nested_types_list
->next
;
16015 do_cleanups (back_to
);
16018 quirk_gcc_member_function_pointer (type
, objfile
);
16020 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16021 snapshots) has been known to create a die giving a declaration
16022 for a class that has, as a child, a die giving a definition for a
16023 nested class. So we have to process our children even if the
16024 current die is a declaration. Normally, of course, a declaration
16025 won't have any children at all. */
16027 child_die
= die
->child
;
16029 while (child_die
!= NULL
&& child_die
->tag
)
16031 if (child_die
->tag
== DW_TAG_member
16032 || child_die
->tag
== DW_TAG_variable
16033 || child_die
->tag
== DW_TAG_inheritance
16034 || child_die
->tag
== DW_TAG_template_value_param
16035 || child_die
->tag
== DW_TAG_template_type_param
)
16040 process_die (child_die
, cu
);
16042 child_die
= sibling_die (child_die
);
16045 /* Do not consider external references. According to the DWARF standard,
16046 these DIEs are identified by the fact that they have no byte_size
16047 attribute, and a declaration attribute. */
16048 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16049 || !die_is_declaration (die
, cu
))
16050 new_symbol (die
, type
, cu
);
16053 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16054 update TYPE using some information only available in DIE's children. */
16057 update_enumeration_type_from_children (struct die_info
*die
,
16059 struct dwarf2_cu
*cu
)
16061 struct die_info
*child_die
;
16062 int unsigned_enum
= 1;
16066 auto_obstack obstack
;
16068 for (child_die
= die
->child
;
16069 child_die
!= NULL
&& child_die
->tag
;
16070 child_die
= sibling_die (child_die
))
16072 struct attribute
*attr
;
16074 const gdb_byte
*bytes
;
16075 struct dwarf2_locexpr_baton
*baton
;
16078 if (child_die
->tag
!= DW_TAG_enumerator
)
16081 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16085 name
= dwarf2_name (child_die
, cu
);
16087 name
= "<anonymous enumerator>";
16089 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16090 &value
, &bytes
, &baton
);
16096 else if ((mask
& value
) != 0)
16101 /* If we already know that the enum type is neither unsigned, nor
16102 a flag type, no need to look at the rest of the enumerates. */
16103 if (!unsigned_enum
&& !flag_enum
)
16108 TYPE_UNSIGNED (type
) = 1;
16110 TYPE_FLAG_ENUM (type
) = 1;
16113 /* Given a DW_AT_enumeration_type die, set its type. We do not
16114 complete the type's fields yet, or create any symbols. */
16116 static struct type
*
16117 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16119 struct objfile
*objfile
= cu
->objfile
;
16121 struct attribute
*attr
;
16124 /* If the definition of this type lives in .debug_types, read that type.
16125 Don't follow DW_AT_specification though, that will take us back up
16126 the chain and we want to go down. */
16127 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16130 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16132 /* The type's CU may not be the same as CU.
16133 Ensure TYPE is recorded with CU in die_type_hash. */
16134 return set_die_type (die
, type
, cu
);
16137 type
= alloc_type (objfile
);
16139 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16140 name
= dwarf2_full_name (NULL
, die
, cu
);
16142 TYPE_TAG_NAME (type
) = name
;
16144 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16147 struct type
*underlying_type
= die_type (die
, cu
);
16149 TYPE_TARGET_TYPE (type
) = underlying_type
;
16152 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16155 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16159 TYPE_LENGTH (type
) = 0;
16162 /* The enumeration DIE can be incomplete. In Ada, any type can be
16163 declared as private in the package spec, and then defined only
16164 inside the package body. Such types are known as Taft Amendment
16165 Types. When another package uses such a type, an incomplete DIE
16166 may be generated by the compiler. */
16167 if (die_is_declaration (die
, cu
))
16168 TYPE_STUB (type
) = 1;
16170 /* Finish the creation of this type by using the enum's children.
16171 We must call this even when the underlying type has been provided
16172 so that we can determine if we're looking at a "flag" enum. */
16173 update_enumeration_type_from_children (die
, type
, cu
);
16175 /* If this type has an underlying type that is not a stub, then we
16176 may use its attributes. We always use the "unsigned" attribute
16177 in this situation, because ordinarily we guess whether the type
16178 is unsigned -- but the guess can be wrong and the underlying type
16179 can tell us the reality. However, we defer to a local size
16180 attribute if one exists, because this lets the compiler override
16181 the underlying type if needed. */
16182 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16184 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16185 if (TYPE_LENGTH (type
) == 0)
16186 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16189 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16191 return set_die_type (die
, type
, cu
);
16194 /* Given a pointer to a die which begins an enumeration, process all
16195 the dies that define the members of the enumeration, and create the
16196 symbol for the enumeration type.
16198 NOTE: We reverse the order of the element list. */
16201 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16203 struct type
*this_type
;
16205 this_type
= get_die_type (die
, cu
);
16206 if (this_type
== NULL
)
16207 this_type
= read_enumeration_type (die
, cu
);
16209 if (die
->child
!= NULL
)
16211 struct die_info
*child_die
;
16212 struct symbol
*sym
;
16213 struct field
*fields
= NULL
;
16214 int num_fields
= 0;
16217 child_die
= die
->child
;
16218 while (child_die
&& child_die
->tag
)
16220 if (child_die
->tag
!= DW_TAG_enumerator
)
16222 process_die (child_die
, cu
);
16226 name
= dwarf2_name (child_die
, cu
);
16229 sym
= new_symbol (child_die
, this_type
, cu
);
16231 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
16233 fields
= (struct field
*)
16235 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
16236 * sizeof (struct field
));
16239 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
16240 FIELD_TYPE (fields
[num_fields
]) = NULL
;
16241 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
16242 FIELD_BITSIZE (fields
[num_fields
]) = 0;
16248 child_die
= sibling_die (child_die
);
16253 TYPE_NFIELDS (this_type
) = num_fields
;
16254 TYPE_FIELDS (this_type
) = (struct field
*)
16255 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
16256 memcpy (TYPE_FIELDS (this_type
), fields
,
16257 sizeof (struct field
) * num_fields
);
16262 /* If we are reading an enum from a .debug_types unit, and the enum
16263 is a declaration, and the enum is not the signatured type in the
16264 unit, then we do not want to add a symbol for it. Adding a
16265 symbol would in some cases obscure the true definition of the
16266 enum, giving users an incomplete type when the definition is
16267 actually available. Note that we do not want to do this for all
16268 enums which are just declarations, because C++0x allows forward
16269 enum declarations. */
16270 if (cu
->per_cu
->is_debug_types
16271 && die_is_declaration (die
, cu
))
16273 struct signatured_type
*sig_type
;
16275 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16276 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16277 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16281 new_symbol (die
, this_type
, cu
);
16284 /* Extract all information from a DW_TAG_array_type DIE and put it in
16285 the DIE's type field. For now, this only handles one dimensional
16288 static struct type
*
16289 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16291 struct objfile
*objfile
= cu
->objfile
;
16292 struct die_info
*child_die
;
16294 struct type
*element_type
, *range_type
, *index_type
;
16295 struct attribute
*attr
;
16297 unsigned int bit_stride
= 0;
16299 element_type
= die_type (die
, cu
);
16301 /* The die_type call above may have already set the type for this DIE. */
16302 type
= get_die_type (die
, cu
);
16306 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16308 bit_stride
= DW_UNSND (attr
) * 8;
16310 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16312 bit_stride
= DW_UNSND (attr
);
16314 /* Irix 6.2 native cc creates array types without children for
16315 arrays with unspecified length. */
16316 if (die
->child
== NULL
)
16318 index_type
= objfile_type (objfile
)->builtin_int
;
16319 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16320 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16322 return set_die_type (die
, type
, cu
);
16325 std::vector
<struct type
*> range_types
;
16326 child_die
= die
->child
;
16327 while (child_die
&& child_die
->tag
)
16329 if (child_die
->tag
== DW_TAG_subrange_type
)
16331 struct type
*child_type
= read_type_die (child_die
, cu
);
16333 if (child_type
!= NULL
)
16335 /* The range type was succesfully read. Save it for the
16336 array type creation. */
16337 range_types
.push_back (child_type
);
16340 child_die
= sibling_die (child_die
);
16343 /* Dwarf2 dimensions are output from left to right, create the
16344 necessary array types in backwards order. */
16346 type
= element_type
;
16348 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16352 while (i
< range_types
.size ())
16353 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16358 size_t ndim
= range_types
.size ();
16360 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16364 /* Understand Dwarf2 support for vector types (like they occur on
16365 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16366 array type. This is not part of the Dwarf2/3 standard yet, but a
16367 custom vendor extension. The main difference between a regular
16368 array and the vector variant is that vectors are passed by value
16370 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16372 make_vector_type (type
);
16374 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16375 implementation may choose to implement triple vectors using this
16377 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16380 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16381 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16383 complaint (&symfile_complaints
,
16384 _("DW_AT_byte_size for array type smaller "
16385 "than the total size of elements"));
16388 name
= dwarf2_name (die
, cu
);
16390 TYPE_NAME (type
) = name
;
16392 /* Install the type in the die. */
16393 set_die_type (die
, type
, cu
);
16395 /* set_die_type should be already done. */
16396 set_descriptive_type (type
, die
, cu
);
16401 static enum dwarf_array_dim_ordering
16402 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16404 struct attribute
*attr
;
16406 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16409 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16411 /* GNU F77 is a special case, as at 08/2004 array type info is the
16412 opposite order to the dwarf2 specification, but data is still
16413 laid out as per normal fortran.
16415 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16416 version checking. */
16418 if (cu
->language
== language_fortran
16419 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16421 return DW_ORD_row_major
;
16424 switch (cu
->language_defn
->la_array_ordering
)
16426 case array_column_major
:
16427 return DW_ORD_col_major
;
16428 case array_row_major
:
16430 return DW_ORD_row_major
;
16434 /* Extract all information from a DW_TAG_set_type DIE and put it in
16435 the DIE's type field. */
16437 static struct type
*
16438 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16440 struct type
*domain_type
, *set_type
;
16441 struct attribute
*attr
;
16443 domain_type
= die_type (die
, cu
);
16445 /* The die_type call above may have already set the type for this DIE. */
16446 set_type
= get_die_type (die
, cu
);
16450 set_type
= create_set_type (NULL
, domain_type
);
16452 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16454 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16456 return set_die_type (die
, set_type
, cu
);
16459 /* A helper for read_common_block that creates a locexpr baton.
16460 SYM is the symbol which we are marking as computed.
16461 COMMON_DIE is the DIE for the common block.
16462 COMMON_LOC is the location expression attribute for the common
16464 MEMBER_LOC is the location expression attribute for the particular
16465 member of the common block that we are processing.
16466 CU is the CU from which the above come. */
16469 mark_common_block_symbol_computed (struct symbol
*sym
,
16470 struct die_info
*common_die
,
16471 struct attribute
*common_loc
,
16472 struct attribute
*member_loc
,
16473 struct dwarf2_cu
*cu
)
16475 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16476 struct dwarf2_locexpr_baton
*baton
;
16478 unsigned int cu_off
;
16479 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16480 LONGEST offset
= 0;
16482 gdb_assert (common_loc
&& member_loc
);
16483 gdb_assert (attr_form_is_block (common_loc
));
16484 gdb_assert (attr_form_is_block (member_loc
)
16485 || attr_form_is_constant (member_loc
));
16487 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16488 baton
->per_cu
= cu
->per_cu
;
16489 gdb_assert (baton
->per_cu
);
16491 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16493 if (attr_form_is_constant (member_loc
))
16495 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16496 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16499 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16501 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16504 *ptr
++ = DW_OP_call4
;
16505 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16506 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16509 if (attr_form_is_constant (member_loc
))
16511 *ptr
++ = DW_OP_addr
;
16512 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16513 ptr
+= cu
->header
.addr_size
;
16517 /* We have to copy the data here, because DW_OP_call4 will only
16518 use a DW_AT_location attribute. */
16519 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16520 ptr
+= DW_BLOCK (member_loc
)->size
;
16523 *ptr
++ = DW_OP_plus
;
16524 gdb_assert (ptr
- baton
->data
== baton
->size
);
16526 SYMBOL_LOCATION_BATON (sym
) = baton
;
16527 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16530 /* Create appropriate locally-scoped variables for all the
16531 DW_TAG_common_block entries. Also create a struct common_block
16532 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16533 is used to sepate the common blocks name namespace from regular
16537 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16539 struct attribute
*attr
;
16541 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16544 /* Support the .debug_loc offsets. */
16545 if (attr_form_is_block (attr
))
16549 else if (attr_form_is_section_offset (attr
))
16551 dwarf2_complex_location_expr_complaint ();
16556 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16557 "common block member");
16562 if (die
->child
!= NULL
)
16564 struct objfile
*objfile
= cu
->objfile
;
16565 struct die_info
*child_die
;
16566 size_t n_entries
= 0, size
;
16567 struct common_block
*common_block
;
16568 struct symbol
*sym
;
16570 for (child_die
= die
->child
;
16571 child_die
&& child_die
->tag
;
16572 child_die
= sibling_die (child_die
))
16575 size
= (sizeof (struct common_block
)
16576 + (n_entries
- 1) * sizeof (struct symbol
*));
16578 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16580 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16581 common_block
->n_entries
= 0;
16583 for (child_die
= die
->child
;
16584 child_die
&& child_die
->tag
;
16585 child_die
= sibling_die (child_die
))
16587 /* Create the symbol in the DW_TAG_common_block block in the current
16589 sym
= new_symbol (child_die
, NULL
, cu
);
16592 struct attribute
*member_loc
;
16594 common_block
->contents
[common_block
->n_entries
++] = sym
;
16596 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16600 /* GDB has handled this for a long time, but it is
16601 not specified by DWARF. It seems to have been
16602 emitted by gfortran at least as recently as:
16603 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16604 complaint (&symfile_complaints
,
16605 _("Variable in common block has "
16606 "DW_AT_data_member_location "
16607 "- DIE at 0x%x [in module %s]"),
16608 to_underlying (child_die
->sect_off
),
16609 objfile_name (cu
->objfile
));
16611 if (attr_form_is_section_offset (member_loc
))
16612 dwarf2_complex_location_expr_complaint ();
16613 else if (attr_form_is_constant (member_loc
)
16614 || attr_form_is_block (member_loc
))
16617 mark_common_block_symbol_computed (sym
, die
, attr
,
16621 dwarf2_complex_location_expr_complaint ();
16626 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16627 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16631 /* Create a type for a C++ namespace. */
16633 static struct type
*
16634 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16636 struct objfile
*objfile
= cu
->objfile
;
16637 const char *previous_prefix
, *name
;
16641 /* For extensions, reuse the type of the original namespace. */
16642 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16644 struct die_info
*ext_die
;
16645 struct dwarf2_cu
*ext_cu
= cu
;
16647 ext_die
= dwarf2_extension (die
, &ext_cu
);
16648 type
= read_type_die (ext_die
, ext_cu
);
16650 /* EXT_CU may not be the same as CU.
16651 Ensure TYPE is recorded with CU in die_type_hash. */
16652 return set_die_type (die
, type
, cu
);
16655 name
= namespace_name (die
, &is_anonymous
, cu
);
16657 /* Now build the name of the current namespace. */
16659 previous_prefix
= determine_prefix (die
, cu
);
16660 if (previous_prefix
[0] != '\0')
16661 name
= typename_concat (&objfile
->objfile_obstack
,
16662 previous_prefix
, name
, 0, cu
);
16664 /* Create the type. */
16665 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16666 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
16668 return set_die_type (die
, type
, cu
);
16671 /* Read a namespace scope. */
16674 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16676 struct objfile
*objfile
= cu
->objfile
;
16679 /* Add a symbol associated to this if we haven't seen the namespace
16680 before. Also, add a using directive if it's an anonymous
16683 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16687 type
= read_type_die (die
, cu
);
16688 new_symbol (die
, type
, cu
);
16690 namespace_name (die
, &is_anonymous
, cu
);
16693 const char *previous_prefix
= determine_prefix (die
, cu
);
16695 std::vector
<const char *> excludes
;
16696 add_using_directive (using_directives (cu
->language
),
16697 previous_prefix
, TYPE_NAME (type
), NULL
,
16698 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16702 if (die
->child
!= NULL
)
16704 struct die_info
*child_die
= die
->child
;
16706 while (child_die
&& child_die
->tag
)
16708 process_die (child_die
, cu
);
16709 child_die
= sibling_die (child_die
);
16714 /* Read a Fortran module as type. This DIE can be only a declaration used for
16715 imported module. Still we need that type as local Fortran "use ... only"
16716 declaration imports depend on the created type in determine_prefix. */
16718 static struct type
*
16719 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16721 struct objfile
*objfile
= cu
->objfile
;
16722 const char *module_name
;
16725 module_name
= dwarf2_name (die
, cu
);
16727 complaint (&symfile_complaints
,
16728 _("DW_TAG_module has no name, offset 0x%x"),
16729 to_underlying (die
->sect_off
));
16730 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16732 /* determine_prefix uses TYPE_TAG_NAME. */
16733 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
16735 return set_die_type (die
, type
, cu
);
16738 /* Read a Fortran module. */
16741 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16743 struct die_info
*child_die
= die
->child
;
16746 type
= read_type_die (die
, cu
);
16747 new_symbol (die
, type
, cu
);
16749 while (child_die
&& child_die
->tag
)
16751 process_die (child_die
, cu
);
16752 child_die
= sibling_die (child_die
);
16756 /* Return the name of the namespace represented by DIE. Set
16757 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16760 static const char *
16761 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16763 struct die_info
*current_die
;
16764 const char *name
= NULL
;
16766 /* Loop through the extensions until we find a name. */
16768 for (current_die
= die
;
16769 current_die
!= NULL
;
16770 current_die
= dwarf2_extension (die
, &cu
))
16772 /* We don't use dwarf2_name here so that we can detect the absence
16773 of a name -> anonymous namespace. */
16774 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16780 /* Is it an anonymous namespace? */
16782 *is_anonymous
= (name
== NULL
);
16784 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16789 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16790 the user defined type vector. */
16792 static struct type
*
16793 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16795 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
16796 struct comp_unit_head
*cu_header
= &cu
->header
;
16798 struct attribute
*attr_byte_size
;
16799 struct attribute
*attr_address_class
;
16800 int byte_size
, addr_class
;
16801 struct type
*target_type
;
16803 target_type
= die_type (die
, cu
);
16805 /* The die_type call above may have already set the type for this DIE. */
16806 type
= get_die_type (die
, cu
);
16810 type
= lookup_pointer_type (target_type
);
16812 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16813 if (attr_byte_size
)
16814 byte_size
= DW_UNSND (attr_byte_size
);
16816 byte_size
= cu_header
->addr_size
;
16818 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16819 if (attr_address_class
)
16820 addr_class
= DW_UNSND (attr_address_class
);
16822 addr_class
= DW_ADDR_none
;
16824 /* If the pointer size or address class is different than the
16825 default, create a type variant marked as such and set the
16826 length accordingly. */
16827 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
16829 if (gdbarch_address_class_type_flags_p (gdbarch
))
16833 type_flags
= gdbarch_address_class_type_flags
16834 (gdbarch
, byte_size
, addr_class
);
16835 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16837 type
= make_type_with_address_space (type
, type_flags
);
16839 else if (TYPE_LENGTH (type
) != byte_size
)
16841 complaint (&symfile_complaints
,
16842 _("invalid pointer size %d"), byte_size
);
16846 /* Should we also complain about unhandled address classes? */
16850 TYPE_LENGTH (type
) = byte_size
;
16851 return set_die_type (die
, type
, cu
);
16854 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16855 the user defined type vector. */
16857 static struct type
*
16858 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16861 struct type
*to_type
;
16862 struct type
*domain
;
16864 to_type
= die_type (die
, cu
);
16865 domain
= die_containing_type (die
, cu
);
16867 /* The calls above may have already set the type for this DIE. */
16868 type
= get_die_type (die
, cu
);
16872 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16873 type
= lookup_methodptr_type (to_type
);
16874 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16876 struct type
*new_type
= alloc_type (cu
->objfile
);
16878 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16879 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16880 TYPE_VARARGS (to_type
));
16881 type
= lookup_methodptr_type (new_type
);
16884 type
= lookup_memberptr_type (to_type
, domain
);
16886 return set_die_type (die
, type
, cu
);
16889 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16890 the user defined type vector. */
16892 static struct type
*
16893 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16894 enum type_code refcode
)
16896 struct comp_unit_head
*cu_header
= &cu
->header
;
16897 struct type
*type
, *target_type
;
16898 struct attribute
*attr
;
16900 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16902 target_type
= die_type (die
, cu
);
16904 /* The die_type call above may have already set the type for this DIE. */
16905 type
= get_die_type (die
, cu
);
16909 type
= lookup_reference_type (target_type
, refcode
);
16910 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16913 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16917 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16919 return set_die_type (die
, type
, cu
);
16922 /* Add the given cv-qualifiers to the element type of the array. GCC
16923 outputs DWARF type qualifiers that apply to an array, not the
16924 element type. But GDB relies on the array element type to carry
16925 the cv-qualifiers. This mimics section 6.7.3 of the C99
16928 static struct type
*
16929 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16930 struct type
*base_type
, int cnst
, int voltl
)
16932 struct type
*el_type
, *inner_array
;
16934 base_type
= copy_type (base_type
);
16935 inner_array
= base_type
;
16937 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16939 TYPE_TARGET_TYPE (inner_array
) =
16940 copy_type (TYPE_TARGET_TYPE (inner_array
));
16941 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16944 el_type
= TYPE_TARGET_TYPE (inner_array
);
16945 cnst
|= TYPE_CONST (el_type
);
16946 voltl
|= TYPE_VOLATILE (el_type
);
16947 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16949 return set_die_type (die
, base_type
, cu
);
16952 static struct type
*
16953 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16955 struct type
*base_type
, *cv_type
;
16957 base_type
= die_type (die
, cu
);
16959 /* The die_type call above may have already set the type for this DIE. */
16960 cv_type
= get_die_type (die
, cu
);
16964 /* In case the const qualifier is applied to an array type, the element type
16965 is so qualified, not the array type (section 6.7.3 of C99). */
16966 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16967 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16969 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16970 return set_die_type (die
, cv_type
, cu
);
16973 static struct type
*
16974 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16976 struct type
*base_type
, *cv_type
;
16978 base_type
= die_type (die
, cu
);
16980 /* The die_type call above may have already set the type for this DIE. */
16981 cv_type
= get_die_type (die
, cu
);
16985 /* In case the volatile qualifier is applied to an array type, the
16986 element type is so qualified, not the array type (section 6.7.3
16988 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16989 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16991 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16992 return set_die_type (die
, cv_type
, cu
);
16995 /* Handle DW_TAG_restrict_type. */
16997 static struct type
*
16998 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17000 struct type
*base_type
, *cv_type
;
17002 base_type
= die_type (die
, cu
);
17004 /* The die_type call above may have already set the type for this DIE. */
17005 cv_type
= get_die_type (die
, cu
);
17009 cv_type
= make_restrict_type (base_type
);
17010 return set_die_type (die
, cv_type
, cu
);
17013 /* Handle DW_TAG_atomic_type. */
17015 static struct type
*
17016 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17018 struct type
*base_type
, *cv_type
;
17020 base_type
= die_type (die
, cu
);
17022 /* The die_type call above may have already set the type for this DIE. */
17023 cv_type
= get_die_type (die
, cu
);
17027 cv_type
= make_atomic_type (base_type
);
17028 return set_die_type (die
, cv_type
, cu
);
17031 /* Extract all information from a DW_TAG_string_type DIE and add to
17032 the user defined type vector. It isn't really a user defined type,
17033 but it behaves like one, with other DIE's using an AT_user_def_type
17034 attribute to reference it. */
17036 static struct type
*
17037 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17039 struct objfile
*objfile
= cu
->objfile
;
17040 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17041 struct type
*type
, *range_type
, *index_type
, *char_type
;
17042 struct attribute
*attr
;
17043 unsigned int length
;
17045 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17048 length
= DW_UNSND (attr
);
17052 /* Check for the DW_AT_byte_size attribute. */
17053 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17056 length
= DW_UNSND (attr
);
17064 index_type
= objfile_type (objfile
)->builtin_int
;
17065 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17066 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17067 type
= create_string_type (NULL
, char_type
, range_type
);
17069 return set_die_type (die
, type
, cu
);
17072 /* Assuming that DIE corresponds to a function, returns nonzero
17073 if the function is prototyped. */
17076 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17078 struct attribute
*attr
;
17080 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17081 if (attr
&& (DW_UNSND (attr
) != 0))
17084 /* The DWARF standard implies that the DW_AT_prototyped attribute
17085 is only meaninful for C, but the concept also extends to other
17086 languages that allow unprototyped functions (Eg: Objective C).
17087 For all other languages, assume that functions are always
17089 if (cu
->language
!= language_c
17090 && cu
->language
!= language_objc
17091 && cu
->language
!= language_opencl
)
17094 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17095 prototyped and unprototyped functions; default to prototyped,
17096 since that is more common in modern code (and RealView warns
17097 about unprototyped functions). */
17098 if (producer_is_realview (cu
->producer
))
17104 /* Handle DIES due to C code like:
17108 int (*funcp)(int a, long l);
17112 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17114 static struct type
*
17115 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17117 struct objfile
*objfile
= cu
->objfile
;
17118 struct type
*type
; /* Type that this function returns. */
17119 struct type
*ftype
; /* Function that returns above type. */
17120 struct attribute
*attr
;
17122 type
= die_type (die
, cu
);
17124 /* The die_type call above may have already set the type for this DIE. */
17125 ftype
= get_die_type (die
, cu
);
17129 ftype
= lookup_function_type (type
);
17131 if (prototyped_function_p (die
, cu
))
17132 TYPE_PROTOTYPED (ftype
) = 1;
17134 /* Store the calling convention in the type if it's available in
17135 the subroutine die. Otherwise set the calling convention to
17136 the default value DW_CC_normal. */
17137 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17139 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
17140 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17141 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17143 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17145 /* Record whether the function returns normally to its caller or not
17146 if the DWARF producer set that information. */
17147 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17148 if (attr
&& (DW_UNSND (attr
) != 0))
17149 TYPE_NO_RETURN (ftype
) = 1;
17151 /* We need to add the subroutine type to the die immediately so
17152 we don't infinitely recurse when dealing with parameters
17153 declared as the same subroutine type. */
17154 set_die_type (die
, ftype
, cu
);
17156 if (die
->child
!= NULL
)
17158 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17159 struct die_info
*child_die
;
17160 int nparams
, iparams
;
17162 /* Count the number of parameters.
17163 FIXME: GDB currently ignores vararg functions, but knows about
17164 vararg member functions. */
17166 child_die
= die
->child
;
17167 while (child_die
&& child_die
->tag
)
17169 if (child_die
->tag
== DW_TAG_formal_parameter
)
17171 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17172 TYPE_VARARGS (ftype
) = 1;
17173 child_die
= sibling_die (child_die
);
17176 /* Allocate storage for parameters and fill them in. */
17177 TYPE_NFIELDS (ftype
) = nparams
;
17178 TYPE_FIELDS (ftype
) = (struct field
*)
17179 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17181 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17182 even if we error out during the parameters reading below. */
17183 for (iparams
= 0; iparams
< nparams
; iparams
++)
17184 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17187 child_die
= die
->child
;
17188 while (child_die
&& child_die
->tag
)
17190 if (child_die
->tag
== DW_TAG_formal_parameter
)
17192 struct type
*arg_type
;
17194 /* DWARF version 2 has no clean way to discern C++
17195 static and non-static member functions. G++ helps
17196 GDB by marking the first parameter for non-static
17197 member functions (which is the this pointer) as
17198 artificial. We pass this information to
17199 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17201 DWARF version 3 added DW_AT_object_pointer, which GCC
17202 4.5 does not yet generate. */
17203 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17205 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17207 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17208 arg_type
= die_type (child_die
, cu
);
17210 /* RealView does not mark THIS as const, which the testsuite
17211 expects. GCC marks THIS as const in method definitions,
17212 but not in the class specifications (GCC PR 43053). */
17213 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17214 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17217 struct dwarf2_cu
*arg_cu
= cu
;
17218 const char *name
= dwarf2_name (child_die
, cu
);
17220 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17223 /* If the compiler emits this, use it. */
17224 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17227 else if (name
&& strcmp (name
, "this") == 0)
17228 /* Function definitions will have the argument names. */
17230 else if (name
== NULL
&& iparams
== 0)
17231 /* Declarations may not have the names, so like
17232 elsewhere in GDB, assume an artificial first
17233 argument is "this". */
17237 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17241 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17244 child_die
= sibling_die (child_die
);
17251 static struct type
*
17252 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17254 struct objfile
*objfile
= cu
->objfile
;
17255 const char *name
= NULL
;
17256 struct type
*this_type
, *target_type
;
17258 name
= dwarf2_full_name (NULL
, die
, cu
);
17259 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17260 TYPE_TARGET_STUB (this_type
) = 1;
17261 set_die_type (die
, this_type
, cu
);
17262 target_type
= die_type (die
, cu
);
17263 if (target_type
!= this_type
)
17264 TYPE_TARGET_TYPE (this_type
) = target_type
;
17267 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17268 spec and cause infinite loops in GDB. */
17269 complaint (&symfile_complaints
,
17270 _("Self-referential DW_TAG_typedef "
17271 "- DIE at 0x%x [in module %s]"),
17272 to_underlying (die
->sect_off
), objfile_name (objfile
));
17273 TYPE_TARGET_TYPE (this_type
) = NULL
;
17278 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17279 (which may be different from NAME) to the architecture back-end to allow
17280 it to guess the correct format if necessary. */
17282 static struct type
*
17283 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17284 const char *name_hint
)
17286 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17287 const struct floatformat
**format
;
17290 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17292 type
= init_float_type (objfile
, bits
, name
, format
);
17294 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17299 /* Find a representation of a given base type and install
17300 it in the TYPE field of the die. */
17302 static struct type
*
17303 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17305 struct objfile
*objfile
= cu
->objfile
;
17307 struct attribute
*attr
;
17308 int encoding
= 0, bits
= 0;
17311 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17314 encoding
= DW_UNSND (attr
);
17316 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17319 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17321 name
= dwarf2_name (die
, cu
);
17324 complaint (&symfile_complaints
,
17325 _("DW_AT_name missing from DW_TAG_base_type"));
17330 case DW_ATE_address
:
17331 /* Turn DW_ATE_address into a void * pointer. */
17332 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17333 type
= init_pointer_type (objfile
, bits
, name
, type
);
17335 case DW_ATE_boolean
:
17336 type
= init_boolean_type (objfile
, bits
, 1, name
);
17338 case DW_ATE_complex_float
:
17339 type
= dwarf2_init_float_type (objfile
, bits
/ 2, NULL
, name
);
17340 type
= init_complex_type (objfile
, name
, type
);
17342 case DW_ATE_decimal_float
:
17343 type
= init_decfloat_type (objfile
, bits
, name
);
17346 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
17348 case DW_ATE_signed
:
17349 type
= init_integer_type (objfile
, bits
, 0, name
);
17351 case DW_ATE_unsigned
:
17352 if (cu
->language
== language_fortran
17354 && startswith (name
, "character("))
17355 type
= init_character_type (objfile
, bits
, 1, name
);
17357 type
= init_integer_type (objfile
, bits
, 1, name
);
17359 case DW_ATE_signed_char
:
17360 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17361 || cu
->language
== language_pascal
17362 || cu
->language
== language_fortran
)
17363 type
= init_character_type (objfile
, bits
, 0, name
);
17365 type
= init_integer_type (objfile
, bits
, 0, name
);
17367 case DW_ATE_unsigned_char
:
17368 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17369 || cu
->language
== language_pascal
17370 || cu
->language
== language_fortran
17371 || cu
->language
== language_rust
)
17372 type
= init_character_type (objfile
, bits
, 1, name
);
17374 type
= init_integer_type (objfile
, bits
, 1, name
);
17378 gdbarch
*arch
= get_objfile_arch (objfile
);
17381 type
= builtin_type (arch
)->builtin_char16
;
17382 else if (bits
== 32)
17383 type
= builtin_type (arch
)->builtin_char32
;
17386 complaint (&symfile_complaints
,
17387 _("unsupported DW_ATE_UTF bit size: '%d'"),
17389 type
= init_integer_type (objfile
, bits
, 1, name
);
17391 return set_die_type (die
, type
, cu
);
17396 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
17397 dwarf_type_encoding_name (encoding
));
17398 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17402 if (name
&& strcmp (name
, "char") == 0)
17403 TYPE_NOSIGN (type
) = 1;
17405 return set_die_type (die
, type
, cu
);
17408 /* Parse dwarf attribute if it's a block, reference or constant and put the
17409 resulting value of the attribute into struct bound_prop.
17410 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17413 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17414 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
17416 struct dwarf2_property_baton
*baton
;
17417 struct obstack
*obstack
= &cu
->objfile
->objfile_obstack
;
17419 if (attr
== NULL
|| prop
== NULL
)
17422 if (attr_form_is_block (attr
))
17424 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17425 baton
->referenced_type
= NULL
;
17426 baton
->locexpr
.per_cu
= cu
->per_cu
;
17427 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17428 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17429 prop
->data
.baton
= baton
;
17430 prop
->kind
= PROP_LOCEXPR
;
17431 gdb_assert (prop
->data
.baton
!= NULL
);
17433 else if (attr_form_is_ref (attr
))
17435 struct dwarf2_cu
*target_cu
= cu
;
17436 struct die_info
*target_die
;
17437 struct attribute
*target_attr
;
17439 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17440 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17441 if (target_attr
== NULL
)
17442 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17444 if (target_attr
== NULL
)
17447 switch (target_attr
->name
)
17449 case DW_AT_location
:
17450 if (attr_form_is_section_offset (target_attr
))
17452 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17453 baton
->referenced_type
= die_type (target_die
, target_cu
);
17454 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17455 prop
->data
.baton
= baton
;
17456 prop
->kind
= PROP_LOCLIST
;
17457 gdb_assert (prop
->data
.baton
!= NULL
);
17459 else if (attr_form_is_block (target_attr
))
17461 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17462 baton
->referenced_type
= die_type (target_die
, target_cu
);
17463 baton
->locexpr
.per_cu
= cu
->per_cu
;
17464 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17465 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17466 prop
->data
.baton
= baton
;
17467 prop
->kind
= PROP_LOCEXPR
;
17468 gdb_assert (prop
->data
.baton
!= NULL
);
17472 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17473 "dynamic property");
17477 case DW_AT_data_member_location
:
17481 if (!handle_data_member_location (target_die
, target_cu
,
17485 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17486 baton
->referenced_type
= read_type_die (target_die
->parent
,
17488 baton
->offset_info
.offset
= offset
;
17489 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17490 prop
->data
.baton
= baton
;
17491 prop
->kind
= PROP_ADDR_OFFSET
;
17496 else if (attr_form_is_constant (attr
))
17498 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17499 prop
->kind
= PROP_CONST
;
17503 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17504 dwarf2_name (die
, cu
));
17511 /* Read the given DW_AT_subrange DIE. */
17513 static struct type
*
17514 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17516 struct type
*base_type
, *orig_base_type
;
17517 struct type
*range_type
;
17518 struct attribute
*attr
;
17519 struct dynamic_prop low
, high
;
17520 int low_default_is_valid
;
17521 int high_bound_is_count
= 0;
17523 LONGEST negative_mask
;
17525 orig_base_type
= die_type (die
, cu
);
17526 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17527 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17528 creating the range type, but we use the result of check_typedef
17529 when examining properties of the type. */
17530 base_type
= check_typedef (orig_base_type
);
17532 /* The die_type call above may have already set the type for this DIE. */
17533 range_type
= get_die_type (die
, cu
);
17537 low
.kind
= PROP_CONST
;
17538 high
.kind
= PROP_CONST
;
17539 high
.data
.const_val
= 0;
17541 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17542 omitting DW_AT_lower_bound. */
17543 switch (cu
->language
)
17546 case language_cplus
:
17547 low
.data
.const_val
= 0;
17548 low_default_is_valid
= 1;
17550 case language_fortran
:
17551 low
.data
.const_val
= 1;
17552 low_default_is_valid
= 1;
17555 case language_objc
:
17556 case language_rust
:
17557 low
.data
.const_val
= 0;
17558 low_default_is_valid
= (cu
->header
.version
>= 4);
17562 case language_pascal
:
17563 low
.data
.const_val
= 1;
17564 low_default_is_valid
= (cu
->header
.version
>= 4);
17567 low
.data
.const_val
= 0;
17568 low_default_is_valid
= 0;
17572 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17574 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
17575 else if (!low_default_is_valid
)
17576 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
17577 "- DIE at 0x%x [in module %s]"),
17578 to_underlying (die
->sect_off
), objfile_name (cu
->objfile
));
17580 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17581 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
17583 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
17584 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
17586 /* If bounds are constant do the final calculation here. */
17587 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17588 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17590 high_bound_is_count
= 1;
17594 /* Dwarf-2 specifications explicitly allows to create subrange types
17595 without specifying a base type.
17596 In that case, the base type must be set to the type of
17597 the lower bound, upper bound or count, in that order, if any of these
17598 three attributes references an object that has a type.
17599 If no base type is found, the Dwarf-2 specifications say that
17600 a signed integer type of size equal to the size of an address should
17602 For the following C code: `extern char gdb_int [];'
17603 GCC produces an empty range DIE.
17604 FIXME: muller/2010-05-28: Possible references to object for low bound,
17605 high bound or count are not yet handled by this code. */
17606 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
17608 struct objfile
*objfile
= cu
->objfile
;
17609 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17610 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
17611 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
17613 /* Test "int", "long int", and "long long int" objfile types,
17614 and select the first one having a size above or equal to the
17615 architecture address size. */
17616 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17617 base_type
= int_type
;
17620 int_type
= objfile_type (objfile
)->builtin_long
;
17621 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17622 base_type
= int_type
;
17625 int_type
= objfile_type (objfile
)->builtin_long_long
;
17626 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17627 base_type
= int_type
;
17632 /* Normally, the DWARF producers are expected to use a signed
17633 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17634 But this is unfortunately not always the case, as witnessed
17635 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17636 is used instead. To work around that ambiguity, we treat
17637 the bounds as signed, and thus sign-extend their values, when
17638 the base type is signed. */
17640 -((LONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17641 if (low
.kind
== PROP_CONST
17642 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17643 low
.data
.const_val
|= negative_mask
;
17644 if (high
.kind
== PROP_CONST
17645 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17646 high
.data
.const_val
|= negative_mask
;
17648 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
17650 if (high_bound_is_count
)
17651 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17653 /* Ada expects an empty array on no boundary attributes. */
17654 if (attr
== NULL
&& cu
->language
!= language_ada
)
17655 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17657 name
= dwarf2_name (die
, cu
);
17659 TYPE_NAME (range_type
) = name
;
17661 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17663 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17665 set_die_type (die
, range_type
, cu
);
17667 /* set_die_type should be already done. */
17668 set_descriptive_type (range_type
, die
, cu
);
17673 static struct type
*
17674 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17678 /* For now, we only support the C meaning of an unspecified type: void. */
17680 type
= init_type (cu
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
17681 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17683 return set_die_type (die
, type
, cu
);
17686 /* Read a single die and all its descendents. Set the die's sibling
17687 field to NULL; set other fields in the die correctly, and set all
17688 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17689 location of the info_ptr after reading all of those dies. PARENT
17690 is the parent of the die in question. */
17692 static struct die_info
*
17693 read_die_and_children (const struct die_reader_specs
*reader
,
17694 const gdb_byte
*info_ptr
,
17695 const gdb_byte
**new_info_ptr
,
17696 struct die_info
*parent
)
17698 struct die_info
*die
;
17699 const gdb_byte
*cur_ptr
;
17702 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
17705 *new_info_ptr
= cur_ptr
;
17708 store_in_ref_table (die
, reader
->cu
);
17711 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17715 *new_info_ptr
= cur_ptr
;
17718 die
->sibling
= NULL
;
17719 die
->parent
= parent
;
17723 /* Read a die, all of its descendents, and all of its siblings; set
17724 all of the fields of all of the dies correctly. Arguments are as
17725 in read_die_and_children. */
17727 static struct die_info
*
17728 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17729 const gdb_byte
*info_ptr
,
17730 const gdb_byte
**new_info_ptr
,
17731 struct die_info
*parent
)
17733 struct die_info
*first_die
, *last_sibling
;
17734 const gdb_byte
*cur_ptr
;
17736 cur_ptr
= info_ptr
;
17737 first_die
= last_sibling
= NULL
;
17741 struct die_info
*die
17742 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17746 *new_info_ptr
= cur_ptr
;
17753 last_sibling
->sibling
= die
;
17755 last_sibling
= die
;
17759 /* Read a die, all of its descendents, and all of its siblings; set
17760 all of the fields of all of the dies correctly. Arguments are as
17761 in read_die_and_children.
17762 This the main entry point for reading a DIE and all its children. */
17764 static struct die_info
*
17765 read_die_and_siblings (const struct die_reader_specs
*reader
,
17766 const gdb_byte
*info_ptr
,
17767 const gdb_byte
**new_info_ptr
,
17768 struct die_info
*parent
)
17770 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17771 new_info_ptr
, parent
);
17773 if (dwarf_die_debug
)
17775 fprintf_unfiltered (gdb_stdlog
,
17776 "Read die from %s@0x%x of %s:\n",
17777 get_section_name (reader
->die_section
),
17778 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17779 bfd_get_filename (reader
->abfd
));
17780 dump_die (die
, dwarf_die_debug
);
17786 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17788 The caller is responsible for filling in the extra attributes
17789 and updating (*DIEP)->num_attrs.
17790 Set DIEP to point to a newly allocated die with its information,
17791 except for its child, sibling, and parent fields.
17792 Set HAS_CHILDREN to tell whether the die has children or not. */
17794 static const gdb_byte
*
17795 read_full_die_1 (const struct die_reader_specs
*reader
,
17796 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17797 int *has_children
, int num_extra_attrs
)
17799 unsigned int abbrev_number
, bytes_read
, i
;
17800 struct abbrev_info
*abbrev
;
17801 struct die_info
*die
;
17802 struct dwarf2_cu
*cu
= reader
->cu
;
17803 bfd
*abfd
= reader
->abfd
;
17805 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17806 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17807 info_ptr
+= bytes_read
;
17808 if (!abbrev_number
)
17815 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
17817 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17819 bfd_get_filename (abfd
));
17821 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17822 die
->sect_off
= sect_off
;
17823 die
->tag
= abbrev
->tag
;
17824 die
->abbrev
= abbrev_number
;
17826 /* Make the result usable.
17827 The caller needs to update num_attrs after adding the extra
17829 die
->num_attrs
= abbrev
->num_attrs
;
17831 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17832 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17836 *has_children
= abbrev
->has_children
;
17840 /* Read a die and all its attributes.
17841 Set DIEP to point to a newly allocated die with its information,
17842 except for its child, sibling, and parent fields.
17843 Set HAS_CHILDREN to tell whether the die has children or not. */
17845 static const gdb_byte
*
17846 read_full_die (const struct die_reader_specs
*reader
,
17847 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17850 const gdb_byte
*result
;
17852 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
17854 if (dwarf_die_debug
)
17856 fprintf_unfiltered (gdb_stdlog
,
17857 "Read die from %s@0x%x of %s:\n",
17858 get_section_name (reader
->die_section
),
17859 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17860 bfd_get_filename (reader
->abfd
));
17861 dump_die (*diep
, dwarf_die_debug
);
17867 /* Abbreviation tables.
17869 In DWARF version 2, the description of the debugging information is
17870 stored in a separate .debug_abbrev section. Before we read any
17871 dies from a section we read in all abbreviations and install them
17872 in a hash table. */
17874 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
17876 static struct abbrev_info
*
17877 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
17879 struct abbrev_info
*abbrev
;
17881 abbrev
= XOBNEW (&abbrev_table
->abbrev_obstack
, struct abbrev_info
);
17882 memset (abbrev
, 0, sizeof (struct abbrev_info
));
17887 /* Add an abbreviation to the table. */
17890 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
17891 unsigned int abbrev_number
,
17892 struct abbrev_info
*abbrev
)
17894 unsigned int hash_number
;
17896 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
17897 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
17898 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
17901 /* Look up an abbrev in the table.
17902 Returns NULL if the abbrev is not found. */
17904 static struct abbrev_info
*
17905 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
17906 unsigned int abbrev_number
)
17908 unsigned int hash_number
;
17909 struct abbrev_info
*abbrev
;
17911 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
17912 abbrev
= abbrev_table
->abbrevs
[hash_number
];
17916 if (abbrev
->number
== abbrev_number
)
17918 abbrev
= abbrev
->next
;
17923 /* Read in an abbrev table. */
17925 static struct abbrev_table
*
17926 abbrev_table_read_table (struct dwarf2_section_info
*section
,
17927 sect_offset sect_off
)
17929 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17930 bfd
*abfd
= get_section_bfd_owner (section
);
17931 struct abbrev_table
*abbrev_table
;
17932 const gdb_byte
*abbrev_ptr
;
17933 struct abbrev_info
*cur_abbrev
;
17934 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
17935 unsigned int abbrev_form
;
17936 struct attr_abbrev
*cur_attrs
;
17937 unsigned int allocated_attrs
;
17939 abbrev_table
= XNEW (struct abbrev_table
);
17940 abbrev_table
->sect_off
= sect_off
;
17941 obstack_init (&abbrev_table
->abbrev_obstack
);
17942 abbrev_table
->abbrevs
=
17943 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct abbrev_info
*,
17945 memset (abbrev_table
->abbrevs
, 0,
17946 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
17948 dwarf2_read_section (objfile
, section
);
17949 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
17950 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
17951 abbrev_ptr
+= bytes_read
;
17953 allocated_attrs
= ATTR_ALLOC_CHUNK
;
17954 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
17956 /* Loop until we reach an abbrev number of 0. */
17957 while (abbrev_number
)
17959 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
17961 /* read in abbrev header */
17962 cur_abbrev
->number
= abbrev_number
;
17964 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
17965 abbrev_ptr
+= bytes_read
;
17966 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
17969 /* now read in declarations */
17972 LONGEST implicit_const
;
17974 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
17975 abbrev_ptr
+= bytes_read
;
17976 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
17977 abbrev_ptr
+= bytes_read
;
17978 if (abbrev_form
== DW_FORM_implicit_const
)
17980 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
17982 abbrev_ptr
+= bytes_read
;
17986 /* Initialize it due to a false compiler warning. */
17987 implicit_const
= -1;
17990 if (abbrev_name
== 0)
17993 if (cur_abbrev
->num_attrs
== allocated_attrs
)
17995 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
17997 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
18000 cur_attrs
[cur_abbrev
->num_attrs
].name
18001 = (enum dwarf_attribute
) abbrev_name
;
18002 cur_attrs
[cur_abbrev
->num_attrs
].form
18003 = (enum dwarf_form
) abbrev_form
;
18004 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
18005 ++cur_abbrev
->num_attrs
;
18008 cur_abbrev
->attrs
=
18009 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18010 cur_abbrev
->num_attrs
);
18011 memcpy (cur_abbrev
->attrs
, cur_attrs
,
18012 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18014 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
18016 /* Get next abbreviation.
18017 Under Irix6 the abbreviations for a compilation unit are not
18018 always properly terminated with an abbrev number of 0.
18019 Exit loop if we encounter an abbreviation which we have
18020 already read (which means we are about to read the abbreviations
18021 for the next compile unit) or if the end of the abbreviation
18022 table is reached. */
18023 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18025 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18026 abbrev_ptr
+= bytes_read
;
18027 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
18032 return abbrev_table
;
18035 /* Free the resources held by ABBREV_TABLE. */
18038 abbrev_table_free (struct abbrev_table
*abbrev_table
)
18040 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
18041 xfree (abbrev_table
);
18044 /* Same as abbrev_table_free but as a cleanup.
18045 We pass in a pointer to the pointer to the table so that we can
18046 set the pointer to NULL when we're done. It also simplifies
18047 build_type_psymtabs_1. */
18050 abbrev_table_free_cleanup (void *table_ptr
)
18052 struct abbrev_table
**abbrev_table_ptr
= (struct abbrev_table
**) table_ptr
;
18054 if (*abbrev_table_ptr
!= NULL
)
18055 abbrev_table_free (*abbrev_table_ptr
);
18056 *abbrev_table_ptr
= NULL
;
18059 /* Read the abbrev table for CU from ABBREV_SECTION. */
18062 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
18063 struct dwarf2_section_info
*abbrev_section
)
18066 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_sect_off
);
18069 /* Release the memory used by the abbrev table for a compilation unit. */
18072 dwarf2_free_abbrev_table (void *ptr_to_cu
)
18074 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr_to_cu
;
18076 if (cu
->abbrev_table
!= NULL
)
18077 abbrev_table_free (cu
->abbrev_table
);
18078 /* Set this to NULL so that we SEGV if we try to read it later,
18079 and also because free_comp_unit verifies this is NULL. */
18080 cu
->abbrev_table
= NULL
;
18083 /* Returns nonzero if TAG represents a type that we might generate a partial
18087 is_type_tag_for_partial (int tag
)
18092 /* Some types that would be reasonable to generate partial symbols for,
18093 that we don't at present. */
18094 case DW_TAG_array_type
:
18095 case DW_TAG_file_type
:
18096 case DW_TAG_ptr_to_member_type
:
18097 case DW_TAG_set_type
:
18098 case DW_TAG_string_type
:
18099 case DW_TAG_subroutine_type
:
18101 case DW_TAG_base_type
:
18102 case DW_TAG_class_type
:
18103 case DW_TAG_interface_type
:
18104 case DW_TAG_enumeration_type
:
18105 case DW_TAG_structure_type
:
18106 case DW_TAG_subrange_type
:
18107 case DW_TAG_typedef
:
18108 case DW_TAG_union_type
:
18115 /* Load all DIEs that are interesting for partial symbols into memory. */
18117 static struct partial_die_info
*
18118 load_partial_dies (const struct die_reader_specs
*reader
,
18119 const gdb_byte
*info_ptr
, int building_psymtab
)
18121 struct dwarf2_cu
*cu
= reader
->cu
;
18122 struct objfile
*objfile
= cu
->objfile
;
18123 struct partial_die_info
*part_die
;
18124 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18125 struct abbrev_info
*abbrev
;
18126 unsigned int bytes_read
;
18127 unsigned int load_all
= 0;
18128 int nesting_level
= 1;
18133 gdb_assert (cu
->per_cu
!= NULL
);
18134 if (cu
->per_cu
->load_all_dies
)
18138 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18142 &cu
->comp_unit_obstack
,
18143 hashtab_obstack_allocate
,
18144 dummy_obstack_deallocate
);
18146 part_die
= XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
18150 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
18152 /* A NULL abbrev means the end of a series of children. */
18153 if (abbrev
== NULL
)
18155 if (--nesting_level
== 0)
18157 /* PART_DIE was probably the last thing allocated on the
18158 comp_unit_obstack, so we could call obstack_free
18159 here. We don't do that because the waste is small,
18160 and will be cleaned up when we're done with this
18161 compilation unit. This way, we're also more robust
18162 against other users of the comp_unit_obstack. */
18165 info_ptr
+= bytes_read
;
18166 last_die
= parent_die
;
18167 parent_die
= parent_die
->die_parent
;
18171 /* Check for template arguments. We never save these; if
18172 they're seen, we just mark the parent, and go on our way. */
18173 if (parent_die
!= NULL
18174 && cu
->language
== language_cplus
18175 && (abbrev
->tag
== DW_TAG_template_type_param
18176 || abbrev
->tag
== DW_TAG_template_value_param
))
18178 parent_die
->has_template_arguments
= 1;
18182 /* We don't need a partial DIE for the template argument. */
18183 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18188 /* We only recurse into c++ subprograms looking for template arguments.
18189 Skip their other children. */
18191 && cu
->language
== language_cplus
18192 && parent_die
!= NULL
18193 && parent_die
->tag
== DW_TAG_subprogram
)
18195 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18199 /* Check whether this DIE is interesting enough to save. Normally
18200 we would not be interested in members here, but there may be
18201 later variables referencing them via DW_AT_specification (for
18202 static members). */
18204 && !is_type_tag_for_partial (abbrev
->tag
)
18205 && abbrev
->tag
!= DW_TAG_constant
18206 && abbrev
->tag
!= DW_TAG_enumerator
18207 && abbrev
->tag
!= DW_TAG_subprogram
18208 && abbrev
->tag
!= DW_TAG_lexical_block
18209 && abbrev
->tag
!= DW_TAG_variable
18210 && abbrev
->tag
!= DW_TAG_namespace
18211 && abbrev
->tag
!= DW_TAG_module
18212 && abbrev
->tag
!= DW_TAG_member
18213 && abbrev
->tag
!= DW_TAG_imported_unit
18214 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18216 /* Otherwise we skip to the next sibling, if any. */
18217 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18221 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
18224 /* This two-pass algorithm for processing partial symbols has a
18225 high cost in cache pressure. Thus, handle some simple cases
18226 here which cover the majority of C partial symbols. DIEs
18227 which neither have specification tags in them, nor could have
18228 specification tags elsewhere pointing at them, can simply be
18229 processed and discarded.
18231 This segment is also optional; scan_partial_symbols and
18232 add_partial_symbol will handle these DIEs if we chain
18233 them in normally. When compilers which do not emit large
18234 quantities of duplicate debug information are more common,
18235 this code can probably be removed. */
18237 /* Any complete simple types at the top level (pretty much all
18238 of them, for a language without namespaces), can be processed
18240 if (parent_die
== NULL
18241 && part_die
->has_specification
== 0
18242 && part_die
->is_declaration
== 0
18243 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
18244 || part_die
->tag
== DW_TAG_base_type
18245 || part_die
->tag
== DW_TAG_subrange_type
))
18247 if (building_psymtab
&& part_die
->name
!= NULL
)
18248 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
18249 VAR_DOMAIN
, LOC_TYPEDEF
,
18250 &objfile
->static_psymbols
,
18251 0, cu
->language
, objfile
);
18252 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
18256 /* The exception for DW_TAG_typedef with has_children above is
18257 a workaround of GCC PR debug/47510. In the case of this complaint
18258 type_name_no_tag_or_error will error on such types later.
18260 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18261 it could not find the child DIEs referenced later, this is checked
18262 above. In correct DWARF DW_TAG_typedef should have no children. */
18264 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
18265 complaint (&symfile_complaints
,
18266 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18267 "- DIE at 0x%x [in module %s]"),
18268 to_underlying (part_die
->sect_off
), objfile_name (objfile
));
18270 /* If we're at the second level, and we're an enumerator, and
18271 our parent has no specification (meaning possibly lives in a
18272 namespace elsewhere), then we can add the partial symbol now
18273 instead of queueing it. */
18274 if (part_die
->tag
== DW_TAG_enumerator
18275 && parent_die
!= NULL
18276 && parent_die
->die_parent
== NULL
18277 && parent_die
->tag
== DW_TAG_enumeration_type
18278 && parent_die
->has_specification
== 0)
18280 if (part_die
->name
== NULL
)
18281 complaint (&symfile_complaints
,
18282 _("malformed enumerator DIE ignored"));
18283 else if (building_psymtab
)
18284 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
18285 VAR_DOMAIN
, LOC_CONST
,
18286 cu
->language
== language_cplus
18287 ? &objfile
->global_psymbols
18288 : &objfile
->static_psymbols
,
18289 0, cu
->language
, objfile
);
18291 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
18295 /* We'll save this DIE so link it in. */
18296 part_die
->die_parent
= parent_die
;
18297 part_die
->die_sibling
= NULL
;
18298 part_die
->die_child
= NULL
;
18300 if (last_die
&& last_die
== parent_die
)
18301 last_die
->die_child
= part_die
;
18303 last_die
->die_sibling
= part_die
;
18305 last_die
= part_die
;
18307 if (first_die
== NULL
)
18308 first_die
= part_die
;
18310 /* Maybe add the DIE to the hash table. Not all DIEs that we
18311 find interesting need to be in the hash table, because we
18312 also have the parent/sibling/child chains; only those that we
18313 might refer to by offset later during partial symbol reading.
18315 For now this means things that might have be the target of a
18316 DW_AT_specification, DW_AT_abstract_origin, or
18317 DW_AT_extension. DW_AT_extension will refer only to
18318 namespaces; DW_AT_abstract_origin refers to functions (and
18319 many things under the function DIE, but we do not recurse
18320 into function DIEs during partial symbol reading) and
18321 possibly variables as well; DW_AT_specification refers to
18322 declarations. Declarations ought to have the DW_AT_declaration
18323 flag. It happens that GCC forgets to put it in sometimes, but
18324 only for functions, not for types.
18326 Adding more things than necessary to the hash table is harmless
18327 except for the performance cost. Adding too few will result in
18328 wasted time in find_partial_die, when we reread the compilation
18329 unit with load_all_dies set. */
18332 || abbrev
->tag
== DW_TAG_constant
18333 || abbrev
->tag
== DW_TAG_subprogram
18334 || abbrev
->tag
== DW_TAG_variable
18335 || abbrev
->tag
== DW_TAG_namespace
18336 || part_die
->is_declaration
)
18340 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18341 to_underlying (part_die
->sect_off
),
18346 part_die
= XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
18348 /* For some DIEs we want to follow their children (if any). For C
18349 we have no reason to follow the children of structures; for other
18350 languages we have to, so that we can get at method physnames
18351 to infer fully qualified class names, for DW_AT_specification,
18352 and for C++ template arguments. For C++, we also look one level
18353 inside functions to find template arguments (if the name of the
18354 function does not already contain the template arguments).
18356 For Ada, we need to scan the children of subprograms and lexical
18357 blocks as well because Ada allows the definition of nested
18358 entities that could be interesting for the debugger, such as
18359 nested subprograms for instance. */
18360 if (last_die
->has_children
18362 || last_die
->tag
== DW_TAG_namespace
18363 || last_die
->tag
== DW_TAG_module
18364 || last_die
->tag
== DW_TAG_enumeration_type
18365 || (cu
->language
== language_cplus
18366 && last_die
->tag
== DW_TAG_subprogram
18367 && (last_die
->name
== NULL
18368 || strchr (last_die
->name
, '<') == NULL
))
18369 || (cu
->language
!= language_c
18370 && (last_die
->tag
== DW_TAG_class_type
18371 || last_die
->tag
== DW_TAG_interface_type
18372 || last_die
->tag
== DW_TAG_structure_type
18373 || last_die
->tag
== DW_TAG_union_type
))
18374 || (cu
->language
== language_ada
18375 && (last_die
->tag
== DW_TAG_subprogram
18376 || last_die
->tag
== DW_TAG_lexical_block
))))
18379 parent_die
= last_die
;
18383 /* Otherwise we skip to the next sibling, if any. */
18384 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18386 /* Back to the top, do it again. */
18390 /* Read a minimal amount of information into the minimal die structure. */
18392 static const gdb_byte
*
18393 read_partial_die (const struct die_reader_specs
*reader
,
18394 struct partial_die_info
*part_die
,
18395 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
18396 const gdb_byte
*info_ptr
)
18398 struct dwarf2_cu
*cu
= reader
->cu
;
18399 struct objfile
*objfile
= cu
->objfile
;
18400 const gdb_byte
*buffer
= reader
->buffer
;
18402 struct attribute attr
;
18403 int has_low_pc_attr
= 0;
18404 int has_high_pc_attr
= 0;
18405 int high_pc_relative
= 0;
18407 memset (part_die
, 0, sizeof (struct partial_die_info
));
18409 part_die
->sect_off
= (sect_offset
) (info_ptr
- buffer
);
18411 info_ptr
+= abbrev_len
;
18413 if (abbrev
== NULL
)
18416 part_die
->tag
= abbrev
->tag
;
18417 part_die
->has_children
= abbrev
->has_children
;
18419 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18421 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
18423 /* Store the data if it is of an attribute we want to keep in a
18424 partial symbol table. */
18428 switch (part_die
->tag
)
18430 case DW_TAG_compile_unit
:
18431 case DW_TAG_partial_unit
:
18432 case DW_TAG_type_unit
:
18433 /* Compilation units have a DW_AT_name that is a filename, not
18434 a source language identifier. */
18435 case DW_TAG_enumeration_type
:
18436 case DW_TAG_enumerator
:
18437 /* These tags always have simple identifiers already; no need
18438 to canonicalize them. */
18439 part_die
->name
= DW_STRING (&attr
);
18443 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18444 &objfile
->per_bfd
->storage_obstack
);
18448 case DW_AT_linkage_name
:
18449 case DW_AT_MIPS_linkage_name
:
18450 /* Note that both forms of linkage name might appear. We
18451 assume they will be the same, and we only store the last
18453 if (cu
->language
== language_ada
)
18454 part_die
->name
= DW_STRING (&attr
);
18455 part_die
->linkage_name
= DW_STRING (&attr
);
18458 has_low_pc_attr
= 1;
18459 part_die
->lowpc
= attr_value_as_address (&attr
);
18461 case DW_AT_high_pc
:
18462 has_high_pc_attr
= 1;
18463 part_die
->highpc
= attr_value_as_address (&attr
);
18464 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18465 high_pc_relative
= 1;
18467 case DW_AT_location
:
18468 /* Support the .debug_loc offsets. */
18469 if (attr_form_is_block (&attr
))
18471 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
18473 else if (attr_form_is_section_offset (&attr
))
18475 dwarf2_complex_location_expr_complaint ();
18479 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18480 "partial symbol information");
18483 case DW_AT_external
:
18484 part_die
->is_external
= DW_UNSND (&attr
);
18486 case DW_AT_declaration
:
18487 part_die
->is_declaration
= DW_UNSND (&attr
);
18490 part_die
->has_type
= 1;
18492 case DW_AT_abstract_origin
:
18493 case DW_AT_specification
:
18494 case DW_AT_extension
:
18495 part_die
->has_specification
= 1;
18496 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18497 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18498 || cu
->per_cu
->is_dwz
);
18500 case DW_AT_sibling
:
18501 /* Ignore absolute siblings, they might point outside of
18502 the current compile unit. */
18503 if (attr
.form
== DW_FORM_ref_addr
)
18504 complaint (&symfile_complaints
,
18505 _("ignoring absolute DW_AT_sibling"));
18508 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18509 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18511 if (sibling_ptr
< info_ptr
)
18512 complaint (&symfile_complaints
,
18513 _("DW_AT_sibling points backwards"));
18514 else if (sibling_ptr
> reader
->buffer_end
)
18515 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18517 part_die
->sibling
= sibling_ptr
;
18520 case DW_AT_byte_size
:
18521 part_die
->has_byte_size
= 1;
18523 case DW_AT_const_value
:
18524 part_die
->has_const_value
= 1;
18526 case DW_AT_calling_convention
:
18527 /* DWARF doesn't provide a way to identify a program's source-level
18528 entry point. DW_AT_calling_convention attributes are only meant
18529 to describe functions' calling conventions.
18531 However, because it's a necessary piece of information in
18532 Fortran, and before DWARF 4 DW_CC_program was the only
18533 piece of debugging information whose definition refers to
18534 a 'main program' at all, several compilers marked Fortran
18535 main programs with DW_CC_program --- even when those
18536 functions use the standard calling conventions.
18538 Although DWARF now specifies a way to provide this
18539 information, we support this practice for backward
18541 if (DW_UNSND (&attr
) == DW_CC_program
18542 && cu
->language
== language_fortran
)
18543 part_die
->main_subprogram
= 1;
18546 if (DW_UNSND (&attr
) == DW_INL_inlined
18547 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18548 part_die
->may_be_inlined
= 1;
18552 if (part_die
->tag
== DW_TAG_imported_unit
)
18554 part_die
->d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18555 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18556 || cu
->per_cu
->is_dwz
);
18560 case DW_AT_main_subprogram
:
18561 part_die
->main_subprogram
= DW_UNSND (&attr
);
18569 if (high_pc_relative
)
18570 part_die
->highpc
+= part_die
->lowpc
;
18572 if (has_low_pc_attr
&& has_high_pc_attr
)
18574 /* When using the GNU linker, .gnu.linkonce. sections are used to
18575 eliminate duplicate copies of functions and vtables and such.
18576 The linker will arbitrarily choose one and discard the others.
18577 The AT_*_pc values for such functions refer to local labels in
18578 these sections. If the section from that file was discarded, the
18579 labels are not in the output, so the relocs get a value of 0.
18580 If this is a discarded function, mark the pc bounds as invalid,
18581 so that GDB will ignore it. */
18582 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18584 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18586 complaint (&symfile_complaints
,
18587 _("DW_AT_low_pc %s is zero "
18588 "for DIE at 0x%x [in module %s]"),
18589 paddress (gdbarch
, part_die
->lowpc
),
18590 to_underlying (part_die
->sect_off
), objfile_name (objfile
));
18592 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18593 else if (part_die
->lowpc
>= part_die
->highpc
)
18595 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18597 complaint (&symfile_complaints
,
18598 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18599 "for DIE at 0x%x [in module %s]"),
18600 paddress (gdbarch
, part_die
->lowpc
),
18601 paddress (gdbarch
, part_die
->highpc
),
18602 to_underlying (part_die
->sect_off
),
18603 objfile_name (objfile
));
18606 part_die
->has_pc_info
= 1;
18612 /* Find a cached partial DIE at OFFSET in CU. */
18614 static struct partial_die_info
*
18615 find_partial_die_in_comp_unit (sect_offset sect_off
, struct dwarf2_cu
*cu
)
18617 struct partial_die_info
*lookup_die
= NULL
;
18618 struct partial_die_info part_die
;
18620 part_die
.sect_off
= sect_off
;
18621 lookup_die
= ((struct partial_die_info
*)
18622 htab_find_with_hash (cu
->partial_dies
, &part_die
,
18623 to_underlying (sect_off
)));
18628 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18629 except in the case of .debug_types DIEs which do not reference
18630 outside their CU (they do however referencing other types via
18631 DW_FORM_ref_sig8). */
18633 static struct partial_die_info
*
18634 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18636 struct objfile
*objfile
= cu
->objfile
;
18637 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18638 struct partial_die_info
*pd
= NULL
;
18640 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18641 && offset_in_cu_p (&cu
->header
, sect_off
))
18643 pd
= find_partial_die_in_comp_unit (sect_off
, cu
);
18646 /* We missed recording what we needed.
18647 Load all dies and try again. */
18648 per_cu
= cu
->per_cu
;
18652 /* TUs don't reference other CUs/TUs (except via type signatures). */
18653 if (cu
->per_cu
->is_debug_types
)
18655 error (_("Dwarf Error: Type Unit at offset 0x%x contains"
18656 " external reference to offset 0x%x [in module %s].\n"),
18657 to_underlying (cu
->header
.sect_off
), to_underlying (sect_off
),
18658 bfd_get_filename (objfile
->obfd
));
18660 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18663 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18664 load_partial_comp_unit (per_cu
);
18666 per_cu
->cu
->last_used
= 0;
18667 pd
= find_partial_die_in_comp_unit (sect_off
, per_cu
->cu
);
18670 /* If we didn't find it, and not all dies have been loaded,
18671 load them all and try again. */
18673 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18675 per_cu
->load_all_dies
= 1;
18677 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18678 THIS_CU->cu may already be in use. So we can't just free it and
18679 replace its DIEs with the ones we read in. Instead, we leave those
18680 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18681 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18683 load_partial_comp_unit (per_cu
);
18685 pd
= find_partial_die_in_comp_unit (sect_off
, per_cu
->cu
);
18689 internal_error (__FILE__
, __LINE__
,
18690 _("could not find partial DIE 0x%x "
18691 "in cache [from module %s]\n"),
18692 to_underlying (sect_off
), bfd_get_filename (objfile
->obfd
));
18696 /* See if we can figure out if the class lives in a namespace. We do
18697 this by looking for a member function; its demangled name will
18698 contain namespace info, if there is any. */
18701 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18702 struct dwarf2_cu
*cu
)
18704 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18705 what template types look like, because the demangler
18706 frequently doesn't give the same name as the debug info. We
18707 could fix this by only using the demangled name to get the
18708 prefix (but see comment in read_structure_type). */
18710 struct partial_die_info
*real_pdi
;
18711 struct partial_die_info
*child_pdi
;
18713 /* If this DIE (this DIE's specification, if any) has a parent, then
18714 we should not do this. We'll prepend the parent's fully qualified
18715 name when we create the partial symbol. */
18717 real_pdi
= struct_pdi
;
18718 while (real_pdi
->has_specification
)
18719 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
18720 real_pdi
->spec_is_dwz
, cu
);
18722 if (real_pdi
->die_parent
!= NULL
)
18725 for (child_pdi
= struct_pdi
->die_child
;
18727 child_pdi
= child_pdi
->die_sibling
)
18729 if (child_pdi
->tag
== DW_TAG_subprogram
18730 && child_pdi
->linkage_name
!= NULL
)
18732 char *actual_class_name
18733 = language_class_name_from_physname (cu
->language_defn
,
18734 child_pdi
->linkage_name
);
18735 if (actual_class_name
!= NULL
)
18739 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
18741 strlen (actual_class_name
)));
18742 xfree (actual_class_name
);
18749 /* Adjust PART_DIE before generating a symbol for it. This function
18750 may set the is_external flag or change the DIE's name. */
18753 fixup_partial_die (struct partial_die_info
*part_die
,
18754 struct dwarf2_cu
*cu
)
18756 /* Once we've fixed up a die, there's no point in doing so again.
18757 This also avoids a memory leak if we were to call
18758 guess_partial_die_structure_name multiple times. */
18759 if (part_die
->fixup_called
)
18762 /* If we found a reference attribute and the DIE has no name, try
18763 to find a name in the referred to DIE. */
18765 if (part_die
->name
== NULL
&& part_die
->has_specification
)
18767 struct partial_die_info
*spec_die
;
18769 spec_die
= find_partial_die (part_die
->spec_offset
,
18770 part_die
->spec_is_dwz
, cu
);
18772 fixup_partial_die (spec_die
, cu
);
18774 if (spec_die
->name
)
18776 part_die
->name
= spec_die
->name
;
18778 /* Copy DW_AT_external attribute if it is set. */
18779 if (spec_die
->is_external
)
18780 part_die
->is_external
= spec_die
->is_external
;
18784 /* Set default names for some unnamed DIEs. */
18786 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
18787 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
18789 /* If there is no parent die to provide a namespace, and there are
18790 children, see if we can determine the namespace from their linkage
18792 if (cu
->language
== language_cplus
18793 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
18794 && part_die
->die_parent
== NULL
18795 && part_die
->has_children
18796 && (part_die
->tag
== DW_TAG_class_type
18797 || part_die
->tag
== DW_TAG_structure_type
18798 || part_die
->tag
== DW_TAG_union_type
))
18799 guess_partial_die_structure_name (part_die
, cu
);
18801 /* GCC might emit a nameless struct or union that has a linkage
18802 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18803 if (part_die
->name
== NULL
18804 && (part_die
->tag
== DW_TAG_class_type
18805 || part_die
->tag
== DW_TAG_interface_type
18806 || part_die
->tag
== DW_TAG_structure_type
18807 || part_die
->tag
== DW_TAG_union_type
)
18808 && part_die
->linkage_name
!= NULL
)
18812 demangled
= gdb_demangle (part_die
->linkage_name
, DMGL_TYPES
);
18817 /* Strip any leading namespaces/classes, keep only the base name.
18818 DW_AT_name for named DIEs does not contain the prefixes. */
18819 base
= strrchr (demangled
, ':');
18820 if (base
&& base
> demangled
&& base
[-1] == ':')
18827 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
18828 base
, strlen (base
)));
18833 part_die
->fixup_called
= 1;
18836 /* Read an attribute value described by an attribute form. */
18838 static const gdb_byte
*
18839 read_attribute_value (const struct die_reader_specs
*reader
,
18840 struct attribute
*attr
, unsigned form
,
18841 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
18843 struct dwarf2_cu
*cu
= reader
->cu
;
18844 struct objfile
*objfile
= cu
->objfile
;
18845 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18846 bfd
*abfd
= reader
->abfd
;
18847 struct comp_unit_head
*cu_header
= &cu
->header
;
18848 unsigned int bytes_read
;
18849 struct dwarf_block
*blk
;
18851 attr
->form
= (enum dwarf_form
) form
;
18854 case DW_FORM_ref_addr
:
18855 if (cu
->header
.version
== 2)
18856 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18858 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
18859 &cu
->header
, &bytes_read
);
18860 info_ptr
+= bytes_read
;
18862 case DW_FORM_GNU_ref_alt
:
18863 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
18864 info_ptr
+= bytes_read
;
18867 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18868 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18869 info_ptr
+= bytes_read
;
18871 case DW_FORM_block2
:
18872 blk
= dwarf_alloc_block (cu
);
18873 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18875 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18876 info_ptr
+= blk
->size
;
18877 DW_BLOCK (attr
) = blk
;
18879 case DW_FORM_block4
:
18880 blk
= dwarf_alloc_block (cu
);
18881 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18883 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18884 info_ptr
+= blk
->size
;
18885 DW_BLOCK (attr
) = blk
;
18887 case DW_FORM_data2
:
18888 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18891 case DW_FORM_data4
:
18892 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18895 case DW_FORM_data8
:
18896 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18899 case DW_FORM_data16
:
18900 blk
= dwarf_alloc_block (cu
);
18902 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18904 DW_BLOCK (attr
) = blk
;
18906 case DW_FORM_sec_offset
:
18907 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
18908 info_ptr
+= bytes_read
;
18910 case DW_FORM_string
:
18911 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18912 DW_STRING_IS_CANONICAL (attr
) = 0;
18913 info_ptr
+= bytes_read
;
18916 if (!cu
->per_cu
->is_dwz
)
18918 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
18920 DW_STRING_IS_CANONICAL (attr
) = 0;
18921 info_ptr
+= bytes_read
;
18925 case DW_FORM_line_strp
:
18926 if (!cu
->per_cu
->is_dwz
)
18928 DW_STRING (attr
) = read_indirect_line_string (abfd
, info_ptr
,
18929 cu_header
, &bytes_read
);
18930 DW_STRING_IS_CANONICAL (attr
) = 0;
18931 info_ptr
+= bytes_read
;
18935 case DW_FORM_GNU_strp_alt
:
18937 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
18938 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
18941 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
18942 DW_STRING_IS_CANONICAL (attr
) = 0;
18943 info_ptr
+= bytes_read
;
18946 case DW_FORM_exprloc
:
18947 case DW_FORM_block
:
18948 blk
= dwarf_alloc_block (cu
);
18949 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18950 info_ptr
+= bytes_read
;
18951 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18952 info_ptr
+= blk
->size
;
18953 DW_BLOCK (attr
) = blk
;
18955 case DW_FORM_block1
:
18956 blk
= dwarf_alloc_block (cu
);
18957 blk
->size
= read_1_byte (abfd
, info_ptr
);
18959 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18960 info_ptr
+= blk
->size
;
18961 DW_BLOCK (attr
) = blk
;
18963 case DW_FORM_data1
:
18964 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18968 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18971 case DW_FORM_flag_present
:
18972 DW_UNSND (attr
) = 1;
18974 case DW_FORM_sdata
:
18975 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18976 info_ptr
+= bytes_read
;
18978 case DW_FORM_udata
:
18979 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18980 info_ptr
+= bytes_read
;
18983 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18984 + read_1_byte (abfd
, info_ptr
));
18988 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18989 + read_2_bytes (abfd
, info_ptr
));
18993 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18994 + read_4_bytes (abfd
, info_ptr
));
18998 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18999 + read_8_bytes (abfd
, info_ptr
));
19002 case DW_FORM_ref_sig8
:
19003 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19006 case DW_FORM_ref_udata
:
19007 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19008 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19009 info_ptr
+= bytes_read
;
19011 case DW_FORM_indirect
:
19012 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19013 info_ptr
+= bytes_read
;
19014 if (form
== DW_FORM_implicit_const
)
19016 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19017 info_ptr
+= bytes_read
;
19019 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19022 case DW_FORM_implicit_const
:
19023 DW_SND (attr
) = implicit_const
;
19025 case DW_FORM_GNU_addr_index
:
19026 if (reader
->dwo_file
== NULL
)
19028 /* For now flag a hard error.
19029 Later we can turn this into a complaint. */
19030 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19031 dwarf_form_name (form
),
19032 bfd_get_filename (abfd
));
19034 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
19035 info_ptr
+= bytes_read
;
19037 case DW_FORM_GNU_str_index
:
19038 if (reader
->dwo_file
== NULL
)
19040 /* For now flag a hard error.
19041 Later we can turn this into a complaint if warranted. */
19042 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19043 dwarf_form_name (form
),
19044 bfd_get_filename (abfd
));
19047 ULONGEST str_index
=
19048 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19050 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19051 DW_STRING_IS_CANONICAL (attr
) = 0;
19052 info_ptr
+= bytes_read
;
19056 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19057 dwarf_form_name (form
),
19058 bfd_get_filename (abfd
));
19062 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19063 attr
->form
= DW_FORM_GNU_ref_alt
;
19065 /* We have seen instances where the compiler tried to emit a byte
19066 size attribute of -1 which ended up being encoded as an unsigned
19067 0xffffffff. Although 0xffffffff is technically a valid size value,
19068 an object of this size seems pretty unlikely so we can relatively
19069 safely treat these cases as if the size attribute was invalid and
19070 treat them as zero by default. */
19071 if (attr
->name
== DW_AT_byte_size
19072 && form
== DW_FORM_data4
19073 && DW_UNSND (attr
) >= 0xffffffff)
19076 (&symfile_complaints
,
19077 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19078 hex_string (DW_UNSND (attr
)));
19079 DW_UNSND (attr
) = 0;
19085 /* Read an attribute described by an abbreviated attribute. */
19087 static const gdb_byte
*
19088 read_attribute (const struct die_reader_specs
*reader
,
19089 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19090 const gdb_byte
*info_ptr
)
19092 attr
->name
= abbrev
->name
;
19093 return read_attribute_value (reader
, attr
, abbrev
->form
,
19094 abbrev
->implicit_const
, info_ptr
);
19097 /* Read dwarf information from a buffer. */
19099 static unsigned int
19100 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19102 return bfd_get_8 (abfd
, buf
);
19106 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19108 return bfd_get_signed_8 (abfd
, buf
);
19111 static unsigned int
19112 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19114 return bfd_get_16 (abfd
, buf
);
19118 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19120 return bfd_get_signed_16 (abfd
, buf
);
19123 static unsigned int
19124 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19126 return bfd_get_32 (abfd
, buf
);
19130 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19132 return bfd_get_signed_32 (abfd
, buf
);
19136 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19138 return bfd_get_64 (abfd
, buf
);
19142 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19143 unsigned int *bytes_read
)
19145 struct comp_unit_head
*cu_header
= &cu
->header
;
19146 CORE_ADDR retval
= 0;
19148 if (cu_header
->signed_addr_p
)
19150 switch (cu_header
->addr_size
)
19153 retval
= bfd_get_signed_16 (abfd
, buf
);
19156 retval
= bfd_get_signed_32 (abfd
, buf
);
19159 retval
= bfd_get_signed_64 (abfd
, buf
);
19162 internal_error (__FILE__
, __LINE__
,
19163 _("read_address: bad switch, signed [in module %s]"),
19164 bfd_get_filename (abfd
));
19169 switch (cu_header
->addr_size
)
19172 retval
= bfd_get_16 (abfd
, buf
);
19175 retval
= bfd_get_32 (abfd
, buf
);
19178 retval
= bfd_get_64 (abfd
, buf
);
19181 internal_error (__FILE__
, __LINE__
,
19182 _("read_address: bad switch, "
19183 "unsigned [in module %s]"),
19184 bfd_get_filename (abfd
));
19188 *bytes_read
= cu_header
->addr_size
;
19192 /* Read the initial length from a section. The (draft) DWARF 3
19193 specification allows the initial length to take up either 4 bytes
19194 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19195 bytes describe the length and all offsets will be 8 bytes in length
19198 An older, non-standard 64-bit format is also handled by this
19199 function. The older format in question stores the initial length
19200 as an 8-byte quantity without an escape value. Lengths greater
19201 than 2^32 aren't very common which means that the initial 4 bytes
19202 is almost always zero. Since a length value of zero doesn't make
19203 sense for the 32-bit format, this initial zero can be considered to
19204 be an escape value which indicates the presence of the older 64-bit
19205 format. As written, the code can't detect (old format) lengths
19206 greater than 4GB. If it becomes necessary to handle lengths
19207 somewhat larger than 4GB, we could allow other small values (such
19208 as the non-sensical values of 1, 2, and 3) to also be used as
19209 escape values indicating the presence of the old format.
19211 The value returned via bytes_read should be used to increment the
19212 relevant pointer after calling read_initial_length().
19214 [ Note: read_initial_length() and read_offset() are based on the
19215 document entitled "DWARF Debugging Information Format", revision
19216 3, draft 8, dated November 19, 2001. This document was obtained
19219 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19221 This document is only a draft and is subject to change. (So beware.)
19223 Details regarding the older, non-standard 64-bit format were
19224 determined empirically by examining 64-bit ELF files produced by
19225 the SGI toolchain on an IRIX 6.5 machine.
19227 - Kevin, July 16, 2002
19231 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19233 LONGEST length
= bfd_get_32 (abfd
, buf
);
19235 if (length
== 0xffffffff)
19237 length
= bfd_get_64 (abfd
, buf
+ 4);
19240 else if (length
== 0)
19242 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19243 length
= bfd_get_64 (abfd
, buf
);
19254 /* Cover function for read_initial_length.
19255 Returns the length of the object at BUF, and stores the size of the
19256 initial length in *BYTES_READ and stores the size that offsets will be in
19258 If the initial length size is not equivalent to that specified in
19259 CU_HEADER then issue a complaint.
19260 This is useful when reading non-comp-unit headers. */
19263 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19264 const struct comp_unit_head
*cu_header
,
19265 unsigned int *bytes_read
,
19266 unsigned int *offset_size
)
19268 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19270 gdb_assert (cu_header
->initial_length_size
== 4
19271 || cu_header
->initial_length_size
== 8
19272 || cu_header
->initial_length_size
== 12);
19274 if (cu_header
->initial_length_size
!= *bytes_read
)
19275 complaint (&symfile_complaints
,
19276 _("intermixed 32-bit and 64-bit DWARF sections"));
19278 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19282 /* Read an offset from the data stream. The size of the offset is
19283 given by cu_header->offset_size. */
19286 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19287 const struct comp_unit_head
*cu_header
,
19288 unsigned int *bytes_read
)
19290 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19292 *bytes_read
= cu_header
->offset_size
;
19296 /* Read an offset from the data stream. */
19299 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19301 LONGEST retval
= 0;
19303 switch (offset_size
)
19306 retval
= bfd_get_32 (abfd
, buf
);
19309 retval
= bfd_get_64 (abfd
, buf
);
19312 internal_error (__FILE__
, __LINE__
,
19313 _("read_offset_1: bad switch [in module %s]"),
19314 bfd_get_filename (abfd
));
19320 static const gdb_byte
*
19321 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19323 /* If the size of a host char is 8 bits, we can return a pointer
19324 to the buffer, otherwise we have to copy the data to a buffer
19325 allocated on the temporary obstack. */
19326 gdb_assert (HOST_CHAR_BIT
== 8);
19330 static const char *
19331 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19332 unsigned int *bytes_read_ptr
)
19334 /* If the size of a host char is 8 bits, we can return a pointer
19335 to the string, otherwise we have to copy the string to a buffer
19336 allocated on the temporary obstack. */
19337 gdb_assert (HOST_CHAR_BIT
== 8);
19340 *bytes_read_ptr
= 1;
19343 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19344 return (const char *) buf
;
19347 /* Return pointer to string at section SECT offset STR_OFFSET with error
19348 reporting strings FORM_NAME and SECT_NAME. */
19350 static const char *
19351 read_indirect_string_at_offset_from (bfd
*abfd
, LONGEST str_offset
,
19352 struct dwarf2_section_info
*sect
,
19353 const char *form_name
,
19354 const char *sect_name
)
19356 dwarf2_read_section (dwarf2_per_objfile
->objfile
, sect
);
19357 if (sect
->buffer
== NULL
)
19358 error (_("%s used without %s section [in module %s]"),
19359 form_name
, sect_name
, bfd_get_filename (abfd
));
19360 if (str_offset
>= sect
->size
)
19361 error (_("%s pointing outside of %s section [in module %s]"),
19362 form_name
, sect_name
, bfd_get_filename (abfd
));
19363 gdb_assert (HOST_CHAR_BIT
== 8);
19364 if (sect
->buffer
[str_offset
] == '\0')
19366 return (const char *) (sect
->buffer
+ str_offset
);
19369 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19371 static const char *
19372 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
19374 return read_indirect_string_at_offset_from (abfd
, str_offset
,
19375 &dwarf2_per_objfile
->str
,
19376 "DW_FORM_strp", ".debug_str");
19379 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19381 static const char *
19382 read_indirect_line_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
19384 return read_indirect_string_at_offset_from (abfd
, str_offset
,
19385 &dwarf2_per_objfile
->line_str
,
19386 "DW_FORM_line_strp",
19387 ".debug_line_str");
19390 /* Read a string at offset STR_OFFSET in the .debug_str section from
19391 the .dwz file DWZ. Throw an error if the offset is too large. If
19392 the string consists of a single NUL byte, return NULL; otherwise
19393 return a pointer to the string. */
19395 static const char *
19396 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
19398 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
19400 if (dwz
->str
.buffer
== NULL
)
19401 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19402 "section [in module %s]"),
19403 bfd_get_filename (dwz
->dwz_bfd
));
19404 if (str_offset
>= dwz
->str
.size
)
19405 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19406 ".debug_str section [in module %s]"),
19407 bfd_get_filename (dwz
->dwz_bfd
));
19408 gdb_assert (HOST_CHAR_BIT
== 8);
19409 if (dwz
->str
.buffer
[str_offset
] == '\0')
19411 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19414 /* Return pointer to string at .debug_str offset as read from BUF.
19415 BUF is assumed to be in a compilation unit described by CU_HEADER.
19416 Return *BYTES_READ_PTR count of bytes read from BUF. */
19418 static const char *
19419 read_indirect_string (bfd
*abfd
, const gdb_byte
*buf
,
19420 const struct comp_unit_head
*cu_header
,
19421 unsigned int *bytes_read_ptr
)
19423 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19425 return read_indirect_string_at_offset (abfd
, str_offset
);
19428 /* Return pointer to string at .debug_line_str offset as read from BUF.
19429 BUF is assumed to be in a compilation unit described by CU_HEADER.
19430 Return *BYTES_READ_PTR count of bytes read from BUF. */
19432 static const char *
19433 read_indirect_line_string (bfd
*abfd
, const gdb_byte
*buf
,
19434 const struct comp_unit_head
*cu_header
,
19435 unsigned int *bytes_read_ptr
)
19437 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19439 return read_indirect_line_string_at_offset (abfd
, str_offset
);
19443 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19444 unsigned int *bytes_read_ptr
)
19447 unsigned int num_read
;
19449 unsigned char byte
;
19456 byte
= bfd_get_8 (abfd
, buf
);
19459 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19460 if ((byte
& 128) == 0)
19466 *bytes_read_ptr
= num_read
;
19471 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19472 unsigned int *bytes_read_ptr
)
19475 int shift
, num_read
;
19476 unsigned char byte
;
19483 byte
= bfd_get_8 (abfd
, buf
);
19486 result
|= ((LONGEST
) (byte
& 127) << shift
);
19488 if ((byte
& 128) == 0)
19493 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
19494 result
|= -(((LONGEST
) 1) << shift
);
19495 *bytes_read_ptr
= num_read
;
19499 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19500 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
19501 ADDR_SIZE is the size of addresses from the CU header. */
19504 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
19506 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19507 bfd
*abfd
= objfile
->obfd
;
19508 const gdb_byte
*info_ptr
;
19510 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
19511 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
19512 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19513 objfile_name (objfile
));
19514 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
19515 error (_("DW_FORM_addr_index pointing outside of "
19516 ".debug_addr section [in module %s]"),
19517 objfile_name (objfile
));
19518 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
19519 + addr_base
+ addr_index
* addr_size
);
19520 if (addr_size
== 4)
19521 return bfd_get_32 (abfd
, info_ptr
);
19523 return bfd_get_64 (abfd
, info_ptr
);
19526 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19529 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19531 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
19534 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19537 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19538 unsigned int *bytes_read
)
19540 bfd
*abfd
= cu
->objfile
->obfd
;
19541 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19543 return read_addr_index (cu
, addr_index
);
19546 /* Data structure to pass results from dwarf2_read_addr_index_reader
19547 back to dwarf2_read_addr_index. */
19549 struct dwarf2_read_addr_index_data
19551 ULONGEST addr_base
;
19555 /* die_reader_func for dwarf2_read_addr_index. */
19558 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
19559 const gdb_byte
*info_ptr
,
19560 struct die_info
*comp_unit_die
,
19564 struct dwarf2_cu
*cu
= reader
->cu
;
19565 struct dwarf2_read_addr_index_data
*aidata
=
19566 (struct dwarf2_read_addr_index_data
*) data
;
19568 aidata
->addr_base
= cu
->addr_base
;
19569 aidata
->addr_size
= cu
->header
.addr_size
;
19572 /* Given an index in .debug_addr, fetch the value.
19573 NOTE: This can be called during dwarf expression evaluation,
19574 long after the debug information has been read, and thus per_cu->cu
19575 may no longer exist. */
19578 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
19579 unsigned int addr_index
)
19581 struct objfile
*objfile
= per_cu
->objfile
;
19582 struct dwarf2_cu
*cu
= per_cu
->cu
;
19583 ULONGEST addr_base
;
19586 /* This is intended to be called from outside this file. */
19587 dw2_setup (objfile
);
19589 /* We need addr_base and addr_size.
19590 If we don't have PER_CU->cu, we have to get it.
19591 Nasty, but the alternative is storing the needed info in PER_CU,
19592 which at this point doesn't seem justified: it's not clear how frequently
19593 it would get used and it would increase the size of every PER_CU.
19594 Entry points like dwarf2_per_cu_addr_size do a similar thing
19595 so we're not in uncharted territory here.
19596 Alas we need to be a bit more complicated as addr_base is contained
19599 We don't need to read the entire CU(/TU).
19600 We just need the header and top level die.
19602 IWBN to use the aging mechanism to let us lazily later discard the CU.
19603 For now we skip this optimization. */
19607 addr_base
= cu
->addr_base
;
19608 addr_size
= cu
->header
.addr_size
;
19612 struct dwarf2_read_addr_index_data aidata
;
19614 /* Note: We can't use init_cutu_and_read_dies_simple here,
19615 we need addr_base. */
19616 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
19617 dwarf2_read_addr_index_reader
, &aidata
);
19618 addr_base
= aidata
.addr_base
;
19619 addr_size
= aidata
.addr_size
;
19622 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
19625 /* Given a DW_FORM_GNU_str_index, fetch the string.
19626 This is only used by the Fission support. */
19628 static const char *
19629 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19631 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19632 const char *objf_name
= objfile_name (objfile
);
19633 bfd
*abfd
= objfile
->obfd
;
19634 struct dwarf2_cu
*cu
= reader
->cu
;
19635 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
19636 struct dwarf2_section_info
*str_offsets_section
=
19637 &reader
->dwo_file
->sections
.str_offsets
;
19638 const gdb_byte
*info_ptr
;
19639 ULONGEST str_offset
;
19640 static const char form_name
[] = "DW_FORM_GNU_str_index";
19642 dwarf2_read_section (objfile
, str_section
);
19643 dwarf2_read_section (objfile
, str_offsets_section
);
19644 if (str_section
->buffer
== NULL
)
19645 error (_("%s used without .debug_str.dwo section"
19646 " in CU at offset 0x%x [in module %s]"),
19647 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
19648 if (str_offsets_section
->buffer
== NULL
)
19649 error (_("%s used without .debug_str_offsets.dwo section"
19650 " in CU at offset 0x%x [in module %s]"),
19651 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
19652 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
19653 error (_("%s pointing outside of .debug_str_offsets.dwo"
19654 " section in CU at offset 0x%x [in module %s]"),
19655 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
19656 info_ptr
= (str_offsets_section
->buffer
19657 + str_index
* cu
->header
.offset_size
);
19658 if (cu
->header
.offset_size
== 4)
19659 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19661 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19662 if (str_offset
>= str_section
->size
)
19663 error (_("Offset from %s pointing outside of"
19664 " .debug_str.dwo section in CU at offset 0x%x [in module %s]"),
19665 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
19666 return (const char *) (str_section
->buffer
+ str_offset
);
19669 /* Return the length of an LEB128 number in BUF. */
19672 leb128_size (const gdb_byte
*buf
)
19674 const gdb_byte
*begin
= buf
;
19680 if ((byte
& 128) == 0)
19681 return buf
- begin
;
19686 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19695 cu
->language
= language_c
;
19698 case DW_LANG_C_plus_plus
:
19699 case DW_LANG_C_plus_plus_11
:
19700 case DW_LANG_C_plus_plus_14
:
19701 cu
->language
= language_cplus
;
19704 cu
->language
= language_d
;
19706 case DW_LANG_Fortran77
:
19707 case DW_LANG_Fortran90
:
19708 case DW_LANG_Fortran95
:
19709 case DW_LANG_Fortran03
:
19710 case DW_LANG_Fortran08
:
19711 cu
->language
= language_fortran
;
19714 cu
->language
= language_go
;
19716 case DW_LANG_Mips_Assembler
:
19717 cu
->language
= language_asm
;
19719 case DW_LANG_Ada83
:
19720 case DW_LANG_Ada95
:
19721 cu
->language
= language_ada
;
19723 case DW_LANG_Modula2
:
19724 cu
->language
= language_m2
;
19726 case DW_LANG_Pascal83
:
19727 cu
->language
= language_pascal
;
19730 cu
->language
= language_objc
;
19733 case DW_LANG_Rust_old
:
19734 cu
->language
= language_rust
;
19736 case DW_LANG_Cobol74
:
19737 case DW_LANG_Cobol85
:
19739 cu
->language
= language_minimal
;
19742 cu
->language_defn
= language_def (cu
->language
);
19745 /* Return the named attribute or NULL if not there. */
19747 static struct attribute
*
19748 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19753 struct attribute
*spec
= NULL
;
19755 for (i
= 0; i
< die
->num_attrs
; ++i
)
19757 if (die
->attrs
[i
].name
== name
)
19758 return &die
->attrs
[i
];
19759 if (die
->attrs
[i
].name
== DW_AT_specification
19760 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19761 spec
= &die
->attrs
[i
];
19767 die
= follow_die_ref (die
, spec
, &cu
);
19773 /* Return the named attribute or NULL if not there,
19774 but do not follow DW_AT_specification, etc.
19775 This is for use in contexts where we're reading .debug_types dies.
19776 Following DW_AT_specification, DW_AT_abstract_origin will take us
19777 back up the chain, and we want to go down. */
19779 static struct attribute
*
19780 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19784 for (i
= 0; i
< die
->num_attrs
; ++i
)
19785 if (die
->attrs
[i
].name
== name
)
19786 return &die
->attrs
[i
];
19791 /* Return the string associated with a string-typed attribute, or NULL if it
19792 is either not found or is of an incorrect type. */
19794 static const char *
19795 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19797 struct attribute
*attr
;
19798 const char *str
= NULL
;
19800 attr
= dwarf2_attr (die
, name
, cu
);
19804 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19805 || attr
->form
== DW_FORM_string
19806 || attr
->form
== DW_FORM_GNU_str_index
19807 || attr
->form
== DW_FORM_GNU_strp_alt
)
19808 str
= DW_STRING (attr
);
19810 complaint (&symfile_complaints
,
19811 _("string type expected for attribute %s for "
19812 "DIE at 0x%x in module %s"),
19813 dwarf_attr_name (name
), to_underlying (die
->sect_off
),
19814 objfile_name (cu
->objfile
));
19820 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19821 and holds a non-zero value. This function should only be used for
19822 DW_FORM_flag or DW_FORM_flag_present attributes. */
19825 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19827 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19829 return (attr
&& DW_UNSND (attr
));
19833 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19835 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19836 which value is non-zero. However, we have to be careful with
19837 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19838 (via dwarf2_flag_true_p) follows this attribute. So we may
19839 end up accidently finding a declaration attribute that belongs
19840 to a different DIE referenced by the specification attribute,
19841 even though the given DIE does not have a declaration attribute. */
19842 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19843 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19846 /* Return the die giving the specification for DIE, if there is
19847 one. *SPEC_CU is the CU containing DIE on input, and the CU
19848 containing the return value on output. If there is no
19849 specification, but there is an abstract origin, that is
19852 static struct die_info
*
19853 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19855 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19858 if (spec_attr
== NULL
)
19859 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19861 if (spec_attr
== NULL
)
19864 return follow_die_ref (die
, spec_attr
, spec_cu
);
19867 /* Stub for free_line_header to match void * callback types. */
19870 free_line_header_voidp (void *arg
)
19872 struct line_header
*lh
= (struct line_header
*) arg
;
19878 line_header::add_include_dir (const char *include_dir
)
19880 if (dwarf_line_debug
>= 2)
19881 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
19882 include_dirs
.size () + 1, include_dir
);
19884 include_dirs
.push_back (include_dir
);
19888 line_header::add_file_name (const char *name
,
19890 unsigned int mod_time
,
19891 unsigned int length
)
19893 if (dwarf_line_debug
>= 2)
19894 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
19895 (unsigned) file_names
.size () + 1, name
);
19897 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
19900 /* A convenience function to find the proper .debug_line section for a CU. */
19902 static struct dwarf2_section_info
*
19903 get_debug_line_section (struct dwarf2_cu
*cu
)
19905 struct dwarf2_section_info
*section
;
19907 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19909 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19910 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19911 else if (cu
->per_cu
->is_dwz
)
19913 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
19915 section
= &dwz
->line
;
19918 section
= &dwarf2_per_objfile
->line
;
19923 /* Read directory or file name entry format, starting with byte of
19924 format count entries, ULEB128 pairs of entry formats, ULEB128 of
19925 entries count and the entries themselves in the described entry
19929 read_formatted_entries (bfd
*abfd
, const gdb_byte
**bufp
,
19930 struct line_header
*lh
,
19931 const struct comp_unit_head
*cu_header
,
19932 void (*callback
) (struct line_header
*lh
,
19935 unsigned int mod_time
,
19936 unsigned int length
))
19938 gdb_byte format_count
, formati
;
19939 ULONGEST data_count
, datai
;
19940 const gdb_byte
*buf
= *bufp
;
19941 const gdb_byte
*format_header_data
;
19942 unsigned int bytes_read
;
19944 format_count
= read_1_byte (abfd
, buf
);
19946 format_header_data
= buf
;
19947 for (formati
= 0; formati
< format_count
; formati
++)
19949 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19951 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19955 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19957 for (datai
= 0; datai
< data_count
; datai
++)
19959 const gdb_byte
*format
= format_header_data
;
19960 struct file_entry fe
;
19962 for (formati
= 0; formati
< format_count
; formati
++)
19964 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19965 format
+= bytes_read
;
19967 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19968 format
+= bytes_read
;
19970 gdb::optional
<const char *> string
;
19971 gdb::optional
<unsigned int> uint
;
19975 case DW_FORM_string
:
19976 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
19980 case DW_FORM_line_strp
:
19981 string
.emplace (read_indirect_line_string (abfd
, buf
,
19987 case DW_FORM_data1
:
19988 uint
.emplace (read_1_byte (abfd
, buf
));
19992 case DW_FORM_data2
:
19993 uint
.emplace (read_2_bytes (abfd
, buf
));
19997 case DW_FORM_data4
:
19998 uint
.emplace (read_4_bytes (abfd
, buf
));
20002 case DW_FORM_data8
:
20003 uint
.emplace (read_8_bytes (abfd
, buf
));
20007 case DW_FORM_udata
:
20008 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20012 case DW_FORM_block
:
20013 /* It is valid only for DW_LNCT_timestamp which is ignored by
20018 switch (content_type
)
20021 if (string
.has_value ())
20024 case DW_LNCT_directory_index
:
20025 if (uint
.has_value ())
20026 fe
.d_index
= (dir_index
) *uint
;
20028 case DW_LNCT_timestamp
:
20029 if (uint
.has_value ())
20030 fe
.mod_time
= *uint
;
20033 if (uint
.has_value ())
20039 complaint (&symfile_complaints
,
20040 _("Unknown format content type %s"),
20041 pulongest (content_type
));
20045 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20051 /* Read the statement program header starting at OFFSET in
20052 .debug_line, or .debug_line.dwo. Return a pointer
20053 to a struct line_header, allocated using xmalloc.
20054 Returns NULL if there is a problem reading the header, e.g., if it
20055 has a version we don't understand.
20057 NOTE: the strings in the include directory and file name tables of
20058 the returned object point into the dwarf line section buffer,
20059 and must not be freed. */
20061 static line_header_up
20062 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20064 const gdb_byte
*line_ptr
;
20065 unsigned int bytes_read
, offset_size
;
20067 const char *cur_dir
, *cur_file
;
20068 struct dwarf2_section_info
*section
;
20071 section
= get_debug_line_section (cu
);
20072 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20073 if (section
->buffer
== NULL
)
20075 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20076 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
20078 complaint (&symfile_complaints
, _("missing .debug_line section"));
20082 /* We can't do this until we know the section is non-empty.
20083 Only then do we know we have such a section. */
20084 abfd
= get_section_bfd_owner (section
);
20086 /* Make sure that at least there's room for the total_length field.
20087 That could be 12 bytes long, but we're just going to fudge that. */
20088 if (to_underlying (sect_off
) + 4 >= section
->size
)
20090 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20094 line_header_up
lh (new line_header ());
20096 lh
->sect_off
= sect_off
;
20097 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20099 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20101 /* Read in the header. */
20103 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20104 &bytes_read
, &offset_size
);
20105 line_ptr
+= bytes_read
;
20106 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20108 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20111 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
20112 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20114 if (lh
->version
> 5)
20116 /* This is a version we don't understand. The format could have
20117 changed in ways we don't handle properly so just punt. */
20118 complaint (&symfile_complaints
,
20119 _("unsupported version in .debug_line section"));
20122 if (lh
->version
>= 5)
20124 gdb_byte segment_selector_size
;
20126 /* Skip address size. */
20127 read_1_byte (abfd
, line_ptr
);
20130 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20132 if (segment_selector_size
!= 0)
20134 complaint (&symfile_complaints
,
20135 _("unsupported segment selector size %u "
20136 "in .debug_line section"),
20137 segment_selector_size
);
20141 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20142 line_ptr
+= offset_size
;
20143 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20145 if (lh
->version
>= 4)
20147 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20151 lh
->maximum_ops_per_instruction
= 1;
20153 if (lh
->maximum_ops_per_instruction
== 0)
20155 lh
->maximum_ops_per_instruction
= 1;
20156 complaint (&symfile_complaints
,
20157 _("invalid maximum_ops_per_instruction "
20158 "in `.debug_line' section"));
20161 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20163 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20165 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20167 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20169 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20171 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20172 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20174 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20178 if (lh
->version
>= 5)
20180 /* Read directory table. */
20181 read_formatted_entries (abfd
, &line_ptr
, lh
.get (), &cu
->header
,
20182 [] (struct line_header
*lh
, const char *name
,
20183 dir_index d_index
, unsigned int mod_time
,
20184 unsigned int length
)
20186 lh
->add_include_dir (name
);
20189 /* Read file name table. */
20190 read_formatted_entries (abfd
, &line_ptr
, lh
.get (), &cu
->header
,
20191 [] (struct line_header
*lh
, const char *name
,
20192 dir_index d_index
, unsigned int mod_time
,
20193 unsigned int length
)
20195 lh
->add_file_name (name
, d_index
, mod_time
, length
);
20200 /* Read directory table. */
20201 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20203 line_ptr
+= bytes_read
;
20204 lh
->add_include_dir (cur_dir
);
20206 line_ptr
+= bytes_read
;
20208 /* Read file name table. */
20209 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20211 unsigned int mod_time
, length
;
20214 line_ptr
+= bytes_read
;
20215 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20216 line_ptr
+= bytes_read
;
20217 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20218 line_ptr
+= bytes_read
;
20219 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20220 line_ptr
+= bytes_read
;
20222 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20224 line_ptr
+= bytes_read
;
20226 lh
->statement_program_start
= line_ptr
;
20228 if (line_ptr
> (section
->buffer
+ section
->size
))
20229 complaint (&symfile_complaints
,
20230 _("line number info header doesn't "
20231 "fit in `.debug_line' section"));
20236 /* Subroutine of dwarf_decode_lines to simplify it.
20237 Return the file name of the psymtab for included file FILE_INDEX
20238 in line header LH of PST.
20239 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20240 If space for the result is malloc'd, it will be freed by a cleanup.
20241 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename.
20243 The function creates dangling cleanup registration. */
20245 static const char *
20246 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
20247 const struct partial_symtab
*pst
,
20248 const char *comp_dir
)
20250 const file_entry
&fe
= lh
->file_names
[file_index
];
20251 const char *include_name
= fe
.name
;
20252 const char *include_name_to_compare
= include_name
;
20253 const char *pst_filename
;
20254 char *copied_name
= NULL
;
20257 const char *dir_name
= fe
.include_dir (lh
);
20259 if (!IS_ABSOLUTE_PATH (include_name
)
20260 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20262 /* Avoid creating a duplicate psymtab for PST.
20263 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20264 Before we do the comparison, however, we need to account
20265 for DIR_NAME and COMP_DIR.
20266 First prepend dir_name (if non-NULL). If we still don't
20267 have an absolute path prepend comp_dir (if non-NULL).
20268 However, the directory we record in the include-file's
20269 psymtab does not contain COMP_DIR (to match the
20270 corresponding symtab(s)).
20275 bash$ gcc -g ./hello.c
20276 include_name = "hello.c"
20278 DW_AT_comp_dir = comp_dir = "/tmp"
20279 DW_AT_name = "./hello.c"
20283 if (dir_name
!= NULL
)
20285 char *tem
= concat (dir_name
, SLASH_STRING
,
20286 include_name
, (char *)NULL
);
20288 make_cleanup (xfree
, tem
);
20289 include_name
= tem
;
20290 include_name_to_compare
= include_name
;
20292 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20294 char *tem
= concat (comp_dir
, SLASH_STRING
,
20295 include_name
, (char *)NULL
);
20297 make_cleanup (xfree
, tem
);
20298 include_name_to_compare
= tem
;
20302 pst_filename
= pst
->filename
;
20303 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20305 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
20306 pst_filename
, (char *)NULL
);
20307 pst_filename
= copied_name
;
20310 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20312 if (copied_name
!= NULL
)
20313 xfree (copied_name
);
20317 return include_name
;
20320 /* State machine to track the state of the line number program. */
20322 class lnp_state_machine
20325 /* Initialize a machine state for the start of a line number
20327 lnp_state_machine (gdbarch
*arch
, line_header
*lh
, bool record_lines_p
);
20329 file_entry
*current_file ()
20331 /* lh->file_names is 0-based, but the file name numbers in the
20332 statement program are 1-based. */
20333 return m_line_header
->file_name_at (m_file
);
20336 /* Record the line in the state machine. END_SEQUENCE is true if
20337 we're processing the end of a sequence. */
20338 void record_line (bool end_sequence
);
20340 /* Check address and if invalid nop-out the rest of the lines in this
20342 void check_line_address (struct dwarf2_cu
*cu
,
20343 const gdb_byte
*line_ptr
,
20344 CORE_ADDR lowpc
, CORE_ADDR address
);
20346 void handle_set_discriminator (unsigned int discriminator
)
20348 m_discriminator
= discriminator
;
20349 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20352 /* Handle DW_LNE_set_address. */
20353 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20356 address
+= baseaddr
;
20357 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20360 /* Handle DW_LNS_advance_pc. */
20361 void handle_advance_pc (CORE_ADDR adjust
);
20363 /* Handle a special opcode. */
20364 void handle_special_opcode (unsigned char op_code
);
20366 /* Handle DW_LNS_advance_line. */
20367 void handle_advance_line (int line_delta
)
20369 advance_line (line_delta
);
20372 /* Handle DW_LNS_set_file. */
20373 void handle_set_file (file_name_index file
);
20375 /* Handle DW_LNS_negate_stmt. */
20376 void handle_negate_stmt ()
20378 m_is_stmt
= !m_is_stmt
;
20381 /* Handle DW_LNS_const_add_pc. */
20382 void handle_const_add_pc ();
20384 /* Handle DW_LNS_fixed_advance_pc. */
20385 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20387 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20391 /* Handle DW_LNS_copy. */
20392 void handle_copy ()
20394 record_line (false);
20395 m_discriminator
= 0;
20398 /* Handle DW_LNE_end_sequence. */
20399 void handle_end_sequence ()
20401 m_record_line_callback
= ::record_line
;
20405 /* Advance the line by LINE_DELTA. */
20406 void advance_line (int line_delta
)
20408 m_line
+= line_delta
;
20410 if (line_delta
!= 0)
20411 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20414 gdbarch
*m_gdbarch
;
20416 /* True if we're recording lines.
20417 Otherwise we're building partial symtabs and are just interested in
20418 finding include files mentioned by the line number program. */
20419 bool m_record_lines_p
;
20421 /* The line number header. */
20422 line_header
*m_line_header
;
20424 /* These are part of the standard DWARF line number state machine,
20425 and initialized according to the DWARF spec. */
20427 unsigned char m_op_index
= 0;
20428 /* The line table index (1-based) of the current file. */
20429 file_name_index m_file
= (file_name_index
) 1;
20430 unsigned int m_line
= 1;
20432 /* These are initialized in the constructor. */
20434 CORE_ADDR m_address
;
20436 unsigned int m_discriminator
;
20438 /* Additional bits of state we need to track. */
20440 /* The last file that we called dwarf2_start_subfile for.
20441 This is only used for TLLs. */
20442 unsigned int m_last_file
= 0;
20443 /* The last file a line number was recorded for. */
20444 struct subfile
*m_last_subfile
= NULL
;
20446 /* The function to call to record a line. */
20447 record_line_ftype
*m_record_line_callback
= NULL
;
20449 /* The last line number that was recorded, used to coalesce
20450 consecutive entries for the same line. This can happen, for
20451 example, when discriminators are present. PR 17276. */
20452 unsigned int m_last_line
= 0;
20453 bool m_line_has_non_zero_discriminator
= false;
20457 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20459 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20460 / m_line_header
->maximum_ops_per_instruction
)
20461 * m_line_header
->minimum_instruction_length
);
20462 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20463 m_op_index
= ((m_op_index
+ adjust
)
20464 % m_line_header
->maximum_ops_per_instruction
);
20468 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20470 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20471 CORE_ADDR addr_adj
= (((m_op_index
20472 + (adj_opcode
/ m_line_header
->line_range
))
20473 / m_line_header
->maximum_ops_per_instruction
)
20474 * m_line_header
->minimum_instruction_length
);
20475 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20476 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
20477 % m_line_header
->maximum_ops_per_instruction
);
20479 int line_delta
= (m_line_header
->line_base
20480 + (adj_opcode
% m_line_header
->line_range
));
20481 advance_line (line_delta
);
20482 record_line (false);
20483 m_discriminator
= 0;
20487 lnp_state_machine::handle_set_file (file_name_index file
)
20491 const file_entry
*fe
= current_file ();
20493 dwarf2_debug_line_missing_file_complaint ();
20494 else if (m_record_lines_p
)
20496 const char *dir
= fe
->include_dir (m_line_header
);
20498 m_last_subfile
= current_subfile
;
20499 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20500 dwarf2_start_subfile (fe
->name
, dir
);
20505 lnp_state_machine::handle_const_add_pc ()
20508 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20511 = (((m_op_index
+ adjust
)
20512 / m_line_header
->maximum_ops_per_instruction
)
20513 * m_line_header
->minimum_instruction_length
);
20515 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20516 m_op_index
= ((m_op_index
+ adjust
)
20517 % m_line_header
->maximum_ops_per_instruction
);
20520 /* Ignore this record_line request. */
20523 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
20528 /* Return non-zero if we should add LINE to the line number table.
20529 LINE is the line to add, LAST_LINE is the last line that was added,
20530 LAST_SUBFILE is the subfile for LAST_LINE.
20531 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20532 had a non-zero discriminator.
20534 We have to be careful in the presence of discriminators.
20535 E.g., for this line:
20537 for (i = 0; i < 100000; i++);
20539 clang can emit four line number entries for that one line,
20540 each with a different discriminator.
20541 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20543 However, we want gdb to coalesce all four entries into one.
20544 Otherwise the user could stepi into the middle of the line and
20545 gdb would get confused about whether the pc really was in the
20546 middle of the line.
20548 Things are further complicated by the fact that two consecutive
20549 line number entries for the same line is a heuristic used by gcc
20550 to denote the end of the prologue. So we can't just discard duplicate
20551 entries, we have to be selective about it. The heuristic we use is
20552 that we only collapse consecutive entries for the same line if at least
20553 one of those entries has a non-zero discriminator. PR 17276.
20555 Note: Addresses in the line number state machine can never go backwards
20556 within one sequence, thus this coalescing is ok. */
20559 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
20560 int line_has_non_zero_discriminator
,
20561 struct subfile
*last_subfile
)
20563 if (current_subfile
!= last_subfile
)
20565 if (line
!= last_line
)
20567 /* Same line for the same file that we've seen already.
20568 As a last check, for pr 17276, only record the line if the line
20569 has never had a non-zero discriminator. */
20570 if (!line_has_non_zero_discriminator
)
20575 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
20576 in the line table of subfile SUBFILE. */
20579 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20580 unsigned int line
, CORE_ADDR address
,
20581 record_line_ftype p_record_line
)
20583 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20585 if (dwarf_line_debug
)
20587 fprintf_unfiltered (gdb_stdlog
,
20588 "Recording line %u, file %s, address %s\n",
20589 line
, lbasename (subfile
->name
),
20590 paddress (gdbarch
, address
));
20593 (*p_record_line
) (subfile
, line
, addr
);
20596 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20597 Mark the end of a set of line number records.
20598 The arguments are the same as for dwarf_record_line_1.
20599 If SUBFILE is NULL the request is ignored. */
20602 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20603 CORE_ADDR address
, record_line_ftype p_record_line
)
20605 if (subfile
== NULL
)
20608 if (dwarf_line_debug
)
20610 fprintf_unfiltered (gdb_stdlog
,
20611 "Finishing current line, file %s, address %s\n",
20612 lbasename (subfile
->name
),
20613 paddress (gdbarch
, address
));
20616 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
20620 lnp_state_machine::record_line (bool end_sequence
)
20622 if (dwarf_line_debug
)
20624 fprintf_unfiltered (gdb_stdlog
,
20625 "Processing actual line %u: file %u,"
20626 " address %s, is_stmt %u, discrim %u\n",
20627 m_line
, to_underlying (m_file
),
20628 paddress (m_gdbarch
, m_address
),
20629 m_is_stmt
, m_discriminator
);
20632 file_entry
*fe
= current_file ();
20635 dwarf2_debug_line_missing_file_complaint ();
20636 /* For now we ignore lines not starting on an instruction boundary.
20637 But not when processing end_sequence for compatibility with the
20638 previous version of the code. */
20639 else if (m_op_index
== 0 || end_sequence
)
20641 fe
->included_p
= 1;
20642 if (m_record_lines_p
&& m_is_stmt
)
20644 if (m_last_subfile
!= current_subfile
|| end_sequence
)
20646 dwarf_finish_line (m_gdbarch
, m_last_subfile
,
20647 m_address
, m_record_line_callback
);
20652 if (dwarf_record_line_p (m_line
, m_last_line
,
20653 m_line_has_non_zero_discriminator
,
20656 dwarf_record_line_1 (m_gdbarch
, current_subfile
,
20658 m_record_line_callback
);
20660 m_last_subfile
= current_subfile
;
20661 m_last_line
= m_line
;
20667 lnp_state_machine::lnp_state_machine (gdbarch
*arch
, line_header
*lh
,
20668 bool record_lines_p
)
20671 m_record_lines_p
= record_lines_p
;
20672 m_line_header
= lh
;
20674 m_record_line_callback
= ::record_line
;
20676 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20677 was a line entry for it so that the backend has a chance to adjust it
20678 and also record it in case it needs it. This is currently used by MIPS
20679 code, cf. `mips_adjust_dwarf2_line'. */
20680 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20681 m_is_stmt
= lh
->default_is_stmt
;
20682 m_discriminator
= 0;
20686 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20687 const gdb_byte
*line_ptr
,
20688 CORE_ADDR lowpc
, CORE_ADDR address
)
20690 /* If address < lowpc then it's not a usable value, it's outside the
20691 pc range of the CU. However, we restrict the test to only address
20692 values of zero to preserve GDB's previous behaviour which is to
20693 handle the specific case of a function being GC'd by the linker. */
20695 if (address
== 0 && address
< lowpc
)
20697 /* This line table is for a function which has been
20698 GCd by the linker. Ignore it. PR gdb/12528 */
20700 struct objfile
*objfile
= cu
->objfile
;
20701 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20703 complaint (&symfile_complaints
,
20704 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20705 line_offset
, objfile_name (objfile
));
20706 m_record_line_callback
= noop_record_line
;
20707 /* Note: record_line_callback is left as noop_record_line until
20708 we see DW_LNE_end_sequence. */
20712 /* Subroutine of dwarf_decode_lines to simplify it.
20713 Process the line number information in LH.
20714 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20715 program in order to set included_p for every referenced header. */
20718 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20719 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20721 const gdb_byte
*line_ptr
, *extended_end
;
20722 const gdb_byte
*line_end
;
20723 unsigned int bytes_read
, extended_len
;
20724 unsigned char op_code
, extended_op
;
20725 CORE_ADDR baseaddr
;
20726 struct objfile
*objfile
= cu
->objfile
;
20727 bfd
*abfd
= objfile
->obfd
;
20728 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20729 /* True if we're recording line info (as opposed to building partial
20730 symtabs and just interested in finding include files mentioned by
20731 the line number program). */
20732 bool record_lines_p
= !decode_for_pst_p
;
20734 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
20736 line_ptr
= lh
->statement_program_start
;
20737 line_end
= lh
->statement_program_end
;
20739 /* Read the statement sequences until there's nothing left. */
20740 while (line_ptr
< line_end
)
20742 /* The DWARF line number program state machine. Reset the state
20743 machine at the start of each sequence. */
20744 lnp_state_machine
state_machine (gdbarch
, lh
, record_lines_p
);
20745 bool end_sequence
= false;
20747 if (record_lines_p
)
20749 /* Start a subfile for the current file of the state
20751 const file_entry
*fe
= state_machine
.current_file ();
20754 dwarf2_start_subfile (fe
->name
, fe
->include_dir (lh
));
20757 /* Decode the table. */
20758 while (line_ptr
< line_end
&& !end_sequence
)
20760 op_code
= read_1_byte (abfd
, line_ptr
);
20763 if (op_code
>= lh
->opcode_base
)
20765 /* Special opcode. */
20766 state_machine
.handle_special_opcode (op_code
);
20768 else switch (op_code
)
20770 case DW_LNS_extended_op
:
20771 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20773 line_ptr
+= bytes_read
;
20774 extended_end
= line_ptr
+ extended_len
;
20775 extended_op
= read_1_byte (abfd
, line_ptr
);
20777 switch (extended_op
)
20779 case DW_LNE_end_sequence
:
20780 state_machine
.handle_end_sequence ();
20781 end_sequence
= true;
20783 case DW_LNE_set_address
:
20786 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
20787 line_ptr
+= bytes_read
;
20789 state_machine
.check_line_address (cu
, line_ptr
,
20791 state_machine
.handle_set_address (baseaddr
, address
);
20794 case DW_LNE_define_file
:
20796 const char *cur_file
;
20797 unsigned int mod_time
, length
;
20800 cur_file
= read_direct_string (abfd
, line_ptr
,
20802 line_ptr
+= bytes_read
;
20803 dindex
= (dir_index
)
20804 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20805 line_ptr
+= bytes_read
;
20807 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20808 line_ptr
+= bytes_read
;
20810 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20811 line_ptr
+= bytes_read
;
20812 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20815 case DW_LNE_set_discriminator
:
20817 /* The discriminator is not interesting to the
20818 debugger; just ignore it. We still need to
20819 check its value though:
20820 if there are consecutive entries for the same
20821 (non-prologue) line we want to coalesce them.
20824 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20825 line_ptr
+= bytes_read
;
20827 state_machine
.handle_set_discriminator (discr
);
20831 complaint (&symfile_complaints
,
20832 _("mangled .debug_line section"));
20835 /* Make sure that we parsed the extended op correctly. If e.g.
20836 we expected a different address size than the producer used,
20837 we may have read the wrong number of bytes. */
20838 if (line_ptr
!= extended_end
)
20840 complaint (&symfile_complaints
,
20841 _("mangled .debug_line section"));
20846 state_machine
.handle_copy ();
20848 case DW_LNS_advance_pc
:
20851 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20852 line_ptr
+= bytes_read
;
20854 state_machine
.handle_advance_pc (adjust
);
20857 case DW_LNS_advance_line
:
20860 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20861 line_ptr
+= bytes_read
;
20863 state_machine
.handle_advance_line (line_delta
);
20866 case DW_LNS_set_file
:
20868 file_name_index file
20869 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20871 line_ptr
+= bytes_read
;
20873 state_machine
.handle_set_file (file
);
20876 case DW_LNS_set_column
:
20877 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20878 line_ptr
+= bytes_read
;
20880 case DW_LNS_negate_stmt
:
20881 state_machine
.handle_negate_stmt ();
20883 case DW_LNS_set_basic_block
:
20885 /* Add to the address register of the state machine the
20886 address increment value corresponding to special opcode
20887 255. I.e., this value is scaled by the minimum
20888 instruction length since special opcode 255 would have
20889 scaled the increment. */
20890 case DW_LNS_const_add_pc
:
20891 state_machine
.handle_const_add_pc ();
20893 case DW_LNS_fixed_advance_pc
:
20895 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20898 state_machine
.handle_fixed_advance_pc (addr_adj
);
20903 /* Unknown standard opcode, ignore it. */
20906 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20908 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20909 line_ptr
+= bytes_read
;
20916 dwarf2_debug_line_missing_end_sequence_complaint ();
20918 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20919 in which case we still finish recording the last line). */
20920 state_machine
.record_line (true);
20924 /* Decode the Line Number Program (LNP) for the given line_header
20925 structure and CU. The actual information extracted and the type
20926 of structures created from the LNP depends on the value of PST.
20928 1. If PST is NULL, then this procedure uses the data from the program
20929 to create all necessary symbol tables, and their linetables.
20931 2. If PST is not NULL, this procedure reads the program to determine
20932 the list of files included by the unit represented by PST, and
20933 builds all the associated partial symbol tables.
20935 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20936 It is used for relative paths in the line table.
20937 NOTE: When processing partial symtabs (pst != NULL),
20938 comp_dir == pst->dirname.
20940 NOTE: It is important that psymtabs have the same file name (via strcmp)
20941 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20942 symtab we don't use it in the name of the psymtabs we create.
20943 E.g. expand_line_sal requires this when finding psymtabs to expand.
20944 A good testcase for this is mb-inline.exp.
20946 LOWPC is the lowest address in CU (or 0 if not known).
20948 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20949 for its PC<->lines mapping information. Otherwise only the filename
20950 table is read in. */
20953 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20954 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
20955 CORE_ADDR lowpc
, int decode_mapping
)
20957 struct objfile
*objfile
= cu
->objfile
;
20958 const int decode_for_pst_p
= (pst
!= NULL
);
20960 if (decode_mapping
)
20961 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20963 if (decode_for_pst_p
)
20967 /* Now that we're done scanning the Line Header Program, we can
20968 create the psymtab of each included file. */
20969 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
20970 if (lh
->file_names
[file_index
].included_p
== 1)
20972 const char *include_name
=
20973 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
20974 if (include_name
!= NULL
)
20975 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20980 /* Make sure a symtab is created for every file, even files
20981 which contain only variables (i.e. no code with associated
20983 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
20986 for (i
= 0; i
< lh
->file_names
.size (); i
++)
20988 file_entry
&fe
= lh
->file_names
[i
];
20990 dwarf2_start_subfile (fe
.name
, fe
.include_dir (lh
));
20992 if (current_subfile
->symtab
== NULL
)
20994 current_subfile
->symtab
20995 = allocate_symtab (cust
, current_subfile
->name
);
20997 fe
.symtab
= current_subfile
->symtab
;
21002 /* Start a subfile for DWARF. FILENAME is the name of the file and
21003 DIRNAME the name of the source directory which contains FILENAME
21004 or NULL if not known.
21005 This routine tries to keep line numbers from identical absolute and
21006 relative file names in a common subfile.
21008 Using the `list' example from the GDB testsuite, which resides in
21009 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21010 of /srcdir/list0.c yields the following debugging information for list0.c:
21012 DW_AT_name: /srcdir/list0.c
21013 DW_AT_comp_dir: /compdir
21014 files.files[0].name: list0.h
21015 files.files[0].dir: /srcdir
21016 files.files[1].name: list0.c
21017 files.files[1].dir: /srcdir
21019 The line number information for list0.c has to end up in a single
21020 subfile, so that `break /srcdir/list0.c:1' works as expected.
21021 start_subfile will ensure that this happens provided that we pass the
21022 concatenation of files.files[1].dir and files.files[1].name as the
21026 dwarf2_start_subfile (const char *filename
, const char *dirname
)
21030 /* In order not to lose the line information directory,
21031 we concatenate it to the filename when it makes sense.
21032 Note that the Dwarf3 standard says (speaking of filenames in line
21033 information): ``The directory index is ignored for file names
21034 that represent full path names''. Thus ignoring dirname in the
21035 `else' branch below isn't an issue. */
21037 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21039 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
21043 start_subfile (filename
);
21049 /* Start a symtab for DWARF.
21050 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
21052 static struct compunit_symtab
*
21053 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
21054 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
21056 struct compunit_symtab
*cust
21057 = start_symtab (cu
->objfile
, name
, comp_dir
, low_pc
, cu
->language
);
21059 record_debugformat ("DWARF 2");
21060 record_producer (cu
->producer
);
21062 /* We assume that we're processing GCC output. */
21063 processing_gcc_compilation
= 2;
21065 cu
->processing_has_namespace_info
= 0;
21071 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21072 struct dwarf2_cu
*cu
)
21074 struct objfile
*objfile
= cu
->objfile
;
21075 struct comp_unit_head
*cu_header
= &cu
->header
;
21077 /* NOTE drow/2003-01-30: There used to be a comment and some special
21078 code here to turn a symbol with DW_AT_external and a
21079 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21080 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21081 with some versions of binutils) where shared libraries could have
21082 relocations against symbols in their debug information - the
21083 minimal symbol would have the right address, but the debug info
21084 would not. It's no longer necessary, because we will explicitly
21085 apply relocations when we read in the debug information now. */
21087 /* A DW_AT_location attribute with no contents indicates that a
21088 variable has been optimized away. */
21089 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21091 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21095 /* Handle one degenerate form of location expression specially, to
21096 preserve GDB's previous behavior when section offsets are
21097 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
21098 then mark this symbol as LOC_STATIC. */
21100 if (attr_form_is_block (attr
)
21101 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21102 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21103 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21104 && (DW_BLOCK (attr
)->size
21105 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21107 unsigned int dummy
;
21109 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21110 SYMBOL_VALUE_ADDRESS (sym
) =
21111 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
21113 SYMBOL_VALUE_ADDRESS (sym
) =
21114 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
21115 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21116 fixup_symbol_section (sym
, objfile
);
21117 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
21118 SYMBOL_SECTION (sym
));
21122 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21123 expression evaluator, and use LOC_COMPUTED only when necessary
21124 (i.e. when the value of a register or memory location is
21125 referenced, or a thread-local block, etc.). Then again, it might
21126 not be worthwhile. I'm assuming that it isn't unless performance
21127 or memory numbers show me otherwise. */
21129 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21131 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21132 cu
->has_loclist
= 1;
21135 /* Given a pointer to a DWARF information entry, figure out if we need
21136 to make a symbol table entry for it, and if so, create a new entry
21137 and return a pointer to it.
21138 If TYPE is NULL, determine symbol type from the die, otherwise
21139 used the passed type.
21140 If SPACE is not NULL, use it to hold the new symbol. If it is
21141 NULL, allocate a new symbol on the objfile's obstack. */
21143 static struct symbol
*
21144 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21145 struct symbol
*space
)
21147 struct objfile
*objfile
= cu
->objfile
;
21148 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21149 struct symbol
*sym
= NULL
;
21151 struct attribute
*attr
= NULL
;
21152 struct attribute
*attr2
= NULL
;
21153 CORE_ADDR baseaddr
;
21154 struct pending
**list_to_add
= NULL
;
21156 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21158 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21160 name
= dwarf2_name (die
, cu
);
21163 const char *linkagename
;
21164 int suppress_add
= 0;
21169 sym
= allocate_symbol (objfile
);
21170 OBJSTAT (objfile
, n_syms
++);
21172 /* Cache this symbol's name and the name's demangled form (if any). */
21173 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
21174 linkagename
= dwarf2_physname (name
, die
, cu
);
21175 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
21177 /* Fortran does not have mangling standard and the mangling does differ
21178 between gfortran, iFort etc. */
21179 if (cu
->language
== language_fortran
21180 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
21181 symbol_set_demangled_name (&(sym
->ginfo
),
21182 dwarf2_full_name (name
, die
, cu
),
21185 /* Default assumptions.
21186 Use the passed type or decode it from the die. */
21187 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21188 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21190 SYMBOL_TYPE (sym
) = type
;
21192 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21193 attr
= dwarf2_attr (die
,
21194 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21198 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21201 attr
= dwarf2_attr (die
,
21202 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21206 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21207 struct file_entry
*fe
;
21209 if (cu
->line_header
!= NULL
)
21210 fe
= cu
->line_header
->file_name_at (file_index
);
21215 complaint (&symfile_complaints
,
21216 _("file index out of range"));
21218 symbol_set_symtab (sym
, fe
->symtab
);
21224 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21229 addr
= attr_value_as_address (attr
);
21230 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21231 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
21233 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21234 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21235 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21236 add_symbol_to_list (sym
, cu
->list_in_scope
);
21238 case DW_TAG_subprogram
:
21239 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21241 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21242 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21243 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21244 || cu
->language
== language_ada
)
21246 /* Subprograms marked external are stored as a global symbol.
21247 Ada subprograms, whether marked external or not, are always
21248 stored as a global symbol, because we want to be able to
21249 access them globally. For instance, we want to be able
21250 to break on a nested subprogram without having to
21251 specify the context. */
21252 list_to_add
= &global_symbols
;
21256 list_to_add
= cu
->list_in_scope
;
21259 case DW_TAG_inlined_subroutine
:
21260 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21262 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21263 SYMBOL_INLINED (sym
) = 1;
21264 list_to_add
= cu
->list_in_scope
;
21266 case DW_TAG_template_value_param
:
21268 /* Fall through. */
21269 case DW_TAG_constant
:
21270 case DW_TAG_variable
:
21271 case DW_TAG_member
:
21272 /* Compilation with minimal debug info may result in
21273 variables with missing type entries. Change the
21274 misleading `void' type to something sensible. */
21275 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21276 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21278 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21279 /* In the case of DW_TAG_member, we should only be called for
21280 static const members. */
21281 if (die
->tag
== DW_TAG_member
)
21283 /* dwarf2_add_field uses die_is_declaration,
21284 so we do the same. */
21285 gdb_assert (die_is_declaration (die
, cu
));
21290 dwarf2_const_value (attr
, sym
, cu
);
21291 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21294 if (attr2
&& (DW_UNSND (attr2
) != 0))
21295 list_to_add
= &global_symbols
;
21297 list_to_add
= cu
->list_in_scope
;
21301 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21304 var_decode_location (attr
, sym
, cu
);
21305 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21307 /* Fortran explicitly imports any global symbols to the local
21308 scope by DW_TAG_common_block. */
21309 if (cu
->language
== language_fortran
&& die
->parent
21310 && die
->parent
->tag
== DW_TAG_common_block
)
21313 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21314 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21315 && !dwarf2_per_objfile
->has_section_at_zero
)
21317 /* When a static variable is eliminated by the linker,
21318 the corresponding debug information is not stripped
21319 out, but the variable address is set to null;
21320 do not add such variables into symbol table. */
21322 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21324 /* Workaround gfortran PR debug/40040 - it uses
21325 DW_AT_location for variables in -fPIC libraries which may
21326 get overriden by other libraries/executable and get
21327 a different address. Resolve it by the minimal symbol
21328 which may come from inferior's executable using copy
21329 relocation. Make this workaround only for gfortran as for
21330 other compilers GDB cannot guess the minimal symbol
21331 Fortran mangling kind. */
21332 if (cu
->language
== language_fortran
&& die
->parent
21333 && die
->parent
->tag
== DW_TAG_module
21335 && startswith (cu
->producer
, "GNU Fortran"))
21336 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21338 /* A variable with DW_AT_external is never static,
21339 but it may be block-scoped. */
21340 list_to_add
= (cu
->list_in_scope
== &file_symbols
21341 ? &global_symbols
: cu
->list_in_scope
);
21344 list_to_add
= cu
->list_in_scope
;
21348 /* We do not know the address of this symbol.
21349 If it is an external symbol and we have type information
21350 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21351 The address of the variable will then be determined from
21352 the minimal symbol table whenever the variable is
21354 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21356 /* Fortran explicitly imports any global symbols to the local
21357 scope by DW_TAG_common_block. */
21358 if (cu
->language
== language_fortran
&& die
->parent
21359 && die
->parent
->tag
== DW_TAG_common_block
)
21361 /* SYMBOL_CLASS doesn't matter here because
21362 read_common_block is going to reset it. */
21364 list_to_add
= cu
->list_in_scope
;
21366 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21367 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21369 /* A variable with DW_AT_external is never static, but it
21370 may be block-scoped. */
21371 list_to_add
= (cu
->list_in_scope
== &file_symbols
21372 ? &global_symbols
: cu
->list_in_scope
);
21374 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21376 else if (!die_is_declaration (die
, cu
))
21378 /* Use the default LOC_OPTIMIZED_OUT class. */
21379 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21381 list_to_add
= cu
->list_in_scope
;
21385 case DW_TAG_formal_parameter
:
21386 /* If we are inside a function, mark this as an argument. If
21387 not, we might be looking at an argument to an inlined function
21388 when we do not have enough information to show inlined frames;
21389 pretend it's a local variable in that case so that the user can
21391 if (context_stack_depth
> 0
21392 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
21393 SYMBOL_IS_ARGUMENT (sym
) = 1;
21394 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21397 var_decode_location (attr
, sym
, cu
);
21399 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21402 dwarf2_const_value (attr
, sym
, cu
);
21405 list_to_add
= cu
->list_in_scope
;
21407 case DW_TAG_unspecified_parameters
:
21408 /* From varargs functions; gdb doesn't seem to have any
21409 interest in this information, so just ignore it for now.
21412 case DW_TAG_template_type_param
:
21414 /* Fall through. */
21415 case DW_TAG_class_type
:
21416 case DW_TAG_interface_type
:
21417 case DW_TAG_structure_type
:
21418 case DW_TAG_union_type
:
21419 case DW_TAG_set_type
:
21420 case DW_TAG_enumeration_type
:
21421 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21422 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21425 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21426 really ever be static objects: otherwise, if you try
21427 to, say, break of a class's method and you're in a file
21428 which doesn't mention that class, it won't work unless
21429 the check for all static symbols in lookup_symbol_aux
21430 saves you. See the OtherFileClass tests in
21431 gdb.c++/namespace.exp. */
21435 list_to_add
= (cu
->list_in_scope
== &file_symbols
21436 && cu
->language
== language_cplus
21437 ? &global_symbols
: cu
->list_in_scope
);
21439 /* The semantics of C++ state that "struct foo {
21440 ... }" also defines a typedef for "foo". */
21441 if (cu
->language
== language_cplus
21442 || cu
->language
== language_ada
21443 || cu
->language
== language_d
21444 || cu
->language
== language_rust
)
21446 /* The symbol's name is already allocated along
21447 with this objfile, so we don't need to
21448 duplicate it for the type. */
21449 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21450 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
21455 case DW_TAG_typedef
:
21456 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21457 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21458 list_to_add
= cu
->list_in_scope
;
21460 case DW_TAG_base_type
:
21461 case DW_TAG_subrange_type
:
21462 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21463 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21464 list_to_add
= cu
->list_in_scope
;
21466 case DW_TAG_enumerator
:
21467 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21470 dwarf2_const_value (attr
, sym
, cu
);
21473 /* NOTE: carlton/2003-11-10: See comment above in the
21474 DW_TAG_class_type, etc. block. */
21476 list_to_add
= (cu
->list_in_scope
== &file_symbols
21477 && cu
->language
== language_cplus
21478 ? &global_symbols
: cu
->list_in_scope
);
21481 case DW_TAG_imported_declaration
:
21482 case DW_TAG_namespace
:
21483 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21484 list_to_add
= &global_symbols
;
21486 case DW_TAG_module
:
21487 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21488 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21489 list_to_add
= &global_symbols
;
21491 case DW_TAG_common_block
:
21492 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21493 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21494 add_symbol_to_list (sym
, cu
->list_in_scope
);
21497 /* Not a tag we recognize. Hopefully we aren't processing
21498 trash data, but since we must specifically ignore things
21499 we don't recognize, there is nothing else we should do at
21501 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
21502 dwarf_tag_name (die
->tag
));
21508 sym
->hash_next
= objfile
->template_symbols
;
21509 objfile
->template_symbols
= sym
;
21510 list_to_add
= NULL
;
21513 if (list_to_add
!= NULL
)
21514 add_symbol_to_list (sym
, list_to_add
);
21516 /* For the benefit of old versions of GCC, check for anonymous
21517 namespaces based on the demangled name. */
21518 if (!cu
->processing_has_namespace_info
21519 && cu
->language
== language_cplus
)
21520 cp_scan_for_anonymous_namespaces (sym
, objfile
);
21525 /* A wrapper for new_symbol_full that always allocates a new symbol. */
21527 static struct symbol
*
21528 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
21530 return new_symbol_full (die
, type
, cu
, NULL
);
21533 /* Given an attr with a DW_FORM_dataN value in host byte order,
21534 zero-extend it as appropriate for the symbol's type. The DWARF
21535 standard (v4) is not entirely clear about the meaning of using
21536 DW_FORM_dataN for a constant with a signed type, where the type is
21537 wider than the data. The conclusion of a discussion on the DWARF
21538 list was that this is unspecified. We choose to always zero-extend
21539 because that is the interpretation long in use by GCC. */
21542 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21543 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21545 struct objfile
*objfile
= cu
->objfile
;
21546 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21547 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21548 LONGEST l
= DW_UNSND (attr
);
21550 if (bits
< sizeof (*value
) * 8)
21552 l
&= ((LONGEST
) 1 << bits
) - 1;
21555 else if (bits
== sizeof (*value
) * 8)
21559 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21560 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21567 /* Read a constant value from an attribute. Either set *VALUE, or if
21568 the value does not fit in *VALUE, set *BYTES - either already
21569 allocated on the objfile obstack, or newly allocated on OBSTACK,
21570 or, set *BATON, if we translated the constant to a location
21574 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21575 const char *name
, struct obstack
*obstack
,
21576 struct dwarf2_cu
*cu
,
21577 LONGEST
*value
, const gdb_byte
**bytes
,
21578 struct dwarf2_locexpr_baton
**baton
)
21580 struct objfile
*objfile
= cu
->objfile
;
21581 struct comp_unit_head
*cu_header
= &cu
->header
;
21582 struct dwarf_block
*blk
;
21583 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21584 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21590 switch (attr
->form
)
21593 case DW_FORM_GNU_addr_index
:
21597 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21598 dwarf2_const_value_length_mismatch_complaint (name
,
21599 cu_header
->addr_size
,
21600 TYPE_LENGTH (type
));
21601 /* Symbols of this form are reasonably rare, so we just
21602 piggyback on the existing location code rather than writing
21603 a new implementation of symbol_computed_ops. */
21604 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21605 (*baton
)->per_cu
= cu
->per_cu
;
21606 gdb_assert ((*baton
)->per_cu
);
21608 (*baton
)->size
= 2 + cu_header
->addr_size
;
21609 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21610 (*baton
)->data
= data
;
21612 data
[0] = DW_OP_addr
;
21613 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21614 byte_order
, DW_ADDR (attr
));
21615 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21618 case DW_FORM_string
:
21620 case DW_FORM_GNU_str_index
:
21621 case DW_FORM_GNU_strp_alt
:
21622 /* DW_STRING is already allocated on the objfile obstack, point
21624 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21626 case DW_FORM_block1
:
21627 case DW_FORM_block2
:
21628 case DW_FORM_block4
:
21629 case DW_FORM_block
:
21630 case DW_FORM_exprloc
:
21631 case DW_FORM_data16
:
21632 blk
= DW_BLOCK (attr
);
21633 if (TYPE_LENGTH (type
) != blk
->size
)
21634 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21635 TYPE_LENGTH (type
));
21636 *bytes
= blk
->data
;
21639 /* The DW_AT_const_value attributes are supposed to carry the
21640 symbol's value "represented as it would be on the target
21641 architecture." By the time we get here, it's already been
21642 converted to host endianness, so we just need to sign- or
21643 zero-extend it as appropriate. */
21644 case DW_FORM_data1
:
21645 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21647 case DW_FORM_data2
:
21648 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21650 case DW_FORM_data4
:
21651 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21653 case DW_FORM_data8
:
21654 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21657 case DW_FORM_sdata
:
21658 case DW_FORM_implicit_const
:
21659 *value
= DW_SND (attr
);
21662 case DW_FORM_udata
:
21663 *value
= DW_UNSND (attr
);
21667 complaint (&symfile_complaints
,
21668 _("unsupported const value attribute form: '%s'"),
21669 dwarf_form_name (attr
->form
));
21676 /* Copy constant value from an attribute to a symbol. */
21679 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21680 struct dwarf2_cu
*cu
)
21682 struct objfile
*objfile
= cu
->objfile
;
21684 const gdb_byte
*bytes
;
21685 struct dwarf2_locexpr_baton
*baton
;
21687 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21688 SYMBOL_PRINT_NAME (sym
),
21689 &objfile
->objfile_obstack
, cu
,
21690 &value
, &bytes
, &baton
);
21694 SYMBOL_LOCATION_BATON (sym
) = baton
;
21695 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21697 else if (bytes
!= NULL
)
21699 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21700 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21704 SYMBOL_VALUE (sym
) = value
;
21705 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21709 /* Return the type of the die in question using its DW_AT_type attribute. */
21711 static struct type
*
21712 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21714 struct attribute
*type_attr
;
21716 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21719 /* A missing DW_AT_type represents a void type. */
21720 return objfile_type (cu
->objfile
)->builtin_void
;
21723 return lookup_die_type (die
, type_attr
, cu
);
21726 /* True iff CU's producer generates GNAT Ada auxiliary information
21727 that allows to find parallel types through that information instead
21728 of having to do expensive parallel lookups by type name. */
21731 need_gnat_info (struct dwarf2_cu
*cu
)
21733 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
21734 of GNAT produces this auxiliary information, without any indication
21735 that it is produced. Part of enhancing the FSF version of GNAT
21736 to produce that information will be to put in place an indicator
21737 that we can use in order to determine whether the descriptive type
21738 info is available or not. One suggestion that has been made is
21739 to use a new attribute, attached to the CU die. For now, assume
21740 that the descriptive type info is not available. */
21744 /* Return the auxiliary type of the die in question using its
21745 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21746 attribute is not present. */
21748 static struct type
*
21749 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21751 struct attribute
*type_attr
;
21753 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21757 return lookup_die_type (die
, type_attr
, cu
);
21760 /* If DIE has a descriptive_type attribute, then set the TYPE's
21761 descriptive type accordingly. */
21764 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21765 struct dwarf2_cu
*cu
)
21767 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21769 if (descriptive_type
)
21771 ALLOCATE_GNAT_AUX_TYPE (type
);
21772 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21776 /* Return the containing type of the die in question using its
21777 DW_AT_containing_type attribute. */
21779 static struct type
*
21780 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21782 struct attribute
*type_attr
;
21784 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21786 error (_("Dwarf Error: Problem turning containing type into gdb type "
21787 "[in module %s]"), objfile_name (cu
->objfile
));
21789 return lookup_die_type (die
, type_attr
, cu
);
21792 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21794 static struct type
*
21795 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21797 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21798 char *message
, *saved
;
21800 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
21801 objfile_name (objfile
),
21802 to_underlying (cu
->header
.sect_off
),
21803 to_underlying (die
->sect_off
));
21804 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
21805 message
, strlen (message
));
21808 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21811 /* Look up the type of DIE in CU using its type attribute ATTR.
21812 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21813 DW_AT_containing_type.
21814 If there is no type substitute an error marker. */
21816 static struct type
*
21817 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21818 struct dwarf2_cu
*cu
)
21820 struct objfile
*objfile
= cu
->objfile
;
21821 struct type
*this_type
;
21823 gdb_assert (attr
->name
== DW_AT_type
21824 || attr
->name
== DW_AT_GNAT_descriptive_type
21825 || attr
->name
== DW_AT_containing_type
);
21827 /* First see if we have it cached. */
21829 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21831 struct dwarf2_per_cu_data
*per_cu
;
21832 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21834 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, cu
->objfile
);
21835 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21837 else if (attr_form_is_ref (attr
))
21839 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21841 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21843 else if (attr
->form
== DW_FORM_ref_sig8
)
21845 ULONGEST signature
= DW_SIGNATURE (attr
);
21847 return get_signatured_type (die
, signature
, cu
);
21851 complaint (&symfile_complaints
,
21852 _("Dwarf Error: Bad type attribute %s in DIE"
21853 " at 0x%x [in module %s]"),
21854 dwarf_attr_name (attr
->name
), to_underlying (die
->sect_off
),
21855 objfile_name (objfile
));
21856 return build_error_marker_type (cu
, die
);
21859 /* If not cached we need to read it in. */
21861 if (this_type
== NULL
)
21863 struct die_info
*type_die
= NULL
;
21864 struct dwarf2_cu
*type_cu
= cu
;
21866 if (attr_form_is_ref (attr
))
21867 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21868 if (type_die
== NULL
)
21869 return build_error_marker_type (cu
, die
);
21870 /* If we find the type now, it's probably because the type came
21871 from an inter-CU reference and the type's CU got expanded before
21873 this_type
= read_type_die (type_die
, type_cu
);
21876 /* If we still don't have a type use an error marker. */
21878 if (this_type
== NULL
)
21879 return build_error_marker_type (cu
, die
);
21884 /* Return the type in DIE, CU.
21885 Returns NULL for invalid types.
21887 This first does a lookup in die_type_hash,
21888 and only reads the die in if necessary.
21890 NOTE: This can be called when reading in partial or full symbols. */
21892 static struct type
*
21893 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21895 struct type
*this_type
;
21897 this_type
= get_die_type (die
, cu
);
21901 return read_type_die_1 (die
, cu
);
21904 /* Read the type in DIE, CU.
21905 Returns NULL for invalid types. */
21907 static struct type
*
21908 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21910 struct type
*this_type
= NULL
;
21914 case DW_TAG_class_type
:
21915 case DW_TAG_interface_type
:
21916 case DW_TAG_structure_type
:
21917 case DW_TAG_union_type
:
21918 this_type
= read_structure_type (die
, cu
);
21920 case DW_TAG_enumeration_type
:
21921 this_type
= read_enumeration_type (die
, cu
);
21923 case DW_TAG_subprogram
:
21924 case DW_TAG_subroutine_type
:
21925 case DW_TAG_inlined_subroutine
:
21926 this_type
= read_subroutine_type (die
, cu
);
21928 case DW_TAG_array_type
:
21929 this_type
= read_array_type (die
, cu
);
21931 case DW_TAG_set_type
:
21932 this_type
= read_set_type (die
, cu
);
21934 case DW_TAG_pointer_type
:
21935 this_type
= read_tag_pointer_type (die
, cu
);
21937 case DW_TAG_ptr_to_member_type
:
21938 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21940 case DW_TAG_reference_type
:
21941 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21943 case DW_TAG_rvalue_reference_type
:
21944 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21946 case DW_TAG_const_type
:
21947 this_type
= read_tag_const_type (die
, cu
);
21949 case DW_TAG_volatile_type
:
21950 this_type
= read_tag_volatile_type (die
, cu
);
21952 case DW_TAG_restrict_type
:
21953 this_type
= read_tag_restrict_type (die
, cu
);
21955 case DW_TAG_string_type
:
21956 this_type
= read_tag_string_type (die
, cu
);
21958 case DW_TAG_typedef
:
21959 this_type
= read_typedef (die
, cu
);
21961 case DW_TAG_subrange_type
:
21962 this_type
= read_subrange_type (die
, cu
);
21964 case DW_TAG_base_type
:
21965 this_type
= read_base_type (die
, cu
);
21967 case DW_TAG_unspecified_type
:
21968 this_type
= read_unspecified_type (die
, cu
);
21970 case DW_TAG_namespace
:
21971 this_type
= read_namespace_type (die
, cu
);
21973 case DW_TAG_module
:
21974 this_type
= read_module_type (die
, cu
);
21976 case DW_TAG_atomic_type
:
21977 this_type
= read_tag_atomic_type (die
, cu
);
21980 complaint (&symfile_complaints
,
21981 _("unexpected tag in read_type_die: '%s'"),
21982 dwarf_tag_name (die
->tag
));
21989 /* See if we can figure out if the class lives in a namespace. We do
21990 this by looking for a member function; its demangled name will
21991 contain namespace info, if there is any.
21992 Return the computed name or NULL.
21993 Space for the result is allocated on the objfile's obstack.
21994 This is the full-die version of guess_partial_die_structure_name.
21995 In this case we know DIE has no useful parent. */
21998 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22000 struct die_info
*spec_die
;
22001 struct dwarf2_cu
*spec_cu
;
22002 struct die_info
*child
;
22005 spec_die
= die_specification (die
, &spec_cu
);
22006 if (spec_die
!= NULL
)
22012 for (child
= die
->child
;
22014 child
= child
->sibling
)
22016 if (child
->tag
== DW_TAG_subprogram
)
22018 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22020 if (linkage_name
!= NULL
)
22023 = language_class_name_from_physname (cu
->language_defn
,
22027 if (actual_name
!= NULL
)
22029 const char *die_name
= dwarf2_name (die
, cu
);
22031 if (die_name
!= NULL
22032 && strcmp (die_name
, actual_name
) != 0)
22034 /* Strip off the class name from the full name.
22035 We want the prefix. */
22036 int die_name_len
= strlen (die_name
);
22037 int actual_name_len
= strlen (actual_name
);
22039 /* Test for '::' as a sanity check. */
22040 if (actual_name_len
> die_name_len
+ 2
22041 && actual_name
[actual_name_len
22042 - die_name_len
- 1] == ':')
22043 name
= (char *) obstack_copy0 (
22044 &cu
->objfile
->per_bfd
->storage_obstack
,
22045 actual_name
, actual_name_len
- die_name_len
- 2);
22048 xfree (actual_name
);
22057 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22058 prefix part in such case. See
22059 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22061 static const char *
22062 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22064 struct attribute
*attr
;
22067 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22068 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22071 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22074 attr
= dw2_linkage_name_attr (die
, cu
);
22075 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22078 /* dwarf2_name had to be already called. */
22079 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22081 /* Strip the base name, keep any leading namespaces/classes. */
22082 base
= strrchr (DW_STRING (attr
), ':');
22083 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22086 return (char *) obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
22088 &base
[-1] - DW_STRING (attr
));
22091 /* Return the name of the namespace/class that DIE is defined within,
22092 or "" if we can't tell. The caller should not xfree the result.
22094 For example, if we're within the method foo() in the following
22104 then determine_prefix on foo's die will return "N::C". */
22106 static const char *
22107 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22109 struct die_info
*parent
, *spec_die
;
22110 struct dwarf2_cu
*spec_cu
;
22111 struct type
*parent_type
;
22112 const char *retval
;
22114 if (cu
->language
!= language_cplus
22115 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22116 && cu
->language
!= language_rust
)
22119 retval
= anonymous_struct_prefix (die
, cu
);
22123 /* We have to be careful in the presence of DW_AT_specification.
22124 For example, with GCC 3.4, given the code
22128 // Definition of N::foo.
22132 then we'll have a tree of DIEs like this:
22134 1: DW_TAG_compile_unit
22135 2: DW_TAG_namespace // N
22136 3: DW_TAG_subprogram // declaration of N::foo
22137 4: DW_TAG_subprogram // definition of N::foo
22138 DW_AT_specification // refers to die #3
22140 Thus, when processing die #4, we have to pretend that we're in
22141 the context of its DW_AT_specification, namely the contex of die
22144 spec_die
= die_specification (die
, &spec_cu
);
22145 if (spec_die
== NULL
)
22146 parent
= die
->parent
;
22149 parent
= spec_die
->parent
;
22153 if (parent
== NULL
)
22155 else if (parent
->building_fullname
)
22158 const char *parent_name
;
22160 /* It has been seen on RealView 2.2 built binaries,
22161 DW_TAG_template_type_param types actually _defined_ as
22162 children of the parent class:
22165 template class <class Enum> Class{};
22166 Class<enum E> class_e;
22168 1: DW_TAG_class_type (Class)
22169 2: DW_TAG_enumeration_type (E)
22170 3: DW_TAG_enumerator (enum1:0)
22171 3: DW_TAG_enumerator (enum2:1)
22173 2: DW_TAG_template_type_param
22174 DW_AT_type DW_FORM_ref_udata (E)
22176 Besides being broken debug info, it can put GDB into an
22177 infinite loop. Consider:
22179 When we're building the full name for Class<E>, we'll start
22180 at Class, and go look over its template type parameters,
22181 finding E. We'll then try to build the full name of E, and
22182 reach here. We're now trying to build the full name of E,
22183 and look over the parent DIE for containing scope. In the
22184 broken case, if we followed the parent DIE of E, we'd again
22185 find Class, and once again go look at its template type
22186 arguments, etc., etc. Simply don't consider such parent die
22187 as source-level parent of this die (it can't be, the language
22188 doesn't allow it), and break the loop here. */
22189 name
= dwarf2_name (die
, cu
);
22190 parent_name
= dwarf2_name (parent
, cu
);
22191 complaint (&symfile_complaints
,
22192 _("template param type '%s' defined within parent '%s'"),
22193 name
? name
: "<unknown>",
22194 parent_name
? parent_name
: "<unknown>");
22198 switch (parent
->tag
)
22200 case DW_TAG_namespace
:
22201 parent_type
= read_type_die (parent
, cu
);
22202 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22203 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22204 Work around this problem here. */
22205 if (cu
->language
== language_cplus
22206 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
22208 /* We give a name to even anonymous namespaces. */
22209 return TYPE_TAG_NAME (parent_type
);
22210 case DW_TAG_class_type
:
22211 case DW_TAG_interface_type
:
22212 case DW_TAG_structure_type
:
22213 case DW_TAG_union_type
:
22214 case DW_TAG_module
:
22215 parent_type
= read_type_die (parent
, cu
);
22216 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22217 return TYPE_TAG_NAME (parent_type
);
22219 /* An anonymous structure is only allowed non-static data
22220 members; no typedefs, no member functions, et cetera.
22221 So it does not need a prefix. */
22223 case DW_TAG_compile_unit
:
22224 case DW_TAG_partial_unit
:
22225 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22226 if (cu
->language
== language_cplus
22227 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
22228 && die
->child
!= NULL
22229 && (die
->tag
== DW_TAG_class_type
22230 || die
->tag
== DW_TAG_structure_type
22231 || die
->tag
== DW_TAG_union_type
))
22233 char *name
= guess_full_die_structure_name (die
, cu
);
22238 case DW_TAG_enumeration_type
:
22239 parent_type
= read_type_die (parent
, cu
);
22240 if (TYPE_DECLARED_CLASS (parent_type
))
22242 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22243 return TYPE_TAG_NAME (parent_type
);
22246 /* Fall through. */
22248 return determine_prefix (parent
, cu
);
22252 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22253 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22254 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22255 an obconcat, otherwise allocate storage for the result. The CU argument is
22256 used to determine the language and hence, the appropriate separator. */
22258 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22261 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22262 int physname
, struct dwarf2_cu
*cu
)
22264 const char *lead
= "";
22267 if (suffix
== NULL
|| suffix
[0] == '\0'
22268 || prefix
== NULL
|| prefix
[0] == '\0')
22270 else if (cu
->language
== language_d
)
22272 /* For D, the 'main' function could be defined in any module, but it
22273 should never be prefixed. */
22274 if (strcmp (suffix
, "D main") == 0)
22282 else if (cu
->language
== language_fortran
&& physname
)
22284 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22285 DW_AT_MIPS_linkage_name is preferred and used instead. */
22293 if (prefix
== NULL
)
22295 if (suffix
== NULL
)
22302 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22304 strcpy (retval
, lead
);
22305 strcat (retval
, prefix
);
22306 strcat (retval
, sep
);
22307 strcat (retval
, suffix
);
22312 /* We have an obstack. */
22313 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22317 /* Return sibling of die, NULL if no sibling. */
22319 static struct die_info
*
22320 sibling_die (struct die_info
*die
)
22322 return die
->sibling
;
22325 /* Get name of a die, return NULL if not found. */
22327 static const char *
22328 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22329 struct obstack
*obstack
)
22331 if (name
&& cu
->language
== language_cplus
)
22333 std::string canon_name
= cp_canonicalize_string (name
);
22335 if (!canon_name
.empty ())
22337 if (canon_name
!= name
)
22338 name
= (const char *) obstack_copy0 (obstack
,
22339 canon_name
.c_str (),
22340 canon_name
.length ());
22347 /* Get name of a die, return NULL if not found.
22348 Anonymous namespaces are converted to their magic string. */
22350 static const char *
22351 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22353 struct attribute
*attr
;
22355 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22356 if ((!attr
|| !DW_STRING (attr
))
22357 && die
->tag
!= DW_TAG_namespace
22358 && die
->tag
!= DW_TAG_class_type
22359 && die
->tag
!= DW_TAG_interface_type
22360 && die
->tag
!= DW_TAG_structure_type
22361 && die
->tag
!= DW_TAG_union_type
)
22366 case DW_TAG_compile_unit
:
22367 case DW_TAG_partial_unit
:
22368 /* Compilation units have a DW_AT_name that is a filename, not
22369 a source language identifier. */
22370 case DW_TAG_enumeration_type
:
22371 case DW_TAG_enumerator
:
22372 /* These tags always have simple identifiers already; no need
22373 to canonicalize them. */
22374 return DW_STRING (attr
);
22376 case DW_TAG_namespace
:
22377 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22378 return DW_STRING (attr
);
22379 return CP_ANONYMOUS_NAMESPACE_STR
;
22381 case DW_TAG_class_type
:
22382 case DW_TAG_interface_type
:
22383 case DW_TAG_structure_type
:
22384 case DW_TAG_union_type
:
22385 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22386 structures or unions. These were of the form "._%d" in GCC 4.1,
22387 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22388 and GCC 4.4. We work around this problem by ignoring these. */
22389 if (attr
&& DW_STRING (attr
)
22390 && (startswith (DW_STRING (attr
), "._")
22391 || startswith (DW_STRING (attr
), "<anonymous")))
22394 /* GCC might emit a nameless typedef that has a linkage name. See
22395 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22396 if (!attr
|| DW_STRING (attr
) == NULL
)
22398 char *demangled
= NULL
;
22400 attr
= dw2_linkage_name_attr (die
, cu
);
22401 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22404 /* Avoid demangling DW_STRING (attr) the second time on a second
22405 call for the same DIE. */
22406 if (!DW_STRING_IS_CANONICAL (attr
))
22407 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
22413 /* FIXME: we already did this for the partial symbol... */
22416 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
22417 demangled
, strlen (demangled
)));
22418 DW_STRING_IS_CANONICAL (attr
) = 1;
22421 /* Strip any leading namespaces/classes, keep only the base name.
22422 DW_AT_name for named DIEs does not contain the prefixes. */
22423 base
= strrchr (DW_STRING (attr
), ':');
22424 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22427 return DW_STRING (attr
);
22436 if (!DW_STRING_IS_CANONICAL (attr
))
22439 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22440 &cu
->objfile
->per_bfd
->storage_obstack
);
22441 DW_STRING_IS_CANONICAL (attr
) = 1;
22443 return DW_STRING (attr
);
22446 /* Return the die that this die in an extension of, or NULL if there
22447 is none. *EXT_CU is the CU containing DIE on input, and the CU
22448 containing the return value on output. */
22450 static struct die_info
*
22451 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22453 struct attribute
*attr
;
22455 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22459 return follow_die_ref (die
, attr
, ext_cu
);
22462 /* Convert a DIE tag into its string name. */
22464 static const char *
22465 dwarf_tag_name (unsigned tag
)
22467 const char *name
= get_DW_TAG_name (tag
);
22470 return "DW_TAG_<unknown>";
22475 /* Convert a DWARF attribute code into its string name. */
22477 static const char *
22478 dwarf_attr_name (unsigned attr
)
22482 #ifdef MIPS /* collides with DW_AT_HP_block_index */
22483 if (attr
== DW_AT_MIPS_fde
)
22484 return "DW_AT_MIPS_fde";
22486 if (attr
== DW_AT_HP_block_index
)
22487 return "DW_AT_HP_block_index";
22490 name
= get_DW_AT_name (attr
);
22493 return "DW_AT_<unknown>";
22498 /* Convert a DWARF value form code into its string name. */
22500 static const char *
22501 dwarf_form_name (unsigned form
)
22503 const char *name
= get_DW_FORM_name (form
);
22506 return "DW_FORM_<unknown>";
22511 static const char *
22512 dwarf_bool_name (unsigned mybool
)
22520 /* Convert a DWARF type code into its string name. */
22522 static const char *
22523 dwarf_type_encoding_name (unsigned enc
)
22525 const char *name
= get_DW_ATE_name (enc
);
22528 return "DW_ATE_<unknown>";
22534 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22538 print_spaces (indent
, f
);
22539 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
22540 dwarf_tag_name (die
->tag
), die
->abbrev
,
22541 to_underlying (die
->sect_off
));
22543 if (die
->parent
!= NULL
)
22545 print_spaces (indent
, f
);
22546 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
22547 to_underlying (die
->parent
->sect_off
));
22550 print_spaces (indent
, f
);
22551 fprintf_unfiltered (f
, " has children: %s\n",
22552 dwarf_bool_name (die
->child
!= NULL
));
22554 print_spaces (indent
, f
);
22555 fprintf_unfiltered (f
, " attributes:\n");
22557 for (i
= 0; i
< die
->num_attrs
; ++i
)
22559 print_spaces (indent
, f
);
22560 fprintf_unfiltered (f
, " %s (%s) ",
22561 dwarf_attr_name (die
->attrs
[i
].name
),
22562 dwarf_form_name (die
->attrs
[i
].form
));
22564 switch (die
->attrs
[i
].form
)
22567 case DW_FORM_GNU_addr_index
:
22568 fprintf_unfiltered (f
, "address: ");
22569 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22571 case DW_FORM_block2
:
22572 case DW_FORM_block4
:
22573 case DW_FORM_block
:
22574 case DW_FORM_block1
:
22575 fprintf_unfiltered (f
, "block: size %s",
22576 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22578 case DW_FORM_exprloc
:
22579 fprintf_unfiltered (f
, "expression: size %s",
22580 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22582 case DW_FORM_data16
:
22583 fprintf_unfiltered (f
, "constant of 16 bytes");
22585 case DW_FORM_ref_addr
:
22586 fprintf_unfiltered (f
, "ref address: ");
22587 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22589 case DW_FORM_GNU_ref_alt
:
22590 fprintf_unfiltered (f
, "alt ref address: ");
22591 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22597 case DW_FORM_ref_udata
:
22598 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22599 (long) (DW_UNSND (&die
->attrs
[i
])));
22601 case DW_FORM_data1
:
22602 case DW_FORM_data2
:
22603 case DW_FORM_data4
:
22604 case DW_FORM_data8
:
22605 case DW_FORM_udata
:
22606 case DW_FORM_sdata
:
22607 fprintf_unfiltered (f
, "constant: %s",
22608 pulongest (DW_UNSND (&die
->attrs
[i
])));
22610 case DW_FORM_sec_offset
:
22611 fprintf_unfiltered (f
, "section offset: %s",
22612 pulongest (DW_UNSND (&die
->attrs
[i
])));
22614 case DW_FORM_ref_sig8
:
22615 fprintf_unfiltered (f
, "signature: %s",
22616 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22618 case DW_FORM_string
:
22620 case DW_FORM_line_strp
:
22621 case DW_FORM_GNU_str_index
:
22622 case DW_FORM_GNU_strp_alt
:
22623 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22624 DW_STRING (&die
->attrs
[i
])
22625 ? DW_STRING (&die
->attrs
[i
]) : "",
22626 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22629 if (DW_UNSND (&die
->attrs
[i
]))
22630 fprintf_unfiltered (f
, "flag: TRUE");
22632 fprintf_unfiltered (f
, "flag: FALSE");
22634 case DW_FORM_flag_present
:
22635 fprintf_unfiltered (f
, "flag: TRUE");
22637 case DW_FORM_indirect
:
22638 /* The reader will have reduced the indirect form to
22639 the "base form" so this form should not occur. */
22640 fprintf_unfiltered (f
,
22641 "unexpected attribute form: DW_FORM_indirect");
22643 case DW_FORM_implicit_const
:
22644 fprintf_unfiltered (f
, "constant: %s",
22645 plongest (DW_SND (&die
->attrs
[i
])));
22648 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22649 die
->attrs
[i
].form
);
22652 fprintf_unfiltered (f
, "\n");
22657 dump_die_for_error (struct die_info
*die
)
22659 dump_die_shallow (gdb_stderr
, 0, die
);
22663 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22665 int indent
= level
* 4;
22667 gdb_assert (die
!= NULL
);
22669 if (level
>= max_level
)
22672 dump_die_shallow (f
, indent
, die
);
22674 if (die
->child
!= NULL
)
22676 print_spaces (indent
, f
);
22677 fprintf_unfiltered (f
, " Children:");
22678 if (level
+ 1 < max_level
)
22680 fprintf_unfiltered (f
, "\n");
22681 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22685 fprintf_unfiltered (f
,
22686 " [not printed, max nesting level reached]\n");
22690 if (die
->sibling
!= NULL
&& level
> 0)
22692 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22696 /* This is called from the pdie macro in gdbinit.in.
22697 It's not static so gcc will keep a copy callable from gdb. */
22700 dump_die (struct die_info
*die
, int max_level
)
22702 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22706 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22710 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22711 to_underlying (die
->sect_off
),
22717 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22721 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22723 if (attr_form_is_ref (attr
))
22724 return (sect_offset
) DW_UNSND (attr
);
22726 complaint (&symfile_complaints
,
22727 _("unsupported die ref attribute form: '%s'"),
22728 dwarf_form_name (attr
->form
));
22732 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22733 * the value held by the attribute is not constant. */
22736 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22738 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22739 return DW_SND (attr
);
22740 else if (attr
->form
== DW_FORM_udata
22741 || attr
->form
== DW_FORM_data1
22742 || attr
->form
== DW_FORM_data2
22743 || attr
->form
== DW_FORM_data4
22744 || attr
->form
== DW_FORM_data8
)
22745 return DW_UNSND (attr
);
22748 /* For DW_FORM_data16 see attr_form_is_constant. */
22749 complaint (&symfile_complaints
,
22750 _("Attribute value is not a constant (%s)"),
22751 dwarf_form_name (attr
->form
));
22752 return default_value
;
22756 /* Follow reference or signature attribute ATTR of SRC_DIE.
22757 On entry *REF_CU is the CU of SRC_DIE.
22758 On exit *REF_CU is the CU of the result. */
22760 static struct die_info
*
22761 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22762 struct dwarf2_cu
**ref_cu
)
22764 struct die_info
*die
;
22766 if (attr_form_is_ref (attr
))
22767 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22768 else if (attr
->form
== DW_FORM_ref_sig8
)
22769 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22772 dump_die_for_error (src_die
);
22773 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22774 objfile_name ((*ref_cu
)->objfile
));
22780 /* Follow reference OFFSET.
22781 On entry *REF_CU is the CU of the source die referencing OFFSET.
22782 On exit *REF_CU is the CU of the result.
22783 Returns NULL if OFFSET is invalid. */
22785 static struct die_info
*
22786 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22787 struct dwarf2_cu
**ref_cu
)
22789 struct die_info temp_die
;
22790 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22792 gdb_assert (cu
->per_cu
!= NULL
);
22796 if (cu
->per_cu
->is_debug_types
)
22798 /* .debug_types CUs cannot reference anything outside their CU.
22799 If they need to, they have to reference a signatured type via
22800 DW_FORM_ref_sig8. */
22801 if (!offset_in_cu_p (&cu
->header
, sect_off
))
22804 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22805 || !offset_in_cu_p (&cu
->header
, sect_off
))
22807 struct dwarf2_per_cu_data
*per_cu
;
22809 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22812 /* If necessary, add it to the queue and load its DIEs. */
22813 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22814 load_full_comp_unit (per_cu
, cu
->language
);
22816 target_cu
= per_cu
->cu
;
22818 else if (cu
->dies
== NULL
)
22820 /* We're loading full DIEs during partial symbol reading. */
22821 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22822 load_full_comp_unit (cu
->per_cu
, language_minimal
);
22825 *ref_cu
= target_cu
;
22826 temp_die
.sect_off
= sect_off
;
22827 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22829 to_underlying (sect_off
));
22832 /* Follow reference attribute ATTR of SRC_DIE.
22833 On entry *REF_CU is the CU of SRC_DIE.
22834 On exit *REF_CU is the CU of the result. */
22836 static struct die_info
*
22837 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22838 struct dwarf2_cu
**ref_cu
)
22840 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22841 struct dwarf2_cu
*cu
= *ref_cu
;
22842 struct die_info
*die
;
22844 die
= follow_die_offset (sect_off
,
22845 (attr
->form
== DW_FORM_GNU_ref_alt
22846 || cu
->per_cu
->is_dwz
),
22849 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
22850 "at 0x%x [in module %s]"),
22851 to_underlying (sect_off
), to_underlying (src_die
->sect_off
),
22852 objfile_name (cu
->objfile
));
22857 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
22858 Returned value is intended for DW_OP_call*. Returned
22859 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
22861 struct dwarf2_locexpr_baton
22862 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22863 struct dwarf2_per_cu_data
*per_cu
,
22864 CORE_ADDR (*get_frame_pc
) (void *baton
),
22867 struct dwarf2_cu
*cu
;
22868 struct die_info
*die
;
22869 struct attribute
*attr
;
22870 struct dwarf2_locexpr_baton retval
;
22872 dw2_setup (per_cu
->objfile
);
22874 if (per_cu
->cu
== NULL
)
22879 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22880 Instead just throw an error, not much else we can do. */
22881 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
22882 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
22885 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22887 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
22888 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
22890 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22893 /* DWARF: "If there is no such attribute, then there is no effect.".
22894 DATA is ignored if SIZE is 0. */
22896 retval
.data
= NULL
;
22899 else if (attr_form_is_section_offset (attr
))
22901 struct dwarf2_loclist_baton loclist_baton
;
22902 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22905 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22907 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22909 retval
.size
= size
;
22913 if (!attr_form_is_block (attr
))
22914 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
22915 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22916 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
22918 retval
.data
= DW_BLOCK (attr
)->data
;
22919 retval
.size
= DW_BLOCK (attr
)->size
;
22921 retval
.per_cu
= cu
->per_cu
;
22923 age_cached_comp_units ();
22928 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
22931 struct dwarf2_locexpr_baton
22932 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22933 struct dwarf2_per_cu_data
*per_cu
,
22934 CORE_ADDR (*get_frame_pc
) (void *baton
),
22937 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22939 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
22942 /* Write a constant of a given type as target-ordered bytes into
22945 static const gdb_byte
*
22946 write_constant_as_bytes (struct obstack
*obstack
,
22947 enum bfd_endian byte_order
,
22954 *len
= TYPE_LENGTH (type
);
22955 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22956 store_unsigned_integer (result
, *len
, byte_order
, value
);
22961 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
22962 pointer to the constant bytes and set LEN to the length of the
22963 data. If memory is needed, allocate it on OBSTACK. If the DIE
22964 does not have a DW_AT_const_value, return NULL. */
22967 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22968 struct dwarf2_per_cu_data
*per_cu
,
22969 struct obstack
*obstack
,
22972 struct dwarf2_cu
*cu
;
22973 struct die_info
*die
;
22974 struct attribute
*attr
;
22975 const gdb_byte
*result
= NULL
;
22978 enum bfd_endian byte_order
;
22980 dw2_setup (per_cu
->objfile
);
22982 if (per_cu
->cu
== NULL
)
22987 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22988 Instead just throw an error, not much else we can do. */
22989 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
22990 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
22993 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22995 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
22996 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
22999 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23003 byte_order
= (bfd_big_endian (per_cu
->objfile
->obfd
)
23004 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23006 switch (attr
->form
)
23009 case DW_FORM_GNU_addr_index
:
23013 *len
= cu
->header
.addr_size
;
23014 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23015 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23019 case DW_FORM_string
:
23021 case DW_FORM_GNU_str_index
:
23022 case DW_FORM_GNU_strp_alt
:
23023 /* DW_STRING is already allocated on the objfile obstack, point
23025 result
= (const gdb_byte
*) DW_STRING (attr
);
23026 *len
= strlen (DW_STRING (attr
));
23028 case DW_FORM_block1
:
23029 case DW_FORM_block2
:
23030 case DW_FORM_block4
:
23031 case DW_FORM_block
:
23032 case DW_FORM_exprloc
:
23033 case DW_FORM_data16
:
23034 result
= DW_BLOCK (attr
)->data
;
23035 *len
= DW_BLOCK (attr
)->size
;
23038 /* The DW_AT_const_value attributes are supposed to carry the
23039 symbol's value "represented as it would be on the target
23040 architecture." By the time we get here, it's already been
23041 converted to host endianness, so we just need to sign- or
23042 zero-extend it as appropriate. */
23043 case DW_FORM_data1
:
23044 type
= die_type (die
, cu
);
23045 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23046 if (result
== NULL
)
23047 result
= write_constant_as_bytes (obstack
, byte_order
,
23050 case DW_FORM_data2
:
23051 type
= die_type (die
, cu
);
23052 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23053 if (result
== NULL
)
23054 result
= write_constant_as_bytes (obstack
, byte_order
,
23057 case DW_FORM_data4
:
23058 type
= die_type (die
, cu
);
23059 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23060 if (result
== NULL
)
23061 result
= write_constant_as_bytes (obstack
, byte_order
,
23064 case DW_FORM_data8
:
23065 type
= die_type (die
, cu
);
23066 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23067 if (result
== NULL
)
23068 result
= write_constant_as_bytes (obstack
, byte_order
,
23072 case DW_FORM_sdata
:
23073 case DW_FORM_implicit_const
:
23074 type
= die_type (die
, cu
);
23075 result
= write_constant_as_bytes (obstack
, byte_order
,
23076 type
, DW_SND (attr
), len
);
23079 case DW_FORM_udata
:
23080 type
= die_type (die
, cu
);
23081 result
= write_constant_as_bytes (obstack
, byte_order
,
23082 type
, DW_UNSND (attr
), len
);
23086 complaint (&symfile_complaints
,
23087 _("unsupported const value attribute form: '%s'"),
23088 dwarf_form_name (attr
->form
));
23095 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23096 valid type for this die is found. */
23099 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23100 struct dwarf2_per_cu_data
*per_cu
)
23102 struct dwarf2_cu
*cu
;
23103 struct die_info
*die
;
23105 dw2_setup (per_cu
->objfile
);
23107 if (per_cu
->cu
== NULL
)
23113 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23117 return die_type (die
, cu
);
23120 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23124 dwarf2_get_die_type (cu_offset die_offset
,
23125 struct dwarf2_per_cu_data
*per_cu
)
23127 dw2_setup (per_cu
->objfile
);
23129 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23130 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23133 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23134 On entry *REF_CU is the CU of SRC_DIE.
23135 On exit *REF_CU is the CU of the result.
23136 Returns NULL if the referenced DIE isn't found. */
23138 static struct die_info
*
23139 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23140 struct dwarf2_cu
**ref_cu
)
23142 struct die_info temp_die
;
23143 struct dwarf2_cu
*sig_cu
;
23144 struct die_info
*die
;
23146 /* While it might be nice to assert sig_type->type == NULL here,
23147 we can get here for DW_AT_imported_declaration where we need
23148 the DIE not the type. */
23150 /* If necessary, add it to the queue and load its DIEs. */
23152 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23153 read_signatured_type (sig_type
);
23155 sig_cu
= sig_type
->per_cu
.cu
;
23156 gdb_assert (sig_cu
!= NULL
);
23157 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23158 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23159 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23160 to_underlying (temp_die
.sect_off
));
23163 /* For .gdb_index version 7 keep track of included TUs.
23164 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23165 if (dwarf2_per_objfile
->index_table
!= NULL
23166 && dwarf2_per_objfile
->index_table
->version
<= 7)
23168 VEC_safe_push (dwarf2_per_cu_ptr
,
23169 (*ref_cu
)->per_cu
->imported_symtabs
,
23180 /* Follow signatured type referenced by ATTR in SRC_DIE.
23181 On entry *REF_CU is the CU of SRC_DIE.
23182 On exit *REF_CU is the CU of the result.
23183 The result is the DIE of the type.
23184 If the referenced type cannot be found an error is thrown. */
23186 static struct die_info
*
23187 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23188 struct dwarf2_cu
**ref_cu
)
23190 ULONGEST signature
= DW_SIGNATURE (attr
);
23191 struct signatured_type
*sig_type
;
23192 struct die_info
*die
;
23194 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23196 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23197 /* sig_type will be NULL if the signatured type is missing from
23199 if (sig_type
== NULL
)
23201 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23202 " from DIE at 0x%x [in module %s]"),
23203 hex_string (signature
), to_underlying (src_die
->sect_off
),
23204 objfile_name ((*ref_cu
)->objfile
));
23207 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23210 dump_die_for_error (src_die
);
23211 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23212 " from DIE at 0x%x [in module %s]"),
23213 hex_string (signature
), to_underlying (src_die
->sect_off
),
23214 objfile_name ((*ref_cu
)->objfile
));
23220 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23221 reading in and processing the type unit if necessary. */
23223 static struct type
*
23224 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23225 struct dwarf2_cu
*cu
)
23227 struct signatured_type
*sig_type
;
23228 struct dwarf2_cu
*type_cu
;
23229 struct die_info
*type_die
;
23232 sig_type
= lookup_signatured_type (cu
, signature
);
23233 /* sig_type will be NULL if the signatured type is missing from
23235 if (sig_type
== NULL
)
23237 complaint (&symfile_complaints
,
23238 _("Dwarf Error: Cannot find signatured DIE %s referenced"
23239 " from DIE at 0x%x [in module %s]"),
23240 hex_string (signature
), to_underlying (die
->sect_off
),
23241 objfile_name (dwarf2_per_objfile
->objfile
));
23242 return build_error_marker_type (cu
, die
);
23245 /* If we already know the type we're done. */
23246 if (sig_type
->type
!= NULL
)
23247 return sig_type
->type
;
23250 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23251 if (type_die
!= NULL
)
23253 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23254 is created. This is important, for example, because for c++ classes
23255 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23256 type
= read_type_die (type_die
, type_cu
);
23259 complaint (&symfile_complaints
,
23260 _("Dwarf Error: Cannot build signatured type %s"
23261 " referenced from DIE at 0x%x [in module %s]"),
23262 hex_string (signature
), to_underlying (die
->sect_off
),
23263 objfile_name (dwarf2_per_objfile
->objfile
));
23264 type
= build_error_marker_type (cu
, die
);
23269 complaint (&symfile_complaints
,
23270 _("Dwarf Error: Problem reading signatured DIE %s referenced"
23271 " from DIE at 0x%x [in module %s]"),
23272 hex_string (signature
), to_underlying (die
->sect_off
),
23273 objfile_name (dwarf2_per_objfile
->objfile
));
23274 type
= build_error_marker_type (cu
, die
);
23276 sig_type
->type
= type
;
23281 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23282 reading in and processing the type unit if necessary. */
23284 static struct type
*
23285 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23286 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23288 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23289 if (attr_form_is_ref (attr
))
23291 struct dwarf2_cu
*type_cu
= cu
;
23292 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23294 return read_type_die (type_die
, type_cu
);
23296 else if (attr
->form
== DW_FORM_ref_sig8
)
23298 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23302 complaint (&symfile_complaints
,
23303 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23304 " at 0x%x [in module %s]"),
23305 dwarf_form_name (attr
->form
), to_underlying (die
->sect_off
),
23306 objfile_name (dwarf2_per_objfile
->objfile
));
23307 return build_error_marker_type (cu
, die
);
23311 /* Load the DIEs associated with type unit PER_CU into memory. */
23314 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23316 struct signatured_type
*sig_type
;
23318 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23319 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23321 /* We have the per_cu, but we need the signatured_type.
23322 Fortunately this is an easy translation. */
23323 gdb_assert (per_cu
->is_debug_types
);
23324 sig_type
= (struct signatured_type
*) per_cu
;
23326 gdb_assert (per_cu
->cu
== NULL
);
23328 read_signatured_type (sig_type
);
23330 gdb_assert (per_cu
->cu
!= NULL
);
23333 /* die_reader_func for read_signatured_type.
23334 This is identical to load_full_comp_unit_reader,
23335 but is kept separate for now. */
23338 read_signatured_type_reader (const struct die_reader_specs
*reader
,
23339 const gdb_byte
*info_ptr
,
23340 struct die_info
*comp_unit_die
,
23344 struct dwarf2_cu
*cu
= reader
->cu
;
23346 gdb_assert (cu
->die_hash
== NULL
);
23348 htab_create_alloc_ex (cu
->header
.length
/ 12,
23352 &cu
->comp_unit_obstack
,
23353 hashtab_obstack_allocate
,
23354 dummy_obstack_deallocate
);
23357 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
23358 &info_ptr
, comp_unit_die
);
23359 cu
->dies
= comp_unit_die
;
23360 /* comp_unit_die is not stored in die_hash, no need. */
23362 /* We try not to read any attributes in this function, because not
23363 all CUs needed for references have been loaded yet, and symbol
23364 table processing isn't initialized. But we have to set the CU language,
23365 or we won't be able to build types correctly.
23366 Similarly, if we do not read the producer, we can not apply
23367 producer-specific interpretation. */
23368 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23371 /* Read in a signatured type and build its CU and DIEs.
23372 If the type is a stub for the real type in a DWO file,
23373 read in the real type from the DWO file as well. */
23376 read_signatured_type (struct signatured_type
*sig_type
)
23378 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23380 gdb_assert (per_cu
->is_debug_types
);
23381 gdb_assert (per_cu
->cu
== NULL
);
23383 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
23384 read_signatured_type_reader
, NULL
);
23385 sig_type
->per_cu
.tu_read
= 1;
23388 /* Decode simple location descriptions.
23389 Given a pointer to a dwarf block that defines a location, compute
23390 the location and return the value.
23392 NOTE drow/2003-11-18: This function is called in two situations
23393 now: for the address of static or global variables (partial symbols
23394 only) and for offsets into structures which are expected to be
23395 (more or less) constant. The partial symbol case should go away,
23396 and only the constant case should remain. That will let this
23397 function complain more accurately. A few special modes are allowed
23398 without complaint for global variables (for instance, global
23399 register values and thread-local values).
23401 A location description containing no operations indicates that the
23402 object is optimized out. The return value is 0 for that case.
23403 FIXME drow/2003-11-16: No callers check for this case any more; soon all
23404 callers will only want a very basic result and this can become a
23407 Note that stack[0] is unused except as a default error return. */
23410 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
23412 struct objfile
*objfile
= cu
->objfile
;
23414 size_t size
= blk
->size
;
23415 const gdb_byte
*data
= blk
->data
;
23416 CORE_ADDR stack
[64];
23418 unsigned int bytes_read
, unsnd
;
23424 stack
[++stacki
] = 0;
23463 stack
[++stacki
] = op
- DW_OP_lit0
;
23498 stack
[++stacki
] = op
- DW_OP_reg0
;
23500 dwarf2_complex_location_expr_complaint ();
23504 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23506 stack
[++stacki
] = unsnd
;
23508 dwarf2_complex_location_expr_complaint ();
23512 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
23517 case DW_OP_const1u
:
23518 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23522 case DW_OP_const1s
:
23523 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23527 case DW_OP_const2u
:
23528 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23532 case DW_OP_const2s
:
23533 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23537 case DW_OP_const4u
:
23538 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23542 case DW_OP_const4s
:
23543 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23547 case DW_OP_const8u
:
23548 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23553 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23559 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23564 stack
[stacki
+ 1] = stack
[stacki
];
23569 stack
[stacki
- 1] += stack
[stacki
];
23573 case DW_OP_plus_uconst
:
23574 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23580 stack
[stacki
- 1] -= stack
[stacki
];
23585 /* If we're not the last op, then we definitely can't encode
23586 this using GDB's address_class enum. This is valid for partial
23587 global symbols, although the variable's address will be bogus
23590 dwarf2_complex_location_expr_complaint ();
23593 case DW_OP_GNU_push_tls_address
:
23594 case DW_OP_form_tls_address
:
23595 /* The top of the stack has the offset from the beginning
23596 of the thread control block at which the variable is located. */
23597 /* Nothing should follow this operator, so the top of stack would
23599 /* This is valid for partial global symbols, but the variable's
23600 address will be bogus in the psymtab. Make it always at least
23601 non-zero to not look as a variable garbage collected by linker
23602 which have DW_OP_addr 0. */
23604 dwarf2_complex_location_expr_complaint ();
23608 case DW_OP_GNU_uninit
:
23611 case DW_OP_GNU_addr_index
:
23612 case DW_OP_GNU_const_index
:
23613 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23620 const char *name
= get_DW_OP_name (op
);
23623 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
23626 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
23630 return (stack
[stacki
]);
23633 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23634 outside of the allocated space. Also enforce minimum>0. */
23635 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23637 complaint (&symfile_complaints
,
23638 _("location description stack overflow"));
23644 complaint (&symfile_complaints
,
23645 _("location description stack underflow"));
23649 return (stack
[stacki
]);
23652 /* memory allocation interface */
23654 static struct dwarf_block
*
23655 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23657 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23660 static struct die_info
*
23661 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23663 struct die_info
*die
;
23664 size_t size
= sizeof (struct die_info
);
23667 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23669 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23670 memset (die
, 0, sizeof (struct die_info
));
23675 /* Macro support. */
23677 /* Return file name relative to the compilation directory of file number I in
23678 *LH's file name table. The result is allocated using xmalloc; the caller is
23679 responsible for freeing it. */
23682 file_file_name (int file
, struct line_header
*lh
)
23684 /* Is the file number a valid index into the line header's file name
23685 table? Remember that file numbers start with one, not zero. */
23686 if (1 <= file
&& file
<= lh
->file_names
.size ())
23688 const file_entry
&fe
= lh
->file_names
[file
- 1];
23690 if (!IS_ABSOLUTE_PATH (fe
.name
))
23692 const char *dir
= fe
.include_dir (lh
);
23694 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
23696 return xstrdup (fe
.name
);
23700 /* The compiler produced a bogus file number. We can at least
23701 record the macro definitions made in the file, even if we
23702 won't be able to find the file by name. */
23703 char fake_name
[80];
23705 xsnprintf (fake_name
, sizeof (fake_name
),
23706 "<bad macro file number %d>", file
);
23708 complaint (&symfile_complaints
,
23709 _("bad file number in macro information (%d)"),
23712 return xstrdup (fake_name
);
23716 /* Return the full name of file number I in *LH's file name table.
23717 Use COMP_DIR as the name of the current directory of the
23718 compilation. The result is allocated using xmalloc; the caller is
23719 responsible for freeing it. */
23721 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
23723 /* Is the file number a valid index into the line header's file name
23724 table? Remember that file numbers start with one, not zero. */
23725 if (1 <= file
&& file
<= lh
->file_names
.size ())
23727 char *relative
= file_file_name (file
, lh
);
23729 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
23731 return reconcat (relative
, comp_dir
, SLASH_STRING
,
23732 relative
, (char *) NULL
);
23735 return file_file_name (file
, lh
);
23739 static struct macro_source_file
*
23740 macro_start_file (int file
, int line
,
23741 struct macro_source_file
*current_file
,
23742 struct line_header
*lh
)
23744 /* File name relative to the compilation directory of this source file. */
23745 char *file_name
= file_file_name (file
, lh
);
23747 if (! current_file
)
23749 /* Note: We don't create a macro table for this compilation unit
23750 at all until we actually get a filename. */
23751 struct macro_table
*macro_table
= get_macro_table ();
23753 /* If we have no current file, then this must be the start_file
23754 directive for the compilation unit's main source file. */
23755 current_file
= macro_set_main (macro_table
, file_name
);
23756 macro_define_special (macro_table
);
23759 current_file
= macro_include (current_file
, line
, file_name
);
23763 return current_file
;
23766 static const char *
23767 consume_improper_spaces (const char *p
, const char *body
)
23771 complaint (&symfile_complaints
,
23772 _("macro definition contains spaces "
23773 "in formal argument list:\n`%s'"),
23785 parse_macro_definition (struct macro_source_file
*file
, int line
,
23790 /* The body string takes one of two forms. For object-like macro
23791 definitions, it should be:
23793 <macro name> " " <definition>
23795 For function-like macro definitions, it should be:
23797 <macro name> "() " <definition>
23799 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
23801 Spaces may appear only where explicitly indicated, and in the
23804 The Dwarf 2 spec says that an object-like macro's name is always
23805 followed by a space, but versions of GCC around March 2002 omit
23806 the space when the macro's definition is the empty string.
23808 The Dwarf 2 spec says that there should be no spaces between the
23809 formal arguments in a function-like macro's formal argument list,
23810 but versions of GCC around March 2002 include spaces after the
23814 /* Find the extent of the macro name. The macro name is terminated
23815 by either a space or null character (for an object-like macro) or
23816 an opening paren (for a function-like macro). */
23817 for (p
= body
; *p
; p
++)
23818 if (*p
== ' ' || *p
== '(')
23821 if (*p
== ' ' || *p
== '\0')
23823 /* It's an object-like macro. */
23824 int name_len
= p
- body
;
23825 char *name
= savestring (body
, name_len
);
23826 const char *replacement
;
23829 replacement
= body
+ name_len
+ 1;
23832 dwarf2_macro_malformed_definition_complaint (body
);
23833 replacement
= body
+ name_len
;
23836 macro_define_object (file
, line
, name
, replacement
);
23840 else if (*p
== '(')
23842 /* It's a function-like macro. */
23843 char *name
= savestring (body
, p
- body
);
23846 char **argv
= XNEWVEC (char *, argv_size
);
23850 p
= consume_improper_spaces (p
, body
);
23852 /* Parse the formal argument list. */
23853 while (*p
&& *p
!= ')')
23855 /* Find the extent of the current argument name. */
23856 const char *arg_start
= p
;
23858 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
23861 if (! *p
|| p
== arg_start
)
23862 dwarf2_macro_malformed_definition_complaint (body
);
23865 /* Make sure argv has room for the new argument. */
23866 if (argc
>= argv_size
)
23869 argv
= XRESIZEVEC (char *, argv
, argv_size
);
23872 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
23875 p
= consume_improper_spaces (p
, body
);
23877 /* Consume the comma, if present. */
23882 p
= consume_improper_spaces (p
, body
);
23891 /* Perfectly formed definition, no complaints. */
23892 macro_define_function (file
, line
, name
,
23893 argc
, (const char **) argv
,
23895 else if (*p
== '\0')
23897 /* Complain, but do define it. */
23898 dwarf2_macro_malformed_definition_complaint (body
);
23899 macro_define_function (file
, line
, name
,
23900 argc
, (const char **) argv
,
23904 /* Just complain. */
23905 dwarf2_macro_malformed_definition_complaint (body
);
23908 /* Just complain. */
23909 dwarf2_macro_malformed_definition_complaint (body
);
23915 for (i
= 0; i
< argc
; i
++)
23921 dwarf2_macro_malformed_definition_complaint (body
);
23924 /* Skip some bytes from BYTES according to the form given in FORM.
23925 Returns the new pointer. */
23927 static const gdb_byte
*
23928 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
23929 enum dwarf_form form
,
23930 unsigned int offset_size
,
23931 struct dwarf2_section_info
*section
)
23933 unsigned int bytes_read
;
23937 case DW_FORM_data1
:
23942 case DW_FORM_data2
:
23946 case DW_FORM_data4
:
23950 case DW_FORM_data8
:
23954 case DW_FORM_data16
:
23958 case DW_FORM_string
:
23959 read_direct_string (abfd
, bytes
, &bytes_read
);
23960 bytes
+= bytes_read
;
23963 case DW_FORM_sec_offset
:
23965 case DW_FORM_GNU_strp_alt
:
23966 bytes
+= offset_size
;
23969 case DW_FORM_block
:
23970 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
23971 bytes
+= bytes_read
;
23974 case DW_FORM_block1
:
23975 bytes
+= 1 + read_1_byte (abfd
, bytes
);
23977 case DW_FORM_block2
:
23978 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
23980 case DW_FORM_block4
:
23981 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
23984 case DW_FORM_sdata
:
23985 case DW_FORM_udata
:
23986 case DW_FORM_GNU_addr_index
:
23987 case DW_FORM_GNU_str_index
:
23988 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
23991 dwarf2_section_buffer_overflow_complaint (section
);
23996 case DW_FORM_implicit_const
:
24001 complaint (&symfile_complaints
,
24002 _("invalid form 0x%x in `%s'"),
24003 form
, get_section_name (section
));
24011 /* A helper for dwarf_decode_macros that handles skipping an unknown
24012 opcode. Returns an updated pointer to the macro data buffer; or,
24013 on error, issues a complaint and returns NULL. */
24015 static const gdb_byte
*
24016 skip_unknown_opcode (unsigned int opcode
,
24017 const gdb_byte
**opcode_definitions
,
24018 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24020 unsigned int offset_size
,
24021 struct dwarf2_section_info
*section
)
24023 unsigned int bytes_read
, i
;
24025 const gdb_byte
*defn
;
24027 if (opcode_definitions
[opcode
] == NULL
)
24029 complaint (&symfile_complaints
,
24030 _("unrecognized DW_MACFINO opcode 0x%x"),
24035 defn
= opcode_definitions
[opcode
];
24036 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24037 defn
+= bytes_read
;
24039 for (i
= 0; i
< arg
; ++i
)
24041 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24042 (enum dwarf_form
) defn
[i
], offset_size
,
24044 if (mac_ptr
== NULL
)
24046 /* skip_form_bytes already issued the complaint. */
24054 /* A helper function which parses the header of a macro section.
24055 If the macro section is the extended (for now called "GNU") type,
24056 then this updates *OFFSET_SIZE. Returns a pointer to just after
24057 the header, or issues a complaint and returns NULL on error. */
24059 static const gdb_byte
*
24060 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24062 const gdb_byte
*mac_ptr
,
24063 unsigned int *offset_size
,
24064 int section_is_gnu
)
24066 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24068 if (section_is_gnu
)
24070 unsigned int version
, flags
;
24072 version
= read_2_bytes (abfd
, mac_ptr
);
24073 if (version
!= 4 && version
!= 5)
24075 complaint (&symfile_complaints
,
24076 _("unrecognized version `%d' in .debug_macro section"),
24082 flags
= read_1_byte (abfd
, mac_ptr
);
24084 *offset_size
= (flags
& 1) ? 8 : 4;
24086 if ((flags
& 2) != 0)
24087 /* We don't need the line table offset. */
24088 mac_ptr
+= *offset_size
;
24090 /* Vendor opcode descriptions. */
24091 if ((flags
& 4) != 0)
24093 unsigned int i
, count
;
24095 count
= read_1_byte (abfd
, mac_ptr
);
24097 for (i
= 0; i
< count
; ++i
)
24099 unsigned int opcode
, bytes_read
;
24102 opcode
= read_1_byte (abfd
, mac_ptr
);
24104 opcode_definitions
[opcode
] = mac_ptr
;
24105 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24106 mac_ptr
+= bytes_read
;
24115 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24116 including DW_MACRO_import. */
24119 dwarf_decode_macro_bytes (bfd
*abfd
,
24120 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24121 struct macro_source_file
*current_file
,
24122 struct line_header
*lh
,
24123 struct dwarf2_section_info
*section
,
24124 int section_is_gnu
, int section_is_dwz
,
24125 unsigned int offset_size
,
24126 htab_t include_hash
)
24128 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24129 enum dwarf_macro_record_type macinfo_type
;
24130 int at_commandline
;
24131 const gdb_byte
*opcode_definitions
[256];
24133 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24134 &offset_size
, section_is_gnu
);
24135 if (mac_ptr
== NULL
)
24137 /* We already issued a complaint. */
24141 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24142 GDB is still reading the definitions from command line. First
24143 DW_MACINFO_start_file will need to be ignored as it was already executed
24144 to create CURRENT_FILE for the main source holding also the command line
24145 definitions. On first met DW_MACINFO_start_file this flag is reset to
24146 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24148 at_commandline
= 1;
24152 /* Do we at least have room for a macinfo type byte? */
24153 if (mac_ptr
>= mac_end
)
24155 dwarf2_section_buffer_overflow_complaint (section
);
24159 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24162 /* Note that we rely on the fact that the corresponding GNU and
24163 DWARF constants are the same. */
24164 switch (macinfo_type
)
24166 /* A zero macinfo type indicates the end of the macro
24171 case DW_MACRO_define
:
24172 case DW_MACRO_undef
:
24173 case DW_MACRO_define_strp
:
24174 case DW_MACRO_undef_strp
:
24175 case DW_MACRO_define_sup
:
24176 case DW_MACRO_undef_sup
:
24178 unsigned int bytes_read
;
24183 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24184 mac_ptr
+= bytes_read
;
24186 if (macinfo_type
== DW_MACRO_define
24187 || macinfo_type
== DW_MACRO_undef
)
24189 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24190 mac_ptr
+= bytes_read
;
24194 LONGEST str_offset
;
24196 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24197 mac_ptr
+= offset_size
;
24199 if (macinfo_type
== DW_MACRO_define_sup
24200 || macinfo_type
== DW_MACRO_undef_sup
24203 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
24205 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
24208 body
= read_indirect_string_at_offset (abfd
, str_offset
);
24211 is_define
= (macinfo_type
== DW_MACRO_define
24212 || macinfo_type
== DW_MACRO_define_strp
24213 || macinfo_type
== DW_MACRO_define_sup
);
24214 if (! current_file
)
24216 /* DWARF violation as no main source is present. */
24217 complaint (&symfile_complaints
,
24218 _("debug info with no main source gives macro %s "
24220 is_define
? _("definition") : _("undefinition"),
24224 if ((line
== 0 && !at_commandline
)
24225 || (line
!= 0 && at_commandline
))
24226 complaint (&symfile_complaints
,
24227 _("debug info gives %s macro %s with %s line %d: %s"),
24228 at_commandline
? _("command-line") : _("in-file"),
24229 is_define
? _("definition") : _("undefinition"),
24230 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24233 parse_macro_definition (current_file
, line
, body
);
24236 gdb_assert (macinfo_type
== DW_MACRO_undef
24237 || macinfo_type
== DW_MACRO_undef_strp
24238 || macinfo_type
== DW_MACRO_undef_sup
);
24239 macro_undef (current_file
, line
, body
);
24244 case DW_MACRO_start_file
:
24246 unsigned int bytes_read
;
24249 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24250 mac_ptr
+= bytes_read
;
24251 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24252 mac_ptr
+= bytes_read
;
24254 if ((line
== 0 && !at_commandline
)
24255 || (line
!= 0 && at_commandline
))
24256 complaint (&symfile_complaints
,
24257 _("debug info gives source %d included "
24258 "from %s at %s line %d"),
24259 file
, at_commandline
? _("command-line") : _("file"),
24260 line
== 0 ? _("zero") : _("non-zero"), line
);
24262 if (at_commandline
)
24264 /* This DW_MACRO_start_file was executed in the
24266 at_commandline
= 0;
24269 current_file
= macro_start_file (file
, line
, current_file
, lh
);
24273 case DW_MACRO_end_file
:
24274 if (! current_file
)
24275 complaint (&symfile_complaints
,
24276 _("macro debug info has an unmatched "
24277 "`close_file' directive"));
24280 current_file
= current_file
->included_by
;
24281 if (! current_file
)
24283 enum dwarf_macro_record_type next_type
;
24285 /* GCC circa March 2002 doesn't produce the zero
24286 type byte marking the end of the compilation
24287 unit. Complain if it's not there, but exit no
24290 /* Do we at least have room for a macinfo type byte? */
24291 if (mac_ptr
>= mac_end
)
24293 dwarf2_section_buffer_overflow_complaint (section
);
24297 /* We don't increment mac_ptr here, so this is just
24300 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24302 if (next_type
!= 0)
24303 complaint (&symfile_complaints
,
24304 _("no terminating 0-type entry for "
24305 "macros in `.debug_macinfo' section"));
24312 case DW_MACRO_import
:
24313 case DW_MACRO_import_sup
:
24317 bfd
*include_bfd
= abfd
;
24318 struct dwarf2_section_info
*include_section
= section
;
24319 const gdb_byte
*include_mac_end
= mac_end
;
24320 int is_dwz
= section_is_dwz
;
24321 const gdb_byte
*new_mac_ptr
;
24323 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24324 mac_ptr
+= offset_size
;
24326 if (macinfo_type
== DW_MACRO_import_sup
)
24328 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
24330 dwarf2_read_section (objfile
, &dwz
->macro
);
24332 include_section
= &dwz
->macro
;
24333 include_bfd
= get_section_bfd_owner (include_section
);
24334 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24338 new_mac_ptr
= include_section
->buffer
+ offset
;
24339 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24343 /* This has actually happened; see
24344 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24345 complaint (&symfile_complaints
,
24346 _("recursive DW_MACRO_import in "
24347 ".debug_macro section"));
24351 *slot
= (void *) new_mac_ptr
;
24353 dwarf_decode_macro_bytes (include_bfd
, new_mac_ptr
,
24354 include_mac_end
, current_file
, lh
,
24355 section
, section_is_gnu
, is_dwz
,
24356 offset_size
, include_hash
);
24358 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24363 case DW_MACINFO_vendor_ext
:
24364 if (!section_is_gnu
)
24366 unsigned int bytes_read
;
24368 /* This reads the constant, but since we don't recognize
24369 any vendor extensions, we ignore it. */
24370 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24371 mac_ptr
+= bytes_read
;
24372 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24373 mac_ptr
+= bytes_read
;
24375 /* We don't recognize any vendor extensions. */
24381 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24382 mac_ptr
, mac_end
, abfd
, offset_size
,
24384 if (mac_ptr
== NULL
)
24388 } while (macinfo_type
!= 0);
24392 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24393 int section_is_gnu
)
24395 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24396 struct line_header
*lh
= cu
->line_header
;
24398 const gdb_byte
*mac_ptr
, *mac_end
;
24399 struct macro_source_file
*current_file
= 0;
24400 enum dwarf_macro_record_type macinfo_type
;
24401 unsigned int offset_size
= cu
->header
.offset_size
;
24402 const gdb_byte
*opcode_definitions
[256];
24404 struct dwarf2_section_info
*section
;
24405 const char *section_name
;
24407 if (cu
->dwo_unit
!= NULL
)
24409 if (section_is_gnu
)
24411 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24412 section_name
= ".debug_macro.dwo";
24416 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24417 section_name
= ".debug_macinfo.dwo";
24422 if (section_is_gnu
)
24424 section
= &dwarf2_per_objfile
->macro
;
24425 section_name
= ".debug_macro";
24429 section
= &dwarf2_per_objfile
->macinfo
;
24430 section_name
= ".debug_macinfo";
24434 dwarf2_read_section (objfile
, section
);
24435 if (section
->buffer
== NULL
)
24437 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
24440 abfd
= get_section_bfd_owner (section
);
24442 /* First pass: Find the name of the base filename.
24443 This filename is needed in order to process all macros whose definition
24444 (or undefinition) comes from the command line. These macros are defined
24445 before the first DW_MACINFO_start_file entry, and yet still need to be
24446 associated to the base file.
24448 To determine the base file name, we scan the macro definitions until we
24449 reach the first DW_MACINFO_start_file entry. We then initialize
24450 CURRENT_FILE accordingly so that any macro definition found before the
24451 first DW_MACINFO_start_file can still be associated to the base file. */
24453 mac_ptr
= section
->buffer
+ offset
;
24454 mac_end
= section
->buffer
+ section
->size
;
24456 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24457 &offset_size
, section_is_gnu
);
24458 if (mac_ptr
== NULL
)
24460 /* We already issued a complaint. */
24466 /* Do we at least have room for a macinfo type byte? */
24467 if (mac_ptr
>= mac_end
)
24469 /* Complaint is printed during the second pass as GDB will probably
24470 stop the first pass earlier upon finding
24471 DW_MACINFO_start_file. */
24475 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24478 /* Note that we rely on the fact that the corresponding GNU and
24479 DWARF constants are the same. */
24480 switch (macinfo_type
)
24482 /* A zero macinfo type indicates the end of the macro
24487 case DW_MACRO_define
:
24488 case DW_MACRO_undef
:
24489 /* Only skip the data by MAC_PTR. */
24491 unsigned int bytes_read
;
24493 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24494 mac_ptr
+= bytes_read
;
24495 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24496 mac_ptr
+= bytes_read
;
24500 case DW_MACRO_start_file
:
24502 unsigned int bytes_read
;
24505 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24506 mac_ptr
+= bytes_read
;
24507 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24508 mac_ptr
+= bytes_read
;
24510 current_file
= macro_start_file (file
, line
, current_file
, lh
);
24514 case DW_MACRO_end_file
:
24515 /* No data to skip by MAC_PTR. */
24518 case DW_MACRO_define_strp
:
24519 case DW_MACRO_undef_strp
:
24520 case DW_MACRO_define_sup
:
24521 case DW_MACRO_undef_sup
:
24523 unsigned int bytes_read
;
24525 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24526 mac_ptr
+= bytes_read
;
24527 mac_ptr
+= offset_size
;
24531 case DW_MACRO_import
:
24532 case DW_MACRO_import_sup
:
24533 /* Note that, according to the spec, a transparent include
24534 chain cannot call DW_MACRO_start_file. So, we can just
24535 skip this opcode. */
24536 mac_ptr
+= offset_size
;
24539 case DW_MACINFO_vendor_ext
:
24540 /* Only skip the data by MAC_PTR. */
24541 if (!section_is_gnu
)
24543 unsigned int bytes_read
;
24545 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24546 mac_ptr
+= bytes_read
;
24547 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24548 mac_ptr
+= bytes_read
;
24553 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24554 mac_ptr
, mac_end
, abfd
, offset_size
,
24556 if (mac_ptr
== NULL
)
24560 } while (macinfo_type
!= 0 && current_file
== NULL
);
24562 /* Second pass: Process all entries.
24564 Use the AT_COMMAND_LINE flag to determine whether we are still processing
24565 command-line macro definitions/undefinitions. This flag is unset when we
24566 reach the first DW_MACINFO_start_file entry. */
24568 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
24570 NULL
, xcalloc
, xfree
));
24571 mac_ptr
= section
->buffer
+ offset
;
24572 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
24573 *slot
= (void *) mac_ptr
;
24574 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
24575 current_file
, lh
, section
,
24576 section_is_gnu
, 0, offset_size
,
24577 include_hash
.get ());
24580 /* Check if the attribute's form is a DW_FORM_block*
24581 if so return true else false. */
24584 attr_form_is_block (const struct attribute
*attr
)
24586 return (attr
== NULL
? 0 :
24587 attr
->form
== DW_FORM_block1
24588 || attr
->form
== DW_FORM_block2
24589 || attr
->form
== DW_FORM_block4
24590 || attr
->form
== DW_FORM_block
24591 || attr
->form
== DW_FORM_exprloc
);
24594 /* Return non-zero if ATTR's value is a section offset --- classes
24595 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
24596 You may use DW_UNSND (attr) to retrieve such offsets.
24598 Section 7.5.4, "Attribute Encodings", explains that no attribute
24599 may have a value that belongs to more than one of these classes; it
24600 would be ambiguous if we did, because we use the same forms for all
24604 attr_form_is_section_offset (const struct attribute
*attr
)
24606 return (attr
->form
== DW_FORM_data4
24607 || attr
->form
== DW_FORM_data8
24608 || attr
->form
== DW_FORM_sec_offset
);
24611 /* Return non-zero if ATTR's value falls in the 'constant' class, or
24612 zero otherwise. When this function returns true, you can apply
24613 dwarf2_get_attr_constant_value to it.
24615 However, note that for some attributes you must check
24616 attr_form_is_section_offset before using this test. DW_FORM_data4
24617 and DW_FORM_data8 are members of both the constant class, and of
24618 the classes that contain offsets into other debug sections
24619 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
24620 that, if an attribute's can be either a constant or one of the
24621 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
24622 taken as section offsets, not constants.
24624 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
24625 cannot handle that. */
24628 attr_form_is_constant (const struct attribute
*attr
)
24630 switch (attr
->form
)
24632 case DW_FORM_sdata
:
24633 case DW_FORM_udata
:
24634 case DW_FORM_data1
:
24635 case DW_FORM_data2
:
24636 case DW_FORM_data4
:
24637 case DW_FORM_data8
:
24638 case DW_FORM_implicit_const
:
24646 /* DW_ADDR is always stored already as sect_offset; despite for the forms
24647 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
24650 attr_form_is_ref (const struct attribute
*attr
)
24652 switch (attr
->form
)
24654 case DW_FORM_ref_addr
:
24659 case DW_FORM_ref_udata
:
24660 case DW_FORM_GNU_ref_alt
:
24667 /* Return the .debug_loc section to use for CU.
24668 For DWO files use .debug_loc.dwo. */
24670 static struct dwarf2_section_info
*
24671 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24675 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24677 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24679 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
24680 : &dwarf2_per_objfile
->loc
);
24683 /* A helper function that fills in a dwarf2_loclist_baton. */
24686 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24687 struct dwarf2_loclist_baton
*baton
,
24688 const struct attribute
*attr
)
24690 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24692 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
24694 baton
->per_cu
= cu
->per_cu
;
24695 gdb_assert (baton
->per_cu
);
24696 /* We don't know how long the location list is, but make sure we
24697 don't run off the edge of the section. */
24698 baton
->size
= section
->size
- DW_UNSND (attr
);
24699 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
24700 baton
->base_address
= cu
->base_address
;
24701 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24705 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24706 struct dwarf2_cu
*cu
, int is_block
)
24708 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24709 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24711 if (attr_form_is_section_offset (attr
)
24712 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24713 the section. If so, fall through to the complaint in the
24715 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
24717 struct dwarf2_loclist_baton
*baton
;
24719 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24721 fill_in_loclist_baton (cu
, baton
, attr
);
24723 if (cu
->base_known
== 0)
24724 complaint (&symfile_complaints
,
24725 _("Location list used without "
24726 "specifying the CU base address."));
24728 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24729 ? dwarf2_loclist_block_index
24730 : dwarf2_loclist_index
);
24731 SYMBOL_LOCATION_BATON (sym
) = baton
;
24735 struct dwarf2_locexpr_baton
*baton
;
24737 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24738 baton
->per_cu
= cu
->per_cu
;
24739 gdb_assert (baton
->per_cu
);
24741 if (attr_form_is_block (attr
))
24743 /* Note that we're just copying the block's data pointer
24744 here, not the actual data. We're still pointing into the
24745 info_buffer for SYM's objfile; right now we never release
24746 that buffer, but when we do clean up properly this may
24748 baton
->size
= DW_BLOCK (attr
)->size
;
24749 baton
->data
= DW_BLOCK (attr
)->data
;
24753 dwarf2_invalid_attrib_class_complaint ("location description",
24754 SYMBOL_NATURAL_NAME (sym
));
24758 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24759 ? dwarf2_locexpr_block_index
24760 : dwarf2_locexpr_index
);
24761 SYMBOL_LOCATION_BATON (sym
) = baton
;
24765 /* Return the OBJFILE associated with the compilation unit CU. If CU
24766 came from a separate debuginfo file, then the master objfile is
24770 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
24772 struct objfile
*objfile
= per_cu
->objfile
;
24774 /* Return the master objfile, so that we can report and look up the
24775 correct file containing this variable. */
24776 if (objfile
->separate_debug_objfile_backlink
)
24777 objfile
= objfile
->separate_debug_objfile_backlink
;
24782 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
24783 (CU_HEADERP is unused in such case) or prepare a temporary copy at
24784 CU_HEADERP first. */
24786 static const struct comp_unit_head
*
24787 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
24788 struct dwarf2_per_cu_data
*per_cu
)
24790 const gdb_byte
*info_ptr
;
24793 return &per_cu
->cu
->header
;
24795 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
24797 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
24798 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
24799 rcuh_kind::COMPILE
);
24804 /* Return the address size given in the compilation unit header for CU. */
24807 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
24809 struct comp_unit_head cu_header_local
;
24810 const struct comp_unit_head
*cu_headerp
;
24812 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24814 return cu_headerp
->addr_size
;
24817 /* Return the offset size given in the compilation unit header for CU. */
24820 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
24822 struct comp_unit_head cu_header_local
;
24823 const struct comp_unit_head
*cu_headerp
;
24825 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24827 return cu_headerp
->offset_size
;
24830 /* See its dwarf2loc.h declaration. */
24833 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
24835 struct comp_unit_head cu_header_local
;
24836 const struct comp_unit_head
*cu_headerp
;
24838 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24840 if (cu_headerp
->version
== 2)
24841 return cu_headerp
->addr_size
;
24843 return cu_headerp
->offset_size
;
24846 /* Return the text offset of the CU. The returned offset comes from
24847 this CU's objfile. If this objfile came from a separate debuginfo
24848 file, then the offset may be different from the corresponding
24849 offset in the parent objfile. */
24852 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
24854 struct objfile
*objfile
= per_cu
->objfile
;
24856 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
24859 /* Return DWARF version number of PER_CU. */
24862 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
24864 return per_cu
->dwarf_version
;
24867 /* Locate the .debug_info compilation unit from CU's objfile which contains
24868 the DIE at OFFSET. Raises an error on failure. */
24870 static struct dwarf2_per_cu_data
*
24871 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24872 unsigned int offset_in_dwz
,
24873 struct objfile
*objfile
)
24875 struct dwarf2_per_cu_data
*this_cu
;
24877 const sect_offset
*cu_off
;
24880 high
= dwarf2_per_objfile
->n_comp_units
- 1;
24883 struct dwarf2_per_cu_data
*mid_cu
;
24884 int mid
= low
+ (high
- low
) / 2;
24886 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
24887 cu_off
= &mid_cu
->sect_off
;
24888 if (mid_cu
->is_dwz
> offset_in_dwz
24889 || (mid_cu
->is_dwz
== offset_in_dwz
&& *cu_off
>= sect_off
))
24894 gdb_assert (low
== high
);
24895 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
24896 cu_off
= &this_cu
->sect_off
;
24897 if (this_cu
->is_dwz
!= offset_in_dwz
|| *cu_off
> sect_off
)
24899 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24900 error (_("Dwarf Error: could not find partial DIE containing "
24901 "offset 0x%x [in module %s]"),
24902 to_underlying (sect_off
), bfd_get_filename (objfile
->obfd
));
24904 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
24906 return dwarf2_per_objfile
->all_comp_units
[low
-1];
24910 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
24911 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
24912 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24913 error (_("invalid dwarf2 offset %u"), to_underlying (sect_off
));
24914 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24919 /* Initialize dwarf2_cu CU, owned by PER_CU. */
24922 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
24924 memset (cu
, 0, sizeof (*cu
));
24926 cu
->per_cu
= per_cu
;
24927 cu
->objfile
= per_cu
->objfile
;
24928 obstack_init (&cu
->comp_unit_obstack
);
24931 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24934 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24935 enum language pretend_language
)
24937 struct attribute
*attr
;
24939 /* Set the language we're debugging. */
24940 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24942 set_cu_language (DW_UNSND (attr
), cu
);
24945 cu
->language
= pretend_language
;
24946 cu
->language_defn
= language_def (cu
->language
);
24949 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24952 /* Release one cached compilation unit, CU. We unlink it from the tree
24953 of compilation units, but we don't remove it from the read_in_chain;
24954 the caller is responsible for that.
24955 NOTE: DATA is a void * because this function is also used as a
24956 cleanup routine. */
24959 free_heap_comp_unit (void *data
)
24961 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) data
;
24963 gdb_assert (cu
->per_cu
!= NULL
);
24964 cu
->per_cu
->cu
= NULL
;
24967 obstack_free (&cu
->comp_unit_obstack
, NULL
);
24972 /* This cleanup function is passed the address of a dwarf2_cu on the stack
24973 when we're finished with it. We can't free the pointer itself, but be
24974 sure to unlink it from the cache. Also release any associated storage. */
24977 free_stack_comp_unit (void *data
)
24979 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) data
;
24981 gdb_assert (cu
->per_cu
!= NULL
);
24982 cu
->per_cu
->cu
= NULL
;
24985 obstack_free (&cu
->comp_unit_obstack
, NULL
);
24986 cu
->partial_dies
= NULL
;
24989 /* Free all cached compilation units. */
24992 free_cached_comp_units (void *data
)
24994 dwarf2_per_objfile
->free_cached_comp_units ();
24997 /* Increase the age counter on each cached compilation unit, and free
24998 any that are too old. */
25001 age_cached_comp_units (void)
25003 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25005 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25006 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25007 while (per_cu
!= NULL
)
25009 per_cu
->cu
->last_used
++;
25010 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25011 dwarf2_mark (per_cu
->cu
);
25012 per_cu
= per_cu
->cu
->read_in_chain
;
25015 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25016 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25017 while (per_cu
!= NULL
)
25019 struct dwarf2_per_cu_data
*next_cu
;
25021 next_cu
= per_cu
->cu
->read_in_chain
;
25023 if (!per_cu
->cu
->mark
)
25025 free_heap_comp_unit (per_cu
->cu
);
25026 *last_chain
= next_cu
;
25029 last_chain
= &per_cu
->cu
->read_in_chain
;
25035 /* Remove a single compilation unit from the cache. */
25038 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25040 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25042 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25043 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25044 while (per_cu
!= NULL
)
25046 struct dwarf2_per_cu_data
*next_cu
;
25048 next_cu
= per_cu
->cu
->read_in_chain
;
25050 if (per_cu
== target_per_cu
)
25052 free_heap_comp_unit (per_cu
->cu
);
25054 *last_chain
= next_cu
;
25058 last_chain
= &per_cu
->cu
->read_in_chain
;
25064 /* Release all extra memory associated with OBJFILE. */
25067 dwarf2_free_objfile (struct objfile
*objfile
)
25070 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
25071 dwarf2_objfile_data_key
);
25073 if (dwarf2_per_objfile
== NULL
)
25076 dwarf2_per_objfile
->~dwarf2_per_objfile ();
25079 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25080 We store these in a hash table separate from the DIEs, and preserve them
25081 when the DIEs are flushed out of cache.
25083 The CU "per_cu" pointer is needed because offset alone is not enough to
25084 uniquely identify the type. A file may have multiple .debug_types sections,
25085 or the type may come from a DWO file. Furthermore, while it's more logical
25086 to use per_cu->section+offset, with Fission the section with the data is in
25087 the DWO file but we don't know that section at the point we need it.
25088 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25089 because we can enter the lookup routine, get_die_type_at_offset, from
25090 outside this file, and thus won't necessarily have PER_CU->cu.
25091 Fortunately, PER_CU is stable for the life of the objfile. */
25093 struct dwarf2_per_cu_offset_and_type
25095 const struct dwarf2_per_cu_data
*per_cu
;
25096 sect_offset sect_off
;
25100 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25103 per_cu_offset_and_type_hash (const void *item
)
25105 const struct dwarf2_per_cu_offset_and_type
*ofs
25106 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25108 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25111 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25114 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25116 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25117 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25118 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25119 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25121 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25122 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25125 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25126 table if necessary. For convenience, return TYPE.
25128 The DIEs reading must have careful ordering to:
25129 * Not cause infite loops trying to read in DIEs as a prerequisite for
25130 reading current DIE.
25131 * Not trying to dereference contents of still incompletely read in types
25132 while reading in other DIEs.
25133 * Enable referencing still incompletely read in types just by a pointer to
25134 the type without accessing its fields.
25136 Therefore caller should follow these rules:
25137 * Try to fetch any prerequisite types we may need to build this DIE type
25138 before building the type and calling set_die_type.
25139 * After building type call set_die_type for current DIE as soon as
25140 possible before fetching more types to complete the current type.
25141 * Make the type as complete as possible before fetching more types. */
25143 static struct type
*
25144 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25146 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25147 struct objfile
*objfile
= cu
->objfile
;
25148 struct attribute
*attr
;
25149 struct dynamic_prop prop
;
25151 /* For Ada types, make sure that the gnat-specific data is always
25152 initialized (if not already set). There are a few types where
25153 we should not be doing so, because the type-specific area is
25154 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25155 where the type-specific area is used to store the floatformat).
25156 But this is not a problem, because the gnat-specific information
25157 is actually not needed for these types. */
25158 if (need_gnat_info (cu
)
25159 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25160 && TYPE_CODE (type
) != TYPE_CODE_FLT
25161 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25162 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25163 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25164 && !HAVE_GNAT_AUX_INFO (type
))
25165 INIT_GNAT_SPECIFIC (type
);
25167 /* Read DW_AT_allocated and set in type. */
25168 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25169 if (attr_form_is_block (attr
))
25171 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25172 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
, objfile
);
25174 else if (attr
!= NULL
)
25176 complaint (&symfile_complaints
,
25177 _("DW_AT_allocated has the wrong form (%s) at DIE 0x%x"),
25178 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25179 to_underlying (die
->sect_off
));
25182 /* Read DW_AT_associated and set in type. */
25183 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25184 if (attr_form_is_block (attr
))
25186 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25187 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
, objfile
);
25189 else if (attr
!= NULL
)
25191 complaint (&symfile_complaints
,
25192 _("DW_AT_associated has the wrong form (%s) at DIE 0x%x"),
25193 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25194 to_underlying (die
->sect_off
));
25197 /* Read DW_AT_data_location and set in type. */
25198 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25199 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25200 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
, objfile
);
25202 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25204 dwarf2_per_objfile
->die_type_hash
=
25205 htab_create_alloc_ex (127,
25206 per_cu_offset_and_type_hash
,
25207 per_cu_offset_and_type_eq
,
25209 &objfile
->objfile_obstack
,
25210 hashtab_obstack_allocate
,
25211 dummy_obstack_deallocate
);
25214 ofs
.per_cu
= cu
->per_cu
;
25215 ofs
.sect_off
= die
->sect_off
;
25217 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25218 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25220 complaint (&symfile_complaints
,
25221 _("A problem internal to GDB: DIE 0x%x has type already set"),
25222 to_underlying (die
->sect_off
));
25223 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25224 struct dwarf2_per_cu_offset_and_type
);
25229 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25230 or return NULL if the die does not have a saved type. */
25232 static struct type
*
25233 get_die_type_at_offset (sect_offset sect_off
,
25234 struct dwarf2_per_cu_data
*per_cu
)
25236 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25238 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25241 ofs
.per_cu
= per_cu
;
25242 ofs
.sect_off
= sect_off
;
25243 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25244 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25251 /* Look up the type for DIE in CU in die_type_hash,
25252 or return NULL if DIE does not have a saved type. */
25254 static struct type
*
25255 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25257 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25260 /* Add a dependence relationship from CU to REF_PER_CU. */
25263 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25264 struct dwarf2_per_cu_data
*ref_per_cu
)
25268 if (cu
->dependencies
== NULL
)
25270 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25271 NULL
, &cu
->comp_unit_obstack
,
25272 hashtab_obstack_allocate
,
25273 dummy_obstack_deallocate
);
25275 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25277 *slot
= ref_per_cu
;
25280 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25281 Set the mark field in every compilation unit in the
25282 cache that we must keep because we are keeping CU. */
25285 dwarf2_mark_helper (void **slot
, void *data
)
25287 struct dwarf2_per_cu_data
*per_cu
;
25289 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25291 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25292 reading of the chain. As such dependencies remain valid it is not much
25293 useful to track and undo them during QUIT cleanups. */
25294 if (per_cu
->cu
== NULL
)
25297 if (per_cu
->cu
->mark
)
25299 per_cu
->cu
->mark
= 1;
25301 if (per_cu
->cu
->dependencies
!= NULL
)
25302 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25307 /* Set the mark field in CU and in every other compilation unit in the
25308 cache that we must keep because we are keeping CU. */
25311 dwarf2_mark (struct dwarf2_cu
*cu
)
25316 if (cu
->dependencies
!= NULL
)
25317 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25321 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25325 per_cu
->cu
->mark
= 0;
25326 per_cu
= per_cu
->cu
->read_in_chain
;
25330 /* Trivial hash function for partial_die_info: the hash value of a DIE
25331 is its offset in .debug_info for this objfile. */
25334 partial_die_hash (const void *item
)
25336 const struct partial_die_info
*part_die
25337 = (const struct partial_die_info
*) item
;
25339 return to_underlying (part_die
->sect_off
);
25342 /* Trivial comparison function for partial_die_info structures: two DIEs
25343 are equal if they have the same offset. */
25346 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25348 const struct partial_die_info
*part_die_lhs
25349 = (const struct partial_die_info
*) item_lhs
;
25350 const struct partial_die_info
*part_die_rhs
25351 = (const struct partial_die_info
*) item_rhs
;
25353 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25356 static struct cmd_list_element
*set_dwarf_cmdlist
;
25357 static struct cmd_list_element
*show_dwarf_cmdlist
;
25360 set_dwarf_cmd (const char *args
, int from_tty
)
25362 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25367 show_dwarf_cmd (const char *args
, int from_tty
)
25369 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25372 /* Free data associated with OBJFILE, if necessary. */
25375 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
25377 struct dwarf2_per_objfile
*data
= (struct dwarf2_per_objfile
*) d
;
25380 /* Make sure we don't accidentally use dwarf2_per_objfile while
25382 dwarf2_per_objfile
= NULL
;
25384 for (ix
= 0; ix
< data
->n_comp_units
; ++ix
)
25385 VEC_free (dwarf2_per_cu_ptr
, data
->all_comp_units
[ix
]->imported_symtabs
);
25387 for (ix
= 0; ix
< data
->n_type_units
; ++ix
)
25388 VEC_free (dwarf2_per_cu_ptr
,
25389 data
->all_type_units
[ix
]->per_cu
.imported_symtabs
);
25390 xfree (data
->all_type_units
);
25392 VEC_free (dwarf2_section_info_def
, data
->types
);
25394 if (data
->dwo_files
)
25395 free_dwo_files (data
->dwo_files
, objfile
);
25396 if (data
->dwp_file
)
25397 gdb_bfd_unref (data
->dwp_file
->dbfd
);
25399 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
25400 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
25402 if (data
->index_table
!= NULL
)
25403 data
->index_table
->~mapped_index ();
25407 /* The "save gdb-index" command. */
25409 /* Write SIZE bytes from the buffer pointed to by DATA to FILE, with
25413 file_write (FILE *file
, const void *data
, size_t size
)
25415 if (fwrite (data
, 1, size
, file
) != size
)
25416 error (_("couldn't data write to file"));
25419 /* Write the contents of VEC to FILE, with error checking. */
25421 template<typename Elem
, typename Alloc
>
25423 file_write (FILE *file
, const std::vector
<Elem
, Alloc
> &vec
)
25425 file_write (file
, vec
.data (), vec
.size () * sizeof (vec
[0]));
25428 /* In-memory buffer to prepare data to be written later to a file. */
25432 /* Copy DATA to the end of the buffer. */
25433 template<typename T
>
25434 void append_data (const T
&data
)
25436 std::copy (reinterpret_cast<const gdb_byte
*> (&data
),
25437 reinterpret_cast<const gdb_byte
*> (&data
+ 1),
25438 grow (sizeof (data
)));
25441 /* Copy CSTR (a zero-terminated string) to the end of buffer. The
25442 terminating zero is appended too. */
25443 void append_cstr0 (const char *cstr
)
25445 const size_t size
= strlen (cstr
) + 1;
25446 std::copy (cstr
, cstr
+ size
, grow (size
));
25449 /* Store INPUT as ULEB128 to the end of buffer. */
25450 void append_unsigned_leb128 (ULONGEST input
)
25454 gdb_byte output
= input
& 0x7f;
25458 append_data (output
);
25464 /* Accept a host-format integer in VAL and append it to the buffer
25465 as a target-format integer which is LEN bytes long. */
25466 void append_uint (size_t len
, bfd_endian byte_order
, ULONGEST val
)
25468 ::store_unsigned_integer (grow (len
), len
, byte_order
, val
);
25471 /* Return the size of the buffer. */
25472 size_t size () const
25474 return m_vec
.size ();
25477 /* Return true iff the buffer is empty. */
25478 bool empty () const
25480 return m_vec
.empty ();
25483 /* Write the buffer to FILE. */
25484 void file_write (FILE *file
) const
25486 ::file_write (file
, m_vec
);
25490 /* Grow SIZE bytes at the end of the buffer. Returns a pointer to
25491 the start of the new block. */
25492 gdb_byte
*grow (size_t size
)
25494 m_vec
.resize (m_vec
.size () + size
);
25495 return &*m_vec
.end () - size
;
25498 gdb::byte_vector m_vec
;
25501 /* An entry in the symbol table. */
25502 struct symtab_index_entry
25504 /* The name of the symbol. */
25506 /* The offset of the name in the constant pool. */
25507 offset_type index_offset
;
25508 /* A sorted vector of the indices of all the CUs that hold an object
25510 std::vector
<offset_type
> cu_indices
;
25513 /* The symbol table. This is a power-of-2-sized hash table. */
25514 struct mapped_symtab
25518 data
.resize (1024);
25521 offset_type n_elements
= 0;
25522 std::vector
<symtab_index_entry
> data
;
25525 /* Find a slot in SYMTAB for the symbol NAME. Returns a reference to
25528 Function is used only during write_hash_table so no index format backward
25529 compatibility is needed. */
25531 static symtab_index_entry
&
25532 find_slot (struct mapped_symtab
*symtab
, const char *name
)
25534 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
25536 index
= hash
& (symtab
->data
.size () - 1);
25537 step
= ((hash
* 17) & (symtab
->data
.size () - 1)) | 1;
25541 if (symtab
->data
[index
].name
== NULL
25542 || strcmp (name
, symtab
->data
[index
].name
) == 0)
25543 return symtab
->data
[index
];
25544 index
= (index
+ step
) & (symtab
->data
.size () - 1);
25548 /* Expand SYMTAB's hash table. */
25551 hash_expand (struct mapped_symtab
*symtab
)
25553 auto old_entries
= std::move (symtab
->data
);
25555 symtab
->data
.clear ();
25556 symtab
->data
.resize (old_entries
.size () * 2);
25558 for (auto &it
: old_entries
)
25559 if (it
.name
!= NULL
)
25561 auto &ref
= find_slot (symtab
, it
.name
);
25562 ref
= std::move (it
);
25566 /* Add an entry to SYMTAB. NAME is the name of the symbol.
25567 CU_INDEX is the index of the CU in which the symbol appears.
25568 IS_STATIC is one if the symbol is static, otherwise zero (global). */
25571 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
25572 int is_static
, gdb_index_symbol_kind kind
,
25573 offset_type cu_index
)
25575 offset_type cu_index_and_attrs
;
25577 ++symtab
->n_elements
;
25578 if (4 * symtab
->n_elements
/ 3 >= symtab
->data
.size ())
25579 hash_expand (symtab
);
25581 symtab_index_entry
&slot
= find_slot (symtab
, name
);
25582 if (slot
.name
== NULL
)
25585 /* index_offset is set later. */
25588 cu_index_and_attrs
= 0;
25589 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
25590 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
25591 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
25593 /* We don't want to record an index value twice as we want to avoid the
25595 We process all global symbols and then all static symbols
25596 (which would allow us to avoid the duplication by only having to check
25597 the last entry pushed), but a symbol could have multiple kinds in one CU.
25598 To keep things simple we don't worry about the duplication here and
25599 sort and uniqufy the list after we've processed all symbols. */
25600 slot
.cu_indices
.push_back (cu_index_and_attrs
);
25603 /* Sort and remove duplicates of all symbols' cu_indices lists. */
25606 uniquify_cu_indices (struct mapped_symtab
*symtab
)
25608 for (auto &entry
: symtab
->data
)
25610 if (entry
.name
!= NULL
&& !entry
.cu_indices
.empty ())
25612 auto &cu_indices
= entry
.cu_indices
;
25613 std::sort (cu_indices
.begin (), cu_indices
.end ());
25614 auto from
= std::unique (cu_indices
.begin (), cu_indices
.end ());
25615 cu_indices
.erase (from
, cu_indices
.end ());
25620 /* A form of 'const char *' suitable for container keys. Only the
25621 pointer is stored. The strings themselves are compared, not the
25626 c_str_view (const char *cstr
)
25630 bool operator== (const c_str_view
&other
) const
25632 return strcmp (m_cstr
, other
.m_cstr
) == 0;
25635 /* Return the underlying C string. Note, the returned string is
25636 only a reference with lifetime of this object. */
25637 const char *c_str () const
25643 friend class c_str_view_hasher
;
25644 const char *const m_cstr
;
25647 /* A std::unordered_map::hasher for c_str_view that uses the right
25648 hash function for strings in a mapped index. */
25649 class c_str_view_hasher
25652 size_t operator () (const c_str_view
&x
) const
25654 return mapped_index_string_hash (INT_MAX
, x
.m_cstr
);
25658 /* A std::unordered_map::hasher for std::vector<>. */
25659 template<typename T
>
25660 class vector_hasher
25663 size_t operator () (const std::vector
<T
> &key
) const
25665 return iterative_hash (key
.data (),
25666 sizeof (key
.front ()) * key
.size (), 0);
25670 /* Write the mapped hash table SYMTAB to the data buffer OUTPUT, with
25671 constant pool entries going into the data buffer CPOOL. */
25674 write_hash_table (mapped_symtab
*symtab
, data_buf
&output
, data_buf
&cpool
)
25677 /* Elements are sorted vectors of the indices of all the CUs that
25678 hold an object of this name. */
25679 std::unordered_map
<std::vector
<offset_type
>, offset_type
,
25680 vector_hasher
<offset_type
>>
25683 /* We add all the index vectors to the constant pool first, to
25684 ensure alignment is ok. */
25685 for (symtab_index_entry
&entry
: symtab
->data
)
25687 if (entry
.name
== NULL
)
25689 gdb_assert (entry
.index_offset
== 0);
25691 /* Finding before inserting is faster than always trying to
25692 insert, because inserting always allocates a node, does the
25693 lookup, and then destroys the new node if another node
25694 already had the same key. C++17 try_emplace will avoid
25697 = symbol_hash_table
.find (entry
.cu_indices
);
25698 if (found
!= symbol_hash_table
.end ())
25700 entry
.index_offset
= found
->second
;
25704 symbol_hash_table
.emplace (entry
.cu_indices
, cpool
.size ());
25705 entry
.index_offset
= cpool
.size ();
25706 cpool
.append_data (MAYBE_SWAP (entry
.cu_indices
.size ()));
25707 for (const auto index
: entry
.cu_indices
)
25708 cpool
.append_data (MAYBE_SWAP (index
));
25712 /* Now write out the hash table. */
25713 std::unordered_map
<c_str_view
, offset_type
, c_str_view_hasher
> str_table
;
25714 for (const auto &entry
: symtab
->data
)
25716 offset_type str_off
, vec_off
;
25718 if (entry
.name
!= NULL
)
25720 const auto insertpair
= str_table
.emplace (entry
.name
, cpool
.size ());
25721 if (insertpair
.second
)
25722 cpool
.append_cstr0 (entry
.name
);
25723 str_off
= insertpair
.first
->second
;
25724 vec_off
= entry
.index_offset
;
25728 /* While 0 is a valid constant pool index, it is not valid
25729 to have 0 for both offsets. */
25734 output
.append_data (MAYBE_SWAP (str_off
));
25735 output
.append_data (MAYBE_SWAP (vec_off
));
25739 typedef std::unordered_map
<partial_symtab
*, unsigned int> psym_index_map
;
25741 /* Helper struct for building the address table. */
25742 struct addrmap_index_data
25744 addrmap_index_data (data_buf
&addr_vec_
, psym_index_map
&cu_index_htab_
)
25745 : addr_vec (addr_vec_
), cu_index_htab (cu_index_htab_
)
25748 struct objfile
*objfile
;
25749 data_buf
&addr_vec
;
25750 psym_index_map
&cu_index_htab
;
25752 /* Non-zero if the previous_* fields are valid.
25753 We can't write an entry until we see the next entry (since it is only then
25754 that we know the end of the entry). */
25755 int previous_valid
;
25756 /* Index of the CU in the table of all CUs in the index file. */
25757 unsigned int previous_cu_index
;
25758 /* Start address of the CU. */
25759 CORE_ADDR previous_cu_start
;
25762 /* Write an address entry to ADDR_VEC. */
25765 add_address_entry (struct objfile
*objfile
, data_buf
&addr_vec
,
25766 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
25768 CORE_ADDR baseaddr
;
25770 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
25772 addr_vec
.append_uint (8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
25773 addr_vec
.append_uint (8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
25774 addr_vec
.append_data (MAYBE_SWAP (cu_index
));
25777 /* Worker function for traversing an addrmap to build the address table. */
25780 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
25782 struct addrmap_index_data
*data
= (struct addrmap_index_data
*) datap
;
25783 struct partial_symtab
*pst
= (struct partial_symtab
*) obj
;
25785 if (data
->previous_valid
)
25786 add_address_entry (data
->objfile
, data
->addr_vec
,
25787 data
->previous_cu_start
, start_addr
,
25788 data
->previous_cu_index
);
25790 data
->previous_cu_start
= start_addr
;
25793 const auto it
= data
->cu_index_htab
.find (pst
);
25794 gdb_assert (it
!= data
->cu_index_htab
.cend ());
25795 data
->previous_cu_index
= it
->second
;
25796 data
->previous_valid
= 1;
25799 data
->previous_valid
= 0;
25804 /* Write OBJFILE's address map to ADDR_VEC.
25805 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
25806 in the index file. */
25809 write_address_map (struct objfile
*objfile
, data_buf
&addr_vec
,
25810 psym_index_map
&cu_index_htab
)
25812 struct addrmap_index_data
addrmap_index_data (addr_vec
, cu_index_htab
);
25814 /* When writing the address table, we have to cope with the fact that
25815 the addrmap iterator only provides the start of a region; we have to
25816 wait until the next invocation to get the start of the next region. */
25818 addrmap_index_data
.objfile
= objfile
;
25819 addrmap_index_data
.previous_valid
= 0;
25821 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
25822 &addrmap_index_data
);
25824 /* It's highly unlikely the last entry (end address = 0xff...ff)
25825 is valid, but we should still handle it.
25826 The end address is recorded as the start of the next region, but that
25827 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
25829 if (addrmap_index_data
.previous_valid
)
25830 add_address_entry (objfile
, addr_vec
,
25831 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
25832 addrmap_index_data
.previous_cu_index
);
25835 /* Return the symbol kind of PSYM. */
25837 static gdb_index_symbol_kind
25838 symbol_kind (struct partial_symbol
*psym
)
25840 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
25841 enum address_class aclass
= PSYMBOL_CLASS (psym
);
25849 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
25851 return GDB_INDEX_SYMBOL_KIND_TYPE
;
25853 case LOC_CONST_BYTES
:
25854 case LOC_OPTIMIZED_OUT
:
25856 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
25858 /* Note: It's currently impossible to recognize psyms as enum values
25859 short of reading the type info. For now punt. */
25860 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
25862 /* There are other LOC_FOO values that one might want to classify
25863 as variables, but dwarf2read.c doesn't currently use them. */
25864 return GDB_INDEX_SYMBOL_KIND_OTHER
;
25866 case STRUCT_DOMAIN
:
25867 return GDB_INDEX_SYMBOL_KIND_TYPE
;
25869 return GDB_INDEX_SYMBOL_KIND_OTHER
;
25873 /* Add a list of partial symbols to SYMTAB. */
25876 write_psymbols (struct mapped_symtab
*symtab
,
25877 std::unordered_set
<partial_symbol
*> &psyms_seen
,
25878 struct partial_symbol
**psymp
,
25880 offset_type cu_index
,
25883 for (; count
-- > 0; ++psymp
)
25885 struct partial_symbol
*psym
= *psymp
;
25887 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
25888 error (_("Ada is not currently supported by the index"));
25890 /* Only add a given psymbol once. */
25891 if (psyms_seen
.insert (psym
).second
)
25893 gdb_index_symbol_kind kind
= symbol_kind (psym
);
25895 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
25896 is_static
, kind
, cu_index
);
25901 /* A helper struct used when iterating over debug_types. */
25902 struct signatured_type_index_data
25904 signatured_type_index_data (data_buf
&types_list_
,
25905 std::unordered_set
<partial_symbol
*> &psyms_seen_
)
25906 : types_list (types_list_
), psyms_seen (psyms_seen_
)
25909 struct objfile
*objfile
;
25910 struct mapped_symtab
*symtab
;
25911 data_buf
&types_list
;
25912 std::unordered_set
<partial_symbol
*> &psyms_seen
;
25916 /* A helper function that writes a single signatured_type to an
25920 write_one_signatured_type (void **slot
, void *d
)
25922 struct signatured_type_index_data
*info
25923 = (struct signatured_type_index_data
*) d
;
25924 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
25925 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
25927 write_psymbols (info
->symtab
,
25929 &info
->objfile
->global_psymbols
[psymtab
->globals_offset
],
25930 psymtab
->n_global_syms
, info
->cu_index
,
25932 write_psymbols (info
->symtab
,
25934 &info
->objfile
->static_psymbols
[psymtab
->statics_offset
],
25935 psymtab
->n_static_syms
, info
->cu_index
,
25938 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
25939 to_underlying (entry
->per_cu
.sect_off
));
25940 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
25941 to_underlying (entry
->type_offset_in_tu
));
25942 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
, entry
->signature
);
25949 /* Recurse into all "included" dependencies and count their symbols as
25950 if they appeared in this psymtab. */
25953 recursively_count_psymbols (struct partial_symtab
*psymtab
,
25954 size_t &psyms_seen
)
25956 for (int i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
25957 if (psymtab
->dependencies
[i
]->user
!= NULL
)
25958 recursively_count_psymbols (psymtab
->dependencies
[i
],
25961 psyms_seen
+= psymtab
->n_global_syms
;
25962 psyms_seen
+= psymtab
->n_static_syms
;
25965 /* Recurse into all "included" dependencies and write their symbols as
25966 if they appeared in this psymtab. */
25969 recursively_write_psymbols (struct objfile
*objfile
,
25970 struct partial_symtab
*psymtab
,
25971 struct mapped_symtab
*symtab
,
25972 std::unordered_set
<partial_symbol
*> &psyms_seen
,
25973 offset_type cu_index
)
25977 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
25978 if (psymtab
->dependencies
[i
]->user
!= NULL
)
25979 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
25980 symtab
, psyms_seen
, cu_index
);
25982 write_psymbols (symtab
,
25984 &objfile
->global_psymbols
[psymtab
->globals_offset
],
25985 psymtab
->n_global_syms
, cu_index
,
25987 write_psymbols (symtab
,
25989 &objfile
->static_psymbols
[psymtab
->statics_offset
],
25990 psymtab
->n_static_syms
, cu_index
,
25994 /* DWARF-5 .debug_names builder. */
25998 debug_names (bool is_dwarf64
, bfd_endian dwarf5_byte_order
)
25999 : m_dwarf5_byte_order (dwarf5_byte_order
),
26000 m_dwarf32 (dwarf5_byte_order
),
26001 m_dwarf64 (dwarf5_byte_order
),
26002 m_dwarf (is_dwarf64
26003 ? static_cast<dwarf
&> (m_dwarf64
)
26004 : static_cast<dwarf
&> (m_dwarf32
)),
26005 m_name_table_string_offs (m_dwarf
.name_table_string_offs
),
26006 m_name_table_entry_offs (m_dwarf
.name_table_entry_offs
)
26009 /* Insert one symbol. */
26010 void insert (const partial_symbol
*psym
, int cu_index
, bool is_static
)
26012 const int dwarf_tag
= psymbol_tag (psym
);
26013 if (dwarf_tag
== 0)
26015 const char *const name
= SYMBOL_SEARCH_NAME (psym
);
26016 const auto insertpair
26017 = m_name_to_value_set
.emplace (c_str_view (name
),
26018 std::set
<symbol_value
> ());
26019 std::set
<symbol_value
> &value_set
= insertpair
.first
->second
;
26020 value_set
.emplace (symbol_value (dwarf_tag
, cu_index
, is_static
));
26023 /* Build all the tables. All symbols must be already inserted.
26024 This function does not call file_write, caller has to do it
26028 /* Verify the build method has not be called twice. */
26029 gdb_assert (m_abbrev_table
.empty ());
26030 const size_t name_count
= m_name_to_value_set
.size ();
26031 m_bucket_table
.resize
26032 (std::pow (2, std::ceil (std::log2 (name_count
* 4 / 3))));
26033 m_hash_table
.reserve (name_count
);
26034 m_name_table_string_offs
.reserve (name_count
);
26035 m_name_table_entry_offs
.reserve (name_count
);
26037 /* Map each hash of symbol to its name and value. */
26038 struct hash_it_pair
26041 decltype (m_name_to_value_set
)::const_iterator it
;
26043 std::vector
<std::forward_list
<hash_it_pair
>> bucket_hash
;
26044 bucket_hash
.resize (m_bucket_table
.size ());
26045 for (decltype (m_name_to_value_set
)::const_iterator it
26046 = m_name_to_value_set
.cbegin ();
26047 it
!= m_name_to_value_set
.cend ();
26050 const char *const name
= it
->first
.c_str ();
26051 const uint32_t hash
= dwarf5_djb_hash (name
);
26052 hash_it_pair hashitpair
;
26053 hashitpair
.hash
= hash
;
26054 hashitpair
.it
= it
;
26055 auto &slot
= bucket_hash
[hash
% bucket_hash
.size()];
26056 slot
.push_front (std::move (hashitpair
));
26058 for (size_t bucket_ix
= 0; bucket_ix
< bucket_hash
.size (); ++bucket_ix
)
26060 const std::forward_list
<hash_it_pair
> &hashitlist
26061 = bucket_hash
[bucket_ix
];
26062 if (hashitlist
.empty ())
26064 uint32_t &bucket_slot
= m_bucket_table
[bucket_ix
];
26065 /* The hashes array is indexed starting at 1. */
26066 store_unsigned_integer (reinterpret_cast<gdb_byte
*> (&bucket_slot
),
26067 sizeof (bucket_slot
), m_dwarf5_byte_order
,
26068 m_hash_table
.size () + 1);
26069 for (const hash_it_pair
&hashitpair
: hashitlist
)
26071 m_hash_table
.push_back (0);
26072 store_unsigned_integer (reinterpret_cast<gdb_byte
*>
26073 (&m_hash_table
.back ()),
26074 sizeof (m_hash_table
.back ()),
26075 m_dwarf5_byte_order
, hashitpair
.hash
);
26076 const c_str_view
&name
= hashitpair
.it
->first
;
26077 const std::set
<symbol_value
> &value_set
= hashitpair
.it
->second
;
26078 m_name_table_string_offs
.push_back_reorder
26079 (m_debugstrlookup
.lookup (name
.c_str ()));
26080 m_name_table_entry_offs
.push_back_reorder (m_entry_pool
.size ());
26081 gdb_assert (!value_set
.empty ());
26082 for (const symbol_value
&value
: value_set
)
26084 int &idx
= m_indexkey_to_idx
[index_key (value
.dwarf_tag
,
26088 idx
= m_idx_next
++;
26089 m_abbrev_table
.append_unsigned_leb128 (idx
);
26090 m_abbrev_table
.append_unsigned_leb128 (value
.dwarf_tag
);
26091 m_abbrev_table
.append_unsigned_leb128 (DW_IDX_compile_unit
);
26092 m_abbrev_table
.append_unsigned_leb128 (DW_FORM_udata
);
26093 m_abbrev_table
.append_unsigned_leb128 (value
.is_static
26094 ? DW_IDX_GNU_internal
26095 : DW_IDX_GNU_external
);
26096 m_abbrev_table
.append_unsigned_leb128 (DW_FORM_flag_present
);
26098 /* Terminate attributes list. */
26099 m_abbrev_table
.append_unsigned_leb128 (0);
26100 m_abbrev_table
.append_unsigned_leb128 (0);
26103 m_entry_pool
.append_unsigned_leb128 (idx
);
26104 m_entry_pool
.append_unsigned_leb128 (value
.cu_index
);
26107 /* Terminate the list of CUs. */
26108 m_entry_pool
.append_unsigned_leb128 (0);
26111 gdb_assert (m_hash_table
.size () == name_count
);
26113 /* Terminate tags list. */
26114 m_abbrev_table
.append_unsigned_leb128 (0);
26117 /* Return .debug_names bucket count. This must be called only after
26118 calling the build method. */
26119 uint32_t bucket_count () const
26121 /* Verify the build method has been already called. */
26122 gdb_assert (!m_abbrev_table
.empty ());
26123 const uint32_t retval
= m_bucket_table
.size ();
26125 /* Check for overflow. */
26126 gdb_assert (retval
== m_bucket_table
.size ());
26130 /* Return .debug_names names count. This must be called only after
26131 calling the build method. */
26132 uint32_t name_count () const
26134 /* Verify the build method has been already called. */
26135 gdb_assert (!m_abbrev_table
.empty ());
26136 const uint32_t retval
= m_hash_table
.size ();
26138 /* Check for overflow. */
26139 gdb_assert (retval
== m_hash_table
.size ());
26143 /* Return number of bytes of .debug_names abbreviation table. This
26144 must be called only after calling the build method. */
26145 uint32_t abbrev_table_bytes () const
26147 gdb_assert (!m_abbrev_table
.empty ());
26148 return m_abbrev_table
.size ();
26151 /* Recurse into all "included" dependencies and store their symbols
26152 as if they appeared in this psymtab. */
26153 void recursively_write_psymbols
26154 (struct objfile
*objfile
,
26155 struct partial_symtab
*psymtab
,
26156 std::unordered_set
<partial_symbol
*> &psyms_seen
,
26159 for (int i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
26160 if (psymtab
->dependencies
[i
]->user
!= NULL
)
26161 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
26162 psyms_seen
, cu_index
);
26164 write_psymbols (psyms_seen
,
26165 &objfile
->global_psymbols
[psymtab
->globals_offset
],
26166 psymtab
->n_global_syms
, cu_index
, false);
26167 write_psymbols (psyms_seen
,
26168 &objfile
->static_psymbols
[psymtab
->statics_offset
],
26169 psymtab
->n_static_syms
, cu_index
, true);
26172 /* Return number of bytes the .debug_names section will have. This
26173 must be called only after calling the build method. */
26174 size_t bytes () const
26176 /* Verify the build method has been already called. */
26177 gdb_assert (!m_abbrev_table
.empty ());
26178 size_t expected_bytes
= 0;
26179 expected_bytes
+= m_bucket_table
.size () * sizeof (m_bucket_table
[0]);
26180 expected_bytes
+= m_hash_table
.size () * sizeof (m_hash_table
[0]);
26181 expected_bytes
+= m_name_table_string_offs
.bytes ();
26182 expected_bytes
+= m_name_table_entry_offs
.bytes ();
26183 expected_bytes
+= m_abbrev_table
.size ();
26184 expected_bytes
+= m_entry_pool
.size ();
26185 return expected_bytes
;
26188 /* Write .debug_names to FILE_NAMES and .debug_str addition to
26189 FILE_STR. This must be called only after calling the build
26191 void file_write (FILE *file_names
, FILE *file_str
) const
26193 /* Verify the build method has been already called. */
26194 gdb_assert (!m_abbrev_table
.empty ());
26195 ::file_write (file_names
, m_bucket_table
);
26196 ::file_write (file_names
, m_hash_table
);
26197 m_name_table_string_offs
.file_write (file_names
);
26198 m_name_table_entry_offs
.file_write (file_names
);
26199 m_abbrev_table
.file_write (file_names
);
26200 m_entry_pool
.file_write (file_names
);
26201 m_debugstrlookup
.file_write (file_str
);
26206 /* Storage for symbol names mapping them to their .debug_str section
26208 class debug_str_lookup
26212 /* Object costructor to be called for current DWARF2_PER_OBJFILE.
26213 All .debug_str section strings are automatically stored. */
26214 debug_str_lookup ()
26215 : m_abfd (dwarf2_per_objfile
->objfile
->obfd
)
26217 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
26218 &dwarf2_per_objfile
->str
);
26219 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
26221 for (const gdb_byte
*data
= dwarf2_per_objfile
->str
.buffer
;
26222 data
< (dwarf2_per_objfile
->str
.buffer
26223 + dwarf2_per_objfile
->str
.size
);)
26225 const char *const s
= reinterpret_cast<const char *> (data
);
26226 const auto insertpair
26227 = m_str_table
.emplace (c_str_view (s
),
26228 data
- dwarf2_per_objfile
->str
.buffer
);
26229 if (!insertpair
.second
)
26230 complaint (&symfile_complaints
,
26231 _("Duplicate string \"%s\" in "
26232 ".debug_str section [in module %s]"),
26233 s
, bfd_get_filename (m_abfd
));
26234 data
+= strlen (s
) + 1;
26238 /* Return offset of symbol name S in the .debug_str section. Add
26239 such symbol to the section's end if it does not exist there
26241 size_t lookup (const char *s
)
26243 const auto it
= m_str_table
.find (c_str_view (s
));
26244 if (it
!= m_str_table
.end ())
26246 const size_t offset
= (dwarf2_per_objfile
->str
.size
26247 + m_str_add_buf
.size ());
26248 m_str_table
.emplace (c_str_view (s
), offset
);
26249 m_str_add_buf
.append_cstr0 (s
);
26253 /* Append the end of the .debug_str section to FILE. */
26254 void file_write (FILE *file
) const
26256 m_str_add_buf
.file_write (file
);
26260 std::unordered_map
<c_str_view
, size_t, c_str_view_hasher
> m_str_table
;
26263 /* Data to add at the end of .debug_str for new needed symbol names. */
26264 data_buf m_str_add_buf
;
26267 /* Container to map used DWARF tags to their .debug_names abbreviation
26272 index_key (int dwarf_tag_
, bool is_static_
)
26273 : dwarf_tag (dwarf_tag_
), is_static (is_static_
)
26278 operator== (const index_key
&other
) const
26280 return dwarf_tag
== other
.dwarf_tag
&& is_static
== other
.is_static
;
26283 const int dwarf_tag
;
26284 const bool is_static
;
26287 /* Provide std::unordered_map::hasher for index_key. */
26288 class index_key_hasher
26292 operator () (const index_key
&key
) const
26294 return (std::hash
<int>() (key
.dwarf_tag
) << 1) | key
.is_static
;
26298 /* Parameters of one symbol entry. */
26302 const int dwarf_tag
, cu_index
;
26303 const bool is_static
;
26305 symbol_value (int dwarf_tag_
, int cu_index_
, bool is_static_
)
26306 : dwarf_tag (dwarf_tag_
), cu_index (cu_index_
), is_static (is_static_
)
26310 operator< (const symbol_value
&other
) const
26329 /* Abstract base class to unify DWARF-32 and DWARF-64 name table
26334 const bfd_endian dwarf5_byte_order
;
26336 explicit offset_vec (bfd_endian dwarf5_byte_order_
)
26337 : dwarf5_byte_order (dwarf5_byte_order_
)
26340 /* Call std::vector::reserve for NELEM elements. */
26341 virtual void reserve (size_t nelem
) = 0;
26343 /* Call std::vector::push_back with store_unsigned_integer byte
26344 reordering for ELEM. */
26345 virtual void push_back_reorder (size_t elem
) = 0;
26347 /* Return expected output size in bytes. */
26348 virtual size_t bytes () const = 0;
26350 /* Write name table to FILE. */
26351 virtual void file_write (FILE *file
) const = 0;
26354 /* Template to unify DWARF-32 and DWARF-64 output. */
26355 template<typename OffsetSize
>
26356 class offset_vec_tmpl
: public offset_vec
26359 explicit offset_vec_tmpl (bfd_endian dwarf5_byte_order_
)
26360 : offset_vec (dwarf5_byte_order_
)
26363 /* Implement offset_vec::reserve. */
26364 void reserve (size_t nelem
) override
26366 m_vec
.reserve (nelem
);
26369 /* Implement offset_vec::push_back_reorder. */
26370 void push_back_reorder (size_t elem
) override
26372 m_vec
.push_back (elem
);
26373 /* Check for overflow. */
26374 gdb_assert (m_vec
.back () == elem
);
26375 store_unsigned_integer (reinterpret_cast<gdb_byte
*> (&m_vec
.back ()),
26376 sizeof (m_vec
.back ()), dwarf5_byte_order
, elem
);
26379 /* Implement offset_vec::bytes. */
26380 size_t bytes () const override
26382 return m_vec
.size () * sizeof (m_vec
[0]);
26385 /* Implement offset_vec::file_write. */
26386 void file_write (FILE *file
) const override
26388 ::file_write (file
, m_vec
);
26392 std::vector
<OffsetSize
> m_vec
;
26395 /* Base class to unify DWARF-32 and DWARF-64 .debug_names output
26396 respecting name table width. */
26400 offset_vec
&name_table_string_offs
, &name_table_entry_offs
;
26402 dwarf (offset_vec
&name_table_string_offs_
,
26403 offset_vec
&name_table_entry_offs_
)
26404 : name_table_string_offs (name_table_string_offs_
),
26405 name_table_entry_offs (name_table_entry_offs_
)
26410 /* Template to unify DWARF-32 and DWARF-64 .debug_names output
26411 respecting name table width. */
26412 template<typename OffsetSize
>
26413 class dwarf_tmpl
: public dwarf
26416 explicit dwarf_tmpl (bfd_endian dwarf5_byte_order_
)
26417 : dwarf (m_name_table_string_offs
, m_name_table_entry_offs
),
26418 m_name_table_string_offs (dwarf5_byte_order_
),
26419 m_name_table_entry_offs (dwarf5_byte_order_
)
26423 offset_vec_tmpl
<OffsetSize
> m_name_table_string_offs
;
26424 offset_vec_tmpl
<OffsetSize
> m_name_table_entry_offs
;
26427 /* Try to reconstruct original DWARF tag for given partial_symbol.
26428 This function is not DWARF-5 compliant but it is sufficient for
26429 GDB as a DWARF-5 index consumer. */
26430 static int psymbol_tag (const struct partial_symbol
*psym
)
26432 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
26433 enum address_class aclass
= PSYMBOL_CLASS (psym
);
26441 return DW_TAG_subprogram
;
26443 return DW_TAG_typedef
;
26445 case LOC_CONST_BYTES
:
26446 case LOC_OPTIMIZED_OUT
:
26448 return DW_TAG_variable
;
26450 /* Note: It's currently impossible to recognize psyms as enum values
26451 short of reading the type info. For now punt. */
26452 return DW_TAG_variable
;
26454 /* There are other LOC_FOO values that one might want to classify
26455 as variables, but dwarf2read.c doesn't currently use them. */
26456 return DW_TAG_variable
;
26458 case STRUCT_DOMAIN
:
26459 return DW_TAG_structure_type
;
26465 /* Call insert for all partial symbols and mark them in PSYMS_SEEN. */
26466 void write_psymbols (std::unordered_set
<partial_symbol
*> &psyms_seen
,
26467 struct partial_symbol
**psymp
, int count
, int cu_index
,
26470 for (; count
-- > 0; ++psymp
)
26472 struct partial_symbol
*psym
= *psymp
;
26474 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
26475 error (_("Ada is not currently supported by the index"));
26477 /* Only add a given psymbol once. */
26478 if (psyms_seen
.insert (psym
).second
)
26479 insert (psym
, cu_index
, is_static
);
26483 /* Store value of each symbol. */
26484 std::unordered_map
<c_str_view
, std::set
<symbol_value
>, c_str_view_hasher
>
26485 m_name_to_value_set
;
26487 /* Tables of DWARF-5 .debug_names. They are in object file byte
26489 std::vector
<uint32_t> m_bucket_table
;
26490 std::vector
<uint32_t> m_hash_table
;
26492 const bfd_endian m_dwarf5_byte_order
;
26493 dwarf_tmpl
<uint32_t> m_dwarf32
;
26494 dwarf_tmpl
<uint64_t> m_dwarf64
;
26496 offset_vec
&m_name_table_string_offs
, &m_name_table_entry_offs
;
26497 debug_str_lookup m_debugstrlookup
;
26499 /* Map each used .debug_names abbreviation tag parameter to its
26501 std::unordered_map
<index_key
, int, index_key_hasher
> m_indexkey_to_idx
;
26503 /* Next unused .debug_names abbreviation tag for
26504 m_indexkey_to_idx. */
26505 int m_idx_next
= 1;
26507 /* .debug_names abbreviation table. */
26508 data_buf m_abbrev_table
;
26510 /* .debug_names entry pool. */
26511 data_buf m_entry_pool
;
26514 /* Return iff any of the needed offsets does not fit into 32-bit
26515 .debug_names section. */
26518 check_dwarf64_offsets ()
26520 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
26522 const dwarf2_per_cu_data
&per_cu
= *dwarf2_per_objfile
->all_comp_units
[i
];
26524 if (to_underlying (per_cu
.sect_off
) >= (static_cast<uint64_t> (1) << 32))
26527 for (int i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
26529 const signatured_type
&sigtype
= *dwarf2_per_objfile
->all_type_units
[i
];
26530 const dwarf2_per_cu_data
&per_cu
= sigtype
.per_cu
;
26532 if (to_underlying (per_cu
.sect_off
) >= (static_cast<uint64_t> (1) << 32))
26538 /* The psyms_seen set is potentially going to be largish (~40k
26539 elements when indexing a -g3 build of GDB itself). Estimate the
26540 number of elements in order to avoid too many rehashes, which
26541 require rebuilding buckets and thus many trips to
26547 size_t psyms_count
= 0;
26548 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
26550 struct dwarf2_per_cu_data
*per_cu
26551 = dwarf2_per_objfile
->all_comp_units
[i
];
26552 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
26554 if (psymtab
!= NULL
&& psymtab
->user
== NULL
)
26555 recursively_count_psymbols (psymtab
, psyms_count
);
26557 /* Generating an index for gdb itself shows a ratio of
26558 TOTAL_SEEN_SYMS/UNIQUE_SYMS or ~5. 4 seems like a good bet. */
26559 return psyms_count
/ 4;
26562 /* Write new .gdb_index section for OBJFILE into OUT_FILE.
26563 Return how many bytes were expected to be written into OUT_FILE. */
26566 write_gdbindex (struct objfile
*objfile
, FILE *out_file
)
26568 mapped_symtab symtab
;
26571 /* While we're scanning CU's create a table that maps a psymtab pointer
26572 (which is what addrmap records) to its index (which is what is recorded
26573 in the index file). This will later be needed to write the address
26575 psym_index_map cu_index_htab
;
26576 cu_index_htab
.reserve (dwarf2_per_objfile
->n_comp_units
);
26578 /* The CU list is already sorted, so we don't need to do additional
26579 work here. Also, the debug_types entries do not appear in
26580 all_comp_units, but only in their own hash table. */
26582 std::unordered_set
<partial_symbol
*> psyms_seen (psyms_seen_size ());
26583 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
26585 struct dwarf2_per_cu_data
*per_cu
26586 = dwarf2_per_objfile
->all_comp_units
[i
];
26587 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
26589 /* CU of a shared file from 'dwz -m' may be unused by this main file.
26590 It may be referenced from a local scope but in such case it does not
26591 need to be present in .gdb_index. */
26592 if (psymtab
== NULL
)
26595 if (psymtab
->user
== NULL
)
26596 recursively_write_psymbols (objfile
, psymtab
, &symtab
,
26599 const auto insertpair
= cu_index_htab
.emplace (psymtab
, i
);
26600 gdb_assert (insertpair
.second
);
26602 cu_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
26603 to_underlying (per_cu
->sect_off
));
26604 cu_list
.append_uint (8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
26607 /* Dump the address map. */
26609 write_address_map (objfile
, addr_vec
, cu_index_htab
);
26611 /* Write out the .debug_type entries, if any. */
26612 data_buf types_cu_list
;
26613 if (dwarf2_per_objfile
->signatured_types
)
26615 signatured_type_index_data
sig_data (types_cu_list
,
26618 sig_data
.objfile
= objfile
;
26619 sig_data
.symtab
= &symtab
;
26620 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
26621 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
26622 write_one_signatured_type
, &sig_data
);
26625 /* Now that we've processed all symbols we can shrink their cu_indices
26627 uniquify_cu_indices (&symtab
);
26629 data_buf symtab_vec
, constant_pool
;
26630 write_hash_table (&symtab
, symtab_vec
, constant_pool
);
26633 const offset_type size_of_contents
= 6 * sizeof (offset_type
);
26634 offset_type total_len
= size_of_contents
;
26636 /* The version number. */
26637 contents
.append_data (MAYBE_SWAP (8));
26639 /* The offset of the CU list from the start of the file. */
26640 contents
.append_data (MAYBE_SWAP (total_len
));
26641 total_len
+= cu_list
.size ();
26643 /* The offset of the types CU list from the start of the file. */
26644 contents
.append_data (MAYBE_SWAP (total_len
));
26645 total_len
+= types_cu_list
.size ();
26647 /* The offset of the address table from the start of the file. */
26648 contents
.append_data (MAYBE_SWAP (total_len
));
26649 total_len
+= addr_vec
.size ();
26651 /* The offset of the symbol table from the start of the file. */
26652 contents
.append_data (MAYBE_SWAP (total_len
));
26653 total_len
+= symtab_vec
.size ();
26655 /* The offset of the constant pool from the start of the file. */
26656 contents
.append_data (MAYBE_SWAP (total_len
));
26657 total_len
+= constant_pool
.size ();
26659 gdb_assert (contents
.size () == size_of_contents
);
26661 contents
.file_write (out_file
);
26662 cu_list
.file_write (out_file
);
26663 types_cu_list
.file_write (out_file
);
26664 addr_vec
.file_write (out_file
);
26665 symtab_vec
.file_write (out_file
);
26666 constant_pool
.file_write (out_file
);
26671 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
26672 static const gdb_byte dwarf5_gdb_augmentation
[] = { 'G', 'D', 'B', 0 };
26674 /* Write a new .debug_names section for OBJFILE into OUT_FILE, write
26675 needed addition to .debug_str section to OUT_FILE_STR. Return how
26676 many bytes were expected to be written into OUT_FILE. */
26679 write_debug_names (struct objfile
*objfile
, FILE *out_file
, FILE *out_file_str
)
26681 const bool dwarf5_is_dwarf64
= check_dwarf64_offsets ();
26682 const int dwarf5_offset_size
= dwarf5_is_dwarf64
? 8 : 4;
26683 const enum bfd_endian dwarf5_byte_order
26684 = gdbarch_byte_order (get_objfile_arch (objfile
));
26686 /* The CU list is already sorted, so we don't need to do additional
26687 work here. Also, the debug_types entries do not appear in
26688 all_comp_units, but only in their own hash table. */
26690 debug_names
nametable (dwarf5_is_dwarf64
, dwarf5_byte_order
);
26691 std::unordered_set
<partial_symbol
*> psyms_seen (psyms_seen_size ());
26692 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
26694 const dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->all_comp_units
[i
];
26695 partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
26697 /* CU of a shared file from 'dwz -m' may be unused by this main
26698 file. It may be referenced from a local scope but in such
26699 case it does not need to be present in .debug_names. */
26700 if (psymtab
== NULL
)
26703 if (psymtab
->user
== NULL
)
26704 nametable
.recursively_write_psymbols (objfile
, psymtab
, psyms_seen
, i
);
26706 cu_list
.append_uint (dwarf5_offset_size
, dwarf5_byte_order
,
26707 to_underlying (per_cu
->sect_off
));
26709 nametable
.build ();
26711 /* No addr_vec - DWARF-5 uses .debug_aranges generated by GCC. */
26713 data_buf types_cu_list
;
26714 for (int i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
26716 const signatured_type
&sigtype
= *dwarf2_per_objfile
->all_type_units
[i
];
26717 const dwarf2_per_cu_data
&per_cu
= sigtype
.per_cu
;
26719 types_cu_list
.append_uint (dwarf5_offset_size
, dwarf5_byte_order
,
26720 to_underlying (per_cu
.sect_off
));
26723 const offset_type bytes_of_header
26724 = ((dwarf5_is_dwarf64
? 12 : 4)
26726 + sizeof (dwarf5_gdb_augmentation
));
26727 size_t expected_bytes
= 0;
26728 expected_bytes
+= bytes_of_header
;
26729 expected_bytes
+= cu_list
.size ();
26730 expected_bytes
+= types_cu_list
.size ();
26731 expected_bytes
+= nametable
.bytes ();
26734 if (!dwarf5_is_dwarf64
)
26736 const uint64_t size64
= expected_bytes
- 4;
26737 gdb_assert (size64
< 0xfffffff0);
26738 header
.append_uint (4, dwarf5_byte_order
, size64
);
26742 header
.append_uint (4, dwarf5_byte_order
, 0xffffffff);
26743 header
.append_uint (8, dwarf5_byte_order
, expected_bytes
- 12);
26746 /* The version number. */
26747 header
.append_uint (2, dwarf5_byte_order
, 5);
26750 header
.append_uint (2, dwarf5_byte_order
, 0);
26752 /* comp_unit_count - The number of CUs in the CU list. */
26753 header
.append_uint (4, dwarf5_byte_order
, dwarf2_per_objfile
->n_comp_units
);
26755 /* local_type_unit_count - The number of TUs in the local TU
26757 header
.append_uint (4, dwarf5_byte_order
, dwarf2_per_objfile
->n_type_units
);
26759 /* foreign_type_unit_count - The number of TUs in the foreign TU
26761 header
.append_uint (4, dwarf5_byte_order
, 0);
26763 /* bucket_count - The number of hash buckets in the hash lookup
26765 header
.append_uint (4, dwarf5_byte_order
, nametable
.bucket_count ());
26767 /* name_count - The number of unique names in the index. */
26768 header
.append_uint (4, dwarf5_byte_order
, nametable
.name_count ());
26770 /* abbrev_table_size - The size in bytes of the abbreviations
26772 header
.append_uint (4, dwarf5_byte_order
, nametable
.abbrev_table_bytes ());
26774 /* augmentation_string_size - The size in bytes of the augmentation
26775 string. This value is rounded up to a multiple of 4. */
26776 static_assert (sizeof (dwarf5_gdb_augmentation
) % 4 == 0, "");
26777 header
.append_uint (4, dwarf5_byte_order
, sizeof (dwarf5_gdb_augmentation
));
26778 header
.append_data (dwarf5_gdb_augmentation
);
26780 gdb_assert (header
.size () == bytes_of_header
);
26782 header
.file_write (out_file
);
26783 cu_list
.file_write (out_file
);
26784 types_cu_list
.file_write (out_file
);
26785 nametable
.file_write (out_file
, out_file_str
);
26787 return expected_bytes
;
26790 /* Assert that FILE's size is EXPECTED_SIZE. Assumes file's seek
26791 position is at the end of the file. */
26794 assert_file_size (FILE *file
, const char *filename
, size_t expected_size
)
26796 const auto file_size
= ftell (file
);
26797 if (file_size
== -1)
26798 error (_("Can't get `%s' size"), filename
);
26799 gdb_assert (file_size
== expected_size
);
26802 /* An index variant. */
26805 /* GDB's own .gdb_index format. */
26808 /* DWARF5 .debug_names. */
26812 /* Create an index file for OBJFILE in the directory DIR. */
26815 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
,
26816 dw_index_kind index_kind
)
26818 if (dwarf2_per_objfile
->using_index
)
26819 error (_("Cannot use an index to create the index"));
26821 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
26822 error (_("Cannot make an index when the file has multiple .debug_types sections"));
26824 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
26828 if (stat (objfile_name (objfile
), &st
) < 0)
26829 perror_with_name (objfile_name (objfile
));
26831 std::string
filename (std::string (dir
) + SLASH_STRING
26832 + lbasename (objfile_name (objfile
))
26833 + (index_kind
== dw_index_kind::DEBUG_NAMES
26834 ? INDEX5_SUFFIX
: INDEX4_SUFFIX
));
26836 FILE *out_file
= gdb_fopen_cloexec (filename
.c_str (), "wb").release ();
26838 error (_("Can't open `%s' for writing"), filename
.c_str ());
26840 /* Order matters here; we want FILE to be closed before FILENAME is
26841 unlinked, because on MS-Windows one cannot delete a file that is
26842 still open. (Don't call anything here that might throw until
26843 file_closer is created.) */
26844 gdb::unlinker
unlink_file (filename
.c_str ());
26845 gdb_file_up
close_out_file (out_file
);
26847 if (index_kind
== dw_index_kind::DEBUG_NAMES
)
26849 std::string
filename_str (std::string (dir
) + SLASH_STRING
26850 + lbasename (objfile_name (objfile
))
26851 + DEBUG_STR_SUFFIX
);
26853 = gdb_fopen_cloexec (filename_str
.c_str (), "wb").release ();
26855 error (_("Can't open `%s' for writing"), filename_str
.c_str ());
26856 gdb::unlinker
unlink_file_str (filename_str
.c_str ());
26857 gdb_file_up
close_out_file_str (out_file_str
);
26859 const size_t total_len
26860 = write_debug_names (objfile
, out_file
, out_file_str
);
26861 assert_file_size (out_file
, filename
.c_str (), total_len
);
26863 /* We want to keep the file .debug_str file too. */
26864 unlink_file_str
.keep ();
26868 const size_t total_len
26869 = write_gdbindex (objfile
, out_file
);
26870 assert_file_size (out_file
, filename
.c_str (), total_len
);
26873 /* We want to keep the file. */
26874 unlink_file
.keep ();
26877 /* Implementation of the `save gdb-index' command.
26879 Note that the .gdb_index file format used by this command is
26880 documented in the GDB manual. Any changes here must be documented
26884 save_gdb_index_command (const char *arg
, int from_tty
)
26886 struct objfile
*objfile
;
26887 const char dwarf5space
[] = "-dwarf-5 ";
26888 dw_index_kind index_kind
= dw_index_kind::GDB_INDEX
;
26893 arg
= skip_spaces (arg
);
26894 if (strncmp (arg
, dwarf5space
, strlen (dwarf5space
)) == 0)
26896 index_kind
= dw_index_kind::DEBUG_NAMES
;
26897 arg
+= strlen (dwarf5space
);
26898 arg
= skip_spaces (arg
);
26902 error (_("usage: save gdb-index [-dwarf-5] DIRECTORY"));
26904 ALL_OBJFILES (objfile
)
26908 /* If the objfile does not correspond to an actual file, skip it. */
26909 if (stat (objfile_name (objfile
), &st
) < 0)
26913 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
26914 dwarf2_objfile_data_key
);
26915 if (dwarf2_per_objfile
)
26920 write_psymtabs_to_index (objfile
, arg
, index_kind
);
26922 CATCH (except
, RETURN_MASK_ERROR
)
26924 exception_fprintf (gdb_stderr
, except
,
26925 _("Error while writing index for `%s': "),
26926 objfile_name (objfile
));
26935 int dwarf_always_disassemble
;
26938 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
26939 struct cmd_list_element
*c
, const char *value
)
26941 fprintf_filtered (file
,
26942 _("Whether to always disassemble "
26943 "DWARF expressions is %s.\n"),
26948 show_check_physname (struct ui_file
*file
, int from_tty
,
26949 struct cmd_list_element
*c
, const char *value
)
26951 fprintf_filtered (file
,
26952 _("Whether to check \"physname\" is %s.\n"),
26957 _initialize_dwarf2_read (void)
26959 struct cmd_list_element
*c
;
26961 dwarf2_objfile_data_key
26962 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
26964 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
26965 Set DWARF specific variables.\n\
26966 Configure DWARF variables such as the cache size"),
26967 &set_dwarf_cmdlist
, "maintenance set dwarf ",
26968 0/*allow-unknown*/, &maintenance_set_cmdlist
);
26970 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
26971 Show DWARF specific variables\n\
26972 Show DWARF variables such as the cache size"),
26973 &show_dwarf_cmdlist
, "maintenance show dwarf ",
26974 0/*allow-unknown*/, &maintenance_show_cmdlist
);
26976 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
26977 &dwarf_max_cache_age
, _("\
26978 Set the upper bound on the age of cached DWARF compilation units."), _("\
26979 Show the upper bound on the age of cached DWARF compilation units."), _("\
26980 A higher limit means that cached compilation units will be stored\n\
26981 in memory longer, and more total memory will be used. Zero disables\n\
26982 caching, which can slow down startup."),
26984 show_dwarf_max_cache_age
,
26985 &set_dwarf_cmdlist
,
26986 &show_dwarf_cmdlist
);
26988 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
26989 &dwarf_always_disassemble
, _("\
26990 Set whether `info address' always disassembles DWARF expressions."), _("\
26991 Show whether `info address' always disassembles DWARF expressions."), _("\
26992 When enabled, DWARF expressions are always printed in an assembly-like\n\
26993 syntax. When disabled, expressions will be printed in a more\n\
26994 conversational style, when possible."),
26996 show_dwarf_always_disassemble
,
26997 &set_dwarf_cmdlist
,
26998 &show_dwarf_cmdlist
);
27000 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
27001 Set debugging of the DWARF reader."), _("\
27002 Show debugging of the DWARF reader."), _("\
27003 When enabled (non-zero), debugging messages are printed during DWARF\n\
27004 reading and symtab expansion. A value of 1 (one) provides basic\n\
27005 information. A value greater than 1 provides more verbose information."),
27008 &setdebuglist
, &showdebuglist
);
27010 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
27011 Set debugging of the DWARF DIE reader."), _("\
27012 Show debugging of the DWARF DIE reader."), _("\
27013 When enabled (non-zero), DIEs are dumped after they are read in.\n\
27014 The value is the maximum depth to print."),
27017 &setdebuglist
, &showdebuglist
);
27019 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
27020 Set debugging of the dwarf line reader."), _("\
27021 Show debugging of the dwarf line reader."), _("\
27022 When enabled (non-zero), line number entries are dumped as they are read in.\n\
27023 A value of 1 (one) provides basic information.\n\
27024 A value greater than 1 provides more verbose information."),
27027 &setdebuglist
, &showdebuglist
);
27029 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
27030 Set cross-checking of \"physname\" code against demangler."), _("\
27031 Show cross-checking of \"physname\" code against demangler."), _("\
27032 When enabled, GDB's internal \"physname\" code is checked against\n\
27034 NULL
, show_check_physname
,
27035 &setdebuglist
, &showdebuglist
);
27037 add_setshow_boolean_cmd ("use-deprecated-index-sections",
27038 no_class
, &use_deprecated_index_sections
, _("\
27039 Set whether to use deprecated gdb_index sections."), _("\
27040 Show whether to use deprecated gdb_index sections."), _("\
27041 When enabled, deprecated .gdb_index sections are used anyway.\n\
27042 Normally they are ignored either because of a missing feature or\n\
27043 performance issue.\n\
27044 Warning: This option must be enabled before gdb reads the file."),
27047 &setlist
, &showlist
);
27049 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
27051 Save a gdb-index file.\n\
27052 Usage: save gdb-index [-dwarf-5] DIRECTORY\n\
27054 No options create one file with .gdb-index extension for pre-DWARF-5\n\
27055 compatible .gdb_index section. With -dwarf-5 creates two files with\n\
27056 extension .debug_names and .debug_str for DWARF-5 .debug_names section."),
27058 set_cmd_completer (c
, filename_completer
);
27060 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
27061 &dwarf2_locexpr_funcs
);
27062 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
27063 &dwarf2_loclist_funcs
);
27065 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
27066 &dwarf2_block_frame_base_locexpr_funcs
);
27067 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
27068 &dwarf2_block_frame_base_loclist_funcs
);
27071 selftests::register_test ("dw2_expand_symtabs_matching",
27072 selftests::dw2_expand_symtabs_matching::run_test
);